From 72f519f5c1d716e0124d2d8a0a54e64362a57bac Mon Sep 17 00:00:00 2001 From: Evgeny Fomin Date: Wed, 6 Nov 2024 20:39:56 +0100 Subject: [PATCH] wip --- grovedb/src/merk_cache.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/grovedb/src/merk_cache.rs b/grovedb/src/merk_cache.rs index 42e48ce2..3ed25653 100644 --- a/grovedb/src/merk_cache.rs +++ b/grovedb/src/merk_cache.rs @@ -235,7 +235,7 @@ impl<'db, 'c> MerkHandle<'db, 'c> { mod tests { use grovedb_costs::OperationCost; use grovedb_path::SubtreePath; - use grovedb_storage::StorageBatch; + use grovedb_storage::{Storage, StorageBatch}; use grovedb_version::version::GroveVersion; use super::MerkCache; @@ -322,4 +322,35 @@ mod tests { // Do something and finalize another batch: assert!(cache.finalize().unwrap().unwrap().len() > 0); } + + #[test] + fn changes_to_merk_are_propagated() { + let version = GroveVersion::latest(); + let db = make_deep_tree(&version); + let tx = db.start_transaction(); + + let pre_hash = db.root_hash(Some(&tx), &version).unwrap().unwrap(); + + let mut cache = MerkCache::new(&db, &tx, version); + let [mut subtree] = cache + .get_multi_mut([SubtreePath::from(&[TEST_LEAF, b"innertree"])]) + .unwrap() + .unwrap(); + subtree + .insert(b"ayy", Element::new_item(b"lmao".to_vec()), None) + .unwrap() + .unwrap(); + + let batch = cache.finalize().unwrap().unwrap(); + + db.db + .commit_multi_context_batch(*batch, Some(&tx)) + .unwrap() + .unwrap(); + + assert_ne!( + pre_hash, + db.root_hash(Some(&tx), &version).unwrap().unwrap() + ) + } }