Skip to content

Commit a2d908e

Browse files
committed
[test] Throw error instead of segfaulting in failure scenario
If the miner code is faulty and does not include any transactions in a block, the code segfaults when it tries to access block transactions. Instead, add a check that safely aborts the process.
1 parent 9a3bbe8 commit a2d908e

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/test/miner_tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
123123
m_node.mempool->addUnchecked(entry.Fee(50000).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
124124

125125
std::unique_ptr<CBlockTemplate> pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
126+
BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 4);
126127
BOOST_CHECK(pblocktemplate->block.vtx[1]->GetHash() == hashParentTx);
127128
BOOST_CHECK(pblocktemplate->block.vtx[2]->GetHash() == hashHighFeeTx);
128129
BOOST_CHECK(pblocktemplate->block.vtx[3]->GetHash() == hashMediumFeeTx);
@@ -157,6 +158,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
157158
hashLowFeeTx = tx.GetHash();
158159
m_node.mempool->addUnchecked(entry.Fee(feeToUse+2).FromTx(tx));
159160
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
161+
BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 6);
160162
BOOST_CHECK(pblocktemplate->block.vtx[4]->GetHash() == hashFreeTx);
161163
BOOST_CHECK(pblocktemplate->block.vtx[5]->GetHash() == hashLowFeeTx);
162164

@@ -191,6 +193,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
191193
tx.vout[0].nValue = 100000000 - 10000; // 10k satoshi fee
192194
m_node.mempool->addUnchecked(entry.Fee(10000).FromTx(tx));
193195
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
196+
BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 9);
194197
BOOST_CHECK(pblocktemplate->block.vtx[8]->GetHash() == hashLowFeeTx2);
195198
}
196199

0 commit comments

Comments
 (0)