Skip to content

Commit 33e6538

Browse files
committed
Merge bitcoin#32360: test: Force named args for RPCOverloadWrapper optional args
fa48be3 test: Force named args for RPCOverloadWrapper optional args (MarcoFalke) aaaa453 test: Remove unused createwallet_passthrough (MarcoFalke) cccc1f4 test: Remove unused RPCOverloadWrapper is_cli field (MarcoFalke) Pull request description: This can avoid bugs and makes the test code easier to read, because the order of positional args does not have to be known or assumed. Also, contains two commits to remove dead code. ACKs for top commit: achow101: ACK fa48be3 rkrux: tACK fa48be3 janb84: tACK [fa48be3](bitcoin@fa48be3) Tree-SHA512: d938fbc18be5035ad0d0e1ad2bf7297b2b66ede3bb2d3f10b8d27aa2a19d27a897b024a5f5a2a1cceca467837890729c26054928cb06acbe282b9e9eea94ae69
2 parents 3a29ba3 + fa48be3 commit 33e6538

File tree

5 files changed

+20
-24
lines changed

5 files changed

+20
-24
lines changed

test/functional/rpc_psbt.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def test_utxo_conversion(self):
111111
# Mine a transaction that credits the offline address
112112
offline_addr = offline_node.getnewaddress(address_type="bech32m")
113113
online_addr = w2.getnewaddress(address_type="bech32m")
114-
wonline.importaddress(offline_addr, "", False)
114+
wonline.importaddress(offline_addr, label="", rescan=False)
115115
mining_wallet = mining_node.get_wallet_rpc(self.default_wallet_name)
116116
mining_wallet.sendtoaddress(address=offline_addr, amount=1.0)
117117
self.generate(mining_node, nblocks=1, sync_fun=lambda: self.sync_all([online_node, mining_node]))
@@ -312,9 +312,9 @@ def run_test(self):
312312
wmulti = self.nodes[2].get_wallet_rpc('wmulti')
313313

314314
# Create all the addresses
315-
p2sh = wmulti.addmultisigaddress(2, [pubkey0, pubkey1, pubkey2], "", "legacy")['address']
316-
p2wsh = wmulti.addmultisigaddress(2, [pubkey0, pubkey1, pubkey2], "", "bech32")['address']
317-
p2sh_p2wsh = wmulti.addmultisigaddress(2, [pubkey0, pubkey1, pubkey2], "", "p2sh-segwit")['address']
315+
p2sh = wmulti.addmultisigaddress(2, [pubkey0, pubkey1, pubkey2], label="", address_type="legacy")["address"]
316+
p2wsh = wmulti.addmultisigaddress(2, [pubkey0, pubkey1, pubkey2], label="", address_type="bech32")["address"]
317+
p2sh_p2wsh = wmulti.addmultisigaddress(2, [pubkey0, pubkey1, pubkey2], label="", address_type="p2sh-segwit")["address"]
318318
p2wpkh = self.nodes[1].getnewaddress("", "bech32")
319319
p2pkh = self.nodes[1].getnewaddress("", "legacy")
320320
p2sh_p2wpkh = self.nodes[1].getnewaddress("", "p2sh-segwit")

test/functional/test_framework/test_node.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2017-2022 The Bitcoin Core developers
2+
# Copyright (c) 2017-present The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Class for bitcoind node under test"""
@@ -209,7 +209,7 @@ def __del__(self):
209209
def __getattr__(self, name):
210210
"""Dispatches any unrecognised messages to the RPC connection or a CLI instance."""
211211
if self.use_cli:
212-
return getattr(RPCOverloadWrapper(self.cli, True), name)
212+
return getattr(RPCOverloadWrapper(self.cli), name)
213213
else:
214214
assert self.rpc_connected and self.rpc is not None, self._node_msg("Error: no RPC connection")
215215
return getattr(RPCOverloadWrapper(self.rpc), name)
@@ -374,7 +374,7 @@ def setmocktime(self, timestamp):
374374

375375
def get_wallet_rpc(self, wallet_name):
376376
if self.use_cli:
377-
return RPCOverloadWrapper(self.cli("-rpcwallet={}".format(wallet_name)), True)
377+
return RPCOverloadWrapper(self.cli("-rpcwallet={}".format(wallet_name)))
378378
else:
379379
assert self.rpc_connected and self.rpc, self._node_msg("RPC not connected")
380380
wallet_path = "wallet/{}".format(urllib.parse.quote(wallet_name))
@@ -925,60 +925,56 @@ def send_cli(self, clicommand=None, *args, **kwargs):
925925
return cli_stdout.rstrip("\n")
926926

927927
class RPCOverloadWrapper():
928-
def __init__(self, rpc, cli=False):
928+
def __init__(self, rpc):
929929
self.rpc = rpc
930-
self.is_cli = cli
931930

932931
def __getattr__(self, name):
933932
return getattr(self.rpc, name)
934933

