20
20
"""
21
21
22
22
from test_framework .test_framework import BitcoinTestFramework
23
- from test_framework .util import (start_nodes , connect_nodes , sync_blocks , assert_equal )
23
+ from test_framework .util import (start_nodes , connect_nodes , sync_blocks , assert_equal , set_node_times )
24
24
from decimal import Decimal
25
25
26
26
import collections
29
29
30
30
Call = enum .Enum ("Call" , "single multi" )
31
31
Data = enum .Enum ("Data" , "address pub priv" )
32
- Rescan = enum .Enum ("Rescan" , "no yes" )
32
+ Rescan = enum .Enum ("Rescan" , "no yes late_timestamp " )
33
33
34
34
35
35
class Variant (collections .namedtuple ("Variant" , "call data rescan" )):
36
36
"""Helper for importing one key and verifying scanned transactions."""
37
37
38
- def do_import (self ):
38
+ def do_import (self , timestamp ):
39
39
"""Call one key import RPC."""
40
40
41
41
if self .call == Call .single :
@@ -51,15 +51,15 @@ def do_import(self):
51
51
"scriptPubKey" : {
52
52
"address" : self .address ["address" ]
53
53
},
54
- "timestamp" : "now" ,
54
+ "timestamp" : timestamp + ( 1 if self . rescan == Rescan . late_timestamp else 0 ) ,
55
55
"pubkeys" : [self .address ["pubkey" ]] if self .data == Data .pub else [],
56
56
"keys" : [self .key ] if self .data == Data .priv else [],
57
57
"label" : self .label ,
58
58
"watchonly" : self .data != Data .priv
59
- }], {"rescan" : self .rescan == Rescan .yes })
59
+ }], {"rescan" : self .rescan in ( Rescan .yes , Rescan . late_timestamp ) })
60
60
assert_equal (response , [{"success" : True }])
61
61
62
- def check (self , txid = None , amount = None ):
62
+ def check (self , txid = None , amount = None , confirmations = None ):
63
63
"""Verify that getbalance/listtransactions return expected values."""
64
64
65
65
balance = self .node .getbalance (self .label , 0 , True )
@@ -76,7 +76,7 @@ def check(self, txid=None, amount=None):
76
76
assert_equal (tx ["category" ], "receive" )
77
77
assert_equal (tx ["label" ], self .label )
78
78
assert_equal (tx ["txid" ], txid )
79
- assert_equal (tx ["confirmations" ], 1 )
79
+ assert_equal (tx ["confirmations" ], confirmations )
80
80
assert_equal ("trusted" not in tx , True )
81
81
if self .data != Data .priv :
82
82
assert_equal (tx ["involvesWatchonly" ], True )
@@ -109,9 +109,13 @@ def run_test(self):
109
109
variant .initial_amount = 25 - (i + 1 ) / 4.0
110
110
variant .initial_txid = self .nodes [0 ].sendtoaddress (variant .address ["address" ], variant .initial_amount )
111
111
112
- # Generate a block containing the initial transactions.
112
+ # Generate a block containing the initial transactions, then another
113
+ # block further in the future (past the rescan window).
113
114
self .nodes [0 ].generate (1 )
114
115
assert_equal (self .nodes [0 ].getrawmempool (), [])
116
+ timestamp = self .nodes [0 ].getblockheader (self .nodes [0 ].getbestblockhash ())["time" ]
117
+ set_node_times (self .nodes , timestamp + 1 )
118
+ self .nodes [0 ].generate (1 )
115
119
sync_blocks (self .nodes )
116
120
117
121
# For each variation of wallet key import, invoke the import RPC and
@@ -124,11 +128,11 @@ def run_test(self):
124
128
# balances in the second part of the test.)
125
129
for variant in IMPORT_VARIANTS :
126
130
variant .node = self .nodes [1 if variant .rescan == Rescan .yes else 2 ]
127
- variant .do_import ()
131
+ variant .do_import (timestamp )
128
132
if variant .rescan == Rescan .yes :
129
133
variant .expected_balance = variant .initial_amount
130
134
variant .expected_txs = 1
131
- variant .check (variant .initial_txid , variant .initial_amount )
135
+ variant .check (variant .initial_txid , variant .initial_amount , 2 )
132
136
else :
133
137
variant .expected_balance = 0
134
138
variant .expected_txs = 0
@@ -149,7 +153,7 @@ def run_test(self):
149
153
for variant in IMPORT_VARIANTS :
150
154
variant .expected_balance += variant .sent_amount
151
155
variant .expected_txs += 1
152
- variant .check (variant .sent_txid , variant .sent_amount )
156
+ variant .check (variant .sent_txid , variant .sent_amount , 1 )
153
157
154
158
155
159
if __name__ == "__main__" :
0 commit comments