Skip to content

Commit 8f8ce9e

Browse files
committed
test: rename .rpc to ._rpc and remove unnecessary uses
It is usually not necessary, and makes it impossible to use --usecli
1 parent 5b08885 commit 8f8ce9e

File tree

7 files changed

+20
-20
lines changed

7 files changed

+20
-20
lines changed

test/functional/rpc_deprecated.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def run_test(self):
1919
# such RPCs are fully removed. For example:
2020
#
2121
# self.log.info("Test generate RPC")
22-
# assert_raises_rpc_error(-32, 'The wallet generate rpc method is deprecated', self.nodes[0].rpc.generate, 1)
22+
# assert_raises_rpc_error(-32, 'The wallet generate rpc method is deprecated', self.nodes[0].generate, 1)
2323
#
2424
# Please ensure that for all the RPC methods tested here, there is
2525
# at least one other functional test that still tests the RPCs
@@ -32,7 +32,7 @@ def run_test(self):
3232
self.log.info("Tests for deprecated wallet-related RPC methods (if any)")
3333
self.log.info("Test settxfee RPC deprecation")
3434
self.nodes[0].createwallet("settxfeerpc")
35-
assert_raises_rpc_error(-32, 'settxfee is deprecated and will be fully removed in v31.0.', self.nodes[0].rpc.settxfee, 0.01)
35+
assert_raises_rpc_error(-32, 'settxfee is deprecated and will be fully removed in v31.0.', self.nodes[0].settxfee, 0.01)
3636

3737
if __name__ == '__main__':
3838
DeprecatedRpcTest(__file__).main()

test/functional/rpc_generate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_generate(self):
125125
)
126126

127127
self.log.info("Test rpc generate raises with message to use cli option")
128-
assert_raises_rpc_error(-32601, message, self.nodes[0].rpc.generate)
128+
assert_raises_rpc_error(-32601, message, self.nodes[0]._rpc.generate)
129129

130130
self.log.info("Test rpc generate help prints message to use cli option")
131131
assert_equal(message, self.nodes[0].help("generate"))

test/functional/test_framework/test_framework.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ def start_node(self, i, *args, **kwargs):
593593
node.wait_for_rpc_connection()
594594

595595
if self.options.coveragedir is not None:
596-
coverage.write_all_rpc_commands(self.options.coveragedir, node.rpc)
596+
coverage.write_all_rpc_commands(self.options.coveragedir, node._rpc)
597597

598598
def start_nodes(self, extra_args=None, *args, **kwargs):
599599
"""Start multiple bitcoinds"""
@@ -608,7 +608,7 @@ def start_nodes(self, extra_args=None, *args, **kwargs):
608608

609609
if self.options.coveragedir is not None:
610610
for node in self.nodes:
611-
coverage.write_all_rpc_commands(self.options.coveragedir, node.rpc)
611+
coverage.write_all_rpc_commands(self.options.coveragedir, node._rpc)
612612

613613
def stop_node(self, i, expected_stderr='', wait=0):
614614
"""Stop a bitcoind test node"""

