Skip to content

Commit d314207

Browse files
committed
test: Replace usage of importaddress
1 parent fcc4575 commit d314207

File tree

7 files changed

+34
-48
lines changed

7 files changed

+34
-48
lines changed

test/functional/rpc_psbt.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ def test_utxo_conversion(self):
112112
# Mine a transaction that credits the offline address
113113
offline_addr = offline_node.getnewaddress(address_type="bech32m")
114114
online_addr = w2.getnewaddress(address_type="bech32m")
115-
wonline.importaddress(offline_addr, label="", rescan=False)
115+
import_res = wonline.importdescriptors([{"desc": offline_node.getaddressinfo(offline_addr)["desc"], "timestamp": "now"}])
116+
assert_equal(import_res[0]["success"], True)
116117
mining_wallet = mining_node.get_wallet_rpc(self.default_wallet_name)
117118
mining_wallet.sendtoaddress(address=offline_addr, amount=1.0)
118119
self.generate(mining_node, nblocks=1, sync_fun=lambda: self.sync_all([online_node, mining_node]))

test/functional/test_framework/test_node.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -959,30 +959,3 @@ def importpubkey(self, pubkey, *, label=None, rescan=None):
959959
import_res = self.importdescriptors(req)
960960
if not import_res[0]['success']:
961961
raise JSONRPCException(import_res[0]['error'])
962-
963-
def importaddress(self, address, *, label=None, rescan=None, p2sh=None):
964-
wallet_info = self.getwalletinfo()
965-
if 'descriptors' not in wallet_info or ('descriptors' in wallet_info and not wallet_info['descriptors']):
966-
return self.__getattr__('importaddress')(address, label, rescan, p2sh)
967-
is_hex = False
968-
try:
969-
int(address ,16)
970-
is_hex = True
971-
desc = descsum_create('raw(' + address + ')')
972-
except Exception:
973-
desc = descsum_create('addr(' + address + ')')
974-
reqs = [{
975-
'desc': desc,
976-
'timestamp': 0 if rescan else 'now',
977-
'label': label if label else '',
978-
}]
979-
if is_hex and p2sh:
980-
reqs.append({
981-
'desc': descsum_create('p2sh(raw(' + address + '))'),
982-
'timestamp': 0 if rescan else 'now',
983-
'label': label if label else '',
984-
})
985-
import_res = self.importdescriptors(reqs)
986-
for res in import_res:
987-
if not res['success']:
988-
raise JSONRPCException(res['error'])

test/functional/wallet_basic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,8 @@ def test_chain_listunspent(self):
673673
self.generate(self.wallet, 1, sync_fun=self.no_op)
674674
self.nodes[0].createwallet("watch_wallet", disable_private_keys=True)
675675
watch_wallet = self.nodes[0].get_wallet_rpc("watch_wallet")
676-
watch_wallet.importaddress(self.wallet.get_address())
676+
import_res = watch_wallet.importdescriptors([{"desc": self.wallet.get_descriptor(), "timestamp": "now"}])
677+
assert_equal(import_res[0]["success"], True)
677678

678679
# DEFAULT_ANCESTOR_LIMIT transactions off a confirmed tx should be fine
679680
chain = self.wallet.create_self_transfer_chain(chain_length=DEFAULT_ANCESTOR_LIMIT)

test/functional/wallet_importprunedfunds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def run_test(self):
9090
# Import with affiliated address with no rescan
9191
self.nodes[1].createwallet('wwatch', disable_private_keys=True)
9292
wwatch = self.nodes[1].get_wallet_rpc('wwatch')
93-
wwatch.importaddress(address=address2, rescan=False)
93+
wwatch.importdescriptors([{"desc": self.nodes[0].getaddressinfo(address2)["desc"], "timestamp": "now"}])
9494
wwatch.importprunedfunds(rawtransaction=rawtxn2, txoutproof=proof2)
9595
assert [tx for tx in wwatch.listtransactions(include_watchonly=True) if tx['txid'] == txnid2]
9696

test/functional/wallet_labels.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from collections import defaultdict
1313

