From 60bd7959a3e628aa2c810cd060cdb3ce9c9f9a31 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 15 Oct 2018 14:59:43 +0200 Subject: [PATCH] core/vm, eth/tracers: fix nil deref in tests --- core/vm/logger_test.go | 34 +++++++++++++++++++++++++++++++++- eth/tracers/tracer_test.go | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/core/vm/logger_test.go b/core/vm/logger_test.go index cdbb70dc42..deaed919fa 100644 --- a/core/vm/logger_test.go +++ b/core/vm/logger_test.go @@ -17,6 +17,7 @@ package vm import ( + "github.com/ethereum/go-ethereum/core/types" "math/big" "testing" @@ -41,9 +42,40 @@ func (d *dummyContractRef) SetBalance(*big.Int) {} func (d *dummyContractRef) SetNonce(uint64) {} func (d *dummyContractRef) Balance() *big.Int { return new(big.Int) } +type dummyStatedb struct { +} + +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 TestStoreCapture(t *testing.T) { var ( - env = NewEVM(Context{}, nil, params.TestChainConfig, Config{}) + env = NewEVM(Context{}, dummyStatedb{}, params.TestChainConfig, Config{}) logger = NewStructLogger(nil) mem = NewMemory() stack = newstack() diff --git a/eth/tracers/tracer_test.go b/eth/tracers/tracer_test.go index 58b6247245..cd76041dff 100644 --- a/eth/tracers/tracer_test.go +++ b/eth/tracers/tracer_test.go @@ -20,6 +20,7 @@ import ( "bytes" "encoding/json" "errors" + "github.com/ethereum/go-ethereum/core/types" "math/big" "testing" "time" @@ -43,8 +44,39 @@ func (account) ReturnGas(*big.Int) {} func (account) SetCode(common.Hash, []byte) {} func (account) ForEachStorage(cb func(key, value common.Hash) bool) {} +type dummyStatedb struct { +} + +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 runTrace(tracer *Tracer) (json.RawMessage, error) { - env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, nil, 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} @@ -126,7 +158,7 @@ func TestHaltBetweenSteps(t *testing.T) { t.Fatal(err) } - env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, nil, 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)