1
1
package loop
2
2
3
3
import (
4
- "bytes"
5
4
"context"
6
5
"crypto/sha256"
7
6
"errors"
@@ -57,9 +56,7 @@ func TestLoopOutSuccess(t *testing.T) {
57
56
58
57
// Initiate loop out.
59
58
info , err := ctx .swapClient .LoopOut (context .Background (), & req )
60
- if err != nil {
61
- t .Fatal (err )
62
- }
59
+ require .NoError (t , err )
63
60
64
61
ctx .assertStored ()
65
62
ctx .assertStatus (loopdb .StateInitiated )
@@ -84,9 +81,7 @@ func TestLoopOutFailOffchain(t *testing.T) {
84
81
ctx := createClientTestContext (t , nil )
85
82
86
83
_ , err := ctx .swapClient .LoopOut (context .Background (), testRequest )
87
- if err != nil {
88
- t .Fatal (err )
89
- }
84
+ require .NoError (t , err )
90
85
91
86
ctx .assertStored ()
92
87
ctx .assertStatus (loopdb .StateInitiated )
@@ -208,14 +203,10 @@ func testLoopOutResume(t *testing.T, confs uint32, expired, preimageRevealed,
208
203
amt := btcutil .Amount (50000 )
209
204
210
205
swapPayReq , err := getInvoice (hash , amt , swapInvoiceDesc )
211
- if err != nil {
212
- t .Fatal (err )
213
- }
206
+ require .NoError (t , err )
214
207
215
208
prePayReq , err := getInvoice (hash , 100 , prepayInvoiceDesc )
216
- if err != nil {
217
- t .Fatal (err )
218
- }
209
+ require .NoError (t , err )
219
210
220
211
_ , senderPubKey := test .CreateKey (1 )
221
212
var senderKey [33 ]byte
@@ -284,16 +275,26 @@ func testLoopOutResume(t *testing.T, confs uint32, expired, preimageRevealed,
284
275
285
276
// Assert that the loopout htlc equals to the expected one.
286
277
scriptVersion := GetHtlcScriptVersion (protocolVersion )
278
+ var htlc * swap.Htlc
287
279
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 ())
291
296
}
292
297
293
- htlc , err := swap .NewHtlc (
294
- scriptVersion , pendingSwap .Contract .CltvExpiry , senderKey ,
295
- receiverKey , hash , outputType , & chaincfg .TestNet3Params ,
296
- )
297
298
require .NoError (t , err )
298
299
require .Equal (t , htlc .PkScript , confIntent .PkScript )
299
300
@@ -363,10 +364,11 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
363
364
// Expect client on-chain sweep of HTLC.
364
365
sweepTx := ctx .ReceiveTx ()
365
366
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
+ )
370
372
371
373
var preImageIndex int
372
374
switch scriptVersion {
@@ -380,9 +382,7 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
380
382
// Check preimage.
381
383
clientPreImage := sweepTx .TxIn [0 ].Witness [preImageIndex ]
382
384
clientPreImageHash := sha256 .Sum256 (clientPreImage )
383
- if clientPreImageHash != hash {
384
- ctx .T .Fatalf ("incorrect preimage" )
385
- }
385
+ require .Equal (ctx .T , hash , lntypes .Hash (clientPreImageHash ))
386
386
387
387
// Since we successfully published our sweep, we expect the preimage to
388
388
// have been pushed to our mock server.
0 commit comments