Skip to content

Commit

Permalink
One node hash fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesolo committed Aug 28, 2018
1 parent b5865a5 commit 2d09a48
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# IDE
.idea

# Binary
*.exe
3 changes: 2 additions & 1 deletion trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func (t *MerkleTrie) MaxDepth() byte {
func hash(n *node) []byte {
if n.key != nil {
h := sha256.New()
return h.Sum(n.value)
h.Write(n.value)
return h.Sum(nil)
}
if n.left == nil {
return hash(n.right)
Expand Down
9 changes: 9 additions & 0 deletions trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ func ExampleEmptyMerkleTrieHash() {
// e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
}

func ExampleOneNode() {
tree := trie.NewMerkleTrie()
tree.Add([]byte{1}, []byte{2})
fmt.Printf("%x\n", tree.Hash())

// Output:
// dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986
}

func ExampleSetHighBit() {
tree := trie.NewMerkleTrie()
tree.Add(zero(), nil)
Expand Down

0 comments on commit 2d09a48

Please sign in to comment.