-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Entry operations test logic but not prop yet
- Loading branch information
1 parent
66e60a5
commit d8b4510
Showing
5 changed files
with
51 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,36 @@ | ||
mod utils; | ||
use std::collections::HashMap; | ||
|
||
use kairos_trie::{ | ||
stored::{memory_db::MemoryDb, merkle::SnapshotBuilder}, | ||
Transaction, TrieRoot, | ||
}; | ||
use utils::operations::*; | ||
|
||
pub fn end_to_end_entry_ops(batches: &[&[Operation]]) { | ||
let db = &MemoryDb::<[u8; 8]>::empty(); | ||
|
||
let mut prior_root_hash = TrieRoot::default(); | ||
// used as a reference for trie behavior | ||
let mut hash_map = HashMap::new(); | ||
|
||
for batch in batches.iter() { | ||
let (new_root_hash, snapshot) = | ||
run_against_snapshot_builder(batch, prior_root_hash, db, &mut hash_map); | ||
|
||
run_against_snapshot(batch, snapshot, new_root_hash, prior_root_hash); | ||
prior_root_hash = new_root_hash; | ||
} | ||
|
||
// After all batches are applied, the trie and the hashmap should be in sync | ||
let bump = bumpalo::Bump::new(); | ||
let txn = Transaction::from_snapshot_builder( | ||
SnapshotBuilder::<_, [u8; 8]>::empty(db, &bump).with_trie_root_hash(prior_root_hash), | ||
); | ||
|
||
// Check that the trie and the hashmap are in sync | ||
for (k, v) in hash_map.iter() { | ||
let ret_v = txn.get(k).unwrap().unwrap(); | ||
assert_eq!(v, ret_v); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
use kairos_trie::KeyHash; | ||
use proptest::prelude::*; | ||
|
||
pub mod insert_get; | ||
pub mod operations; | ||
|
||
prop_compose! { | ||
pub fn arb_key_hash()(data in any::<[u8; 32]>()) -> KeyHash { | ||
KeyHash::from(&data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters