From 4d32c19516fdb65b364638fa088b8d7167b438b6 Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Thu, 8 May 2025 11:54:19 -0700 Subject: [PATCH] test: Replace importpubkey --- test/functional/test_framework/test_node.py | 15 --------------- test/functional/wallet_createwallet.py | 6 ++++-- test/functional/wallet_fundrawtransaction.py | 4 ++-- test/functional/wallet_labels.py | 1 - test/functional/wallet_simulaterawtx.py | 3 ++- 5 files changed, 8 insertions(+), 21 deletions(-) diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index ffd9252edab..e978c1e3790 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -27,7 +27,6 @@ from .authproxy import ( JSONRPCException, serialization_fallback, ) -from .descriptors import descsum_create from .messages import NODE_P2P_V2 from .p2p import P2P_SERVICES, P2P_SUBVERSION from .util import ( @@ -930,17 +929,3 @@ class RPCOverloadWrapper(): def __getattr__(self, name): return getattr(self.rpc, name) - - def importpubkey(self, pubkey, *, label=None, rescan=None): - wallet_info = self.getwalletinfo() - if 'descriptors' not in wallet_info or ('descriptors' in wallet_info and not wallet_info['descriptors']): - return self.__getattr__('importpubkey')(pubkey, label, rescan) - desc = descsum_create('combo(' + pubkey + ')') - req = [{ - 'desc': desc, - 'timestamp': 0 if rescan else 'now', - 'label': label if label else '', - }] - import_res = self.importdescriptors(req) - if not import_res[0]['success']: - raise JSONRPCException(import_res[0]['error']) diff --git a/test/functional/wallet_createwallet.py b/test/functional/wallet_createwallet.py index edd54fe4387..1f86b265e8d 100755 --- a/test/functional/wallet_createwallet.py +++ b/test/functional/wallet_createwallet.py @@ -42,7 +42,8 @@ class CreateWalletTest(BitcoinTestFramework): w1 = node.get_wallet_rpc('w1') assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w1.getnewaddress) assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w1.getrawchangeaddress) - w1.importpubkey(w0.getaddressinfo(address1)['pubkey']) + import_res = w1.importdescriptors([{"desc": w0.getaddressinfo(address1)['desc'], "timestamp": "now"}]) + assert_equal(import_res[0]["success"], True) self.log.info('Test that private keys cannot be imported') privkey, pubkey = generate_keypair(wif=True) @@ -57,7 +58,8 @@ class CreateWalletTest(BitcoinTestFramework): w2 = node.get_wallet_rpc('w2') assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w2.getnewaddress) assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w2.getrawchangeaddress) - w2.importpubkey(w0.getaddressinfo(address1)['pubkey']) + import_res = w2.importdescriptors([{"desc": w0.getaddressinfo(address1)['desc'], "timestamp": "now"}]) + assert_equal(import_res[0]["success"], True) self.log.info("Test blank creation with private keys enabled.") self.nodes[0].createwallet(wallet_name='w3', disable_private_keys=False, blank=True) diff --git a/test/functional/wallet_fundrawtransaction.py b/test/functional/wallet_fundrawtransaction.py index 08d9e9226cb..a3b19847335 100755 --- a/test/functional/wallet_fundrawtransaction.py +++ b/test/functional/wallet_fundrawtransaction.py @@ -190,9 +190,9 @@ class RawTransactionsTest(BitcoinTestFramework): self.nodes[3].createwallet(wallet_name="wwatch", disable_private_keys=True) wwatch = self.nodes[3].get_wallet_rpc('wwatch') watchonly_address = self.nodes[0].getnewaddress() - watchonly_pubkey = self.nodes[0].getaddressinfo(watchonly_address)["pubkey"] self.watchonly_amount = Decimal(200) - wwatch.importpubkey(watchonly_pubkey, label="", rescan=True) + import_res = wwatch.importdescriptors([{"desc": self.nodes[0].getaddressinfo(watchonly_address)["desc"], "timestamp": "now"}]) + assert_equal(import_res[0]["success"], True) self.watchonly_utxo = self.create_outpoints(self.nodes[0], outputs=[{watchonly_address: self.watchonly_amount}])[0] # Lock UTXO so nodes[0] doesn't accidentally spend it diff --git a/test/functional/wallet_labels.py b/test/functional/wallet_labels.py index 56b721551b3..068a4980db7 100755 --- a/test/functional/wallet_labels.py +++ b/test/functional/wallet_labels.py @@ -34,7 +34,6 @@ class WalletLabelsTest(BitcoinTestFramework): [node.getnewaddress], [node.setlabel, address], [node.getaddressesbylabel], - [node.importpubkey, pubkey], [node.getreceivedbylabel], [node.listsinceblock, node.getblockhash(0), 1, False, True, False], ] diff --git a/test/functional/wallet_simulaterawtx.py b/test/functional/wallet_simulaterawtx.py index 91955d751e3..4ee663067ee 100755 --- a/test/functional/wallet_simulaterawtx.py +++ b/test/functional/wallet_simulaterawtx.py @@ -45,7 +45,8 @@ class SimulateTxTest(BitcoinTestFramework): address2 = w1.getnewaddress() # Add address1 as watch-only to w2 - w2.importpubkey(pubkey=w1.getaddressinfo(address1)["pubkey"]) + import_res = w2.importdescriptors([{"desc": w1.getaddressinfo(address1)["desc"], "timestamp": "now"}]) + assert_equal(import_res[0]["success"], True) tx1 = node.createrawtransaction([], [{address1: 5.0}]) tx2 = node.createrawtransaction([], [{address2: 10.0}])