From 4d8ad4e17d9c942d77b40fb588d841d675c83d51 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 17 Nov 2017 15:09:38 +0100 Subject: [PATCH] pytest: Test that upon reconnect the channel gets re-enabled Signed-off-by: Christian Decker --- tests/test_lightningd.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index d9b08ccf8..5856bac6b 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -253,6 +253,20 @@ class LightningDTests(BaseLightningDTests): decoded2=bitcoind.rpc.decoderawtransaction(tx) raise ValueError("Can't find {} payment in {} (1={} 2={})".format(amount, tx, decoded, decoded2)) + def line_graph(self, n=2): + """Build a line graph of the specified length and fund it. + """ + nodes = [self.node_factory.get_node() for _ in range(n)] + + for i in range(len(nodes)-1): + nodes[i].rpc.connect( + nodes[i+1].info['id'], + 'localhost:{}'.format(nodes[i+1].info['port']) + ) + self.fund_channel(nodes[i], nodes[i+1], 10**6) + + return nodes + def pay(self, lsrc, ldst, amt, label=None, async=False): if not label: label = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(20)) @@ -2181,5 +2195,25 @@ class LightningDTests(BaseLightningDTests): self.assertRaises(ValueError, l2.rpc.waitanyinvoice, 'doesntexist') + + def test_channel_reenable(self): + l1, l2 = self.line_graph(n=2) + + l1.bitcoin.rpc.generate(6) + l1.daemon.wait_for_log('Received node_announcement for node {}'.format(l2.info['id'])) + l2.daemon.wait_for_log('Received node_announcement for node {}'.format(l1.info['id'])) + + # Both directions should be active before the restart + assert [c['active'] for c in l1.rpc.getchannels()['channels']] == [True, True] + + # Restart l2, will cause l1 to reconnect + l2.stop() + l2.daemon.start() + + # Now they should sync and re-establish again + l1.daemon.wait_for_log('Received node_announcement for node {}'.format(l2.info['id'])) + l2.daemon.wait_for_log('Received node_announcement for node {}'.format(l1.info['id'])) + assert [c['active'] for c in l1.rpc.getchannels()['channels']] == [True, True] + if __name__ == '__main__': unittest.main(verbosity=2)