grin/core/tests/verifier_cache.rs
Yeastplume b8c8840cec
Refactor wallet commands (#2067)
* start wallet command refactoring

* another re-structuring attempt

* rustfmt

* begin splitting up wallet commands

* rustfmt

* clean up wallet arg checking

* rustfmt

* macro for arg parsing

* rustfmt

* factor out init commands

* rustfmt

* move recover to new format

* rustfmt

* add listen command to new format

* rustfmt

* Finish moving commands to new format

* rustfmt

* rustfmt

* propogate errors more cleanly

* rustfmt

* error handling cleanup
2018-12-06 12:04:02 +00:00

68 lines
2 KiB
Rust

// Copyright 2018 The Grin Developers
//
// 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.
extern crate chrono;
extern crate grin_core;
extern crate grin_keychain as keychain;
extern crate grin_util as util;
use std::sync::Arc;
use util::RwLock;
pub mod common;
use grin_core::core::verifier_cache::{LruVerifierCache, VerifierCache};
use grin_core::core::{Output, OutputFeatures};
use grin_core::libtx::proof;
use keychain::{ExtKeychain, Keychain};
fn verifier_cache() -> Arc<RwLock<VerifierCache>> {
Arc::new(RwLock::new(LruVerifierCache::new()))
}
#[test]
fn test_verifier_cache_rangeproofs() {
let cache = verifier_cache();
let keychain = ExtKeychain::from_random_seed().unwrap();
let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0);
let commit = keychain.commit(5, &key_id).unwrap();
let proof = proof::create(&keychain, 5, &key_id, commit, None).unwrap();
let out = Output {
features: OutputFeatures::DEFAULT_OUTPUT,
commit: commit,
proof: proof,
};
// Check our output is not verified according to the cache.
{
let mut cache = cache.write();
let unverified = cache.filter_rangeproof_unverified(&vec![out]);
assert_eq!(unverified, vec![out]);
}
// Add our output to the cache.
{
let mut cache = cache.write();
cache.add_rangeproof_verified(vec![out]);
}
// Check it shows as verified according to the cache.
{
let mut cache = cache.write();
let unverified = cache.filter_rangeproof_unverified(&vec![out]);
assert_eq!(unverified, vec![]);
}
}