mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 16:14:23 +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
@@ -1083,7 +1083,7 @@ def test_fundee_forget_funding_tx_unconfirmed(node_factory, bitcoind):
|
|||||||
# blocks.
|
# blocks.
|
||||||
blocks = 200
|
blocks = 200
|
||||||
# funder
|
# funder
|
||||||
l1 = node_factory.get_node(fake_bitcoin_cli=True)
|
l1 = node_factory.get_node()
|
||||||
# fundee
|
# fundee
|
||||||
l2 = node_factory.get_node(options={"dev-max-funding-unconfirmed-blocks": blocks})
|
l2 = node_factory.get_node(options={"dev-max-funding-unconfirmed-blocks": blocks})
|
||||||
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
|
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
|
||||||
@@ -1094,13 +1094,13 @@ 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('exit 1')
|
l1.bitcoind_cmd_override('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.
|
||||||
l1.rpc.fundchannel(l2.info['id'], 10**6)
|
l1.rpc.fundchannel(l2.info['id'], 10**6)
|
||||||
# Prevent l1 from timing out bitcoin-cli.
|
# Prevent l1 from timing out bitcoin-cli.
|
||||||
l1.fake_bitcoind_unfail()
|
l1.bitcoind_cmd_remove_override()
|
||||||
# Generate blocks until unconfirmed.
|
# Generate blocks until unconfirmed.
|
||||||
bitcoind.generate_block(blocks)
|
bitcoind.generate_block(blocks)
|
||||||
|
|
||||||
|
|||||||
@@ -83,12 +83,12 @@ def test_db_upgrade(node_factory):
|
|||||||
|
|
||||||
|
|
||||||
def test_bitcoin_failure(node_factory, bitcoind):
|
def test_bitcoin_failure(node_factory, bitcoind):
|
||||||
l1 = node_factory.get_node(fake_bitcoin_cli=True)
|
l1 = node_factory.get_node()
|
||||||
|
|
||||||
# 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('exit 1')
|
l1.bitcoind_cmd_override('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',
|
||||||
@@ -99,7 +99,7 @@ def test_bitcoin_failure(node_factory, bitcoind):
|
|||||||
'getblockhash .* exited with status 1'])
|
'getblockhash .* exited with status 1'])
|
||||||
|
|
||||||
# Restore, then it should recover and get blockheight.
|
# Restore, then it should recover and get blockheight.
|
||||||
l1.fake_bitcoind_unfail()
|
l1.bitcoind_cmd_remove_override()
|
||||||
bitcoind.generate_block(5)
|
bitcoind.generate_block(5)
|
||||||
sync_blockheight(bitcoind, [l1])
|
sync_blockheight(bitcoind, [l1])
|
||||||
|
|
||||||
|
|||||||
@@ -601,18 +601,19 @@ 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, failscript='exit 1', cmd=None):
|
def bitcoind_cmd_override(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(failscript)
|
text_file.write(failscript)
|
||||||
|
os.chmod(f, os.stat(f).st_mode | stat.S_IEXEC)
|
||||||
if cmd:
|
if cmd:
|
||||||
failfile = "bitcoin-cli-fail-{}".format(cmd)
|
failfile = "bitcoin-cli-fail-{}".format(cmd)
|
||||||
else:
|
else:
|
||||||
failfile = "bitcoin-cli-fail"
|
failfile = "bitcoin-cli-fail"
|
||||||
os.rename(f, os.path.join(self.daemon.lightning_dir, failfile))
|
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:
|
if cmd:
|
||||||
failfile = "bitcoin-cli-fail-{}".format(cmd)
|
failfile = "bitcoin-cli-fail-{}".format(cmd)
|
||||||
else:
|
else:
|
||||||
@@ -644,7 +645,6 @@ class NodeFactory(object):
|
|||||||
'may_fail',
|
'may_fail',
|
||||||
'may_reconnect',
|
'may_reconnect',
|
||||||
'random_hsm',
|
'random_hsm',
|
||||||
'fake_bitcoin_cli'
|
|
||||||
]
|
]
|
||||||
node_opts = {k: v for k, v in opts.items() if k in node_opt_keys}
|
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}
|
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]
|
return [j.result() for j in jobs]
|
||||||
|
|
||||||
def get_node(self, disconnect=None, options=None, may_fail=False, may_reconnect=False, random_hsm=False,
|
def get_node(self, disconnect=None, options=None, may_fail=False, may_reconnect=False, random_hsm=False):
|
||||||
fake_bitcoin_cli=False):
|
|
||||||
with self.lock:
|
with self.lock:
|
||||||
node_id = self.next_id
|
node_id = self.next_id
|
||||||
self.next_id += 1
|
self.next_id += 1
|
||||||
@@ -705,18 +704,16 @@ class NodeFactory(object):
|
|||||||
if not may_reconnect:
|
if not may_reconnect:
|
||||||
daemon.opts["dev-no-reconnect"] = None
|
daemon.opts["dev-no-reconnect"] = None
|
||||||
|
|
||||||
if fake_bitcoin_cli:
|
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'
|
'! [ -x bitcoin-cli-fail ] || exec ./bitcoin-cli-fail "$@"\n'
|
||||||
'! [ -f bitcoin-cli-fail ] || . {ldir}/bitcoin-cli-fail\n'
|
'for a in "$@"; do\n'
|
||||||
'for a in "$@"; do\n'
|
'\t! [ -x bitcoin-cli-fail-"$a" ] || exec ./bitcoin-cli-fail-"$a" "$@"\n'
|
||||||
'\t! [ -f bitcoin-cli-fail-"$a" ] || . {ldir}/bitcoin-cli-fail-"$a"\n'
|
'done\n'
|
||||||
'done\n'
|
'exec bitcoin-cli "$@"\n')
|
||||||
'exec bitcoin-cli "$@"\n'
|
os.chmod(cli, os.stat(cli).st_mode | stat.S_IEXEC)
|
||||||
.format(ldir=lightning_dir))
|
daemon.opts['bitcoin-cli'] = cli
|
||||||
os.chmod(cli, os.stat(cli).st_mode | stat.S_IEXEC)
|
|
||||||
daemon.opts['bitcoin-cli'] = cli
|
|
||||||
|
|
||||||
if options is not None:
|
if options is not None:
|
||||||
daemon.opts.update(options)
|
daemon.opts.update(options)
|
||||||
|
|||||||
Reference in New Issue
Block a user