test/functional/test_framework/test_node.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def __init__(self, i, datadir_path, *, chain, rpchost, timewait, timeout_factor,
155155
self.running = False
156156
self.process = None
157157
self.rpc_connected = False
158-
self.rpc = None
158+
self._rpc = None # Should usually not be accessed directly in tests to allow for --usecli mode
159159
self.reuse_http_connections = True # Must be set before calling get_rpc_proxy() i.e. before restarting node
160160
self.url = None
161161
self.log = logging.getLogger('TestFramework.node%d' % i)
@@ -212,8 +212,8 @@ def __getattr__(self, name):
212212
if self.use_cli:
213213
return getattr(self.cli, name)
214214
else:
215-
assert self.rpc_connected and self.rpc is not None, self._node_msg("Error: no RPC connection")
216-
return getattr(self.rpc, name)
215+
assert self.rpc_connected and self._rpc is not None, self._node_msg("Error: no RPC connection")
216+
return getattr(self._rpc, name)
217217

218218
def start(self, extra_args=None, *, cwd=None, stdout=None, stderr=None, env=None, **kwargs):
219219
"""Start the node."""
@@ -317,8 +317,8 @@ def suppress_error(category: str, e: Exception):
317317
self.rpc_connected = True
318318
if self.use_cli:
319319
return
320-
self.rpc = rpc
321-
self.url = self.rpc.rpc_url
320+
self._rpc = rpc
321+
self.url = self._rpc.rpc_url
322322
return
323323
except JSONRPCException as e:
324324
# Suppress these as they are expected during initialization.
@@ -395,9 +395,9 @@ def get_wallet_rpc(self, wallet_name):
395395
if self.use_cli:
396396
return self.cli("-rpcwallet={}".format(wallet_name))
397397
else:
398-
assert self.rpc_connected and self.rpc, self._node_msg("RPC not connected")
398+
assert self.rpc_connected and self._rpc, self._node_msg("RPC not connected")
399399
wallet_path = "wallet/{}".format(urllib.parse.quote(wallet_name))
400-
return self.rpc / wallet_path
400+
return self._rpc / wallet_path
401401

402402
def version_is_at_least(self, ver):
403403
return self.version is None or self.version >= ver
@@ -452,7 +452,7 @@ def is_node_stopped(self, *, expected_stderr="", expected_ret_code=0):
452452
self.running = False
453453
self.process = None
454454
self.rpc_connected = False
455-
self.rpc = None
455+
self._rpc = None
456456
self.log.debug("Node stopped")
457457
return True
458458

test/functional/wallet_backwards_compatibility.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def run_test(self):
327327
for node in descriptors_nodes:
328328
self.log.info(f"- {node.version}")
329329
wallet_name = f"up_{node.version}"
330-
node.rpc.createwallet(wallet_name=wallet_name, descriptors=True)
330+
node.createwallet(wallet_name=wallet_name, descriptors=True)
331331
wallet_prev = node.get_wallet_rpc(wallet_name)
332332
address = wallet_prev.getnewaddress('', "bech32")
333333
addr_info = wallet_prev.getaddressinfo(address)
@@ -395,9 +395,9 @@ def run_test(self):
395395
self.log.info(f"- {node.version}")
396396
wallet_name = f"legacy_up_{node.version}"
397397
if self.major_version_at_least(node, 21):
398-
node.rpc.createwallet(wallet_name=wallet_name, descriptors=False)
398+
node.createwallet(wallet_name=wallet_name, descriptors=False)
399399
else:
400-
node.rpc.createwallet(wallet_name=wallet_name)
400+
node.createwallet(wallet_name=wallet_name)
401401
wallet_prev = node.get_wallet_rpc(wallet_name)
402402
address = wallet_prev.getnewaddress('', "bech32")
403403
addr_info = wallet_prev.getaddressinfo(address)

test/functional/wallet_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,14 @@ def run_test(self):
454454
# - True: unicode escaped as \u....
455455
# - False: unicode directly as UTF-8
456456
for mode in [True, False]:
457-
self.nodes[0].rpc.ensure_ascii = mode
457+
self.nodes[0]._rpc.ensure_ascii = mode
458458
# unicode check: Basic Multilingual Plane, Supplementary Plane respectively
459459
for label in [u'рыба', u'𝅘𝅥𝅯']:
460460
addr = self.nodes[0].getnewaddress()
461461
self.nodes[0].setlabel(addr, label)
462462
test_address(self.nodes[0], addr, labels=[label])
463463
assert label in self.nodes[0].listlabels()
464-
self.nodes[0].rpc.ensure_ascii = True # restore to default
464+
self.nodes[0]._rpc.ensure_ascii = True # restore to default
465465

466466
# -reindex tests
467467
chainlimit = 6

test/functional/wallet_miniscript.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,14 @@ def signing_test(
297297
psbt.i[0].map[k] = bytes.fromhex(preimage)
298298
psbt = psbt.to_base64()
299299
res = self.ms_sig_wallet.walletprocesspsbt(psbt=psbt, finalize=False)
300-
psbtin = self.nodes[0].rpc.decodepsbt(res["psbt"])["inputs"][0]
300+
psbtin = self.nodes[0].decodepsbt(res["psbt"])["inputs"][0]
301301
sigs_field_name = "taproot_script_path_sigs" if is_taproot else "partial_signatures"
302302
assert len(psbtin[sigs_field_name]) == sigs_count
303303
res = self.ms_sig_wallet.finalizepsbt(res["psbt"])
304304
assert res["complete"] == (stack_size is not None)
305305

306306
if stack_size is not None:
307-
txin = self.nodes[0].rpc.decoderawtransaction(res["hex"])["vin"][0]
307+
txin = self.nodes[0].decoderawtransaction(res["hex"])["vin"][0]
308308
assert len(txin["txinwitness"]) == stack_size, txin["txinwitness"]
309309
self.log.info("Broadcasting the transaction.")
310310
# If necessary, satisfy a relative timelock

0 commit comments

Comments
 (0)