diff --git a/core/vm/celo_contracts_test.go b/core/vm/celo_contracts_test.go index 59f2d3faa9..b92c15d77f 100644 --- a/core/vm/celo_contracts_test.go +++ b/core/vm/celo_contracts_test.go @@ -50,3 +50,5 @@ var mockEVM = &EVM{ Context: vmBlockCtx, TxContext: vmTxCtx, } + +var mockPrecompileContext = NewContext(common.HexToAddress("1337"), mockEVM) diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index fc60147363..ecfe566d40 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -96,7 +96,7 @@ func testPrecompiled(addr string, test precompiledTest, t *testing.T) { in := common.Hex2Bytes(test.Input) gas := p.RequiredGas(in) t.Run(fmt.Sprintf("%s-Gas=%d", test.Name, gas), func(t *testing.T) { - if res, _, err := RunPrecompiledContract(p, in, gas, NewContext(common.HexToAddress("1337"), mockEVM)); err != nil { + if res, _, err := RunPrecompiledContract(p, in, gas, mockPrecompileContext); err != nil { t.Error(err) } else if common.Bytes2Hex(res) != test.Expected { t.Errorf("Expected %v, got %v", test.Expected, common.Bytes2Hex(res)) @@ -118,7 +118,7 @@ func testPrecompiledOOG(addr string, test precompiledTest, t *testing.T) { gas := p.RequiredGas(in) - 1 t.Run(fmt.Sprintf("%s-Gas=%d", test.Name, gas), func(t *testing.T) { - _, _, err := RunPrecompiledContract(p, in, gas, NewContext(common.HexToAddress("1337"), mockEVM)) + _, _, err := RunPrecompiledContract(p, in, gas, mockPrecompileContext) if err.Error() != "out of gas" { t.Errorf("Expected error [out of gas], got [%v]", err) } @@ -135,7 +135,7 @@ func testPrecompiledFailure(addr string, test precompiledFailureTest, t *testing in := common.Hex2Bytes(test.Input) gas := p.RequiredGas(in) t.Run(test.Name, func(t *testing.T) { - _, _, err := RunPrecompiledContract(p, in, gas, NewContext(common.HexToAddress("1337"), mockEVM)) + _, _, err := RunPrecompiledContract(p, in, gas, mockPrecompileContext) if err.Error() != test.ExpectedError { t.Errorf("Expected error [%v], got [%v]", test.ExpectedError, err) } @@ -167,7 +167,7 @@ func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) { bench.ResetTimer() for i := 0; i < bench.N; i++ { copy(data, in) - res, _, err = RunPrecompiledContract(p, data, reqGas, NewContext(common.HexToAddress("1337"), mockEVM)) + res, _, err = RunPrecompiledContract(p, data, reqGas, mockPrecompileContext) } bench.StopTimer() elapsed := uint64(time.Since(start))