Skip to content

Commit

Permalink
all: inline mdb definition
Browse files Browse the repository at this point in the history
  • Loading branch information
rjl493456442 committed May 9, 2018
1 parent 76e01aa commit a080dcf
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 104 deletions.
3 changes: 1 addition & 2 deletions cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ func runCmd(ctx *cli.Context) error {
chainConfig = gen.Config
blockNumber = gen.Number
} else {
db := ethdb.NewMemDatabase()
statedb, _ = state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ = state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
}
if ctx.GlobalString(SenderFlag.Name) != "" {
sender = common.HexToAddress(ctx.GlobalString(SenderFlag.Name))
Expand Down
5 changes: 1 addition & 4 deletions core/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,11 @@ func (tm *TestManager) Db() ethdb.Database {
}

func NewTestManager() *TestManager {
db := ethdb.NewMemDatabase()

testManager := &TestManager{}
testManager.eventMux = new(event.TypeMux)
testManager.db = db
testManager.db = ethdb.NewMemDatabase()
// testManager.txPool = NewTxPool(testManager)
// testManager.blockChain = NewBlockChain(testManager)
// testManager.stateManager = NewStateManager(testManager)

return testManager
}
3 changes: 1 addition & 2 deletions core/state/managed_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions core/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
9 changes: 3 additions & 6 deletions core/state/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}))
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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))

Expand Down
6 changes: 2 additions & 4 deletions core/state/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
54 changes: 18 additions & 36 deletions core/tx_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ func pricedTransaction(nonce uint64, gaslimit uint64, gasprice *big.Int, key *ec
}

func setupTxPool() (*TxPool, *ecdsa.PrivateKey) {
diskdb := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(diskdb))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}

