@@ -21,7 +21,6 @@ import (
2121 "encoding/json"
2222 "fmt"
2323 "io/ioutil"
24- "math/big"
2524 "testing"
2625 "time"
2726
@@ -72,10 +71,9 @@ var blake2FMalformedInputTests = []precompiledFailureTest{
7271func testPrecompiled (addr string , test precompiledTest , t * testing.T ) {
7372 p := allPrecompiles [common .HexToAddress (addr )]
7473 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 {
7977 t .Error (err )
8078 } else if common .Bytes2Hex (res ) != test .Expected {
8179 t .Errorf ("Expected %v, got %v" , test .Expected , common .Bytes2Hex (res ))
@@ -91,10 +89,10 @@ func testPrecompiled(addr string, test precompiledTest, t *testing.T) {
9189func testPrecompiledOOG (addr string , test precompiledTest , t * testing.T ) {
9290 p := allPrecompiles [common .HexToAddress (addr )]
9391 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 )
9896 if err .Error () != "out of gas" {
9997 t .Errorf ("Expected error [out of gas], got [%v]" , err )
10098 }
@@ -109,11 +107,9 @@ func testPrecompiledOOG(addr string, test precompiledTest, t *testing.T) {
109107func testPrecompiledFailure (addr string , test precompiledFailureTest , t * testing.T ) {
110108 p := allPrecompiles [common .HexToAddress (addr )]
111109 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 )
115111 t .Run (test .Name , func (t * testing.T ) {
116- _ , err := RunPrecompiledContract (p , in , contract )
112+ _ , _ , err := RunPrecompiledContract (p , in , gas )
117113 if err .Error () != test .ExpectedError {
118114 t .Errorf ("Expected error [%v], got [%v]" , test .ExpectedError , err )
119115 }
@@ -132,23 +128,20 @@ func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) {
132128 p := allPrecompiles [common .HexToAddress (addr )]
133129 in := common .Hex2Bytes (test .Input )
134130 reqGas := p .RequiredGas (in )
135- contract := NewContract (AccountRef (common .HexToAddress ("1337" )),
136- nil , new (big.Int ), reqGas )
137131
138132 var (
139133 res []byte
140134 err error
141135 data = make ([]byte , len (in ))
142136 )
143137
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 ) {
145139 bench .ReportAllocs ()
146140 start := time .Now ().Nanosecond ()
147141 bench .ResetTimer ()
148142 for i := 0 ; i < bench .N ; i ++ {
149- contract .Gas = reqGas
150143 copy (data , in )
151- res , err = RunPrecompiledContract (p , data , contract )
144+ res , _ , err = RunPrecompiledContract (p , data , reqGas )
152145 }
153146 bench .StopTimer ()
154147 elapsed := float64 (time .Now ().Nanosecond () - start )
0 commit comments