@@ -128,85 +128,88 @@ BOOST_FIXTURE_TEST_CASE(ephemeral_tests, RegTestingSetup)
128
128
// We first start with nothing "in the mempool", using package checks
129
129
130
130
// Trivial single transaction with no dust
131
- BOOST_CHECK (!CheckEphemeralSpends ({dust_spend}, minrelay, pool). has_value () );
131
+ BOOST_CHECK (!CheckEphemeralSpends ({dust_spend}, minrelay, pool));
132
132
133
133
// Now with dust, ok because the tx has no dusty parents
134
- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1}, minrelay, pool). has_value () );
134
+ BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1}, minrelay, pool));
135
135
136
136
// Dust checks pass
137
- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, dust_spend}, CFeeRate (0 ), pool). has_value () );
138
- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, dust_spend}, minrelay, pool). has_value () );
137
+ BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, dust_spend}, CFeeRate (0 ), pool));
138
+ BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, dust_spend}, minrelay, pool));
139
139
140
140
auto dust_non_spend = make_tx ({COutPoint{dust_txid, dust_index - 1 }}, /* version=*/ 2 );
141
141
142
142
// Child spending non-dust only from parent should be disallowed even if dust otherwise spent
143
- BOOST_CHECK (CheckEphemeralSpends ({grandparent_tx_1, dust_non_spend, dust_spend}, minrelay, pool).has_value ());
144
- BOOST_CHECK (CheckEphemeralSpends ({grandparent_tx_1, dust_spend, dust_non_spend}, minrelay, pool).has_value ());
145
- BOOST_CHECK (CheckEphemeralSpends ({grandparent_tx_1, dust_non_spend}, minrelay, pool).has_value ());
143
+ const auto dust_non_spend_txid{dust_non_spend->GetHash ()};
144
+ const Txid null_txid;
145
+ assert (dust_non_spend_txid != null_txid);
146
+ BOOST_CHECK_EQUAL (CheckEphemeralSpends ({grandparent_tx_1, dust_non_spend, dust_spend}, minrelay, pool).value_or (null_txid), dust_non_spend_txid);
147
+ BOOST_CHECK_EQUAL (CheckEphemeralSpends ({grandparent_tx_1, dust_spend, dust_non_spend}, minrelay, pool).value_or (null_txid), dust_non_spend_txid);
148
+ BOOST_CHECK_EQUAL (CheckEphemeralSpends ({grandparent_tx_1, dust_non_spend}, minrelay, pool).value_or (null_txid), dust_non_spend_txid);
146
149
147
150
auto grandparent_tx_2 = make_ephemeral_tx (random_outpoints (1 ), /* version=*/ 2 );
148
151
const auto dust_txid_2 = grandparent_tx_2->GetHash ();
149
152
150
153
// Spend dust from one but not another is ok, as long as second grandparent has no child
151
- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, dust_spend}, minrelay, pool). has_value () );
154
+ BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, dust_spend}, minrelay, pool));
152
155
153
156
auto dust_non_spend_both_parents = make_tx ({COutPoint{dust_txid, dust_index}, COutPoint{dust_txid_2, dust_index - 1 }}, /* version=*/ 2 );
154
157
// But if we spend from the parent, it must spend dust
155
- BOOST_CHECK (CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, dust_non_spend_both_parents}, minrelay, pool).has_value ());
158
+ 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 ());
156
159
157
160
auto dust_spend_both_parents = make_tx ({COutPoint{dust_txid, dust_index}, COutPoint{dust_txid_2, dust_index}}, /* version=*/ 2 );
158
- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, dust_spend_both_parents}, minrelay, pool). has_value () );
161
+ BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, dust_spend_both_parents}, minrelay, pool));
159
162
160
163
// Spending other outputs is also correct, as long as the dusty one is spent
161
164
const std::vector<COutPoint> all_outpoints{COutPoint (dust_txid, 0 ), COutPoint (dust_txid, 1 ), COutPoint (dust_txid, 2 ),
162
165
COutPoint (dust_txid_2, 0 ), COutPoint (dust_txid_2, 1 ), COutPoint (dust_txid_2, 2 )};
163
166
auto dust_spend_all_outpoints = make_tx (all_outpoints, /* version=*/ 2 );
164
- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, dust_spend_all_outpoints}, minrelay, pool). has_value () );
167
+ BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, dust_spend_all_outpoints}, minrelay, pool));
165
168
166
169
// 2 grandparents with dust <- 1 dust-spending parent with dust <- child with no dust
167
170
auto parent_with_dust = make_ephemeral_tx ({COutPoint{dust_txid, dust_index}, COutPoint{dust_txid_2, dust_index}}, /* version=*/ 2 );
168
171
// Ok for parent to have dust
169
- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, parent_with_dust}, minrelay, pool). has_value () );
172
+ BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, parent_with_dust}, minrelay, pool));
170
173
auto child_no_dust = make_tx ({COutPoint{parent_with_dust->GetHash (), dust_index}}, /* version=*/ 2 );
171
- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, parent_with_dust, child_no_dust}, minrelay, pool). has_value () );
174
+ BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, parent_with_dust, child_no_dust}, minrelay, pool));
172
175
173
176
// 2 grandparents with dust <- 1 dust-spending parent with dust <- child with dust
174
177
auto child_with_dust = make_ephemeral_tx ({COutPoint{parent_with_dust->GetHash (), dust_index}}, /* version=*/ 2 );
175
- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, parent_with_dust, child_with_dust}, minrelay, pool). has_value () );
178
+ BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, parent_with_dust, child_with_dust}, minrelay, pool));
176
179
177
180
// Tests with parents in mempool
178
181
179
182
// Nothing in mempool, this should pass for any transaction
180
- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1}, minrelay, pool). has_value () );
183
+ BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1}, minrelay, pool));
181
184
182
185
// Add first grandparent to mempool and fetch entry
183
186
pool.addUnchecked (entry.FromTx (grandparent_tx_1));
184
187
185
188
// Ignores ancestors that aren't direct parents
186
- BOOST_CHECK (!CheckEphemeralSpends ({child_no_dust}, minrelay, pool). has_value () );
189
+ BOOST_CHECK (!CheckEphemeralSpends ({child_no_dust}, minrelay, pool));
187
190
188
191
// Valid spend of dust with grandparent in mempool
189
- BOOST_CHECK (!CheckEphemeralSpends ({parent_with_dust}, minrelay, pool). has_value () );
192
+ BOOST_CHECK (!CheckEphemeralSpends ({parent_with_dust}, minrelay, pool));
190
193
191
194
// Second grandparent in same package
192
- BOOST_CHECK (!CheckEphemeralSpends ({parent_with_dust, grandparent_tx_2}, minrelay, pool). has_value () );
195
+ BOOST_CHECK (!CheckEphemeralSpends ({parent_with_dust, grandparent_tx_2}, minrelay, pool));
193
196
// Order in package doesn't matter
194
- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_2, parent_with_dust}, minrelay, pool). has_value () );
197
+ BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_2, parent_with_dust}, minrelay, pool));
195
198
196
199
// Add second grandparent to mempool
197
200
pool.addUnchecked (entry.FromTx (grandparent_tx_2));
198
201
199
202
// Only spends single dust out of two direct parents
200
- BOOST_CHECK (CheckEphemeralSpends ({dust_non_spend_both_parents}, minrelay, pool).has_value ());
203
+ BOOST_CHECK_EQUAL (CheckEphemeralSpends ({dust_non_spend_both_parents}, minrelay, pool).value_or (null_txid), dust_non_spend_both_parents-> GetHash ());
201
204
202
205
// Spends both parents' dust
203
- BOOST_CHECK (!CheckEphemeralSpends ({parent_with_dust}, minrelay, pool). has_value () );
206
+ BOOST_CHECK (!CheckEphemeralSpends ({parent_with_dust}, minrelay, pool));
204
207
205
208
// Now add dusty parent to mempool
206
209
pool.addUnchecked (entry.FromTx (parent_with_dust));
207
210
208
211
// Passes dust checks even with non-parent ancestors
209
- BOOST_CHECK (!CheckEphemeralSpends ({child_no_dust}, minrelay, pool). has_value () );
212
+ BOOST_CHECK (!CheckEphemeralSpends ({child_no_dust}, minrelay, pool));
210
213
}
211
214
212
215
BOOST_FIXTURE_TEST_CASE (version3_tests, RegTestingSetup)
0 commit comments