Skip to content

Commit c7e57ce

Browse files
committed
Merge #9839: [qa] Make import-rescan.py watchonly check reliable
864890a [qa] Make import-rescan.py watchonly check reliable (Russell Yanofsky) Tree-SHA512: ea0e2b1d4fc8f35174c3d575fb751b428daf6ad3aa944fad4e3ddcc9195e4f17051473acabc54203b1d27cca64cf911b737ab92e986c40ef384410652e2dbea1
2 parents 6206252 + 864890a commit c7e57ce

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
@@ -7,11 +7,11 @@
77
Test rescan behavior of importaddress, importpubkey, importprivkey, and
88
importmulti RPCs with different types of keys and rescan options.
99
10-
In the first part of the test, node 0 creates an address for each type of
11-
import RPC call and sends BTC to it. Then other nodes import the addresses,
12-
and the test makes listtransactions and getbalance calls to confirm that the
13-
importing node either did or did not execute rescans picking up the send
14-
transactions.
10+
In the first part of the test, node 1 creates an address for each type of
11+
import RPC call and node 0 sends BTC to it. Then other nodes import the
12+
addresses, and the test makes listtransactions and getbalance calls to confirm
13+
that the importing node either did or did not execute rescans picking up the
14+
send transactions.
1515
1616
In the second part of the test, node 0 sends more BTC to each address, and the
1717
test makes more listtransactions and getbalance calls to confirm that the
@@ -83,6 +83,12 @@ def check(self, txid=None, amount=None, confirmations=None):
8383
assert_equal(tx["txid"], txid)
8484
assert_equal(tx["confirmations"], confirmations)
8585
assert_equal("trusted" not in tx, True)
86+
# Verify the transaction is correctly marked watchonly depending on
87+
# whether the transaction pays to an imported public key or
88+
# imported private key. The test setup ensures that transaction
89+
# inputs will not be from watchonly keys (important because
90+
# involvesWatchonly will be true if either the transaction output
91+
# or inputs are watchonly).
8692
if self.data != Data.priv:
8793
assert_equal(tx["involvesWatchonly"], True)
8894
else:
@@ -108,11 +114,11 @@ def check(self, txid=None, amount=None, confirmations=None):
108114
class ImportRescanTest(BitcoinTestFramework):
109115
def __init__(self):
110116
super().__init__()
111-
self.num_nodes = 1 + len(IMPORT_NODES)
117+
self.num_nodes = 2 + len(IMPORT_NODES)
112118

113119
def setup_network(self):
114120
extra_args = [["-debug=1"] for _ in range(self.num_nodes)]
115-
for i, import_node in enumerate(IMPORT_NODES, 1):
121+
for i, import_node in enumerate(IMPORT_NODES, 2):
116122
if import_node.prune:
117123
extra_args[i] += ["-prune=1"]
118124

@@ -125,9 +131,9 @@ def run_test(self):
125131
# each possible type of wallet import RPC.
126132
for i, variant in enumerate(IMPORT_VARIANTS):
127133
variant.label = "label {} {}".format(i, variant)
128-
variant.address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress(variant.label))
129-
variant.key = self.nodes[0].dumpprivkey(variant.address["address"])
130-
variant.initial_amount = 25 - (i + 1) / 4.0
134+
variant.address = self.nodes[1].validateaddress(self.nodes[1].getnewaddress(variant.label))
135+
variant.key = self.nodes[1].dumpprivkey(variant.address["address"])
136+
variant.initial_amount = 10 - (i + 1) / 4.0
131137
variant.initial_txid = self.nodes[0].sendtoaddress(variant.address["address"], variant.initial_amount)
132138

133139
# Generate a block containing the initial transactions, then another
@@ -144,7 +150,7 @@ def run_test(self):
144150
for variant in IMPORT_VARIANTS:
145151
variant.expect_disabled = variant.rescan == Rescan.yes and variant.prune and variant.call == Call.single
146152
expect_rescan = variant.rescan == Rescan.yes and not variant.expect_disabled
147-
variant.node = self.nodes[1 + IMPORT_NODES.index(ImportNode(variant.prune, expect_rescan))]
153+
variant.node = self.nodes[2 + IMPORT_NODES.index(ImportNode(variant.prune, expect_rescan))]
148154
variant.do_import(timestamp)
149155
if expect_rescan:
150156
variant.expected_balance = variant.initial_amount
@@ -158,7 +164,7 @@ def run_test(self):
158164
# Create new transactions sending to each address.
159165
fee = self.nodes[0].getnetworkinfo()["relayfee"]
160166
for i, variant in enumerate(IMPORT_VARIANTS):
161-
variant.sent_amount = 25 - (2 * i + 1) / 8.0
167+
variant.sent_amount = 10 - (2 * i + 1) / 8.0
162168
variant.sent_txid = self.nodes[0].sendtoaddress(variant.address["address"], variant.sent_amount)
163169

164170
# Generate a block containing the new transactions.

0 commit comments

Comments
 (0)