@@ -30,6 +30,7 @@ import (
3030 "testing"
3131 "time"
3232
33+ "github.com/ethereum/go-ethereum/common"
3334 "github.com/ethereum/go-ethereum/core"
3435 "github.com/ethereum/go-ethereum/core/rawdb"
3536 "github.com/ethereum/go-ethereum/core/types"
@@ -38,10 +39,7 @@ import (
3839 "github.com/holiman/uint256"
3940)
4041
41- func TestState (t * testing.T ) {
42- t .Parallel ()
43-
44- st := new (testMatcher )
42+ func initMatcher (st * testMatcher ) {
4543 // Long tests:
4644 st .slow (`^stAttackTest/ContractCreationSpam` )
4745 st .slow (`^stBadOpcode/badOpcodes` )
@@ -60,72 +58,102 @@ func TestState(t *testing.T) {
6058 // Broken tests:
6159 // EOF is not part of cancun
6260 st .skipLoad (`^stEOF/` )
61+ }
6362
64- // For Istanbul, older tests were moved into LegacyTests
63+ func TestState (t * testing.T ) {
64+ t .Parallel ()
65+
66+ st := new (testMatcher )
67+ initMatcher (st )
6568 for _ , dir := range []string {
6669 filepath .Join (baseDir , "EIPTests" , "StateTests" ),
6770 stateTestDir ,
68- legacyStateTestDir ,
6971 benchmarksDir ,
7072 } {
7173 st .walk (t , dir , func (t * testing.T , name string , test * StateTest ) {
72- if runtime .GOARCH == "386" && runtime .GOOS == "windows" && rand .Int63 ()% 2 == 0 {
73- t .Skip ("test (randomly) skipped on 32-bit windows" )
74- return
75- }
76- for _ , subtest := range test .Subtests () {
77- subtest := subtest
78- key := fmt .Sprintf ("%s/%d" , subtest .Fork , subtest .Index )
74+ execStateTest (t , st , test )
75+ })
76+ }
77+ }
7978
80- t .Run (key + "/hash/trie" , func (t * testing.T ) {
81- withTrace (t , test .gasLimit (subtest ), func (vmconfig vm.Config ) error {
82- var result error
83- test .Run (subtest , vmconfig , false , rawdb .HashScheme , func (err error , state * StateTestState ) {
84- result = st .checkFailure (t , err )
85- })
86- return result
87- })
79+ // TestLegacyState tests some older tests, which were moved to the folder
80+ // 'LegacyTests' for the Istanbul fork.
81+ func TestLegacyState (t * testing.T ) {
82+ st := new (testMatcher )
83+ initMatcher (st )
84+ st .walk (t , legacyStateTestDir , func (t * testing.T , name string , test * StateTest ) {
85+ execStateTest (t , st , test )
86+ })
87+ }
88+
89+ // TestExecutionSpecState runs the test fixtures from execution-spec-tests.
90+ func TestExecutionSpecState (t * testing.T ) {
91+ if ! common .FileExist (executionSpecStateTestDir ) {
92+ t .Skipf ("directory %s does not exist" , executionSpecStateTestDir )
93+ }
94+ st := new (testMatcher )
95+
96+ st .walk (t , executionSpecStateTestDir , func (t * testing.T , name string , test * StateTest ) {
97+ execStateTest (t , st , test )
98+ })
99+ }
100+
101+ func execStateTest (t * testing.T , st * testMatcher , test * StateTest ) {
102+ if runtime .GOARCH == "386" && runtime .GOOS == "windows" && rand .Int63 ()% 2 == 0 {
103+ t .Skip ("test (randomly) skipped on 32-bit windows" )
104+ return
105+ }
106+ for _ , subtest := range test .Subtests () {
107+ subtest := subtest
108+ key := fmt .Sprintf ("%s/%d" , subtest .Fork , subtest .Index )
109+
110+ t .Run (key + "/hash/trie" , func (t * testing.T ) {
111+ withTrace (t , test .gasLimit (subtest ), func (vmconfig vm.Config ) error {
112+ var result error
113+ test .Run (subtest , vmconfig , false , rawdb .HashScheme , func (err error , state * StateTestState ) {
114+ result = st .checkFailure (t , err )
88115 })
89- t . Run ( key + "/hash/snap" , func ( t * testing. T ) {
90- withTrace ( t , test . gasLimit ( subtest ), func ( vmconfig vm. Config ) error {
91- var result error
92- test .Run (subtest , vmconfig , true , rawdb . HashScheme , func (err error , state * StateTestState ) {
93- if state . Snapshots != nil && state . StateDB != nil {
94- if _ , err := state . Snapshots . Journal ( state . StateDB . IntermediateRoot ( false )); err != nil {
95- result = err
96- return
97- }
98- }
99- result = st . checkFailure ( t , err )
100- })
101- return result
102- } )
116+ return result
117+ })
118+ })
119+ t .Run (key + "/hash/snap" , func (t * testing. T ) {
120+ withTrace ( t , test . gasLimit ( subtest ), func ( vmconfig vm. Config ) error {
121+ var result error
122+ test . Run ( subtest , vmconfig , true , rawdb . HashScheme , func ( err error , state * StateTestState ) {
123+ if state . Snapshots != nil && state . StateDB != nil {
124+ if _ , err := state . Snapshots . Journal ( state . StateDB . IntermediateRoot ( false )); err != nil {
125+ result = err
126+ return
127+ }
128+ }
129+ result = st . checkFailure ( t , err )
103130 })
104- t . Run ( key + "/path/trie" , func ( t * testing. T ) {
105- withTrace ( t , test . gasLimit ( subtest ), func ( vmconfig vm. Config ) error {
106- var result error
107- test .Run (subtest , vmconfig , false , rawdb . PathScheme , func (err error , state * StateTestState ) {
108- result = st . checkFailure ( t , err )
109- })
110- return result
111- } )
131+ return result
132+ })
133+ })
134+ t .Run (key + "/path/trie" , func (t * testing. T ) {
135+ withTrace ( t , test . gasLimit ( subtest ), func ( vmconfig vm. Config ) error {
136+ var result error
137+ test . Run ( subtest , vmconfig , false , rawdb . PathScheme , func ( err error , state * StateTestState ) {
138+ result = st . checkFailure ( t , err )
112139 })
113- t . Run ( key + "/path/snap" , func ( t * testing. T ) {
114- withTrace ( t , test . gasLimit ( subtest ), func ( vmconfig vm. Config ) error {
115- var result error
116- test .Run (subtest , vmconfig , true , rawdb . PathScheme , func (err error , state * StateTestState ) {
117- if state . Snapshots != nil && state . StateDB != nil {
118- if _ , err := state . Snapshots . Journal ( state . StateDB . IntermediateRoot ( false )); err != nil {
119- result = err
120- return
121- }
122- }
123- result = st . checkFailure ( t , err )
124- })
125- return result
126- } )
140+ return result
141+ })
142+ })
143+ t .Run (key + "/path/snap" , func (t * testing. T ) {
144+ withTrace ( t , test . gasLimit ( subtest ), func ( vmconfig vm. Config ) error {
145+ var result error
146+ test . Run ( subtest , vmconfig , true , rawdb . PathScheme , func ( err error , state * StateTestState ) {
147+ if state . Snapshots != nil && state . StateDB != nil {
148+ if _ , err := state . Snapshots . Journal ( state . StateDB . IntermediateRoot ( false )); err != nil {
149+ result = err
150+ return
151+ }
152+ }
153+ result = st . checkFailure ( t , err )
127154 })
128- }
155+ return result
156+ })
129157 })
130158 }
131159}
0 commit comments