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 ,
@@ -40,14 +41,18 @@ var (
40
41
defaultConfirmations = int32 (loopdb .DefaultLoopOutHtlcConfirmations )
41
42
)
42
43
43
- // TestSuccess tests the loop out happy flow.
44
+ // TestSuccess tests the loop out happy flow, using a custom htlc confirmation
45
+ // target.
44
46
func TestSuccess (t * testing.T ) {
45
47
defer test .Guard (t )()
46
48
47
49
ctx := createClientTestContext (t , nil )
48
50
51
+ req := * testRequest
52
+ req .HtlcConfirmations = 2
53
+
49
54
// Initiate loop out.
50
- info , err := ctx .swapClient .LoopOut (context .Background (), testRequest )
55
+ info , err := ctx .swapClient .LoopOut (context .Background (), & req )
51
56
if err != nil {
52
57
t .Fatal (err )
53
58
}
@@ -59,7 +64,7 @@ func TestSuccess(t *testing.T) {
59
64
signalPrepaymentResult := ctx .AssertPaid (prepayInvoiceDesc )
60
65
61
66
// Expect client to register for conf.
62
- confIntent := ctx .AssertRegisterConf (false , defaultConfirmations )
67
+ confIntent := ctx .AssertRegisterConf (false , req . HtlcConfirmations )
63
68
64
69
testSuccess (ctx , testRequest .Amount , info .SwapHash ,
65
70
signalPrepaymentResult , signalSwapPaymentResult , false ,
@@ -143,18 +148,25 @@ func TestFailWrongAmount(t *testing.T) {
143
148
func TestResume (t * testing.T ) {
144
149
defer test .Guard (t )()
145
150
151
+ defaultConfs := loopdb .DefaultLoopOutHtlcConfirmations
152
+
146
153
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 )
148
158
})
149
159
t .Run ("expired not revealed" , func (t * testing.T ) {
150
- testResume (t , true , false , false )
160
+ testResume (t , defaultConfs , true , false , false )
151
161
})
152
162
t .Run ("expired revealed" , func (t * testing.T ) {
153
- testResume (t , true , true , true )
163
+ testResume (t , defaultConfs , true , true , true )
154
164
})
155
165
}
156
166
157
- func testResume (t * testing.T , expired , preimageRevealed , expectSuccess bool ) {
167
+ func testResume (t * testing.T , confs uint32 , expired , preimageRevealed ,
168
+ expectSuccess bool ) {
169
+
158
170
defer test .Guard (t )()
159
171
160
172
preimage := testPreimage
@@ -193,12 +205,13 @@ func testResume(t *testing.T, expired, preimageRevealed, expectSuccess bool) {
193
205
update .HtlcTxHash = & chainhash.Hash {1 , 2 , 6 }
194
206
}
195
207
208
+ // Create a pending swap with our custom number of confirmations.
196
209
pendingSwap := & loopdb.LoopOut {
197
210
Contract : & loopdb.LoopOutContract {
198
211
DestAddr : dest ,
199
212
SwapInvoice : swapPayReq ,
200
213
SweepConfTarget : 2 ,
201
- HtlcConfirmations : loopdb . DefaultLoopOutHtlcConfirmations ,
214
+ HtlcConfirmations : confs ,
202
215
MaxSwapRoutingFee : 70000 ,
203
216
PrepayInvoice : prePayReq ,
204
217
SwapContract : loopdb.SwapContract {
@@ -234,10 +247,8 @@ func testResume(t *testing.T, expired, preimageRevealed, expectSuccess bool) {
234
247
signalSwapPaymentResult := ctx .AssertPaid (swapInvoiceDesc )
235
248
signalPrepaymentResult := ctx .AssertPaid (prepayInvoiceDesc )
236
249
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 ))
241
252
242
253
signalSwapPaymentResult (nil )
243
254
signalPrepaymentResult (nil )
0 commit comments