Skip to content

Commit 8424290

Browse files
committed
unit test: ephemeral_tests is using a dust relay rate, not minrelay
1 parent d9cfa5f commit 8424290

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/test/txvalidation_tests.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ BOOST_FIXTURE_TEST_CASE(ephemeral_tests, RegTestingSetup)
117117
TestMemPoolEntryHelper entry;
118118
CTxMemPool::setEntries empty_ancestors;
119119

120-
CFeeRate minrelay(1000);
120+
// Arbitrary non-0 feerate for these tests
121+
CFeeRate dustrelay(DUST_RELAY_TX_FEE);
121122

122123
// Basic transaction with dust
123124
auto grandparent_tx_1 = make_ephemeral_tx(random_outpoints(1), /*version=*/2);
@@ -129,88 +130,88 @@ BOOST_FIXTURE_TEST_CASE(ephemeral_tests, RegTestingSetup)
129130
// We first start with nothing "in the mempool", using package checks
130131

131132
// Trivial single transaction with no dust
132-
BOOST_CHECK(!CheckEphemeralSpends({dust_spend}, minrelay, pool));
133+
BOOST_CHECK(!CheckEphemeralSpends({dust_spend}, dustrelay, pool));
133134

134135
// Now with dust, ok because the tx has no dusty parents
135-
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1}, minrelay, pool));
136+
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1}, dustrelay, pool));
136137

137138
// Dust checks pass
138139
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, dust_spend}, CFeeRate(0), pool));
139-
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, dust_spend}, minrelay, pool));
140+
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, dust_spend}, dustrelay, pool));
140141

141142
auto dust_non_spend = make_tx({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX - 1}}, /*version=*/2);
142143

143144
// Child spending non-dust only from parent should be disallowed even if dust otherwise spent
144145
const auto dust_non_spend_txid{dust_non_spend->GetHash()};
145146
const Txid null_txid;
146147
assert(dust_non_spend_txid != null_txid);
147-
BOOST_CHECK_EQUAL(CheckEphemeralSpends({grandparent_tx_1, dust_non_spend, dust_spend}, minrelay, pool).value_or(null_txid), dust_non_spend_txid);
148-
BOOST_CHECK_EQUAL(CheckEphemeralSpends({grandparent_tx_1, dust_spend, dust_non_spend}, minrelay, pool).value_or(null_txid), dust_non_spend_txid);
149-
BOOST_CHECK_EQUAL(CheckEphemeralSpends({grandparent_tx_1, dust_non_spend}, minrelay, pool).value_or(null_txid), dust_non_spend_txid);
148+
BOOST_CHECK_EQUAL(CheckEphemeralSpends({grandparent_tx_1, dust_non_spend, dust_spend}, dustrelay, pool).value_or(null_txid), dust_non_spend_txid);
149+
BOOST_CHECK_EQUAL(CheckEphemeralSpends({grandparent_tx_1, dust_spend, dust_non_spend}, dustrelay, pool).value_or(null_txid), dust_non_spend_txid);
150+
BOOST_CHECK_EQUAL(CheckEphemeralSpends({grandparent_tx_1, dust_non_spend}, dustrelay, pool).value_or(null_txid), dust_non_spend_txid);
150151

151152
auto grandparent_tx_2 = make_ephemeral_tx(random_outpoints(1), /*version=*/2);
152153
const auto dust_txid_2 = grandparent_tx_2->GetHash();
153154

154155
// Spend dust from one but not another is ok, as long as second grandparent has no child
155-
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, dust_spend}, minrelay, pool));
156+
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, dust_spend}, dustrelay, pool));
156157

157158
auto dust_non_spend_both_parents = make_tx({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX}, COutPoint{dust_txid_2, EPHEMERAL_DUST_INDEX - 1}}, /*version=*/2);
158159
// But if we spend from the parent, it must spend dust
159-
BOOST_CHECK_EQUAL(CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, dust_non_spend_both_parents}, minrelay, pool).value_or(null_txid), dust_non_spend_both_parents->GetHash());
160+
BOOST_CHECK_EQUAL(CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, dust_non_spend_both_parents}, dustrelay, pool).value_or(null_txid), dust_non_spend_both_parents->GetHash());
160161

161162
auto dust_spend_both_parents = make_tx({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX}, COutPoint{dust_txid_2, EPHEMERAL_DUST_INDEX}}, /*version=*/2);
162-
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, dust_spend_both_parents}, minrelay, pool));
163+
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, dust_spend_both_parents}, dustrelay, pool));
163164

