@@ -21,7 +21,6 @@ import (
21
21
"encoding/json"
22
22
"fmt"
23
23
"io/ioutil"
24
- "math/big"
25
24
"testing"
26
25
"time"
27
26
@@ -72,10 +71,9 @@ var blake2FMalformedInputTests = []precompiledFailureTest{
72
71
func testPrecompiled (addr string , test precompiledTest , t * testing.T ) {
73
72
p := allPrecompiles [common .HexToAddress (addr )]
74
73
in := common .Hex2Bytes (test .Input )
75
- contract := NewContract (AccountRef (common .HexToAddress ("1337" )),
76
- nil , new (big.Int ), p .RequiredGas (in ))
77
- t .Run (fmt .Sprintf ("%s-Gas=%d" , test .Name , contract .Gas ), func (t * testing.T ) {
78
- if res , err := RunPrecompiledContract (p , in , contract ); err != nil {
74
+ gas := p .RequiredGas (in )
75
+ t .Run (fmt .Sprintf ("%s-Gas=%d" , test .Name , gas ), func (t * testing.T ) {
76
+ if res , _ , err := RunPrecompiledContract (p , in , gas ); err != nil {
79
77
t .Error (err )
80
78
} else if common .Bytes2Hex (res ) != test .Expected {
81
79
t .Errorf ("Expected %v, got %v" , test .Expected , common .Bytes2Hex (res ))
@@ -91,10 +89,10 @@ func testPrecompiled(addr string, test precompiledTest, t *testing.T) {
91
89
func testPrecompiledOOG (addr string , test precompiledTest , t * testing.T ) {
92
90
p := allPrecompiles [common .HexToAddress (addr )]
93
91
in := common .Hex2Bytes (test .Input )
94
- contract := NewContract ( AccountRef ( common . HexToAddress ( "1337" )),
95
- nil , new (big. Int ), p . RequiredGas ( in ) - 1 )
96
- t .Run (fmt .Sprintf ("%s-Gas=%d" , test .Name , contract . Gas ), func (t * testing.T ) {
97
- _ , err := RunPrecompiledContract (p , in , contract )
92
+ gas := p . RequiredGas ( in ) - 1
93
+
94
+ t .Run (fmt .Sprintf ("%s-Gas=%d" , test .Name , gas ), func (t * testing.T ) {
95
+ _ , _ , err := RunPrecompiledContract (p , in , gas )
98
96
if err .Error () != "out of gas" {
99
97
t .Errorf ("Expected error [out of gas], got [%v]" , err )
100
98
}
@@ -109,11 +107,9 @@ func testPrecompiledOOG(addr string, test precompiledTest, t *testing.T) {
109
107
func testPrecompiledFailure (addr string , test precompiledFailureTest , t * testing.T ) {
110
108
p := allPrecompiles [common .HexToAddress (addr )]
111
109
in := common .Hex2Bytes (test .Input )
112
- contract := NewContract (AccountRef (common .HexToAddress ("31337" )),
113
- nil , new (big.Int ), p .RequiredGas (in ))
114
-
110
+ gas := p .RequiredGas (in )
115
111
t .Run (test .Name , func (t * testing.T ) {
116
- _ , err := RunPrecompiledContract (p , in , contract )
112
+ _ , _ , err := RunPrecompiledContract (p , in , gas )
117
113
if err .Error () != test .ExpectedError {
118
114
t .Errorf ("Expected error [%v], got [%v]" , test .ExpectedError , err )
119
115
}
@@ -132,23 +128,20 @@ func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) {
132
128
p := allPrecompiles [common .HexToAddress (addr )]
133
129
in := common .Hex2Bytes (test .Input )
134
130
reqGas := p .RequiredGas (in )
135
- contract := NewContract (AccountRef (common .HexToAddress ("1337" )),
136
- nil , new (big.Int ), reqGas )
137
131
138
132
var (
139
133
res []byte
140
134
err error
141
135
data = make ([]byte , len (in ))
142
136
)
143
137
144
- bench .Run (fmt .Sprintf ("%s-Gas=%d" , test .Name , contract . Gas ), func (bench * testing.B ) {
138
+ bench .Run (fmt .Sprintf ("%s-Gas=%d" , test .Name , reqGas ), func (bench * testing.B ) {
145
139
bench .ReportAllocs ()
146
140
start := time .Now ().Nanosecond ()
147
141
bench .ResetTimer ()
148
142
for i := 0 ; i < bench .N ; i ++ {
149
- contract .Gas = reqGas
150
143
copy (data , in )
151
- res , err = RunPrecompiledContract (p , data , contract )
144
+ res , _ , err = RunPrecompiledContract (p , data , reqGas )
152
145
}
153
146
bench .StopTimer ()
154
147
elapsed := float64 (time .Now ().Nanosecond () - start )
0 commit comments