Skip to content

Commit cf8007c

Browse files
committed
wallet/tests: Enable Silent Payments in wallet unit tests
1 parent 5462e18 commit cf8007c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-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: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ class ListCoinsTestingSetup : public TestChain100Setup
365365
{
366366
CTransactionRef tx;
367367
CCoinControl dummy;
368+
if (std::holds_alternative<V0SilentPaymentDestination>(recipient.dest)) {
369+
dummy.m_silent_payment = true;
370+
}
368371
{
369372
auto res = CreateTransaction(*wallet, {recipient}, /*change_pos=*/std::nullopt, dummy);
370373
BOOST_CHECK(res);
@@ -481,10 +484,28 @@ BOOST_FIXTURE_TEST_CASE(BasicOutputTypesTest, ListCoinsTest)
481484
// 2. One UTXO from the change, due to payment address matching logic
482485

483486
for (const auto& out_type : OUTPUT_TYPES) {
484-
if (out_type == OutputType::UNKNOWN || out_type == OutputType::SILENT_PAYMENTS) continue;
487+
if (out_type == OutputType::UNKNOWN) continue;
488+
if (out_type == OutputType::SILENT_PAYMENTS) continue;
485489
expected_coins_sizes[out_type] = 2U;
486490
TestCoinsResult(*this, out_type, 1 * COIN, expected_coins_sizes);
487491
}
492+
493+
// Add a taproot UTXO to be used for creating a silent payment
494+
util::Result<CTxDestination> dest = Assert(wallet->GetNewDestination(OutputType::BECH32M, ""));
495+
AddTx(CRecipient{*dest, 1 * COIN, /*fSubtractFeeFromAmount=*/true});
496+
CoinFilterParams filter;
497+
filter.skip_locked = true;
498+
available_coins = WITH_LOCK(wallet->cs_wallet, return AvailableCoins(*wallet, nullptr, std::nullopt, filter));
499+
BOOST_CHECK_EQUAL(available_coins.coins[OutputType::BECH32M].size(), 2U);
500+
// Expect 3 OutputType::BECH32M UTXOs
501+
// 1. One UTXO as the recipient because Silent Payments produce taproot scriptPubKeys
502+
// 3. Two locked UTXOs from previous OutputType::BECH32M test
503+
expected_coins_sizes[OutputType::BECH32M] = 3U;
504+
// Expect 2 OutputType::UNKNOWN UTXOs
505+
// 1. One UTXO from mining the previous block
506+
// 1. One UTXO from mining the block used in the test
507+
expected_coins_sizes[OutputType::UNKNOWN] = 2U;
508+
TestCoinsResult(*this, OutputType::SILENT_PAYMENTS, 1 * COIN, expected_coins_sizes);
488509
}
489510

490511
BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)

0 commit comments

Comments
 (0)