27
27
Amount : btcutil .Amount (50000 ),
28
28
DestAddr : testAddr ,
29
29
MaxMinerFee : 50000 ,
30
+ HtlcConfirmations : defaultConfirmations ,
30
31
SweepConfTarget : 2 ,
31
32
MaxSwapFee : 1050 ,
32
33
MaxPrepayAmount : 100 ,
@@ -36,16 +37,22 @@ var (
36
37
37
38
swapInvoiceDesc = "swap"
38
39
prepayInvoiceDesc = "prepay"
40
+
41
+ defaultConfirmations = int32 (loopdb .DefaultLoopOutHtlcConfirmations )
39
42
)
40
43
41
- // TestSuccess tests the loop out happy flow.
44
+ // TestSuccess tests the loop out happy flow, using a custom htlc confirmation
45
+ // target.
42
46
func TestSuccess (t * testing.T ) {
43
47
defer test .Guard (t )()
44
48
45
49
ctx := createClientTestContext (t , nil )
46
50
51
+ req := * testRequest
52
+ req .HtlcConfirmations = 2
53
+
47
54
// Initiate loop out.
48
- info , err := ctx .swapClient .LoopOut (context .Background (), testRequest )
55
+ info , err := ctx .swapClient .LoopOut (context .Background (), & req )
49
56
if err != nil {
50
57
t .Fatal (err )
51
58
}
@@ -57,7 +64,7 @@ func TestSuccess(t *testing.T) {
57
64
signalPrepaymentResult := ctx .AssertPaid (prepayInvoiceDesc )
58
65
59
66
// Expect client to register for conf.
60
- confIntent := ctx .AssertRegisterConf (false )
67
+ confIntent := ctx .AssertRegisterConf (false , req . HtlcConfirmations )
61
68
62
69
testSuccess (ctx , testRequest .Amount , info .SwapHash ,
63
70
signalPrepaymentResult , signalSwapPaymentResult , false ,
@@ -83,7 +90,7 @@ func TestFailOffchain(t *testing.T) {
83
90
signalSwapPaymentResult := ctx .AssertPaid (swapInvoiceDesc )
84
91
signalPrepaymentResult := ctx .AssertPaid (prepayInvoiceDesc )
85
92
86
- ctx .AssertRegisterConf (false )
93
+ ctx .AssertRegisterConf (false , defaultConfirmations )
87
94
88
95
signalSwapPaymentResult (
89
96
errors .New (lndclient .PaymentResultUnknownPaymentHash ),
@@ -141,18 +148,25 @@ func TestFailWrongAmount(t *testing.T) {
141
148
func TestResume (t * testing.T ) {
142
149
defer test .Guard (t )()
143
150
151
+ defaultConfs := loopdb .DefaultLoopOutHtlcConfirmations
152
+
144
153
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 )
146
158
})
147
159
t .Run ("expired not revealed" , func (t * testing.T ) {
148
- testResume (t , true , false , false )
160
+ testResume (t , defaultConfs , true , false , false )
149
161
})
150
162
t .Run ("expired revealed" , func (t * testing.T ) {
151
- testResume (t , true , true , true )
163
+ testResume (t , defaultConfs , true , true , true )
152
164
})
153
165
}
154
166
155
- func testResume (t * testing.T , expired , preimageRevealed , expectSuccess bool ) {
167
+ func testResume (t * testing.T , confs uint32 , expired , preimageRevealed ,
168
+ expectSuccess bool ) {
169
+
156
170
defer test .Guard (t )()
157
171
158
172
preimage := testPreimage
@@ -191,11 +205,13 @@ func testResume(t *testing.T, expired, preimageRevealed, expectSuccess bool) {
191
205
update .HtlcTxHash = & chainhash.Hash {1 , 2 , 6 }
192
206
}
193
207
208
+ // Create a pending swap with our custom number of confirmations.
194
209
pendingSwap := & loopdb.LoopOut {
195
210
Contract : & loopdb.LoopOutContract {
196
211
DestAddr : dest ,
197
212
SwapInvoice : swapPayReq ,
198
213
SweepConfTarget : 2 ,
214
+ HtlcConfirmations : confs ,
199
215
MaxSwapRoutingFee : 70000 ,
200
216
PrepayInvoice : prePayReq ,
201
217
SwapContract : loopdb.SwapContract {
@@ -231,8 +247,8 @@ func testResume(t *testing.T, expired, preimageRevealed, expectSuccess bool) {
231
247
signalSwapPaymentResult := ctx .AssertPaid (swapInvoiceDesc )
232
248
signalPrepaymentResult := ctx .AssertPaid (prepayInvoiceDesc )
233
249
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 ) )
236
252
237
253
signalSwapPaymentResult (nil )
238
254
signalPrepaymentResult (nil )
0 commit comments