@@ -12,6 +12,7 @@ import (
1212 "github.com/btcsuite/btcutil"
1313 "github.com/lightninglabs/lndclient"
1414 "github.com/lightninglabs/loop/loopdb"
15+ "github.com/lightninglabs/loop/swap"
1516 "github.com/lightninglabs/loop/test"
1617 "github.com/lightningnetwork/lnd/lnrpc"
1718 "github.com/lightningnetwork/lnd/lntypes"
@@ -68,7 +69,7 @@ func TestSuccess(t *testing.T) {
6869
6970 testSuccess (ctx , testRequest .Amount , info .SwapHash ,
7071 signalPrepaymentResult , signalSwapPaymentResult , false ,
71- confIntent ,
72+ confIntent , swap . HtlcV2 ,
7273 )
7374}
7475
@@ -150,22 +151,46 @@ func TestResume(t *testing.T) {
150151
151152 defaultConfs := loopdb .DefaultLoopOutHtlcConfirmations
152153
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+ }
165190}
166191
167192func testResume (t * testing.T , confs uint32 , expired , preimageRevealed ,
168- expectSuccess bool ) {
193+ expectSuccess bool , protocolVersion loopdb. ProtocolVersion ) {
169194
170195 defer test .Guard (t )()
171196
@@ -222,6 +247,7 @@ func testResume(t *testing.T, confs uint32, expired, preimageRevealed,
222247 SenderKey : senderKey ,
223248 MaxSwapFee : 60000 ,
224249 MaxMinerFee : 50000 ,
250+ ProtocolVersion : protocolVersion ,
225251 },
226252 },
227253 Loop : loopdb.Loop {
@@ -250,6 +276,15 @@ func testResume(t *testing.T, confs uint32, expired, preimageRevealed,
250276 // Expect client to register for our expected number of confirmations.
251277 confIntent := ctx .AssertRegisterConf (preimageRevealed , int32 (confs ))
252278
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+
253288 signalSwapPaymentResult (nil )
254289 signalPrepaymentResult (nil )
255290
@@ -267,13 +302,14 @@ func testResume(t *testing.T, confs uint32, expired, preimageRevealed,
267302 func (r error ) {},
268303 func (r error ) {},
269304 preimageRevealed ,
270- confIntent ,
305+ confIntent , scriptVersion ,
271306 )
272307}
273308
274309func testSuccess (ctx * testContext , amt btcutil.Amount , hash lntypes.Hash ,
275310 signalPrepaymentResult , signalSwapPaymentResult func (error ),
276- preimageRevealed bool , confIntent * test.ConfRegistration ) {
311+ preimageRevealed bool , confIntent * test.ConfRegistration ,
312+ scriptVersion swap.ScriptVersion ) {
277313
278314 htlcOutpoint := ctx .publishHtlc (confIntent .PkScript , amt )
279315
@@ -304,8 +340,13 @@ func testSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
304340 ctx .T .Fatalf ("client not sweeping from htlc tx" )
305341 }
306342
343+ preImageIndex := 1
344+ if scriptVersion == swap .HtlcV2 {
345+ preImageIndex = 0
346+ }
347+
307348 // Check preimage.
308- clientPreImage := sweepTx .TxIn [0 ].Witness [1 ]
349+ clientPreImage := sweepTx .TxIn [0 ].Witness [preImageIndex ]
309350 clientPreImageHash := sha256 .Sum256 (clientPreImage )
310351 if clientPreImageHash != hash {
311352 ctx .T .Fatalf ("incorrect preimage" )
0 commit comments