fn new_tree()

in crypto/src/merkle/tests.rs [68:92]


fn new_tree() {
    let leaves = Digest256::bytes_as_digests(&LEAVES4).to_vec();
    let tree = MerkleTree::<Blake3_256>::new(leaves.clone()).unwrap();
    assert_eq!(2, tree.depth());
    let root = hash_2x1(
        hash_2x1(leaves[0], leaves[1]),
        hash_2x1(leaves[2], leaves[3]),
    );
    assert_eq!(&root, tree.root());

    let leaves = Digest256::bytes_as_digests(&LEAVES8).to_vec();
    let tree = MerkleTree::<Blake3_256>::new(leaves.clone()).unwrap();
    assert_eq!(3, tree.depth());
    let root = hash_2x1(
        hash_2x1(
            hash_2x1(leaves[0], leaves[1]),
            hash_2x1(leaves[2], leaves[3]),
        ),
        hash_2x1(
            hash_2x1(leaves[4], leaves[5]),
            hash_2x1(leaves[6], leaves[7]),
        ),
    );
    assert_eq!(&root, tree.root());
}