all: clean up and proerly abstract database access
This commit is contained in:
@ -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))
|
||||
}
|
||||
|
Reference in New Issue
Block a user