aboutsummaryrefslogtreecommitdiffstats
path: root/trie/trie_test.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-12-01 19:28:26 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-12-01 19:28:26 +0800
commit96d86740a1d27d548cba4fffd22d3b85a6975c4d (patch)
tree2f1c94790089a9dff935e434d6985a8bd8ad1c44 /trie/trie_test.go
parent23031b1554a05817ac23f2ef0d4780e16f065663 (diff)
parent52904ae32f0a591e7dccad7827ff1c2a73c27026 (diff)
downloaddexon-96d86740a1d27d548cba4fffd22d3b85a6975c4d.tar.gz
dexon-96d86740a1d27d548cba4fffd22d3b85a6975c4d.tar.zst
dexon-96d86740a1d27d548cba4fffd22d3b85a6975c4d.zip
Merge pull request #2005 from zsfelfoldi/light-trie
Trie error handling
Diffstat (limited to 'trie/trie_test.go')
-rw-r--r--trie/trie_test.go75
1 files changed, 74 insertions, 1 deletions
diff --git a/trie/trie_test.go b/trie/trie_test.go
index c96861bed..35d043cdf 100644
--- a/trie/trie_test.go
+++ b/trie/trie_test.go
@@ -64,11 +64,84 @@ func TestMissingRoot(t *testing.T) {
if trie != nil {
t.Error("New returned non-nil trie for invalid root")
}
- if err != ErrMissingRoot {
+ if _, ok := err.(*MissingNodeError); !ok {
t.Error("New returned wrong error: %v", err)
}
}
+func TestMissingNode(t *testing.T) {
+ db, _ := ethdb.NewMemDatabase()
+ trie, _ := New(common.Hash{}, db)
+ updateString(trie, "120000", "qwerqwerqwerqwerqwerqwerqwerqwer")
+ updateString(trie, "123456", "asdfasdfasdfasdfasdfasdfasdfasdf")
+ root, _ := trie.Commit()
+
+ ClearGlobalCache()
+
+ trie, _ = New(root, db)
+ _, err := trie.TryGet([]byte("120000"))
+ if err != nil {
+ t.Errorf("Unexpected error: %v", err)
+ }
+
+ trie, _ = New(root, db)
+ _, err = trie.TryGet([]byte("120099"))
+ if err != nil {
+ t.Errorf("Unexpected error: %v", err)
+ }
+
+ trie, _ = New(root, db)
+ _, err = trie.TryGet([]byte("123456"))
+ if err != nil {
+ t.Errorf("Unexpected error: %v", err)
+ }
+
+ trie, _ = New(root, db)
+ err = trie.TryUpdate([]byte("120099"), []byte("zxcvzxcvzxcvzxcvzxcvzxcvzxcvzxcv"))
+ if err != nil {
+ t.Errorf("Unexpected error: %v", err)
+ }
+
+ trie, _ = New(root, db)
+ err = trie.TryDelete([]byte("123456"))
+ if err != nil {
+ t.Errorf("Unexpected error: %v", err)
+ }
+
+ db.Delete(common.FromHex("e1d943cc8f061a0c0b98162830b970395ac9315654824bf21b73b891365262f9"))
+ ClearGlobalCache()
+
+ trie, _ = New(root, db)
+ _, err = trie.TryGet([]byte("120000"))
+ if _, ok := err.(*MissingNodeError); !ok {
+ t.Errorf("Wrong error: %v", err)
+ }
+
+ trie, _ = New(root, db)
+ _, err = trie.TryGet([]byte("120099"))
+ if _, ok := err.(*MissingNodeError); !ok {
+ t.Errorf("Wrong error: %v", err)
+ }
+
+ trie, _ = New(root, db)
+ _, err = trie.TryGet([]byte("123456"))
+ if err != nil {
+ t.Errorf("Unexpected error: %v", err)
+ }
+
+ trie, _ = New(root, db)
+ err = trie.TryUpdate([]byte("120099"), []byte("zxcv"))
+ if _, ok := err.(*MissingNodeError); !ok {
+ t.Errorf("Wrong error: %v", err)
+ }
+
+ trie, _ = New(root, db)
+ err = trie.TryDelete([]byte("123456"))
+ if _, ok := err.(*MissingNodeError); !ok {
+ t.Errorf("Wrong error: %v", err)
+ }
+}
+
func TestInsert(t *testing.T) {
trie := newEmpty()