itest: check peer alias in ListChannels

This commit is contained in:
Slyghtning
2023-02-24 08:48:32 +01:00
parent 3e5943b7f9
commit 4c198bdfde
3 changed files with 41 additions and 3 deletions

View File

@@ -272,11 +272,20 @@ func testListChannels(ht *lntest.HarnessTest) {
// Check the returned response is correct. // Check the returned response is correct.
aliceChannel := ht.QueryChannelByChanPoint(alice, chanPoint) 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. // Since Alice is the initiator, she pays the commit fee.
aliceBalance := int64(chanAmt) - aliceChannel.CommitFee - int64(pushAmt) aliceBalance := int64(chanAmt) - aliceChannel.CommitFee - int64(pushAmt)
bobAlias := bob.RPC.GetInfo().Alias
// Check the balance related fields are correct. // Check the balance related fields are correct.
require.Equal(ht, aliceBalance, aliceChannel.LocalBalance) 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.RemoteBalance)
require.EqualValues(ht, pushAmt, aliceChannel.PushAmountSat) require.EqualValues(ht, pushAmt, aliceChannel.PushAmountSat)
@@ -318,8 +327,17 @@ func testListChannels(ht *lntest.HarnessTest) {
require.Equal(ht, aliceChannel.ChannelPoint, bobChannel.ChannelPoint, require.Equal(ht, aliceChannel.ChannelPoint, bobChannel.ChannelPoint,
"Bob's channel point mismatched") "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. // Check the balance related fields are correct.
require.Equal(ht, aliceBalance, bobChannel.RemoteBalance) 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.LocalBalance)
require.EqualValues(ht, pushAmt, bobChannel.PushAmountSat) require.EqualValues(ht, pushAmt, bobChannel.PushAmountSat)

View File

@@ -1598,10 +1598,12 @@ func (h *HarnessTest) MineEmptyBlocks(num int) []*wire.MsgBlock {
// QueryChannelByChanPoint tries to find a channel matching the channel point // QueryChannelByChanPoint tries to find a channel matching the channel point
// and asserts. It returns the channel found. // and asserts. It returns the channel found.
func (h *HarnessTest) QueryChannelByChanPoint(hn *node.HarnessNode, 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") require.NoError(h, err, "failed to query channel")
return channel return channel
} }

View File

@@ -31,6 +31,18 @@ import (
"google.golang.org/protobuf/proto" "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. // WaitForBlockchainSync waits until the node is synced to chain.
func (h *HarnessTest) WaitForBlockchainSync(hn *node.HarnessNode) { func (h *HarnessTest) WaitForBlockchainSync(hn *node.HarnessNode) {
err := wait.NoError(func() error { 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 // findChannel tries to find a target channel in the node using the given
// channel point. // channel point.
func (h *HarnessTest) findChannel(hn *node.HarnessNode, 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. // Get the funding point.
fp := h.OutPointFromChannelPoint(chanPoint) fp := h.OutPointFromChannelPoint(chanPoint)
req := &lnrpc.ListChannelsRequest{} req := &lnrpc.ListChannelsRequest{}
for _, opt := range opts {
opt(req)
}
channelInfo := hn.RPC.ListChannels(req) channelInfo := hn.RPC.ListChannels(req)
// Find the target channel. // Find the target channel.