11package loop
22
33import (
4- "bytes"
54 "context"
65 "crypto/sha256"
76 "errors"
@@ -57,9 +56,7 @@ func TestLoopOutSuccess(t *testing.T) {
5756
5857 // Initiate loop out.
5958 info , err := ctx .swapClient .LoopOut (context .Background (), & req )
60- if err != nil {
61- t .Fatal (err )
62- }
59+ require .NoError (t , err )
6360
6461 ctx .assertStored ()
6562 ctx .assertStatus (loopdb .StateInitiated )
@@ -84,9 +81,7 @@ func TestLoopOutFailOffchain(t *testing.T) {
8481 ctx := createClientTestContext (t , nil )
8582
8683 _ , err := ctx .swapClient .LoopOut (context .Background (), testRequest )
87- if err != nil {
88- t .Fatal (err )
89- }
84+ require .NoError (t , err )
9085
9186 ctx .assertStored ()
9287 ctx .assertStatus (loopdb .StateInitiated )
@@ -208,14 +203,10 @@ func testLoopOutResume(t *testing.T, confs uint32, expired, preimageRevealed,
208203 amt := btcutil .Amount (50000 )
209204
210205 swapPayReq , err := getInvoice (hash , amt , swapInvoiceDesc )
211- if err != nil {
212- t .Fatal (err )
213- }
206+ require .NoError (t , err )
214207
215208 prePayReq , err := getInvoice (hash , 100 , prepayInvoiceDesc )
216- if err != nil {
217- t .Fatal (err )
218- }
209+ require .NoError (t , err )
219210
220211 _ , senderPubKey := test .CreateKey (1 )
221212 var senderKey [33 ]byte
@@ -284,16 +275,26 @@ func testLoopOutResume(t *testing.T, confs uint32, expired, preimageRevealed,
284275
285276 // Assert that the loopout htlc equals to the expected one.
286277 scriptVersion := GetHtlcScriptVersion (protocolVersion )
278+ var htlc * swap.Htlc
287279
288- outputType := swap .HtlcP2TR
289- if scriptVersion != swap .HtlcV3 {
290- outputType = swap .HtlcP2WSH
280+ switch scriptVersion {
281+ case swap .HtlcV2 :
282+ htlc , err = swap .NewHtlcV2 (
283+ pendingSwap .Contract .CltvExpiry , senderKey ,
284+ receiverKey , hash , & chaincfg .TestNet3Params ,
285+ )
286+
287+ case swap .HtlcV3 :
288+ htlc , err = swap .NewHtlcV3 (
289+ pendingSwap .Contract .CltvExpiry , senderKey ,
290+ receiverKey , senderKey , receiverKey , hash ,
291+ & chaincfg .TestNet3Params ,
292+ )
293+
294+ default :
295+ t .Fatalf (swap .ErrInvalidScriptVersion .Error ())
291296 }
292297
293- htlc , err := swap .NewHtlc (
294- scriptVersion , pendingSwap .Contract .CltvExpiry , senderKey ,
295- receiverKey , hash , outputType , & chaincfg .TestNet3Params ,
296- )
297298 require .NoError (t , err )
298299 require .Equal (t , htlc .PkScript , confIntent .PkScript )
299300
@@ -363,10 +364,11 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
363364 // Expect client on-chain sweep of HTLC.
364365 sweepTx := ctx .ReceiveTx ()
365366
366- if ! bytes .Equal (sweepTx .TxIn [0 ].PreviousOutPoint .Hash [:],
367- htlcOutpoint .Hash [:]) {
368- ctx .T .Fatalf ("client not sweeping from htlc tx" )
369- }
367+ require .Equal (
368+ ctx .T , htlcOutpoint .Hash [:],
369+ sweepTx .TxIn [0 ].PreviousOutPoint .Hash [:],
370+ "client not sweeping from htlc tx" ,
371+ )
370372
371373 var preImageIndex int
372374 switch scriptVersion {
@@ -380,9 +382,7 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
380382 // Check preimage.
381383 clientPreImage := sweepTx .TxIn [0 ].Witness [preImageIndex ]
382384 clientPreImageHash := sha256 .Sum256 (clientPreImage )
383- if clientPreImageHash != hash {
384- ctx .T .Fatalf ("incorrect preimage" )
385- }
385+ require .Equal (ctx .T , hash , lntypes .Hash (clientPreImageHash ))
386386
387387 // Since we successfully published our sweep, we expect the preimage to
388388 // have been pushed to our mock server.
0 commit comments