mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-21 14:34:49 +01:00
test: add unit test for non-standard txs with too large tx size
The function IsStandardTx() returns rejection reason "tx-size" if the transaction weight is larger than MAX_STANDARD_TX_WEIGHT (=400000 vbytes).
This commit is contained in:
parent
4e8b564df0
commit
4537ba5f21
1 changed files with 20 additions and 0 deletions
|
@ -821,9 +821,29 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
|
|||
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
|
||||
BOOST_CHECK_EQUAL(reason, "scriptsig-size");
|
||||
|
||||
// Check tx-size (non-standard if transaction weight is > MAX_STANDARD_TX_WEIGHT)
|
||||
t.vin.clear();
|
||||
t.vin.resize(2438); // size per input (empty scriptSig): 41 bytes
|
||||
t.vout[0].scriptPubKey = CScript() << OP_RETURN << std::vector<unsigned char>(19, 0); // output size: 30 bytes
|
||||
// tx header: 12 bytes => 48 vbytes
|
||||
// 2438 inputs: 2438*41 = 99958 bytes => 399832 vbytes
|
||||
// 1 output: 30 bytes => 120 vbytes
|
||||
// ===============================
|
||||
// total: 400000 vbytes
|
||||
BOOST_CHECK_EQUAL(GetTransactionWeight(CTransaction(t)), 400000);
|
||||
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
|
||||
|
||||
// increase output size by one byte, so we end up with 400004 vbytes
|
||||
t.vout[0].scriptPubKey = CScript() << OP_RETURN << std::vector<unsigned char>(20, 0); // output size: 31 bytes
|
||||
BOOST_CHECK_EQUAL(GetTransactionWeight(CTransaction(t)), 400004);
|
||||
reason.clear();
|
||||
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
|
||||
BOOST_CHECK_EQUAL(reason, "tx-size");
|
||||
|
||||
// Check bare multisig (standard if policy flag fIsBareMultisigStd is set)
|
||||
fIsBareMultisigStd = true;
|
||||
t.vout[0].scriptPubKey = GetScriptForMultisig(1, {key.GetPubKey()}); // simple 1-of-1
|
||||
t.vin.resize(1);
|
||||
t.vin[0].scriptSig = CScript() << std::vector<unsigned char>(65, 0);
|
||||
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue