@@ -5,7 +5,7 @@ import { waitFor } from '@testing-library/react';
55import Big from 'big.js' ;
66import { BalanceMode } from 'util/constants' ;
77import { injectIntoGrpcUnary } from 'util/tests' ;
8- import { lndChannel , loopInTerms } from 'util/tests/sampleData' ;
8+ import { lndChannel , loopInTerms , loopOutTerms } from 'util/tests/sampleData' ;
99import { BuildSwapStore , createStore , Store } from 'store' ;
1010import { Channel } from 'store/models' ;
1111import { SWAP_ABORT_DELAY } from 'store/stores/buildSwapStore' ;
@@ -83,7 +83,12 @@ describe('BuildSwapStore', () => {
8383 expect ( store . terms . out ) . toEqual ( { min : Big ( 0 ) , max : Big ( 0 ) } ) ;
8484 await store . getTerms ( ) ;
8585 expect ( store . terms . in ) . toEqual ( { min : Big ( 250000 ) , max : Big ( 1000000 ) } ) ;
86- expect ( store . terms . out ) . toEqual ( { min : Big ( 250000 ) , max : Big ( 1000000 ) } ) ;
86+ expect ( store . terms . out ) . toEqual ( {
87+ min : Big ( 250000 ) ,
88+ max : Big ( 1000000 ) ,
89+ minCltv : 20 ,
90+ maxCltv : 60 ,
91+ } ) ;
8792 } ) ;
8893
8994 it ( 'should handle errors fetching loop terms' , async ( ) => {
@@ -116,6 +121,68 @@ describe('BuildSwapStore', () => {
116121 expect ( + store . amountForSelected ) . toBe ( loopInTerms . maxSwapAmount ) ;
117122 } ) ;
118123
124+ it ( 'should validate the conf target' , async ( ) => {
125+ const { minCltvDelta, maxCltvDelta } = loopOutTerms ;
126+ expect ( store . confTarget ) . toBeUndefined ( ) ;
127+
128+ let target = maxCltvDelta - 10 ;
129+ store . setConfTarget ( target ) ;
130+ expect ( store . confTarget ) . toBe ( target ) ;
131+
132+ store . setDirection ( SwapDirection . OUT ) ;
133+ await store . getTerms ( ) ;
134+
135+ store . setConfTarget ( target ) ;
136+ expect ( store . confTarget ) . toBe ( target ) ;
137+
138+ target = minCltvDelta - 10 ;
139+ expect ( ( ) => store . setConfTarget ( target ) ) . toThrow ( ) ;
140+
141+ target = maxCltvDelta + 10 ;
142+ expect ( ( ) => store . setConfTarget ( target ) ) . toThrow ( ) ;
143+ } ) ;
144+
145+ it ( 'should submit the Loop Out conf target' , async ( ) => {
146+ const target = 23 ;
147+ store . setDirection ( SwapDirection . OUT ) ;
148+ store . setAmount ( Big ( 500000 ) ) ;
149+
150+ expect ( store . confTarget ) . toBeUndefined ( ) ;
151+ store . setConfTarget ( target ) ;
152+ expect ( store . confTarget ) . toBe ( target ) ;
153+
154+ let reqTarget = '' ;
155+ // mock the grpc unary function in order to capture the supplied dest
156+ // passed in with the API request
157+ injectIntoGrpcUnary ( ( desc , props ) => {
158+ reqTarget = ( props . request . toObject ( ) as any ) . sweepConfTarget ;
159+ } ) ;
160+
161+ store . requestSwap ( ) ;
162+ await waitFor ( ( ) => expect ( reqTarget ) . toBe ( target ) ) ;
163+ } ) ;
164+
165+ it ( 'should submit the Loop Out address' , async ( ) => {
166+ const addr = 'xyzabc' ;
167+ store . setDirection ( SwapDirection . OUT ) ;
168+ store . setAmount ( Big ( 500000 ) ) ;
169+
170+ expect ( store . loopOutAddress ) . toBeUndefined ( ) ;
171+ store . setLoopOutAddress ( addr ) ;
172+ expect ( store . loopOutAddress ) . toBe ( addr ) ;
173+ // store.goToNextStep();
174+
175+ let reqAddr = '' ;
176+ // mock the grpc unary function in order to capture the supplied dest
177+ // passed in with the API request
178+ injectIntoGrpcUnary ( ( desc , props ) => {
179+ reqAddr = ( props . request . toObject ( ) as any ) . dest ;
180+ } ) ;
181+
182+ store . requestSwap ( ) ;
183+ await waitFor ( ( ) => expect ( reqAddr ) . toBe ( addr ) ) ;
184+ } ) ;
185+
119186 it ( 'should select all channels with the same peer for loop in' , ( ) => {
120187 const channels = rootStore . channelStore . sortedChannels ;
121188 channels [ 1 ] . remotePubkey = channels [ 0 ] . remotePubkey ;
0 commit comments