Skip to content

Commit 4ad7272

Browse files
committed
tests: reduce number of generated blocks for wallet_import_rescan
Generating blocks is slow, especially when --enable-debug. There is no need to generate a new block for each transaction, so avoid doing that to improve this test's runtime.
1 parent 9e229a5 commit 4ad7272

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

test/functional/wallet_import_rescan.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,16 @@ def run_test(self):
179179

180180
# Create one transaction on node 0 with a unique amount for
181181
# each possible type of wallet import RPC.
182+
last_variants = []
182183
for i, variant in enumerate(IMPORT_VARIANTS):
184+
if i % 10 == 0:
185+
blockhash = self.generate(self.nodes[0], 1)[0]
186+
conf_height = self.nodes[0].getblockcount()
187+
timestamp = self.nodes[0].getblockheader(blockhash)["time"]
188+
for var in last_variants:
189+
var.confirmation_height = conf_height
190+
var.timestamp = timestamp
191+
last_variants.clear()
183192
variant.label = "label {} {}".format(i, variant)
184193
variant.address = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress(
185194
label=variant.label,
@@ -188,9 +197,15 @@ def run_test(self):
188197
variant.key = self.nodes[1].dumpprivkey(variant.address["address"])
189198
variant.initial_amount = get_rand_amount()
190199
variant.initial_txid = self.nodes[0].sendtoaddress(variant.address["address"], variant.initial_amount)
191-
self.generate(self.nodes[0], 1) # Generate one block for each send
192-
variant.confirmation_height = self.nodes[0].getblockcount()
193-
variant.timestamp = self.nodes[0].getblockheader(self.nodes[0].getbestblockhash())["time"]
200+
last_variants.append(variant)
201+
202+
blockhash = self.generate(self.nodes[0], 1)[0]
203+
conf_height = self.nodes[0].getblockcount()
204+
timestamp = self.nodes[0].getblockheader(blockhash)["time"]
205+
for var in last_variants:
206+
var.confirmation_height = conf_height
207+
var.timestamp = timestamp
208+
last_variants.clear()
194209

195210
# Generate a block further in the future (past the rescan window).
196211
assert_equal(self.nodes[0].getrawmempool(), [])
@@ -217,11 +232,14 @@ def run_test(self):
217232
variant.check()
218233

219234
# Create new transactions sending to each address.
220-
for variant in IMPORT_VARIANTS:
235+
for i, variant in enumerate(IMPORT_VARIANTS):
236+
if i % 10 == 0:
237+
blockhash = self.generate(self.nodes[0], 1)[0]
238+
conf_height = self.nodes[0].getblockcount() + 1
221239
variant.sent_amount = get_rand_amount()
222240
variant.sent_txid = self.nodes[0].sendtoaddress(variant.address["address"], variant.sent_amount)
223-
self.generate(self.nodes[0], 1) # Generate one block for each send
224-
variant.confirmation_height = self.nodes[0].getblockcount()
241+
variant.confirmation_height = conf_height
242+
self.generate(self.nodes[0], 1)
225243

226244
assert_equal(self.nodes[0].getrawmempool(), [])
227245
self.sync_all()

0 commit comments

Comments
 (0)