Skip to content

Commit c6806ee

Browse files
committed
Merge #15059: test: Add basic test for BIP34
fab17e8 test: Add basic test for BIP34 (MarcoFalke) Pull request description: BIP34 was disabled for testing, which explains why it had no test. Fix that by enabling it and adding a test. Tree-SHA512: 9cb5702d474117ce6420226eb93ee09d6fb5fc856fabc8b67abe56a088cd727674e0e5462000e1afa83b911374036f90abdbdde56a8c236a75572ed47e10a00f
2 parents 29a9f07 + fab17e8 commit c6806ee

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

src/chainparams.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ class CRegTestParams : public CChainParams {
272272
strNetworkID = "regtest";
273273
consensus.nSubsidyHalvingInterval = 150;
274274
consensus.BIP16Exception = uint256();
275-
consensus.BIP34Height = 100000000; // BIP34 has not activated on regtest (far in the future so block v1 are not rejected in tests)
275+
consensus.BIP34Height = 500; // BIP34 activated on regtest (Used in functional tests)
276276
consensus.BIP34Hash = uint256();
277-
consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests)
278-
consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in rpc activation tests)
277+
consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in functional tests)
278+
consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in functional tests)
279279
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
280280
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
281281
consensus.nPowTargetSpacing = 10 * 60;

test/functional/feature_block.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ def run_test(self):
925925
# \-> b67 (20)
926926
#
927927
#
928-
self.log.info("Reject a block with a transaction double spending a transaction creted in the same block")
928+
self.log.info("Reject a block with a transaction double spending a transaction created in the same block")
929929
self.move_tip(65)
930930
b67 = self.next_block(67)
931931
tx1 = self.create_and_sign_transaction(out[20], out[20].vout[0].nValue)
@@ -1220,7 +1220,7 @@ def run_test(self):
12201220
blocks = []
12211221
spend = out[32]
12221222
for i in range(89, LARGE_REORG_SIZE + 89):
1223-
b = self.next_block(i, spend)
1223+
b = self.next_block(i, spend, version=4)
12241224
tx = CTransaction()
12251225
script_length = MAX_BLOCK_BASE_SIZE - len(b.serialize()) - 69
12261226
script_output = CScript([b'\x00' * script_length])
@@ -1239,20 +1239,32 @@ def run_test(self):
12391239
self.move_tip(88)
12401240
blocks2 = []
12411241
for i in range(89, LARGE_REORG_SIZE + 89):
1242-
blocks2.append(self.next_block("alt" + str(i)))
1242+
blocks2.append(self.next_block("alt" + str(i), version=4))
12431243
self.sync_blocks(blocks2, False, force_send=True)
12441244

12451245
# extend alt chain to trigger re-org
1246-
block = self.next_block("alt" + str(chain1_tip + 1))
1246+
block = self.next_block("alt" + str(chain1_tip + 1), version=4)
12471247
self.sync_blocks([block], True, timeout=480)
12481248

12491249
# ... and re-org back to the first chain
12501250
self.move_tip(chain1_tip)
1251-
block = self.next_block(chain1_tip + 1)
1251+
block = self.next_block(chain1_tip + 1, version=4)
12521252
self.sync_blocks([block], False, force_send=True)
1253-
block = self.next_block(chain1_tip + 2)
1253+
block = self.next_block(chain1_tip + 2, version=4)
12541254
self.sync_blocks([block], True, timeout=480)
12551255

1256+
self.log.info("Reject a block with an invalid block header version")
1257+
b_v1 = self.next_block('b_v1', version=1)
1258+
self.sync_blocks([b_v1], success=False, force_send=True, reject_reason='bad-version(0x00000001)')
1259+
1260+
self.move_tip(chain1_tip + 2)
1261+
b_cb34 = self.next_block('b_cb34', version=4)
1262+
b_cb34.vtx[0].vin[0].scriptSig = b_cb34.vtx[0].vin[0].scriptSig[:-1]
1263+
b_cb34.vtx[0].rehash()
1264+
b_cb34.hashMerkleRoot = b_cb34.calc_merkle_root()
1265+
b_cb34.solve()
1266+
self.sync_blocks([b_cb34], success=False, reject_reason='bad-cb-height', reconnect=True)
1267+
12561268
# Helper methods
12571269
################
12581270

@@ -1280,7 +1292,7 @@ def create_and_sign_transaction(self, spend_tx, value, script=CScript([OP_TRUE])
12801292
tx.rehash()
12811293
return tx
12821294

1283-
def next_block(self, number, spend=None, additional_coinbase_value=0, script=CScript([OP_TRUE]), solve=True):
1295+
def next_block(self, number, spend=None, additional_coinbase_value=0, script=CScript([OP_TRUE]), solve=True, *, version=1):
12841296
if self.tip is None:
12851297
base_block_hash = self.genesis_hash
12861298
block_time = int(time.time()) + 1
@@ -1293,11 +1305,11 @@ def next_block(self, number, spend=None, additional_coinbase_value=0, script=CSc
12931305
coinbase.vout[0].nValue += additional_coinbase_value
12941306
coinbase.rehash()
12951307
if spend is None:
1296-
block = create_block(base_block_hash, coinbase, block_time)
1308+
block = create_block(base_block_hash, coinbase, block_time, version=version)
12971309
else:
12981310
coinbase.vout[0].nValue += spend.vout[0].nValue - 1 # all but one satoshi to fees
12991311
coinbase.rehash()
1300-
block = create_block(base_block_hash, coinbase, block_time)
1312+
block = create_block(base_block_hash, coinbase, block_time, version=version)
13011313
tx = self.create_tx(spend, 0, 1, script) # spend 1 satoshi
13021314
self.sign_tx(tx, spend)
13031315
self.add_transactions_to_block(block, [tx])

test/functional/test_framework/blocktools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@
4646
# From BIP141
4747
WITNESS_COMMITMENT_HEADER = b"\xaa\x21\xa9\xed"
4848

49-
def create_block(hashprev, coinbase, ntime=None):
49+
def create_block(hashprev, coinbase, ntime=None, *, version=1):
5050
"""Create a block (with regtest difficulty)."""
5151
block = CBlock()
52+
block.nVersion = version
5253
if ntime is None:
5354
import time
5455
block.nTime = int(time.time() + 600)

0 commit comments

Comments
 (0)