Skip to content

Commit b093f56

Browse files
committed
Fill out dust limit unit test for known types except bare multisig
1 parent 329d7e3 commit b093f56

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

src/test/transaction_tests.cpp

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -937,23 +937,58 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
937937
CheckIsNotStandard(t, "bare-multisig");
938938
g_bare_multi = DEFAULT_PERMIT_BAREMULTISIG;
939939

940+
// Check compressed P2PK outputs dust threshold (must have leading 02 or 03)
941+
t.vout[0].scriptPubKey = CScript() << std::vector<unsigned char>(33, 0x02) << OP_CHECKSIG;
942+
t.vout[0].nValue = 576;
943+
CheckIsStandard(t);
944+
t.vout[0].nValue = 575;
945+
CheckIsNotStandard(t, "dust");
946+
947+
// Check uncompressed P2PK outputs dust threshold (must have leading 04/06/07)
948+
t.vout[0].scriptPubKey = CScript() << std::vector<unsigned char>(65, 0x04) << OP_CHECKSIG;
949+
t.vout[0].nValue = 672;
950+
CheckIsStandard(t);
951+
t.vout[0].nValue = 671;
952+
CheckIsNotStandard(t, "dust");
953+
954+
// Check P2PKH outputs dust threshold
955+
t.vout[0].scriptPubKey = CScript() << OP_DUP << OP_HASH160 << std::vector<unsigned char>(20, 0) << OP_EQUALVERIFY << OP_CHECKSIG;
956+
t.vout[0].nValue = 546;
957+
CheckIsStandard(t);
958+
t.vout[0].nValue = 545;
959+
CheckIsNotStandard(t, "dust");
960+
961+
// Check P2SH outputs dust threshold
962+
t.vout[0].scriptPubKey = CScript() << OP_HASH160 << std::vector<unsigned char>(20, 0) << OP_EQUAL;
963+
t.vout[0].nValue = 540;
964+
CheckIsStandard(t);
965+
t.vout[0].nValue = 539;
966+
CheckIsNotStandard(t, "dust");
967+
940968
// Check P2WPKH outputs dust threshold
941-
t.vout[0].scriptPubKey = CScript() << OP_0 << ParseHex("ffffffffffffffffffffffffffffffffffffffff");
969+
t.vout[0].scriptPubKey = CScript() << OP_0 << std::vector<unsigned char>(20, 0);
942970
t.vout[0].nValue = 294;
943971
CheckIsStandard(t);
944972
t.vout[0].nValue = 293;
945973
CheckIsNotStandard(t, "dust");
946974

947975
// Check P2WSH outputs dust threshold
948-
t.vout[0].scriptPubKey = CScript() << OP_0 << ParseHex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
976+
t.vout[0].scriptPubKey = CScript() << OP_0 << std::vector<unsigned char>(32, 0);
977+
t.vout[0].nValue = 330;
978+
CheckIsStandard(t);
979+
t.vout[0].nValue = 329;
980+
CheckIsNotStandard(t, "dust");
981+
982+
// Check P2TR outputs dust threshold (Invalid xonly key ok!)
983+
t.vout[0].scriptPubKey = CScript() << OP_1 << std::vector<unsigned char>(32, 0);
949984
t.vout[0].nValue = 330;
950985
CheckIsStandard(t);
951986
t.vout[0].nValue = 329;
952987
CheckIsNotStandard(t, "dust");
953988

954-
// Check future Witness Program versions dust threshold
955-
for (int op = OP_2; op <= OP_16; op += 1) {
956-
t.vout[0].scriptPubKey = CScript() << (opcodetype)op << ParseHex("ffff");
989+
// Check future Witness Program versions dust threshold (non-32-byte pushes are undefined for version 1)
990+
for (int op = OP_1; op <= OP_16; op += 1) {
991+
t.vout[0].scriptPubKey = CScript() << (opcodetype)op << std::vector<unsigned char>(2, 0);
957992
t.vout[0].nValue = 240;
958993
CheckIsStandard(t);
959994

0 commit comments

Comments
 (0)