tests: update execution spec tests + split statetest exec (#28993)

This commit is contained in:
Martin HS 2024-02-15 13:30:11 +01:00 committed by GitHub
parent 9e3e46671e
commit 886f0e72e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 104 additions and 75 deletions

View File

@ -1,9 +1,9 @@
# This file contains sha256 checksums of optional build dependencies. # This file contains sha256 checksums of optional build dependencies.
# version:spec-tests 1.0.6 # version:spec-tests 2.1.0
# https://github.com/ethereum/execution-spec-tests/releases # https://github.com/ethereum/execution-spec-tests/releases
# https://github.com/ethereum/execution-spec-tests/releases/download/v1.0.6/ # https://github.com/ethereum/execution-spec-tests/releases/download/v2.1.0/
485af7b66cf41eb3a8c1bd46632913b8eb95995df867cf665617bbc9b4beedd1 fixtures_develop.tar.gz ca89c76851b0900bfcc3cbb9a26cbece1f3d7c64a3bed38723e914713290df6c fixtures_develop.tar.gz
# version:golang 1.21.6 # version:golang 1.21.6
# https://go.dev/dl/ # https://go.dev/dl/

View File

@ -61,14 +61,14 @@ func TestBlockchain(t *testing.T) {
// which run natively, so there's no reason to run them here. // which run natively, so there's no reason to run them here.
} }
// TestExecutionSpec runs the test fixtures from execution-spec-tests. // TestExecutionSpecBlocktests runs the test fixtures from execution-spec-tests.
func TestExecutionSpec(t *testing.T) { func TestExecutionSpecBlocktests(t *testing.T) {
if !common.FileExist(executionSpecDir) { if !common.FileExist(executionSpecBlockchainTestDir) {
t.Skipf("directory %s does not exist", executionSpecDir) t.Skipf("directory %s does not exist", executionSpecBlockchainTestDir)
} }
bt := new(testMatcher) bt := new(testMatcher)
bt.walk(t, executionSpecDir, func(t *testing.T, name string, test *BlockTest) { bt.walk(t, executionSpecBlockchainTestDir, func(t *testing.T, name string, test *BlockTest) {
execBlockTest(t, bt, test) execBlockTest(t, bt, test)
}) })
} }

View File

