Skip to content

Commit c28583d

Browse files
committed
[qa] Extend import-rescan.py to test specific key timestamps
1 parent 8be0866 commit c28583d

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

qa/rpc-tests/import-rescan.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"""
2121

2222
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)
2424
from decimal import Decimal
2525

2626
import collections
@@ -29,13 +29,13 @@
2929

3030
Call = enum.Enum("Call", "single multi")
3131
Data = enum.Enum("Data", "address pub priv")
32-
Rescan = enum.Enum("Rescan", "no yes")
32+
Rescan = enum.Enum("Rescan", "no yes late_timestamp")
3333

3434

3535
class Variant(collections.namedtuple("Variant", "call data rescan")):
3636
"""Helper for importing one key and verifying scanned transactions."""
3737

38-
def do_import(self):
38+
def do_import(self, timestamp):
3939
"""Call one key import RPC."""
4040

4141
if self.call == Call.single:
@@ -51,15 +51,15 @@ def do_import(self):
5151
"scriptPubKey": {
5252
"address": self.address["address"]
5353
},
54-
"timestamp": "now",
54+
"timestamp": timestamp + (1 if self.rescan == Rescan.late_timestamp else 0),
5555
"pubkeys": [self.address["pubkey"]] if self.data == Data.pub else [],
5656
"keys": [self.key] if self.data == Data.priv else [],
5757
"label": self.label,
5858
"watchonly": self.data != Data.priv
59-
}], {"rescan": self.rescan == Rescan.yes})
59+
}], {"rescan": self.rescan in (Rescan.yes, Rescan.late_timestamp)})
6060
assert_equal(response, [{"success": True}])
6161

62-
def check(self, txid=None, amount=None):
62+
def check(self, txid=None, amount=None, confirmations=None):
6363
"""Verify that getbalance/listtransactions return expected values."""
6464

6565
balance = self.node.getbalance(self.label, 0, True)
@@ -76,7 +76,7 @@ def check(self, txid=None, amount=None):
7676
assert_equal(tx["category"], "receive")
7777
assert_equal(tx["label"], self.label)
7878
assert_equal(tx["txid"], txid)
79-
assert_equal(tx["confirmations"], 1)
79+
assert_equal(tx["confirmations"], confirmations)
8080
assert_equal("trusted" not in tx, True)
8181
if self.data != Data.priv:
8282
assert_equal(tx["involvesWatchonly"], True)
@@ -109,9 +109,13 @@ def run_test(self):
109109
variant.initial_amount = 25 - (i + 1) / 4.0
110110
variant.initial_txid = self.nodes[0].sendtoaddress(variant.address["address"], variant.initial_amount)
111111

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).
113114
self.nodes[0].generate(1)
114115
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)
115119
sync_blocks(self.nodes)
116120

117121
# For each variation of wallet key import, invoke the import RPC and
@@ -124,11 +128,11 @@ def run_test(self):
124128
# balances in the second part of the test.)
125129
for variant in IMPORT_VARIANTS:
126130
variant.node = self.nodes[1 if variant.rescan == Rescan.yes else 2]
127-
variant.do_import()
131+
variant.do_import(timestamp)
128132
if variant.rescan == Rescan.yes:
129133
variant.expected_balance = variant.initial_amount
130134
variant.expected_txs = 1
131-
variant.check(variant.initial_txid, variant.initial_amount)
135+
variant.check(variant.initial_txid, variant.initial_amount, 2)
132136
else:
133137
variant.expected_balance = 0
134138
variant.expected_txs = 0
@@ -149,7 +153,7 @@ def run_test(self):
149153
for variant in IMPORT_VARIANTS:
150154
variant.expected_balance += variant.sent_amount
151155
variant.expected_txs += 1
152-
variant.check(variant.sent_txid, variant.sent_amount)
156+
variant.check(variant.sent_txid, variant.sent_amount, 1)
153157

154158

155159
if __name__ == "__main__":

0 commit comments

Comments
 (0)