164165
// Spending other outputs is also correct, as long as the dusty one is spent
165166
const std::vector<COutPoint> all_outpoints{COutPoint(dust_txid, 0), COutPoint(dust_txid, 1), COutPoint(dust_txid, 2),
166167
COutPoint(dust_txid_2, 0), COutPoint(dust_txid_2, 1), COutPoint(dust_txid_2, 2)};
167168
auto dust_spend_all_outpoints = make_tx(all_outpoints, /*version=*/2);
168-
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, dust_spend_all_outpoints}, minrelay, pool));
169+
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, dust_spend_all_outpoints}, dustrelay, pool));
169170

170171
// 2 grandparents with dust <- 1 dust-spending parent with dust <- child with no dust
171172
auto parent_with_dust = make_ephemeral_tx({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX}, COutPoint{dust_txid_2, EPHEMERAL_DUST_INDEX}}, /*version=*/2);
172173
// Ok for parent to have dust
173-
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, parent_with_dust}, minrelay, pool));
174+
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, parent_with_dust}, dustrelay, pool));
174175
auto child_no_dust = make_tx({COutPoint{parent_with_dust->GetHash(), EPHEMERAL_DUST_INDEX}}, /*version=*/2);
175-
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, parent_with_dust, child_no_dust}, minrelay, pool));
176+
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, parent_with_dust, child_no_dust}, dustrelay, pool));
176177

177178
// 2 grandparents with dust <- 1 dust-spending parent with dust <- child with dust
178179
auto child_with_dust = make_ephemeral_tx({COutPoint{parent_with_dust->GetHash(), EPHEMERAL_DUST_INDEX}}, /*version=*/2);
179-
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, parent_with_dust, child_with_dust}, minrelay, pool));
180+
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, parent_with_dust, child_with_dust}, dustrelay, pool));
180181

181182
// Tests with parents in mempool
182183

183184
// Nothing in mempool, this should pass for any transaction
184-
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1}, minrelay, pool));
185+
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1}, dustrelay, pool));
185186

186187
// Add first grandparent to mempool and fetch entry
187188
pool.addUnchecked(entry.FromTx(grandparent_tx_1));
188189

189190
// Ignores ancestors that aren't direct parents
190-
BOOST_CHECK(!CheckEphemeralSpends({child_no_dust}, minrelay, pool));
191+
BOOST_CHECK(!CheckEphemeralSpends({child_no_dust}, dustrelay, pool));
191192

192193
// Valid spend of dust with grandparent in mempool
193-
BOOST_CHECK(!CheckEphemeralSpends({parent_with_dust}, minrelay, pool));
194+
BOOST_CHECK(!CheckEphemeralSpends({parent_with_dust}, dustrelay, pool));
194195

195196
// Second grandparent in same package
196-
BOOST_CHECK(!CheckEphemeralSpends({parent_with_dust, grandparent_tx_2}, minrelay, pool));
197+
BOOST_CHECK(!CheckEphemeralSpends({parent_with_dust, grandparent_tx_2}, dustrelay, pool));
197198
// Order in package doesn't matter
198-
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_2, parent_with_dust}, minrelay, pool));
199+
BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_2, parent_with_dust}, dustrelay, pool));
199200

200201
// Add second grandparent to mempool
201202
pool.addUnchecked(entry.FromTx(grandparent_tx_2));
202203

203204
// Only spends single dust out of two direct parents
204-
BOOST_CHECK_EQUAL(CheckEphemeralSpends({dust_non_spend_both_parents}, minrelay, pool).value_or(null_txid), dust_non_spend_both_parents->GetHash());
205+
BOOST_CHECK_EQUAL(CheckEphemeralSpends({dust_non_spend_both_parents}, dustrelay, pool).value_or(null_txid), dust_non_spend_both_parents->GetHash());
205206

206207
// Spends both parents' dust
207-
BOOST_CHECK(!CheckEphemeralSpends({parent_with_dust}, minrelay, pool));
208+
BOOST_CHECK(!CheckEphemeralSpends({parent_with_dust}, dustrelay, pool));
208209

209210
// Now add dusty parent to mempool
210211
pool.addUnchecked(entry.FromTx(parent_with_dust));
211212

212213
// Passes dust checks even with non-parent ancestors
213-
BOOST_CHECK(!CheckEphemeralSpends({child_no_dust}, minrelay, pool));
214+
BOOST_CHECK(!CheckEphemeralSpends({child_no_dust}, dustrelay, pool));
214215
}
215216

216217
BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup)

0 commit comments

Comments
 (0)