@@ -12,8 +12,8 @@ import {
1212import { randomAppTaggingSecret } from '@aztec/stdlib/testing' ;
1313import { TxEffect , TxHash } from '@aztec/stdlib/tx' ;
1414
15- import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../../tagging/constants.js' ;
16- import { SenderTaggingStore } from './sender_tagging_store.js' ;
15+ import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN , unfinalizedTaggingIndexesWindowEnd } from '../../tagging/constants.js' ;
16+ import { SenderTaggingStore , windowExceededError } from './sender_tagging_store.js' ;
1717
1818/** Helper to create a single-index range (lowestIndex === highestIndex). */
1919function range ( secret : AppTaggingSecret , lowest : number , highest ?: number ) : TaggingIndexRange {
@@ -196,7 +196,7 @@ describe('SenderTaggingStore', () => {
196196 await expect (
197197 taggingStore . storePendingIndexes ( [ range ( secret1 , indexBeyondWindow ) ] , txHash2 , 'test' ) ,
198198 ) . rejects . toThrow (
199- `Highest used index ${ indexBeyondWindow } is further than window length from the highest finalized index ${ finalizedIndex } ` ,
199+ windowExceededError ( indexBeyondWindow , unfinalizedTaggingIndexesWindowEnd ( finalizedIndex ) , finalizedIndex ) ,
200200 ) ;
201201 } ) ;
202202
@@ -241,16 +241,36 @@ describe('SenderTaggingStore', () => {
241241
242242 it ( 'throws after pending txs exhaust window' , async ( ) => {
243243 // One single-index pending tx per index, mirroring how an un-mined backlog accumulates one log per tx on a
244- // shared secret (e.g. the self-send chain in bench_build_block). A fresh secret treats the
245- // finalized floor as 0, so indexes 0..WINDOW fit...
246- for ( let i = 0 ; i <= UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN ; i ++ ) {
244+ // shared secret (e.g. the self-send chain in bench_build_block). With no index finalized yet, exactly
245+ // WINDOW_LEN indexes ( 0..WINDOW_LEN - 1) fit...
246+ for ( let i = 0 ; i < UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN ; i ++ ) {
247247 await taggingStore . storePendingIndexes ( [ range ( secret1 , i ) ] , TxHash . random ( ) , 'test' ) ;
248248 }
249249
250250 // ...and the next tx throws, even with a single additional tag.
251251 await expect (
252252 taggingStore . storePendingIndexes (
253- [ range ( secret1 , UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN + 1 ) ] ,
253+ [ range ( secret1 , UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN ) ] ,
254+ TxHash . random ( ) ,
255+ 'test' ,
256+ ) ,
257+ ) . rejects . toThrow ( / n o i n d e x f i n a l i z e d y e t / ) ;
258+ } ) ;
259+
260+ it ( 'permits exactly WINDOW_LEN pending indexes for a fresh secret' , async ( ) => {
261+ // Fresh-secret counterpart of the two boundary tests above: with no index finalized yet, the last permitted
262+ // pending index is WINDOW_LEN - 1, the same WINDOW_LEN-sized allowance as after any real finalization.
263+ await expect (
264+ taggingStore . storePendingIndexes (
265+ [ range ( secret1 , 0 , UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN - 1 ) ] ,
266+ TxHash . random ( ) ,
267+ 'test' ,
268+ ) ,
269+ ) . resolves . not . toThrow ( ) ;
270+
271+ await expect (
272+ taggingStore . storePendingIndexes (
273+ [ range ( secret1 , UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN ) ] ,
254274 TxHash . random ( ) ,
255275 'test' ,
256276 ) ,
0 commit comments