Skip to content

Commit eefcc1d

Browse files
committed
wallet/tests: Enable SIlent Payments in ListCoinsTest
1 parent 34c4018 commit eefcc1d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/wallet/test/util.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cc
2727
{
2828
LOCK(wallet->cs_wallet);
2929
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
30+
wallet->SetWalletFlag(WALLET_FLAG_SILENT_PAYMENTS);
3031
wallet->SetupDescriptorScriptPubKeyMans();
3132

3233
FlatSigningProvider provider;

src/wallet/test/wallet_tests.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,23 @@ class ListCoinsTestingSetup : public TestChain100Setup
376376
{
377377
CTransactionRef tx;
378378
CCoinControl dummy;
379+
if (std::holds_alternative<V0SilentPaymentDestination>(recipient.dest)) {
380+
dummy.m_silent_payment = true;
381+
}
379382
{
380383
auto res = CreateTransaction(*wallet, {recipient}, /*change_pos=*/std::nullopt, dummy);
381384
BOOST_CHECK(res);
382385
tx = res->tx;
383386
}
387+
std::map<COutPoint, Coin> spent_coins;
388+
for (const CTxIn& txin : tx->vin) {
389+
spent_coins[txin.prevout]; // Create empty map entry keyed by prevout.
390+
}
391+
wallet->chain().findCoins(spent_coins);
392+
{
393+
LOCK(wallet->cs_wallet);
394+
wallet->IsMine(*tx, spent_coins);
395+
}
384396
wallet->CommitTransaction(tx, {}, {});
385397
CMutableTransaction blocktx;
386398
{
@@ -492,10 +504,29 @@ BOOST_FIXTURE_TEST_CASE(BasicOutputTypesTest, ListCoinsTest)
492504
// 2. One UTXO from the change, due to payment address matching logic
493505

494506
for (const auto& out_type : OUTPUT_TYPES) {
495-
if (out_type == OutputType::UNKNOWN || out_type == OutputType::SILENT_PAYMENTS) continue;
507+
if (out_type == OutputType::UNKNOWN) continue;
508+
if (out_type == OutputType::SILENT_PAYMENTS) continue;
496509
expected_coins_sizes[out_type] = 2U;
497510
TestCoinsResult(*this, out_type, 1 * COIN, expected_coins_sizes);
498511
}
512+
513+
// Add a taproot UTXO to be used for creating a silent payment
514+
util::Result<CTxDestination> dest = Assert(wallet->GetNewDestination(OutputType::BECH32M, ""));
515+
AddTx(CRecipient{*dest, 1 * COIN, /*fSubtractFeeFromAmount=*/true});
516+
CoinFilterParams filter;
517+
filter.skip_locked = true;
518+
available_coins = WITH_LOCK(wallet->cs_wallet, return AvailableCoins(*wallet, nullptr, std::nullopt, filter));
519+
BOOST_CHECK_EQUAL(available_coins.coins[OutputType::BECH32M].size(), 2U);
520+
// Expect 4 OutputType::BECH32M UTXOs
521+
// 1. One UTXO as the recipient because Silent Payments produce taproot scriptPubKeys
522+
// 2. One UTXO from the change, due to payment address matching logic
523+
// 3. Two locked UTXOs from previous OutputType::BECH32M test
524+
expected_coins_sizes[OutputType::BECH32M] = 4U;
525+
// Expect 2 OutputType::BECH32M UTXOs
526+
// 1. One UTXO from mining the previous block
527+
// 1. One UTXO from mining the block used in the test
528+
expected_coins_sizes[OutputType::UNKNOWN] = 2U;
529+
TestCoinsResult(*this, OutputType::SILENT_PAYMENTS, 1 * COIN, expected_coins_sizes);
499530
}
500531

501532
BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)

0 commit comments

Comments
 (0)