Skip to content

Commit

Permalink
test: add default hash function, and merkle tree node
Browse files Browse the repository at this point in the history
  • Loading branch information
pthomalla authored and yosriady committed Mar 6, 2019
1 parent 77d9693 commit aeb99b4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/merkle_tree_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,30 @@ defmodule MerkleTreeTest do
assert MerkleTree.new(blocks).root ==
MerkleTree.new(blocks |> Enum.map(&MerkleTree.Crypto.sha256/1), hash_leaf: false).root
end

test "default hash function sha256" do
blocks = ['a', 'a', 'a', 'a']
assert MerkleTree.new(blocks, &MerkleTree.Crypto.sha256/1) == MerkleTree.new(blocks)
end

test "merkle tree node" do
hash = &MerkleTree.Crypto.sha256/1

assert MerkleTree.build(['a', 'b'], &MerkleTree.Crypto.sha256/1) == %MerkleTree.Node{
children: [
%MerkleTree.Node{
children: [],
height: 0,
value: hash.('a')
},
%MerkleTree.Node{
children: [],
height: 0,
value: hash.('b')
}
],
height: 1,
value: hash.(hash.('a') <> hash.('b'))
}
end
end

0 comments on commit aeb99b4

Please sign in to comment.