@@ -15,18 +15,6 @@ describe('BuildSwapStore', () => {
1515 let rootStore : Store ;
1616 let store : BuildSwapStore ;
1717
18- const addChannel = ( capacity : number , localBalance : number ) => {
19- const remoteBalance = capacity - localBalance ;
20- const lndChan = { ...lndChannel , capacity, localBalance, remoteBalance } ;
21- const channel = new Channel ( rootStore , lndChan ) ;
22- channel . chanId = `${ channel . chanId } ${ rootStore . channelStore . channels . size } ` ;
23- rootStore . channelStore . channels . set ( channel . chanId , channel ) ;
24- } ;
25-
26- const round = ( amount : number ) => {
27- return Math . floor ( amount / store . AMOUNT_INCREMENT ) * store . AMOUNT_INCREMENT ;
28- } ;
29-
3018 beforeEach ( async ( ) => {
3119 rootStore = createStore ( ) ;
3220 await rootStore . fetchAllData ( ) ;
@@ -96,6 +84,16 @@ describe('BuildSwapStore', () => {
9684 expect ( + store . amountForSelected ) . toBe ( loopTerms . maxSwapAmount ) ;
9785 } ) ;
9886
87+ it ( 'should select all channels with the same peer for loop in' , ( ) => {
88+ const channels = rootStore . channelStore . sortedChannels ;
89+ channels [ 1 ] . remotePubkey = channels [ 0 ] . remotePubkey ;
90+ channels [ 2 ] . remotePubkey = channels [ 0 ] . remotePubkey ;
91+ expect ( store . selectedChanIds ) . toHaveLength ( 0 ) ;
92+ store . toggleSelectedChannel ( channels [ 0 ] . chanId ) ;
93+ store . setDirection ( SwapDirection . IN ) ;
94+ expect ( store . selectedChanIds ) . toHaveLength ( 3 ) ;
95+ } ) ;
96+
9997 it ( 'should fetch a loop in quote' , async ( ) => {
10098 expect ( + store . quote . swapFee ) . toEqual ( 0 ) ;
10199 expect ( + store . quote . minerFee ) . toEqual ( 0 ) ;
@@ -166,6 +164,31 @@ describe('BuildSwapStore', () => {
166164 } ) ;
167165 } ) ;
168166
167+ it ( 'should store swapped channels after a loop in' , async ( ) => {
168+ const channels = rootStore . channelStore . sortedChannels ;
169+ // the pubkey in the sampleData is not valid, so hard-code this valid one
170+ channels [ 0 ] . remotePubkey =
171+ '035c82e14eb74d2324daa17eebea8c58b46a9eabac87191cc83ee26275b514e6a0' ;
172+ store . toggleSelectedChannel ( channels [ 0 ] . chanId ) ;
173+ store . setDirection ( SwapDirection . IN ) ;
174+ store . setAmount ( Big ( 600 ) ) ;
175+ expect ( rootStore . swapStore . swappedChannels . size ) . toBe ( 0 ) ;
176+ store . requestSwap ( ) ;
177+ await waitFor ( ( ) => expect ( store . currentStep ) . toBe ( BuildSwapSteps . Closed ) ) ;
178+ expect ( rootStore . swapStore . swappedChannels . size ) . toBe ( 1 ) ;
179+ } ) ;
180+
181+ it ( 'should store swapped channels after a loop out' , async ( ) => {
182+ const channels = rootStore . channelStore . sortedChannels ;
183+ store . toggleSelectedChannel ( channels [ 0 ] . chanId ) ;
184+ store . setDirection ( SwapDirection . OUT ) ;
185+ store . setAmount ( Big ( 600 ) ) ;
186+ expect ( rootStore . swapStore . swappedChannels . size ) . toBe ( 0 ) ;
187+ store . requestSwap ( ) ;
188+ await waitFor ( ( ) => expect ( store . currentStep ) . toBe ( BuildSwapSteps . Closed ) ) ;
189+ expect ( rootStore . swapStore . swappedChannels . size ) . toBe ( 1 ) ;
190+ } ) ;
191+
169192 it ( 'should set the correct swap deadline in production' , async ( ) => {
170193 store . setDirection ( SwapDirection . OUT ) ;
171194 store . setAmount ( Big ( 600 ) ) ;
@@ -245,6 +268,19 @@ describe('BuildSwapStore', () => {
245268 } ) ;
246269
247270 describe ( 'min/max swap limits' , ( ) => {
271+ const addChannel = ( capacity : number , localBalance : number ) => {
272+ const remoteBalance = capacity - localBalance ;
273+ const lndChan = { ...lndChannel , capacity, localBalance, remoteBalance } ;
274+ const channel = new Channel ( rootStore , lndChan ) ;
275+ channel . chanId = `${ channel . chanId } ${ rootStore . channelStore . channels . size } ` ;
276+ channel . remotePubkey = `${ channel . remotePubkey } ${ rootStore . channelStore . channels . size } ` ;
277+ rootStore . channelStore . channels . set ( channel . chanId , channel ) ;
278+ } ;
279+
280+ const round = ( amount : number ) => {
281+ return Math . floor ( amount / store . AMOUNT_INCREMENT ) * store . AMOUNT_INCREMENT ;
282+ } ;
283+
248284 beforeEach ( ( ) => {
249285 rootStore . channelStore . channels . clear ( ) ;
250286 [
0 commit comments