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
  • Loading branch information
reductionista committed Dec 9, 2024
1 parent 75f9cf0 commit ce49b7a
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(int64(pendingNonce))

Check failure on line 125 in core/chains/evm/logpoller/helper_test.go

View workflow job for this annotation

GitHub Actions / lint

G115: integer overflow conversion uint64 -> int64 (gosec)
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 ce49b7a

Please sign in to comment.