aboutsummaryrefslogtreecommitdiffstats
path: root/tests/helper
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-10 00:55:01 +0800
committerobscuren <geffobscura@gmail.com>2015-03-10 00:55:01 +0800
commit8560004f380dc688a1171ad5aeffa593aae41193 (patch)
treefea395acf042b51e97a86e2c4cbcf8c16b2912b7 /tests/helper
parent9723191b19f6ddc12f0c3376ede7529b2d72e6a2 (diff)
parent676a0de58d3d7c508b0eeeff192d2095a46f7382 (diff)
downloaddexon-8560004f380dc688a1171ad5aeffa593aae41193.tar
dexon-8560004f380dc688a1171ad5aeffa593aae41193.tar.gz
dexon-8560004f380dc688a1171ad5aeffa593aae41193.tar.bz2
dexon-8560004f380dc688a1171ad5aeffa593aae41193.tar.lz
dexon-8560004f380dc688a1171ad5aeffa593aae41193.tar.xz
dexon-8560004f380dc688a1171ad5aeffa593aae41193.tar.zst
dexon-8560004f380dc688a1171ad5aeffa593aae41193.zip
wip
Diffstat (limited to 'tests/helper')
-rw-r--r--tests/helper/vm.go29
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/helper/vm.go b/tests/helper/vm.go
index f1c1ffdfc..9ebf8f8b6 100644
--- a/tests/helper/vm.go
+++ b/tests/helper/vm.go
@@ -28,6 +28,8 @@ type Env struct {
gasLimit *big.Int
logs state.Logs
+
+ vmTest bool
}
func NewEnv(state *state.StateDB) *Env {
@@ -92,20 +94,40 @@ func (self *Env) vm(addr, data []byte, gas, price, value *big.Int) *core.Executi
}
func (self *Env) Call(caller vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
+ if self.vmTest && self.depth > 0 {
+ caller.ReturnGas(gas, price)
+
+ return nil, nil
+ }
exe := self.vm(addr, data, gas, price, value)
ret, err := exe.Call(addr, caller)
self.Gas = exe.Gas
return ret, err
+
}
func (self *Env) CallCode(caller vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
+ if self.vmTest && self.depth > 0 {
+ caller.ReturnGas(gas, price)
+
+ return nil, nil
+ }
exe := self.vm(caller.Address(), data, gas, price, value)
return exe.Call(addr, caller)
}
func (self *Env) Create(caller vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) {
exe := self.vm(addr, data, gas, price, value)
- return exe.Create(caller)
+ if self.vmTest {
+ caller.ReturnGas(gas, price)
+
+ nonce := self.state.GetNonce(caller.Address())
+ obj := self.state.GetOrNewStateObject(crypto.CreateAddress(caller.Address(), nonce))
+
+ return nil, nil, obj
+ } else {
+ return exe.Create(caller)
+ }
}
func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, state.Logs, *big.Int, error) {
@@ -123,6 +145,7 @@ func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, state.Log
caller := state.GetOrNewStateObject(from)
vmenv := NewEnvFromMap(state, env, exec)
+ vmenv.vmTest = true
vmenv.skipTransfer = true
vmenv.initial = true
ret, err := vmenv.Call(caller, to, data, gas, price, value)
@@ -144,6 +167,7 @@ func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, state.
// Set pre compiled contracts
vm.Precompiled = vm.PrecompiledContracts()
+ snapshot := statedb.Copy()
coinbase := statedb.GetOrNewStateObject(caddr)
coinbase.SetGasPool(ethutil.Big(env["currentGasLimit"]))
@@ -152,6 +176,9 @@ func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, state.
st := core.NewStateTransition(vmenv, message, coinbase)
vmenv.origin = keyPair.Address()
ret, err := st.TransitionState()
+ if core.IsNonceErr(err) || core.IsInvalidTxErr(err) {
+ statedb.Set(snapshot)
+ }
statedb.Update(vmenv.Gas)
return ret, vmenv.logs, vmenv.Gas, err