From d7ab716eea1d1892e3358b1dece6b0e2cd31fce8 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 19 Mar 2015 10:57:02 +0100 Subject: Fixed mkdnode & added some tests --- trie/trie.go | 12 +++++++----- trie/trie_test.go | 11 ++++++++++- 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'trie') diff --git a/trie/trie.go b/trie/trie.go index 1c1112a7f..4f47151a4 100644 --- a/trie/trie.go +++ b/trie/trie.go @@ -6,8 +6,8 @@ import ( "fmt" "sync" - "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" ) func ParanoiaCheck(t1 *Trie, backend Backend) (bool, *Trie) { @@ -305,11 +305,13 @@ func (self *Trie) mknode(value *common.Value) Node { return NewShortNode(self, CompactDecode(string(value.Get(0).Bytes())), self.mknode(value.Get(1))) } case 17: - fnode := NewFullNode(self) - for i := 0; i < l; i++ { - fnode.set(byte(i), self.mknode(value.Get(i))) + if len(value.Bytes()) != 17 { + fnode := NewFullNode(self) + for i := 0; i < l; i++ { + fnode.set(byte(i), self.mknode(value.Get(i))) + } + return fnode } - return fnode case 32: return &HashNode{value.Bytes(), self} } diff --git a/trie/trie_test.go b/trie/trie_test.go index 1393e0c97..16311aadf 100644 --- a/trie/trie_test.go +++ b/trie/trie_test.go @@ -5,8 +5,8 @@ import ( "fmt" "testing" - "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" ) type Db map[string][]byte @@ -32,6 +32,15 @@ func TestEmptyTrie(t *testing.T) { } } +func TestNull(t *testing.T) { + trie := NewEmpty() + + key := make([]byte, 32) + value := common.FromHex("0x823140710bf13990e4500136726d8b55") + trie.Update(key, value) + value = trie.Get(key) +} + func TestInsert(t *testing.T) { trie := NewEmpty() -- cgit v1.2.3