From 010a4f15718737f4daf1c7c5a2364d778e741829 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Wed, 20 Nov 2024 14:52:28 +0800 Subject: [PATCH] lntest: add human-readble names and check num of nodes --- lntest/harness.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lntest/harness.go b/lntest/harness.go index 281d5ff0b..36a66ed0e 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -2165,6 +2165,13 @@ func acceptChannel(t *testing.T, zeroConf bool, stream rpc.AcceptorClient) { require.NoError(t, err) } +// nodeNames defines a slice of human-reable names for the nodes created in the +// `createNodes` method. 8 nodes are defined here as by default we can only +// create this many nodes in one test. +var nodeNames = []string{ + "Alice", "Bob", "Carol", "Dave", "Eve", "Frank", "Grace", "Heidi", +} + // createNodes creates the number of nodes specified by the number of configs. // Each node is created using the specified config, the neighbors are // connected. @@ -2172,12 +2179,15 @@ func (h *HarnessTest) createNodes(nodeCfgs [][]string) []*node.HarnessNode { // Get the number of nodes. numNodes := len(nodeCfgs) + // Make sure we are creating a reasonable number of nodes. + require.LessOrEqual(h, numNodes, len(nodeNames), "too many nodes") + // Make a slice of nodes. nodes := make([]*node.HarnessNode, numNodes) // Create new nodes. for i, nodeCfg := range nodeCfgs { - nodeName := fmt.Sprintf("Node%q", string(rune('A'+i))) + nodeName := nodeNames[i] n := h.NewNode(nodeName, nodeCfg) nodes[i] = n }