Skip to content

Commit 864890a

Browse files
committed
[qa] Make import-rescan.py watchonly check reliable
Send payments during the test from a different node than the node generating keys to be imported, so the spending node doesn't create transactions that inadvertently involve (spend funds from) the imported keys. Fixes #9826
1 parent bed5b30 commit 864890a

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

qa/rpc-tests/import-rescan.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"""Test rescan behavior of importaddress, importpubkey, importprivkey, and
66
importmulti RPCs with different types of keys and rescan options.
77
8-
In the first part of the test, node 0 creates an address for each type of
9-
import RPC call and sends BTC to it. Then other nodes import the addresses,
10-
and the test makes listtransactions and getbalance calls to confirm that the
11-
importing node either did or did not execute rescans picking up the send
12-
transactions.
8+
In the first part of the test, node 1 creates an address for each type of
9+
import RPC call and node 0 sends BTC to it. Then other nodes import the
10+
addresses, and the test makes listtransactions and getbalance calls to confirm
11+
that the importing node either did or did not execute rescans picking up the
12+
send transactions.
1313
1414
In the second part of the test, node 0 sends more BTC to each address, and the
1515
test makes more listtransactions and getbalance calls to confirm that the
@@ -81,6 +81,12 @@ def check(self, txid=None, amount=None, confirmations=None):
8181
assert_equal(tx["txid"], txid)
8282
assert_equal(tx["confirmations"], confirmations)
8383
assert_equal("trusted" not in tx, True)
84+
# Verify the transaction is correctly marked watchonly depending on
85+
# whether the transaction pays to an imported public key or
86+
# imported private key. The test setup ensures that transaction
87+
# inputs will not be from watchonly keys (important because
88+
# involvesWatchonly will be true if either the transaction output
89+
# or inputs are watchonly).
8490
if self.data != Data.priv:
8591
assert_equal(tx["involvesWatchonly"], True)
8692
else:
@@ -106,11 +112,11 @@ def check(self, txid=None, amount=None, confirmations=None):
106112
class ImportRescanTest(BitcoinTestFramework):
107113
def __init__(self):
108114
super().__init__()
109-
self.num_nodes = 1 + len(IMPORT_NODES)
115+
self.num_nodes = 2 + len(IMPORT_NODES)
110116

111117
def setup_network(self):
112118
extra_args = [["-debug=1"] for _ in range(self.num_nodes)]
113-
for i, import_node in enumerate(IMPORT_NODES, 1):
119+
for i, import_node in enumerate(IMPORT_NODES, 2):
114120
if import_node.prune:
115121
extra_args[i] += ["-prune=1"]
116122

@@ -123,9 +129,9 @@ def run_test(self):
123129
# each possible type of wallet import RPC.
124130
for i, variant in enumerate(IMPORT_VARIANTS):
125131
variant.label = "label {} {}".format(i, variant)
126-
variant.address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress(variant.label))
127-
variant.key = self.nodes[0].dumpprivkey(variant.address["address"])
128-
variant.initial_amount = 25 - (i + 1) / 4.0
132+
variant.address = self.nodes[1].validateaddress(self.nodes[1].getnewaddress(variant.label))
133+
variant.key = self.nodes[1].dumpprivkey(variant.address["address"])
134+
variant.initial_amount = 10 - (i + 1) / 4.0
129135
variant.initial_txid = self.nodes[0].sendtoaddress(variant.address["address"], variant.initial_amount)
130136

131137
# Generate a block containing the initial transactions, then another
@@ -142,7 +148,7 @@ def run_test(self):
142148
for variant in IMPORT_VARIANTS:
143149
variant.expect_disabled = variant.rescan == Rescan.yes and variant.prune and variant.call == Call.single
144150
expect_rescan = variant.rescan == Rescan.yes and not variant.expect_disabled
145-
variant.node = self.nodes[1 + IMPORT_NODES.index(ImportNode(variant.prune, expect_rescan))]
151+
variant.node = self.nodes[2 + IMPORT_NODES.index(ImportNode(variant.prune, expect_rescan))]
146152
variant.do_import(timestamp)
147153
if expect_rescan:
148154
variant.expected_balance = variant.initial_amount
@@ -156,7 +162,7 @@ def run_test(self):
156162
# Create new transactions sending to each address.
157163
fee = self.nodes[0].getnetworkinfo()["relayfee"]
158164
for i, variant in enumerate(IMPORT_VARIANTS):
159-
variant.sent_amount = 25 - (2 * i + 1) / 8.0
165+
variant.sent_amount = 10 - (2 * i + 1) / 8.0
160166
variant.sent_txid = self.nodes[0].sendtoaddress(variant.address["address"], variant.sent_amount)
161167

162168
# Generate a block containing the new transactions.

0 commit comments

Comments
 (0)