@@ -251,6 +251,8 @@ describe('Transaction Controller Init', () => {
251251
252252describe ( 'submitShieldSubscriptionSponsorshipIntent' , ( ) => {
253253 const requestMock = buildInitRequestMock ( ) ;
254+ const transactionController =
255+ TransactionControllerInit ( requestMock ) . controller ;
254256 const MOCK_STATE = createSwapsMockStore ( ) . metamask ;
255257 const MOCK_TX_META = {
256258 id : '1' ,
@@ -284,6 +286,7 @@ describe('submitShieldSubscriptionSponsorshipIntent', () => {
284286 MOCK_STATE ,
285287 requestMock . initMessenger ,
286288 MOCK_TX_META ,
289+ transactionController ,
287290 ) ;
288291
289292 expect ( mockInitMessengerCall ) . toHaveBeenCalledWith (
@@ -296,6 +299,23 @@ describe('submitShieldSubscriptionSponsorshipIntent', () => {
296299 ) ;
297300 } ) ;
298301
302+ it ( 'should not submit sponsorship intent if transaction already exists' , async ( ) => {
303+ const getTransactionsSpy = jest
304+ . spyOn ( transactionController , 'getTransactions' )
305+ // @ts -expect-error mock return value
306+ . mockReturnValueOnce ( [ MOCK_TX_META ] ) ;
307+ await submitShieldSubscriptionSponsorshipIntent (
308+ // @ts -expect-error mock state
309+ MOCK_STATE ,
310+ requestMock . initMessenger ,
311+ MOCK_TX_META ,
312+ transactionController ,
313+ ) ;
314+
315+ expect ( getTransactionsSpy ) . toHaveBeenCalled ( ) ;
316+ expect ( mockInitMessengerCall ) . not . toHaveBeenCalled ( ) ;
317+ } ) ;
318+
299319 it ( 'should not submit sponsorship intent if not a shield subscription approve transaction' , async ( ) => {
300320 await submitShieldSubscriptionSponsorshipIntent (
301321 // @ts -expect-error mock state
@@ -305,6 +325,7 @@ describe('submitShieldSubscriptionSponsorshipIntent', () => {
305325 id : '1' ,
306326 type : TransactionType . personalSign ,
307327 } ,
328+ transactionController ,
308329 ) ;
309330
310331 expect ( mockInitMessengerCall ) . not . toHaveBeenCalled ( ) ;
@@ -319,6 +340,7 @@ describe('submitShieldSubscriptionSponsorshipIntent', () => {
319340 ...MOCK_TX_META ,
320341 chainId : CHAIN_ID_MOCK ,
321342 } ,
343+ transactionController ,
322344 ) ;
323345
324346 expect ( mockInitMessengerCall ) . not . toHaveBeenCalled ( ) ;
@@ -339,6 +361,7 @@ describe('submitShieldSubscriptionSponsorshipIntent', () => {
339361 MOCK_STATE ,
340362 requestMock . initMessenger ,
341363 MOCK_TX_META ,
364+ transactionController ,
342365 ) ;
343366
344367 expect ( mockInitMessengerCall ) . not . toHaveBeenCalled ( ) ;
@@ -357,6 +380,7 @@ describe('submitShieldSubscriptionSponsorshipIntent', () => {
357380 MOCK_STATE ,
358381 requestMock . initMessenger ,
359382 MOCK_TX_META ,
383+ transactionController ,
360384 ) ,
361385 ) . resolves . not . toThrow ( ) ;
362386 expect ( errorSpy ) . toHaveBeenCalledWith (
0 commit comments