5
5
"""Test rescan behavior of importaddress, importpubkey, importprivkey, and
6
6
importmulti RPCs with different types of keys and rescan options.
7
7
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.
13
13
14
14
In the second part of the test, node 0 sends more BTC to each address, and the
15
15
test makes more listtransactions and getbalance calls to confirm that the
@@ -81,6 +81,12 @@ def check(self, txid=None, amount=None, confirmations=None):
81
81
assert_equal (tx ["txid" ], txid )
82
82
assert_equal (tx ["confirmations" ], confirmations )
83
83
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).
84
90
if self .data != Data .priv :
85
91
assert_equal (tx ["involvesWatchonly" ], True )
86
92
else :
@@ -106,11 +112,11 @@ def check(self, txid=None, amount=None, confirmations=None):
106
112
class ImportRescanTest (BitcoinTestFramework ):
107
113
def __init__ (self ):
108
114
super ().__init__ ()
109
- self .num_nodes = 1 + len (IMPORT_NODES )
115
+ self .num_nodes = 2 + len (IMPORT_NODES )
110
116
111
117
def setup_network (self ):
112
118
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 ):
114
120
if import_node .prune :
115
121
extra_args [i ] += ["-prune=1" ]
116
122
@@ -123,9 +129,9 @@ def run_test(self):
123
129
# each possible type of wallet import RPC.
124
130
for i , variant in enumerate (IMPORT_VARIANTS ):
125
131
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
129
135
variant .initial_txid = self .nodes [0 ].sendtoaddress (variant .address ["address" ], variant .initial_amount )
130
136
131
137
# Generate a block containing the initial transactions, then another
@@ -142,7 +148,7 @@ def run_test(self):
142
148
for variant in IMPORT_VARIANTS :
143
149
variant .expect_disabled = variant .rescan == Rescan .yes and variant .prune and variant .call == Call .single
144
150
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 ))]
146
152
variant .do_import (timestamp )
147
153
if expect_rescan :
148
154
variant .expected_balance = variant .initial_amount
@@ -156,7 +162,7 @@ def run_test(self):
156
162
# Create new transactions sending to each address.
157
163
fee = self .nodes [0 ].getnetworkinfo ()["relayfee" ]
158
164
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
160
166
variant .sent_txid = self .nodes [0 ].sendtoaddress (variant .address ["address" ], variant .sent_amount )
161
167
162
168
# Generate a block containing the new transactions.
0 commit comments