Skip to content

Commit 83363f7

Browse files
committed
Merge bitcoin#20167: test: Add test for -blockversion
fa9b485 test: Add test for -blockversion (MarcoFalke) fa7fb0e test: Default blockversion to 4 in feature_block (MarcoFalke) fa2b778 test: Remove unused -blockversion from tests (MarcoFalke) Pull request description: `-blockversion` is currently untested, as in: The setting could be made a no-op without any tests failing. Fix that by adding an explicit test for it. Also, related minor cleanups. ACKs for top commit: guggero: ACK fa9b485. Tree-SHA512: 1b2e792f7ed0ec1db163476ee8a938f8f7cb3691f797c721bbe55fdeed92487c2ff83b55467440096917999406c86430cb3a615383cefb4f621828309ff6a1e7
2 parents c1564ba + fa9b485 commit 83363f7

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

test/functional/feature_block.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ def run_test(self):
12511251
blocks = []
12521252
spend = out[32]
12531253
for i in range(89, LARGE_REORG_SIZE + 89):
1254-
b = self.next_block(i, spend, version=4)
1254+
b = self.next_block(i, spend)
12551255
tx = CTransaction()
12561256
script_length = MAX_BLOCK_BASE_SIZE - len(b.serialize()) - 69
12571257
script_output = CScript([b'\x00' * script_length])
@@ -1270,26 +1270,26 @@ def run_test(self):
12701270
self.move_tip(88)
12711271
blocks2 = []
12721272
for i in range(89, LARGE_REORG_SIZE + 89):
1273-
blocks2.append(self.next_block("alt" + str(i), version=4))
1273+
blocks2.append(self.next_block("alt" + str(i)))
12741274
self.send_blocks(blocks2, False, force_send=True)
12751275

12761276
# extend alt chain to trigger re-org
1277-
block = self.next_block("alt" + str(chain1_tip + 1), version=4)
1277+
block = self.next_block("alt" + str(chain1_tip + 1))
12781278
self.send_blocks([block], True, timeout=2440)
12791279

12801280
# ... and re-org back to the first chain
12811281
self.move_tip(chain1_tip)
1282-
block = self.next_block(chain1_tip + 1, version=4)
1282+
block = self.next_block(chain1_tip + 1)
12831283
self.send_blocks([block], False, force_send=True)
1284-
block = self.next_block(chain1_tip + 2, version=4)
1284+
block = self.next_block(chain1_tip + 2)
12851285
self.send_blocks([block], True, timeout=2440)
12861286

12871287
self.log.info("Reject a block with an invalid block header version")
12881288
b_v1 = self.next_block('b_v1', version=1)
12891289
self.send_blocks([b_v1], success=False, force_send=True, reject_reason='bad-version(0x00000001)', reconnect=True)
12901290

12911291
self.move_tip(chain1_tip + 2)
1292-
b_cb34 = self.next_block('b_cb34', version=4)
1292+
b_cb34 = self.next_block('b_cb34')
12931293
b_cb34.vtx[0].vin[0].scriptSig = b_cb34.vtx[0].vin[0].scriptSig[:-1]
12941294
b_cb34.vtx[0].rehash()
12951295
b_cb34.hashMerkleRoot = b_cb34.calc_merkle_root()
@@ -1323,7 +1323,7 @@ def create_and_sign_transaction(self, spend_tx, value, script=CScript([OP_TRUE])
13231323
tx.rehash()
13241324
return tx
13251325

1326-
def next_block(self, number, spend=None, additional_coinbase_value=0, script=CScript([OP_TRUE]), *, version=1):
1326+
def next_block(self, number, spend=None, additional_coinbase_value=0, script=CScript([OP_TRUE]), *, version=4):
13271327
if self.tip is None:
13281328
base_block_hash = self.genesis_hash
13291329
block_time = int(time.time()) + 1

test/functional/feature_csv_activation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ def set_test_params(self):
150150
self.setup_clean_chain = True
151151
self.extra_args = [[
152152
'-whitelist=noban@127.0.0.1',
153-
'-blockversion=4',
154153
'-addresstype=legacy',
155154
'-par=1', # Use only one script thread to get the exact reject reason for testing
156155
]]

test/functional/feature_notifications.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ def setup_network(self):
3939

4040
# -alertnotify and -blocknotify on node0, walletnotify on node1
4141
self.extra_args = [[
42-
"-alertnotify=echo > {}".format(os.path.join(self.alertnotify_dir, '%s')),
43-
"-blocknotify=echo > {}".format(os.path.join(self.blocknotify_dir, '%s'))],
44-
["-blockversion=211",
45-
"-rescan",
46-
"-walletnotify=echo > {}".format(os.path.join(self.walletnotify_dir, notify_outputname('%w', '%s')))]]
42+
"-alertnotify=echo > {}".format(os.path.join(self.alertnotify_dir, '%s')),
43+
"-blocknotify=echo > {}".format(os.path.join(self.blocknotify_dir, '%s')),
44+
], [
45+
"-rescan",
46+
"-walletnotify=echo > {}".format(os.path.join(self.walletnotify_dir, notify_outputname('%w', '%s'))),
47+
]]
4748
self.wallet_names = [self.default_wallet_name, self.wallet]
4849
super().setup_network()
4950

test/functional/mining_basic.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from test_framework.blocktools import (
1515
create_coinbase,
16+
NORMAL_GBT_REQUEST_PARAMS,
1617
TIME_GENESIS_BLOCK,
1718
)
1819
from test_framework.messages import (
@@ -27,6 +28,9 @@
2728
assert_raises_rpc_error,
2829
)
2930

31+
VERSIONBITS_TOP_BITS = 0x20000000
32+
VERSIONBITS_DEPLOYMENT_TESTDUMMY_BIT = 28
33+
3034

3135
def assert_template(node, block, expect, rehash=True):
3236
if rehash:
@@ -54,6 +58,14 @@ def mine_chain(self):
5458
assert_equal(mining_info['blocks'], 200)
5559
assert_equal(mining_info['currentblocktx'], 0)
5660
assert_equal(mining_info['currentblockweight'], 4000)
61+
62+
self.log.info('test blockversion')
63+
self.restart_node(0, extra_args=['-mocktime={}'.format(t), '-blockversion=1337'])
64+
self.connect_nodes(0, 1)
65+
assert_equal(1337, self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)['version'])
66+
self.restart_node(0, extra_args=['-mocktime={}'.format(t)])
67+
self.connect_nodes(0, 1)
68+
assert_equal(VERSIONBITS_TOP_BITS + (1 << VERSIONBITS_DEPLOYMENT_TESTDUMMY_BIT), self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)['version'])
5769
self.restart_node(0)
5870
self.connect_nodes(0, 1)
5971

@@ -79,7 +91,7 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
7991

8092
# Mine a block to leave initial block download
8193
node.generatetoaddress(1, node.get_deterministic_priv_key().address)
82-
tmpl = node.getblocktemplate({'rules': ['segwit']})
94+
tmpl = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
8395
self.log.info("getblocktemplate: Test capability advertised")
8496
assert 'proposal' in tmpl['capabilities']
8597
assert 'coinbasetxn' not in tmpl

0 commit comments

Comments
 (0)