From 07aca1dcf7fa9ccf0eae9bce70d74de5487c9816 Mon Sep 17 00:00:00 2001 From: rymnc <43716372+rymnc@users.noreply.github.com> Date: Tue, 9 May 2023 22:59:45 +0530 Subject: [PATCH] fix: impl --- src/tree.rs | 2 +- tests/memory_keccak.rs | 11 ++++++++--- tests/sled_keccak.rs | 8 ++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/tree.rs b/src/tree.rs index a2f0b32..96156c1 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -251,7 +251,7 @@ where self.fill_nodes(root_key, start, end, &mut subtree, &leaves, start)?; for i in to_remove_indices { - subtree.insert(Key(self.depth, i - leaves.len() + 1), H::default_leaf()); + subtree.insert(Key(self.depth, i + leaves.len()), H::default_leaf()); } let subtree = Arc::new(RwLock::new(subtree)); diff --git a/tests/memory_keccak.rs b/tests/memory_keccak.rs index 1ba2e4c..d823d0d 100644 --- a/tests/memory_keccak.rs +++ b/tests/memory_keccak.rs @@ -151,12 +151,10 @@ fn set_range() -> PmtreeResult<()> { Ok(()) } - #[test] fn batch_operations() -> PmtreeResult<()> { let mut mt = MerkleTree::::new(2, MemoryDBConfig)?; - let leaves = [ hex!("0000000000000000000000000000000000000000000000000000000000000001"), hex!("0000000000000000000000000000000000000000000000000000000000000002"), @@ -184,11 +182,18 @@ fn batch_operations() -> PmtreeResult<()> { // this should be a no-op mt.batch_operations(None, [leaves[1]], [3])?; + assert_eq!( + mt.root(), + hex!("a9bb8c3f1f12e9aa903a50c47f314b57610a3ab32f2d463293f58836def38d36") + ); + + // this should remove the last element + mt.batch_operations(None, [], [3])?; + assert_eq!( mt.root(), hex!("222ff5e0b5877792c2bc1670e2ccd0c2c97cd7bb1672a57d598db05092d3d72c") ); - Ok(()) } diff --git a/tests/sled_keccak.rs b/tests/sled_keccak.rs index 96dd647..d08e79b 100644 --- a/tests/sled_keccak.rs +++ b/tests/sled_keccak.rs @@ -233,6 +233,14 @@ fn batch_operations() -> PmtreeResult<()> { // this should be a no-op mt.batch_operations(None, [leaves[1]], [3])?; + assert_eq!( + mt.root(), + hex!("a9bb8c3f1f12e9aa903a50c47f314b57610a3ab32f2d463293f58836def38d36") + ); + + // this should remove the last element + mt.batch_operations(None, [], [3])?; + assert_eq!( mt.root(), hex!("222ff5e0b5877792c2bc1670e2ccd0c2c97cd7bb1672a57d598db05092d3d72c")