v29.4-roots.3 · Commit 25: [PATCH 25/30] feat(wallet): expose advanced coin control facts
src/wallet/test/spend_tests.cpp
Before: src/wallet/test/spend_tests.cpp · After: src/wallet/test/spend_tests.cpp
File metadata
index e28272a201d6881216dc990f082b5d191342ee38..b0ffdcc26c42bd1d3d09990b3c18f4c44b296d16 100644
Download original patch · Release notes
Diff rows 1–58 of 58. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
src/wallet/test/spend_tests.cpp
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
#include <policy/policy.h>
|
|
9
9
|
#include <random.h>
|
|
10
10
|
#include <script/solver.h>
|
|
11
|
+
#include <util/rbf.h>
|
|
11
12
|
#include <validation.h>
|
|
12
13
|
#include <wallet/coincontrol.h>
|
|
13
14
|
#include <wallet/fees.h>
|
|
@@ -15,6 +16,8 @@
|
|
|
15
16
|
#include <wallet/test/util.h>
|
|
16
17
|
#include <wallet/test/wallet_test_fixture.h>
|
|
17
18
|
|
|
19
|
+
#include <algorithm>
|
|
20
|
+
|
|
18
21
|
#include <boost/test/unit_test.hpp>
|
|
19
22
|
|
|
20
23
|
namespace wallet {
|
|
@@ -171,5 +174,43 @@ BOOST_FIXTURE_TEST_CASE(wallet_duplicated_preset_inputs_test, TestChain100Setup)
|
|
|
171
174
|
BOOST_CHECK(!CreateTransaction(*wallet, recipients, /*change_pos=*/std::nullopt, coin_control));
|
|
172
175
|
}
|
|
173
176
|
|
|
177
|
+
BOOST_FIXTURE_TEST_CASE(manual_coin_control_honors_selection_and_rbf, TestChain100Setup)
|
|
178
|
+
{
|
|
179
|
+
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
|
|
180
|
+
auto wallet{CreateSyncedWallet(*m_node.chain, WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain()), coinbaseKey)};
|
|
181
|
+
const auto coins{WITH_LOCK(wallet->cs_wallet, return AvailableCoins(*wallet).All())};
|
|
182
|
+
BOOST_REQUIRE(!coins.empty());
|
|
183
|
+
const COutput selected_coin{coins.front()};
|
|
184
|
+
const CTxDestination destination{PKHash{GenerateRandomKey().GetPubKey()}};
|
|
185
|
+
const CRecipient recipient{destination, COIN, /*subtract_fee=*/false};
|
|
186
|
+
|
|
187
|
+
CCoinControl coin_control;
|
|
188
|
+
coin_control.m_allow_other_inputs = false;
|
|
189
|
+
coin_control.m_signal_bip125_rbf = false;
|
|
190
|
+
coin_control.Select(selected_coin.outpoint);
|
|
191
|
+
|
|
192
|
+
const auto no_rbf{CreateTransaction(*wallet, {recipient}, /*change_pos=*/std::nullopt, coin_control, /*sign=*/false)};
|
|
193
|
+
BOOST_REQUIRE(no_rbf);
|
|
194
|
+
BOOST_REQUIRE_EQUAL(no_rbf->tx->vin.size(), 1U);
|
|
195
|
+
BOOST_CHECK(no_rbf->tx->vin.front().prevout == selected_coin.outpoint);
|
|
196
|
+
BOOST_CHECK(no_rbf->tx->vin.front().nSequence == CTxIn::MAX_SEQUENCE_NONFINAL);
|
|
197
|
+
CAmount outputs{0};
|
|
198
|
+
for (const auto& output : no_rbf->tx->vout) outputs += output.nValue;
|
|
199
|
+
BOOST_CHECK_EQUAL(selected_coin.txout.nValue, outputs + no_rbf->fee);
|
|
200
|
+
|
|
201
|
+
coin_control.m_signal_bip125_rbf = true;
|
|
202
|
+
const auto rbf{CreateTransaction(*wallet, {recipient}, /*change_pos=*/std::nullopt, coin_control, /*sign=*/false)};
|
|
203
|
+
BOOST_REQUIRE(rbf);
|
|
204
|
+
BOOST_REQUIRE_EQUAL(rbf->tx->vin.size(), 1U);
|
|
205
|
+
BOOST_CHECK(rbf->tx->vin.front().prevout == selected_coin.outpoint);
|
|
206
|
+
BOOST_CHECK_EQUAL(rbf->tx->vin.front().nSequence, MAX_BIP125_RBF_SEQUENCE);
|
|
207
|
+
|
|
208
|
+
WITH_LOCK(wallet->cs_wallet, wallet->LockCoin(selected_coin.outpoint));
|
|
209
|
+
const auto available_after_lock{WITH_LOCK(wallet->cs_wallet, return AvailableCoins(*wallet).All())};
|
|
210
|
+
BOOST_CHECK(std::none_of(available_after_lock.cbegin(), available_after_lock.cend(),
|
|
211
|
+
[&selected_coin](const COutput& coin) { return coin.outpoint == selected_coin.outpoint; }));
|
|
212
|
+
BOOST_CHECK(WITH_LOCK(wallet->cs_wallet, return wallet->IsLockedCoin(selected_coin.outpoint)));
|
|
213
|
+
}
|
|
214
|
+
|
|
174
215
|
BOOST_AUTO_TEST_SUITE_END()
|
|
175
216
|
} // namespace wallet
|