fn merkle_trie_pruning_parent() {
        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");
            merkle_db.set_merkle_root(parent_root.clone()).unwrap();

            let parent_root_bytes = ::hex::decode(parent_root.clone()).expect("Proper hex");
            // check that we have a change log entry for the new root
            let mut parent_change_log = expect_change_log(&*db, &parent_root_bytes);
            assert!(parent_change_log.successors.is_empty());

            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 = merkle_state
                .commit(
                    &parent_root,
                    &[StateChange::Set {
                        key: "ab0000".to_string(),
                        value: "test".as_bytes().to_vec(),
                    }],
                )
                .expect("Set failed to work");
            let successor_root_bytes = ::hex::decode(successor_root.clone()).expect("proper hex");

            // Load the parent change log after the change.
            parent_change_log = expect_change_log(&*db, &parent_root_bytes);
            let successor_change_log = expect_change_log(&*db, &successor_root_bytes);

            assert_has_successors(&parent_change_log, &[&successor_root_bytes]);
            assert_eq!(parent_root_bytes, successor_change_log.parent);

            merkle_db
                .set_merkle_root(successor_root)
                .expect("Unable to apply the new merkle root");

            let mut deletions = parent_change_log
                .successors
                .first()
                .unwrap()
                .deletions
                .clone();
            deletions.push(parent_root_bytes.clone());

            assert_eq!(
                deletions.len(),
                merkle_state
                    .prune(vec!(parent_root.clone()))
                    .expect("Prune should have no errors")
                    .len()
            );
            {
                let reader = db.get_reader().unwrap();
                for addition in parent_change_log
                    .successors
                    .clone()
                    .first()
                    .unwrap()
                    .deletions
                    .clone()
                {
                    assert!(reader.get(&addition).is_none());
                }

                assert!(reader
                    .index_get(CHANGE_LOG_INDEX, &parent_root_bytes)
                    .expect("DB query should succeed")
                    .is_none());
            }
            assert!(merkle_db.set_merkle_root(parent_root).is_err());
        })
    }
/// This test creates a merkle trie with multiple entries, and produces a
/// second trie based on the first where an entry is change.
///
/// - It verifies that both tries have a ChangeLogEntry
/// - Prunes the parent trie
/// - Verifies that the nodes written are gone
/// - verifies that the parent trie's ChangeLogEntry is deleted
This test creates a merkle trie with multiple entries, and produces a
second trie based on the first where an entry is change.

It verifies that both tries have a ChangeLogEntry
Prunes the parent trie
Verifies that the nodes written are gone
verifies that the parent trie's ChangeLogEntry is deleted
This test creates a merkle trie with multiple entries and produces a second trie based on the first where an entry is change . It verifies that both tries have a ChangeLogEntry Prunes the parent trie Verifies that the nodes written are gone verifies that the parent trie ' s ChangeLogEntry is deleted
fn merkle_trie_pruning_parent() {
        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");
            merkle_db.set_merkle_root(parent_root.clone()).unwrap();
            let parent_root_bytes = ::hex::decode(parent_root.clone()).expect("Proper hex");
            // check that we have a change log entry for the new root
            let mut parent_change_log = expect_change_log(&*db, &parent_root_bytes);
            assert!(parent_change_log.successors.is_empty());
            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 = merkle_state
                .commit(
                    &parent_root,
                    &[StateChange::Set {
                        key: "ab0000".to_string(),
                        value: "test".as_bytes().to_vec(),
                    }],
                )
                .expect("Set failed to work");
            let successor_root_bytes = ::hex::decode(successor_root.clone()).expect("proper hex");
            // Load the parent change log after the change.
            parent_change_log = expect_change_log(&*db, &parent_root_bytes);
            let successor_change_log = expect_change_log(&*db, &successor_root_bytes);
            assert_has_successors(&parent_change_log, &[&successor_root_bytes]);
            assert_eq!(parent_root_bytes, successor_change_log.parent);
            merkle_db
                .set_merkle_root(successor_root)
                .expect("Unable to apply the new merkle root");
            let mut deletions = parent_change_log
                .successors
                .first()
                .unwrap()
                .deletions
                .clone();
            deletions.push(parent_root_bytes.clone());
            assert_eq!(
                deletions.len(),
                merkle_state
                    .prune(vec!(parent_root.clone()))
                    .expect("Prune should have no errors")
                    .len()
            );
            {
                let reader = db.get_reader().unwrap();
                for addition in parent_change_log
                    .successors
                    .clone()
                    .first()
                    .unwrap()
                    .deletions
                    .clone()
                {
                    assert!(reader.get(&addition).is_none());
                }
                assert!(reader
                    .index_get(CHANGE_LOG_INDEX, &parent_root_bytes)
                    .expect("DB query should succeed")
                    .is_none());
            }
            assert!(merkle_db.set_merkle_root(parent_root).is_err());
        })
    }
fn merkle_trie_pruning_parent ( ) { 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 ( " " ) ; merkle_db . set_merkle_root ( parent_root . clone ( ) ) . unwrap ( ) ; let parent_root_bytes = :: hex :: decode ( parent_root . clone ( ) ) . expect ( " " ) ; // check that we have a change log entry for the new root let mut parent_change_log = expect_change_log ( & * db , & parent_root_bytes ) ; assert ! ( parent_change_log successors is_empty ( ) ) ; assert_value_at_address ( & merkle_db , " " , " " ) ; assert_value_at_address ( & merkle_db , " " , " " ) ; assert_value_at_address ( & merkle_db , " " , " " ) ; let successor_root = merkle_state . commit ( & parent_root , & [ StateChange :: Set { key : " " . to_string ( ) , value : " " . as_bytes ( ) . to_vec ( ) , } ] , ) . expect ( " " ) ; let successor_root_bytes = :: hex :: decode ( successor_root . clone ( ) ) . expect ( " " ) ; // Load the parent change log after the change. parent_change_log = expect_change_log ( & * db , & parent_root_bytes ) ; let successor_change_log = expect_change_log ( & * db , & successor_root_bytes ) ; assert_has_successors ( & parent_change_log , & [ & successor_root_bytes ] ) ; assert_eq ! ( parent_root_bytes successor_change_log parent ) ; merkle_db . set_merkle_root ( successor_root ) . expect ( " " ) ; let mut deletions = parent_change_log . successors . first ( ) . unwrap ( ) . deletions . clone ( ) ; deletions . push ( parent_root_bytes . clone ( ) ) ; assert_eq ! ( deletions len ( ) merkle_state prune ( vec ( parent_root clone ( ) ) ) expect ( " " ) len ( ) ) ; { let reader = db . get_reader ( ) . unwrap ( ) ; for addition in parent_change_log . successors . clone ( ) . first ( ) . unwrap ( ) . deletions . clone ( ) { assert ! ( reader get ( addition ) is_none ( ) ) ; } assert ! ( reader index_get ( CHANGE_LOG_INDEX parent_root_bytes ) expect ( " " ) is_none ( ) ) ; } assert ! ( merkle_db set_merkle_root ( parent_root ) is_err ( ) ) ; } ) }
This test creates a merkle trie with multiple entries, and produces a
second trie based on the first where an entry is change.
This test creates a merkle trie with multiple entries and produces a second trie based on the first where an entry is change .