aboutsummaryrefslogtreecommitdiffstats
path: root/tests/helper/vm.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-03 18:11:11 +0800
committerobscuren <geffobscura@gmail.com>2015-03-03 18:11:11 +0800
commitc1ef19bef9d4207b5f7d6fc5ff40375a5f0d203b (patch)
treeec0d2325fc2c4e53050ba7b52222eacf6030a289 /tests/helper/vm.go
parentfe7ab662f0f1d17a4f350e344756da9e31790d45 (diff)
downloadgo-tangerine-c1ef19bef9d4207b5f7d6fc5ff40375a5f0d203b.tar.gz
go-tangerine-c1ef19bef9d4207b5f7d6fc5ff40375a5f0d203b.tar.zst
go-tangerine-c1ef19bef9d4207b5f7d6fc5ff40375a5f0d203b.zip
quad mem
Diffstat (limited to 'tests/helper/vm.go')
-rw-r--r--tests/helper/vm.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/helper/vm.go b/tests/helper/vm.go
index f1c1ffdfc..a1a1a98ca 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,38 @@ 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)
+ }
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 +143,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)