Skip to content

Commit f6360f3

Browse files
committed
test: cover nonceBounds pending fallback branches (F-2026-18191)
1 parent 6554a0a commit f6360f3

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

universalClient/tss/sessionmanager/sessionmanager_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"encoding/hex"
77
"encoding/json"
8+
"errors"
89
"fmt"
910
"math/big"
1011
"reflect"
@@ -1401,3 +1402,54 @@ func TestCheckNonceInRange(t *testing.T) {
14011402
require.NoError(t, checkNonceInRange(0, 0, 0, "solana:devnet"))
14021403
})
14031404
}
1405+
1406+
// nonceBuilder is a partial TxBuilder: only GetNextNonce is implemented, so any
1407+
// other call panics loudly rather than silently returning a zero value.
1408+
type nonceBuilder struct {
1409+
common.TxBuilder
1410+
finalized, pending uint64
1411+
finalizedErr, pendingErr error
1412+
}
1413+
1414+
func (b *nonceBuilder) GetNextNonce(_ context.Context, _ string, useFinalized bool) (uint64, error) {
1415+
if useFinalized {
1416+
return b.finalized, b.finalizedErr
1417+
}
1418+
return b.pending, b.pendingErr
1419+
}
1420+
1421+
func TestNonceBounds(t *testing.T) {
1422+
ctx := context.Background()
1423+
1424+
t.Run("pending above finalized becomes the ceiling base", func(t *testing.T) {
1425+
fin, base, err := nonceBounds(ctx, &nonceBuilder{finalized: 100, pending: 140}, "0xtss")
1426+
require.NoError(t, err)
1427+
assert.Equal(t, uint64(100), fin)
1428+
assert.Equal(t, uint64(140), base)
1429+
})
1430+
1431+
// Falling back to finalized is stricter, never wrong.
1432+
t.Run("pending lookup failure falls back to finalized", func(t *testing.T) {
1433+
fin, base, err := nonceBounds(ctx, &nonceBuilder{
1434+
finalized: 100,
1435+
pendingErr: errors.New("rpc down"),
1436+
}, "0xtss")
1437+
require.NoError(t, err)
1438+
assert.Equal(t, uint64(100), fin)
1439+
assert.Equal(t, uint64(100), base)
1440+
})
1441+
1442+
// A stale pending read must never lower the ceiling below finalized.
1443+
t.Run("pending below finalized falls back to finalized", func(t *testing.T) {
1444+
fin, base, err := nonceBounds(ctx, &nonceBuilder{finalized: 100, pending: 60}, "0xtss")
1445+
require.NoError(t, err)
1446+
assert.Equal(t, uint64(100), fin)
1447+
assert.Equal(t, uint64(100), base)
1448+
})
1449+
1450+
// Callers skip the nonce check entirely when finalized is unavailable.
1451+
t.Run("finalized lookup failure errors", func(t *testing.T) {
1452+
_, _, err := nonceBounds(ctx, &nonceBuilder{finalizedErr: errors.New("rpc down")}, "0xtss")
1453+
require.Error(t, err)
1454+
})
1455+
}

0 commit comments

Comments
 (0)