MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_bitcoin_failure

Function test_bitcoin_failure

tests/test_misc.py:106–142  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

104
105
106def test_bitcoin_failure(node_factory, bitcoind):
107 # The node will crash when bitcoind fails, so we need `may_fail` and `broken_log`.
108 l1 = node_factory.get_node(may_fail=True, broken_log=r'getrawblockbyheight|FATAL SIGNAL|backtrace')
109
110 # Make sure we're not failing it between getblockhash and getblock.
111 sync_blockheight(bitcoind, [l1])
112
113 def crash_bitcoincli(r):
114 return {'id': r['id'], 'result': 'not_a_valid_blockhash', 'error': None}
115
116 # This is not a JSON-RPC response by purpose.
117 l1.daemon.rpcproxy.mock_rpc('getblockhash', crash_bitcoincli)
118
119 # Generate a block to trigger the topology update which calls getblockhash.
120 bitcoind.generate_block(1)
121
122 # lightningd should crash with the error
123 # `fatal()` calls `abort()` when crashlog is set (during operation), so exit code is -6 (SIGABRT).
124 l1.daemon.wait_for_log(r'bad response to getrawblockbyheight')
125 assert l1.daemon.wait() != 0
126
127 # We refuse to start if bitcoind is in `blocksonly`
128 # l1 already crashed, so we just need to restart bitcoind.
129 bitcoind.stop()
130 bitcoind.cmd_line += ["-blocksonly"]
131 bitcoind.start()
132
133 # Ignore BROKEN log message about blocksonly mode.
134 l2 = node_factory.get_node(start=False, expect_fail=True,
135 broken_log="plugin-bcli: The 'blocksonly' mode of bitcoind, or any option deactivating transaction relay is not supported.")
136 l2.daemon.start(wait_for_initialized=False, stderr_redir=True)
137 # Will exit with failure code.
138 assert l2.daemon.wait() == 1
139 assert l2.daemon.is_in_stderr(r".*deactivating transaction relay is not"
140 " supported.")
141 assert l2.daemon.is_in_log('deactivating transaction'
142 ' relay is not supported')
143
144
145def test_bitcoin_ibd(node_factory, bitcoind):

Callers

nothing calls this directly

Calls 10

sync_blockheightFunction · 0.90
mock_rpcMethod · 0.80
generate_blockMethod · 0.80
wait_for_logMethod · 0.80
is_in_stderrMethod · 0.80
is_in_logMethod · 0.80
get_nodeMethod · 0.45
waitMethod · 0.45
stopMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected