fn merkle_trie_pruning_duplicate_leaves() {
        run_test(|merkle_path| {
            let db: Box<dyn Database> = make_lmdb(&merkle_path);
            let merkle_state = MerkleState { db: db.clone() };
            let mut merkle_db = MerkleRadixTree::new(db.clone(), None).expect("No db errors");
            let mut updates: Vec<StateChange> = Vec::with_capacity(3);
            updates.push(StateChange::Set {
                key: "ab0000".to_string(),
                value: "0001".as_bytes().to_vec(),
            });
            updates.push(StateChange::Set {
                key: "ab0a01".to_string(),
                value: "0002".as_bytes().to_vec(),
            });
            updates.push(StateChange::Set {
                key: "abff00".to_string(),
                value: "0003".as_bytes().to_vec(),
            });

            let parent_root = merkle_state
                .commit(&merkle_db.get_merkle_root(), &updates)
                .expect("Update failed to work");
            let parent_root_bytes = ::hex::decode(parent_root.clone()).expect("Proper hex");

            // create the middle root
            merkle_db.set_merkle_root(parent_root.clone()).unwrap();
            updates.clear();
            updates.push(StateChange::Set {
                key: "ab0000".to_string(),
                value: "change0".as_bytes().to_vec(),
            });
            updates.push(StateChange::Set {
                key: "ab0001".to_string(),
                value: "change1".as_bytes().to_vec(),
            });

            let successor_root_middle = merkle_state
                .commit(&parent_root, &updates)
                .expect("Update failed to work");

            // Set the value back to the original
            let successor_root_last = merkle_state
                .commit(
                    &successor_root_middle,
                    &[StateChange::Set {
                        key: "ab0000".to_string(),
                        value: "0001".as_bytes().to_vec(),
                    }],
                )
                .expect("Set failed to work");

            merkle_db.set_merkle_root(successor_root_last).unwrap();
            let parent_change_log = expect_change_log(&*db, &parent_root_bytes);
            assert_eq!(
                parent_change_log
                    .successors
                    .clone()
                    .first()
                    .unwrap()
                    .deletions
                    .len(),
                merkle_state
                    .prune(vec!(parent_root.clone()))
                    .expect("Prune should have no errors")
                    .len()
            );

            assert_value_at_address(&merkle_db, "ab0000", "0001");
        })
    }
/// This test creates a merkle trie with multiple entries and produces a
/// successor with duplicate That changes one new leaf, followed by a second
/// successor that produces a leaf with the same hash.  When the pruning the
/// initial root, the duplicate leaf node is not pruned as well.
This test creates a merkle trie with multiple entries and produces a
successor with duplicate That changes one new leaf, followed by a second
successor that produces a leaf with the same hash.  When the pruning the
initial root, the duplicate leaf node is not pruned as well.
This test creates a merkle trie with multiple entries and produces a successor with duplicate That changes one new leaf followed by a second successor that produces a leaf with the same hash . When the pruning the initial root the duplicate leaf node is not pruned as well .
fn merkle_trie_pruning_duplicate_leaves() {
        run_test(|merkle_path| {
            let db: Box<dyn Database> = make_lmdb(&merkle_path);
            let merkle_state = MerkleState { db: db.clone() };
            let mut merkle_db = MerkleRadixTree::new(db.clone(), None).expect("No db errors");
            let mut updates: Vec<StateChange> = Vec::with_capacity(3);
            updates.push(StateChange::Set {
                key: "ab0000".to_string(),
                value: "0001".as_bytes().to_vec(),
            });
            updates.push(StateChange::Set {
                key: "ab0a01".to_string(),
                value: "0002".as_bytes().to_vec(),
            });
            updates.push(StateChange::Set {
                key: "abff00".to_string(),
                value: "0003".as_bytes().to_vec(),
            });
            let parent_root = merkle_state
                .commit(&merkle_db.get_merkle_root(), &updates)
                .expect("Update failed to work");
            let parent_root_bytes = ::hex::decode(parent_root.clone()).expect("Proper hex");
            // create the middle root
            merkle_db.set_merkle_root(parent_root.clone()).unwrap();
            updates.clear();
            updates.push(StateChange::Set {
                key: "ab0000".to_string(),
                value: "change0".as_bytes().to_vec(),
            });
            updates.push(StateChange::Set {
                key: "ab0001".to_string(),
                value: "change1".as_bytes().to_vec(),
            });
            let successor_root_middle = merkle_state
                .commit(&parent_root, &updates)
                .expect("Update failed to work");
            // Set the value back to the original
            let successor_root_last = merkle_state
                .commit(
                    &successor_root_middle,
                    &[StateChange::Set {
                        key: "ab0000".to_string(),
                        value: "0001".as_bytes().to_vec(),
                    }],
                )
                .expect("Set failed to work");
            merkle_db.set_merkle_root(successor_root_last).unwrap();
            let parent_change_log = expect_change_log(&*db, &parent_root_bytes);
            assert_eq!(
                parent_change_log
                    .successors
                    .clone()
                    .first()
                    .unwrap()
                    .deletions
                    .len(),
                merkle_state
                    .prune(vec!(parent_root.clone()))
                    .expect("Prune should have no errors")
                    .len()
            );
            assert_value_at_address(&merkle_db, "ab0000", "0001");
        })
    }
