diff --git a/ethclient/ethclient_test.go b/ethclient/ethclient_test.go index 0f87ad5f5cd3..209e12a34778 100644 --- a/ethclient/ethclient_test.go +++ b/ethclient/ethclient_test.go @@ -263,8 +263,8 @@ func TestEthClient(t *testing.T) { "BalanceAt": { func(t *testing.T) { testBalanceAt(t, client) }, }, - "TxInBlockInterrupted": { - func(t *testing.T) { testTransactionInBlockInterrupted(t, client) }, + "TxInBlock": { + func(t *testing.T) { testTransactionInBlock(t, client) }, }, "ChainID": { func(t *testing.T) { testChainID(t, client) }, @@ -381,7 +381,7 @@ func testBalanceAt(t *testing.T, client *rpc.Client) { } } -func testTransactionInBlockInterrupted(t *testing.T, client *rpc.Client) { +func testTransactionInBlock(t *testing.T, client *rpc.Client) { ec := NewClient(client) // Get current block by number. @@ -390,16 +390,20 @@ func testTransactionInBlockInterrupted(t *testing.T, client *rpc.Client) { t.Fatalf("unexpected error: %v", err) } - // Test tx in block interrupted. - ctx, cancel := context.WithCancel(context.Background()) - cancel() - <-ctx.Done() // Ensure the close of the Done channel - tx, err := ec.TransactionInBlock(ctx, block.Hash(), 0) - if tx != nil { - t.Fatal("transaction should be nil") + tx1, err := ec.TransactionInBlock(context.Background(), block.Hash(), 0) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if tx1.Hash() != testTx1.Hash() { + t.Fatalf("wrong tx hash %v, want %v", tx1.Hash(), testTx1.Hash()) + } + + tx2, err := ec.TransactionInBlock(context.Background(), block.Hash(), 1) + if err != nil { + t.Fatalf("unexpected error: %v", err) } - if err == nil || err == ethereum.NotFound { - t.Fatal("error should not be nil/notfound") + if tx2.Hash() != testTx2.Hash() { + t.Fatalf("wrong tx hash %v, want %v", tx2.Hash(), testTx2.Hash()) } // Test tx in block not found.