aboutsummaryrefslogtreecommitdiffstats
path: root/trie
diff options
context:
space:
mode:
authorgary rong <garyrong0905@gmail.com>2018-05-09 20:24:25 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-05-09 20:24:25 +0800
commit7beccb29becf439df7bf4c033a94c019ad25bead (patch)
tree5d8581c15f3f110c765c6383e0c4c7724418d6f0 /trie
parent5dbd8b42a90779bd4269012c1336679fd4ca9824 (diff)
downloaddexon-7beccb29becf439df7bf4c033a94c019ad25bead.tar
dexon-7beccb29becf439df7bf4c033a94c019ad25bead.tar.gz
dexon-7beccb29becf439df7bf4c033a94c019ad25bead.tar.bz2
dexon-7beccb29becf439df7bf4c033a94c019ad25bead.tar.lz
dexon-7beccb29becf439df7bf4c033a94c019ad25bead.tar.xz
dexon-7beccb29becf439df7bf4c033a94c019ad25bead.tar.zst
dexon-7beccb29becf439df7bf4c033a94c019ad25bead.zip
all: get rid of error when creating memory database (#16716)
* all: get rid of error when create mdb * core: clean up variables definition * all: inline mdb definition
Diffstat (limited to 'trie')
-rw-r--r--trie/iterator_test.go4
-rw-r--r--trie/proof_test.go10
-rw-r--r--trie/secure_trie_test.go8
-rw-r--r--trie/sync_test.go30
-rw-r--r--trie/trie_test.go11
5 files changed, 25 insertions, 38 deletions
diff --git a/trie/iterator_test.go b/trie/iterator_test.go
index dce1c78b5..2a510b1c2 100644
--- a/trie/iterator_test.go
+++ b/trie/iterator_test.go
@@ -289,7 +289,7 @@ func TestIteratorContinueAfterErrorDisk(t *testing.T) { testIteratorContinueA
func TestIteratorContinueAfterErrorMemonly(t *testing.T) { testIteratorContinueAfterError(t, true) }
func testIteratorContinueAfterError(t *testing.T, memonly bool) {
- diskdb, _ := ethdb.NewMemDatabase()
+ diskdb := ethdb.NewMemDatabase()
triedb := NewDatabase(diskdb)
tr, _ := New(common.Hash{}, triedb)
@@ -376,7 +376,7 @@ func TestIteratorContinueAfterSeekErrorMemonly(t *testing.T) {
func testIteratorContinueAfterSeekError(t *testing.T, memonly bool) {
// Commit test trie to db, then remove the node containing "bars".
- diskdb, _ := ethdb.NewMemDatabase()
+ diskdb := ethdb.NewMemDatabase()
triedb := NewDatabase(diskdb)
ctr, _ := New(common.Hash{}, triedb)
diff --git a/trie/proof_test.go b/trie/proof_test.go
index fff313d7f..a3537787c 100644
--- a/trie/proof_test.go
+++ b/trie/proof_test.go
@@ -36,7 +36,7 @@ func TestProof(t *testing.T) {
trie, vals := randomTrie(500)
root := trie.Hash()
for _, kv := range vals {
- proofs, _ := ethdb.NewMemDatabase()
+ proofs := ethdb.NewMemDatabase()
if trie.Prove(kv.k, 0, proofs) != nil {
t.Fatalf("missing key %x while constructing proof", kv.k)
}
@@ -53,7 +53,7 @@ func TestProof(t *testing.T) {
func TestOneElementProof(t *testing.T) {
trie := new(Trie)
updateString(trie, "k", "v")
- proofs, _ := ethdb.NewMemDatabase()
+ proofs := ethdb.NewMemDatabase()
trie.Prove([]byte("k"), 0, proofs)
if len(proofs.Keys()) != 1 {
t.Error("proof should have one element")
@@ -71,7 +71,7 @@ func TestVerifyBadProof(t *testing.T) {
trie, vals := randomTrie(800)
root := trie.Hash()
for _, kv := range vals {
- proofs, _ := ethdb.NewMemDatabase()
+ proofs := ethdb.NewMemDatabase()
trie.Prove(kv.k, 0, proofs)
if len(proofs.Keys()) == 0 {
t.Fatal("zero length proof")
@@ -109,7 +109,7 @@ func BenchmarkProve(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
kv := vals[keys[i%len(keys)]]
- proofs, _ := ethdb.NewMemDatabase()
+ proofs := ethdb.NewMemDatabase()
if trie.Prove(kv.k, 0, proofs); len(proofs.Keys()) == 0 {
b.Fatalf("zero length proof for %x", kv.k)
}
@@ -123,7 +123,7 @@ func BenchmarkVerifyProof(b *testing.B) {
var proofs []*ethdb.MemDatabase
for k := range vals {
keys = append(keys, k)
- proof, _ := ethdb.NewMemDatabase()
+ proof := ethdb.NewMemDatabase()
trie.Prove([]byte(k), 0, proof)
proofs = append(proofs, proof)
}
diff --git a/trie/secure_trie_test.go b/trie/secure_trie_test.go
index aedf5a1cd..d16d99968 100644
--- a/trie/secure_trie_test.go
+++ b/trie/secure_trie_test.go
@@ -28,18 +28,14 @@ import (
)
func newEmptySecure() *SecureTrie {
- diskdb, _ := ethdb.NewMemDatabase()
- triedb := NewDatabase(diskdb)
-
- trie, _ := NewSecure(common.Hash{}, triedb, 0)
+ trie, _ := NewSecure(common.Hash{}, NewDatabase(ethdb.NewMemDatabase()), 0)
return trie
}
// makeTestSecureTrie creates a large enough secure trie for testing.
func makeTestSecureTrie() (*Database, *SecureTrie, map[string][]byte) {
// Create an empty trie
- diskdb, _ := ethdb.NewMemDatabase()
- triedb := NewDatabase(diskdb)
+ triedb := NewDatabase(ethdb.NewMemDatabase())
trie, _ := NewSecure(common.Hash{}, triedb, 0)
diff --git a/trie/sync_test.go b/trie/sync_test.go
index 4a720612b..142a6f5b1 100644
--- a/trie/sync_test.go
+++ b/trie/sync_test.go
@@ -27,8 +27,7 @@ import (
// makeTestTrie create a sample test trie to test node-wise reconstruction.
func makeTestTrie() (*Database, *Trie, map[string][]byte) {
// Create an empty trie
- diskdb, _ := ethdb.NewMemDatabase()
- triedb := NewDatabase(diskdb)
+ triedb := NewDatabase(ethdb.NewMemDatabase())
trie, _ := New(common.Hash{}, triedb)
// Fill it with some arbitrary data
@@ -89,18 +88,13 @@ func checkTrieConsistency(db *Database, root common.Hash) error {
// Tests that an empty trie is not scheduled for syncing.
func TestEmptyTrieSync(t *testing.T) {
- diskdbA, _ := ethdb.NewMemDatabase()
- triedbA := NewDatabase(diskdbA)
-
- diskdbB, _ := ethdb.NewMemDatabase()
- triedbB := NewDatabase(diskdbB)
-
- emptyA, _ := New(common.Hash{}, triedbA)
- emptyB, _ := New(emptyRoot, triedbB)
+ dbA := NewDatabase(ethdb.NewMemDatabase())
+ dbB := NewDatabase(ethdb.NewMemDatabase())
+ emptyA, _ := New(common.Hash{}, dbA)
+ emptyB, _ := New(emptyRoot, dbB)
for i, trie := range []*Trie{emptyA, emptyB} {
- diskdb, _ := ethdb.NewMemDatabase()
- if req := NewTrieSync(trie.Hash(), diskdb, nil).Missing(1); len(req) != 0 {
+ if req := NewTrieSync(trie.Hash(), ethdb.NewMemDatabase(), nil).Missing(1); len(req) != 0 {
t.Errorf("test %d: content requested for empty trie: %v", i, req)
}
}
@@ -116,7 +110,7 @@ func testIterativeTrieSync(t *testing.T, batch int) {
srcDb, srcTrie, srcData := makeTestTrie()
// Create a destination trie and sync with the scheduler
- diskdb, _ := ethdb.NewMemDatabase()
+ diskdb := ethdb.NewMemDatabase()
triedb := NewDatabase(diskdb)
sched := NewTrieSync(srcTrie.Hash(), diskdb, nil)
@@ -149,7 +143,7 @@ func TestIterativeDelayedTrieSync(t *testing.T) {
srcDb, srcTrie, srcData := makeTestTrie()
// Create a destination trie and sync with the scheduler
- diskdb, _ := ethdb.NewMemDatabase()
+ diskdb := ethdb.NewMemDatabase()
triedb := NewDatabase(diskdb)
sched := NewTrieSync(srcTrie.Hash(), diskdb, nil)
@@ -187,7 +181,7 @@ func testIterativeRandomTrieSync(t *testing.T, batch int) {
srcDb, srcTrie, srcData := makeTestTrie()
// Create a destination trie and sync with the scheduler
- diskdb, _ := ethdb.NewMemDatabase()
+ diskdb := ethdb.NewMemDatabase()
triedb := NewDatabase(diskdb)
sched := NewTrieSync(srcTrie.Hash(), diskdb, nil)
@@ -228,7 +222,7 @@ func TestIterativeRandomDelayedTrieSync(t *testing.T) {
srcDb, srcTrie, srcData := makeTestTrie()
// Create a destination trie and sync with the scheduler
- diskdb, _ := ethdb.NewMemDatabase()
+ diskdb := ethdb.NewMemDatabase()
triedb := NewDatabase(diskdb)
sched := NewTrieSync(srcTrie.Hash(), diskdb, nil)
@@ -275,7 +269,7 @@ func TestDuplicateAvoidanceTrieSync(t *testing.T) {
srcDb, srcTrie, srcData := makeTestTrie()
// Create a destination trie and sync with the scheduler
- diskdb, _ := ethdb.NewMemDatabase()
+ diskdb := ethdb.NewMemDatabase()
triedb := NewDatabase(diskdb)
sched := NewTrieSync(srcTrie.Hash(), diskdb, nil)
@@ -315,7 +309,7 @@ func TestIncompleteTrieSync(t *testing.T) {
srcDb, srcTrie, _ := makeTestTrie()
// Create a destination trie and sync with the scheduler
- diskdb, _ := ethdb.NewMemDatabase()
+ diskdb := ethdb.NewMemDatabase()
triedb := NewDatabase(diskdb)
sched := NewTrieSync(srcTrie.Hash(), diskdb, nil)
diff --git a/trie/trie_test.go b/trie/trie_test.go
index 997222628..f8e5fd12a 100644
--- a/trie/trie_test.go
+++ b/trie/trie_test.go
@@ -43,8 +43,7 @@ func init() {
// Used for testing
func newEmpty() *Trie {
- diskdb, _ := ethdb.NewMemDatabase()
- trie, _ := New(common.Hash{}, NewDatabase(diskdb))
+ trie, _ := New(common.Hash{}, NewDatabase(ethdb.NewMemDatabase()))
return trie
}
@@ -68,8 +67,7 @@ func TestNull(t *testing.T) {
}
func TestMissingRoot(t *testing.T) {
- diskdb, _ := ethdb.NewMemDatabase()
- trie, err := New(common.HexToHash("0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"), NewDatabase(diskdb))
+ trie, err := New(common.HexToHash("0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"), NewDatabase(ethdb.NewMemDatabase()))
if trie != nil {
t.Error("New returned non-nil trie for invalid root")
}
@@ -82,7 +80,7 @@ func TestMissingNodeDisk(t *testing.T) { testMissingNode(t, false) }
func TestMissingNodeMemonly(t *testing.T) { testMissingNode(t, true) }
func testMissingNode(t *testing.T, memonly bool) {
- diskdb, _ := ethdb.NewMemDatabase()
+ diskdb := ethdb.NewMemDatabase()
triedb := NewDatabase(diskdb)
trie, _ := New(common.Hash{}, triedb)
@@ -413,8 +411,7 @@ func (randTest) Generate(r *rand.Rand, size int) reflect.Value {
}
func runRandTest(rt randTest) bool {
- diskdb, _ := ethdb.NewMemDatabase()
- triedb := NewDatabase(diskdb)
+ triedb := NewDatabase(ethdb.NewMemDatabase())
tr, _ := New(common.Hash{}, triedb)
values := make(map[string]string) // tracks content of the trie