@@ -765,130 +765,116 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
765765 key.MakeNewKey (true );
766766 t.vout [0 ].scriptPubKey = GetScriptForDestination (PKHash (key.GetPubKey ()));
767767
768- std::string reason;
769- BOOST_CHECK (IsStandardTx (CTransaction (t), reason));
768+ constexpr auto CheckIsStandard = [](const auto & t) {
769+ std::string reason;
770+ BOOST_CHECK (IsStandardTx (CTransaction (t), reason));
771+ BOOST_CHECK (reason.empty ());
772+ };
773+ constexpr auto CheckIsNotStandard = [](const auto & t, const std::string& reason_in) {
774+ std::string reason;
775+ BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
776+ BOOST_CHECK_EQUAL (reason_in, reason);
777+ };
778+
779+ CheckIsStandard (t);
770780
771781 // Check dust with default relay fee:
772- CAmount nDustThreshold = 182 * dustRelayFee.GetFeePerK ()/ 1000 ;
782+ CAmount nDustThreshold = 182 * dustRelayFee.GetFeePerK () / 1000 ;
773783 BOOST_CHECK_EQUAL (nDustThreshold, 546 );
774784 // dust:
775785 t.vout [0 ].nValue = nDustThreshold - 1 ;
776- reason.clear ();
777- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
778- BOOST_CHECK_EQUAL (reason, " dust" );
786+ CheckIsNotStandard (t, " dust" );
779787 // not dust:
780788 t.vout [0 ].nValue = nDustThreshold;
781- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
789+ CheckIsStandard (t );
782790
783791 // Disallowed nVersion
784792 t.nVersion = -1 ;
785- reason.clear ();
786- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
787- BOOST_CHECK_EQUAL (reason, " version" );
793+ CheckIsNotStandard (t, " version" );
788794
789795 t.nVersion = 0 ;
790- reason.clear ();
791- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
792- BOOST_CHECK_EQUAL (reason, " version" );
796+ CheckIsNotStandard (t, " version" );
793797
794798 t.nVersion = 3 ;
795- reason.clear ();
796- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
797- BOOST_CHECK_EQUAL (reason, " version" );
799+ CheckIsNotStandard (t, " version" );
798800
799801 // Allowed nVersion
800802 t.nVersion = 1 ;
801- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
803+ CheckIsStandard (t );
802804
803805 t.nVersion = 2 ;
804- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
806+ CheckIsStandard (t );
805807
806808 // Check dust with odd relay fee to verify rounding:
807809 // nDustThreshold = 182 * 3702 / 1000
808810 dustRelayFee = CFeeRate (3702 );
809811 // dust:
810812 t.vout [0 ].nValue = 673 - 1 ;
811- reason.clear ();
812- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
813- BOOST_CHECK_EQUAL (reason, " dust" );
813+ CheckIsNotStandard (t, " dust" );
814814 // not dust:
815815 t.vout [0 ].nValue = 673 ;
816- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
816+ CheckIsStandard (t );
817817 dustRelayFee = CFeeRate (DUST_RELAY_TX_FEE);
818818
819819 t.vout [0 ].scriptPubKey = CScript () << OP_1;
820- reason.clear ();
821- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
822- BOOST_CHECK_EQUAL (reason, " scriptpubkey" );
820+ CheckIsNotStandard (t, " scriptpubkey" );
823821
824822 // MAX_OP_RETURN_RELAY-byte TxoutType::NULL_DATA (standard)
825823 t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << ParseHex (" 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38" );
826824 BOOST_CHECK_EQUAL (MAX_OP_RETURN_RELAY, t.vout [0 ].scriptPubKey .size ());
827- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
825+ CheckIsStandard (t );
828826
829827 // MAX_OP_RETURN_RELAY+1-byte TxoutType::NULL_DATA (non-standard)
830828 t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << ParseHex (" 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3800" );
831829 BOOST_CHECK_EQUAL (MAX_OP_RETURN_RELAY + 1 , t.vout [0 ].scriptPubKey .size ());
832- reason.clear ();
833- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
834- BOOST_CHECK_EQUAL (reason, " scriptpubkey" );
830+ CheckIsNotStandard (t, " scriptpubkey" );
835831
836832 // Data payload can be encoded in any way...
837833 t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << ParseHex (" " );
838- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
834+ CheckIsStandard (t );
839835 t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << ParseHex (" 00" ) << ParseHex (" 01" );
840- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
836+ CheckIsStandard (t );
841837 // OP_RESERVED *is* considered to be a PUSHDATA type opcode by IsPushOnly()!
842838 t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << OP_RESERVED << -1 << 0 << ParseHex (" 01" ) << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 ;
843- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
839+ CheckIsStandard (t );
844840 t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << 0 << ParseHex (" 01" ) << 2 << ParseHex (" ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" );
845- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
841+ CheckIsStandard (t );
846842
847843 // ...so long as it only contains PUSHDATA's
848844 t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << OP_RETURN;
849- reason.clear ();
850- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
851- BOOST_CHECK_EQUAL (reason, " scriptpubkey" );
845+ CheckIsNotStandard (t, " scriptpubkey" );
852846
853847 // TxoutType::NULL_DATA w/o PUSHDATA
854848 t.vout .resize (1 );
855849 t.vout [0 ].scriptPubKey = CScript () << OP_RETURN;
856- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
850+ CheckIsStandard (t );
857851
858852 // Only one TxoutType::NULL_DATA permitted in all cases
859853 t.vout .resize (2 );
860854 t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << ParseHex (" 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38" );
861855 t.vout [0 ].nValue = 0 ;
862856 t.vout [1 ].scriptPubKey = CScript () << OP_RETURN << ParseHex (" 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38" );
863857 t.vout [1 ].nValue = 0 ;
864- reason.clear ();
865- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
866- BOOST_CHECK_EQUAL (reason, " multi-op-return" );
858+ CheckIsNotStandard (t, " multi-op-return" );
867859
868860 t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << ParseHex (" 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38" );
869861 t.vout [1 ].scriptPubKey = CScript () << OP_RETURN;
870- reason.clear ();
871- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
872- BOOST_CHECK_EQUAL (reason, " multi-op-return" );
862+ CheckIsNotStandard (t, " multi-op-return" );
873863
874864 t.vout [0 ].scriptPubKey = CScript () << OP_RETURN;
875865 t.vout [1 ].scriptPubKey = CScript () << OP_RETURN;
876- reason.clear ();
877- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
878- BOOST_CHECK_EQUAL (reason, " multi-op-return" );
866+ CheckIsNotStandard (t, " multi-op-return" );
879867
880868 // Check large scriptSig (non-standard if size is >1650 bytes)
881869 t.vout .resize (1 );
882870 t.vout [0 ].nValue = MAX_MONEY;
883871 t.vout [0 ].scriptPubKey = GetScriptForDestination (PKHash (key.GetPubKey ()));
884872 // OP_PUSHDATA2 with len (3 bytes) + data (1647 bytes) = 1650 bytes
885873 t.vin [0 ].scriptSig = CScript () << std::vector<unsigned char >(1647 , 0 ); // 1650
886- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
874+ CheckIsStandard (t );
887875
888876 t.vin [0 ].scriptSig = CScript () << std::vector<unsigned char >(1648 , 0 ); // 1651
889- reason.clear ();
890- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
891- BOOST_CHECK_EQUAL (reason, " scriptsig-size" );
877+ CheckIsNotStandard (t, " scriptsig-size" );
892878
893879 // Check scriptSig format (non-standard if there are any other ops than just PUSHs)
894880 t.vin [0 ].scriptSig = CScript ()
@@ -897,7 +883,7 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
897883 << std::vector<unsigned char >(235 , 0 ) // OP_PUSHDATA1 x [...x bytes...]
898884 << std::vector<unsigned char >(1234 , 0 ) // OP_PUSHDATA2 x [...x bytes...]
899885 << OP_9;
900- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
886+ CheckIsStandard (t );
901887
902888 const std::vector<unsigned char > non_push_ops = { // arbitrary set of non-push operations
903889 OP_NOP, OP_VERIFY, OP_IF, OP_ROT, OP_3DUP, OP_SIZE, OP_EQUAL, OP_ADD, OP_SUB,
@@ -917,11 +903,10 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
917903 // replace current push-op with each non-push-op
918904 for (auto op : non_push_ops) {
919905 t.vin [0 ].scriptSig [index] = op;
920- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
921- BOOST_CHECK_EQUAL (reason, " scriptsig-not-pushonly" );
906+ CheckIsNotStandard (t, " scriptsig-not-pushonly" );
922907 }
923908 t.vin [0 ].scriptSig [index] = orig_op; // restore op
924- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
909+ CheckIsStandard (t );
925910 }
926911
927912 // Check tx-size (non-standard if transaction weight is > MAX_STANDARD_TX_WEIGHT)
@@ -934,53 +919,46 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
934919 // ===============================
935920 // total: 400000 vbytes
936921 BOOST_CHECK_EQUAL (GetTransactionWeight (CTransaction (t)), 400000 );
937- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
922+ CheckIsStandard (t );
938923
939924 // increase output size by one byte, so we end up with 400004 vbytes
940925 t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << std::vector<unsigned char >(20 , 0 ); // output size: 31 bytes
941926 BOOST_CHECK_EQUAL (GetTransactionWeight (CTransaction (t)), 400004 );
942- reason.clear ();
943- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
944- BOOST_CHECK_EQUAL (reason, " tx-size" );
927+ CheckIsNotStandard (t, " tx-size" );
945928
946929 // Check bare multisig (standard if policy flag fIsBareMultisigStd is set)
947930 fIsBareMultisigStd = true ;
948931 t.vout [0 ].scriptPubKey = GetScriptForMultisig (1 , {key.GetPubKey ()}); // simple 1-of-1
949932 t.vin .resize (1 );
950933 t.vin [0 ].scriptSig = CScript () << std::vector<unsigned char >(65 , 0 );
951- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
934+ CheckIsStandard (t );
952935
953936 fIsBareMultisigStd = false ;
954- reason.clear ();
955- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
956- BOOST_CHECK_EQUAL (reason, " bare-multisig" );
937+ CheckIsNotStandard (t, " bare-multisig" );
957938 fIsBareMultisigStd = DEFAULT_PERMIT_BAREMULTISIG;
958939
959940 // Check P2WPKH outputs dust threshold
960941 t.vout [0 ].scriptPubKey = CScript () << OP_0 << ParseHex (" ffffffffffffffffffffffffffffffffffffffff" );
961942 t.vout [0 ].nValue = 294 ;
962- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
943+ CheckIsStandard (t );
963944 t.vout [0 ].nValue = 293 ;
964- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
965- BOOST_CHECK_EQUAL (reason, " dust" );
945+ CheckIsNotStandard (t, " dust" );
966946
967947 // Check P2WSH outputs dust threshold
968948 t.vout [0 ].scriptPubKey = CScript () << OP_0 << ParseHex (" ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" );
969949 t.vout [0 ].nValue = 330 ;
970- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
950+ CheckIsStandard (t );
971951 t.vout [0 ].nValue = 329 ;
972- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
973- BOOST_CHECK_EQUAL (reason, " dust" );
952+ CheckIsNotStandard (t, " dust" );
974953
975954 // Check future Witness Program versions dust threshold
976955 for (int op = OP_2; op <= OP_16; op += 1 ) {
977956 t.vout [0 ].scriptPubKey = CScript () << (opcodetype)op << ParseHex (" ffff" );
978957 t.vout [0 ].nValue = 240 ;
979- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
958+ CheckIsStandard (t );
980959
981960 t.vout [0 ].nValue = 239 ;
982- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
983- BOOST_CHECK_EQUAL (reason, " dust" );
961+ CheckIsNotStandard (t, " dust" );
984962 }
985963}
986964
0 commit comments