key, _ := crypto.GenerateKey()
Expand Down Expand Up @@ -158,8 +157,7 @@ func (c *testChain) State() (*state.StateDB, error) {
// a state change between those fetches.
stdb := c.statedb
if *c.trigger {
db := ethdb.NewMemDatabase()
c.statedb, _ = state.New(common.Hash{}, state.NewDatabase(db))
c.statedb, _ = state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
// simulate that the new head block included tx0 and tx1
c.statedb.SetNonce(c.address, 2)
c.statedb.SetBalance(c.address, new(big.Int).SetUint64(params.Ether))
Expand All @@ -175,10 +173,9 @@ func TestStateChangeDuringTransactionPoolReset(t *testing.T) {
t.Parallel()

var (
db = ethdb.NewMemDatabase()
key, _ = crypto.GenerateKey()
address = crypto.PubkeyToAddress(key.PublicKey)
statedb, _ = state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ = state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
trigger = false
)

Expand Down Expand Up @@ -332,8 +329,7 @@ func TestTransactionChainFork(t *testing.T) {

addr := crypto.PubkeyToAddress(key.PublicKey)
resetState := func() {
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
statedb.AddBalance(addr, big.NewInt(100000000000000))

pool.chain = &testBlockChain{statedb, 1000000, new(event.Feed)}
Expand Down Expand Up @@ -362,8 +358,7 @@ func TestTransactionDoubleNonce(t *testing.T) {

addr := crypto.PubkeyToAddress(key.PublicKey)
resetState := func() {
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
statedb.AddBalance(addr, big.NewInt(100000000000000))

pool.chain = &testBlockChain{statedb, 1000000, new(event.Feed)}
Expand Down Expand Up @@ -553,8 +548,7 @@ func TestTransactionPostponing(t *testing.T) {
t.Parallel()

// Create the pool to test the postponing with
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}

pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
Expand Down Expand Up @@ -769,8 +763,7 @@ func testTransactionQueueGlobalLimiting(t *testing.T, nolocals bool) {
t.Parallel()

// Create the pool to test the limit enforcement with
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}

config := testTxPoolConfig
Expand Down Expand Up @@ -858,8 +851,7 @@ func testTransactionQueueTimeLimiting(t *testing.T, nolocals bool) {
evictionInterval = time.Second

// Create the pool to test the non-expiration enforcement
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}

config := testTxPoolConfig
Expand Down Expand Up @@ -1013,8 +1005,7 @@ func TestTransactionPendingGlobalLimiting(t *testing.T) {
t.Parallel()

// Create the pool to test the limit enforcement with
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}

config := testTxPoolConfig
Expand Down Expand Up @@ -1060,8 +1051,7 @@ func TestTransactionCapClearsFromAll(t *testing.T) {
t.Parallel()

// Create the pool to test the limit enforcement with
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}

config := testTxPoolConfig
Expand Down Expand Up @@ -1095,8 +1085,7 @@ func TestTransactionPendingMinimumAllowance(t *testing.T) {
t.Parallel()

// Create the pool to test the limit enforcement with
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}

config := testTxPoolConfig
Expand Down Expand Up @@ -1144,8 +1133,7 @@ func TestTransactionPoolRepricing(t *testing.T) {
t.Parallel()

// Create the pool to test the pricing enforcement with
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}

pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
Expand Down Expand Up @@ -1266,8 +1254,7 @@ func TestTransactionPoolRepricingKeepsLocals(t *testing.T) {
t.Parallel()

// Create the pool to test the pricing enforcement with
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}

pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
Expand Down Expand Up @@ -1329,8 +1316,7 @@ func TestTransactionPoolUnderpricing(t *testing.T) {
t.Parallel()

// Create the pool to test the pricing enforcement with
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}

config := testTxPoolConfig
Expand Down Expand Up @@ -1436,8 +1422,7 @@ func TestTransactionPoolStableUnderpricing(t *testing.T) {
t.Parallel()

// Create the pool to test the pricing enforcement with
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}

config := testTxPoolConfig
Expand Down Expand Up @@ -1503,8 +1488,7 @@ func TestTransactionReplacement(t *testing.T) {
t.Parallel()

// Create the pool to test the pricing enforcement with
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}

pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
Expand Down Expand Up @@ -1598,8 +1582,7 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {
os.Remove(journal)

// Create the original pool to inject transaction into the journal
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}

config := testTxPoolConfig
Expand Down Expand Up @@ -1697,8 +1680,7 @@ func TestTransactionStatusCheck(t *testing.T) {
t.Parallel()

// Create the pool to test the status retrievals with
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}

pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
Expand Down
6 changes: 2 additions & 4 deletions core/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
setDefaults(cfg)

if cfg.State == nil {
db := ethdb.NewMemDatabase()
cfg.State, _ = state.New(common.Hash{}, state.NewDatabase(db))
cfg.State, _ = state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
}
var (
address = common.BytesToAddress([]byte("contract"))
Expand Down Expand Up @@ -130,8 +129,7 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) {
setDefaults(cfg)

if cfg.State == nil {
db := ethdb.NewMemDatabase()
cfg.State, _ = state.New(common.Hash{}, state.NewDatabase(db))
cfg.State, _ = state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
}
var (
vmenv = NewEnv(cfg)
Expand Down
3 changes: 1 addition & 2 deletions core/vm/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ func TestExecute(t *testing.T) {
}

func TestCall(t *testing.T) {
db := ethdb.NewMemDatabase()
state, _ := state.New(common.Hash{}, state.NewDatabase(db))
state, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
address := common.HexToAddress("0x0a")
state.SetCode(address, []byte{
byte(vm.PUSH1), 10,
Expand Down
3 changes: 1 addition & 2 deletions eth/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ var dumper = spew.ConfigState{Indent: " "}
func TestStorageRangeAt(t *testing.T) {
// Create a state where account 0x010000... has a few storage entries.
var (
db = ethdb.NewMemDatabase()
state, _ = state.New(common.Hash{}, state.NewDatabase(db))
state, _ = state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
addr = common.Address{0x01}
keys = []common.Hash{ // hashes of Keys of storage
common.HexToHash("340dd630ad21bf010b4e676dbfa9ba9a02175262d1fa356232cfde6cb5b47ef2"),
Expand Down
3 changes: 1 addition & 2 deletions eth/tracers/tracers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ func TestCallTracer(t *testing.T) {
GasLimit: uint64(test.Context.GasLimit),
GasPrice: tx.GasPrice(),
}
db := ethdb.NewMemDatabase()
statedb := tests.MakePreState(db, test.Genesis.Alloc)
statedb := tests.MakePreState(ethdb.NewMemDatabase(), test.Genesis.Alloc)

// Create the tracer, the EVM environment and run it
tracer, err := New("callTracer")
Expand Down
6 changes: 2 additions & 4 deletions ethdb/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ func TestLDB_PutGet(t *testing.T) {
}

func TestMemoryDB_PutGet(t *testing.T) {
db := ethdb.NewMemDatabase()
testPutGet(db, t)
testPutGet(ethdb.NewMemDatabase(), t)
}

func testPutGet(db ethdb.Database, t *testing.T) {
Expand Down Expand Up @@ -131,8 +130,7 @@ func TestLDB_ParallelPutGet(t *testing.T) {
}

func TestMemoryDB_ParallelPutGet(t *testing.T) {
db := ethdb.NewMemDatabase()
testParallelPutGet(db, t)
testParallelPutGet(ethdb.NewMemDatabase(), t)
}

func testParallelPutGet(db ethdb.Database, t *testing.T) {
Expand Down
9 changes: 3 additions & 6 deletions les/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ func TestGetBlockHeadersLes1(t *testing.T) { testGetBlockHeaders(t, 1) }
func TestGetBlockHeadersLes2(t *testing.T) { testGetBlockHeaders(t, 2) }

func testGetBlockHeaders(t *testing.T, protocol int) {
db := ethdb.NewMemDatabase()
pm := newTestProtocolManagerMust(t, false, downloader.MaxHashFetch+15, nil, nil, nil, db)
pm := newTestProtocolManagerMust(t, false, downloader.MaxHashFetch+15, nil, nil, nil, ethdb.NewMemDatabase())
bc := pm.blockchain.(*core.BlockChain)
peer, _ := newTestPeer(t, "peer", protocol, pm, true)
defer peer.close()
Expand Down Expand Up @@ -181,8 +180,7 @@ func TestGetBlockBodiesLes1(t *testing.T) { testGetBlockBodies(t, 1) }
func TestGetBlockBodiesLes2(t *testing.T) { testGetBlockBodies(t, 2) }

func testGetBlockBodies(t *testing.T, protocol int) {
db := ethdb.NewMemDatabase()
pm := newTestProtocolManagerMust(t, false, downloader.MaxBlockFetch+15, nil, nil, nil, db)
pm := newTestProtocolManagerMust(t, false, downloader.MaxBlockFetch+15, nil, nil, nil, ethdb.NewMemDatabase())
bc := pm.blockchain.(*core.BlockChain)
peer, _ := newTestPeer(t, "peer", protocol, pm, true)
defer peer.close()
Expand Down Expand Up @@ -259,8 +257,7 @@ func TestGetCodeLes2(t *testing.T) { testGetCode(t, 2) }

func testGetCode(t *testing.T, protocol int) {
// Assemble the test environment
db := ethdb.NewMemDatabase()
pm := newTestProtocolManagerMust(t, false, 4, testChainGen, nil, nil, db)
pm := newTestProtocolManagerMust(t, false, 4, testChainGen, nil, nil, ethdb.NewMemDatabase())
bc := pm.blockchain.(*core.BlockChain)
peer, _ := newTestPeer(t, "peer", protocol, pm, true)
defer peer.close()
Expand Down
3 changes: 1 addition & 2 deletions tests/state_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateD
return nil, UnsupportedForkError{subtest.Fork}
}
block := t.genesis(config).ToBlock(nil)
db := ethdb.NewMemDatabase()
statedb := MakePreState(db, t.json.Pre)
statedb := MakePreState(ethdb.NewMemDatabase(), t.json.Pre)

post := t.json.Post[subtest.Fork][subtest.Index]
msg, err := t.json.Tx.toMessage(post)
Expand Down
3 changes: 1 addition & 2 deletions tests/vm_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ type vmExecMarshaling struct {
}

func (t *VMTest) Run(vmconfig vm.Config) error {
db := ethdb.NewMemDatabase()
statedb := MakePreState(db, t.json.Pre)
statedb := MakePreState(ethdb.NewMemDatabase(), t.json.Pre)
ret, gasRemaining, err := t.exec(statedb, vmconfig)

if t.json.GasRemaining == nil {
Expand Down
Loading

0 comments on commit a080dcf

Please sign in to comment.