aboutsummaryrefslogtreecommitdiffstats
path: root/ethtrie/trie_test.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-15 21:29:54 +0800
committerobscuren <geffobscura@gmail.com>2014-07-15 21:29:54 +0800
commit09bade64666f82a2580e7d24a8bc7655e2113287 (patch)
treef0014dd11139789289bb68ebee8d2da52078e12b /ethtrie/trie_test.go
parent5ec62a51537dec6cd299dfc0ff1fbd0847338ff8 (diff)
downloaddexon-09bade64666f82a2580e7d24a8bc7655e2113287.tar
dexon-09bade64666f82a2580e7d24a8bc7655e2113287.tar.gz
dexon-09bade64666f82a2580e7d24a8bc7655e2113287.tar.bz2
dexon-09bade64666f82a2580e7d24a8bc7655e2113287.tar.lz
dexon-09bade64666f82a2580e7d24a8bc7655e2113287.tar.xz
dexon-09bade64666f82a2580e7d24a8bc7655e2113287.tar.zst
dexon-09bade64666f82a2580e7d24a8bc7655e2113287.zip
Fixed an issue where the trie might crash on missmatching lengths
Diffstat (limited to 'ethtrie/trie_test.go')
-rw-r--r--ethtrie/trie_test.go46
1 files changed, 41 insertions, 5 deletions
diff --git a/ethtrie/trie_test.go b/ethtrie/trie_test.go
index a3d4547d7..f39477ff9 100644
--- a/ethtrie/trie_test.go
+++ b/ethtrie/trie_test.go
@@ -5,6 +5,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
+ "github.com/ethereum/eth-go/ethutil"
"io/ioutil"
"math/rand"
"net/http"
@@ -251,8 +252,8 @@ func TestRemote(t *testing.T) {
trie.Update(get(key), get(value))
}
- a := NewValue(h(test.Root)).Bytes()
- b := NewValue(trie.Root).Bytes()
+ a := ethutil.NewValue(h(test.Root)).Bytes()
+ b := ethutil.NewValue(trie.Root).Bytes()
if bytes.Compare(a, b) != 0 {
t.Errorf("%-10s: %x %x", test.Name, a, b)
}
@@ -267,12 +268,12 @@ func TestTrieReplay(t *testing.T) {
}
_, trie2 := New()
- trie.NewIterator().Each(func(key string, v *Value) {
+ trie.NewIterator().Each(func(key string, v *ethutil.Value) {
trie2.Update(key, v.Str())
})
- a := NewValue(trie.Root).Bytes()
- b := NewValue(trie2.Root).Bytes()
+ a := ethutil.NewValue(trie.Root).Bytes()
+ b := ethutil.NewValue(trie2.Root).Bytes()
if bytes.Compare(a, b) != 0 {
t.Errorf("%s %x %x\n", test.Name, trie.Root, trie2.Root)
}
@@ -329,3 +330,38 @@ func TestRegression(t *testing.T) {
}
}
}
+
+func TestDelete(t *testing.T) {
+ _, trie := New()
+
+ trie.Update("a", "jeffreytestlongstring")
+ trie.Update("aa", "otherstring")
+ trie.Update("aaa", "othermorestring")
+ trie.Update("aabbbbccc", "hithere")
+ trie.Update("abbcccdd", "hstanoehutnaheoustnh")
+ trie.Update("rnthaoeuabbcccdd", "hstanoehutnaheoustnh")
+ trie.Update("rneuabbcccdd", "hstanoehutnaheoustnh")
+ trie.Update("rneuabboeusntahoeucccdd", "hstanoehutnaheoustnh")
+ trie.Update("rnxabboeusntahoeucccdd", "hstanoehutnaheoustnh")
+ trie.Delete("aaboaestnuhbccc")
+ trie.Delete("a")
+ trie.Update("a", "nthaonethaosentuh")
+ trie.Update("c", "shtaosntehua")
+ trie.Delete("a")
+ trie.Update("aaaa", "testmegood")
+
+ fmt.Println("aa =>", trie.Get("aa"))
+ _, t2 := New()
+ trie.NewIterator().Each(func(key string, v *ethutil.Value) {
+ if key == "aaaa" {
+ t2.Update(key, v.Str())
+ } else {
+ t2.Update(key, v.Str())
+ }
+ })
+
+ a := ethutil.NewValue(trie.Root).Bytes()
+ b := ethutil.NewValue(t2.Root).Bytes()
+
+ fmt.Printf("o: %x\nc: %x\n", a, b)
+}