2727 Amount : btcutil .Amount (50000 ),
2828 DestAddr : testAddr ,
2929 MaxMinerFee : 50000 ,
30+ HtlcConfirmations : defaultConfirmations ,
3031 SweepConfTarget : 2 ,
3132 MaxSwapFee : 1050 ,
3233 MaxPrepayAmount : 100 ,
@@ -36,16 +37,22 @@ var (
3637
3738 swapInvoiceDesc = "swap"
3839 prepayInvoiceDesc = "prepay"
40+
41+ defaultConfirmations = int32 (loopdb .DefaultLoopOutHtlcConfirmations )
3942)
4043
41- // TestSuccess tests the loop out happy flow.
44+ // TestSuccess tests the loop out happy flow, using a custom htlc confirmation
45+ // target.
4246func TestSuccess (t * testing.T ) {
4347 defer test .Guard (t )()
4448
4549 ctx := createClientTestContext (t , nil )
4650
51+ req := * testRequest
52+ req .HtlcConfirmations = 2
53+
4754 // Initiate loop out.
48- info , err := ctx .swapClient .LoopOut (context .Background (), testRequest )
55+ info , err := ctx .swapClient .LoopOut (context .Background (), & req )
4956 if err != nil {
5057 t .Fatal (err )
5158 }
@@ -57,7 +64,7 @@ func TestSuccess(t *testing.T) {
5764 signalPrepaymentResult := ctx .AssertPaid (prepayInvoiceDesc )
5865
5966 // Expect client to register for conf.
60- confIntent := ctx .AssertRegisterConf (false )
67+ confIntent := ctx .AssertRegisterConf (false , req . HtlcConfirmations )
6168
6269 testSuccess (ctx , testRequest .Amount , info .SwapHash ,
6370 signalPrepaymentResult , signalSwapPaymentResult , false ,
@@ -83,7 +90,7 @@ func TestFailOffchain(t *testing.T) {
8390 signalSwapPaymentResult := ctx .AssertPaid (swapInvoiceDesc )
8491 signalPrepaymentResult := ctx .AssertPaid (prepayInvoiceDesc )
8592
86- ctx .AssertRegisterConf (false )
93+ ctx .AssertRegisterConf (false , defaultConfirmations )
8794
8895 signalSwapPaymentResult (
8996 errors .New (lndclient .PaymentResultUnknownPaymentHash ),
@@ -141,18 +148,25 @@ func TestFailWrongAmount(t *testing.T) {
141148func TestResume (t * testing.T ) {
142149 defer test .Guard (t )()
143150
151+ defaultConfs := loopdb .DefaultLoopOutHtlcConfirmations
152+
144153 t .Run ("not expired" , func (t * testing.T ) {
145- testResume (t , false , false , true )
154+ testResume (t , defaultConfs , false , false , true )
155+ })
156+ t .Run ("not expired, custom confirmations" , func (t * testing.T ) {
157+ testResume (t , 3 , false , false , true )
146158 })
147159 t .Run ("expired not revealed" , func (t * testing.T ) {
148- testResume (t , true , false , false )
160+ testResume (t , defaultConfs , true , false , false )
149161 })
150162 t .Run ("expired revealed" , func (t * testing.T ) {
151- testResume (t , true , true , true )
163+ testResume (t , defaultConfs , true , true , true )
152164 })
153165}
154166
155- func testResume (t * testing.T , expired , preimageRevealed , expectSuccess bool ) {
167+ func testResume (t * testing.T , confs uint32 , expired , preimageRevealed ,
168+ expectSuccess bool ) {
169+
156170 defer test .Guard (t )()
157171
158172 preimage := testPreimage
@@ -191,11 +205,13 @@ func testResume(t *testing.T, expired, preimageRevealed, expectSuccess bool) {
191205 update .HtlcTxHash = & chainhash.Hash {1 , 2 , 6 }
192206 }
193207
208+ // Create a pending swap with our custom number of confirmations.
194209 pendingSwap := & loopdb.LoopOut {
195210 Contract : & loopdb.LoopOutContract {
196211 DestAddr : dest ,
197212 SwapInvoice : swapPayReq ,
198213 SweepConfTarget : 2 ,
214+ HtlcConfirmations : confs ,
199215 MaxSwapRoutingFee : 70000 ,
200216 PrepayInvoice : prePayReq ,
201217 SwapContract : loopdb.SwapContract {
@@ -231,8 +247,8 @@ func testResume(t *testing.T, expired, preimageRevealed, expectSuccess bool) {
231247 signalSwapPaymentResult := ctx .AssertPaid (swapInvoiceDesc )
232248 signalPrepaymentResult := ctx .AssertPaid (prepayInvoiceDesc )
233249
234- // Expect client to register for conf .
235- confIntent := ctx .AssertRegisterConf (preimageRevealed )
250+ // Expect client to register for our expected number of confirmations .
251+ confIntent := ctx .AssertRegisterConf (preimageRevealed , int32 ( confs ) )
236252
237253 signalSwapPaymentResult (nil )
238254 signalPrepaymentResult (nil )
0 commit comments