From aeb99b49adfc84364f33936f398008c5a750108c Mon Sep 17 00:00:00 2001 From: pthomalla Date: Tue, 26 Feb 2019 16:36:33 +0100 Subject: [PATCH] test: add default hash function, and merkle tree node --- test/merkle_tree_test.exs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/merkle_tree_test.exs b/test/merkle_tree_test.exs index 7760606..7da89c2 100644 --- a/test/merkle_tree_test.exs +++ b/test/merkle_tree_test.exs @@ -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