@@ -264,7 +264,7 @@ func TestEthClient(t *testing.T) {
264
264
func (t * testing.T ) { testBalanceAt (t , client ) },
265
265
},
266
266
"TxInBlockInterrupted" : {
267
- func (t * testing.T ) { testTransactionInBlockInterrupted (t , client ) },
267
+ func (t * testing.T ) { testTransactionInBlock (t , client ) },
268
268
},
269
269
"ChainID" : {
270
270
func (t * testing.T ) { testChainID (t , client ) },
@@ -329,7 +329,7 @@ func testHeader(t *testing.T, chain []*types.Block, client *rpc.Client) {
329
329
got .Number = big .NewInt (0 ) // hack to make DeepEqual work
330
330
}
331
331
if ! reflect .DeepEqual (got , tt .want ) {
332
- t .Fatalf ("HeaderByNumber(%v)\n = %v\n want %v" , tt .block , got , tt .want )
332
+ t .Fatalf ("HeaderByNumber(%v) got = %v, want %v" , tt .block , got , tt .want )
333
333
}
334
334
})
335
335
}
@@ -381,7 +381,7 @@ func testBalanceAt(t *testing.T, client *rpc.Client) {
381
381
}
382
382
}
383
383
384
- func testTransactionInBlockInterrupted (t * testing.T , client * rpc.Client ) {
384
+ func testTransactionInBlock (t * testing.T , client * rpc.Client ) {
385
385
ec := NewClient (client )
386
386
387
387
// Get current block by number.
@@ -390,22 +390,27 @@ func testTransactionInBlockInterrupted(t *testing.T, client *rpc.Client) {
390
390
t .Fatalf ("unexpected error: %v" , err )
391
391
}
392
392
393
- // Test tx in block interrupted.
394
- ctx , cancel := context .WithCancel (context .Background ())
395
- cancel ()
396
- <- ctx .Done () // Ensure the close of the Done channel
397
- tx , err := ec .TransactionInBlock (ctx , block .Hash (), 0 )
398
- if tx != nil {
399
- t .Fatal ("transaction should be nil" )
400
- }
401
- if err == nil || err == ethereum .NotFound {
402
- t .Fatal ("error should not be nil/notfound" )
403
- }
404
-
405
393
// Test tx in block not found.
406
394
if _ , err := ec .TransactionInBlock (context .Background (), block .Hash (), 20 ); err != ethereum .NotFound {
407
395
t .Fatal ("error should be ethereum.NotFound" )
408
396
}
397
+
398
+ // Test tx in block found.
399
+ tx , err := ec .TransactionInBlock (context .Background (), block .Hash (), 0 )
400
+ if err != nil {
401
+ t .Fatalf ("unexpected error: %v" , err )
402
+ }
403
+ if tx .Hash () != testTx1 .Hash () {
404
+ t .Fatalf ("unexpected transaction: %v" , tx )
405
+ }
406
+
407
+ tx , err = ec .TransactionInBlock (context .Background (), block .Hash (), 1 )
408
+ if err != nil {
409
+ t .Fatalf ("unexpected error: %v" , err )
410
+ }
411
+ if tx .Hash () != testTx2 .Hash () {
412
+ t .Fatalf ("unexpected transaction: %v" , tx )
413
+ }
409
414
}
410
415
411
416
func testChainID (t * testing.T , client * rpc.Client ) {
0 commit comments