Skip to content
Bitcoin Roots

v29.4-roots.4 · Commit 25: [PATCH 25/37] 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 b0e1fa90f6accafb727227bef053e0f2e7a4a010..21355b5c8561cb617e99e8acc491bff6a7c1613d 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>
@@ -676,6 +677,43 @@ BOOST_FIXTURE_TEST_CASE(ListCoinsTest, ListCoinsTestingSetup)
676
677
  BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U);
677
678
  }
678
679
 
680
+ BOOST_FIXTURE_TEST_CASE(coin_control_interface_facts, TestChain100Setup)
681
+ {
682
+ CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
683
+ auto wallet{std::shared_ptr<CWallet>{CreateSyncedWallet(*m_node.chain, WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain()), coinbaseKey).release()}};
684
+ const CFeeRate feerate{1000};
685
+ const auto available_coins{WITH_LOCK(wallet->cs_wallet, return AvailableCoins(*wallet, /*coin_control=*/nullptr, feerate).All())};
686
+ BOOST_REQUIRE(!available_coins.empty());
687
+ const COutput coin{available_coins.front()};
688
+
689
+ WITH_LOCK(wallet->cs_wallet, wallet->LockCoin(coin.outpoint));
690
+ WalletContext context;
691
+ context.chain = m_node.chain.get();
692
+ auto wallet_interface{interfaces::MakeWallet(context, wallet)};
693
+
694
+ const auto without_feerate{wallet_interface->getCoins({coin.outpoint})};
695
+ BOOST_REQUIRE_EQUAL(without_feerate.size(), 1U);
696
+ BOOST_CHECK(!without_feerate.front().effective_value);
697
+
698
+ const auto coins{wallet_interface->getCoins({coin.outpoint}, feerate)};
699
+ BOOST_REQUIRE_EQUAL(coins.size(), 1U);
700
+ const auto& info{coins.front()};
701
+ BOOST_CHECK(info.outpoint == coin.outpoint);
702
+ BOOST_CHECK_EQUAL(info.txout.nValue, coin.txout.nValue);
703
+ BOOST_CHECK_EQUAL(info.time, coin.time);
704
+ BOOST_CHECK_EQUAL(info.depth_in_main_chain, coin.depth);
705
+ BOOST_CHECK_EQUAL(info.input_bytes, coin.input_bytes);
706
+ BOOST_REQUIRE(info.effective_value);
707
+ BOOST_CHECK_EQUAL(*info.effective_value, coin.GetEffectiveValue());
708
+ BOOST_CHECK_EQUAL(info.ancestor_bump_fees, coin.ancestor_bump_fees);
709
+ BOOST_CHECK_EQUAL(info.is_spendable, coin.spendable);
710
+ BOOST_CHECK_EQUAL(info.is_solvable, coin.solvable);
711
+ BOOST_CHECK_EQUAL(info.is_safe, coin.safe);
712
+ BOOST_CHECK(info.is_locked);
713
+ BOOST_CHECK(!info.is_reused);
714
+ BOOST_CHECK(!info.is_spent);
715
+ }
716
+
679
717
  void TestCoinsResult(ListCoinsTest& context, OutputType out_type, CAmount amount,
680
718
  std::map<OutputType, size_t>& expected_coins_sizes)
681
719
  {