@@ -30,6 +30,7 @@ import (
30
30
"testing"
31
31
"time"
32
32
33
+ "github.com/ethereum/go-ethereum/common"
33
34
"github.com/ethereum/go-ethereum/core"
34
35
"github.com/ethereum/go-ethereum/core/rawdb"
35
36
"github.com/ethereum/go-ethereum/core/types"
@@ -38,10 +39,7 @@ import (
38
39
"github.com/holiman/uint256"
39
40
)
40
41
41
- func TestState (t * testing.T ) {
42
- t .Parallel ()
43
-
44
- st := new (testMatcher )
42
+ func initMatcher (st * testMatcher ) {
45
43
// Long tests:
46
44
st .slow (`^stAttackTest/ContractCreationSpam` )
47
45
st .slow (`^stBadOpcode/badOpcodes` )
@@ -60,72 +58,102 @@ func TestState(t *testing.T) {
60
58
// Broken tests:
61
59
// EOF is not part of cancun
62
60
st .skipLoad (`^stEOF/` )
61
+ }
63
62
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 )
65
68
for _ , dir := range []string {
66
69
filepath .Join (baseDir , "EIPTests" , "StateTests" ),
67
70
stateTestDir ,
68
- legacyStateTestDir ,
69
71
benchmarksDir ,
70
72
} {
71
73
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
+ }
79
78
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 )
88
115
})
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 )
103
130
})
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 )
112
139
})
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 )
127
154
})
128
- }
155
+ return result
156
+ })
129
157
})
130
158
}
131
159
}
0 commit comments