From 8a2aff3d91e8c40b07368c2734322a6a766a917a Mon Sep 17 00:00:00 2001 From: Devon Bear Date: Sat, 21 Oct 2023 03:03:20 -0400 Subject: [PATCH] fix(localnet): Fix race condition in test (#1241) --- e2e/localnet/network/fixture_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/e2e/localnet/network/fixture_test.go b/e2e/localnet/network/fixture_test.go index e5976e679..8421c18b8 100644 --- a/e2e/localnet/network/fixture_test.go +++ b/e2e/localnet/network/fixture_test.go @@ -190,19 +190,29 @@ var _ = Describe("JSON RPC tests", func() { Expect(tf.WaitForNextBlock()).To(Succeed()) // send a transaction and make sure pending nonce is incremented - _, err = contract.ConsumeGas(tf.GenerateTransactOpts("alice"), big.NewInt(10000)) + var tx *coretypes.Transaction + tx, err = contract.ConsumeGas(tf.GenerateTransactOpts("alice"), big.NewInt(10000)) Expect(err).NotTo(HaveOccurred()) + + // Pending nonce should be 1 more than the current nonce alicePendingNonce, err := client.PendingNonceAt(context.Background(), tf.Address("alice")) Expect(err).NotTo(HaveOccurred()) Expect(alicePendingNonce).To(Equal(aliceCurrNonce + 1)) + + // The nonce on disk should still be equal to the nonce prior to the consume gas txn + // being included in a block. acn, err := client.NonceAt(context.Background(), tf.Address("alice"), nil) Expect(err).NotTo(HaveOccurred()) Expect(acn).To(Equal(aliceCurrNonce)) - Expect(tf.WaitForNextBlock()).To(Succeed()) + // Wait for block inclusion. + ExpectSuccessReceipt(client, tx) + // NonceAt and PendingNonce should be equal after inclusion aliceCurrNonce, err = client.NonceAt(context.Background(), tf.Address("alice"), nil) Expect(err).NotTo(HaveOccurred()) + alicePendingNonce, err = client.PendingNonceAt(context.Background(), tf.Address("alice")) + Expect(err).NotTo(HaveOccurred()) Expect(aliceCurrNonce).To(Equal(alicePendingNonce)) })