Skip to content

Commit 222290f

Browse files
author
MarcoFalke
committed
test: Set BIP34Height = 2 for regtest
1 parent fac90c5 commit 222290f

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

src/chainparams.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class CRegTestParams : public CChainParams {
390390
consensus.signet_challenge.clear();
391391
consensus.nSubsidyHalvingInterval = 150;
392392
consensus.BIP16Exception = uint256();
393-
consensus.BIP34Height = 500; // BIP34 activated on regtest (Used in functional tests)
393+
consensus.BIP34Height = 2; // BIP34 activated on regtest (Block at height 1 not enforced for testing purposes)
394394
consensus.BIP34Hash = uint256();
395395
consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in functional tests)
396396
consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in functional tests)

src/test/validation_block_tests.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,29 @@ std::shared_ptr<CBlock> MinerTestingSetup::Block(const uint256& prev_hash)
7777
txCoinbase.vout[1].nValue = txCoinbase.vout[0].nValue;
7878
txCoinbase.vout[0].nValue = 0;
7979
txCoinbase.vin[0].scriptWitness.SetNull();
80+
// Always pad with OP_0 at the end to avoid bad-cb-length error
81+
txCoinbase.vin[0].scriptSig = CScript{} << WITH_LOCK(::cs_main, return m_node.chainman->m_blockman.LookupBlockIndex(prev_hash)->nHeight + 1) << OP_0;
8082
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase));
8183

8284
return pblock;
8385
}
8486

8587
std::shared_ptr<CBlock> MinerTestingSetup::FinalizeBlock(std::shared_ptr<CBlock> pblock)
8688
{
87-
LOCK(cs_main); // For m_node.chainman->m_blockman.LookupBlockIndex
88-
GenerateCoinbaseCommitment(*pblock, m_node.chainman->m_blockman.LookupBlockIndex(pblock->hashPrevBlock), Params().GetConsensus());
89+
const CBlockIndex* prev_block{WITH_LOCK(::cs_main, return m_node.chainman->m_blockman.LookupBlockIndex(pblock->hashPrevBlock))};
90+
GenerateCoinbaseCommitment(*pblock, prev_block, Params().GetConsensus());
8991

9092
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
9193

9294
while (!CheckProofOfWork(pblock->GetHash(), pblock->nBits, Params().GetConsensus())) {
9395
++(pblock->nNonce);
9496
}
9597

98+
// submit block header, so that miner can get the block height from the
99+
// global state and the node has the topology of the chain
100+
BlockValidationState ignored;
101+
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlockHeaders({pblock->GetBlockHeader()}, ignored, Params()));
102+
96103
return pblock;
97104
}
98105

@@ -147,13 +154,6 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
147154
}
148155

149156
bool ignored;
150-
BlockValidationState state;
151-
std::vector<CBlockHeader> headers;
152-
std::transform(blocks.begin(), blocks.end(), std::back_inserter(headers), [](std::shared_ptr<const CBlock> b) { return b->GetBlockHeader(); });
153-
154-
// Process all the headers so we understand the toplogy of the chain
155-
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlockHeaders(headers, state, Params()));
156-
157157
// Connect the genesis block and drain any outstanding events
158158
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(Params(), std::make_shared<CBlock>(Params().GenesisBlock()), true, &ignored));
159159
SyncWithValidationInterfaceQueue();

test/functional/feature_block.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ def run_test(self):
373373
# b30 has a max-sized coinbase scriptSig.
374374
self.move_tip(23)
375375
b30 = self.next_block(30)
376-
b30.vtx[0].vin[0].scriptSig = b'\x00' * 100
376+
b30.vtx[0].vin[0].scriptSig = bytes(b30.vtx[0].vin[0].scriptSig) # Convert CScript to raw bytes
377+
b30.vtx[0].vin[0].scriptSig += b'\x00' * (100 - len(b30.vtx[0].vin[0].scriptSig)) # Fill with 0s
378+
assert_equal(len(b30.vtx[0].vin[0].scriptSig), 100)
377379
b30.vtx[0].rehash()
378380
b30 = self.update_block(30, [])
379381
self.send_blocks([b30], True)
@@ -817,6 +819,7 @@ def run_test(self):
817819
b61.vtx[0].rehash()
818820
b61 = self.update_block(61, [])
819821
assert_equal(duplicate_tx.serialize(), b61.vtx[0].serialize())
822+
# BIP30 is always checked on regtest, regardless of the BIP34 activation height
820823
self.send_blocks([b61], success=False, reject_reason='bad-txns-BIP30', reconnect=True)
821824

822825
# Test BIP30 (allow duplicate if spent)

test/functional/rpc_blockchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _test_getblockchaininfo(self):
129129
assert_greater_than(res['size_on_disk'], 0)
130130

131131
assert_equal(res['softforks'], {
132-
'bip34': {'type': 'buried', 'active': False, 'height': 500},
132+
'bip34': {'type': 'buried', 'active': True, 'height': 2},
133133
'bip66': {'type': 'buried', 'active': False, 'height': 1251},
134134
'bip65': {'type': 'buried', 'active': False, 'height': 1351},
135135
'csv': {'type': 'buried', 'active': False, 'height': 432},

0 commit comments

Comments
 (0)