@ -34,15 +34,16 @@ import (
) )
var ( var (
baseDir = filepath.Join(".", "testdata") baseDir = filepath.Join(".", "testdata")
blockTestDir = filepath.Join(baseDir, "BlockchainTests") blockTestDir = filepath.Join(baseDir, "BlockchainTests")
stateTestDir = filepath.Join(baseDir, "GeneralStateTests") stateTestDir = filepath.Join(baseDir, "GeneralStateTests")
legacyStateTestDir = filepath.Join(baseDir, "LegacyTests", "Constantinople", "GeneralStateTests") legacyStateTestDir = filepath.Join(baseDir, "LegacyTests", "Constantinople", "GeneralStateTests")
transactionTestDir = filepath.Join(baseDir, "TransactionTests") transactionTestDir = filepath.Join(baseDir, "TransactionTests")
rlpTestDir = filepath.Join(baseDir, "RLPTests") rlpTestDir = filepath.Join(baseDir, "RLPTests")
difficultyTestDir = filepath.Join(baseDir, "BasicTests") difficultyTestDir = filepath.Join(baseDir, "BasicTests")
executionSpecDir = filepath.Join(".", "spec-tests", "fixtures") executionSpecBlockchainTestDir = filepath.Join(".", "spec-tests", "fixtures", "blockchain_tests")
benchmarksDir = filepath.Join(".", "evm-benchmarks", "benchmarks") executionSpecStateTestDir = filepath.Join(".", "spec-tests", "fixtures", "state_tests")
benchmarksDir = filepath.Join(".", "evm-benchmarks", "benchmarks")
) )
func readJSON(reader io.Reader, value interface{}) error { func readJSON(reader io.Reader, value interface{}) error {

View File

@ -30,6 +30,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
@ -38,10 +39,7 @@ import (
"github.com/holiman/uint256" "github.com/holiman/uint256"
) )
func TestState(t *testing.T) { func initMatcher(st *testMatcher) {
t.Parallel()
st := new(testMatcher)
// Long tests: // Long tests:
st.slow(`^stAttackTest/ContractCreationSpam`) st.slow(`^stAttackTest/ContractCreationSpam`)
st.slow(`^stBadOpcode/badOpcodes`) st.slow(`^stBadOpcode/badOpcodes`)
@ -60,72 +58,102 @@ func TestState(t *testing.T) {
// Broken tests: // Broken tests:
// EOF is not part of cancun // EOF is not part of cancun
st.skipLoad(`^stEOF/`) st.skipLoad(`^stEOF/`)
}
// For Istanbul, older tests were moved into LegacyTests func TestState(t *testing.T) {
t.Parallel()
st := new(testMatcher)
initMatcher(st)
for _, dir := range []string{ for _, dir := range []string{
filepath.Join(baseDir, "EIPTests", "StateTests"), filepath.Join(baseDir, "EIPTests", "StateTests"),
stateTestDir, stateTestDir,
legacyStateTestDir,
benchmarksDir, benchmarksDir,
} { } {
st.walk(t, dir, func(t *testing.T, name string, test *StateTest) { st.walk(t, dir, func(t *testing.T, name string, test *StateTest) {
if runtime.GOARCH == "386" && runtime.GOOS == "windows" && rand.Int63()%2 == 0 { execStateTest(t, st, test)
t.Skip("test (randomly) skipped on 32-bit windows") })
return }
} }
for _, subtest := range test.Subtests() {
subtest := subtest
key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index)
t.Run(key+"/hash/trie", func(t *testing.T) { // TestLegacyState tests some older tests, which were moved to the folder
withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error { // 'LegacyTests' for the Istanbul fork.
var result error func TestLegacyState(t *testing.T) {
test.Run(subtest, vmconfig, false, rawdb.HashScheme, func(err error, state *StateTestState) { st := new(testMatcher)
result = st.checkFailure(t, err) initMatcher(st)
}) st.walk(t, legacyStateTestDir, func(t *testing.T, name string, test *StateTest) {
return result execStateTest(t, st, test)
}) })
}
// TestExecutionSpecState runs the test fixtures from execution-spec-tests.
func TestExecutionSpecState(t *testing.T) {
if !common.FileExist(executionSpecStateTestDir) {
t.Skipf("directory %s does not exist", executionSpecStateTestDir)
}
st := new(testMatcher)
st.walk(t, executionSpecStateTestDir, func(t *testing.T, name string, test *StateTest) {
execStateTest(t, st, test)
})
}
func execStateTest(t *testing.T, st *testMatcher, test *StateTest) {
if runtime.GOARCH == "386" && runtime.GOOS == "windows" && rand.Int63()%2 == 0 {
t.Skip("test (randomly) skipped on 32-bit windows")
return
}
for _, subtest := range test.Subtests() {
subtest := subtest
key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index)
t.Run(key+"/hash/trie", func(t *testing.T) {
withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error {
var result error
test.Run(subtest, vmconfig, false, rawdb.HashScheme, func(err error, state *StateTestState) {
result = st.checkFailure(t, err)
}) })
t.Run(key+"/hash/snap", func(t *testing.T) { return result
withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error { })
var result error })
test.Run(subtest, vmconfig, true, rawdb.HashScheme, func(err error, state *StateTestState) { t.Run(key+"/hash/snap", func(t *testing.T) {
if state.Snapshots != nil && state.StateDB != nil { withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error {
if _, err := state.Snapshots.Journal(state.StateDB.IntermediateRoot(false)); err != nil { var result error
result = err test.Run(subtest, vmconfig, true, rawdb.HashScheme, func(err error, state *StateTestState) {
return if state.Snapshots != nil && state.StateDB != nil {
} if _, err := state.Snapshots.Journal(state.StateDB.IntermediateRoot(false)); err != nil {
} result = err
result = st.checkFailure(t, err) return
}) }
return result }
}) result = st.checkFailure(t, err)
}) })
t.Run(key+"/path/trie", func(t *testing.T) { return result
withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error { })
var result error })
test.Run(subtest, vmconfig, false, rawdb.PathScheme, func(err error, state *StateTestState) { t.Run(key+"/path/trie", func(t *testing.T) {
result = st.checkFailure(t, err) withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error {
}) var result error
return result test.Run(subtest, vmconfig, false, rawdb.PathScheme, func(err error, state *StateTestState) {
}) result = st.checkFailure(t, err)
}) })
t.Run(key+"/path/snap", func(t *testing.T) { return result
withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error { })
var result error })
test.Run(subtest, vmconfig, true, rawdb.PathScheme, func(err error, state *StateTestState) { t.Run(key+"/path/snap", func(t *testing.T) {
if state.Snapshots != nil && state.StateDB != nil { withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error {
if _, err := state.Snapshots.Journal(state.StateDB.IntermediateRoot(false)); err != nil { var result error
result = err test.Run(subtest, vmconfig, true, rawdb.PathScheme, func(err error, state *StateTestState) {
return if state.Snapshots != nil && state.StateDB != nil {
} if _, err := state.Snapshots.Journal(state.StateDB.IntermediateRoot(false)); err != nil {
} result = err
result = st.checkFailure(t, err) return
}) }
return result }
}) result = st.checkFailure(t, err)
}) })
} return result
})
}) })
} }
} }