@@ -25,6 +25,7 @@ import (
25
25
"time"
26
26
27
27
"github.com/ethereum/go-ethereum/common"
28
+ "github.com/ethereum/go-ethereum/params"
28
29
"github.com/holiman/uint256"
29
30
)
30
31
@@ -97,7 +98,8 @@ func testPrecompiled(addr string, test precompiledTest, t *testing.T) {
97
98
in := common .Hex2Bytes (test .Input )
98
99
gas := p .RequiredGas (in )
99
100
t .Run (fmt .Sprintf ("%s-Gas=%d" , test .Name , gas ), func (t * testing.T ) {
100
- if res , _ , err := runPrecompiledContract (nil , p , common.Address {}, in , gas , new (uint256.Int ), false ); err != nil {
101
+ evm := NewEVM (BlockContext {}, nil , params .TestChainConfig , Config {})
102
+ if res , _ , err := runPrecompiledContract (evm , p , common.Address {}, in , gas , new (uint256.Int ), false ); err != nil {
101
103
t .Error (err )
102
104
} else if common .Bytes2Hex (res ) != test .Expected {
103
105
t .Errorf ("Expected %v, got %v" , test .Expected , common .Bytes2Hex (res ))
@@ -119,7 +121,8 @@ func testPrecompiledOOG(addr string, test precompiledTest, t *testing.T) {
119
121
gas := p .RequiredGas (in ) - 1
120
122
121
123
t .Run (fmt .Sprintf ("%s-Gas=%d" , test .Name , gas ), func (t * testing.T ) {
122
- _ , _ , err := runPrecompiledContract (nil , p , common.Address {}, in , gas , new (uint256.Int ), false )
124
+ evm := NewEVM (BlockContext {}, nil , params .TestChainConfig , Config {})
125
+ _ , _ , err := runPrecompiledContract (evm , p , common.Address {}, in , gas , new (uint256.Int ), false )
123
126
if err .Error () != "out of gas" {
124
127
t .Errorf ("Expected error [out of gas], got [%v]" , err )
125
128
}
@@ -136,7 +139,8 @@ func testPrecompiledFailure(addr string, test precompiledFailureTest, t *testing
136
139
in := common .Hex2Bytes (test .Input )
137
140
gas := p .RequiredGas (in )
138
141
t .Run (test .Name , func (t * testing.T ) {
139
- _ , _ , err := runPrecompiledContract (nil , p , common.Address {}, in , gas , new (uint256.Int ), false )
142
+ evm := NewEVM (BlockContext {}, nil , params .TestChainConfig , Config {})
143
+ _ , _ , err := runPrecompiledContract (evm , p , common.Address {}, in , gas , new (uint256.Int ), false )
140
144
if err .Error () != test .ExpectedError {
141
145
t .Errorf ("Expected error [%v], got [%v]" , test .ExpectedError , err )
142
146
}
@@ -166,9 +170,10 @@ func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) {
166
170
bench .ReportAllocs ()
167
171
start := time .Now ()
168
172
bench .ResetTimer ()
173
+ evm := NewEVM (BlockContext {}, nil , params .TestChainConfig , Config {})
169
174
for i := 0 ; i < bench .N ; i ++ {
170
175
copy (data , in )
171
- res , _ , err = runPrecompiledContract (nil , p , common.Address {}, in , reqGas , new (uint256.Int ), false )
176
+ res , _ , err = runPrecompiledContract (evm , p , common.Address {}, in , reqGas , new (uint256.Int ), false )
172
177
}
173
178
bench .StopTimer ()
174
179
elapsed := uint64 (time .Since (start ))
0 commit comments