From 4c198bdfdeb35b25c16aee87847a136fc1299d16 Mon Sep 17 00:00:00 2001 From: Slyghtning Date: Fri, 24 Feb 2023 08:48:32 +0100 Subject: [PATCH] itest: check peer alias in ListChannels --- itest/lnd_misc_test.go | 18 ++++++++++++++++++ lntest/harness.go | 6 ++++-- lntest/harness_assertion.go | 20 +++++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/itest/lnd_misc_test.go b/itest/lnd_misc_test.go index 577462afe..59da665e6 100644 --- a/itest/lnd_misc_test.go +++ b/itest/lnd_misc_test.go @@ -272,11 +272,20 @@ func testListChannels(ht *lntest.HarnessTest) { // Check the returned response is correct. aliceChannel := ht.QueryChannelByChanPoint(alice, chanPoint) + // Query the channel again, this time with peer alias lookup. + aliceChannelWithAlias := ht.QueryChannelByChanPoint( + alice, chanPoint, lntest.WithPeerAliasLookup(), + ) + // Since Alice is the initiator, she pays the commit fee. aliceBalance := int64(chanAmt) - aliceChannel.CommitFee - int64(pushAmt) + bobAlias := bob.RPC.GetInfo().Alias + // Check the balance related fields are correct. require.Equal(ht, aliceBalance, aliceChannel.LocalBalance) + require.Empty(ht, aliceChannel.PeerAlias) + require.Equal(ht, bobAlias, aliceChannelWithAlias.PeerAlias) require.EqualValues(ht, pushAmt, aliceChannel.RemoteBalance) require.EqualValues(ht, pushAmt, aliceChannel.PushAmountSat) @@ -318,8 +327,17 @@ func testListChannels(ht *lntest.HarnessTest) { require.Equal(ht, aliceChannel.ChannelPoint, bobChannel.ChannelPoint, "Bob's channel point mismatched") + // Query the channel again, this time with node alias lookup. + bobChannelWithAlias := ht.QueryChannelByChanPoint( + bob, chanPoint, lntest.WithPeerAliasLookup(), + ) + + aliceAlias := alice.RPC.GetInfo().Alias + // Check the balance related fields are correct. require.Equal(ht, aliceBalance, bobChannel.RemoteBalance) + require.Empty(ht, bobChannel.PeerAlias) + require.Equal(ht, aliceAlias, bobChannelWithAlias.PeerAlias) require.EqualValues(ht, pushAmt, bobChannel.LocalBalance) require.EqualValues(ht, pushAmt, bobChannel.PushAmountSat) diff --git a/lntest/harness.go b/lntest/harness.go index 963826a1e..1d11a85e8 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -1598,10 +1598,12 @@ func (h *HarnessTest) MineEmptyBlocks(num int) []*wire.MsgBlock { // QueryChannelByChanPoint tries to find a channel matching the channel point // and asserts. It returns the channel found. func (h *HarnessTest) QueryChannelByChanPoint(hn *node.HarnessNode, - chanPoint *lnrpc.ChannelPoint) *lnrpc.Channel { + chanPoint *lnrpc.ChannelPoint, + opts ...ListChannelOption) *lnrpc.Channel { - channel, err := h.findChannel(hn, chanPoint) + channel, err := h.findChannel(hn, chanPoint, opts...) require.NoError(h, err, "failed to query channel") + return channel } diff --git a/lntest/harness_assertion.go b/lntest/harness_assertion.go index f6f1ee96e..bf1bb4ba8 100644 --- a/lntest/harness_assertion.go +++ b/lntest/harness_assertion.go @@ -31,6 +31,18 @@ import ( "google.golang.org/protobuf/proto" ) +// FindChannelOption is a functional type for an option that modifies a +// ListChannelsRequest. +type ListChannelOption func(r *lnrpc.ListChannelsRequest) + +// WithPeerAliasLookup is an option for setting the peer alias lookup flag on a +// ListChannelsRequest. +func WithPeerAliasLookup() ListChannelOption { + return func(r *lnrpc.ListChannelsRequest) { + r.PeerAliasLookup = true + } +} + // WaitForBlockchainSync waits until the node is synced to chain. func (h *HarnessTest) WaitForBlockchainSync(hn *node.HarnessNode) { err := wait.NoError(func() error { @@ -368,12 +380,18 @@ func (h *HarnessTest) AssertChannelExists(hn *node.HarnessNode, // findChannel tries to find a target channel in the node using the given // channel point. func (h *HarnessTest) findChannel(hn *node.HarnessNode, - chanPoint *lnrpc.ChannelPoint) (*lnrpc.Channel, error) { + chanPoint *lnrpc.ChannelPoint, + opts ...ListChannelOption) (*lnrpc.Channel, error) { // Get the funding point. fp := h.OutPointFromChannelPoint(chanPoint) req := &lnrpc.ListChannelsRequest{} + + for _, opt := range opts { + opt(req) + } + channelInfo := hn.RPC.ListChannels(req) // Find the target channel.