undo
This commit is contained in:
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
type Db map[string][]byte
|
||||
@@ -16,18 +16,18 @@ func (self Db) Put(k, v []byte) { self[string(k)] = v }
|
||||
|
||||
// Used for testing
|
||||
func NewEmpty() *Trie {
|
||||
return New(common.Hash{}, make(Db))
|
||||
return New(nil, make(Db))
|
||||
}
|
||||
|
||||
func NewEmptySecure() *SecureTrie {
|
||||
return NewSecure(common.Hash{}, make(Db))
|
||||
return NewSecure(nil, make(Db))
|
||||
}
|
||||
|
||||
func TestEmptyTrie(t *testing.T) {
|
||||
trie := NewEmpty()
|
||||
res := trie.Hash()
|
||||
exp := crypto.Sha3(common.Encode(""))
|
||||
if !bytes.Equal(res[:], exp[:]) {
|
||||
if !bytes.Equal(res, exp) {
|
||||
t.Errorf("expected %x got %x", exp, res)
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func TestInsert(t *testing.T) {
|
||||
|
||||
exp := common.Hex2Bytes("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3")
|
||||
root := trie.Hash()
|
||||
if !bytes.Equal(root[:], exp[:]) {
|
||||
if !bytes.Equal(root, exp) {
|
||||
t.Errorf("exp %x got %x", exp, root)
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func TestInsert(t *testing.T) {
|
||||
|
||||
exp = common.Hex2Bytes("d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab")
|
||||
root = trie.Hash()
|
||||
if !bytes.Equal(root[:], exp) {
|
||||
if !bytes.Equal(root, exp) {
|
||||
t.Errorf("exp %x got %x", exp, root)
|
||||
}
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func TestDelete(t *testing.T) {
|
||||
|
||||
hash := trie.Hash()
|
||||
exp := common.Hex2Bytes("5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84")
|
||||
if !bytes.Equal(hash[:], exp) {
|
||||
if !bytes.Equal(hash, exp) {
|
||||
t.Errorf("expected %x got %x", exp, hash)
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ func TestEmptyValues(t *testing.T) {
|
||||
|
||||
hash := trie.Hash()
|
||||
exp := common.Hex2Bytes("5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84")
|
||||
if !bytes.Equal(hash[:], exp) {
|
||||
if !bytes.Equal(hash, exp) {
|
||||
t.Errorf("expected %x got %x", exp, hash)
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ func TestReplication(t *testing.T) {
|
||||
|
||||
hash := trie2.Hash()
|
||||
exp := trie.Hash()
|
||||
if !bytes.Equal(hash[:], exp[:]) {
|
||||
if !bytes.Equal(hash, exp) {
|
||||
t.Errorf("root failure. expected %x got %x", exp, hash)
|
||||
}
|
||||
|
||||
@@ -168,9 +168,7 @@ func TestReset(t *testing.T) {
|
||||
}
|
||||
trie.Commit()
|
||||
|
||||
var before common.Hash
|
||||
before.Set(trie.roothash)
|
||||
|
||||
before := common.CopyBytes(trie.roothash)
|
||||
trie.UpdateString("should", "revert")
|
||||
trie.Hash()
|
||||
// Should have no effect
|
||||
@@ -179,11 +177,9 @@ func TestReset(t *testing.T) {
|
||||
// ###
|
||||
|
||||
trie.Reset()
|
||||
after := common.CopyBytes(trie.roothash)
|
||||
|
||||
var after common.Hash
|
||||
after.Set(trie.roothash)
|
||||
|
||||
if before != after {
|
||||
if !bytes.Equal(before, after) {
|
||||
t.Errorf("expected roots to be equal. %x - %x", before, after)
|
||||
}
|
||||
}
|
||||
@@ -252,7 +248,7 @@ func BenchmarkGets(b *testing.B) {
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
trie.GetString("horse")
|
||||
trie.Get([]byte("horse"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,9 +263,8 @@ func BenchmarkUpdate(b *testing.B) {
|
||||
}
|
||||
|
||||
type kv struct {
|
||||
k common.Hash
|
||||
v []byte
|
||||
t bool
|
||||
k, v []byte
|
||||
t bool
|
||||
}
|
||||
|
||||
func TestLargeData(t *testing.T) {
|
||||
@@ -277,21 +272,17 @@ func TestLargeData(t *testing.T) {
|
||||
vals := make(map[string]*kv)
|
||||
|
||||
for i := byte(0); i < 255; i++ {
|
||||
var k1 common.Hash
|
||||
k1.SetBytes([]byte{i})
|
||||
var k2 common.Hash
|
||||
k2.SetBytes([]byte{10, i})
|
||||
value := &kv{k1, []byte{i}, false}
|
||||
value2 := &kv{k2, []byte{i}, false}
|
||||
value := &kv{common.LeftPadBytes([]byte{i}, 32), []byte{i}, false}
|
||||
value2 := &kv{common.LeftPadBytes([]byte{10, i}, 32), []byte{i}, false}
|
||||
trie.Update(value.k, value.v)
|
||||
trie.Update(value2.k, value2.v)
|
||||
vals[value.k.Str()] = value
|
||||
vals[value2.k.Str()] = value2
|
||||
vals[string(value.k)] = value
|
||||
vals[string(value2.k)] = value2
|
||||
}
|
||||
|
||||
it := trie.Iterator()
|
||||
for it.Next() {
|
||||
vals[it.Key.Str()].t = true
|
||||
vals[string(it.Key)].t = true
|
||||
}
|
||||
|
||||
var untouched []*kv
|
||||
@@ -332,7 +323,7 @@ func TestSecureDelete(t *testing.T) {
|
||||
|
||||
hash := trie.Hash()
|
||||
exp := common.Hex2Bytes("29b235a58c3c25ab83010c327d5932bcf05324b7d6b1185e650798034783ca9d")
|
||||
if !bytes.Equal(hash[:], exp) {
|
||||
if !bytes.Equal(hash, exp) {
|
||||
t.Errorf("expected %x got %x", exp, hash)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user