aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/evm/logger_test.go
diff options
context:
space:
mode:
authorjm <jm.huang@cobinhood.com>2019-01-15 00:48:13 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:03 +0800
commit266068a53cdf9e06acacf982d63653c03133a634 (patch)
treeaf2d74e6adb309adfe39bafaa2f540fe0bcd1a31 /core/vm/evm/logger_test.go
parentd41cb421d755b8f0bca87b7476f26aa4b879b9d9 (diff)
downloaddexon-266068a53cdf9e06acacf982d63653c03133a634.tar
dexon-266068a53cdf9e06acacf982d63653c03133a634.tar.gz
dexon-266068a53cdf9e06acacf982d63653c03133a634.tar.bz2
dexon-266068a53cdf9e06acacf982d63653c03133a634.tar.lz
dexon-266068a53cdf9e06acacf982d63653c03133a634.tar.xz
dexon-266068a53cdf9e06acacf982d63653c03133a634.tar.zst
dexon-266068a53cdf9e06acacf982d63653c03133a634.zip
core: vm: refactor file structure
For support other vm types, this pr modified the core/vm file structures.
Diffstat (limited to 'core/vm/evm/logger_test.go')
-rw-r--r--core/vm/evm/logger_test.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/core/vm/evm/logger_test.go b/core/vm/evm/logger_test.go
new file mode 100644
index 000000000..a8e0e9044
--- /dev/null
+++ b/core/vm/evm/logger_test.go
@@ -0,0 +1,71 @@
+// Copyright 2016 The go-ethereum Authors
+// This file is part of the go-ethereum library.
+//
+// The go-ethereum library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// The go-ethereum library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
+
+package evm
+
+import (
+ "math/big"
+ "testing"
+
+ "github.com/dexon-foundation/dexon/common"
+ "github.com/dexon-foundation/dexon/core/state"
+ "github.com/dexon-foundation/dexon/core/vm"
+ "github.com/dexon-foundation/dexon/params"
+)
+
+type dummyContractRef struct {
+ calledForEach bool
+}
+
+func (dummyContractRef) ReturnGas(*big.Int) {}
+func (dummyContractRef) Address() common.Address { return common.Address{} }
+func (dummyContractRef) Value() *big.Int { return new(big.Int) }
+func (dummyContractRef) SetCode(common.Hash, []byte) {}
+func (d *dummyContractRef) ForEachStorage(callback func(key, value common.Hash) bool) {
+ d.calledForEach = true
+}
+func (d *dummyContractRef) SubBalance(amount *big.Int) {}
+func (d *dummyContractRef) AddBalance(amount *big.Int) {}
+func (d *dummyContractRef) SetBalance(*big.Int) {}
+func (d *dummyContractRef) SetNonce(uint64) {}
+func (d *dummyContractRef) Balance() *big.Int { return new(big.Int) }
+
+type dummyStatedb struct {
+ state.StateDB
+}
+
+func (*dummyStatedb) GetRefund() uint64 { return 1337 }
+
+func TestStoreCapture(t *testing.T) {
+ var (
+ env = NewEVM(Context{}, &dummyStatedb{}, params.TestChainConfig, Config{})
+ logger = NewStructLogger(nil)
+ mem = vm.NewMemory()
+ stack = NewStack()
+ contract = NewContract(&dummyContractRef{}, &dummyContractRef{}, new(big.Int), 0)
+ )
+ 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()]))
+ }
+ exp := common.BigToHash(big.NewInt(1))
+ if logger.changedValues[contract.Address()][index] != exp {
+ t.Errorf("expected %x, got %x", exp, logger.changedValues[contract.Address()][index])
+ }
+}