From 8d11a90d72e2248a45d7cb566918b2fd0d0cc0aa Mon Sep 17 00:00:00 2001 From: Turtle Date: Wed, 24 Mar 2021 00:04:36 -0400 Subject: [PATCH] itest: test config option for picking particular peers --- lntest/itest/lnd_network_test.go | 45 +++++++++++++++++++++++++++ lntest/itest/lnd_test_list_on_test.go | 4 +++ 2 files changed, 49 insertions(+) diff --git a/lntest/itest/lnd_network_test.go b/lntest/itest/lnd_network_test.go index ab6bcf13c..f2ab0bd58 100644 --- a/lntest/itest/lnd_network_test.go +++ b/lntest/itest/lnd_network_test.go @@ -3,10 +3,12 @@ package itest import ( "context" "fmt" + network "net" "strings" "time" "github.com/lightningnetwork/lnd" + "github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lntest" "github.com/stretchr/testify/require" @@ -278,3 +280,46 @@ func connect(ctxt context.Context, node *lntest.HarnessNode, } return nil } + +// testAddPeerConfig tests that the "--addpeer" config flag successfully adds +// a new peer. +func testAddPeerConfig(net *lntest.NetworkHarness, t *harnessTest) { + ctxb := context.Background() + + ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout) + defer cancel() + alice := net.Alice + info, err := alice.GetInfo(ctxt, &lnrpc.GetInfoRequest{}) + require.NoError(t.t, err) + + alicePeerAddress := info.Uris[0] + + // Create a new node (Carol) with Alice as a peer. + args := []string{ + fmt.Sprintf("--addpeer=%v", alicePeerAddress), + } + carol := net.NewNode(t.t, "Carol", args) + defer shutdownAndAssert(net, t, carol) + + assertConnected(t, alice, carol) + + // If we list Carol's peers, Alice should already be + // listed as one, since we specified her using the + // addpeer flag. + ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout) + defer cancel() + listPeersRequest := &lnrpc.ListPeersRequest{} + listPeersResp, err := carol.ListPeers(ctxt, listPeersRequest) + require.NoError(t.t, err) + + parsedPeerAddr, err := lncfg.ParseLNAddressString( + alicePeerAddress, "9735", network.ResolveTCPAddr, + ) + require.NoError(t.t, err) + + parsedKeyStr := fmt.Sprintf( + "%x", parsedPeerAddr.IdentityKey.SerializeCompressed(), + ) + + require.Equal(t.t, parsedKeyStr, listPeersResp.Peers[0].PubKey) +} diff --git a/lntest/itest/lnd_test_list_on_test.go b/lntest/itest/lnd_test_list_on_test.go index fe6dc0a2a..1c6f024f2 100644 --- a/lntest/itest/lnd_test_list_on_test.go +++ b/lntest/itest/lnd_test_list_on_test.go @@ -395,4 +395,8 @@ var allTestCases = []*testCase{ name: "taproot", test: testTaproot, }, + { + name: "addpeer config", + test: testAddPeerConfig, + }, }