aboutsummaryrefslogtreecommitdiffstats
path: root/core/state
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 /core/state
parent5dbd8b42a90779bd4269012c1336679fd4ca9824 (diff)
downloaddexon-7beccb29becf439df7bf4c033a94c019ad25bead.tar.gz
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 'core/state')
-rw-r--r--core/state/managed_state_test.go3
-rw-r--r--core/state/state_test.go5
-rw-r--r--core/state/statedb_test.go15
-rw-r--r--core/state/sync_test.go16
4 files changed, 16 insertions, 23 deletions
diff --git a/core/state/managed_state_test.go b/core/state/managed_state_test.go
index 1cfdd3a89..3d9c4e867 100644
--- a/core/state/managed_state_test.go
+++ b/core/state/managed_state_test.go
@@ -26,8 +26,7 @@ import (
var addr = common.BytesToAddress([]byte("test"))
func create() (*ManagedState, *account) {
- db, _ := ethdb.NewMemDatabase()
- statedb, _ := New(common.Hash{}, NewDatabase(db))
+ statedb, _ := New(common.Hash{}, NewDatabase(ethdb.NewMemDatabase()))
ms := ManageState(statedb)
ms.StateDB.SetNonce(addr, 100)
ms.accounts[addr] = newAccount(ms.StateDB.getStateObject(addr))
diff --git a/core/state/state_test.go b/core/state/state_test.go
index 6d42d63d8..12778f6f1 100644
--- a/core/state/state_test.go
+++ b/core/state/state_test.go
@@ -87,7 +87,7 @@ func (s *StateSuite) TestDump(c *checker.C) {
}
func (s *StateSuite) SetUpTest(c *checker.C) {
- s.db, _ = ethdb.NewMemDatabase()
+ s.db = ethdb.NewMemDatabase()
s.state, _ = New(common.Hash{}, NewDatabase(s.db))
}
@@ -133,8 +133,7 @@ func (s *StateSuite) TestSnapshotEmpty(c *checker.C) {
// use testing instead of checker because checker does not support
// printing/logging in tests (-check.vv does not work)
func TestSnapshot2(t *testing.T) {
- db, _ := ethdb.NewMemDatabase()
- state, _ := New(common.Hash{}, NewDatabase(db))
+ state, _ := New(common.Hash{}, NewDatabase(ethdb.NewMemDatabase()))
stateobjaddr0 := toAddr([]byte("so0"))
stateobjaddr1 := toAddr([]byte("so1"))
diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go
index 420ca745c..e2b349de8 100644
--- a/core/state/statedb_test.go
+++ b/core/state/statedb_test.go
@@ -39,7 +39,7 @@ import (
// actually committing the state.
func TestUpdateLeaks(t *testing.T) {
// Create an empty state database
- db, _ := ethdb.NewMemDatabase()
+ db := ethdb.NewMemDatabase()
state, _ := New(common.Hash{}, NewDatabase(db))
// Update it with some accounts
@@ -66,8 +66,8 @@ func TestUpdateLeaks(t *testing.T) {
// only the one right before the commit.
func TestIntermediateLeaks(t *testing.T) {
// Create two state databases, one transitioning to the final state, the other final from the beginning
- transDb, _ := ethdb.NewMemDatabase()
- finalDb, _ := ethdb.NewMemDatabase()
+ transDb := ethdb.NewMemDatabase()
+ finalDb := ethdb.NewMemDatabase()
transState, _ := New(common.Hash{}, NewDatabase(transDb))
finalState, _ := New(common.Hash{}, NewDatabase(finalDb))
@@ -122,8 +122,7 @@ func TestIntermediateLeaks(t *testing.T) {
// https://github.com/ethereum/go-ethereum/pull/15549.
func TestCopy(t *testing.T) {
// Create a random state test to copy and modify "independently"
- db, _ := ethdb.NewMemDatabase()
- orig, _ := New(common.Hash{}, NewDatabase(db))
+ orig, _ := New(common.Hash{}, NewDatabase(ethdb.NewMemDatabase()))
for i := byte(0); i < 255; i++ {
obj := orig.GetOrNewStateObject(common.BytesToAddress([]byte{i}))
@@ -334,8 +333,7 @@ func (test *snapshotTest) String() string {
func (test *snapshotTest) run() bool {
// Run all actions and create snapshots.
var (
- db, _ = ethdb.NewMemDatabase()
- state, _ = New(common.Hash{}, NewDatabase(db))
+ state, _ = New(common.Hash{}, NewDatabase(ethdb.NewMemDatabase()))
snapshotRevs = make([]int, len(test.snapshots))
sindex = 0
)
@@ -426,8 +424,7 @@ func (s *StateSuite) TestTouchDelete(c *check.C) {
// TestCopyOfCopy tests that modified objects are carried over to the copy, and the copy of the copy.
// See https://github.com/ethereum/go-ethereum/pull/15225#issuecomment-380191512
func TestCopyOfCopy(t *testing.T) {
- db, _ := ethdb.NewMemDatabase()
- sdb, _ := New(common.Hash{}, NewDatabase(db))
+ sdb, _ := New(common.Hash{}, NewDatabase(ethdb.NewMemDatabase()))
addr := common.HexToAddress("aaaa")
sdb.SetBalance(addr, big.NewInt(42))
diff --git a/core/state/sync_test.go b/core/state/sync_test.go
index 8f14a44e7..317740160 100644
--- a/core/state/sync_test.go
+++ b/core/state/sync_test.go
@@ -38,8 +38,7 @@ type testAccount struct {
// makeTestState create a sample test state to test node-wise reconstruction.
func makeTestState() (Database, common.Hash, []*testAccount) {
// Create an empty state
- diskdb, _ := ethdb.NewMemDatabase()
- db := NewDatabase(diskdb)
+ db := NewDatabase(ethdb.NewMemDatabase())
state, _ := New(common.Hash{}, db)
// Fill it with some arbitrary data
@@ -125,8 +124,7 @@ func checkStateConsistency(db ethdb.Database, root common.Hash) error {
// Tests that an empty state is not scheduled for syncing.
func TestEmptyStateSync(t *testing.T) {
empty := common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
- db, _ := ethdb.NewMemDatabase()
- if req := NewStateSync(empty, db).Missing(1); len(req) != 0 {
+ if req := NewStateSync(empty, ethdb.NewMemDatabase()).Missing(1); len(req) != 0 {
t.Errorf("content requested for empty state: %v", req)
}
}
@@ -141,7 +139,7 @@ func testIterativeStateSync(t *testing.T, batch int) {
srcDb, srcRoot, srcAccounts := makeTestState()
// Create a destination state and sync with the scheduler
- dstDb, _ := ethdb.NewMemDatabase()
+ dstDb := ethdb.NewMemDatabase()
sched := NewStateSync(srcRoot, dstDb)
queue := append([]common.Hash{}, sched.Missing(batch)...)
@@ -173,7 +171,7 @@ func TestIterativeDelayedStateSync(t *testing.T) {
srcDb, srcRoot, srcAccounts := makeTestState()
// Create a destination state and sync with the scheduler
- dstDb, _ := ethdb.NewMemDatabase()
+ dstDb := ethdb.NewMemDatabase()
sched := NewStateSync(srcRoot, dstDb)
queue := append([]common.Hash{}, sched.Missing(0)...)
@@ -210,7 +208,7 @@ func testIterativeRandomStateSync(t *testing.T, batch int) {
srcDb, srcRoot, srcAccounts := makeTestState()
// Create a destination state and sync with the scheduler
- dstDb, _ := ethdb.NewMemDatabase()
+ dstDb := ethdb.NewMemDatabase()
sched := NewStateSync(srcRoot, dstDb)
queue := make(map[common.Hash]struct{})
@@ -250,7 +248,7 @@ func TestIterativeRandomDelayedStateSync(t *testing.T) {
srcDb, srcRoot, srcAccounts := makeTestState()
// Create a destination state and sync with the scheduler
- dstDb, _ := ethdb.NewMemDatabase()
+ dstDb := ethdb.NewMemDatabase()
sched := NewStateSync(srcRoot, dstDb)
queue := make(map[common.Hash]struct{})
@@ -297,7 +295,7 @@ func TestIncompleteStateSync(t *testing.T) {
checkTrieConsistency(srcDb.TrieDB().DiskDB().(ethdb.Database), srcRoot)
// Create a destination state and sync with the scheduler
- dstDb, _ := ethdb.NewMemDatabase()
+ dstDb := ethdb.NewMemDatabase()
sched := NewStateSync(srcRoot, dstDb)
added := []common.Hash{}