Skip to content

Commit ceb3d45

Browse files
committed
Merge #17947: test: add unit test for non-standard txs with too large tx size
4537ba5 test: add unit test for non-standard txs with too large tx size (Sebastian Falbesoner) Pull request description: Approaches another missing unit test of issue #17394: Checks that the function `IsStandardTx()` returns rejection reason `"tx-size"` if the transaction weight is larger than `MAX_STANDARD_TX_WEIGHT` (=400000 vbytes). ACKs for top commit: Empact: Code Review ACK bitcoin/bitcoin@4537ba5 instagibbs: ACK bitcoin/bitcoin@4537ba5 Tree-SHA512: ab32e3e47e0b337253aef3da9b7c97d01f4130d00d5860588dfed02114eec3ba49473acc6419448affd63e883fd827bf308716965606eaddee242c4c5a4eb799
2 parents 4c25787 + 4537ba5 commit ceb3d45

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)