fn merkle_trie_pruning_duplicate_leaves ( ) { run_test ( | merkle_path | { let db : Box < dyn Database > = make_lmdb ( & merkle_path ) ; let merkle_state = MerkleState { db : db . clone ( ) } ; let mut merkle_db = MerkleRadixTree :: new ( db . clone ( ) , None ) . expect ( " " ) ; let mut updates : Vec < StateChange > = Vec :: with_capacity ( 3 ) ; updates . push ( StateChange :: Set { key : " " . to_string ( ) , value : " " . as_bytes ( ) . to_vec ( ) , } ) ; updates . push ( StateChange :: Set { key : " " . to_string ( ) , value : " " . as_bytes ( ) . to_vec ( ) , } ) ; updates . push ( StateChange :: Set { key : " " . to_string ( ) , value : " " . as_bytes ( ) . to_vec ( ) , } ) ; let parent_root = merkle_state . commit ( & merkle_db . get_merkle_root ( ) , & updates ) . expect ( " " ) ; let parent_root_bytes = :: hex :: decode ( parent_root . clone ( ) ) . expect ( " " ) ; // create the middle root merkle_db . set_merkle_root ( parent_root . clone ( ) ) . unwrap ( ) ; updates . clear ( ) ; updates . push ( StateChange :: Set { key : " " . to_string ( ) , value : " " . as_bytes ( ) . to_vec ( ) , } ) ; updates . push ( StateChange :: Set { key : " " . to_string ( ) , value : " " . as_bytes ( ) . to_vec ( ) , } ) ; let successor_root_middle = merkle_state . commit ( & parent_root , & updates ) . expect ( " " ) ; // Set the value back to the original let successor_root_last = merkle_state . commit ( & successor_root_middle , & [ StateChange :: Set { key : " " . to_string ( ) , value : " " . as_bytes ( ) . to_vec ( ) , } ] , ) . expect ( " " ) ; merkle_db . set_merkle_root ( successor_root_last ) . unwrap ( ) ; let parent_change_log = expect_change_log ( & * db , & parent_root_bytes ) ; assert_eq ! ( parent_change_log successors clone ( ) first ( ) unwrap ( ) deletions len ( ) merkle_state prune ( vec ( parent_root clone ( ) ) ) expect ( " " ) len ( ) ) ; assert_value_at_address ( & merkle_db , " " , " " ) ; } ) }
This test creates a merkle trie with multiple entries and produces a
successor with duplicate That changes one new leaf, followed by a second
successor that produces a leaf with the same hash.
This test creates a merkle trie with multiple entries and produces a successor with duplicate That changes one new leaf followed by a second successor that produces a leaf with the same hash .