@@ -20,6 +20,7 @@ import { postSignatureExtraSteps } from '../../../tests/data/postSignatureExtraS
2020import { swapWithApproval } from '../../../tests/data/swapWithApproval'
2121import { swapWithZeroResetApproval } from '../../../tests/data/swapWithZeroResetApproval'
2222import { adaptViemWallet } from '../viemWallet'
23+ import { sameChainDeposit } from '../../../tests/data/sameChainDeposit'
2324
2425const viemChains = [ mainnet , base , zora , optimism , arbitrum , arbitrumNova ]
2526const relayChains = viemChains . map ( convertViemChainToRelayChain )
@@ -1756,3 +1757,97 @@ describe('Should test WebSocket functionality', () => {
17561757 } )
17571758 } )
17581759} )
1760+
1761+ describe ( 'Same-chain step completion.' , ( ) => {
1762+ let statusSpy : ReturnType < typeof vi . spyOn >
1763+
1764+ const mockStatusSequence = ( statuses : string [ ] ) => {
1765+ let index = 0
1766+ statusSpy = vi . spyOn ( axios , 'request' ) . mockImplementation ( ( config : any ) => {
1767+ if ( config . url ?. includes ( '/intents/status' ) ) {
1768+ const status = statuses [ Math . min ( index , statuses . length - 1 ) ]
1769+ index ++
1770+ return Promise . resolve ( {
1771+ data : { status, txHashes : [ '0x' ] } ,
1772+ status : 200
1773+ } ) as any
1774+ }
1775+ return Promise . resolve ( {
1776+ data : { status : 'success' } ,
1777+ status : 200
1778+ } ) as any
1779+ } )
1780+ return statusSpy
1781+ }
1782+
1783+ const statusCallCount = ( ) =>
1784+ statusSpy . mock . calls . filter ( ( call : any ) =>
1785+ call [ 0 ] ?. url ?. includes ( '/intents/status' )
1786+ ) . length
1787+
1788+ beforeEach ( ( ) => {
1789+ vi . clearAllMocks ( )
1790+ vi . resetAllMocks ( )
1791+ axiosPostSpy = mockAxiosPost ( )
1792+ wallet = {
1793+ vmType : 'evm' ,
1794+ getChainId : ( ) => Promise . resolve ( 1 ) ,
1795+ transport : http ( mainnet . rpcUrls . default . http [ 0 ] ) ,
1796+ address : ( ) => Promise . resolve ( '0x' ) ,
1797+ handleSignMessageStep : vi . fn ( ) . mockResolvedValue ( '0x' ) ,
1798+ handleSendTransactionStep : vi . fn ( ) . mockResolvedValue ( '0x' ) ,
1799+ handleConfirmTransactionStep : vi . fn ( ) . mockResolvedValue ( '0x' ) ,
1800+ switchChain : vi . fn ( ) . mockResolvedValue ( '0x' ) ,
1801+ supportsAtomicBatch : vi . fn ( ) . mockResolvedValue ( false ) ,
1802+ handleBatchTransactionStep : vi . fn ( ) . mockResolvedValue ( '0x' )
1803+ }
1804+ client = createClient ( {
1805+ baseApiUrl : MAINNET_RELAY_API ,
1806+ chains : relayChains ,
1807+ pollingInterval : 10
1808+ } )
1809+ } )
1810+
1811+ it ( 'Should complete an atomic same-chain swap without waiting for a solver fill.' , async ( ) => {
1812+ mockStatusSequence ( [ 'pending' , 'pending' , 'success' ] )
1813+
1814+ await executeSteps (
1815+ 1 ,
1816+ { } ,
1817+ wallet ,
1818+ ( ) => { } ,
1819+ JSON . parse ( JSON . stringify ( swapWithApproval ) ) as Execute ,
1820+ undefined
1821+ )
1822+
1823+ // The origin receipt settles the swap, so the fill status is never awaited.
1824+ expect ( statusCallCount ( ) ) . toBeLessThanOrEqual ( 1 )
1825+ } )
1826+
1827+ it ( 'Should wait for the solver fill on a same-chain deposit step.' , async ( ) => {
1828+ mockStatusSequence ( [ 'pending' , 'pending' , 'success' ] )
1829+
1830+ await executeSteps (
1831+ 1 ,
1832+ { } ,
1833+ wallet ,
1834+ ( ) => { } ,
1835+ JSON . parse ( JSON . stringify ( sameChainDeposit ) ) as Execute ,
1836+ undefined
1837+ )
1838+
1839+ expect ( statusCallCount ( ) ) . toBeGreaterThanOrEqual ( 3 )
1840+ } )
1841+
1842+ it ( 'Should complete an atomic same-chain send without waiting for a solver fill.' , async ( ) => {
1843+ mockStatusSequence ( [ 'pending' , 'pending' , 'success' ] )
1844+
1845+ const quote = JSON . parse ( JSON . stringify ( sameChainDeposit ) ) as Execute
1846+ quote . steps [ 0 ] . id = 'send'
1847+
1848+ await executeSteps ( 1 , { } , wallet , ( ) => { } , quote , undefined )
1849+
1850+ expect ( statusCallCount ( ) ) . toBeLessThanOrEqual ( 1 )
1851+ expect ( quote . steps [ 0 ] . items ?. [ 0 ] . status ) . toBe ( 'complete' )
1852+ } )
1853+ } )
0 commit comments