diff options
author | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2020-01-16 15:00:13 +0100 |
---|---|---|
committer | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2020-01-16 15:10:28 +0100 |
commit | 4537ba5f21ad8afb705325cd8e15dd43877eb28f (patch) | |
tree | fb6cf864fca9d76d717203897b663a0735f44d99 /src/test | |
parent | 4e8b564df0d4ff2bc2463aa072b15471361d9e7d (diff) | |
download | bitcoin-4537ba5f21ad8afb705325cd8e15dd43877eb28f.tar.xz |
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).
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/transaction_tests.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index 0939803953..031f237e87 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -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)); |