Skip to content
Bitcoin Roots

v30.3-roots.1 · Commit 25: [PATCH 25/68] feat(wallet): expose advanced coin control facts

src/wallet/test/wallet_tests.cpp

Before: src/wallet/test/wallet_tests.cpp · After: src/wallet/test/wallet_tests.cpp

File metadata
index b46f8eaff14d250a6bc1c75ee567f11f2bf4a4c5..94a487e5ea5fa66c20c0f922bd9ff6406eefb758 100644

Download original patch · Release notes

Diff rows 1–50 of 50. 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/wallet_tests.cpp CHANGED
@@ -11,6 +11,7 @@
11
11
 
12
12
  #include <addresstype.h>
13
13
  #include <interfaces/chain.h>
14
+ #include <interfaces/wallet.h>
14
15
  #include <key_io.h>
15
16
  #include <node/blockstorage.h>
16
17
  #include <policy/policy.h>
@@ -447,6 +448,43 @@ BOOST_FIXTURE_TEST_CASE(ListCoinsTest, ListCoinsTestingSetup)
447
448
  BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U);
448
449
  }
449
450
 
451
+ BOOST_FIXTURE_TEST_CASE(coin_control_interface_facts, TestChain100Setup)
452
+ {
453
+ CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
454
+ auto wallet{std::shared_ptr<CWallet>{CreateSyncedWallet(*m_node.chain, WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain()), coinbaseKey).release()}};
455
+ const CFeeRate feerate{1000};
456
+ const auto available_coins{WITH_LOCK(wallet->cs_wallet, return AvailableCoins(*wallet, /*coin_control=*/nullptr, feerate).All())};
457
+ BOOST_REQUIRE(!available_coins.empty());
458
+ const COutput coin{available_coins.front()};
459
+
460
+ WITH_LOCK(wallet->cs_wallet, wallet->LockCoin(coin.outpoint, /*persist=*/false));
461
+ WalletContext context;
462
+ context.chain = m_node.chain.get();
463
+ auto wallet_interface{interfaces::MakeWallet(context, wallet)};
464
+
465
+ const auto without_feerate{wallet_interface->getCoins({coin.outpoint})};
466
+ BOOST_REQUIRE_EQUAL(without_feerate.size(), 1U);
467
+ BOOST_CHECK(!without_feerate.front().effective_value);
468
+
469
+ const auto coins{wallet_interface->getCoins({coin.outpoint}, feerate)};
470
+ BOOST_REQUIRE_EQUAL(coins.size(), 1U);
471
+ const auto& info{coins.front()};
472
+ BOOST_CHECK(info.outpoint == coin.outpoint);
473
+ BOOST_CHECK_EQUAL(info.txout.nValue, coin.txout.nValue);
474
+ BOOST_CHECK_EQUAL(info.time, coin.time);
475
+ BOOST_CHECK_EQUAL(info.depth_in_main_chain, coin.depth);
476
+ BOOST_CHECK_EQUAL(info.input_bytes, coin.input_bytes);
477
+ BOOST_REQUIRE(info.effective_value);
478
+ BOOST_CHECK_EQUAL(*info.effective_value, coin.GetEffectiveValue());
479
+ BOOST_CHECK_EQUAL(info.ancestor_bump_fees, coin.ancestor_bump_fees);
480
+ BOOST_CHECK_EQUAL(info.is_spendable, WITH_LOCK(wallet->cs_wallet, return wallet->IsMine(coin.txout)));
481
+ BOOST_CHECK_EQUAL(info.is_solvable, coin.solvable);
482
+ BOOST_CHECK_EQUAL(info.is_safe, coin.safe);
483
+ BOOST_CHECK(info.is_locked);
484
+ BOOST_CHECK(!info.is_reused);
485
+ BOOST_CHECK(!info.is_spent);
486
+ }
487
+
450
488
  void TestCoinsResult(ListCoinsTest& context, OutputType out_type, CAmount amount,
451
489
  std::map<OutputType, size_t>& expected_coins_sizes)
452
490
  {