@@ -202,13 +202,12 @@ func TestTraceCall(t *testing.T) {
202202 tx , _ := types .SignTx (types .NewTransaction (uint64 (i ), accounts [1 ].addr , big .NewInt (1000 ), params .TxGas , b .BaseFee (), nil ), signer , accounts [0 ].key )
203203 b .AddTx (tx )
204204 }))
205-
206205 var testSuite = []struct {
207206 blockNumber rpc.BlockNumber
208207 call ethapi.TransactionArgs
209208 config * TraceCallConfig
210209 expectErr error
211- expect interface {}
210+ expect string
212211 }{
213212 // Standard JSON trace upon the genesis, plain transfer.
214213 {
@@ -220,12 +219,7 @@ func TestTraceCall(t *testing.T) {
220219 },
221220 config : nil ,
222221 expectErr : nil ,
223- expect : & logger.ExecutionResult {
224- Gas : params .TxGas ,
225- Failed : false ,
226- ReturnValue : "" ,
227- StructLogs : []logger.StructLogRes {},
228- },
222+ expect : `{"gas":21000,"failed":false,"returnValue":"","structLogs":[]}` ,
229223 },
230224 // Standard JSON trace upon the head, plain transfer.
231225 {
@@ -237,12 +231,7 @@ func TestTraceCall(t *testing.T) {
237231 },
238232 config : nil ,
239233 expectErr : nil ,
240- expect : & logger.ExecutionResult {
241- Gas : params .TxGas ,
242- Failed : false ,
243- ReturnValue : "" ,
244- StructLogs : []logger.StructLogRes {},
245- },
234+ expect : `{"gas":21000,"failed":false,"returnValue":"","structLogs":[]}` ,
246235 },
247236 // Standard JSON trace upon the non-existent block, error expects
248237 {
@@ -254,7 +243,7 @@ func TestTraceCall(t *testing.T) {
254243 },
255244 config : nil ,
256245 expectErr : fmt .Errorf ("block #%d not found" , genBlocks + 1 ),
257- expect : nil ,
246+ // expect: nil,
258247 },
259248 // Standard JSON trace upon the latest block
260249 {
@@ -266,14 +255,9 @@ func TestTraceCall(t *testing.T) {
266255 },
267256 config : nil ,
268257 expectErr : nil ,
269- expect : & logger.ExecutionResult {
270- Gas : params .TxGas ,
271- Failed : false ,
272- ReturnValue : "" ,
273- StructLogs : []logger.StructLogRes {},
274- },
258+ expect : `{"gas":21000,"failed":false,"returnValue":"","structLogs":[]}` ,
275259 },
276- // Standard JSON trace upon the pending block
260+ // Tracing on ' pending' should fail:
277261 {
278262 blockNumber : rpc .PendingBlockNumber ,
279263 call : ethapi.TransactionArgs {
@@ -282,36 +266,48 @@ func TestTraceCall(t *testing.T) {
282266 Value : (* hexutil .Big )(big .NewInt (1000 )),
283267 },
284268 config : nil ,
285- expectErr : nil ,
286- expect : & logger.ExecutionResult {
287- Gas : params .TxGas ,
288- Failed : false ,
289- ReturnValue : "" ,
290- StructLogs : []logger.StructLogRes {},
269+ expectErr : errors .New ("tracing on top of pending is not supported" ),
270+ },
271+ {
272+ blockNumber : rpc .LatestBlockNumber ,
273+ call : ethapi.TransactionArgs {
274+ From : & accounts [0 ].addr ,
275+ Input : & hexutil.Bytes {0x43 }, // blocknumber
276+ },
277+ config : & TraceCallConfig {
278+ BlockOverrides : & ethapi.BlockOverrides {Number : (* hexutil .Big )(big .NewInt (0x1337 ))},
291279 },
280+ expectErr : nil ,
281+ expect : ` {"gas":53018,"failed":false,"returnValue":"","structLogs":[
282+ {"pc":0,"op":"NUMBER","gas":24946984,"gasCost":2,"depth":1,"stack":[]},
283+ {"pc":1,"op":"STOP","gas":24946982,"gasCost":0,"depth":1,"stack":["0x1337"]}]}` ,
292284 },
293285 }
294- for _ , testspec := range testSuite {
286+ for i , testspec := range testSuite {
295287 result , err := api .TraceCall (context .Background (), testspec .call , rpc.BlockNumberOrHash {BlockNumber : & testspec .blockNumber }, testspec .config )
296288 if testspec .expectErr != nil {
297289 if err == nil {
298- t .Errorf ("Expect error %v, get nothing" , testspec .expectErr )
290+ t .Errorf ("test %d: expect error %v, got nothing" , i , testspec .expectErr )
299291 continue
300292 }
301293 if ! reflect .DeepEqual (err , testspec .expectErr ) {
302- t .Errorf ("Error mismatch, want %v, get %v" , testspec .expectErr , err )
294+ t .Errorf ("test %d: error mismatch, want %v, git %v" , i , testspec .expectErr , err )
303295 }
304296 } else {
305297 if err != nil {
306- t .Errorf ("Expect no error, get %v" , err )
298+ t .Errorf ("test %d: expect no error, got %v" , i , err )
307299 continue
308300 }
309301 var have * logger.ExecutionResult
310302 if err := json .Unmarshal (result .(json.RawMessage ), & have ); err != nil {
311- t .Errorf ("failed to unmarshal result %v" , err )
303+ t .Errorf ("test %d: failed to unmarshal result %v" , i , err )
304+ }
305+ var want * logger.ExecutionResult
306+ if err := json .Unmarshal ([]byte (testspec .expect ), & want ); err != nil {
307+ t .Errorf ("test %d: failed to unmarshal result %v" , i , err )
312308 }
313- if ! reflect .DeepEqual (have , testspec . expect ) {
314- t .Errorf ("Result mismatch, want %v, get %v" , testspec .expect , have )
309+ if ! reflect .DeepEqual (have , want ) {
310+ t .Errorf ("test %d: result mismatch, want %v, got %v" , i , testspec .expect , string ( result .(json. RawMessage )) )
315311 }
316312 }
317313 }
@@ -452,7 +448,7 @@ func TestTracingWithOverrides(t *testing.T) {
452448 type res struct {
453449 Gas int
454450 Failed bool
455- returnValue string
451+ ReturnValue string
456452 }
457453 var testSuite = []struct {
458454 blockNumber rpc.BlockNumber
@@ -463,7 +459,7 @@ func TestTracingWithOverrides(t *testing.T) {
463459 }{
464460 // Call which can only succeed if state is state overridden
465461 {
466- blockNumber : rpc .PendingBlockNumber ,
462+ blockNumber : rpc .LatestBlockNumber ,
467463 call : ethapi.TransactionArgs {
468464 From : & randomAccounts [0 ].addr ,
469465 To : & randomAccounts [1 ].addr ,
@@ -478,7 +474,7 @@ func TestTracingWithOverrides(t *testing.T) {
478474 },
479475 // Invalid call without state overriding
480476 {
481- blockNumber : rpc .PendingBlockNumber ,
477+ blockNumber : rpc .LatestBlockNumber ,
482478 call : ethapi.TransactionArgs {
483479 From : & randomAccounts [0 ].addr ,
484480 To : & randomAccounts [1 ].addr ,
@@ -504,7 +500,7 @@ func TestTracingWithOverrides(t *testing.T) {
504500 // }
505501 // }
506502 {
507- blockNumber : rpc .PendingBlockNumber ,
503+ blockNumber : rpc .LatestBlockNumber ,
508504 call : ethapi.TransactionArgs {
509505 From : & randomAccounts [0 ].addr ,
510506 To : & randomAccounts [2 ].addr ,
@@ -521,6 +517,39 @@ func TestTracingWithOverrides(t *testing.T) {
521517 },
522518 want : `{"gas":23347,"failed":false,"returnValue":"000000000000000000000000000000000000000000000000000000000000007b"}` ,
523519 },
520+ { // Override blocknumber
521+ blockNumber : rpc .LatestBlockNumber ,
522+ call : ethapi.TransactionArgs {
523+ From : & accounts [0 ].addr ,
524+ // BLOCKNUMBER PUSH1 MSTORE
525+ Input : newRPCBytes (common .Hex2Bytes ("4360005260206000f3" )),
526+ //&hexutil.Bytes{0x43}, // blocknumber
527+ },
528+ config : & TraceCallConfig {
529+ BlockOverrides : & ethapi.BlockOverrides {Number : (* hexutil .Big )(big .NewInt (0x1337 ))},
530+ },
531+ want : `{"gas":59537,"failed":false,"returnValue":"0000000000000000000000000000000000000000000000000000000000001337"}` ,
532+ },
533+ { // Override blocknumber, and query a blockhash
534+ blockNumber : rpc .LatestBlockNumber ,
535+ call : ethapi.TransactionArgs {
536+ From : & accounts [0 ].addr ,
537+ Input : & hexutil.Bytes {
538+ 0x60 , 0x00 , 0x40 , // BLOCKHASH(0)
539+ 0x60 , 0x00 , 0x52 , // STORE memory offset 0
540+ 0x61 , 0x13 , 0x36 , 0x40 , // BLOCKHASH(0x1336)
541+ 0x60 , 0x20 , 0x52 , // STORE memory offset 32
542+ 0x61 , 0x13 , 0x37 , 0x40 , // BLOCKHASH(0x1337)
543+ 0x60 , 0x40 , 0x52 , // STORE memory offset 64
544+ 0x60 , 0x60 , 0x60 , 0x00 , 0xf3 , // RETURN (0-96)
545+
546+ }, // blocknumber
547+ },
548+ config : & TraceCallConfig {
549+ BlockOverrides : & ethapi.BlockOverrides {Number : (* hexutil .Big )(big .NewInt (0x1337 ))},
550+ },
551+ want : `{"gas":72666,"failed":false,"returnValue":"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}` ,
552+ },
524553 }
525554 for i , tc := range testSuite {
526555 result , err := api .TraceCall (context .Background (), tc .call , rpc.BlockNumberOrHash {BlockNumber : & tc .blockNumber }, tc .config )
0 commit comments