fn merkle_trie_pruning_successors() {
        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");

            merkle_db.set_merkle_root(parent_root.clone()).unwrap();
            assert_value_at_address(&merkle_db, "ab0000", "0001");
            assert_value_at_address(&merkle_db, "ab0a01", "0002");
            assert_value_at_address(&merkle_db, "abff00", "0003");

            let successor_root_left = merkle_state
                .commit(
                    &parent_root,
                    &[StateChange::Set {
                        key: "ab0000".to_string(),
                        value: "left".as_bytes().to_vec(),
                    }],
                )
                .expect("Set failed to work");

            let successor_root_left_bytes =
                ::hex::decode(successor_root_left.clone()).expect("proper hex");

            let successor_root_right = merkle_state
                .commit(
                    &parent_root,
                    &[StateChange::Set {
                        key: "ab0a01".to_string(),
                        value: "right".as_bytes().to_vec(),
                    }],
                )
                .expect("Set failed to work");

            let successor_root_right_bytes =
                ::hex::decode(successor_root_right.clone()).expect("proper hex");

            let mut parent_change_log = expect_change_log(&*db, &parent_root_bytes);
            let successor_left_change_log = expect_change_log(&*db, &successor_root_left_bytes);
            expect_change_log(&*db, &successor_root_right_bytes);

            assert_has_successors(
                &parent_change_log,
                &[&successor_root_left_bytes, &successor_root_right_bytes],
            );

            // Let's prune the left successor:
            let res = merkle_state
                .prune(vec![successor_root_left.clone()])
                .expect("Prune should have no errors");
            assert_eq!(successor_left_change_log.additions.len(), res.len());

            parent_change_log = expect_change_log(&*db, &parent_root_bytes);
            assert_has_successors(&parent_change_log, &[&successor_root_right_bytes]);

            assert!(merkle_db.set_merkle_root(successor_root_left).is_err());
        })
    }
/// This test creates a merkle trie with multiple entries and produces two
/// distinct successor tries from that first.
///
/// - it verifies that all the tries have a ChangeLogEntry
/// - it prunes one of the successors
/// - it verifies the nodes from that successor are removed
/// - it verifies that the pruned successor's ChangeLogEntry is removed
/// - it verifies the original and the remaining successor still are
///   persisted
This test creates a merkle trie with multiple entries and produces two
distinct successor tries from that first.

it verifies that all the tries have a ChangeLogEntry
it prunes one of the successors
it verifies the nodes from that successor are removed
it verifies that the pruned successor's ChangeLogEntry is removed
it verifies the original and the remaining successor still are
persisted
This test creates a merkle trie with multiple entries and produces two distinct successor tries from that first . it verifies that all the tries have a ChangeLogEntry it prunes one of the successors it verifies the nodes from that successor are removed it verifies that the pruned successor ' s ChangeLogEntry is removed it verifies the original and the remaining successor still are persisted
fn merkle_trie_pruning_successors() {
        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");
            merkle_db.set_merkle_root(parent_root.clone()).unwrap();
            assert_value_at_address(&merkle_db, "ab0000", "0001");
            assert_value_at_address(&merkle_db, "ab0a01", "0002");
            assert_value_at_address(&merkle_db, "abff00", "0003");
            let successor_root_left = merkle_state
                .commit(
                    &parent_root,
                    &[StateChange::Set {
                        key: "ab0000".to_string(),
                        value: "left".as_bytes().to_vec(),
                    }],
                )
                .expect("Set failed to work");
            let successor_root_left_bytes =
                ::hex::decode(successor_root_left.clone()).expect("proper hex");
            let successor_root_right = merkle_state
                .commit(
                    &parent_root,
                    &[StateChange::Set {
                        key: "ab0a01".to_string(),
                        value: "right".as_bytes().to_vec(),
                    }],
                )
                .expect("Set failed to work");
            let successor_root_right_bytes =
                ::hex::decode(successor_root_right.clone()).expect("proper hex");
            let mut parent_change_log = expect_change_log(&*db, &parent_root_bytes);
            let successor_left_change_log = expect_change_log(&*db, &successor_root_left_bytes);
            expect_change_log(&*db, &successor_root_right_bytes);
            assert_has_successors(
                &parent_change_log,
                &[&successor_root_left_bytes, &successor_root_right_bytes],
            );
            // Let's prune the left successor:
            let res = merkle_state
                .prune(vec![successor_root_left.clone()])
                .expect("Prune should have no errors");
            assert_eq!(successor_left_change_log.additions.len(), res.len());
            parent_change_log = expect_change_log(&*db, &parent_root_bytes);
            assert_has_successors(&parent_change_log, &[&successor_root_right_bytes]);
            assert!(merkle_db.set_merkle_root(successor_root_left).is_err());
        })
    }
fn merkle_trie_pruning_successors ( ) { 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 ( " " ) ; merkle_db . set_merkle_root ( parent_root . clone ( ) ) . unwrap ( ) ; assert_value_at_address ( & merkle_db , " " , " " ) ; assert_value_at_address ( & merkle_db , " " , " " ) ; assert_value_at_address ( & merkle_db , " " , " " ) ; let successor_root_left = merkle_state . commit ( & parent_root , & [ StateChange :: Set { key : " " . to_string ( ) , value : " " . as_bytes ( ) . to_vec ( ) , } ] , ) . expect ( " " ) ; let successor_root_left_bytes = :: hex :: decode ( successor_root_left . clone ( ) ) . expect ( " " ) ; let successor_root_right = merkle_state . commit ( & parent_root , & [ StateChange :: Set { key : " " . to_string ( ) , value : " " . as_bytes ( ) . to_vec ( ) , } ] , ) . expect ( " " ) ; let successor_root_right_bytes = :: hex :: decode ( successor_root_right . clone ( ) ) . expect ( " " ) ; let mut parent_change_log = expect_change_log ( & * db , & parent_root_bytes ) ; let successor_left_change_log = expect_change_log ( & * db , & successor_root_left_bytes ) ; expect_change_log ( & * db , & successor_root_right_bytes ) ; assert_has_successors ( & parent_change_log , & [ & successor_root_left_bytes , & successor_root_right_bytes ] , ) ; // Let's prune the left successor: let res = merkle_state . prune ( vec ! [ successor_root_left clone ( ) ] ) . expect ( " " ) ; assert_eq ! ( successor_left_change_log additions len ( ) res len ( ) ) ; parent_change_log = expect_change_log ( & * db , & parent_root_bytes ) ; assert_has_successors ( & parent_change_log , & [ & successor_root_right_bytes ] ) ; assert ! ( merkle_db set_merkle_root ( successor_root_left ) is_err ( ) ) ; } ) }
This test creates a merkle trie with multiple entries and produces two
distinct successor tries from that first.
This test creates a merkle trie with multiple entries and produces two distinct successor tries from that first .