fix: impl

This commit is contained in:
rymnc 2023-05-09 22:59:45 +05:30
parent c1de1c3bca
commit 07aca1dcf7
No known key found for this signature in database
GPG Key ID: AAA088D5C68ECD34
3 changed files with 17 additions and 4 deletions

View File

@ -251,7 +251,7 @@ where
self.fill_nodes(root_key, start, end, &mut subtree, &leaves, start)?; self.fill_nodes(root_key, start, end, &mut subtree, &leaves, start)?;
for i in to_remove_indices { 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)); let subtree = Arc::new(RwLock::new(subtree));

View File

@ -151,12 +151,10 @@ fn set_range() -> PmtreeResult<()> {
Ok(()) Ok(())
} }
#[test] #[test]
fn batch_operations() -> PmtreeResult<()> { fn batch_operations() -> PmtreeResult<()> {
let mut mt = MerkleTree::<MemoryDB, MyKeccak>::new(2, MemoryDBConfig)?; let mut mt = MerkleTree::<MemoryDB, MyKeccak>::new(2, MemoryDBConfig)?;
let leaves = [ let leaves = [
hex!("0000000000000000000000000000000000000000000000000000000000000001"), hex!("0000000000000000000000000000000000000000000000000000000000000001"),
hex!("0000000000000000000000000000000000000000000000000000000000000002"), hex!("0000000000000000000000000000000000000000000000000000000000000002"),
@ -184,11 +182,18 @@ fn batch_operations() -> PmtreeResult<()> {
// this should be a no-op // this should be a no-op
mt.batch_operations(None, [leaves[1]], [3])?; 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!( assert_eq!(
mt.root(), mt.root(),
hex!("222ff5e0b5877792c2bc1670e2ccd0c2c97cd7bb1672a57d598db05092d3d72c") hex!("222ff5e0b5877792c2bc1670e2ccd0c2c97cd7bb1672a57d598db05092d3d72c")
); );
Ok(()) Ok(())
} }

View File

@ -233,6 +233,14 @@ fn batch_operations() -> PmtreeResult<()> {
// this should be a no-op // this should be a no-op
mt.batch_operations(None, [leaves[1]], [3])?; 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!( assert_eq!(
mt.root(), mt.root(),
hex!("222ff5e0b5877792c2bc1670e2ccd0c2c97cd7bb1672a57d598db05092d3d72c") hex!("222ff5e0b5877792c2bc1670e2ccd0c2c97cd7bb1672a57d598db05092d3d72c")