@@ -16,6 +16,7 @@ import (
16
16
"github.com/lightninglabs/loop/utils"
17
17
"github.com/lightningnetwork/lnd/lnrpc"
18
18
"github.com/lightningnetwork/lnd/lntypes"
19
+ "github.com/lightningnetwork/lnd/routing/route"
19
20
"github.com/stretchr/testify/require"
20
21
"google.golang.org/grpc/codes"
21
22
"google.golang.org/grpc/status"
45
46
defaultConfirmations = int32 (loopdb .DefaultLoopOutHtlcConfirmations )
46
47
)
47
48
49
+ var htlcKeys = func () loopdb.HtlcKeys {
50
+ var senderKey , receiverKey [33 ]byte
51
+
52
+ // Generate keys.
53
+ _ , senderPubKey := test .CreateKey (1 )
54
+ copy (senderKey [:], senderPubKey .SerializeCompressed ())
55
+ _ , receiverPubKey := test .CreateKey (2 )
56
+ copy (receiverKey [:], receiverPubKey .SerializeCompressed ())
57
+
58
+ return loopdb.HtlcKeys {
59
+ SenderScriptKey : senderKey ,
60
+ ReceiverScriptKey : receiverKey ,
61
+ SenderInternalPubKey : senderKey ,
62
+ ReceiverInternalPubKey : receiverKey ,
63
+ }
64
+ }()
65
+
48
66
// TestLoopOutSuccess tests the loop out happy flow, using a custom htlc
49
67
// confirmation target.
50
68
func TestLoopOutSuccess (t * testing.T ) {
@@ -437,3 +455,59 @@ func TestWrapGrpcError(t *testing.T) {
437
455
})
438
456
}
439
457
}
458
+
459
+ // TestFetchSwapsLastHop asserts that FetchSwaps loads LastHop for LoopIn's.
460
+ func TestFetchSwapsLastHop (t * testing.T ) {
461
+ defer test .Guard (t )()
462
+
463
+ ctx := createClientTestContext (t , nil )
464
+
465
+ lastHop := route.Vertex {1 , 2 , 3 }
466
+
467
+ // Create a loop in swap.
468
+ swapHash := lntypes.Hash {1 , 1 , 1 }
469
+ swap := & loopdb.LoopInContract {
470
+ SwapContract : loopdb.SwapContract {
471
+ CltvExpiry : 111 ,
472
+ AmountRequested : 111 ,
473
+ ProtocolVersion : loopdb .ProtocolVersionMuSig2 ,
474
+ HtlcKeys : htlcKeys ,
475
+ },
476
+ LastHop : & lastHop ,
477
+ }
478
+ err := ctx .store .CreateLoopIn (context .Background (), swapHash , swap )
479
+ require .NoError (t , err , "CreateLoopOut failed" )
480
+
481
+ // Now read all the swaps from the store
482
+ swapInfos , err := ctx .swapClient .FetchSwaps (context .Background ())
483
+ require .NoError (t , err , "FetchSwaps failed" )
484
+
485
+ // Find the loop-in and compare with the expected value.
486
+ require .Len (t , swapInfos , 1 )
487
+ loopInInfo := swapInfos [0 ]
488
+ wantLoopInInfo := & SwapInfo {
489
+ SwapHash : swapHash ,
490
+ SwapContract : loopdb.SwapContract {
491
+ CltvExpiry : 111 ,
492
+ AmountRequested : 111 ,
493
+ ProtocolVersion : loopdb .ProtocolVersionMuSig2 ,
494
+ HtlcKeys : htlcKeys ,
495
+ },
496
+
497
+ // Make sure LastHop is filled.
498
+ LastHop : & lastHop ,
499
+ }
500
+
501
+ // Calculate HtlcAddressP2TR.
502
+ htlc , err := utils .GetHtlc (
503
+ swapHash , & wantLoopInInfo .SwapContract ,
504
+ & chaincfg .TestNet3Params ,
505
+ )
506
+ require .NoError (t , err )
507
+ wantLoopInInfo .HtlcAddressP2TR = htlc .Address
508
+
509
+ require .Equal (t , wantLoopInInfo , loopInInfo )
510
+
511
+ // Shutdown the client not to leak goroutines.
512
+ ctx .finish ()
513
+ }
0 commit comments