Skip to content

Commit

Permalink
test: Add feature_framework_rpc_failure.py
Browse files Browse the repository at this point in the history
Verifies correct behavior when failing to connect to bitcoind RPC interface during setup. Parent commit fixes issues where a raised exception raised additional knock-on exceptions.
  • Loading branch information
hodlinator committed Aug 18, 2024
1 parent bd11075 commit 0ea00cd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/functional/feature_framework_rpc_failure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
# Copyright (c) 2024 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""
Verify failure to connect to bitcoind's RPC interface only raises one exception.
Multiple exceptions being raised muddies the waters of what actually went wrong.
We should maintain this bar of only raising one exception as long as additional
maintenance and complexity is low.
"""

from pathlib import Path

from test_framework.util import (
assert_equal,
)
from test_framework.test_framework import BitcoinTestFramework

class FeatureFrameworkRPCFailure(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1

def setup_network(self):
test_name = Path(__file__).name
self.log.info(f"{test_name}: Setting RPC timeout to 0 to simulate an unresponsive bitcoind")
self.rpc_timeout = 0

try:
BitcoinTestFramework.setup_network(self)
except AssertionError as e:
assert_equal(str(e), "[node 0] Unable to connect to bitcoind after 0s")
self.log.info(f"{test_name}: Caught AssertionError with expected RPC connection failure message")
else:
raise AssertionError("Didn't raise expected error")

def run_test(self):
pass

if __name__ == '__main__':
FeatureFrameworkRPCFailure(__file__).main()
1 change: 1 addition & 0 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@
'p2p_handshake.py --v2transport',
'feature_dirsymlinks.py',
'feature_help.py',
'feature_framework_rpc_failure.py',
'feature_shutdown.py',
'wallet_migration.py',
'p2p_ibd_txrelay.py',
Expand Down

0 comments on commit 0ea00cd

Please sign in to comment.