From 6cea8d2e5bcb2cb8722d94e453d8f49348a3ad6f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 12 Jan 2018 20:37:42 +1030 Subject: [PATCH] test_lightning.py: test_onchain_middleman must wait for route propagation Signed-off-by: Rusty Russell --- tests/test_lightningd.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index f0d106b7b..cf5f09783 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -300,6 +300,16 @@ class LightningDTests(BaseLightningDTests): else: lsrc.rpc.sendpay(to_json([routestep]), rhash, async=False) + # This waits until gossipd sees channel_update in both directions + # (or for local channels, at least a local announcment) + def wait_for_routes(self, l1, channel_ids): + bitcoind.generate_block(5) + # Could happen in any order... + l1.daemon.wait_for_logs(['Channel {}\\(0\\) was updated'.format(c) + for c in channel_ids] + + ['Channel {}\\(1\\) was updated'.format(c) + for c in channel_ids]) + @unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1") def test_shutdown(self): # Fail, in that it will exit before cleanup. @@ -1032,18 +1042,17 @@ class LightningDTests(BaseLightningDTests): # l2 connects to both, so l1 can't reconnect and thus l2 drops to chain l2.rpc.connect(l1.info['id'], 'localhost', l1.info['port']) l2.rpc.connect(l3.info['id'], 'localhost', l3.info['port']) - self.fund_channel(l2, l1, 10**6) - self.fund_channel(l2, l3, 10**6) + c12 = self.fund_channel(l2, l1, 10**6) + c23 = self.fund_channel(l2, l3, 10**6) + + # Make sure routes finalized. + self.wait_for_routes(l1, [c23]) # Give l1 some money to play with. self.pay(l2, l1, 2 * 10**8) # Must be bigger than dust! rhash = l3.rpc.invoice(10**8, 'middleman', 'desc')['rhash'] - # Wait for route propagation. - l1.bitcoin.generate_block(5) - l1.daemon.wait_for_log('Received node_announcement for node {}' - .format(l3.info['id'])) route = l1.rpc.getroute(l3.info['id'], 10**8, 1)["route"] assert len(route) == 2