From 79299a47803e75b66458d72fedd8396020531768 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 15 Jun 2021 06:37:38 +0930 Subject: [PATCH] pyln-client: hack in test that listchannels returns the same old/new. It sometimes fails because the two race, and sometimes because there's randomness, but it generally works (and doesn't fail systemically). We remove this before the final merge. Signed-off-by: Rusty Russell --- contrib/pyln-client/pyln/client/lightning.py | 45 +++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/contrib/pyln-client/pyln/client/lightning.py b/contrib/pyln-client/pyln/client/lightning.py index 7c088c249..363435543 100644 --- a/contrib/pyln-client/pyln/client/lightning.py +++ b/contrib/pyln-client/pyln/client/lightning.py @@ -876,7 +876,50 @@ class LightningRpc(UnixDomainSocketRpc): "short_channel_id": short_channel_id, "source": source } - return self.call("listchannels", payload) + + + # This is a hack to make sure old and new routines return the same result. + e1 = None + ret1 = None + err = None + try: + ret1 = self.call("listchannels", payload) + except RpcError as e: + err = e + e1 = e.error + e2 = None + ret2 = None + try: + ret2 = self.call("listchannelsold", payload) + except RpcError as e: + e2 = e.error + + print("new listchannels: {} exception {}".format(ret1, e1)) + print("old listchannels: {} exception {}".format(ret2, e2)) + # gossipd only marks a channel enabled again when channeld says to; + # our new code just requires a reconnection. So check that + # separately + if ret1: + assert len(ret1['channels']) == len(ret2['channels']) + for i in range(len(ret1['channels'])): + if ret1['channels'][i]['active'] and not ret2['channels'][i]['active']: + ret2['channels'][i]['active'] = True + + def chan_key(c): + return c['source'] + c['destination'] + + # Order is arbitrary + if ret1: + ret1['channels'].sort(key=chan_key) + if ret2: + ret2['channels'].sort(key=chan_key) + + assert ret1 == ret2 + assert e1 == e2 + + if err is not None: + raise err + return ret1 def listconfigs(self, config=None): """List this node's config.