From 668063f61d3414005c2439e5bb6ba6e16c6ba1e9 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 13 Sep 2016 15:38:37 -0700 Subject: [PATCH] test: modify the networkHarness' OpenChannel method to use global IDs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit modifies the OpenChannel helper method within the networkHarness to open the channel according to the destination node’s global lighting ID rather than using a hard coded peer ID as before. With this change the method is now much more general as the prior temporary hack has been removed. --- networktest.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/networktest.go b/networktest.go index 36c406b26..a1f7eef0e 100644 --- a/networktest.go +++ b/networktest.go @@ -79,6 +79,11 @@ type lightningNode struct { nodeId int + // LightningId is the ID, or the sha256 of the node's identity public + // key. This field will only be populated once the node itself has been + // started via the start() method. + LightningID [32]byte + cmd *exec.Cmd pidFile string @@ -181,6 +186,18 @@ func (l *lightningNode) start() error { l.LightningClient = lnrpc.NewLightningClient(conn) + // Obtain the lnid of this node for quick identification purposes. + ctxb := context.Background() + info, err := l.GetInfo(ctxb, &lnrpc.GetInfoRequest{}) + if err != nil { + return nil + } + lnID, err := hex.DecodeString(info.LightningId) + if err != nil { + return err + } + copy(l.LightningID[:], lnID) + return nil } @@ -494,13 +511,10 @@ func (n *networkHarness) OpenChannel(ctx context.Context, srcNode, destNode *lightningNode, amt btcutil.Amount, numConfs uint32) (lnrpc.Lightning_OpenChannelClient, error) { - // TODO(roasbeef): should pass actual id instead, will fail if more - // connections added for Alice. openReq := &lnrpc.OpenChannelRequest{ - TargetPeerId: 1, - LocalFundingAmount: int64(amt), - RemoteFundingAmount: 0, - NumConfs: 1, + TargetNode: destNode.LightningID[:], + LocalFundingAmount: int64(amt), + NumConfs: numConfs, } respStream, err := srcNode.OpenChannel(ctx, openReq) if err != nil {