@@ -765,130 +765,116 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
765
765
key.MakeNewKey (true );
766
766
t.vout [0 ].scriptPubKey = GetScriptForDestination (PKHash (key.GetPubKey ()));
767
767
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);
770
780
771
781
// Check dust with default relay fee:
772
- CAmount nDustThreshold = 182 * dustRelayFee.GetFeePerK ()/ 1000 ;
782
+ CAmount nDustThreshold = 182 * dustRelayFee.GetFeePerK () / 1000 ;
773
783
BOOST_CHECK_EQUAL (nDustThreshold, 546 );
774
784
// dust:
775
785
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" );
779
787
// not dust:
780
788
t.vout [0 ].nValue = nDustThreshold;
781
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
789
+ CheckIsStandard (t );
782
790
783
791
// Disallowed nVersion
784
792
t.nVersion = -1 ;
785
- reason.clear ();
786
- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
787
- BOOST_CHECK_EQUAL (reason, " version" );
793
+ CheckIsNotStandard (t, " version" );
788
794
789
795
t.nVersion = 0 ;
790
- reason.clear ();
791
- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
792
- BOOST_CHECK_EQUAL (reason, " version" );
796
+ CheckIsNotStandard (t, " version" );
793
797
794
798
t.nVersion = 3 ;
795
- reason.clear ();
796
- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
797
- BOOST_CHECK_EQUAL (reason, " version" );
799
+ CheckIsNotStandard (t, " version" );
798
800
799
801
// Allowed nVersion
800
802
t.nVersion = 1 ;
801
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
803
+ CheckIsStandard (t );
802
804
803
805
t.nVersion = 2 ;
804
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
806
+ CheckIsStandard (t );
805
807
806
808
// Check dust with odd relay fee to verify rounding:
807
809
// nDustThreshold = 182 * 3702 / 1000
808
810
dustRelayFee = CFeeRate (3702 );
809
811
// dust:
810
812
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" );
814
814
// not dust:
815
815
t.vout [0 ].nValue = 673 ;
816
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
816
+ CheckIsStandard (t );
817
817
dustRelayFee = CFeeRate (DUST_RELAY_TX_FEE);
818
818
819
819
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" );
823
821
824
822
// MAX_OP_RETURN_RELAY-byte TxoutType::NULL_DATA (standard)
825
823
t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << ParseHex (" 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38" );
826
824
BOOST_CHECK_EQUAL (MAX_OP_RETURN_RELAY, t.vout [0 ].scriptPubKey .size ());
827
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
825
+ CheckIsStandard (t );
828
826
829
827
// MAX_OP_RETURN_RELAY+1-byte TxoutType::NULL_DATA (non-standard)
830
828
t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << ParseHex (" 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3800" );
831
829
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" );
835
831
836
832
// Data payload can be encoded in any way...
837
833
t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << ParseHex (" " );
838
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
834
+ CheckIsStandard (t );
839
835
t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << ParseHex (" 00" ) << ParseHex (" 01" );
840
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
836
+ CheckIsStandard (t );
841
837
// OP_RESERVED *is* considered to be a PUSHDATA type opcode by IsPushOnly()!
842
838
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 );
844
840
t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << 0 << ParseHex (" 01" ) << 2 << ParseHex (" ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" );
845
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
841
+ CheckIsStandard (t );
846
842
847
843
// ...so long as it only contains PUSHDATA's
848
844
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" );
852
846
853
847
// TxoutType::NULL_DATA w/o PUSHDATA
854
848
t.vout .resize (1 );
855
849
t.vout [0 ].scriptPubKey = CScript () << OP_RETURN;
856
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
850
+ CheckIsStandard (t );
857
851
858
852
// Only one TxoutType::NULL_DATA permitted in all cases
859
853
t.vout .resize (2 );
860
854
t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << ParseHex (" 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38" );
861
855
t.vout [0 ].nValue = 0 ;
862
856
t.vout [1 ].scriptPubKey = CScript () << OP_RETURN << ParseHex (" 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38" );
863
857
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" );
867
859
868
860
t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << ParseHex (" 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38" );
869
861
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" );
873
863
874
864
t.vout [0 ].scriptPubKey = CScript () << OP_RETURN;
875
865
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" );
879
867
880
868
// Check large scriptSig (non-standard if size is >1650 bytes)
881
869
t.vout .resize (1 );
882
870
t.vout [0 ].nValue = MAX_MONEY;
883
871
t.vout [0 ].scriptPubKey = GetScriptForDestination (PKHash (key.GetPubKey ()));
884
872
// OP_PUSHDATA2 with len (3 bytes) + data (1647 bytes) = 1650 bytes
885
873
t.vin [0 ].scriptSig = CScript () << std::vector<unsigned char >(1647 , 0 ); // 1650
886
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
874
+ CheckIsStandard (t );
887
875
888
876
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" );
892
878
893
879
// Check scriptSig format (non-standard if there are any other ops than just PUSHs)
894
880
t.vin [0 ].scriptSig = CScript ()
@@ -897,7 +883,7 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
897
883
<< std::vector<unsigned char >(235 , 0 ) // OP_PUSHDATA1 x [...x bytes...]
898
884
<< std::vector<unsigned char >(1234 , 0 ) // OP_PUSHDATA2 x [...x bytes...]
899
885
<< OP_9;
900
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
886
+ CheckIsStandard (t );
901
887
902
888
const std::vector<unsigned char > non_push_ops = { // arbitrary set of non-push operations
903
889
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)
917
903
// replace current push-op with each non-push-op
918
904
for (auto op : non_push_ops) {
919
905
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" );
922
907
}
923
908
t.vin [0 ].scriptSig [index] = orig_op; // restore op
924
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
909
+ CheckIsStandard (t );
925
910
}
926
911
927
912
// Check tx-size (non-standard if transaction weight is > MAX_STANDARD_TX_WEIGHT)
@@ -934,53 +919,46 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
934
919
// ===============================
935
920
// total: 400000 vbytes
936
921
BOOST_CHECK_EQUAL (GetTransactionWeight (CTransaction (t)), 400000 );
937
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
922
+ CheckIsStandard (t );
938
923
939
924
// increase output size by one byte, so we end up with 400004 vbytes
940
925
t.vout [0 ].scriptPubKey = CScript () << OP_RETURN << std::vector<unsigned char >(20 , 0 ); // output size: 31 bytes
941
926
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" );
945
928
946
929
// Check bare multisig (standard if policy flag fIsBareMultisigStd is set)
947
930
fIsBareMultisigStd = true ;
948
931
t.vout [0 ].scriptPubKey = GetScriptForMultisig (1 , {key.GetPubKey ()}); // simple 1-of-1
949
932
t.vin .resize (1 );
950
933
t.vin [0 ].scriptSig = CScript () << std::vector<unsigned char >(65 , 0 );
951
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
934
+ CheckIsStandard (t );
952
935
953
936
fIsBareMultisigStd = false ;
954
- reason.clear ();
955
- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
956
- BOOST_CHECK_EQUAL (reason, " bare-multisig" );
937
+ CheckIsNotStandard (t, " bare-multisig" );
957
938
fIsBareMultisigStd = DEFAULT_PERMIT_BAREMULTISIG;
958
939
959
940
// Check P2WPKH outputs dust threshold
960
941
t.vout [0 ].scriptPubKey = CScript () << OP_0 << ParseHex (" ffffffffffffffffffffffffffffffffffffffff" );
961
942
t.vout [0 ].nValue = 294 ;
962
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
943
+ CheckIsStandard (t );
963
944
t.vout [0 ].nValue = 293 ;
964
- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
965
- BOOST_CHECK_EQUAL (reason, " dust" );
945
+ CheckIsNotStandard (t, " dust" );
966
946
967
947
// Check P2WSH outputs dust threshold
968
948
t.vout [0 ].scriptPubKey = CScript () << OP_0 << ParseHex (" ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" );
969
949
t.vout [0 ].nValue = 330 ;
970
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
950
+ CheckIsStandard (t );
971
951
t.vout [0 ].nValue = 329 ;
972
- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
973
- BOOST_CHECK_EQUAL (reason, " dust" );
952
+ CheckIsNotStandard (t, " dust" );
974
953
975
954
// Check future Witness Program versions dust threshold
976
955
for (int op = OP_2; op <= OP_16; op += 1 ) {
977
956
t.vout [0 ].scriptPubKey = CScript () << (opcodetype)op << ParseHex (" ffff" );
978
957
t.vout [0 ].nValue = 240 ;
979
- BOOST_CHECK ( IsStandardTx ( CTransaction (t), reason) );
958
+ CheckIsStandard (t );
980
959
981
960
t.vout [0 ].nValue = 239 ;
982
- BOOST_CHECK (!IsStandardTx (CTransaction (t), reason));
983
- BOOST_CHECK_EQUAL (reason, " dust" );
961
+ CheckIsNotStandard (t, " dust" );
984
962
}
985
963
}
986
964
0 commit comments