1414
from test_framework.blocktools import COINBASE_MATURITY
15+
from test_framework.descriptors import descsum_create
1516
from test_framework.test_framework import BitcoinTestFramework
1617
from test_framework.util import assert_equal, assert_raises_rpc_error
1718
from test_framework.wallet_util import test_address
@@ -176,17 +177,17 @@ def run_test(self):
176177
}
177178
for l in BECH32_VALID:
178179
ad = BECH32_VALID[l]
179-
wallet_watch_only.importaddress(label=l, rescan=False, address=ad)
180+
import_res = wallet_watch_only.importdescriptors([{"desc": descsum_create(f"addr({ad})"), "timestamp": "now", "label": l}])
181+
assert_equal(import_res[0]["success"], True)
180182
self.generatetoaddress(node, 1, ad)
181183
assert_equal(wallet_watch_only.getaddressesbylabel(label=l), {ad: {'purpose': 'receive'}})
182184
assert_equal(wallet_watch_only.getreceivedbylabel(label=l), 0)
183185
for l in BECH32_INVALID:
184186
ad = BECH32_INVALID[l]
185-
assert_raises_rpc_error(
186-
-5,
187-
"Address is not valid",
188-
lambda: wallet_watch_only.importaddress(label=l, rescan=False, address=ad),
189-
)
187+
import_res = wallet_watch_only.importdescriptors([{"desc": descsum_create(f"addr({ad})"), "timestamp": "now", "label": l}])
188+
assert_equal(import_res[0]["success"], False)
189+
assert_equal(import_res[0]["error"]["code"], -5)
190+
assert_equal(import_res[0]["error"]["message"], "Address is not valid")
190191

191192

192193
class Label:

test/functional/wallet_reindex.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ def birthtime_test(self, node, miner_wallet):
4646
# Blank wallets don't have a birth time
4747
assert 'birthtime' not in wallet_watch_only.getwalletinfo()
4848

49-
# For a descriptors wallet: Import address with timestamp=now.
50-
# For legacy wallet: There is no way of importing a script/address with a custom time. The wallet always imports it with birthtime=1.
51-
# In both cases, disable rescan to not detect the transaction.
52-
wallet_watch_only.importaddress(wallet_addr, rescan=False)
49+
# Import address with timestamp=now.
50+
wallet_watch_only.importdescriptors([{"desc": miner_wallet.getaddressinfo(wallet_addr)["desc"], "timestamp": "now"}])
5351
assert_equal(len(wallet_watch_only.listtransactions()), 0)
5452

5553
# Depending on the wallet type, the birth time changes.

test/functional/wallet_transactiontime_rescan.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,23 @@ def run_test(self):
5050

5151
# prepare the user wallet with 3 watch only addresses
5252
wo1 = usernode.getnewaddress()
53+
wo1_desc = usernode.getaddressinfo(wo1)["desc"]
5354
wo2 = usernode.getnewaddress()
55+
wo2_desc = usernode.getaddressinfo(wo2)["desc"]
5456
wo3 = usernode.getnewaddress()
57+
wo3_desc = usernode.getaddressinfo(wo3)["desc"]
5558

5659
usernode.createwallet(wallet_name='wo', disable_private_keys=True)
5760
wo_wallet = usernode.get_wallet_rpc('wo')
5861

59-
wo_wallet.importaddress(wo1)
60-
wo_wallet.importaddress(wo2)
61-
wo_wallet.importaddress(wo3)
62+
import_res = wo_wallet.importdescriptors(
63+
[
64+
{"desc": wo1_desc, "timestamp": "now"},
65+
{"desc": wo2_desc, "timestamp": "now"},
66+
{"desc": wo3_desc, "timestamp": "now"},
67+
]
68+
)
69+
assert_equal(all([r["success"] for r in import_res]), True)
6270

6371
self.log.info('Start transactions')
6472

@@ -124,16 +132,20 @@ def run_test(self):
124132
restorenode.createwallet(wallet_name='wo', disable_private_keys=True)
125133
restorewo_wallet = restorenode.get_wallet_rpc('wo')
126134

127-
# for descriptor wallets, the test framework maps the importaddress RPC to the
128-
# importdescriptors RPC (with argument 'timestamp'='now'), which always rescans
135+
# importdescriptors with "timestamp": "now" always rescans
129136
# blocks of the past 2 hours, based on the current MTP timestamp; in order to avoid
130137
# importing the last address (wo3), we advance the time further and generate 10 blocks
131138
set_node_times(self.nodes, cur_time + ten_days + ten_days + ten_days + ten_days)
132139
self.generatetoaddress(minernode, 10, m1)
133140

134-
restorewo_wallet.importaddress(wo1, rescan=False)
135-
restorewo_wallet.importaddress(wo2, rescan=False)
136-
restorewo_wallet.importaddress(wo3, rescan=False)
141+
import_res = restorewo_wallet.importdescriptors(
142+
[
143+
{"desc": wo1_desc, "timestamp": "now"},
144+
{"desc": wo2_desc, "timestamp": "now"},
145+
{"desc": wo3_desc, "timestamp": "now"},
146+
]
147+
)
148+
assert_equal(all([r["success"] for r in import_res]), True)
137149

138150
# check user has 0 balance and no transactions
139151
assert_equal(restorewo_wallet.getbalance(), 0)

0 commit comments

Comments
 (0)