From bbc5c109195ffa7b9073b7a01283e38632547670 Mon Sep 17 00:00:00 2001 From: darosior Date: Wed, 5 Feb 2020 16:59:00 +0100 Subject: [PATCH] pytest: adjust mocks and logs for bitcoind For bitcoind_fail_first: We only ever send `getblock` if we got a successful block hash from `getblockhash`, and if we can't get the block in that case it means our Bitcoin backend is faulty and we shouldnt continue. So, mock `getblockhash` instead, which is authorized to spuriously fail. For both bitcoind_fail_first and bitcoind_failure: Adapt the logs. --- tests/test_misc.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_misc.py b/tests/test_misc.py index fcd79e217..4b3ce54e4 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -105,11 +105,11 @@ def test_bitcoin_failure(node_factory, bitcoind): l1.daemon.rpcproxy.mock_rpc('getblockhash', crash_bitcoincli) # This should cause both estimatefee and getblockhash fail - l1.daemon.wait_for_logs(['estimatesmartfee .* exited with status 1', + l1.daemon.wait_for_logs(['Unable to estimate .* fee', 'getblockhash .* exited with status 1']) # And they should retry! - l1.daemon.wait_for_logs(['estimatesmartfee .* exited with status 1', + l1.daemon.wait_for_logs(['Unable to estimate .* fee', 'getblockhash .* exited with status 1']) # Restore, then it should recover and get blockheight. @@ -137,7 +137,7 @@ def test_bitcoin_ibd(node_factory, bitcoind): # "Finish" IDB. l1.daemon.rpcproxy.mock_rpc('getblockchaininfo', None) - l1.daemon.wait_for_log('Bitcoind now synced') + l1.daemon.wait_for_log('Bitcoin backend now synced') assert 'warning_bitcoind_sync' not in l1.rpc.getinfo() @@ -1648,7 +1648,7 @@ def test_bitcoind_fail_first(node_factory, bitcoind, executor): def mock_fail(*args): raise ValueError() - l1.daemon.rpcproxy.mock_rpc('getblock', mock_fail) + l1.daemon.rpcproxy.mock_rpc('getblockhash', mock_fail) l1.daemon.rpcproxy.mock_rpc('estimatesmartfee', mock_fail) f = executor.submit(l1.start) @@ -1657,12 +1657,12 @@ def test_bitcoind_fail_first(node_factory, bitcoind, executor): # Make sure it fails on the first `getblock` call (need to use `is_in_log` # since the `wait_for_log` in `start` sets the offset) wait_for(lambda: l1.daemon.is_in_log( - r'getblock [a-z0-9]* false exited with status 1')) + r'getblockhash [a-z0-9]* exited with status 1')) wait_for(lambda: l1.daemon.is_in_log( - r'estimatesmartfee 2 CONSERVATIVE exited with status 1')) + r'Unable to estimate CONSERVATIVE/2 fee')) # Now unset the mock, so calls go through again - l1.daemon.rpcproxy.mock_rpc('getblock', None) + l1.daemon.rpcproxy.mock_rpc('getblockhash', None) l1.daemon.rpcproxy.mock_rpc('estimatesmartfee', None) f.result()