From f630426b1202e83f965d11291c3adf9c5f91ef71 Mon Sep 17 00:00:00 2001 From: Domino Valdano <2644901+reductionista@users.noreply.github.com> Date: Mon, 9 Dec 2024 13:21:05 -0800 Subject: [PATCH] Avoid a race condition where DeployContract() returns before PendingNonce has been incremented --- core/chains/evm/logpoller/helper_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/chains/evm/logpoller/helper_test.go b/core/chains/evm/logpoller/helper_test.go index 947a839521c..b8d849d7d83 100644 --- a/core/chains/evm/logpoller/helper_test.go +++ b/core/chains/evm/logpoller/helper_test.go @@ -118,11 +118,19 @@ func SetupTH(t testing.TB, opts logpoller.Opts) TestHarness { opts.PollPeriod = 1 * time.Hour } lp := logpoller.NewLogPoller(o, esc, lggr, headTracker, opts) + + pendingNonce, err := backend.Client().PendingNonceAt(testutils.Context(t), owner.From) + require.NoError(t, err) + + owner.Nonce = big.NewInt(0).SetUint64(pendingNonce) emitterAddress1, _, emitter1, err := log_emitter.DeployLogEmitter(owner, backend.Client()) require.NoError(t, err) + + owner.Nonce.Add(owner.Nonce, big.NewInt(1)) // Avoid race where DeployLogEmitter returns before PendingNonce has been incremented emitterAddress2, _, emitter2, err := log_emitter.DeployLogEmitter(owner, backend.Client()) require.NoError(t, err) backend.Commit() + owner.Nonce = nil // Just use pending nonce after this return TestHarness{ Lggr: lggr,