diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index 22e4ce90d..bc50f427b 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -2168,52 +2168,36 @@ class LightningDTests(BaseLightningDTests): l2 = self.node_factory.get_node(options=['--locktime-blocks={}'.format(max_locktime + 1)]) l1.rpc.connect(l2.info['id'], 'localhost', l2.info['port']) + funds = 1000000 + addr = l1.rpc.newaddr()['address'] - txid = l1.bitcoin.rpc.sendtoaddress(addr, 0.01) + txid = l1.bitcoin.rpc.sendtoaddress(addr, funds / 10**8) 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. + self.assertRaisesRegex(ValueError, r'to_self_delay \d+ larger than \d+', + l1.rpc.fundchannel, l2.info['id'], int(funds/10)) 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)) + l2.restart() + l1.rpc.connect(l2.info['id'], 'localhost', l2.info['port']) - # Wait for l1 to notice - wait_for(lambda: len(l1.rpc.getpeers()['peers']) == 0) + # We don't have enough left to cover fees if we try to spend it all. + self.assertRaisesRegex(ValueError, r'Cannot afford funding transaction', + l1.rpc.fundchannel, l2.info['id'], funds) - # Now restart l2, reconnect. - l2.daemon.start() - l1.rpc.connect(l2.info['id'], 'localhost', l2.info['port']) + # Should still be connected. + assert l1.rpc.getpeers()['peers'][0]['connected'] + assert l2.rpc.getpeers()['peers'][0]['connected'] # This works. - l1.rpc.fundchannel(l2.info['id'], int(0.01 * 10**8 / 2)) + l1.rpc.fundchannel(l2.info['id'], int(funds/10)) def test_addfunds_from_block(self): """Send funds to the daemon without telling it explicitly diff --git a/tests/utils.py b/tests/utils.py index b15191455..fda6a7891 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -79,8 +79,8 @@ class TailableProc(object): self.proc.wait() self.thread.join() - if failed: - raise(ValueError("Process '{}' did not cleanly shutdown".format(self.proc.pid))) + if self.proc.returncode: + raise ValueError("Process '{}' did not cleanly shutdown: return code {}".format(self.proc.pid, rc)) return self.proc.returncode @@ -364,3 +364,17 @@ class LightningNode(object): raise ValueError("Node did not exit cleanly, rc={}".format(rc)) else: return rc + + def restart(self, timeout=10, clean=True): + """Stop and restart the lightning node. + + Keyword arguments: + timeout: number of seconds to wait for a shutdown + clean: whether to issue a `stop` RPC command before killing + """ + if clean: + self.stop(timeout) + else: + self.daemon.stop() + + self.daemon.start()