Browse Source

pytest: Added gossip test for new daemon

ppa-0.6.1
Christian Decker 8 years ago
committed by Rusty Russell
parent
commit
dc7b832e83
  1. 42
      tests/test_lightningd.py
  2. 12
      tests/utils.py

42
tests/test_lightningd.py

@ -78,6 +78,8 @@ class NodeFactory(object):
rpc = LegacyLightningRpc(socket_path, self.executor)
else:
daemon = utils.LightningD(lightning_dir, bitcoind.bitcoin_dir, port=port)
# TODO(cdecker) Move into LIGHTNINGD_CONFIG once legacy daemon was removed
daemon.cmd_line.append("--dev-broadcast-interval=1000")
rpc = LightningRpc(socket_path, self.executor)
node = utils.LightningNode(daemon, rpc, bitcoind, self.executor)
@ -299,6 +301,46 @@ class LightningDTests(BaseLightningDTests):
# channeld pinging
self.ping_tests(l1, l2)
def test_routing_gossip(self):
nodes = [self.node_factory.get_node(legacy=False) for _ in range(5)]
l1 = nodes[0]
l5 = nodes[4]
for i in range(len(nodes)-1):
src, dst = nodes[i], nodes[i+1]
src.rpc.connect('localhost', dst.info['port'], dst.info['id'])
src.openchannel(dst, 20000)
def settle_gossip(n):
"""Wait for gossip to settle at the node
"""
expected_connections = 2*(len(nodes) - 1)
start_time = time.time()
# Wait at most 10 seconds, broadcast interval is 1 second
while time.time() - start_time < 10:
channels = n.rpc.getchannels()['channels']
if len(channels) == expected_connections:
break
else:
time.sleep(0.1)
for n in nodes:
settle_gossip(n)
# Deep check that all channels are in there
comb = []
for i in range(len(nodes) - 1):
comb.append((nodes[i].info['id'], nodes[i+1].info['id']))
comb.append((nodes[i+1].info['id'], nodes[i].info['id']))
for n in nodes:
seen = []
channels = n.rpc.getchannels()['channels']
for c in channels:
seen.append((c['source'],c['destination']))
assert set(seen) == set(comb)
class LegacyLightningDTests(BaseLightningDTests):
def test_connect(self):

12
tests/utils.py

@ -260,3 +260,15 @@ class LightningNode(object):
return self.executor.submit(wait_connected)
else:
return wait_connected()
def openchannel(self, remote_node, capacity):
addr = self.rpc.newaddr()['address']
txid = self.bitcoin.rpc.sendtoaddress(addr, capacity / 10**6)
tx = self.bitcoin.rpc.getrawtransaction(txid)
self.rpc.addfunds(tx)
self.rpc.fundchannel(remote_node.info['id'], capacity)
self.daemon.wait_for_log('sendrawtx exit 0, gave')
time.sleep(1)
self.bitcoin.rpc.generate(6)
self.daemon.wait_for_log('Normal operation')

Loading…
Cancel
Save