Skip to content

Commit ced51e7

Browse files
author
Jeff Yanta
committed
Add more edge case tests
1 parent 3b206f8 commit ced51e7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

pkg/code/transaction/nonce_pool.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,15 @@ func NewLocalNoncePool(
284284
refreshPoolCh: make(chan struct{}),
285285
}
286286

287-
np.workerCtx, np.cancelWorkerCtx = context.WithCancel(context.Background())
288-
289287
for _, o := range opts {
290288
o(&np.opts)
291289
}
292-
293290
if err := np.opts.validate(); err != nil {
294-
np.cancelWorkerCtx()
295291
return nil, err
296292
}
297293

294+
np.workerCtx, np.cancelWorkerCtx = context.WithCancel(context.Background())
295+
298296
_, err := np.load(np.workerCtx, np.opts.desiredPoolSize)
299297
switch err {
300298
case nil, nonce.ErrNonceNotFound:

pkg/code/transaction/nonce_pool_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,22 @@ func testLocalNoncePoolReserveWithSignatureEdgeCases(nt *localNoncePoolTest) {
234234
require.NoError(nt.t, err)
235235
require.Equal(nt.t, actual.State, nonce.StateReserved)
236236
require.Equal(nt.t, actual.Signature, "signature1")
237+
238+
n, err = nt.pool.GetNonce(ctx)
239+
require.NoError(nt.t, err)
240+
require.NotNil(nt.t, n)
241+
242+
n.record.State = nonce.StateUnknown
243+
n.record.ClaimNodeID = nil
244+
n.record.ClaimExpiresAt = nil
245+
require.NoError(nt.t, nt.data.SaveNonce(ctx, n.record))
246+
247+
require.Error(nt.t, n.MarkReservedWithSignature(ctx, "signature3"))
248+
249+
actual, err = nt.data.GetNonce(ctx, n.record.Address)
250+
require.NoError(nt.t, err)
251+
require.Equal(nt.t, actual.State, nonce.StateUnknown)
252+
require.Empty(nt.t, actual.Signature)
237253
}
238254

239255
type localNoncePoolTest struct {

0 commit comments

Comments
 (0)