From dc7b832e831b2a2e733ab07507b410404a170d61 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 24 Apr 2017 20:27:53 +0200 Subject: [PATCH] pytest: Added gossip test for new daemon --- tests/test_lightningd.py | 42 ++++++++++++++++++++++++++++++++++++++++ tests/utils.py | 12 ++++++++++++ 2 files changed, 54 insertions(+) diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index 63089c953..974b4a8d9 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -78,6 +78,8 @@ class NodeFactory(object): rpc = LegacyLightningRpc(socket_path, self.executor) else: daemon = utils.LightningD(lightning_dir, bitcoind.bitcoin_dir, port=port) + # TODO(cdecker) Move into LIGHTNINGD_CONFIG once legacy daemon was removed + daemon.cmd_line.append("--dev-broadcast-interval=1000") rpc = LightningRpc(socket_path, self.executor) node = utils.LightningNode(daemon, rpc, bitcoind, self.executor) @@ -299,6 +301,46 @@ class LightningDTests(BaseLightningDTests): # channeld pinging self.ping_tests(l1, l2) + def test_routing_gossip(self): + nodes = [self.node_factory.get_node(legacy=False) for _ in range(5)] + l1 = nodes[0] + l5 = nodes[4] + + for i in range(len(nodes)-1): + src, dst = nodes[i], nodes[i+1] + src.rpc.connect('localhost', dst.info['port'], dst.info['id']) + src.openchannel(dst, 20000) + + def settle_gossip(n): + """Wait for gossip to settle at the node + """ + expected_connections = 2*(len(nodes) - 1) + start_time = time.time() + # Wait at most 10 seconds, broadcast interval is 1 second + while time.time() - start_time < 10: + channels = n.rpc.getchannels()['channels'] + if len(channels) == expected_connections: + break + else: + time.sleep(0.1) + + for n in nodes: + settle_gossip(n) + + # Deep check that all channels are in there + comb = [] + for i in range(len(nodes) - 1): + comb.append((nodes[i].info['id'], nodes[i+1].info['id'])) + comb.append((nodes[i+1].info['id'], nodes[i].info['id'])) + + for n in nodes: + seen = [] + channels = n.rpc.getchannels()['channels'] + for c in channels: + seen.append((c['source'],c['destination'])) + assert set(seen) == set(comb) + + class LegacyLightningDTests(BaseLightningDTests): def test_connect(self): diff --git a/tests/utils.py b/tests/utils.py index 6eb55f268..b0cc0e9b9 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -260,3 +260,15 @@ class LightningNode(object): return self.executor.submit(wait_connected) else: return wait_connected() + + def openchannel(self, remote_node, capacity): + addr = self.rpc.newaddr()['address'] + txid = self.bitcoin.rpc.sendtoaddress(addr, capacity / 10**6) + tx = self.bitcoin.rpc.getrawtransaction(txid) + self.rpc.addfunds(tx) + self.rpc.fundchannel(remote_node.info['id'], capacity) + self.daemon.wait_for_log('sendrawtx exit 0, gave') + time.sleep(1) + self.bitcoin.rpc.generate(6) + self.daemon.wait_for_log('Normal operation') +