aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-01 02:03:31 +0800
committerobscuren <geffobscura@gmail.com>2014-07-01 02:03:31 +0800
commited276cd7c241749a9cf8add4e2fae3d3608a7ea4 (patch)
tree40416177aeac9874e0eecdb7194db9bc13e39174 /ethutil
parent82272ee08a7d72be1cc0947b6a0e8096a0353362 (diff)
downloadgo-tangerine-ed276cd7c241749a9cf8add4e2fae3d3608a7ea4.tar
go-tangerine-ed276cd7c241749a9cf8add4e2fae3d3608a7ea4.tar.gz
go-tangerine-ed276cd7c241749a9cf8add4e2fae3d3608a7ea4.tar.bz2
go-tangerine-ed276cd7c241749a9cf8add4e2fae3d3608a7ea4.tar.lz
go-tangerine-ed276cd7c241749a9cf8add4e2fae3d3608a7ea4.tar.xz
go-tangerine-ed276cd7c241749a9cf8add4e2fae3d3608a7ea4.tar.zst
go-tangerine-ed276cd7c241749a9cf8add4e2fae3d3608a7ea4.zip
Added Paranoia check for VM execution
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/trie.go18
-rw-r--r--ethutil/trie_test.go21
2 files changed, 32 insertions, 7 deletions
diff --git a/ethutil/trie.go b/ethutil/trie.go
index c669bdcb0..56f1648a6 100644
--- a/ethutil/trie.go
+++ b/ethutil/trie.go
@@ -173,10 +173,13 @@ func (t *Trie) Update(key string, value string) {
k := CompactHexDecode(key)
root := t.UpdateState(t.Root, k, value)
- if _, ok := root.([]byte); !ok {
- t.Root = t.cache.PutValue(root, true)
- } else {
+ switch root.(type) {
+ case string:
t.Root = root
+ case []byte:
+ t.Root = root
+ default:
+ t.Root = t.cache.PutValue(root, true)
}
}
@@ -197,10 +200,13 @@ func (t *Trie) Delete(key string) {
k := CompactHexDecode(key)
root := t.DeleteState(t.Root, k)
- if _, ok := root.([]byte); !ok {
- t.Root = t.cache.PutValue(root, true)
- } else {
+ switch root.(type) {
+ case string:
t.Root = root
+ case []byte:
+ t.Root = root
+ default:
+ t.Root = t.cache.PutValue(root, true)
}
}
diff --git a/ethutil/trie_test.go b/ethutil/trie_test.go
index d8db8a0d6..542af5504 100644
--- a/ethutil/trie_test.go
+++ b/ethutil/trie_test.go
@@ -242,7 +242,6 @@ func TestRemote(t *testing.T) {
for key, value := range test.In {
trie.Update(get(key), get(value))
}
- fmt.Printf("%-15s: %x\n", test.Name, trie.Root)
a := NewValue(h(test.Root)).Bytes()
b := NewValue(trie.Root).Bytes()
@@ -271,3 +270,23 @@ func TestTrieReplay(t *testing.T) {
}
})
}
+
+func TestIt(t *testing.T) {
+ _, trie := New()
+
+ test := map[string]string{
+ "0x000000000000000000000000ec4f34c97e43fbb2816cfd95e388353c7181dab1": "0x4e616d6552656700000000000000000000000000000000000000000000000000",
+ "0x0000000000000000000000000000000000000000000000000000000000000045": "0x22b224a1420a802ab51d326e29fa98e34c4f24ea",
+ "0x0000000000000000000000000000000000000000000000000000000000000046": "0x67706c2076330000000000000000000000000000000000000000000000000000",
+ "0x000000000000000000000000697c7b8c961b56f675d570498424ac8de1a918f6": "0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000",
+ "0x0000000000000000000000007ef9e639e2733cb34e4dfc576d4b23f72db776b2": "0x4655474156000000000000000000000000000000000000000000000000000000",
+ "0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000": "0x697c7b8c961b56f675d570498424ac8de1a918f6",
+ "0x4655474156000000000000000000000000000000000000000000000000000000": "0x7ef9e639e2733cb34e4dfc576d4b23f72db776b2",
+ "0x4e616d6552656700000000000000000000000000000000000000000000000000": "0xec4f34c97e43fbb2816cfd95e388353c7181dab1",
+ }
+
+ for k, v := range test {
+ trie.Update(k, v)
+ }
+ fmt.Printf("root : %x\n", trie.Root)
+}