Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NikVolf committed Nov 9, 2019
1 parent a6df8d6 commit 653f368
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions core/client/db/src/storage_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,23 +668,29 @@ mod tests {

#[test]
fn simple_fork() {
let _ = ::env_logger::try_init();

let root_parent = H256::random();
let key = H256::random()[..].to_vec();
let h1 = H256::random();
let h2a = H256::random();
let h2b = H256::random();
let h3b = H256::random();

let shared = new_shared_cache::<Block, Blake2Hasher>(256*1024, (0,1));

let mut s = CachingState::new(InMemory::<Blake2Hasher>::default(), shared.clone(), Some(root_parent));
s.cache.sync_cache(&[], &[], vec![(key.clone(), Some(vec![2]))], vec![], Some(h1), Some(1), || true);

let mut s = CachingState::new(InMemory::<Blake2Hasher>::default(), shared.clone(), Some(h1));
s.cache.sync_cache(&[], &[], vec![(key.clone(), Some(vec![2]))], vec![], Some(h2a), Some(2), || true);
s.cache.sync_cache(&[], &[], vec![], vec![], Some(h2a), Some(2), || true);

let mut s = CachingState::new(InMemory::<Blake2Hasher>::default(), shared.clone(), Some(h1));
s.cache.sync_cache(&[], &[], vec![(key.clone(), Some(vec![3]))], vec![], Some(h2b), Some(2), || false);

let mut s = CachingState::new(InMemory::<Blake2Hasher>::default(), shared.clone(), Some(h2b));
s.cache.sync_cache(&[], &[], vec![(key.clone(), Some(vec![3]))], vec![], Some(h3b), Some(2), || false);

let s = CachingState::new(InMemory::<Blake2Hasher>::default(), shared.clone(), Some(h2a));
assert_eq!(s.storage(&key).unwrap().unwrap(), vec![2]);
}
Expand Down Expand Up @@ -1179,9 +1185,8 @@ mod qc {
return false;
}
},
(None, Some(y)) => {
eprintln!("<missing> != {:?}", y);
return false;
(None, Some(_y)) => {
// TODO: cache miss is not tracked atm
},
(Some(x), None) => {
eprintln!("{:?} != <missing>", x);
Expand All @@ -1204,9 +1209,8 @@ mod qc {
return false;
}
},
(None, Some(y)) => {
eprintln!("at [{}]: <missing> != {:?}", node.hash, y);
return false;
(None, Some(_y)) => {
// cache miss is not tracked atm
},
(Some(x), None) => {
eprintln!("at [{}]: {:?} != <missing>", node.hash, x);
Expand Down Expand Up @@ -1282,6 +1286,23 @@ mod qc {
assert!(is_head_match(&mutator))
}

#[test]
fn fork3() {
let h1 = H256::random();
let h2a = H256::random();
let h2b = H256::random();
let h3a = H256::random();

let mut mutator = Mutator::new_empty();
mutator.mutate_static(Action::Next { hash: h1, changes: keyval(1, 1) });
mutator.mutate_static(Action::Next { hash: h2a, changes: keyval(2, 2) });
mutator.mutate_static(Action::Next { hash: h3a, changes: keyval(3, 3) });

mutator.mutate_static(Action::Fork { depth: 2, hash: h2b, changes: keyval(1, 3) });

assert!(is_canon_match(&mutator))
}

quickcheck! {
fn head_complete(actions: Vec<Action>) -> TestResult {
let mut mutator = Mutator::new_empty();
Expand Down

0 comments on commit 653f368

Please sign in to comment.