// Note the hardcoded hashes are only valid when using Blake256 as the Hasher
Note the hardcoded hashes are only valid when using Blake256 as the Hasher
Note the hardcoded hashes are only valid when using Blake256 as the Hasher
fn delete() {
    let mut mmr = MutableMmr::<Hasher, _>::new(Vec::default(), Bitmap::create()).unwrap();
    assert_eq!(mmr.is_empty(), Ok(true));
    for i in 0..5 {
        assert!(mmr.push(int_to_hash(i)).is_ok());
    }
    assert_eq!(mmr.len(), 5);
    let root = mmr.get_merkle_root().unwrap();
    assert_eq!(
        &root.to_hex(),
        "7b7ddec2af4f3d0b9b165750cf2ff15813e965d29ecd5318e0c8fea901ceaef4"
    );
    // Can't delete past bounds
    assert!(!mmr.delete(5));
    assert_eq!(mmr.len(), 5);
    assert_eq!(mmr.is_empty(), Ok(false));
    assert_eq!(mmr.get_merkle_root(), Ok(root));
    // Delete some nodes
    assert!(mmr.push(int_to_hash(5)).is_ok());
    assert!(mmr.delete(0));
    assert!(mmr.delete(2));
    assert!(mmr.delete(4));
    let root = mmr.get_merkle_root().unwrap();
    assert_eq!(
        &root.to_hex(),
        "69e69ba0c6222f2d9caa68282de0ba7f1259a0fa2b8d84af68f907ef4ec05054"
    );
    assert_eq!(mmr.len(), 3);
    assert_eq!(mmr.is_empty(), Ok(false));
    // Can't delete that which has already been deleted
    assert!(!mmr.delete(0,));
    assert!(!mmr.delete(2,));
    assert!(!mmr.delete(0,));
    // .. or beyond bounds of MMR
    assert!(!mmr.delete(9));
    assert_eq!(mmr.len(), 3);
    assert_eq!(mmr.is_empty(), Ok(false));
    // Merkle root should not have changed:
    assert_eq!(mmr.get_merkle_root(), Ok(root));
    assert!(mmr.delete(1));
    assert!(mmr.delete(5));
    assert!(mmr.delete(3));
    assert_eq!(mmr.len(), 0);
    assert_eq!(mmr.is_empty(), Ok(true));
    mmr.compress();
    let root = mmr.get_merkle_root().unwrap();
    assert_eq!(
        &root.to_hex(),
        "2a540797d919e63cff8051e54ae13197315000bcfde53efd3f711bb3d24995bc"
    );
}
fn delete ( ) { let mut mmr = MutableMmr :: < Hasher , _ > :: new ( Vec :: default ( ) , Bitmap :: create ( ) ) . unwrap ( ) ; assert_eq ! ( mmr is_empty ( ) Ok ( true ) ) ; for i in 0 .. 5 { assert ! ( mmr push ( int_to_hash ( i ) ) is_ok ( ) ) ; } assert_eq ! ( mmr len ( ) 5 ) ; let root = mmr . get_merkle_root ( ) . unwrap ( ) ; assert_eq ! ( root to_hex ( ) " " ) ; // Can't delete past bounds assert ! ( mmr delete ( 5 ) ) ; assert_eq ! ( mmr len ( ) 5 ) ; assert_eq ! ( mmr is_empty ( ) Ok ( false ) ) ; assert_eq ! ( mmr get_merkle_root ( ) Ok ( root ) ) ; // Delete some nodes assert ! ( mmr push ( int_to_hash ( 5 ) ) is_ok ( ) ) ; assert ! ( mmr delete ( 0 ) ) ; assert ! ( mmr delete ( 2 ) ) ; assert ! ( mmr delete ( 4 ) ) ; let root = mmr . get_merkle_root ( ) . unwrap ( ) ; assert_eq ! ( root to_hex ( ) " " ) ; assert_eq ! ( mmr len ( ) 3 ) ; assert_eq ! ( mmr is_empty ( ) Ok ( false ) ) ; // Can't delete that which has already been deleted assert ! ( mmr delete ( 0 ) ) ; assert ! ( mmr delete ( 2 ) ) ; assert ! ( mmr delete ( 0 ) ) ; // .. or beyond bounds of MMR assert ! ( mmr delete ( 9 ) ) ; assert_eq ! ( mmr len ( ) 3 ) ; assert_eq ! ( mmr is_empty ( ) Ok ( false ) ) ; // Merkle root should not have changed: assert_eq ! ( mmr get_merkle_root ( ) Ok ( root ) ) ; assert ! ( mmr delete ( 1 ) ) ; assert ! ( mmr delete ( 5 ) ) ; assert ! ( mmr delete ( 3 ) ) ; assert_eq ! ( mmr len ( ) 0 ) ; assert_eq ! ( mmr is_empty ( ) Ok ( true ) ) ; mmr . compress ( ) ; let root = mmr . get_merkle_root ( ) . unwrap ( ) ; assert_eq ! ( root to_hex ( ) " " ) ; }
Note the hardcoded hashes are only valid when using Blake256 as the Hasher
Note the hardcoded hashes are only valid when using Blake256 as the Hasher