From 5f46a7d0689ff1457b016fdf0de89e5153058864 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 13 Oct 2015 19:23:11 +0200 Subject: [PATCH] transaction_tests: Be more strict checking dust * Don't allow off-by-one or more * Make clear dust is coupled with minRelayTxFee * Check rounding for odd values --- src/primitives/transaction.h | 4 ++-- src/test/transaction_tests.cpp | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 2a457cdae..98882d315 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -143,8 +143,8 @@ public: // to spend something, then we consider it dust. // A typical spendable txout is 34 bytes big, and will // need a CTxIn of at least 148 bytes to spend: - // so dust is a spendable txout less than 546 satoshis - // with default minRelayTxFee. + // so dust is a spendable txout less than + // 546*minRelayTxFee/1000 (in satoshis) if (scriptPubKey.IsUnspendable()) return 0; diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index f9423bc0d..c840f4c9f 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -342,12 +342,27 @@ BOOST_AUTO_TEST_CASE(test_IsStandard) string reason; BOOST_CHECK(IsStandardTx(t, reason)); - t.vout[0].nValue = 501; // dust + // Check dust with default relay fee: + CAmount nDustThreshold = 182 * minRelayTxFee.GetFeePerK()/1000 * 3; + BOOST_CHECK_EQUAL(nDustThreshold, 546); + // dust: + t.vout[0].nValue = nDustThreshold - 1; BOOST_CHECK(!IsStandardTx(t, reason)); - - t.vout[0].nValue = 2730; // not dust + // not dust: + t.vout[0].nValue = nDustThreshold; BOOST_CHECK(IsStandardTx(t, reason)); + // Check dust with odd relay fee to verify rounding: + // nDustThreshold = 182 * 1234 / 1000 * 3 + minRelayTxFee = CFeeRate(1234); + // dust: + t.vout[0].nValue = 672 - 1; + BOOST_CHECK(!IsStandardTx(t, reason)); + // not dust: + t.vout[0].nValue = 672; + BOOST_CHECK(IsStandardTx(t, reason)); + minRelayTxFee = CFeeRate(1000); + t.vout[0].scriptPubKey = CScript() << OP_1; BOOST_CHECK(!IsStandardTx(t, reason));