@@ -58,8 +58,8 @@ func testCtx() *vmContext {
5858 return & vmContext {blockCtx : vm.BlockContext {BlockNumber : big .NewInt (1 )}, txCtx : vm.TxContext {GasPrice : big .NewInt (100000 )}}
5959}
6060
61- func runTrace (tracer * Tracer , vmctx * vmContext ) (json.RawMessage , error ) {
62- env := vm .NewEVM (vmctx .blockCtx , vmctx .txCtx , & dummyStatedb {}, params . TestChainConfig , vm.Config {Debug : true , Tracer : tracer })
61+ func runTrace (tracer * Tracer , vmctx * vmContext , chaincfg * params. ChainConfig ) (json.RawMessage , error ) {
62+ env := vm .NewEVM (vmctx .blockCtx , vmctx .txCtx , & dummyStatedb {}, chaincfg , vm.Config {Debug : true , Tracer : tracer })
6363 var (
6464 startGas uint64 = 10000
6565 value = big .NewInt (0 )
@@ -86,7 +86,7 @@ func TestTracer(t *testing.T) {
8686 ret , err := runTrace (tracer , & vmContext {
8787 blockCtx : vm.BlockContext {BlockNumber : big .NewInt (1 )},
8888 txCtx : vm.TxContext {GasPrice : big .NewInt (100000 )},
89- })
89+ }, params . TestChainConfig )
9090 if err != nil {
9191 return nil , err .Error () // Stringify to allow comparison without nil checks
9292 }
@@ -141,7 +141,7 @@ func TestHalt(t *testing.T) {
141141 time .Sleep (1 * time .Second )
142142 tracer .Stop (timeout )
143143 }()
144- if _ , err = runTrace (tracer , testCtx ()); err .Error () != "stahp in server-side tracer function 'step'" {
144+ if _ , err = runTrace (tracer , testCtx (), params . TestChainConfig ); err .Error () != "stahp in server-side tracer function 'step'" {
145145 t .Errorf ("Expected timeout error, got %v" , err )
146146 }
147147}
@@ -205,3 +205,34 @@ func TestNoStepExec(t *testing.T) {
205205 }
206206 }
207207}
208+
209+ func TestIsPrecompile (t * testing.T ) {
210+ chaincfg := & params.ChainConfig {ChainID : big .NewInt (1 ), HomesteadBlock : big .NewInt (0 ), DAOForkBlock : nil , DAOForkSupport : false , EIP150Block : big .NewInt (0 ), EIP150Hash : common.Hash {}, EIP155Block : big .NewInt (0 ), EIP158Block : big .NewInt (0 ), ByzantiumBlock : big .NewInt (100 ), ConstantinopleBlock : big .NewInt (0 ), PetersburgBlock : big .NewInt (0 ), IstanbulBlock : big .NewInt (200 ), MuirGlacierBlock : big .NewInt (0 ), BerlinBlock : big .NewInt (300 ), LondonBlock : big .NewInt (0 ), EWASMBlock : nil , CatalystBlock : nil , Ethash : new (params.EthashConfig ), Clique : nil }
211+ chaincfg .ByzantiumBlock = big .NewInt (100 )
212+ chaincfg .IstanbulBlock = big .NewInt (200 )
213+ chaincfg .BerlinBlock = big .NewInt (300 )
214+ txCtx := vm.TxContext {GasPrice : big .NewInt (100000 )}
215+ tracer , err := New ("{addr: toAddress('0000000000000000000000000000000000000009'), res: null, step: function() { this.res = isPrecompiled(this.addr); }, fault: function() {}, result: function() { return this.res; }}" , new (Context ))
216+ if err != nil {
217+ t .Fatal (err )
218+ }
219+
220+ blockCtx := vm.BlockContext {BlockNumber : big .NewInt (150 )}
221+ res , err := runTrace (tracer , & vmContext {blockCtx , txCtx }, chaincfg )
222+ if err != nil {
223+ t .Error (err )
224+ }
225+ if string (res ) != "false" {
226+ t .Errorf ("Tracer should not consider blake2f as precompile in byzantium" )
227+ }
228+
229+ tracer , _ = New ("{addr: toAddress('0000000000000000000000000000000000000009'), res: null, step: function() { this.res = isPrecompiled(this.addr); }, fault: function() {}, result: function() { return this.res; }}" , new (Context ))
230+ blockCtx = vm.BlockContext {BlockNumber : big .NewInt (250 )}
231+ res , err = runTrace (tracer , & vmContext {blockCtx , txCtx }, chaincfg )
232+ if err != nil {
233+ t .Error (err )
234+ }
235+ if string (res ) != "true" {
236+ t .Errorf ("Tracer should consider blake2f as precompile in istanbul" )
237+ }
238+ }
0 commit comments