From 2fcdffaef2a4bb7a8d2f147cd40095bec58ce261 Mon Sep 17 00:00:00 2001 From: kashitaka Date: Sun, 3 Aug 2025 00:47:42 +0900 Subject: [PATCH] ethclient: fix flaky pending tx test --- ethclient/ethclient_test.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ethclient/ethclient_test.go b/ethclient/ethclient_test.go index 8e70177944..3b9149f4e2 100644 --- a/ethclient/ethclient_test.go +++ b/ethclient/ethclient_test.go @@ -124,6 +124,18 @@ func newTestBackend(config *node.Config) (*node.Node, []*types.Block, error) { break } } + // Wait until the pending nonce reflects all submitted transactions + numTxs := 0 + for _, block := range blocks[1:] { + numTxs += len(block.Transactions()) + } + for ; ; time.Sleep(time.Millisecond * 100) { + pendingNonceAt, err := ethservice.APIBackend.GetPoolNonce(context.Background(), testAddr) + if err == nil && pendingNonceAt == uint64(numTxs) { + break + } + } + return n, blocks, nil } @@ -506,8 +518,9 @@ func testAtFunctions(t *testing.T, client *rpc.Client) { } // send a transaction for some interesting pending status - // and wait for the transaction to be included in the pending block - sendTransaction(ec) + if err = sendTransaction(ec); err != nil { + t.Fatalf("unexpected error: %v", err) + } // wait for the transaction to be included in the pending block for {