@@ -12,6 +12,7 @@ import (
12
12
"github.com/btcsuite/btcutil"
13
13
"github.com/lightninglabs/lndclient"
14
14
"github.com/lightninglabs/loop/loopdb"
15
+ "github.com/lightninglabs/loop/swap"
15
16
"github.com/lightninglabs/loop/test"
16
17
"github.com/lightningnetwork/lnd/lnrpc"
17
18
"github.com/lightningnetwork/lnd/lntypes"
@@ -68,7 +69,7 @@ func TestSuccess(t *testing.T) {
68
69
69
70
testSuccess (ctx , testRequest .Amount , info .SwapHash ,
70
71
signalPrepaymentResult , signalSwapPaymentResult , false ,
71
- confIntent ,
72
+ confIntent , swap . HtlcV2 ,
72
73
)
73
74
}
74
75
@@ -150,22 +151,46 @@ func TestResume(t *testing.T) {
150
151
151
152
defaultConfs := loopdb .DefaultLoopOutHtlcConfirmations
152
153
153
- t .Run ("not expired" , func (t * testing.T ) {
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 )
158
- })
159
- t .Run ("expired not revealed" , func (t * testing.T ) {
160
- testResume (t , defaultConfs , true , false , false )
161
- })
162
- t .Run ("expired revealed" , func (t * testing.T ) {
163
- testResume (t , defaultConfs , true , true , true )
164
- })
154
+ storedVersion := []loopdb.ProtocolVersion {
155
+ loopdb .ProtocolVersionUnrecorded ,
156
+ loopdb .ProtocolVersionHtlcV2 ,
157
+ }
158
+
159
+ for _ , version := range storedVersion {
160
+ version := version
161
+
162
+ t .Run (version .String (), func (t * testing.T ) {
163
+ t .Run ("not expired" , func (t * testing.T ) {
164
+ testResume (
165
+ t , defaultConfs , false , false , true ,
166
+ version ,
167
+ )
168
+ })
169
+ t .Run ("not expired, custom confirmations" ,
170
+ func (t * testing.T ) {
171
+ testResume (
172
+ t , 3 , false , false , true ,
173
+ version ,
174
+ )
175
+ })
176
+ t .Run ("expired not revealed" , func (t * testing.T ) {
177
+ testResume (
178
+ t , defaultConfs , true , false , false ,
179
+ version ,
180
+ )
181
+ })
182
+ t .Run ("expired revealed" , func (t * testing.T ) {
183
+ testResume (
184
+ t , defaultConfs , true , true , true ,
185
+ version ,
186
+ )
187
+ })
188
+ })
189
+ }
165
190
}
166
191
167
192
func testResume (t * testing.T , confs uint32 , expired , preimageRevealed ,
168
- expectSuccess bool ) {
193
+ expectSuccess bool , protocolVersion loopdb. ProtocolVersion ) {
169
194
170
195
defer test .Guard (t )()
171
196
@@ -222,6 +247,7 @@ func testResume(t *testing.T, confs uint32, expired, preimageRevealed,
222
247
SenderKey : senderKey ,
223
248
MaxSwapFee : 60000 ,
224
249
MaxMinerFee : 50000 ,
250
+ ProtocolVersion : protocolVersion ,
225
251
},
226
252
},
227
253
Loop : loopdb.Loop {
@@ -250,6 +276,15 @@ func testResume(t *testing.T, confs uint32, expired, preimageRevealed,
250
276
// Expect client to register for our expected number of confirmations.
251
277
confIntent := ctx .AssertRegisterConf (preimageRevealed , int32 (confs ))
252
278
279
+ // Assert that the loopout htlc equals to the expected one.
280
+ scriptVersion := GetHtlcScriptVersion (protocolVersion )
281
+ htlc , err := swap .NewHtlc (
282
+ scriptVersion , pendingSwap .Contract .CltvExpiry , senderKey ,
283
+ receiverKey , hash , swap .HtlcP2WSH , & chaincfg .TestNet3Params ,
284
+ )
285
+ require .NoError (t , err )
286
+ require .Equal (t , htlc .PkScript , confIntent .PkScript )
287
+
253
288
signalSwapPaymentResult (nil )
254
289
signalPrepaymentResult (nil )
255
290
@@ -267,13 +302,14 @@ func testResume(t *testing.T, confs uint32, expired, preimageRevealed,
267
302
func (r error ) {},
268
303
func (r error ) {},
269
304
preimageRevealed ,
270
- confIntent ,
305
+ confIntent , scriptVersion ,
271
306
)
272
307
}
273
308
274
309
func testSuccess (ctx * testContext , amt btcutil.Amount , hash lntypes.Hash ,
275
310
signalPrepaymentResult , signalSwapPaymentResult func (error ),
276
- preimageRevealed bool , confIntent * test.ConfRegistration ) {
311
+ preimageRevealed bool , confIntent * test.ConfRegistration ,
312
+ scriptVersion swap.ScriptVersion ) {
277
313
278
314
htlcOutpoint := ctx .publishHtlc (confIntent .PkScript , amt )
279
315
@@ -304,8 +340,13 @@ func testSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
304
340
ctx .T .Fatalf ("client not sweeping from htlc tx" )
305
341
}
306
342
343
+ preImageIndex := 1
344
+ if scriptVersion == swap .HtlcV2 {
345
+ preImageIndex = 0
346
+ }
347
+
307
348
// Check preimage.
308
- clientPreImage := sweepTx .TxIn [0 ].Witness [1 ]
349
+ clientPreImage := sweepTx .TxIn [0 ].Witness [preImageIndex ]
309
350
clientPreImageHash := sha256 .Sum256 (clientPreImage )
310
351
if clientPreImageHash != hash {
311
352
ctx .T .Fatalf ("incorrect preimage" )
0 commit comments