@@ -667,6 +667,45 @@ BOOST_AUTO_TEST_CASE(test_witness)
667667 CheckWithFlag (output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true );
668668}
669669
670+ BOOST_AUTO_TEST_CASE (test_tx_sizelimits)
671+ {
672+ CBasicKeyStore keystore;
673+ CCoinsView coinsDummy;
674+ CCoinsViewCache coins (&coinsDummy);
675+ std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs (keystore, coins);
676+
677+ CMutableTransaction tx;
678+ tx.nVersion = 1 ;
679+ tx.vin .resize (1 );
680+ tx.vin [0 ].prevout .hash = dummyTransactions[0 ].GetHash ();
681+ tx.vin [0 ].prevout .n = 0 ;
682+ tx.vout .resize (1 );
683+ tx.vout [0 ].nValue = 1 ;
684+ tx.vout [0 ].scriptPubKey = CScript ();
685+
686+ size_t sersizeTx = ::GetSerializeSize (tx, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
687+
688+ BOOST_CHECK (sersizeTx <= MAX_TX_BASE_SIZE);
689+
690+ CValidationState state;
691+ BOOST_CHECK_MESSAGE (CheckTransaction (tx, state) && state.IsValid (), " Simple transaction should be valid." );
692+
693+ const size_t nTestOutputs = 125000 ;
694+ tx.vout .resize (nTestOutputs);
695+
696+ for (size_t i = 0 ; i < nTestOutputs; i++) {
697+ tx.vout [i].nValue = 1 ;
698+ tx.vout [i].scriptPubKey = CScript ();
699+ }
700+
701+ sersizeTx = ::GetSerializeSize (tx, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
702+
703+ BOOST_CHECK (sersizeTx > MAX_TX_BASE_SIZE);
704+
705+ BOOST_CHECK_MESSAGE (!CheckTransaction (tx, state) || !state.IsValid (), " Large transaction should be invalid." );
706+
707+ }
708+
670709BOOST_AUTO_TEST_CASE (test_IsStandard)
671710{
672711 LOCK (cs_main);
0 commit comments