From 2df8ad6307d741d0a6d2f746d53f97c7b27ad796 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 2 Dec 2014 00:03:53 +0100 Subject: Added state tests --- tests/helper/vm.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/helper') diff --git a/tests/helper/vm.go b/tests/helper/vm.go index 270fe5470..b4ad93193 100644 --- a/tests/helper/vm.go +++ b/tests/helper/vm.go @@ -3,6 +3,7 @@ package helper import ( "math/big" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/vm" @@ -66,3 +67,17 @@ func RunVm(state *state.State, env, exec map[string]string) ([]byte, *big.Int, e return ret, execution.Gas, err } + +func RunState(state *state.State, env, tx map[string]string) ([]byte, *big.Int, error) { + address := FromHex(tx["to"]) + keyPair, _ := crypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(tx["secretKey"]))) + caller := state.GetOrNewStateObject(keyPair.Address()) + + vmenv := NewEnvFromMap(state, env, tx) + vmenv.origin = caller.Address() + evm := vm.New(vmenv, vm.DebugVmTy) + 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 +} -- cgit