Skip to content

Commit

Permalink
pytest: Test that upon reconnect the channel gets re-enabled
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Decker <[email protected]>
  • Loading branch information
cdecker authored and rustyrussell committed Nov 20, 2017
1 parent aeeb0b7 commit 4d8ad4e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/test_lightningd.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,20 @@ def fund_channel(self, l1, l2, amount):
decoded2=bitcoind.rpc.decoderawtransaction(tx)
raise ValueError("Can't find {} payment in {} (1={} 2={})".format(amount, tx, decoded, decoded2))

def line_graph(self, n=2):
"""Build a line graph of the specified length and fund it.
"""
nodes = [self.node_factory.get_node() for _ in range(n)]

for i in range(len(nodes)-1):
nodes[i].rpc.connect(
nodes[i+1].info['id'],
'localhost:{}'.format(nodes[i+1].info['port'])
)
self.fund_channel(nodes[i], nodes[i+1], 10**6)

return nodes

def pay(self, lsrc, ldst, amt, label=None, async=False):
if not label:
label = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(20))
Expand Down Expand Up @@ -2181,5 +2195,25 @@ def test_waitanyinvoice(self):

self.assertRaises(ValueError, l2.rpc.waitanyinvoice, 'doesntexist')


def test_channel_reenable(self):
l1, l2 = self.line_graph(n=2)

l1.bitcoin.rpc.generate(6)
l1.daemon.wait_for_log('Received node_announcement for node {}'.format(l2.info['id']))
l2.daemon.wait_for_log('Received node_announcement for node {}'.format(l1.info['id']))

# Both directions should be active before the restart
assert [c['active'] for c in l1.rpc.getchannels()['channels']] == [True, True]

# Restart l2, will cause l1 to reconnect
l2.stop()
l2.daemon.start()

# Now they should sync and re-establish again
l1.daemon.wait_for_log('Received node_announcement for node {}'.format(l2.info['id']))
l2.daemon.wait_for_log('Received node_announcement for node {}'.format(l1.info['id']))
assert [c['active'] for c in l1.rpc.getchannels()['channels']] == [True, True]

if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit 4d8ad4e

Please sign in to comment.