@@ -367,6 +367,13 @@ describe('PersonalWallet methods', () => {
367
367
} ) ;
368
368
369
369
describe ( 'submitTx' , ( ) => {
370
+ const valueNotConservedError = new ProviderError (
371
+ ProviderFailure . BadRequest ,
372
+ new CardanoNodeErrors . TxSubmissionErrors . ValueNotConservedError ( {
373
+ valueNotConserved : { consumed : 2 , produced : 1 }
374
+ } )
375
+ ) ;
376
+
370
377
it ( 'resolves on success' , async ( ) => {
371
378
const tx = await wallet . finalizeTx ( { tx : await wallet . initializeTx ( props ) } ) ;
372
379
const outgoingTx = toOutgoingTx ( tx ) ;
@@ -442,14 +449,9 @@ describe('PersonalWallet methods', () => {
442
449
} ) ;
443
450
444
451
it ( 'mightBeAlreadySubmitted option interprets ValueNotConservedError as success' , async ( ) => {
445
- txSubmitProvider . submitTx . mockRejectedValueOnce (
446
- new ProviderError (
447
- ProviderFailure . BadRequest ,
448
- new CardanoNodeErrors . TxSubmissionErrors . ValueNotConservedError ( {
449
- valueNotConserved : { consumed : 2 , produced : 1 }
450
- } )
451
- )
452
- ) ;
452
+ txSubmitProvider . submitTx
453
+ . mockRejectedValueOnce ( valueNotConservedError )
454
+ . mockRejectedValueOnce ( valueNotConservedError ) ;
453
455
const tx = await wallet . finalizeTx ( { tx : await wallet . initializeTx ( props ) } ) ;
454
456
const outgoingTx = toOutgoingTx ( tx ) ;
455
457
@@ -462,6 +464,20 @@ describe('PersonalWallet methods', () => {
462
464
expect ( await txPending ) . toEqual ( outgoingTx ) ;
463
465
} ) ;
464
466
467
+ it ( 'attempts to resubmit the tx that is already in flight' , async ( ) => {
468
+ const tx = await wallet . finalizeTx ( { tx : await wallet . initializeTx ( props ) } ) ;
469
+
470
+ await wallet . submitTx ( tx ) ;
471
+ expect ( await firstValueFrom ( wallet . transactions . outgoing . inFlight$ ) ) . toHaveLength ( 1 ) ;
472
+
473
+ // resubmit the same tx while it's 'in flight'
474
+ txSubmitProvider . submitTx . mockRejectedValueOnce ( valueNotConservedError ) ;
475
+ await wallet . submitTx ( tx , { mightBeAlreadySubmitted : true } ) ;
476
+
477
+ expect ( await firstValueFrom ( wallet . transactions . outgoing . inFlight$ ) ) . toHaveLength ( 1 ) ;
478
+ expect ( txSubmitProvider . submitTx ) . toBeCalledTimes ( 2 ) ;
479
+ } ) ;
480
+
465
481
it ( 'resolves on success when submitting a tx when sending coins to a handle' , async ( ) => {
466
482
const txBuilder = wallet . createTxBuilder ( ) ;
467
483
const txOutput = await txBuilder . buildOutput ( ) . handle ( 'alice' ) . coin ( 1_000_000n ) . build ( ) ;
0 commit comments