Skip to content

Commit ecad0a8

Browse files
author
MarcoFalke
committed
Merge #17299: test: add reason checks for non-standard txs in test_IsStandard
c1c6c41 test: add reason checks for non-standard txs in test_IsStandard (Sebastian Falbesoner) Pull request description: While taking a look at #17272 I noticed that for some reason the unit test `test_IsStandard` (which was not adapted to the policy change in the referenced PR commits) didn't fail as expected: https://github.com/bitcoin/bitcoin/blob/6a97e8a060f7632bbaee27d3de8035dc6ebe3895/src/test/transaction_tests.cpp#L758-L762 It turned out that `IsStandardTx()` returned `"dust"` as rejection reason (instead of the expected `"multi-op-return"`), leading to the conclusion that bitcoin/bitcoin@5fe6f05 erroneously performs the `IsDust()` check also for TX_NULL_DATA transactions. To avoid cases like this in the future, this PR makes the unit test `test_IsStandard` more strict by also checking for the concrete reason after each occurence of `IsStandardTx()` returning false. ACKs for top commit: instagibbs: utACK bitcoin/bitcoin@c1c6c41 Tree-SHA512: c7419884cc52977c73f8f8c476eaebed80ba7bda4d03509d3f46dd977be911389f7b53daefa5ef31d2f7df9402243152e01e83f1b8a9fb300c19d1a0f69a89a9
2 parents 6a97e8a + c1c6c41 commit ecad0a8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/test/transaction_tests.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,9 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
706706
BOOST_CHECK_EQUAL(nDustThreshold, 546);
707707
// dust:
708708
t.vout[0].nValue = nDustThreshold - 1;
709+
reason.clear();
709710
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
711+
BOOST_CHECK_EQUAL(reason, "dust");
710712
// not dust:
711713
t.vout[0].nValue = nDustThreshold;
712714
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
@@ -716,14 +718,18 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
716718
dustRelayFee = CFeeRate(3702);
717719
// dust:
718720
t.vout[0].nValue = 673 - 1;
721+
reason.clear();
719722
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
723+
BOOST_CHECK_EQUAL(reason, "dust");
720724
// not dust:
721725
t.vout[0].nValue = 673;
722726
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
723727
dustRelayFee = CFeeRate(DUST_RELAY_TX_FEE);
724728

725729
t.vout[0].scriptPubKey = CScript() << OP_1;
730+
reason.clear();
726731
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
732+
BOOST_CHECK_EQUAL(reason, "scriptpubkey");
727733

728734
// MAX_OP_RETURN_RELAY-byte TX_NULL_DATA (standard)
729735
t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
@@ -733,7 +739,9 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
733739
// MAX_OP_RETURN_RELAY+1-byte TX_NULL_DATA (non-standard)
734740
t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3800");
735741
BOOST_CHECK_EQUAL(MAX_OP_RETURN_RELAY + 1, t.vout[0].scriptPubKey.size());
742+
reason.clear();
736743
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
744+
BOOST_CHECK_EQUAL(reason, "scriptpubkey");
737745

738746
// Data payload can be encoded in any way...
739747
t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("");
@@ -748,7 +756,9 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
748756

749757
// ...so long as it only contains PUSHDATA's
750758
t.vout[0].scriptPubKey = CScript() << OP_RETURN << OP_RETURN;
759+
reason.clear();
751760
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
761+
BOOST_CHECK_EQUAL(reason, "scriptpubkey");
752762

753763
// TX_NULL_DATA w/o PUSHDATA
754764
t.vout.resize(1);
@@ -759,15 +769,21 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
759769
t.vout.resize(2);
760770
t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
761771
t.vout[1].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
772+
reason.clear();
762773
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
774+
BOOST_CHECK_EQUAL(reason, "multi-op-return");
763775

764776
t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
765777
t.vout[1].scriptPubKey = CScript() << OP_RETURN;
778+
reason.clear();
766779
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
780+
BOOST_CHECK_EQUAL(reason, "multi-op-return");
767781

768782
t.vout[0].scriptPubKey = CScript() << OP_RETURN;
769783
t.vout[1].scriptPubKey = CScript() << OP_RETURN;
784+
reason.clear();
770785
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
786+
BOOST_CHECK_EQUAL(reason, "multi-op-return");
771787
}
772788

773789
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)