From 882cafd3c779f37fad41a5c2a3e84afb03d66594 Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Thu, 16 Feb 2023 16:49:19 +0100 Subject: [PATCH] pytest: adds skipped test_create_gossip_mesh This can be adapted and used to create test gossip stores. The test is just skipped by design as it would fail on intention. --- contrib/pyln-testing/pyln/testing/utils.py | 11 +++++- tests/test_misc.py | 45 ++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py index 722aeb49b..34a59baa5 100644 --- a/contrib/pyln-testing/pyln/testing/utils.py +++ b/contrib/pyln-testing/pyln/testing/utils.py @@ -838,7 +838,7 @@ class LightningNode(object): ) def connect(self, remote_node): - self.rpc.connect(remote_node.info['id'], '127.0.0.1', remote_node.daemon.port) + self.rpc.connect(remote_node.info['id'], '127.0.0.1', remote_node.port) def is_connected(self, remote_node): return remote_node.info['id'] in [p['id'] for p in self.rpc.listpeers()['peers']] @@ -846,6 +846,7 @@ class LightningNode(object): def openchannel(self, remote_node, capacity=FUNDAMOUNT, addrtype="bech32", confirm=True, wait_for_announce=True, connect=True): addr, wallettxid = self.fundwallet(10 * capacity, addrtype) + # connect if necessary if connect and not self.is_connected(remote_node): self.connect(remote_node) @@ -892,7 +893,9 @@ class LightningNode(object): else: chan_capacity = total_capacity - self.rpc.connect(remote_node.info['id'], 'localhost', remote_node.port) + # connect if necessary + if not self.is_connected(remote_node): + self.connect(remote_node) res = self.rpc.fundchannel(remote_node.info['id'], chan_capacity, feerate='slow', minconf=0, announce=announce, push_msat=Millisatoshi(chan_capacity * 500)) blockid = self.bitcoin.generate_block(1, wait_for_mempool=res['txid'])[0] @@ -994,6 +997,10 @@ class LightningNode(object): # Now we should. wait_for(lambda: has_funds_on_addr(addr)) + # connect if necessary + if not self.is_connected(l2): + self.connect(l2) + # Now go ahead and open a channel res = self.rpc.fundchannel(l2.info['id'], amount, announce=announce_channel, diff --git a/tests/test_misc.py b/tests/test_misc.py index 6b8f04610..517102a63 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -3102,3 +3102,48 @@ def test_hsm_capabilities(node_factory): l1 = node_factory.get_node() # This appears before the start message, so it'll already be present. assert l1.daemon.is_in_log(r"hsmd: capability \+WIRE_HSMD_CHECK_PUBKEY") + + +@pytest.mark.skip(reason="Fails by intention for creating test gossip stores") +def test_create_gossip_mesh(node_factory, bitcoind): + """ + Feel free to modify this test and remove the '@pytest.mark.skip' above. + Run it to get a customized gossip store. It fails on purpose, see below. + + This builds a small mesh + + l1--l2--l3 + | | | + l4--l5--l6 + | | | + l7--l8--l9 + """ + nodes = node_factory.get_nodes(9) + nodeids = [n.info['id'] for n in nodes] + + [l1, l2, l3, l4, l5, l6, l7, l8, l9] = nodes + scid12, _ = l1.fundchannel(l2, wait_for_active=False, connect=True) + scid14, _ = l1.fundchannel(l4, wait_for_active=False, connect=True) + scid23, _ = l2.fundchannel(l3, wait_for_active=False, connect=True) + scid25, _ = l2.fundchannel(l5, wait_for_active=False, connect=True) + scid36, _ = l3.fundchannel(l6, wait_for_active=False, connect=True) + scid45, _ = l4.fundchannel(l5, wait_for_active=False, connect=True) + scid47, _ = l4.fundchannel(l7, wait_for_active=False, connect=True) + scid56, _ = l5.fundchannel(l6, wait_for_active=False, connect=True) + scid58, _ = l5.fundchannel(l8, wait_for_active=False, connect=True) + scid69, _ = l6.fundchannel(l9, wait_for_active=False, connect=True) + scid78, _ = l7.fundchannel(l8, wait_for_active=False, connect=True) + scid89, _ = l8.fundchannel(l9, wait_for_active=False, connect=True) + bitcoind.generate_block(10) + + scids = [scid12, scid14, scid23, scid25, scid36, scid45, scid47, scid56, + scid58, scid69, scid78, scid89] + + # waits for all nodes to have all scids gossip active + for n in nodes: + for scid in scids: + n.wait_channel_active(scid) + + print("nodeids", nodeids) + print("scids", scids) + assert False, "Test failed on purpose, grab the gossip store from /tmp/ltests-..."