From 2c77fc5bf2ed462862100bf5f565047871194684 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 2 Aug 2018 16:23:04 +0200 Subject: [PATCH] pytest: Add a helper to determine a node's peer channel state --- tests/utils.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/utils.py b/tests/utils.py index d79d4216a..dab36d27f 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -507,6 +507,28 @@ class LightningNode(object): return group.group(1) raise ValueError("No daemon {} found".format(subd)) + def channel_state(self, other): + """Return the state of the channel to the other node. + + Returns None if there is no such peer, or a channel hasn't been funded + yet. + + """ + peers = self.rpc.listpeers(other.info['id'])['peers'] + if not peers or 'channels' not in peers[0]: + return None + channel = peers[0]['channels'][0] + return channel['state'] + + def get_channel_scid(self, other): + """Get the short_channel_id for the channel to the other node. + """ + peers = self.rpc.listpeers(other.info['id'])['peers'] + if not peers or 'channels' not in peers[0]: + return None + channel = peers[0]['channels'][0] + return channel['short_channel_id'] + 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']]