diff --git a/tests/test_connection.py b/tests/test_connection.py index f5ac204fd..fcfe11f9c 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -1094,7 +1094,7 @@ def test_fundee_forget_funding_tx_unconfirmed(node_factory, bitcoind): time.sleep(1) # Prevent funder from broadcasting funding tx. - l1.fake_bitcoind_fail(1) + l1.fake_bitcoind_fail('exit 1') # Fund the channel. # The process will complete, but funder will be unable # to broadcast and confirm funding tx. diff --git a/tests/test_misc.py b/tests/test_misc.py index 6674a58a8..d6e04ba2b 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -88,7 +88,7 @@ def test_bitcoin_failure(node_factory, bitcoind): # Make sure we're not failing it between getblockhash and getblock. sync_blockheight(bitcoind, [l1]) - l1.fake_bitcoind_fail(1) + l1.fake_bitcoind_fail('exit 1') # This should cause both estimatefee and getblockhash fail l1.daemon.wait_for_logs(['estimatesmartfee .* exited with status 1', diff --git a/tests/utils.py b/tests/utils.py index b93771a2b..21af3439e 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -601,15 +601,23 @@ class LightningNode(object): # wait for sendpay to comply self.rpc.waitsendpay(rhash) - def fake_bitcoind_fail(self, exitcode): + def fake_bitcoind_fail(self, failscript='exit 1', cmd=None): # Create and rename, for atomicity. f = os.path.join(self.daemon.lightning_dir, "bitcoin-cli-fail.tmp") with open(f, "w") as text_file: - text_file.write("%d" % exitcode) - os.rename(f, os.path.join(self.daemon.lightning_dir, "bitcoin-cli-fail")) + text_file.write(failscript) + if cmd: + failfile = "bitcoin-cli-fail-{}".format(cmd) + else: + failfile = "bitcoin-cli-fail" + os.rename(f, os.path.join(self.daemon.lightning_dir, failfile)) - def fake_bitcoind_unfail(self): - os.remove(os.path.join(self.daemon.lightning_dir, "bitcoin-cli-fail")) + def fake_bitcoind_unfail(self, cmd=None): + if cmd: + failfile = "bitcoin-cli-fail-{}".format(cmd) + else: + failfile = "bitcoin-cli-fail" + os.remove(os.path.join(self.daemon.lightning_dir, failfile)) class NodeFactory(object): @@ -701,8 +709,12 @@ class NodeFactory(object): cli = os.path.join(lightning_dir, "fake-bitcoin-cli") with open(cli, "w") as text_file: text_file.write('#! /bin/sh\n' - '! [ -f bitcoin-cli-fail ] || exit `cat bitcoin-cli-fail`\n' - 'exec bitcoin-cli "$@"\n') + '! [ -f bitcoin-cli-fail ] || . {ldir}/bitcoin-cli-fail\n' + 'for a in "$@"; do\n' + '\t! [ -f bitcoin-cli-fail-"$a" ] || . {ldir}/bitcoin-cli-fail-"$a"\n' + 'done\n' + 'exec bitcoin-cli "$@"\n' + .format(ldir=lightning_dir)) os.chmod(cli, os.stat(cli).st_mode | stat.S_IEXEC) daemon.opts['bitcoin-cli'] = cli