From 5f7cf307e7ff602051bd962de92033f73d298f4f Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Sun, 9 Feb 2020 17:45:28 +0100 Subject: [PATCH] pyln-testing: adds helper wait_for_htlcs Changelog-Added: pyln-testing adds wait_for_htlcs helper to settle HTLCs --- contrib/pyln-testing/pyln/testing/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py index 759e48556..a88e3af9f 100644 --- a/contrib/pyln-testing/pyln/testing/utils.py +++ b/contrib/pyln-testing/pyln/testing/utils.py @@ -790,6 +790,15 @@ class LightningNode(object): if time.time() > start_time + timeout: raise ValueError("Error waiting for a route to destination {}".format(destination)) + # This helper waits for all HTLCs to settle + def wait_for_htlcs(self): + peers = self.rpc.listpeers()['peers'] + for p, peer in enumerate(peers): + if 'channels' in peer: + for c, channel in enumerate(peer['channels']): + if 'htlcs' in channel: + wait_for(lambda: len(self.rpc.listpeers()['peers'][p]['channels'][c]['htlcs']) == 0) + def pay(self, dst, amt, label=None): if not label: label = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(20))