From 42f00e390e3d6419016eabd97f008bf4b1f6f9c7 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Wed, 17 Oct 2018 15:24:51 +0200 Subject: [PATCH] core/vm, eth/tracers: update tests to be nicer --- core/vm/logger_test.go | 35 ++++------------------------------- eth/tracers/tracer_test.go | 35 +++++------------------------------ 2 files changed, 9 insertions(+), 61 deletions(-) diff --git a/core/vm/logger_test.go b/core/vm/logger_test.go index 77df71de34..cba7c7a0ef 100644 --- a/core/vm/logger_test.go +++ b/core/vm/logger_test.go @@ -21,7 +21,7 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/params" ) @@ -43,39 +43,14 @@ func (d *dummyContractRef) SetNonce(uint64) {} func (d *dummyContractRef) Balance() *big.Int { return new(big.Int) } type dummyStatedb struct { + state.StateDB } -func (dummyStatedb) CreateAccount(common.Address) { panic("implement me") } -func (dummyStatedb) SubBalance(common.Address, *big.Int) { panic("implement me") } -func (dummyStatedb) AddBalance(common.Address, *big.Int) { panic("implement me") } -func (dummyStatedb) GetBalance(common.Address) *big.Int { panic("implement me") } -func (dummyStatedb) GetNonce(common.Address) uint64 { panic("implement me") } -func (dummyStatedb) SetNonce(common.Address, uint64) { panic("implement me") } -func (dummyStatedb) GetCodeHash(common.Address) common.Hash { panic("implement me") } -func (dummyStatedb) GetCode(common.Address) []byte { panic("implement me") } -func (dummyStatedb) SetCode(common.Address, []byte) { panic("implement me") } -func (dummyStatedb) GetCodeSize(common.Address) int { panic("implement me") } -func (dummyStatedb) AddRefund(uint64) { panic("implement me") } -func (dummyStatedb) SubRefund(uint64) { panic("implement me") } -func (dummyStatedb) GetRefund() uint64 { return 1337 } -func (dummyStatedb) GetCommittedState(common.Address, common.Hash) common.Hash { panic("implement me") } -func (dummyStatedb) GetState(common.Address, common.Hash) common.Hash { panic("implement me") } -func (dummyStatedb) SetState(common.Address, common.Hash, common.Hash) { panic("implement me") } -func (dummyStatedb) Suicide(common.Address) bool { panic("implement me") } -func (dummyStatedb) HasSuicided(common.Address) bool { panic("implement me") } -func (dummyStatedb) Exist(common.Address) bool { panic("implement me") } -func (dummyStatedb) Empty(common.Address) bool { panic("implement me") } -func (dummyStatedb) RevertToSnapshot(int) { panic("implement me") } -func (dummyStatedb) Snapshot() int { panic("implement me") } -func (dummyStatedb) AddLog(*types.Log) { panic("implement me") } -func (dummyStatedb) AddPreimage(common.Hash, []byte) { panic("implement me") } -func (dummyStatedb) ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) { - panic("implement me") -} +func (dummyStatedb) GetRefund() uint64 { return 1337 } func TestStoreCapture(t *testing.T) { var ( - env = NewEVM(Context{}, dummyStatedb{}, params.TestChainConfig, Config{}) + env = NewEVM(Context{}, &dummyStatedb{}, params.TestChainConfig, Config{}) logger = NewStructLogger(nil) mem = NewMemory() stack = newstack() @@ -83,9 +58,7 @@ func TestStoreCapture(t *testing.T) { ) stack.push(big.NewInt(1)) stack.push(big.NewInt(0)) - var index common.Hash - logger.CaptureState(env, 0, SSTORE, 0, 0, mem, stack, contract, 0, nil) if len(logger.changedValues[contract.Address()]) == 0 { t.Fatalf("expected exactly 1 changed value on address %x, got %d", contract.Address(), len(logger.changedValues[contract.Address()])) diff --git a/eth/tracers/tracer_test.go b/eth/tracers/tracer_test.go index 07e9d41700..52f29c83fc 100644 --- a/eth/tracers/tracer_test.go +++ b/eth/tracers/tracer_test.go @@ -25,7 +25,7 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/params" ) @@ -45,38 +45,13 @@ func (account) SetCode(common.Hash, []byte) {} func (account) ForEachStorage(cb func(key, value common.Hash) bool) {} type dummyStatedb struct { + state.StateDB } -func (dummyStatedb) CreateAccount(common.Address) { panic("implement me") } -func (dummyStatedb) SubBalance(common.Address, *big.Int) { panic("implement me") } -func (dummyStatedb) AddBalance(common.Address, *big.Int) { panic("implement me") } -func (dummyStatedb) GetBalance(common.Address) *big.Int { panic("implement me") } -func (dummyStatedb) GetNonce(common.Address) uint64 { panic("implement me") } -func (dummyStatedb) SetNonce(common.Address, uint64) { panic("implement me") } -func (dummyStatedb) GetCodeHash(common.Address) common.Hash { panic("implement me") } -func (dummyStatedb) GetCode(common.Address) []byte { panic("implement me") } -func (dummyStatedb) SetCode(common.Address, []byte) { panic("implement me") } -func (dummyStatedb) GetCodeSize(common.Address) int { panic("implement me") } -func (dummyStatedb) AddRefund(uint64) { panic("implement me") } -func (dummyStatedb) SubRefund(uint64) { panic("implement me") } -func (dummyStatedb) GetRefund() uint64 { return 1337 } -func (dummyStatedb) GetCommittedState(common.Address, common.Hash) common.Hash { panic("implement me") } -func (dummyStatedb) GetState(common.Address, common.Hash) common.Hash { panic("implement me") } -func (dummyStatedb) SetState(common.Address, common.Hash, common.Hash) { panic("implement me") } -func (dummyStatedb) Suicide(common.Address) bool { panic("implement me") } -func (dummyStatedb) HasSuicided(common.Address) bool { panic("implement me") } -func (dummyStatedb) Exist(common.Address) bool { panic("implement me") } -func (dummyStatedb) Empty(common.Address) bool { panic("implement me") } -func (dummyStatedb) RevertToSnapshot(int) { panic("implement me") } -func (dummyStatedb) Snapshot() int { panic("implement me") } -func (dummyStatedb) AddLog(*types.Log) { panic("implement me") } -func (dummyStatedb) AddPreimage(common.Hash, []byte) { panic("implement me") } -func (dummyStatedb) ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) { - panic("implement me") -} +func (dummyStatedb) GetRefund() uint64 { return 1337 } func runTrace(tracer *Tracer) (json.RawMessage, error) { - env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, dummyStatedb{}, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer}) + env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, &dummyStatedb{}, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer}) contract := vm.NewContract(account{}, account{}, big.NewInt(0), 10000) contract.Code = []byte{byte(vm.PUSH1), 0x1, byte(vm.PUSH1), 0x1, 0x0} @@ -158,7 +133,7 @@ func TestHaltBetweenSteps(t *testing.T) { t.Fatal(err) } - env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, dummyStatedb{}, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer}) + env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, &dummyStatedb{}, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer}) contract := vm.NewContract(&account{}, &account{}, big.NewInt(0), 0) tracer.CaptureState(env, 0, 0, 0, 0, nil, nil, contract, 0, nil)