mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 08:04:26 +01:00
pytest: always use the fake-bitcoin-cli, name it more appropriately.
We're going to use it to override specific commands. It's non-valgrinded already since we use '--trace-children-skip=*bitcoin-cli*' so the overhead should be minimal. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
5e20eedb41
commit
7a77b81dff
@@ -601,18 +601,19 @@ class LightningNode(object):
|
||||
# wait for sendpay to comply
|
||||
self.rpc.waitsendpay(rhash)
|
||||
|
||||
def fake_bitcoind_fail(self, failscript='exit 1', cmd=None):
|
||||
def bitcoind_cmd_override(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(failscript)
|
||||
os.chmod(f, os.stat(f).st_mode | stat.S_IEXEC)
|
||||
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, cmd=None):
|
||||
def bitcoind_cmd_remove_override(self, cmd=None):
|
||||
if cmd:
|
||||
failfile = "bitcoin-cli-fail-{}".format(cmd)
|
||||
else:
|
||||
@@ -644,7 +645,6 @@ class NodeFactory(object):
|
||||
'may_fail',
|
||||
'may_reconnect',
|
||||
'random_hsm',
|
||||
'fake_bitcoin_cli'
|
||||
]
|
||||
node_opts = {k: v for k, v in opts.items() if k in node_opt_keys}
|
||||
cli_opts = {k: v for k, v in opts.items() if k not in node_opt_keys}
|
||||
@@ -673,8 +673,7 @@ class NodeFactory(object):
|
||||
|
||||
return [j.result() for j in jobs]
|
||||
|
||||
def get_node(self, disconnect=None, options=None, may_fail=False, may_reconnect=False, random_hsm=False,
|
||||
fake_bitcoin_cli=False):
|
||||
def get_node(self, disconnect=None, options=None, may_fail=False, may_reconnect=False, random_hsm=False):
|
||||
with self.lock:
|
||||
node_id = self.next_id
|
||||
self.next_id += 1
|
||||
@@ -705,18 +704,16 @@ class NodeFactory(object):
|
||||
if not may_reconnect:
|
||||
daemon.opts["dev-no-reconnect"] = None
|
||||
|
||||
if fake_bitcoin_cli:
|
||||
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 ] || . {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
|
||||
cli = os.path.join(lightning_dir, "fake-bitcoin-cli")
|
||||
with open(cli, "w") as text_file:
|
||||
text_file.write('#! /bin/sh\n'
|
||||
'! [ -x bitcoin-cli-fail ] || exec ./bitcoin-cli-fail "$@"\n'
|
||||
'for a in "$@"; do\n'
|
||||
'\t! [ -x bitcoin-cli-fail-"$a" ] || exec ./bitcoin-cli-fail-"$a" "$@"\n'
|
||||
'done\n'
|
||||
'exec bitcoin-cli "$@"\n')
|
||||
os.chmod(cli, os.stat(cli).st_mode | stat.S_IEXEC)
|
||||
daemon.opts['bitcoin-cli'] = cli
|
||||
|
||||
if options is not None:
|
||||
daemon.opts.update(options)
|
||||
|
||||
Reference in New Issue
Block a user