@@ -31,7 +31,7 @@ const { generateTxAlonzo, mockChainHistoryProvider, queryTransactionsResult, que
31
31
const updateTransactionsBlockNo = ( transactions : Cardano . HydratedTx [ ] , blockNo = Cardano . BlockNo ( 10_050 ) ) =>
32
32
transactions . map ( ( tx ) => ( {
33
33
...tx ,
34
- blockHeader : { ...tx . blockHeader , blockNo }
34
+ blockHeader : { ...tx . blockHeader , blockNo, slot : Cardano . Slot ( 0 ) }
35
35
} ) ) ;
36
36
37
37
const updateTransactionIds = ( transactions : Cardano . HydratedTx [ ] , tailPattern = 'aaa' ) =>
@@ -343,6 +343,13 @@ describe('TransactionsTracker', () => {
343
343
Cardano . BlockNo ( 10_051 )
344
344
) ;
345
345
346
+ txId1 . blockHeader . slot = Cardano . Slot ( 10_050 ) ;
347
+ txId2 . blockHeader . slot = Cardano . Slot ( 10_051 ) ;
348
+ txId3 . blockHeader . slot = Cardano . Slot ( 10_052 ) ;
349
+
350
+ txId1OtherBlock . blockHeader . slot = Cardano . Slot ( 10_050 ) ;
351
+ txId2OtherBlock . blockHeader . slot = Cardano . Slot ( 10_051 ) ;
352
+
346
353
await firstValueFrom ( store . setAll ( [ txId1 , txId2 ] ) ) ;
347
354
348
355
chainHistoryProvider . transactionsByAddresses = jest . fn ( ( ) => ( {
@@ -364,11 +371,11 @@ describe('TransactionsTracker', () => {
364
371
365
372
expect ( await firstValueFrom ( provider$ . pipe ( bufferCount ( 2 ) ) ) ) . toEqual ( [
366
373
[ txId1 , txId2 ] , // from store
367
- [ txId1OtherBlock , txId2OtherBlock , txId3 ] // chain history
374
+ [ txId1 , txId2 , txId3 ] // chain history
368
375
] ) ;
369
376
expect ( rollbacks . length ) . toBe ( 0 ) ;
370
377
expect ( store . setAll ) . toBeCalledTimes ( 2 ) ;
371
- expect ( store . setAll ) . nthCalledWith ( 2 , [ txId1OtherBlock , txId2OtherBlock , txId3 ] ) ;
378
+ expect ( store . setAll ) . nthCalledWith ( 2 , [ txId1 , txId2 , txId3 ] ) ;
372
379
} ) ;
373
380
374
381
// latestStoredBlock <1 2 3>
@@ -380,8 +387,16 @@ describe('TransactionsTracker', () => {
380
387
queryTransactionsResult2 . pageResults ,
381
388
Cardano . BlockNo ( 10_050 )
382
389
) ;
390
+
391
+ txId1 . blockHeader . slot = Cardano . Slot ( 10_050 ) ;
392
+ txId2 . blockHeader . slot = Cardano . Slot ( 10_051 ) ;
393
+ txId3 . blockHeader . slot = Cardano . Slot ( 10_052 ) ;
394
+
383
395
const [ txId1OtherBlock , txId2OtherBlock ] = updateTransactionsBlockNo ( [ txId1 , txId2 ] , Cardano . BlockNo ( 10_051 ) ) ;
384
396
397
+ txId1OtherBlock . blockHeader . slot = Cardano . Slot ( 10_051 ) ;
398
+ txId2OtherBlock . blockHeader . slot = Cardano . Slot ( 10_052 ) ;
399
+
385
400
await firstValueFrom ( store . setAll ( [ txId1 , txId2 , txId3 ] ) ) ;
386
401
387
402
chainHistoryProvider . transactionsByAddresses = jest . fn ( ( ) => ( {
@@ -496,6 +511,43 @@ describe('TransactionsTracker', () => {
496
511
expect ( store . setAll ) . nthCalledWith ( 2 , [ txId3OtherBlock , txId2OtherBlock , txId1OtherBlock ] ) ;
497
512
} ) ;
498
513
514
+ it ( 'process transactions in the right order (sorted by slot ASC) regardless of transaction order in the backend response' , async ( ) => {
515
+ const [ txId1 , txId2 , txId3 ] = updateTransactionsBlockNo (
516
+ queryTransactionsResult2 . pageResults ,
517
+ Cardano . BlockNo ( 10_000 )
518
+ ) ;
519
+
520
+ txId1 . blockHeader . slot = Cardano . Slot ( 10_000 ) ;
521
+ txId2 . blockHeader . slot = Cardano . Slot ( 10_001 ) ;
522
+ txId3 . blockHeader . slot = Cardano . Slot ( 10_002 ) ;
523
+
524
+ await firstValueFrom ( store . setAll ( [ txId1 , txId2 , txId3 ] ) ) ;
525
+
526
+ chainHistoryProvider . transactionsByAddresses = jest . fn ( ( ) => ( {
527
+ pageResults : [ txId3 , txId2 , txId1 ] ,
528
+ totalResultCount : 3
529
+ } ) ) ;
530
+
531
+ const { transactionsSource$ : provider$ , rollback$ } = createAddressTransactionsProvider ( {
532
+ addresses$ : of ( addresses ) ,
533
+ chainHistoryProvider,
534
+ logger,
535
+ retryBackoffConfig,
536
+ store,
537
+ tipBlockHeight$
538
+ } ) ;
539
+
540
+ const rollbacks : Cardano . HydratedTx [ ] = [ ] ;
541
+ rollback$ . subscribe ( ( tx ) => rollbacks . push ( tx ) ) ;
542
+
543
+ expect ( await firstValueFrom ( provider$ . pipe ( bufferCount ( 1 ) ) ) ) . toEqual ( [
544
+ [ txId1 , txId2 , txId3 ] // chain history
545
+ ] ) ;
546
+ expect ( rollbacks . length ) . toBe ( 0 ) ;
547
+ expect ( store . setAll ) . toBeCalledTimes ( 1 ) ;
548
+ expect ( store . setAll ) . nthCalledWith ( 1 , [ txId1 , txId2 , txId3 ] ) ;
549
+ } ) ;
550
+
499
551
// latestStoredBlock <1 2 3>
500
552
// newBlock <1 2 3>
501
553
// rollback$ none
0 commit comments