Skip to content

Commit 0e9cb2d

Browse files
author
MarcoFalke
committed
Merge #15773: test: Add BitcoinTestFramework::sync_* methods
fafe5f0 test: Remove unused imports (MarcoFalke) fa16a09 scripted-diff: use self.sync_* methods (MarcoFalke) faf77f9 test: Pass self to test_simple_bumpfee_succeeds (MarcoFalke) fa6dc7c test: Add BitcoinTestFramework::sync_* methods (MarcoFalke) fafe008 test: Pass at most one node group to sync_all (MarcoFalke) fa4680e scripted-diff: Rename sync_blocks to send_blocks to avoid name collisions and confusion (MarcoFalke) Pull request description: This adds methods to the test framework that can be called by just `self.sync_*()`. This avoids having to import the underlying util method. Also, in the default case, where all nodes are synced this avoid having to pass `self.nodes` explicitly. So the effective changes are: ```diff @@ -from test_framework.util import sync_blocks, sync_mempools @@ - sync_blocks(self.nodes) + self.sync_blocks() @@ - sync_mempools(self.nodes) + self.sync_mempools() ACKs for commit fafe5f: promag: utACK fafe5f0. jonatack: ACK bitcoin/bitcoin@fafe5f0, nice simplification. Tree-SHA512: 5c81840edf9fb3c5de2d7bf95ca36a5a8d23567cd1479a0f4044547c2080e9a3c5cf375357bc8eebb5b68829be050a171ab2512cfd47b89feed51fe3bad2cd72
2 parents bb68abe + fafe5f0 commit 0e9cb2d

32 files changed

+331
-288
lines changed

test/functional/example_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def setup_network(self):
117117
# sync_all() should not include node2, since we're not expecting it to
118118
# sync.
119119
connect_nodes(self.nodes[0], 1)
120-
self.sync_all([self.nodes[0:2]])
120+
self.sync_all(self.nodes[0:2])
121121

122122
# Use setup_nodes() to customize the node start behaviour (for example if
123123
# you don't want to start all nodes at the start of the test).
@@ -141,7 +141,7 @@ def run_test(self):
141141

142142
# Generating a block on one of the nodes will get us out of IBD
143143
blocks = [int(self.nodes[0].generate(nblocks=1)[0], 16)]
144-
self.sync_all([self.nodes[0:2]])
144+
self.sync_all(self.nodes[0:2])
145145

146146
# Notice above how we called an RPC by calling a method with the same
147147
# name on the node object. Notice also how we used a keyword argument

test/functional/feature_bip68_sequence.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut, FromHex, ToHex
1111
from test_framework.script import CScript
1212
from test_framework.test_framework import BitcoinTestFramework
13-
from test_framework.util import assert_equal, assert_greater_than, assert_raises_rpc_error, get_bip9_status, satoshi_round, sync_blocks
13+
from test_framework.util import (
14+
assert_equal,
15+
assert_greater_than,
16+
assert_raises_rpc_error,
17+
get_bip9_status,
18+
satoshi_round,
19+
)
1420

1521
SEQUENCE_LOCKTIME_DISABLE_FLAG = (1<<31)
1622
SEQUENCE_LOCKTIME_TYPE_FLAG = (1<<22) # this means use time (0 means height)
@@ -385,7 +391,7 @@ def activateCSV(self):
385391
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], "locked_in")
386392
self.nodes[0].generate(1)
387393
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], "active")
388-
sync_blocks(self.nodes)
394+
self.sync_blocks()
389395

390396
# Use self.nodes[1] to test that version 2 transactions are standard.
391397
def test_version2_relay(self):

test/functional/feature_block.py

Lines changed: 99 additions & 99 deletions
Large diffs are not rendered by default.

test/functional/feature_csv_activation.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def create_test_block(self, txs, version=536870912):
168168
block.solve()
169169
return block
170170

171-
def sync_blocks(self, blocks, success=True):
171+
def send_blocks(self, blocks, success=True):
172172
"""Sends blocks to test node. Syncs and verifies that tip has advanced to most recent block.
173173
174174
Call with success = False if the tip shouldn't advance to the most recent block."""
@@ -190,7 +190,7 @@ def run_test(self):
190190
self.log.info("Test that the csv softfork is DEFINED")
191191
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'defined')
192192
test_blocks = self.generate_blocks(61, 4)
193-
self.sync_blocks(test_blocks)
193+
self.send_blocks(test_blocks)
194194

195195
self.log.info("Advance from DEFINED to STARTED, height = 143")
196196
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'started')
@@ -202,7 +202,7 @@ def run_test(self):
202202
test_blocks = self.generate_blocks(20, 4, test_blocks) # 0x00000004 (signalling not)
203203
test_blocks = self.generate_blocks(50, 536871169, test_blocks) # 0x20000101 (signalling ready)
204204
test_blocks = self.generate_blocks(24, 536936448, test_blocks) # 0x20010000 (signalling not)
205-
self.sync_blocks(test_blocks)
205+
self.send_blocks(test_blocks)
206206

207207
self.log.info("Failed to advance past STARTED, height = 287")
208208
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'started')
@@ -214,14 +214,14 @@ def run_test(self):
214214
test_blocks = self.generate_blocks(26, 4, test_blocks) # 0x00000004 (signalling not)
215215
test_blocks = self.generate_blocks(50, 536871169, test_blocks) # 0x20000101 (signalling ready)
216216
test_blocks = self.generate_blocks(10, 536936448, test_blocks) # 0x20010000 (signalling not)
217-
self.sync_blocks(test_blocks)
217+
self.send_blocks(test_blocks)
218218

219219
self.log.info("Advanced from STARTED to LOCKED_IN, height = 431")
220220
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'locked_in')
221221

222222
# Generate 140 more version 4 blocks
223223
test_blocks = self.generate_blocks(140, 4)
224-
self.sync_blocks(test_blocks)
224+
self.send_blocks(test_blocks)
225225

226226
# Inputs at height = 572
227227
#
@@ -264,7 +264,7 @@ def run_test(self):
264264

265265
# 2 more version 4 blocks
266266
test_blocks = self.generate_blocks(2, 4)
267-
self.sync_blocks(test_blocks)
267+
self.send_blocks(test_blocks)
268268

269269
self.log.info("Not yet advanced to ACTIVE, height = 574 (will activate for block 576, not 575)")
270270
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'locked_in')
@@ -318,7 +318,7 @@ def run_test(self):
318318
# try BIP 112 with seq=9 txs
319319
success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v1))
320320
success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v1))
321-
self.sync_blocks([self.create_test_block(success_txs)])
321+
self.send_blocks([self.create_test_block(success_txs)])
322322
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
323323

324324
self.log.info("Test version 2 txs")
@@ -337,12 +337,12 @@ def run_test(self):
337337
# try BIP 112 with seq=9 txs
338338
success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v2))
339339
success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v2))
340-
self.sync_blocks([self.create_test_block(success_txs)])
340+
self.send_blocks([self.create_test_block(success_txs)])
341341
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
342342

343343
# 1 more version 4 block to get us to height 575 so the fork should now be active for the next block
344344
test_blocks = self.generate_blocks(1, 4)
345-
self.sync_blocks(test_blocks)
345+
self.send_blocks(test_blocks)
346346
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'active')
347347

348348
self.log.info("Post-Soft Fork Tests.")
@@ -354,74 +354,74 @@ def run_test(self):
354354
bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
355355
bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2)
356356
for bip113tx in [bip113signed1, bip113signed2]:
357-
self.sync_blocks([self.create_test_block([bip113tx])], success=False)
357+
self.send_blocks([self.create_test_block([bip113tx])], success=False)
358358
# BIP 113 tests should now pass if the locktime is < MTP
359359
bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block
360360
bip113signed1 = sign_transaction(self.nodes[0], bip113tx_v1)
361361
bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block
362362
bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2)
363363
for bip113tx in [bip113signed1, bip113signed2]:
364-
self.sync_blocks([self.create_test_block([bip113tx])])
364+
self.send_blocks([self.create_test_block([bip113tx])])
365365
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
366366

367367
# Next block height = 580 after 4 blocks of random version
368368
test_blocks = self.generate_blocks(4, 1234)
369-
self.sync_blocks(test_blocks)
369+
self.send_blocks(test_blocks)
370370

371371
self.log.info("BIP 68 tests")
372372
self.log.info("Test version 1 txs - all should still pass")
373373

374374
success_txs = []
375375
success_txs.extend(all_rlt_txs(bip68txs_v1))
376-
self.sync_blocks([self.create_test_block(success_txs)])
376+
self.send_blocks([self.create_test_block(success_txs)])
377377
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
378378

379379
self.log.info("Test version 2 txs")
380380

381381
# All txs with SEQUENCE_LOCKTIME_DISABLE_FLAG set pass
382382
bip68success_txs = [tx['tx'] for tx in bip68txs_v2 if tx['sdf']]
383-
self.sync_blocks([self.create_test_block(bip68success_txs)])
383+
self.send_blocks([self.create_test_block(bip68success_txs)])
384384
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
385385

386386
# All txs without flag fail as we are at delta height = 8 < 10 and delta time = 8 * 600 < 10 * 512
387387
bip68timetxs = [tx['tx'] for tx in bip68txs_v2 if not tx['sdf'] and tx['stf']]
388388
for tx in bip68timetxs:
389-
self.sync_blocks([self.create_test_block([tx])], success=False)
389+
self.send_blocks([self.create_test_block([tx])], success=False)
390390

391391
bip68heighttxs = [tx['tx'] for tx in bip68txs_v2 if not tx['sdf'] and not tx['stf']]
392392
for tx in bip68heighttxs:
393-
self.sync_blocks([self.create_test_block([tx])], success=False)
393+
self.send_blocks([self.create_test_block([tx])], success=False)
394394

395395
# Advance one block to 581
396396
test_blocks = self.generate_blocks(1, 1234)
397-
self.sync_blocks(test_blocks)
397+
self.send_blocks(test_blocks)
398398

399399
# Height txs should fail and time txs should now pass 9 * 600 > 10 * 512
400400
bip68success_txs.extend(bip68timetxs)
401-
self.sync_blocks([self.create_test_block(bip68success_txs)])
401+
self.send_blocks([self.create_test_block(bip68success_txs)])
402402
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
403403
for tx in bip68heighttxs:
404-
self.sync_blocks([self.create_test_block([tx])], success=False)
404+
self.send_blocks([self.create_test_block([tx])], success=False)
405405

406406
# Advance one block to 582
407407
test_blocks = self.generate_blocks(1, 1234)
408-
self.sync_blocks(test_blocks)
408+
self.send_blocks(test_blocks)
409409

410410
# All BIP 68 txs should pass
411411
bip68success_txs.extend(bip68heighttxs)
412-
self.sync_blocks([self.create_test_block(bip68success_txs)])
412+
self.send_blocks([self.create_test_block(bip68success_txs)])
413413
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
414414

415415
self.log.info("BIP 112 tests")
416416
self.log.info("Test version 1 txs")
417417

418418
# -1 OP_CSV tx should fail
419-
self.sync_blocks([self.create_test_block([bip112tx_special_v1])], success=False)
419+
self.send_blocks([self.create_test_block([bip112tx_special_v1])], success=False)
420420
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, version 1 txs should still pass
421421

422422
success_txs = [tx['tx'] for tx in bip112txs_vary_OP_CSV_v1 if tx['sdf']]
423423
success_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v1 if tx['sdf']]
424-
self.sync_blocks([self.create_test_block(success_txs)])
424+
self.send_blocks([self.create_test_block(success_txs)])
425425
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
426426

427427
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV, version 1 txs should now fail
@@ -430,18 +430,18 @@ def run_test(self):
430430
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v1 if not tx['sdf']]
431431
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v1 if not tx['sdf']]
432432
for tx in fail_txs:
433-
self.sync_blocks([self.create_test_block([tx])], success=False)
433+
self.send_blocks([self.create_test_block([tx])], success=False)
434434

435435
self.log.info("Test version 2 txs")
436436

437437
# -1 OP_CSV tx should fail
438-
self.sync_blocks([self.create_test_block([bip112tx_special_v2])], success=False)
438+
self.send_blocks([self.create_test_block([bip112tx_special_v2])], success=False)
439439

440440
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, version 2 txs should pass (all sequence locks are met)
441441
success_txs = [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if tx['sdf']]
442442
success_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v2 if tx['sdf']]
443443

444-
self.sync_blocks([self.create_test_block(success_txs)])
444+
self.send_blocks([self.create_test_block(success_txs)])
445445
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
446446

447447
# SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV for all remaining txs ##
@@ -450,23 +450,23 @@ def run_test(self):
450450
fail_txs = all_rlt_txs(bip112txs_vary_nSequence_9_v2)
451451
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v2 if not tx['sdf']]
452452
for tx in fail_txs:
453-
self.sync_blocks([self.create_test_block([tx])], success=False)
453+
self.send_blocks([self.create_test_block([tx])], success=False)
454454

455455
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in nSequence, tx should fail
456456
fail_txs = [tx['tx'] for tx in bip112txs_vary_nSequence_v2 if tx['sdf']]
457457
for tx in fail_txs:
458-
self.sync_blocks([self.create_test_block([tx])], success=False)
458+
self.send_blocks([self.create_test_block([tx])], success=False)
459459

460460
# If sequencelock types mismatch, tx should fail
461461
fail_txs = [tx['tx'] for tx in bip112txs_vary_nSequence_v2 if not tx['sdf'] and tx['stf']]
462462
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']]
463463
for tx in fail_txs:
464-
self.sync_blocks([self.create_test_block([tx])], success=False)
464+
self.send_blocks([self.create_test_block([tx])], success=False)
465465

466466
# Remaining txs should pass, just test masking works properly
467467
success_txs = [tx['tx'] for tx in bip112txs_vary_nSequence_v2 if not tx['sdf'] and not tx['stf']]
468468
success_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and not tx['stf']]
469-
self.sync_blocks([self.create_test_block(success_txs)])
469+
self.send_blocks([self.create_test_block(success_txs)])
470470
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
471471

472472
# Additional test, of checking that comparison of two time types works properly
@@ -476,7 +476,7 @@ def run_test(self):
476476
signtx = sign_transaction(self.nodes[0], tx)
477477
time_txs.append(signtx)
478478

479-
self.sync_blocks([self.create_test_block(time_txs)])
479+
self.send_blocks([self.create_test_block(time_txs)])
480480
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
481481

482482
# TODO: Test empty stack fails

test/functional/feature_fee_estimation.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2014-2018 The Bitcoin Core developers
2+
# Copyright (c) 2014-2019 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test fee estimation code."""
@@ -15,8 +15,6 @@
1515
assert_greater_than_or_equal,
1616
connect_nodes,
1717
satoshi_round,
18-
sync_blocks,
19-
sync_mempools,
2018
)
2119

2220
# Construct 2 trivial P2SH's and the ScriptSigs that spend them
@@ -162,9 +160,9 @@ def transact_and_mine(self, numblocks, mining_node):
162160
self.memutxo, Decimal("0.005"), min_fee, min_fee)
163161
tx_kbytes = (len(txhex) // 2) / 1000.0
164162
self.fees_per_kb.append(float(fee) / tx_kbytes)
165-
sync_mempools(self.nodes[0:3], wait=.1)
163+
self.sync_mempools(self.nodes[0:3], wait=.1)
166164
mined = mining_node.getblock(mining_node.generate(1)[0], True)["tx"]
167-
sync_blocks(self.nodes[0:3], wait=.1)
165+
self.sync_blocks(self.nodes[0:3], wait=.1)
168166
# update which txouts are confirmed
169167
newmem = []
170168
for utx in self.memutxo:
@@ -237,7 +235,7 @@ def run_test(self):
237235
while len(self.nodes[1].getrawmempool()) > 0:
238236
self.nodes[1].generate(1)
239237

240-
sync_blocks(self.nodes[0:3], wait=.1)
238+
self.sync_blocks(self.nodes[0:3], wait=.1)
241239
self.log.info("Final estimates after emptying mempools")
242240
check_estimates(self.nodes[1], self.fees_per_kb)
243241

test/functional/feature_pruning.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@
1414
from test_framework.messages import CBlock, ToHex
1515
from test_framework.script import CScript, OP_RETURN, OP_NOP
1616
from test_framework.test_framework import BitcoinTestFramework
17-
from test_framework.util import assert_equal, assert_greater_than, assert_raises_rpc_error, connect_nodes, disconnect_nodes, sync_blocks, wait_until
17+
from test_framework.util import (
18+
assert_equal,
19+
assert_greater_than,
20+
assert_raises_rpc_error,
21+
connect_nodes,
22+
disconnect_nodes,
23+
wait_until,
24+
)
1825

1926
MIN_BLOCKS_TO_KEEP = 288
2027

@@ -100,7 +107,7 @@ def setup_network(self):
100107
connect_nodes(self.nodes[0], 2)
101108
connect_nodes(self.nodes[0], 3)
102109
connect_nodes(self.nodes[0], 4)
103-
sync_blocks(self.nodes[0:5])
110+
self.sync_blocks(self.nodes[0:5])
104111

105112
def setup_nodes(self):
106113
self.add_nodes(self.num_nodes, self.extra_args)
@@ -111,13 +118,13 @@ def setup_nodes(self):
111118
def create_big_chain(self):
112119
# Start by creating some coinbases we can spend later
113120
self.nodes[1].generate(200)
114-
sync_blocks(self.nodes[0:2])
121+
self.sync_blocks(self.nodes[0:2])
115122
self.nodes[0].generate(150)
116123

117124
# Then mine enough full blocks to create more than 550MiB of data
118125
mine_large_blocks(self.nodes[0], 645)
119126

120-
sync_blocks(self.nodes[0:5])
127+
self.sync_blocks(self.nodes[0:5])
121128

122129
def test_height_min(self):
123130
assert os.path.isfile(os.path.join(self.prunedir, "blk00000.dat")), "blk00000.dat is missing, pruning too early"
@@ -153,7 +160,7 @@ def create_chain_with_staleblocks(self):
153160
# Create connections in the order so both nodes can see the reorg at the same time
154161
connect_nodes(self.nodes[0], 1)
155162
connect_nodes(self.nodes[0], 2)
156-
sync_blocks(self.nodes[0:3])
163+
self.sync_blocks(self.nodes[0:3])
157164

158165
self.log.info("Usage can be over target because of high stale rate: %d" % calc_usage(self.prunedir))
159166

@@ -190,7 +197,7 @@ def reorg_test(self):
190197
self.log.info("Reconnect nodes")
191198
connect_nodes(self.nodes[0], 1)
192199
connect_nodes(self.nodes[1], 2)
193-
sync_blocks(self.nodes[0:3], timeout=120)
200+
self.sync_blocks(self.nodes[0:3], timeout=120)
194201

195202
self.log.info("Verify height on node 2: %d" % self.nodes[2].getblockcount())
196203
self.log.info("Usage possibly still high because of stale blocks in block files: %d" % calc_usage(self.prunedir))
@@ -345,7 +352,7 @@ def wallet_test(self):
345352
self.log.info("Syncing node 5 to test wallet")
346353
connect_nodes(self.nodes[0], 5)
347354
nds = [self.nodes[0], self.nodes[5]]
348-
sync_blocks(nds, wait=5, timeout=300)
355+
self.sync_blocks(nds, wait=5, timeout=300)
349356
self.stop_node(5) # stop and start to trigger rescan
350357
self.start_node(5, extra_args=["-prune=550"])
351358
self.log.info("Success")

0 commit comments

Comments
 (0)