Browse Source

test_lightningd: add test for funding failures.

We should not disconnect from a peer just because it fails opening; we
should return it to gossipd, and give a meaningful error.

Closes: #401
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
8ed511b3c7
  1. 55
      tests/test_lightningd.py

55
tests/test_lightningd.py

@ -2160,6 +2160,61 @@ class LightningDTests(BaseLightningDTests):
assert outputs[0] > 8990000
assert outputs[2] == 10000000
def test_funding_fail(self):
"""Add some funds, fund a channel without enough funds"""
# Previous runs with same bitcoind can leave funds!
l1 = self.node_factory.get_node(random_hsm=True)
max_locktime = 3 * 6 * 24
l2 = self.node_factory.get_node(options=['--locktime-blocks={}'.format(max_locktime + 1)])
l1.rpc.connect(l2.info['id'], 'localhost', l2.info['port'])
addr = l1.rpc.newaddr()['address']
txid = l1.bitcoin.rpc.sendtoaddress(addr, 0.01)
bitcoind.generate_block(1)
# Wait for it to arrive.
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
# Fail because l1 dislikes l2's huge locktime.
try:
l1.rpc.fundchannel(l2.info['id'], 100000)
except ValueError as verr:
str(verr).index('to_self_delay {} larger than {}'
.format(max_locktime+1, max_locktime))
except Exception as err:
self.fail("Unexpected exception {}".format(err))
else:
self.fail("huge locktime ignored?")
# We don't have enough left to cover fees if we try to spend it all.
try:
l1.rpc.fundchannel(l2.info['id'], 1000000)
except ValueError as verr:
str(verr).index('Cannot afford funding transaction')
except Exception as err:
self.fail("Unexpected exception {}".format(err))
else:
self.fail("We somehow covered fees?")
# Should still be connected.
assert l1.rpc.getpeers()['peers'][0]['connected']
assert l2.rpc.getpeers()['peers'][0]['connected']
# Restart l2 without ridiculous locktime.
l2.daemon.proc.terminate()
l2.daemon.cmd_line.remove('--locktime-blocks={}'.format(max_locktime + 1))
# Wait for l1 to notice
wait_for(lambda: len(l1.rpc.getpeers()['peers']) == 0)
# Now restart l2, reconnect.
l2.daemon.start()
l1.rpc.connect(l2.info['id'], 'localhost', l2.info['port'])
# This works.
l1.rpc.fundchannel(l2.info['id'], int(0.01 * 10**8 / 2))
def test_addfunds_from_block(self):
"""Send funds to the daemon without telling it explicitly
"""

Loading…
Cancel
Save