Added state tests

This commit is contained in:
obscuren
2014-12-02 00:03:53 +01:00
parent a052357872
commit 2df8ad6307
4 changed files with 86 additions and 7 deletions

View File

@ -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
}