@@ -41,9 +41,11 @@ type twoOperandParams struct {
41
41
y string
42
42
}
43
43
44
- var alphabetSoup = "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
45
- var commonParams []* twoOperandParams
46
- var twoOpMethods map [string ]executionFunc
44
+ var (
45
+ alphabetSoup = "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
46
+ commonParams []* twoOperandParams
47
+ twoOpMethods map [string ]executionFunc
48
+ )
47
49
48
50
func init () {
49
51
// Params is a list of common edgecases that should be used for some common tests
@@ -92,10 +94,10 @@ func init() {
92
94
93
95
func testTwoOperandOp (t * testing.T , tests []TwoOperandTestcase , opFn executionFunc , name string ) {
94
96
var (
95
- env = NewEVM (BlockContext {}, TxContext {}, nil , params .TestChainConfig , Config {})
96
- stack = newstack ()
97
- pc = uint64 (0 )
98
- evmInterpreter = env .interpreter
97
+ env = NewEVM (BlockContext {}, TxContext {}, nil , params .TestChainConfig , Config {})
98
+ stack = newstack ()
99
+ pc = uint64 (0 )
100
+ interpreter = env .interpreter
99
101
)
100
102
101
103
for i , test := range tests {
@@ -104,7 +106,7 @@ func testTwoOperandOp(t *testing.T, tests []TwoOperandTestcase, opFn executionFu
104
106
expected := new (uint256.Int ).SetBytes (common .Hex2Bytes (test .Expected ))
105
107
stack .push (x )
106
108
stack .push (y )
107
- opFn (& pc , evmInterpreter , & ScopeContext {nil , stack , nil })
109
+ opFn (& pc , interpreter .( * EVMInterpreter ) , & ScopeContext {nil , stack , nil })
108
110
if len (stack .data ) != 1 {
109
111
t .Errorf ("Expected one item on stack after %v, got %d: " , name , len (stack .data ))
110
112
}
@@ -202,7 +204,8 @@ func TestAddMod(t *testing.T) {
202
204
z string
203
205
expected string
204
206
}{
205
- {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ,
207
+ {
208
+ "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ,
206
209
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe" ,
207
210
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ,
208
211
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe" ,
@@ -246,7 +249,7 @@ func TestWriteExpectedValues(t *testing.T) {
246
249
y := new (uint256.Int ).SetBytes (common .Hex2Bytes (param .y ))
247
250
stack .push (x )
248
251
stack .push (y )
249
- opFn (& pc , interpreter , & ScopeContext {nil , stack , nil })
252
+ opFn (& pc , interpreter .( * EVMInterpreter ) , & ScopeContext {nil , stack , nil })
250
253
actual := stack .pop ()
251
254
result [i ] = TwoOperandTestcase {param .x , param .y , fmt .Sprintf ("%064x" , actual )}
252
255
}
@@ -258,7 +261,7 @@ func TestWriteExpectedValues(t *testing.T) {
258
261
if err != nil {
259
262
t .Fatal (err )
260
263
}
261
- _ = os .WriteFile (fmt .Sprintf ("testdata/testcases_%v.json" , name ), data , 0644 )
264
+ _ = os .WriteFile (fmt .Sprintf ("testdata/testcases_%v.json" , name ), data , 0o644 )
262
265
if err != nil {
263
266
t .Fatal (err )
264
267
}
@@ -447,11 +450,13 @@ func BenchmarkOpEq(b *testing.B) {
447
450
448
451
opBenchmark (b , opEq , x , y )
449
452
}
453
+
450
454
func BenchmarkOpEq2 (b * testing.B ) {
451
455
x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
452
456
y := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201fffffffe"
453
457
opBenchmark (b , opEq , x , y )
454
458
}
459
+
455
460
func BenchmarkOpAnd (b * testing.B ) {
456
461
x := alphabetSoup
457
462
y := alphabetSoup
@@ -502,18 +507,21 @@ func BenchmarkOpSHL(b *testing.B) {
502
507
503
508
opBenchmark (b , opSHL , x , y )
504
509
}
510
+
505
511
func BenchmarkOpSHR (b * testing.B ) {
506
512
x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
507
513
y := "ff"
508
514
509
515
opBenchmark (b , opSHR , x , y )
510
516
}
517
+
511
518
func BenchmarkOpSAR (b * testing.B ) {
512
519
x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
513
520
y := "ff"
514
521
515
522
opBenchmark (b , opSAR , x , y )
516
523
}
524
+
517
525
func BenchmarkOpIsZero (b * testing.B ) {
518
526
x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
519
527
opBenchmark (b , opIszero , x )
@@ -673,12 +681,12 @@ func TestRandom(t *testing.T) {
673
681
{name : "hash(0x010203)" , random : crypto .Keccak256Hash ([]byte {0x01 , 0x02 , 0x03 })},
674
682
} {
675
683
var (
676
- env = NewEVM (BlockContext {Random : & tt .random }, TxContext {}, nil , params .TestChainConfig , Config {})
677
- stack = newstack ()
678
- pc = uint64 (0 )
679
- evmInterpreter = env .interpreter
684
+ env = NewEVM (BlockContext {Random : & tt .random }, TxContext {}, nil , params .TestChainConfig , Config {})
685
+ stack = newstack ()
686
+ pc = uint64 (0 )
687
+ interpreter = env .interpreter
680
688
)
681
- opRandom (& pc , evmInterpreter , & ScopeContext {nil , stack , nil })
689
+ opRandom (& pc , interpreter .( * EVMInterpreter ) , & ScopeContext {nil , stack , nil })
682
690
if len (stack .data ) != 1 {
683
691
t .Errorf ("Expected one item on stack after %v, got %d: " , tt .name , len (stack .data ))
684
692
}
0 commit comments