2020-01-20 14:40:58 +03:00
|
|
|
// Copyright 2020 The Grin Developers
|
2018-08-30 22:08:16 +03:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
pub mod common;
|
|
|
|
|
2018-12-08 02:59:40 +03:00
|
|
|
use self::core::core::verifier_cache::{LruVerifierCache, VerifierCache};
|
|
|
|
use self::core::core::{Output, OutputFeatures};
|
|
|
|
use self::core::libtx::proof;
|
|
|
|
use grin_core as core;
|
2019-11-14 18:27:30 +03:00
|
|
|
use keychain::{ExtKeychain, Keychain, SwitchCommitmentType};
|
2018-12-08 02:59:40 +03:00
|
|
|
use std::sync::Arc;
|
2019-11-14 18:27:30 +03:00
|
|
|
use util::RwLock;
|
2018-08-30 22:08:16 +03:00
|
|
|
|
2018-12-08 02:59:40 +03:00
|
|
|
fn verifier_cache() -> Arc<RwLock<dyn VerifierCache>> {
|
2018-08-30 22:08:16 +03:00
|
|
|
Arc::new(RwLock::new(LruVerifierCache::new()))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_verifier_cache_rangeproofs() {
|
|
|
|
let cache = verifier_cache();
|
|
|
|
|
2018-12-29 01:46:21 +03:00
|
|
|
let keychain = ExtKeychain::from_random_seed(false).unwrap();
|
2018-10-10 12:11:01 +03:00
|
|
|
let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0);
|
2020-02-04 16:52:00 +03:00
|
|
|
let switch = SwitchCommitmentType::Regular;
|
2019-06-27 11:19:17 +03:00
|
|
|
let commit = keychain.commit(5, &key_id, switch).unwrap();
|
|
|
|
let builder = proof::ProofBuilder::new(&keychain);
|
|
|
|
let proof = proof::create(&keychain, &builder, 5, &key_id, switch, commit, None).unwrap();
|
2018-08-30 22:08:16 +03:00
|
|
|
|
2020-09-03 12:59:54 +03:00
|
|
|
let out = Output::new(OutputFeatures::Plain, commit, proof);
|
2018-08-30 22:08:16 +03:00
|
|
|
|
|
|
|
// Check our output is not verified according to the cache.
|
|
|
|
{
|
2018-10-20 03:13:07 +03:00
|
|
|
let mut cache = cache.write();
|
2020-02-05 19:02:07 +03:00
|
|
|
let unverified = cache.filter_rangeproof_unverified(&[out]);
|
2018-08-30 22:08:16 +03:00
|
|
|
assert_eq!(unverified, vec![out]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add our output to the cache.
|
|
|
|
{
|
2018-10-20 03:13:07 +03:00
|
|
|
let mut cache = cache.write();
|
2018-08-30 22:08:16 +03:00
|
|
|
cache.add_rangeproof_verified(vec![out]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check it shows as verified according to the cache.
|
|
|
|
{
|
2018-10-20 03:13:07 +03:00
|
|
|
let mut cache = cache.write();
|
2020-02-05 19:02:07 +03:00
|
|
|
let unverified = cache.filter_rangeproof_unverified(&[out]);
|
2018-08-30 22:08:16 +03:00
|
|
|
assert_eq!(unverified, vec![]);
|
|
|
|
}
|
|
|
|
}
|