pytest: Replace wait_for_channels with an actual check

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-05-28 18:10:24 +02:00 committed by Rusty Russell
parent ba31dd2d9d
commit 202ce5e4ea
2 changed files with 10 additions and 1 deletions

View File

@ -3857,7 +3857,8 @@ class LightningDTests(BaseLightningDTests):
assert l2.rpc.listinvoices('inv1')['invoices'][0]['status'] == 'paid'
# FIXME: We should re-add pre-announced routes on startup!
self.wait_for_routes(l1, [chanid])
l1.bitcoin.rpc.generate(5)
l1.wait_channel_active(chanid)
# A duplicate should succeed immediately (nop) and return correct preimage.
preimage = l1.rpc.pay(inv1['bolt11'])['payment_preimage']

View File

@ -459,3 +459,11 @@ class LightningNode(object):
# Intermittent decoding failure. See if it decodes badly twice?
decoded2 = self.bitcoin.rpc.decoderawtransaction(tx)
raise ValueError("Can't find {} payment in {} (1={} 2={})".format(amount, tx, decoded, decoded2))
def is_channel_active(self, chanid):
channels = self.rpc.listchannels()['channels']
active = [(c['short_channel_id'], c['flags']) for c in channels if c['active']]
return (chanid, 0) in active and (chanid, 1) in active
def wait_channel_active(self, chanid):
wait_for(lambda: self.is_channel_active(chanid), interval=1)