Skip to content

Commit

Permalink
Avoid a race condition where DeployContract() returns before PendingN…
Browse files Browse the repository at this point in the history
…once has been incremented (#15579)
  • Loading branch information
reductionista authored Dec 10, 2024
1 parent 9d8d9f4 commit 10ef5a4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/chains/evm/logpoller/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 10ef5a4

Please sign in to comment.