From 3d9a4e7084c33cb28a2265c0dd232a0ea3871c92 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 3 Dec 2014 12:21:12 +0100 Subject: Fixed mem error in vm. Fixed logs tests --- tests/helper/vm.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'tests/helper/vm.go') diff --git a/tests/helper/vm.go b/tests/helper/vm.go index b4ad93193..8e6645fc3 100644 --- a/tests/helper/vm.go +++ b/tests/helper/vm.go @@ -20,6 +20,8 @@ type Env struct { time int64 difficulty *big.Int gasLimit *big.Int + + logs state.Logs } func NewEnv(state *state.State) *Env { @@ -51,24 +53,27 @@ func (self *Env) Difficulty() *big.Int { return self.difficulty } func (self *Env) BlockHash() []byte { return nil } func (self *Env) State() *state.State { return self.state } func (self *Env) GasLimit() *big.Int { return self.gasLimit } -func (self *Env) AddLog(*state.Log) {} +func (self *Env) AddLog(log *state.Log) { + self.logs = append(self.logs, log) +} func (self *Env) Transfer(from, to vm.Account, amount *big.Int) error { return vm.Transfer(from, to, amount) } -func RunVm(state *state.State, env, exec map[string]string) ([]byte, *big.Int, error) { +func RunVm(state *state.State, env, exec map[string]string) ([]byte, state.Logs, *big.Int, error) { address := FromHex(exec["address"]) caller := state.GetOrNewStateObject(FromHex(exec["caller"])) - evm := vm.New(NewEnvFromMap(state, env, exec), vm.DebugVmTy) + vmenv := NewEnvFromMap(state, env, exec) + evm := vm.New(vmenv, vm.DebugVmTy) execution := vm.NewExecution(evm, address, FromHex(exec["data"]), ethutil.Big(exec["gas"]), ethutil.Big(exec["gasPrice"]), ethutil.Big(exec["value"])) execution.SkipTransfer = true ret, err := execution.Exec(address, caller) - return ret, execution.Gas, err + return ret, vmenv.logs, execution.Gas, err } -func RunState(state *state.State, env, tx map[string]string) ([]byte, *big.Int, error) { +func RunState(state *state.State, env, tx map[string]string) ([]byte, state.Logs, *big.Int, error) { address := FromHex(tx["to"]) keyPair, _ := crypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(tx["secretKey"]))) caller := state.GetOrNewStateObject(keyPair.Address()) @@ -79,5 +84,5 @@ func RunState(state *state.State, env, tx map[string]string) ([]byte, *big.Int, execution := vm.NewExecution(evm, address, FromHex(tx["data"]), ethutil.Big(tx["gasLimit"]), ethutil.Big(tx["gasPrice"]), ethutil.Big(tx["value"])) ret, err := execution.Exec(address, caller) - return ret, execution.Gas, err + return ret, vmenv.logs, execution.Gas, err } -- cgit