Skip to content

Commit 11db662

Browse files
fix(devenv): harden tests by checking how many sends are left before getting next holdings
1 parent 1595e87 commit 11db662

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

ccip/devenv/impl.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ type Chain struct {
225225
nextFeeCID string // holding CID to be used as fee on next message send
226226
transferTokenInstrument *splice_api_token_holding_v1.InstrumentId
227227
nextTransferCID string // holding CID to be used as transfer on next message send
228+
rotationEndSeq uint64 // last on-chain seq in current setup batch; 0 = always rotate
228229

229230
// verifierObs is injected post-construction by test runners (see SetVerifierObservation).
230231
// Required by ConfirmExecOnDest to fetch verifier results from indexer (aggregator optional).
@@ -1113,6 +1114,17 @@ func (c *Chain) SetupSend(
11131114
return nil
11141115
}
11151116

1117+
// SetSequentialSends limits holding rotation to the next sends messages in this setup batch.
1118+
// After the send whose on-chain seq equals nextSeq+sends, setNextHoldings is skipped.
1119+
// Pass 0 to always rotate (open-ended load).
1120+
func (c *Chain) SetSequentialSends(sends int) {
1121+
if sends <= 0 {
1122+
c.rotationEndSeq = 0
1123+
return
1124+
}
1125+
c.rotationEndSeq = uint64(sends)
1126+
}
1127+
11161128
// MintTokens mint tokens for transfer and fees. To be used on devenv tests only.
11171129
// this method won't work in staging/prod tests
11181130
func (c *Chain) MintTokens(ctx context.Context, amount *big.Rat) error {
@@ -1451,12 +1463,6 @@ func (c *Chain) SendMessage(ctx context.Context, dest uint64, fields cciptestint
14511463
Uint64("seqNo", parsedSend.seqNo).
14521464
Msg("CCIP Send executed")
14531465

1454-
// Set next holdings
1455-
err = c.setNextHoldings(update.GetTransaction().GetEvents(), hasTokenTransfer, new(big.Rat).SetFrac(fields.TokenAmount.Amount, big.NewInt(CantonFixedPointScale)))
1456-
if err != nil {
1457-
return cciptestinterfaces.MessageSentEvent{}, fmt.Errorf("set next holdings: %w", err)
1458-
}
1459-
14601466
event := cciptestinterfaces.MessageSentEvent{
14611467
MessageID: parsedSend.messageID,
14621468
ReceiptIssuers: nil, // TODO: add them later, not currently needed
@@ -1469,6 +1475,21 @@ func (c *Chain) SendMessage(ctx context.Context, dest uint64, fields cciptestint
14691475
c.lastSentSeq = parsedSend.seqNo
14701476
c.lastSentEvent = event
14711477

1478+
// Case it's the last send
1479+
if c.rotationEndSeq == 0 {
1480+
c.logger.Info().
1481+
Uint64("rotationEndSeq", c.rotationEndSeq).
1482+
Msg("Skipping holding rotation after last planned send in batch")
1483+
1484+
return event, nil
1485+
}
1486+
1487+
c.rotationEndSeq--
1488+
err = c.setNextHoldings(update.GetTransaction().GetEvents(), hasTokenTransfer, new(big.Rat).SetFrac(fields.TokenAmount.Amount, big.NewInt(CantonFixedPointScale)))
1489+
if err != nil {
1490+
return cciptestinterfaces.MessageSentEvent{}, fmt.Errorf("set next holdings: %w", err)
1491+
}
1492+
14721493
return event, nil
14731494
}
14741495

ccip/devenv/tests/helpers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ func (b E2EBootstrap) SetupCantonSend(t *testing.T, ctx context.Context, transfe
146146
require.NoError(t, b.Canton.MintTokens(ctx, new(big.Rat).SetUint64(fee)))
147147
}
148148
require.NoError(t, b.Canton.SetupSend(ctx, fee, new(big.Rat).SetUint64(transferAmount)))
149+
b.Canton.SetSequentialSends(1)
149150
}
150151

151152
// SetupCantonTokenSend prepares Canton for token sends (fee + transfer holdings).
@@ -195,6 +196,7 @@ func (b E2EBootstrap) SetupCantonTokenSend(t *testing.T, ctx context.Context, la
195196
} else {
196197
require.NoError(t, b.Canton.SetupSend(ctx, fee, transferPerSend))
197198
}
199+
b.Canton.SetSequentialSends(sends)
198200
}
199201

200202
// SetupCantonReceive deploys the client party's PerPartyRouter before inbound messages

0 commit comments

Comments
 (0)