935-
def createwallet_passthrough(self, *args, **kwargs):
936-
return self.__getattr__("createwallet")(*args, **kwargs)
937-
938-
def importprivkey(self, privkey, label=None, rescan=None):
934+
def importprivkey(self, privkey, *, label=None, rescan=None):
939935
wallet_info = self.getwalletinfo()
940936
if 'descriptors' not in wallet_info or ('descriptors' in wallet_info and not wallet_info['descriptors']):
941937
return self.__getattr__('importprivkey')(privkey, label, rescan)
942938
desc = descsum_create('combo(' + privkey + ')')
943939
req = [{
944940
'desc': desc,
945941
'timestamp': 0 if rescan else 'now',
946-
'label': label if label else ''
942+
'label': label if label else '',
947943
}]
948944
import_res = self.importdescriptors(req)
949945
if not import_res[0]['success']:
950946
raise JSONRPCException(import_res[0]['error'])
951947

952-
def addmultisigaddress(self, nrequired, keys, label=None, address_type=None):
948+
def addmultisigaddress(self, nrequired, keys, *, label=None, address_type=None):
953949
wallet_info = self.getwalletinfo()
954950
if 'descriptors' not in wallet_info or ('descriptors' in wallet_info and not wallet_info['descriptors']):
955951
return self.__getattr__('addmultisigaddress')(nrequired, keys, label, address_type)
956952
cms = self.createmultisig(nrequired, keys, address_type)
957953
req = [{
958954
'desc': cms['descriptor'],
959955
'timestamp': 0,
960-
'label': label if label else ''
956+
'label': label if label else '',
961957
}]
962958
import_res = self.importdescriptors(req)
963959
if not import_res[0]['success']:
964960
raise JSONRPCException(import_res[0]['error'])
965961
return cms
966962

967-
def importpubkey(self, pubkey, label=None, rescan=None):
963+
def importpubkey(self, pubkey, *, label=None, rescan=None):
968964
wallet_info = self.getwalletinfo()
969965
if 'descriptors' not in wallet_info or ('descriptors' in wallet_info and not wallet_info['descriptors']):
970966
return self.__getattr__('importpubkey')(pubkey, label, rescan)
971967
desc = descsum_create('combo(' + pubkey + ')')
972968
req = [{
973969
'desc': desc,
974970
'timestamp': 0 if rescan else 'now',
975-
'label': label if label else ''
971+
'label': label if label else '',
976972
}]
977973
import_res = self.importdescriptors(req)
978974
if not import_res[0]['success']:
979975
raise JSONRPCException(import_res[0]['error'])
980976

981-
def importaddress(self, address, label=None, rescan=None, p2sh=None):
977+
def importaddress(self, address, *, label=None, rescan=None, p2sh=None):
982978
wallet_info = self.getwalletinfo()
983979
if 'descriptors' not in wallet_info or ('descriptors' in wallet_info and not wallet_info['descriptors']):
984980
return self.__getattr__('importaddress')(address, label, rescan, p2sh)
@@ -992,13 +988,13 @@ def importaddress(self, address, label=None, rescan=None, p2sh=None):
992988
reqs = [{
993989
'desc': desc,
994990
'timestamp': 0 if rescan else 'now',
995-
'label': label if label else ''
991+
'label': label if label else '',
996992
}]
997993
if is_hex and p2sh:
998994
reqs.append({
999995
'desc': descsum_create('p2sh(raw(' + address + '))'),
1000996
'timestamp': 0 if rescan else 'now',
1001-
'label': label if label else ''
997+
'label': label if label else '',
1002998
})
1003999
import_res = self.importdescriptors(reqs)
10041000
for res in import_res:

test/functional/wallet_address_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def run_test(self):
344344
self.test_address(3, self.nodes[3].getrawchangeaddress(), multisig=False, typ='bech32')
345345

346346
self.log.info('test invalid address type arguments')
347-
assert_raises_rpc_error(-5, "Unknown address type ''", self.nodes[3].addmultisigaddress, 2, [compressed_1, compressed_2], None, '')
347+
assert_raises_rpc_error(-5, "Unknown address type ''", self.nodes[3].addmultisigaddress, 2, [compressed_1, compressed_2], address_type="")
348348
assert_raises_rpc_error(-5, "Unknown address type ''", self.nodes[3].getnewaddress, None, '')
349349
assert_raises_rpc_error(-5, "Unknown address type ''", self.nodes[3].getrawchangeaddress, '')
350350
assert_raises_rpc_error(-5, "Unknown address type 'bech23'", self.nodes[3].getrawchangeaddress, 'bech23')

test/functional/wallet_fundrawtransaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def test_change_position(self):
192192
watchonly_address = self.nodes[0].getnewaddress()
193193
watchonly_pubkey = self.nodes[0].getaddressinfo(watchonly_address)["pubkey"]
194194
self.watchonly_amount = Decimal(200)
195-
wwatch.importpubkey(watchonly_pubkey, "", True)
195+
wwatch.importpubkey(watchonly_pubkey, label="", rescan=True)
196196
self.watchonly_utxo = self.create_outpoints(self.nodes[0], outputs=[{watchonly_address: self.watchonly_amount}])[0]
197197

198198
# Lock UTXO so nodes[0] doesn't accidentally spend it

test/functional/wallet_labels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def invalid_label_name_test(self):
4949
assert_equal(response[0]['error']['message'], "Invalid label name")
5050

5151
for rpc_call in rpc_calls:
52-
assert_raises_rpc_error(-11, "Invalid label name", *rpc_call, "*")
52+
assert_raises_rpc_error(-11, "Invalid label name", *rpc_call, label="*")
5353

5454
def run_test(self):
5555
# Check that there's no UTXO on the node

0 commit comments

Comments
 (0)