@@ -200,13 +200,51 @@ func TestTraceCall(t *testing.T) {
200
200
}
201
201
genBlocks := 10
202
202
signer := types.HomesteadSigner {}
203
+ nonce := uint64 (0 )
203
204
backend := newTestBackend (t , genBlocks , genesis , func (i int , b * core.BlockGen ) {
204
205
// Transfer from account[0] to account[1]
205
206
// value: 1000 wei
206
207
// fee: 0 wei
207
- tx , _ := types .SignTx (types .NewTransaction (uint64 (i ), accounts [1 ].addr , big .NewInt (1000 ), params .TxGas , b .BaseFee (), nil ), signer , accounts [0 ].key )
208
+ tx , _ := types .SignTx (types .NewTx (& types.LegacyTx {
209
+ Nonce : nonce ,
210
+ To : & accounts [1 ].addr ,
211
+ Value : big .NewInt (1000 ),
212
+ Gas : params .TxGas ,
213
+ GasPrice : b .BaseFee (),
214
+ Data : nil }),
215
+ signer , accounts [0 ].key )
208
216
b .AddTx (tx )
217
+ nonce ++
218
+
219
+ if i == genBlocks - 2 {
220
+ // Transfer from account[0] to account[2]
221
+ tx , _ = types .SignTx (types .NewTx (& types.LegacyTx {
222
+ Nonce : nonce ,
223
+ To : & accounts [2 ].addr ,
224
+ Value : big .NewInt (1000 ),
225
+ Gas : params .TxGas ,
226
+ GasPrice : b .BaseFee (),
227
+ Data : nil }),
228
+ signer , accounts [0 ].key )
229
+ b .AddTx (tx )
230
+ nonce ++
231
+
232
+ // Transfer from account[0] to account[1] again
233
+ tx , _ = types .SignTx (types .NewTx (& types.LegacyTx {
234
+ Nonce : nonce ,
235
+ To : & accounts [1 ].addr ,
236
+ Value : big .NewInt (1000 ),
237
+ Gas : params .TxGas ,
238
+ GasPrice : b .BaseFee (),
239
+ Data : nil }),
240
+ signer , accounts [0 ].key )
241
+ b .AddTx (tx )
242
+ nonce ++
243
+ }
209
244
})
245
+
246
+ uintPtr := func (i int ) * hexutil.Uint { x := hexutil .Uint (i ); return & x }
247
+
210
248
defer backend .teardown ()
211
249
api := NewAPI (backend )
212
250
var testSuite = []struct {
@@ -240,6 +278,51 @@ func TestTraceCall(t *testing.T) {
240
278
expectErr : nil ,
241
279
expect : `{"gas":21000,"failed":false,"returnValue":"","structLogs":[]}` ,
242
280
},
281
+ // Upon the last state, default to the post block's state
282
+ {
283
+ blockNumber : rpc .BlockNumber (genBlocks - 1 ),
284
+ call : ethapi.TransactionArgs {
285
+ From : & accounts [2 ].addr ,
286
+ To : & accounts [0 ].addr ,
287
+ Value : (* hexutil .Big )(new (big.Int ).Add (big .NewInt (params .Ether ), big .NewInt (100 ))),
288
+ },
289
+ config : nil ,
290
+ expect : `{"gas":21000,"failed":false,"returnValue":"","structLogs":[]}` ,
291
+ },
292
+ // Before the first transaction, should be failed
293
+ {
294
+ blockNumber : rpc .BlockNumber (genBlocks - 1 ),
295
+ call : ethapi.TransactionArgs {
296
+ From : & accounts [2 ].addr ,
297
+ To : & accounts [0 ].addr ,
298
+ Value : (* hexutil .Big )(new (big.Int ).Add (big .NewInt (params .Ether ), big .NewInt (100 ))),
299
+ },
300
+ config : & TraceCallConfig {TxIndex : uintPtr (0 )},
301
+ expectErr : fmt .Errorf ("tracing failed: insufficient funds for gas * price + value: address %s have 1000000000000000000 want 1000000000000000100" , accounts [2 ].addr ),
302
+ },
303
+ // Before the target transaction, should be failed
304
+ {
305
+ blockNumber : rpc .BlockNumber (genBlocks - 1 ),
306
+ call : ethapi.TransactionArgs {
307
+ From : & accounts [2 ].addr ,
308
+ To : & accounts [0 ].addr ,
309
+ Value : (* hexutil .Big )(new (big.Int ).Add (big .NewInt (params .Ether ), big .NewInt (100 ))),
310
+ },
311
+ config : & TraceCallConfig {TxIndex : uintPtr (1 )},
312
+ expectErr : fmt .Errorf ("tracing failed: insufficient funds for gas * price + value: address %s have 1000000000000000000 want 1000000000000000100" , accounts [2 ].addr ),
313
+ },
314
+ // After the target transaction, should be succeed
315
+ {
316
+ blockNumber : rpc .BlockNumber (genBlocks - 1 ),
317
+ call : ethapi.TransactionArgs {
318
+ From : & accounts [2 ].addr ,
319
+ To : & accounts [0 ].addr ,
320
+ Value : (* hexutil .Big )(new (big.Int ).Add (big .NewInt (params .Ether ), big .NewInt (100 ))),
321
+ },
322
+ config : & TraceCallConfig {TxIndex : uintPtr (2 )},
323
+ expectErr : nil ,
324
+ expect : `{"gas":21000,"failed":false,"returnValue":"","structLogs":[]}` ,
325
+ },
243
326
// Standard JSON trace upon the non-existent block, error expects
244
327
{
245
328
blockNumber : rpc .BlockNumber (genBlocks + 1 ),
@@ -297,8 +380,8 @@ func TestTraceCall(t *testing.T) {
297
380
t .Errorf ("test %d: expect error %v, got nothing" , i , testspec .expectErr )
298
381
continue
299
382
}
300
- if ! reflect .DeepEqual (err , testspec .expectErr ) {
301
- t .Errorf ("test %d: error mismatch, want %v, git %v " , i , testspec .expectErr , err )
383
+ if ! reflect .DeepEqual (err . Error () , testspec .expectErr . Error () ) {
384
+ t .Errorf ("test %d: error mismatch, want '%v', got '%v' " , i , testspec .expectErr , err )
302
385
}
303
386
} else {
304
387
if err != nil {
@@ -338,7 +421,14 @@ func TestTraceTransaction(t *testing.T) {
338
421
// Transfer from account[0] to account[1]
339
422
// value: 1000 wei
340
423
// fee: 0 wei
341
- tx , _ := types .SignTx (types .NewTransaction (uint64 (i ), accounts [1 ].addr , big .NewInt (1000 ), params .TxGas , b .BaseFee (), nil ), signer , accounts [0 ].key )
424
+ tx , _ := types .SignTx (types .NewTx (& types.LegacyTx {
425
+ Nonce : uint64 (i ),
426
+ To : & accounts [1 ].addr ,
427
+ Value : big .NewInt (1000 ),
428
+ Gas : params .TxGas ,
429
+ GasPrice : b .BaseFee (),
430
+ Data : nil }),
431
+ signer , accounts [0 ].key )
342
432
b .AddTx (tx )
343
433
target = tx .Hash ()
344
434
})
@@ -388,7 +478,14 @@ func TestTraceBlock(t *testing.T) {
388
478
// Transfer from account[0] to account[1]
389
479
// value: 1000 wei
390
480
// fee: 0 wei
391
- tx , _ := types .SignTx (types .NewTransaction (uint64 (i ), accounts [1 ].addr , big .NewInt (1000 ), params .TxGas , b .BaseFee (), nil ), signer , accounts [0 ].key )
481
+ tx , _ := types .SignTx (types .NewTx (& types.LegacyTx {
482
+ Nonce : uint64 (i ),
483
+ To : & accounts [1 ].addr ,
484
+ Value : big .NewInt (1000 ),
485
+ Gas : params .TxGas ,
486
+ GasPrice : b .BaseFee (),
487
+ Data : nil }),
488
+ signer , accounts [0 ].key )
392
489
b .AddTx (tx )
393
490
txHash = tx .Hash ()
394
491
})
@@ -478,7 +575,14 @@ func TestTracingWithOverrides(t *testing.T) {
478
575
// Transfer from account[0] to account[1]
479
576
// value: 1000 wei
480
577
// fee: 0 wei
481
- tx , _ := types .SignTx (types .NewTransaction (uint64 (i ), accounts [1 ].addr , big .NewInt (1000 ), params .TxGas , b .BaseFee (), nil ), signer , accounts [0 ].key )
578
+ tx , _ := types .SignTx (types .NewTx (& types.LegacyTx {
579
+ Nonce : uint64 (i ),
580
+ To : & accounts [1 ].addr ,
581
+ Value : big .NewInt (1000 ),
582
+ Gas : params .TxGas ,
583
+ GasPrice : b .BaseFee (),
584
+ Data : nil }),
585
+ signer , accounts [0 ].key )
482
586
b .AddTx (tx )
483
587
})
484
588
defer backend .chain .Stop ()
0 commit comments