|
|
@@ -24,6 +24,8 @@ import (
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
|
|
|
+ "github.com/ethereum/go-ethereum/core/state/snapshot"
|
|
|
+
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
|
"github.com/ethereum/go-ethereum/common/math"
|
|
|
@@ -145,8 +147,8 @@ func (t *StateTest) Subtests() []StateSubtest {
|
|
|
}
|
|
|
|
|
|
// Run executes a specific subtest and verifies the post-state and logs
|
|
|
-func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateDB, error) {
|
|
|
- statedb, root, err := t.RunNoVerify(subtest, vmconfig)
|
|
|
+func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config, snapshotter bool) (*state.StateDB, error) {
|
|
|
+ statedb, root, err := t.RunNoVerify(subtest, vmconfig, snapshotter)
|
|
|
if err != nil {
|
|
|
return statedb, err
|
|
|
}
|
|
|
@@ -163,14 +165,14 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateD
|
|
|
}
|
|
|
|
|
|
// RunNoVerify runs a specific subtest and returns the statedb and post-state root
|
|
|
-func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config) (*state.StateDB, common.Hash, error) {
|
|
|
+func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapshotter bool) (*state.StateDB, common.Hash, error) {
|
|
|
config, eips, err := getVMConfig(subtest.Fork)
|
|
|
if err != nil {
|
|
|
return nil, common.Hash{}, UnsupportedForkError{subtest.Fork}
|
|
|
}
|
|
|
vmconfig.ExtraEips = eips
|
|
|
block := t.genesis(config).ToBlock(nil)
|
|
|
- statedb := MakePreState(rawdb.NewMemoryDatabase(), t.json.Pre)
|
|
|
+ statedb := MakePreState(rawdb.NewMemoryDatabase(), t.json.Pre, snapshotter)
|
|
|
|
|
|
post := t.json.Post[subtest.Fork][subtest.Index]
|
|
|
msg, err := t.json.Tx.toMessage(post)
|
|
|
@@ -204,7 +206,7 @@ func (t *StateTest) gasLimit(subtest StateSubtest) uint64 {
|
|
|
return t.json.Tx.GasLimit[t.json.Post[subtest.Fork][subtest.Index].Indexes.Gas]
|
|
|
}
|
|
|
|
|
|
-func MakePreState(db ethdb.Database, accounts core.GenesisAlloc) *state.StateDB {
|
|
|
+func MakePreState(db ethdb.Database, accounts core.GenesisAlloc, snapshotter bool) *state.StateDB {
|
|
|
sdb := state.NewDatabase(db)
|
|
|
statedb, _ := state.New(common.Hash{}, sdb, nil)
|
|
|
for addr, a := range accounts {
|
|
|
@@ -217,7 +219,12 @@ func MakePreState(db ethdb.Database, accounts core.GenesisAlloc) *state.StateDB
|
|
|
}
|
|
|
// Commit and re-open to start with a clean state.
|
|
|
root, _ := statedb.Commit(false)
|
|
|
- statedb, _ = state.New(root, sdb, nil)
|
|
|
+
|
|
|
+ var snaps *snapshot.Tree
|
|
|
+ if snapshotter {
|
|
|
+ snaps = snapshot.New(db, sdb.TrieDB(), 1, root, false)
|
|
|
+ }
|
|
|
+ statedb, _ = state.New(root, sdb, snaps)
|
|
|
return statedb
|
|
|
}
|
|
|
|