aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Holst Swende <martin@swende.se>2019-09-11 19:46:14 +0800
committerFelix Lange <fjl@twurst.com>2019-09-11 19:46:14 +0800
commit91b73495098c7941e3eb1c58a702952bf5acf1a6 (patch)
treed91baffcf08bd05bf6a6888b63d3164bd37f86d6
parent52a967cfab1f01120a4324e25c655a5a1497fcd3 (diff)
downloadgo-tangerine-91b73495098c7941e3eb1c58a702952bf5acf1a6.tar
go-tangerine-91b73495098c7941e3eb1c58a702952bf5acf1a6.tar.gz
go-tangerine-91b73495098c7941e3eb1c58a702952bf5acf1a6.tar.bz2
go-tangerine-91b73495098c7941e3eb1c58a702952bf5acf1a6.tar.lz
go-tangerine-91b73495098c7941e3eb1c58a702952bf5acf1a6.tar.xz
go-tangerine-91b73495098c7941e3eb1c58a702952bf5acf1a6.tar.zst
go-tangerine-91b73495098c7941e3eb1c58a702952bf5acf1a6.zip
tests: expose internal RunNoVerify method (#20051)
-rw-r--r--tests/state_test_util.go34
1 files changed, 22 insertions, 12 deletions
diff --git a/tests/state_test_util.go b/tests/state_test_util.go
index c6341e524..59ebcb6e1 100644
--- a/tests/state_test_util.go
+++ b/tests/state_test_util.go
@@ -144,11 +144,29 @@ func (t *StateTest) Subtests() []StateSubtest {
return sub
}
-// Run executes a specific subtest.
+// 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)
+ if err != nil {
+ return statedb, err
+ }
+ post := t.json.Post[subtest.Fork][subtest.Index]
+ // N.B: We need to do this in a two-step process, because the first Commit takes care
+ // of suicides, and we need to touch the coinbase _after_ it has potentially suicided.
+ if root != common.Hash(post.Root) {
+ return statedb, fmt.Errorf("post state root mismatch: got %x, want %x", root, post.Root)
+ }
+ if logs := rlpHash(statedb.Logs()); logs != common.Hash(post.Logs) {
+ return statedb, fmt.Errorf("post state logs hash mismatch: got %x, want %x", logs, post.Logs)
+ }
+ return statedb, nil
+}
+
+// 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) {
config, eips, err := getVMConfig(subtest.Fork)
if err != nil {
- return nil, UnsupportedForkError{subtest.Fork}
+ return nil, common.Hash{}, UnsupportedForkError{subtest.Fork}
}
vmconfig.ExtraEips = eips
block := t.genesis(config).ToBlock(nil)
@@ -157,7 +175,7 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateD
post := t.json.Post[subtest.Fork][subtest.Index]
msg, err := t.json.Tx.toMessage(post)
if err != nil {
- return nil, err
+ return nil, common.Hash{}, err
}
context := core.NewEVMContext(msg, block.Header(), nil, &t.json.Env.Coinbase)
context.GetHash = vmTestBlockHash
@@ -179,15 +197,7 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateD
statedb.AddBalance(block.Coinbase(), new(big.Int))
// And _now_ get the state root
root := statedb.IntermediateRoot(config.IsEIP158(block.Number()))
- // N.B: We need to do this in a two-step process, because the first Commit takes care
- // of suicides, and we need to touch the coinbase _after_ it has potentially suicided.
- if root != common.Hash(post.Root) {
- return statedb, fmt.Errorf("post state root mismatch: got %x, want %x", root, post.Root)
- }
- if logs := rlpHash(statedb.Logs()); logs != common.Hash(post.Logs) {
- return statedb, fmt.Errorf("post state logs hash mismatch: got %x, want %x", logs, post.Logs)
- }
- return statedb, nil
+ return statedb, root, nil
}
func (t *StateTest) gasLimit(subtest StateSubtest) uint64 {