aboutsummaryrefslogtreecommitdiffstats
path: root/tests/state_test_util.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-12-06 09:16:03 +0800
committerFelix Lange <fjl@twurst.com>2016-12-06 09:16:03 +0800
commit3fc7c978277051391f8ea7831559e9f4f83c3166 (patch)
treeb11b41c1723e02adc098ddc9f4188a8bad782ed8 /tests/state_test_util.go
parent7f79d249a64ee72b185ffa9a9ed78f137b7938de (diff)
downloaddexon-3fc7c978277051391f8ea7831559e9f4f83c3166.tar
dexon-3fc7c978277051391f8ea7831559e9f4f83c3166.tar.gz
dexon-3fc7c978277051391f8ea7831559e9f4f83c3166.tar.bz2
dexon-3fc7c978277051391f8ea7831559e9f4f83c3166.tar.lz
dexon-3fc7c978277051391f8ea7831559e9f4f83c3166.tar.xz
dexon-3fc7c978277051391f8ea7831559e9f4f83c3166.tar.zst
dexon-3fc7c978277051391f8ea7831559e9f4f83c3166.zip
core, core/vm: implemented a generic environment (#3348)
Environment is now a struct (not an interface). This reduces a lot of tech-debt throughout the codebase where a virtual machine environment had to be implemented in order to test or run it. The new environment is suitable to be used en the json tests, core consensus and light client.
Diffstat (limited to 'tests/state_test_util.go')
-rw-r--r--tests/state_test_util.go29
1 files changed, 4 insertions, 25 deletions
diff --git a/tests/state_test_util.go b/tests/state_test_util.go
index 117bb4b28..dc5872d98 100644
--- a/tests/state_test_util.go
+++ b/tests/state_test_util.go
@@ -18,7 +18,6 @@ package tests
import (
"bytes"
- "encoding/hex"
"fmt"
"io"
"math/big"
@@ -29,9 +28,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
- "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
- "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/params"
@@ -207,39 +204,21 @@ func runStateTest(chainConfig *params.ChainConfig, test VmTest) error {
}
func RunState(chainConfig *params.ChainConfig, statedb *state.StateDB, env, tx map[string]string) ([]byte, vm.Logs, *big.Int, error) {
- var (
- data = common.FromHex(tx["data"])
- gas = common.Big(tx["gasLimit"])
- price = common.Big(tx["gasPrice"])
- value = common.Big(tx["value"])
- nonce = common.Big(tx["nonce"]).Uint64()
- )
-
- var to *common.Address
- if len(tx["to"]) > 2 {
- t := common.HexToAddress(tx["to"])
- to = &t
- }
+ environment, msg := NewEVMEnvironment(false, chainConfig, statedb, env, tx)
// Set pre compiled contracts
vm.Precompiled = vm.PrecompiledContracts()
gaspool := new(core.GasPool).AddGas(common.Big(env["currentGasLimit"]))
- key, _ := hex.DecodeString(tx["secretKey"])
- addr := crypto.PubkeyToAddress(crypto.ToECDSA(key).PublicKey)
- message := types.NewMessage(addr, to, nonce, value, gas, price, data, true)
- vmenv := NewEnvFromMap(chainConfig, statedb, env, tx)
- vmenv.origin = addr
-
root, _ := statedb.Commit(false)
statedb.Reset(root)
snapshot := statedb.Snapshot()
- ret, _, err := core.ApplyMessage(vmenv, message, gaspool)
+ ret, gasUsed, err := core.ApplyMessage(environment, msg, gaspool)
if core.IsNonceErr(err) || core.IsInvalidTxErr(err) || core.IsGasLimitErr(err) {
statedb.RevertToSnapshot(snapshot)
}
- statedb.Commit(chainConfig.IsEIP158(vmenv.BlockNumber()))
+ statedb.Commit(chainConfig.IsEIP158(environment.Context.BlockNumber))
- return ret, vmenv.state.Logs(), vmenv.Gas, err
+ return ret, statedb.Logs(), gasUsed, err
}