mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
Validate oversized transaction
This commit is contained in:
parent
1984187840
commit
327a31d1a4
@ -378,6 +378,32 @@ BOOST_AUTO_TEST_CASE(tx_no_inputs)
|
||||
BOOST_CHECK(state.GetRejectReason() == "bad-txns-vin-empty");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(tx_oversized)
|
||||
{
|
||||
auto createTransaction =[](size_t payloadSize) {
|
||||
CMutableTransaction tx;
|
||||
tx.vin.resize(1);
|
||||
tx.vout.emplace_back(1, CScript() << OP_RETURN << std::vector<unsigned char>(payloadSize));
|
||||
return CTransaction(tx);
|
||||
};
|
||||
const auto maxTransactionSize = MAX_BLOCK_WEIGHT / WITNESS_SCALE_FACTOR;
|
||||
const auto oversizedTransactionBaseSize = ::GetSerializeSize(TX_NO_WITNESS(createTransaction(maxTransactionSize))) - maxTransactionSize;
|
||||
|
||||
auto maxPayloadSize = maxTransactionSize - oversizedTransactionBaseSize;
|
||||
{
|
||||
TxValidationState state;
|
||||
CheckTransaction(createTransaction(maxPayloadSize), state);
|
||||
BOOST_CHECK(state.GetRejectReason() != "bad-txns-oversize");
|
||||
}
|
||||
|
||||
maxPayloadSize += 1;
|
||||
{
|
||||
TxValidationState state;
|
||||
BOOST_CHECK_MESSAGE(!CheckTransaction(createTransaction(maxPayloadSize), state), "Oversized transaction should be invalid");
|
||||
BOOST_CHECK(state.GetRejectReason() == "bad-txns-oversize");
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(basic_transaction_tests)
|
||||
{
|
||||
// Random real transaction (e2769b09e784f32f62ef849763d4f45b98e07ba658647343b915ff832b110436)
|
||||
|
Loading…
Reference in New Issue
Block a user