From fa2b778d0cf723925af8710d52cae211d4f036df Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 16 Oct 2020 13:05:56 +0200 Subject: [PATCH 1/3] test: Remove unused -blockversion from tests --- test/functional/feature_csv_activation.py | 1 - test/functional/feature_notifications.py | 11 ++++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/functional/feature_csv_activation.py b/test/functional/feature_csv_activation.py index 39e8bca751..46ba18b9b5 100755 --- a/test/functional/feature_csv_activation.py +++ b/test/functional/feature_csv_activation.py @@ -150,7 +150,6 @@ class BIP68_112_113Test(BitcoinTestFramework): self.setup_clean_chain = True self.extra_args = [[ '-whitelist=noban@127.0.0.1', - '-blockversion=4', '-addresstype=legacy', '-par=1', # Use only one script thread to get the exact reject reason for testing ]] diff --git a/test/functional/feature_notifications.py b/test/functional/feature_notifications.py index 5522f2b7c6..a5f27b0587 100755 --- a/test/functional/feature_notifications.py +++ b/test/functional/feature_notifications.py @@ -41,11 +41,12 @@ class NotificationsTest(BitcoinTestFramework): # -alertnotify and -blocknotify on node0, walletnotify on node1 self.extra_args = [[ - "-alertnotify=echo > {}".format(os.path.join(self.alertnotify_dir, '%s')), - "-blocknotify=echo > {}".format(os.path.join(self.blocknotify_dir, '%s'))], - ["-blockversion=211", - "-rescan", - "-walletnotify=echo > {}".format(os.path.join(self.walletnotify_dir, notify_outputname('%w', '%s')))]] + "-alertnotify=echo > {}".format(os.path.join(self.alertnotify_dir, '%s')), + "-blocknotify=echo > {}".format(os.path.join(self.blocknotify_dir, '%s')), + ], [ + "-rescan", + "-walletnotify=echo > {}".format(os.path.join(self.walletnotify_dir, notify_outputname('%w', '%s'))), + ]] self.wallet_names = [self.default_wallet_name, self.wallet] super().setup_network() From fa7fb0e44241982a6e5cd560c06ac0c9d8f47f88 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 16 Oct 2020 13:28:35 +0200 Subject: [PATCH 2/3] test: Default blockversion to 4 in feature_block There is one tests that checks version=1 blocks are rejected. For all other tests the version doesn't matter as long as it is large enough. --- test/functional/feature_block.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py index 19753d73ef..3cf7f3890c 100755 --- a/test/functional/feature_block.py +++ b/test/functional/feature_block.py @@ -1251,7 +1251,7 @@ class FullBlockTest(BitcoinTestFramework): blocks = [] spend = out[32] for i in range(89, LARGE_REORG_SIZE + 89): - b = self.next_block(i, spend, version=4) + b = self.next_block(i, spend) tx = CTransaction() script_length = MAX_BLOCK_BASE_SIZE - len(b.serialize()) - 69 script_output = CScript([b'\x00' * script_length]) @@ -1270,18 +1270,18 @@ class FullBlockTest(BitcoinTestFramework): self.move_tip(88) blocks2 = [] for i in range(89, LARGE_REORG_SIZE + 89): - blocks2.append(self.next_block("alt" + str(i), version=4)) + blocks2.append(self.next_block("alt" + str(i))) self.send_blocks(blocks2, False, force_send=True) # extend alt chain to trigger re-org - block = self.next_block("alt" + str(chain1_tip + 1), version=4) + block = self.next_block("alt" + str(chain1_tip + 1)) self.send_blocks([block], True, timeout=2440) # ... and re-org back to the first chain self.move_tip(chain1_tip) - block = self.next_block(chain1_tip + 1, version=4) + block = self.next_block(chain1_tip + 1) self.send_blocks([block], False, force_send=True) - block = self.next_block(chain1_tip + 2, version=4) + block = self.next_block(chain1_tip + 2) self.send_blocks([block], True, timeout=2440) self.log.info("Reject a block with an invalid block header version") @@ -1289,7 +1289,7 @@ class FullBlockTest(BitcoinTestFramework): self.send_blocks([b_v1], success=False, force_send=True, reject_reason='bad-version(0x00000001)', reconnect=True) self.move_tip(chain1_tip + 2) - b_cb34 = self.next_block('b_cb34', version=4) + b_cb34 = self.next_block('b_cb34') b_cb34.vtx[0].vin[0].scriptSig = b_cb34.vtx[0].vin[0].scriptSig[:-1] b_cb34.vtx[0].rehash() b_cb34.hashMerkleRoot = b_cb34.calc_merkle_root() @@ -1323,7 +1323,7 @@ class FullBlockTest(BitcoinTestFramework): tx.rehash() return tx - def next_block(self, number, spend=None, additional_coinbase_value=0, script=CScript([OP_TRUE]), *, version=1): + def next_block(self, number, spend=None, additional_coinbase_value=0, script=CScript([OP_TRUE]), *, version=4): if self.tip is None: base_block_hash = self.genesis_hash block_time = int(time.time()) + 1 From fa9b48549ca39b862a10bcfd90e3eac2a0e8ad2e Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 16 Oct 2020 13:43:29 +0200 Subject: [PATCH 3/3] test: Add test for -blockversion --- test/functional/mining_basic.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test/functional/mining_basic.py b/test/functional/mining_basic.py index 1b2c7644bd..ba467c1517 100755 --- a/test/functional/mining_basic.py +++ b/test/functional/mining_basic.py @@ -13,6 +13,7 @@ from decimal import Decimal from test_framework.blocktools import ( create_coinbase, + NORMAL_GBT_REQUEST_PARAMS, TIME_GENESIS_BLOCK, ) from test_framework.messages import ( @@ -25,9 +26,11 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, assert_raises_rpc_error, - connect_nodes, ) +VERSIONBITS_TOP_BITS = 0x20000000 +VERSIONBITS_DEPLOYMENT_TESTDUMMY_BIT = 28 + def assert_template(node, block, expect, rehash=True): if rehash: @@ -55,8 +58,16 @@ class MiningTest(BitcoinTestFramework): assert_equal(mining_info['blocks'], 200) assert_equal(mining_info['currentblocktx'], 0) assert_equal(mining_info['currentblockweight'], 4000) + + self.log.info('test blockversion') + self.restart_node(0, extra_args=['-mocktime={}'.format(t), '-blockversion=1337']) + self.connect_nodes(0, 1) + assert_equal(1337, self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)['version']) + self.restart_node(0, extra_args=['-mocktime={}'.format(t)]) + self.connect_nodes(0, 1) + assert_equal(VERSIONBITS_TOP_BITS + (1 << VERSIONBITS_DEPLOYMENT_TESTDUMMY_BIT), self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)['version']) self.restart_node(0) - connect_nodes(self.nodes[0], 1) + self.connect_nodes(0, 1) def run_test(self): self.mine_chain() @@ -80,7 +91,7 @@ class MiningTest(BitcoinTestFramework): # Mine a block to leave initial block download node.generatetoaddress(1, node.get_deterministic_priv_key().address) - tmpl = node.getblocktemplate({'rules': ['segwit']}) + tmpl = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS) self.log.info("getblocktemplate: Test capability advertised") assert 'proposal' in tmpl['capabilities'] assert 'coinbasetxn' not in tmpl