pytest: allow more elaborate bitcoin-cli override.
In particular, this lets us intercept individual commands, such as estimatesmartfee. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
3d8836c1e5
commit
5e20eedb41
|
@ -1094,7 +1094,7 @@ def test_fundee_forget_funding_tx_unconfirmed(node_factory, bitcoind):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# Prevent funder from broadcasting funding tx.
|
# Prevent funder from broadcasting funding tx.
|
||||||
l1.fake_bitcoind_fail(1)
|
l1.fake_bitcoind_fail('exit 1')
|
||||||
# Fund the channel.
|
# Fund the channel.
|
||||||
# The process will complete, but funder will be unable
|
# The process will complete, but funder will be unable
|
||||||
# to broadcast and confirm funding tx.
|
# to broadcast and confirm funding tx.
|
||||||
|
|
|
@ -88,7 +88,7 @@ def test_bitcoin_failure(node_factory, bitcoind):
|
||||||
# Make sure we're not failing it between getblockhash and getblock.
|
# Make sure we're not failing it between getblockhash and getblock.
|
||||||
sync_blockheight(bitcoind, [l1])
|
sync_blockheight(bitcoind, [l1])
|
||||||
|
|
||||||
l1.fake_bitcoind_fail(1)
|
l1.fake_bitcoind_fail('exit 1')
|
||||||
|
|
||||||
# This should cause both estimatefee and getblockhash fail
|
# This should cause both estimatefee and getblockhash fail
|
||||||
l1.daemon.wait_for_logs(['estimatesmartfee .* exited with status 1',
|
l1.daemon.wait_for_logs(['estimatesmartfee .* exited with status 1',
|
||||||
|
|
|
@ -601,15 +601,23 @@ class LightningNode(object):
|
||||||
# wait for sendpay to comply
|
# wait for sendpay to comply
|
||||||
self.rpc.waitsendpay(rhash)
|
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.
|
# Create and rename, for atomicity.
|
||||||
f = os.path.join(self.daemon.lightning_dir, "bitcoin-cli-fail.tmp")
|
f = os.path.join(self.daemon.lightning_dir, "bitcoin-cli-fail.tmp")
|
||||||
with open(f, "w") as text_file:
|
with open(f, "w") as text_file:
|
||||||
text_file.write("%d" % exitcode)
|
text_file.write(failscript)
|
||||||
os.rename(f, os.path.join(self.daemon.lightning_dir, "bitcoin-cli-fail"))
|
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):
|
def fake_bitcoind_unfail(self, cmd=None):
|
||||||
os.remove(os.path.join(self.daemon.lightning_dir, "bitcoin-cli-fail"))
|
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):
|
class NodeFactory(object):
|
||||||
|
@ -701,8 +709,12 @@ class NodeFactory(object):
|
||||||
cli = os.path.join(lightning_dir, "fake-bitcoin-cli")
|
cli = os.path.join(lightning_dir, "fake-bitcoin-cli")
|
||||||
with open(cli, "w") as text_file:
|
with open(cli, "w") as text_file:
|
||||||
text_file.write('#! /bin/sh\n'
|
text_file.write('#! /bin/sh\n'
|
||||||
'! [ -f bitcoin-cli-fail ] || exit `cat bitcoin-cli-fail`\n'
|
'! [ -f bitcoin-cli-fail ] || . {ldir}/bitcoin-cli-fail\n'
|
||||||
'exec bitcoin-cli "$@"\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)
|
os.chmod(cli, os.stat(cli).st_mode | stat.S_IEXEC)
|
||||||
daemon.opts['bitcoin-cli'] = cli
|
daemon.opts['bitcoin-cli'] = cli
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue