@@ -20,6 +20,7 @@ def run_test (self):
2020 print ("Mining blocks..." )
2121 self .nodes [0 ].generate (1 )
2222 self .nodes [1 ].generate (1 )
23+ timestamp = self .nodes [1 ].getblock (self .nodes [1 ].getbestblockhash ())['mediantime' ]
2324
2425 # keyword definition
2526 PRIV_KEY = 'privkey'
@@ -59,6 +60,9 @@ def run_test (self):
5960 address_assert = self .nodes [1 ].validateaddress (address ['address' ])
6061 assert_equal (address_assert ['iswatchonly' ], True )
6162 assert_equal (address_assert ['ismine' ], False )
63+ assert_equal (address_assert ['timestamp' ], timestamp )
64+ watchonly_address = address ['address' ]
65+ watchonly_timestamp = timestamp
6266
6367
6468 # ScriptPubKey + internal
@@ -73,6 +77,7 @@ def run_test (self):
7377 address_assert = self .nodes [1 ].validateaddress (address ['address' ])
7478 assert_equal (address_assert ['iswatchonly' ], True )
7579 assert_equal (address_assert ['ismine' ], False )
80+ assert_equal (address_assert ['timestamp' ], timestamp )
7681
7782 # ScriptPubKey + !internal
7883 print ("Should not import a scriptPubKey without internal flag" )
@@ -87,6 +92,7 @@ def run_test (self):
8792 address_assert = self .nodes [1 ].validateaddress (address ['address' ])
8893 assert_equal (address_assert ['iswatchonly' ], False )
8994 assert_equal (address_assert ['ismine' ], False )
95+ assert_equal ('timestamp' in address_assert , False )
9096
9197
9298 # Address + Public key + !Internal
@@ -103,6 +109,7 @@ def run_test (self):
103109 address_assert = self .nodes [1 ].validateaddress (address ['address' ])
104110 assert_equal (address_assert ['iswatchonly' ], True )
105111 assert_equal (address_assert ['ismine' ], False )
112+ assert_equal (address_assert ['timestamp' ], timestamp )
106113
107114
108115 # ScriptPubKey + Public key + internal
@@ -119,6 +126,7 @@ def run_test (self):
119126 address_assert = self .nodes [1 ].validateaddress (address ['address' ])
120127 assert_equal (address_assert ['iswatchonly' ], True )
121128 assert_equal (address_assert ['ismine' ], False )
129+ assert_equal (address_assert ['timestamp' ], timestamp )
122130
123131 # ScriptPubKey + Public key + !internal
124132 print ("Should not import a scriptPubKey without internal and with public key" )
@@ -135,11 +143,11 @@ def run_test (self):
135143 address_assert = self .nodes [1 ].validateaddress (address ['address' ])
136144 assert_equal (address_assert ['iswatchonly' ], False )
137145 assert_equal (address_assert ['ismine' ], False )
146+ assert_equal ('timestamp' in address_assert , False )
138147
139148 # Address + Private key + !watchonly
140149 print ("Should import an address with private key" )
141150 address = self .nodes [0 ].validateaddress (self .nodes [0 ].getnewaddress ())
142- timestamp = self .nodes [1 ].getblock (self .nodes [1 ].getbestblockhash ())['mediantime' ]
143151 result = self .nodes [1 ].importmulti ([{
144152 "scriptPubKey" : {
145153 "address" : address ['address' ]
@@ -170,6 +178,7 @@ def run_test (self):
170178 address_assert = self .nodes [1 ].validateaddress (address ['address' ])
171179 assert_equal (address_assert ['iswatchonly' ], False )
172180 assert_equal (address_assert ['ismine' ], False )
181+ assert_equal ('timestamp' in address_assert , False )
173182
174183 # ScriptPubKey + Private key + internal
175184 print ("Should import a scriptPubKey with internal and with private key" )
@@ -184,6 +193,7 @@ def run_test (self):
184193 address_assert = self .nodes [1 ].validateaddress (address ['address' ])
185194 assert_equal (address_assert ['iswatchonly' ], False )
186195 assert_equal (address_assert ['ismine' ], True )
196+ assert_equal (address_assert ['timestamp' ], timestamp )
187197
188198 # ScriptPubKey + Private key + !internal
189199 print ("Should not import a scriptPubKey without internal and with private key" )
@@ -199,6 +209,7 @@ def run_test (self):
199209 address_assert = self .nodes [1 ].validateaddress (address ['address' ])
200210 assert_equal (address_assert ['iswatchonly' ], False )
201211 assert_equal (address_assert ['ismine' ], False )
212+ assert_equal ('timestamp' in address_assert , False )
202213
203214
204215 # P2SH address
@@ -209,6 +220,7 @@ def run_test (self):
209220 self .nodes [1 ].generate (100 )
210221 transactionid = self .nodes [1 ].sendtoaddress (multi_sig_script ['address' ], 10.00 )
211222 self .nodes [1 ].generate (1 )
223+ timestamp = self .nodes [1 ].getblock (self .nodes [1 ].getbestblockhash ())['mediantime' ]
212224 transaction = self .nodes [1 ].gettransaction (transactionid )
213225
214226 print ("Should import a p2sh" )
@@ -222,6 +234,7 @@ def run_test (self):
222234 address_assert = self .nodes [1 ].validateaddress (multi_sig_script ['address' ])
223235 assert_equal (address_assert ['isscript' ], True )
224236 assert_equal (address_assert ['iswatchonly' ], True )
237+ assert_equal (address_assert ['timestamp' ], timestamp )
225238 p2shunspent = self .nodes [1 ].listunspent (0 ,999999 , [multi_sig_script ['address' ]])[0 ]
226239 assert_equal (p2shunspent ['spendable' ], False )
227240 assert_equal (p2shunspent ['solvable' ], False )
@@ -235,6 +248,7 @@ def run_test (self):
235248 self .nodes [1 ].generate (100 )
236249 transactionid = self .nodes [1 ].sendtoaddress (multi_sig_script ['address' ], 10.00 )
237250 self .nodes [1 ].generate (1 )
251+ timestamp = self .nodes [1 ].getblock (self .nodes [1 ].getbestblockhash ())['mediantime' ]
238252 transaction = self .nodes [1 ].gettransaction (transactionid )
239253
240254 print ("Should import a p2sh with respective redeem script" )
@@ -246,6 +260,8 @@ def run_test (self):
246260 "redeemscript" : multi_sig_script ['redeemScript' ]
247261 }])
248262 assert_equal (result [0 ]['success' ], True )
263+ address_assert = self .nodes [1 ].validateaddress (multi_sig_script ['address' ])
264+ assert_equal (address_assert ['timestamp' ], timestamp )
249265
250266 p2shunspent = self .nodes [1 ].listunspent (0 ,999999 , [multi_sig_script ['address' ]])[0 ]
251267 assert_equal (p2shunspent ['spendable' ], False )
@@ -260,6 +276,7 @@ def run_test (self):
260276 self .nodes [1 ].generate (100 )
261277 transactionid = self .nodes [1 ].sendtoaddress (multi_sig_script ['address' ], 10.00 )
262278 self .nodes [1 ].generate (1 )
279+ timestamp = self .nodes [1 ].getblock (self .nodes [1 ].getbestblockhash ())['mediantime' ]
263280 transaction = self .nodes [1 ].gettransaction (transactionid )
264281
265282 print ("Should import a p2sh with respective redeem script and private keys" )
@@ -272,6 +289,8 @@ def run_test (self):
272289 "keys" : [ self .nodes [0 ].dumpprivkey (sig_address_1 ['address' ]), self .nodes [0 ].dumpprivkey (sig_address_2 ['address' ])]
273290 }])
274291 assert_equal (result [0 ]['success' ], True )
292+ address_assert = self .nodes [1 ].validateaddress (multi_sig_script ['address' ])
293+ assert_equal (address_assert ['timestamp' ], timestamp )
275294
276295 p2shunspent = self .nodes [1 ].listunspent (0 ,999999 , [multi_sig_script ['address' ]])[0 ]
277296 assert_equal (p2shunspent ['spendable' ], False )
@@ -319,6 +338,7 @@ def run_test (self):
319338 address_assert = self .nodes [1 ].validateaddress (address ['address' ])
320339 assert_equal (address_assert ['iswatchonly' ], False )
321340 assert_equal (address_assert ['ismine' ], False )
341+ assert_equal ('timestamp' in address_assert , False )
322342
323343
324344 # ScriptPubKey + Public key + internal + Wrong pubkey
@@ -338,6 +358,7 @@ def run_test (self):
338358 address_assert = self .nodes [1 ].validateaddress (address ['address' ])
339359 assert_equal (address_assert ['iswatchonly' ], False )
340360 assert_equal (address_assert ['ismine' ], False )
361+ assert_equal ('timestamp' in address_assert , False )
341362
342363
343364 # Address + Private key + !watchonly + Wrong private key
@@ -357,6 +378,7 @@ def run_test (self):
357378 address_assert = self .nodes [1 ].validateaddress (address ['address' ])
358379 assert_equal (address_assert ['iswatchonly' ], False )
359380 assert_equal (address_assert ['ismine' ], False )
381+ assert_equal ('timestamp' in address_assert , False )
360382
361383
362384 # ScriptPubKey + Private key + internal + Wrong private key
@@ -375,6 +397,15 @@ def run_test (self):
375397 address_assert = self .nodes [1 ].validateaddress (address ['address' ])
376398 assert_equal (address_assert ['iswatchonly' ], False )
377399 assert_equal (address_assert ['ismine' ], False )
400+ assert_equal ('timestamp' in address_assert , False )
401+
402+ # restart nodes to check for proper serialization/deserialization of watch only address
403+ stop_nodes (self .nodes )
404+ self .nodes = start_nodes (2 , self .options .tmpdir )
405+ address_assert = self .nodes [1 ].validateaddress (watchonly_address )
406+ assert_equal (address_assert ['iswatchonly' ], True )
407+ assert_equal (address_assert ['ismine' ], False )
408+ assert_equal (address_assert ['timestamp' ], watchonly_timestamp );
378409
379410 # Bad or missing timestamps
380411 print ("Should throw on invalid or missing timestamp values" )
0 commit comments