aboutsummaryrefslogtreecommitdiffstats
path: root/trie/trie_test.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-09-24 20:57:49 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-03-06 19:35:03 +0800
commit054412e33528e53f6deae940c870217b614707b9 (patch)
tree7ffc999bb39384e1bfa8c71d80923879fc2e866b /trie/trie_test.go
parent15eee47ebf878b4eff3c2359b9eaa57bba397448 (diff)
downloadgo-tangerine-054412e33528e53f6deae940c870217b614707b9.tar
go-tangerine-054412e33528e53f6deae940c870217b614707b9.tar.gz
go-tangerine-054412e33528e53f6deae940c870217b614707b9.tar.bz2
go-tangerine-054412e33528e53f6deae940c870217b614707b9.tar.lz
go-tangerine-054412e33528e53f6deae940c870217b614707b9.tar.xz
go-tangerine-054412e33528e53f6deae940c870217b614707b9.tar.zst
go-tangerine-054412e33528e53f6deae940c870217b614707b9.zip
all: clean up and proerly abstract database access
Diffstat (limited to 'trie/trie_test.go')
-rw-r--r--trie/trie_test.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/trie/trie_test.go b/trie/trie_test.go
index 4d84aa96c..cf133706f 100644
--- a/trie/trie_test.go
+++ b/trie/trie_test.go
@@ -33,6 +33,8 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
+ "github.com/ethereum/go-ethereum/ethdb/leveldb"
+ "github.com/ethereum/go-ethereum/ethdb/memorydb"
"github.com/ethereum/go-ethereum/rlp"
)
@@ -43,7 +45,7 @@ func init() {
// Used for testing
func newEmpty() *Trie {
- trie, _ := New(common.Hash{}, NewDatabase(ethdb.NewMemDatabase()))
+ trie, _ := New(common.Hash{}, NewDatabase(memorydb.New()))
return trie
}
@@ -67,7 +69,7 @@ func TestNull(t *testing.T) {
}
func TestMissingRoot(t *testing.T) {
- trie, err := New(common.HexToHash("0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"), NewDatabase(ethdb.NewMemDatabase()))
+ trie, err := New(common.HexToHash("0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"), NewDatabase(memorydb.New()))
if trie != nil {
t.Error("New returned non-nil trie for invalid root")
}
@@ -80,7 +82,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 := memorydb.New()
triedb := NewDatabase(diskdb)
trie, _ := New(common.Hash{}, triedb)
@@ -317,13 +319,13 @@ func TestLargeValue(t *testing.T) {
}
type countingDB struct {
- ethdb.Database
+ ethdb.KeyValueStore
gets map[string]int
}
func (db *countingDB) Get(key []byte) ([]byte, error) {
db.gets[string(key)]++
- return db.Database.Get(key)
+ return db.KeyValueStore.Get(key)
}
// TestCacheUnload checks that decoded nodes are unloaded after a
@@ -342,7 +344,7 @@ func TestCacheUnload(t *testing.T) {
// Commit the trie repeatedly and access key1.
// The branch containing it is loaded from DB exactly two times:
// in the 0th and 6th iteration.
- diskdb := &countingDB{Database: trie.db.diskdb, gets: make(map[string]int)}
+ diskdb := &countingDB{KeyValueStore: trie.db.diskdb, gets: make(map[string]int)}
triedb := NewDatabase(diskdb)
trie, _ = New(root, triedb)
trie.SetCacheLimit(5)
@@ -412,7 +414,7 @@ func (randTest) Generate(r *rand.Rand, size int) reflect.Value {
}
func runRandTest(rt randTest) bool {
- triedb := NewDatabase(ethdb.NewMemDatabase())
+ triedb := NewDatabase(memorydb.New())
tr, _ := New(common.Hash{}, triedb)
values := make(map[string]string) // tracks content of the trie
@@ -540,7 +542,7 @@ func benchGet(b *testing.B, commit bool) {
b.StopTimer()
if commit {
- ldb := trie.db.diskdb.(*ethdb.LDBDatabase)
+ ldb := trie.db.diskdb.(*leveldb.LevelDBDatabase)
ldb.Close()
os.RemoveAll(ldb.Path())
}
@@ -596,7 +598,7 @@ func tempDB() (string, *Database) {
if err != nil {
panic(fmt.Sprintf("can't create temporary directory: %v", err))
}
- diskdb, err := ethdb.NewLDBDatabase(dir, 256, 0)
+ diskdb, err := leveldb.New(dir, 256, 0, "")
if err != nil {
panic(fmt.Sprintf("can't create temporary database: %v", err))
}