diff options
author | obscuren <geffobscura@gmail.com> | 2014-12-02 07:03:53 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-12-02 07:03:53 +0800 |
commit | 2df8ad6307d741d0a6d2f746d53f97c7b27ad796 (patch) | |
tree | 778c60ff0d3b9e8a69844ea131e5876a80cc0150 /tests/helper | |
parent | a052357872217d5e99e7ee1a7a4b524b53addcdd (diff) | |
download | dexon-2df8ad6307d741d0a6d2f746d53f97c7b27ad796.tar dexon-2df8ad6307d741d0a6d2f746d53f97c7b27ad796.tar.gz dexon-2df8ad6307d741d0a6d2f746d53f97c7b27ad796.tar.bz2 dexon-2df8ad6307d741d0a6d2f746d53f97c7b27ad796.tar.lz dexon-2df8ad6307d741d0a6d2f746d53f97c7b27ad796.tar.xz dexon-2df8ad6307d741d0a6d2f746d53f97c7b27ad796.tar.zst dexon-2df8ad6307d741d0a6d2f746d53f97c7b27ad796.zip |
Added state tests
Diffstat (limited to 'tests/helper')
-rw-r--r-- | tests/helper/vm.go | 15 |
1 files changed, 15 insertions, 0 deletions
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 +} |