Skip to content

Commit 4537ba5

Browse files
committed
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).
1 parent 4e8b564 commit 4537ba5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/test/transaction_tests.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,9 +821,29 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
821821
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
822822
BOOST_CHECK_EQUAL(reason, "scriptsig-size");
823823

824+
// Check tx-size (non-standard if transaction weight is > MAX_STANDARD_TX_WEIGHT)
825+
t.vin.clear();
826+
t.vin.resize(2438); // size per input (empty scriptSig): 41 bytes
827+
t.vout[0].scriptPubKey = CScript() << OP_RETURN << std::vector<unsigned char>(19, 0); // output size: 30 bytes
828+
// tx header: 12 bytes => 48 vbytes
829+
// 2438 inputs: 2438*41 = 99958 bytes => 399832 vbytes
830+
// 1 output: 30 bytes => 120 vbytes
831+
// ===============================
832+
// total: 400000 vbytes
833+
BOOST_CHECK_EQUAL(GetTransactionWeight(CTransaction(t)), 400000);
834+
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
835+
836+
// increase output size by one byte, so we end up with 400004 vbytes
837+
t.vout[0].scriptPubKey = CScript() << OP_RETURN << std::vector<unsigned char>(20, 0); // output size: 31 bytes
838+
BOOST_CHECK_EQUAL(GetTransactionWeight(CTransaction(t)), 400004);
839+
reason.clear();
840+
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
841+
BOOST_CHECK_EQUAL(reason, "tx-size");
842+
824843
// Check bare multisig (standard if policy flag fIsBareMultisigStd is set)
825844
fIsBareMultisigStd = true;
826845
t.vout[0].scriptPubKey = GetScriptForMultisig(1, {key.GetPubKey()}); // simple 1-of-1
846+
t.vin.resize(1);
827847
t.vin[0].scriptSig = CScript() << std::vector<unsigned char>(65, 0);
828848
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
829849

0 commit comments

Comments
 (0)