mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
added tests
This commit is contained in:
parent
ab8ae84f08
commit
0ceb181030
4 changed files with 49 additions and 0 deletions
11
trie/arc.go
11
trie/arc.go
|
|
@ -62,6 +62,17 @@ func newARC(c int) *arc {
|
|||
}
|
||||
}
|
||||
|
||||
func (a *arc) Clear() {
|
||||
a.mutex.Lock()
|
||||
defer a.mutex.Unlock()
|
||||
a.p = 0
|
||||
a.t1 = list.New()
|
||||
a.b1 = list.New()
|
||||
a.t2 = list.New()
|
||||
a.b2 = list.New()
|
||||
a.cache = make(map[string]*entry, a.c)
|
||||
}
|
||||
|
||||
// Put inserts a new key-value pair into the cache.
|
||||
// This optimizes future access to this entry (side effect).
|
||||
func (a *arc) Put(key hashNode, value node) bool {
|
||||
|
|
|
|||
|
|
@ -57,6 +57,12 @@ func (s *TrieEncodingSuite) TestCompactHexDecode(c *checker.C) {
|
|||
c.Assert(res, checker.DeepEquals, exp)
|
||||
}
|
||||
|
||||
func (s *TrieEncodingSuite) TestCompactHexEncode(c *checker.C) {
|
||||
exp := []byte("verb")
|
||||
res := compactHexEncode([]byte{7, 6, 6, 5, 7, 2, 6, 2, 16})
|
||||
c.Assert(res, checker.DeepEquals, exp)
|
||||
}
|
||||
|
||||
func (s *TrieEncodingSuite) TestCompactDecode(c *checker.C) {
|
||||
// odd compact decode
|
||||
exp := []byte{1, 2, 3, 4, 5}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
)
|
||||
|
||||
|
|
@ -33,6 +34,33 @@ func TestProof(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestStoreProof(t *testing.T) {
|
||||
trie, vals := randomTrie(500)
|
||||
root := trie.Hash()
|
||||
mdb, _ := ethdb.NewMemDatabase()
|
||||
for _, kv := range vals {
|
||||
proof := trie.Prove(kv.k)
|
||||
if proof == nil {
|
||||
t.Fatalf("missing key %x while constructing proof", kv.k)
|
||||
}
|
||||
val, err := VerifyProof(root, kv.k, proof)
|
||||
if err != nil {
|
||||
t.Fatalf("VerifyProof error for key %x: %v\nraw proof: %x", kv.k, err, proof)
|
||||
}
|
||||
if !bytes.Equal(val, kv.v) {
|
||||
t.Fatalf("VerifyProof returned wrong value for key %x: got %x, want %x", kv.k, val, kv.v)
|
||||
}
|
||||
StoreProof(mdb, proof)
|
||||
}
|
||||
ClearGlobalCache()
|
||||
mtrie, _ := New(root, mdb)
|
||||
for _, kv := range vals {
|
||||
if !bytes.Equal(mtrie.Get(kv.k), kv.v) {
|
||||
t.Fatalf("Can't retrieve stored proof")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOneElementProof(t *testing.T) {
|
||||
trie := new(Trie)
|
||||
updateString(trie, "k", "v")
|
||||
|
|
|
|||
|
|
@ -46,6 +46,10 @@ var (
|
|||
emptyState = crypto.Sha3Hash(nil)
|
||||
)
|
||||
|
||||
func ClearGlobalCache() {
|
||||
globalCache.Clear()
|
||||
}
|
||||
|
||||
var ErrMissingRoot = errors.New("missing root node")
|
||||
|
||||
// OdrAccess is an interface to on-demand network access layer
|
||||
|
|
|
|||
Loading…
Reference in a new issue