mirror of
https://github.com/lightninglabs/loop
synced 2024-11-09 19:10:47 +00:00
Merge pull request #806 from starius/client-last-hop
client: fill LastHop in FetchSwaps
This commit is contained in:
commit
0c8d12a75e
@ -283,6 +283,7 @@ func (s *Client) FetchSwaps(ctx context.Context) ([]*SwapInfo, error) {
|
||||
SwapStateData: swp.State(),
|
||||
SwapHash: swp.Hash,
|
||||
LastUpdate: swp.LastUpdateTime(),
|
||||
LastHop: swp.Contract.LastHop,
|
||||
}
|
||||
|
||||
htlc, err := utils.GetHtlc(
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
"github.com/lightninglabs/loop/utils"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@ -45,6 +46,23 @@ var (
|
||||
defaultConfirmations = int32(loopdb.DefaultLoopOutHtlcConfirmations)
|
||||
)
|
||||
|
||||
var htlcKeys = func() loopdb.HtlcKeys {
|
||||
var senderKey, receiverKey [33]byte
|
||||
|
||||
// Generate keys.
|
||||
_, senderPubKey := test.CreateKey(1)
|
||||
copy(senderKey[:], senderPubKey.SerializeCompressed())
|
||||
_, receiverPubKey := test.CreateKey(2)
|
||||
copy(receiverKey[:], receiverPubKey.SerializeCompressed())
|
||||
|
||||
return loopdb.HtlcKeys{
|
||||
SenderScriptKey: senderKey,
|
||||
ReceiverScriptKey: receiverKey,
|
||||
SenderInternalPubKey: senderKey,
|
||||
ReceiverInternalPubKey: receiverKey,
|
||||
}
|
||||
}()
|
||||
|
||||
// TestLoopOutSuccess tests the loop out happy flow, using a custom htlc
|
||||
// confirmation target.
|
||||
func TestLoopOutSuccess(t *testing.T) {
|
||||
@ -437,3 +455,59 @@ func TestWrapGrpcError(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestFetchSwapsLastHop asserts that FetchSwaps loads LastHop for LoopIn's.
|
||||
func TestFetchSwapsLastHop(t *testing.T) {
|
||||
defer test.Guard(t)()
|
||||
|
||||
ctx := createClientTestContext(t, nil)
|
||||
|
||||
lastHop := route.Vertex{1, 2, 3}
|
||||
|
||||
// Create a loop in swap.
|
||||
swapHash := lntypes.Hash{1, 1, 1}
|
||||
swap := &loopdb.LoopInContract{
|
||||
SwapContract: loopdb.SwapContract{
|
||||
CltvExpiry: 111,
|
||||
AmountRequested: 111,
|
||||
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
||||
HtlcKeys: htlcKeys,
|
||||
},
|
||||
LastHop: &lastHop,
|
||||
}
|
||||
err := ctx.store.CreateLoopIn(context.Background(), swapHash, swap)
|
||||
require.NoError(t, err, "CreateLoopOut failed")
|
||||
|
||||
// Now read all the swaps from the store
|
||||
swapInfos, err := ctx.swapClient.FetchSwaps(context.Background())
|
||||
require.NoError(t, err, "FetchSwaps failed")
|
||||
|
||||
// Find the loop-in and compare with the expected value.
|
||||
require.Len(t, swapInfos, 1)
|
||||
loopInInfo := swapInfos[0]
|
||||
wantLoopInInfo := &SwapInfo{
|
||||
SwapHash: swapHash,
|
||||
SwapContract: loopdb.SwapContract{
|
||||
CltvExpiry: 111,
|
||||
AmountRequested: 111,
|
||||
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
||||
HtlcKeys: htlcKeys,
|
||||
},
|
||||
|
||||
// Make sure LastHop is filled.
|
||||
LastHop: &lastHop,
|
||||
}
|
||||
|
||||
// Calculate HtlcAddressP2TR.
|
||||
htlc, err := utils.GetHtlc(
|
||||
swapHash, &wantLoopInInfo.SwapContract,
|
||||
&chaincfg.TestNet3Params,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
wantLoopInInfo.HtlcAddressP2TR = htlc.Address
|
||||
|
||||
require.Equal(t, wantLoopInInfo, loopInInfo)
|
||||
|
||||
// Shutdown the client not to leak goroutines.
|
||||
ctx.finish()
|
||||
}
|
||||
|
@ -108,6 +108,7 @@ func newSwapClient(t *testing.T, config *clientConfig) *Client {
|
||||
sweeper: sweeper,
|
||||
executor: executor,
|
||||
resumeReady: make(chan struct{}),
|
||||
abandonChans: make(map[lntypes.Hash]chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user