1
0
Fork 0
mirror of https://github.com/lightningnetwork/lnd.git synced 2025-03-13 19:16:56 +01:00

itest: test config option for picking particular peers

This commit is contained in:
Turtle 2021-03-24 00:04:36 -04:00 committed by Orbital
parent 747161a1f4
commit 8d11a90d72
2 changed files with 49 additions and 0 deletions

View file

@ -3,10 +3,12 @@ package itest
import ( import (
"context" "context"
"fmt" "fmt"
network "net"
"strings" "strings"
"time" "time"
"github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntest"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -278,3 +280,46 @@ func connect(ctxt context.Context, node *lntest.HarnessNode,
} }
return nil 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)
}

View file

@ -395,4 +395,8 @@ var allTestCases = []*testCase{
name: "taproot", name: "taproot",
test: testTaproot, test: testTaproot,
}, },
{
name: "addpeer config",
test: testAddPeerConfig,
},
} }