mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
Merge 65d7c31b3f into merged_master (Bitcoin PR bitcoin/bitcoin#25789)
This commit is contained in:
commit
6be0c1b786
4 changed files with 43 additions and 2 deletions
|
|
@ -180,7 +180,6 @@ BITCOIN_TESTS += \
|
|||
wallet/test/wallet_crypto_tests.cpp \
|
||||
wallet/test/wallet_transaction_tests.cpp \
|
||||
wallet/test/coinselector_tests.cpp \
|
||||
wallet/test/availablecoins_tests.cpp \
|
||||
wallet/test/init_tests.cpp \
|
||||
wallet/test/ismine_tests.cpp \
|
||||
wallet/test/rpc_util_tests.cpp \
|
||||
|
|
|
|||
|
|
@ -405,7 +405,7 @@ CoinsResult AvailableCoins(const CWallet& wallet,
|
|||
if (coinControl && coinControl->HasSelected() && coinControl->IsSelected(outpoint))
|
||||
continue;
|
||||
|
||||
if (wallet.IsLockedCoin(outpoint))
|
||||
if (wallet.IsLockedCoin(outpoint) && params.skip_locked)
|
||||
continue;
|
||||
|
||||
if (wallet.IsSpent(outpoint))
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@ struct CoinFilterParams {
|
|||
bool only_spendable{true};
|
||||
// By default, do not include immature coinbase outputs
|
||||
bool include_immature_coinbase{false};
|
||||
// By default, skip locked UTXOs
|
||||
bool skip_locked{true};
|
||||
// ELEMENTS: by default include all assets
|
||||
std::optional<CAsset> asset;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -627,6 +627,46 @@ BOOST_FIXTURE_TEST_CASE(ListCoinsTest, ListCoinsTestingSetup)
|
|||
BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U);
|
||||
}
|
||||
|
||||
void TestCoinsResult(ListCoinsTest& context, OutputType out_type, CAmount amount,
|
||||
std::map<OutputType, size_t>& expected_coins_sizes)
|
||||
{
|
||||
LOCK(context.wallet->cs_wallet);
|
||||
util::Result<CTxDestination> dest = Assert(context.wallet->GetNewDestination(out_type, ""));
|
||||
CWalletTx& wtx = context.AddTx(CRecipient{{GetScriptForDestination(*dest)}, amount, CAsset(), CPubKey(), /*fSubtractFeeFromAmount=*/true});
|
||||
CoinFilterParams filter;
|
||||
filter.skip_locked = false;
|
||||
CoinsResult available_coins = AvailableCoins(*context.wallet, nullptr, std::nullopt, filter);
|
||||
// Lock outputs so they are not spent in follow-up transactions
|
||||
for (uint32_t i = 0; i < wtx.tx->vout.size(); i++) context.wallet->LockCoin({wtx.GetHash(), i});
|
||||
for (const auto& [type, size] : expected_coins_sizes) BOOST_CHECK_EQUAL(size, available_coins.coins[type].size());
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(BasicOutputTypesTest, ListCoinsTest)
|
||||
{
|
||||
std::map<OutputType, size_t> expected_coins_sizes;
|
||||
for (const auto& out_type : OUTPUT_TYPES) { expected_coins_sizes[out_type] = 0U; }
|
||||
|
||||
// Verify our wallet has one usable coinbase UTXO before starting
|
||||
// This UTXO is a P2PK, so it should show up in the Other bucket
|
||||
expected_coins_sizes[OutputType::UNKNOWN] = 1U;
|
||||
CoinsResult available_coins = WITH_LOCK(wallet->cs_wallet, return AvailableCoins(*wallet));
|
||||
BOOST_CHECK_EQUAL(available_coins.Size(), expected_coins_sizes[OutputType::UNKNOWN]);
|
||||
BOOST_CHECK_EQUAL(available_coins.coins[OutputType::UNKNOWN].size(), expected_coins_sizes[OutputType::UNKNOWN]);
|
||||
|
||||
// We will create a self transfer for each of the OutputTypes and
|
||||
// verify it is put in the correct bucket after running GetAvailablecoins
|
||||
//
|
||||
// For each OutputType, We expect 2 UTXOs in our wallet following the self transfer:
|
||||
// 1. One UTXO as the recipient
|
||||
// 2. One UTXO from the change, due to payment address matching logic
|
||||
|
||||
for (const auto& out_type : OUTPUT_TYPES) {
|
||||
if (out_type == OutputType::UNKNOWN) continue;
|
||||
expected_coins_sizes[out_type] = 2U;
|
||||
TestCoinsResult(*this, out_type, 1 * COIN, expected_coins_sizes);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
|
||||
{
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue