2727 Amount : btcutil .Amount (50000 ),
2828 DestAddr : testAddr ,
2929 MaxMinerFee : 50000 ,
30+ HtlcConfirmations : defaultConfirmations ,
3031 SweepConfTarget : 2 ,
3132 MaxSwapFee : 1050 ,
3233 MaxPrepayAmount : 100 ,
@@ -40,14 +41,18 @@ var (
4041 defaultConfirmations = int32 (loopdb .DefaultLoopOutHtlcConfirmations )
4142)
4243
43- // TestSuccess tests the loop out happy flow.
44+ // TestSuccess tests the loop out happy flow, using a custom htlc confirmation
45+ // target.
4446func TestSuccess (t * testing.T ) {
4547 defer test .Guard (t )()
4648
4749 ctx := createClientTestContext (t , nil )
4850
51+ req := * testRequest
52+ req .HtlcConfirmations = 2
53+
4954 // Initiate loop out.
50- info , err := ctx .swapClient .LoopOut (context .Background (), testRequest )
55+ info , err := ctx .swapClient .LoopOut (context .Background (), & req )
5156 if err != nil {
5257 t .Fatal (err )
5358 }
@@ -59,7 +64,7 @@ func TestSuccess(t *testing.T) {
5964 signalPrepaymentResult := ctx .AssertPaid (prepayInvoiceDesc )
6065
6166 // Expect client to register for conf.
62- confIntent := ctx .AssertRegisterConf (false , defaultConfirmations )
67+ confIntent := ctx .AssertRegisterConf (false , req . HtlcConfirmations )
6368
6469 testSuccess (ctx , testRequest .Amount , info .SwapHash ,
6570 signalPrepaymentResult , signalSwapPaymentResult , false ,
@@ -143,18 +148,25 @@ func TestFailWrongAmount(t *testing.T) {
143148func TestResume (t * testing.T ) {
144149 defer test .Guard (t )()
145150
151+ defaultConfs := loopdb .DefaultLoopOutHtlcConfirmations
152+
146153 t .Run ("not expired" , func (t * testing.T ) {
147- 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 )
148158 })
149159 t .Run ("expired not revealed" , func (t * testing.T ) {
150- testResume (t , true , false , false )
160+ testResume (t , defaultConfs , true , false , false )
151161 })
152162 t .Run ("expired revealed" , func (t * testing.T ) {
153- testResume (t , true , true , true )
163+ testResume (t , defaultConfs , true , true , true )
154164 })
155165}
156166
157- func testResume (t * testing.T , expired , preimageRevealed , expectSuccess bool ) {
167+ func testResume (t * testing.T , confs uint32 , expired , preimageRevealed ,
168+ expectSuccess bool ) {
169+
158170 defer test .Guard (t )()
159171
160172 preimage := testPreimage
@@ -193,12 +205,13 @@ func testResume(t *testing.T, expired, preimageRevealed, expectSuccess bool) {
193205 update .HtlcTxHash = & chainhash.Hash {1 , 2 , 6 }
194206 }
195207
208+ // Create a pending swap with our custom number of confirmations.
196209 pendingSwap := & loopdb.LoopOut {
197210 Contract : & loopdb.LoopOutContract {
198211 DestAddr : dest ,
199212 SwapInvoice : swapPayReq ,
200213 SweepConfTarget : 2 ,
201- HtlcConfirmations : loopdb . DefaultLoopOutHtlcConfirmations ,
214+ HtlcConfirmations : confs ,
202215 MaxSwapRoutingFee : 70000 ,
203216 PrepayInvoice : prePayReq ,
204217 SwapContract : loopdb.SwapContract {
@@ -234,10 +247,8 @@ func testResume(t *testing.T, expired, preimageRevealed, expectSuccess bool) {
234247 signalSwapPaymentResult := ctx .AssertPaid (swapInvoiceDesc )
235248 signalPrepaymentResult := ctx .AssertPaid (prepayInvoiceDesc )
236249
237- // Expect client to register for conf.
238- confIntent := ctx .AssertRegisterConf (
239- preimageRevealed , defaultConfirmations ,
240- )
250+ // Expect client to register for our expected number of confirmations.
251+ confIntent := ctx .AssertRegisterConf (preimageRevealed , int32 (confs ))
241252
242253 signalSwapPaymentResult (nil )
243254 signalPrepaymentResult (nil )
0 commit comments