@@ -244,35 +244,6 @@ BOOST_FIXTURE_TEST_CASE(write_wallet_settings_concurrently, TestingSetup)
244
244
/* num_expected_wallets=*/ 0 );
245
245
}
246
246
247
- // Check that GetImmatureCredit() returns a newly calculated value instead of
248
- // the cached value after a MarkDirty() call.
249
- //
250
- // This is a regression test written to verify a bugfix for the immature credit
251
- // function. Similar tests probably should be written for the other credit and
252
- // debit functions.
253
- BOOST_FIXTURE_TEST_CASE (coin_mark_dirty_immature_credit, TestChain100Setup)
254
- {
255
- CWallet wallet (m_node.chain .get (), " " , CreateMockableWalletDatabase ());
256
-
257
- LOCK (wallet.cs_wallet );
258
- LOCK (Assert (m_node.chainman )->GetMutex ());
259
- CWalletTx wtx{m_coinbase_txns.back (), TxStateConfirmed{m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash (), m_node.chainman ->ActiveChain ().Height (), /* index=*/ 0 }};
260
- wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
261
- wallet.SetupDescriptorScriptPubKeyMans ();
262
-
263
- wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
264
-
265
- // Call GetImmatureCredit() once before adding the key to the wallet to
266
- // cache the current immature credit amount, which is 0.
267
- BOOST_CHECK_EQUAL (CachedTxGetImmatureCredit (wallet, wtx, ISMINE_SPENDABLE), 0 );
268
-
269
- // Invalidate the cached value, add the key, and make sure a new immature
270
- // credit amount is calculated.
271
- wtx.MarkDirty ();
272
- AddKey (wallet, coinbaseKey);
273
- BOOST_CHECK_EQUAL (CachedTxGetImmatureCredit (wallet, wtx, ISMINE_SPENDABLE), 50 *COIN);
274
- }
275
-
276
247
static int64_t AddTx (ChainstateManager& chainman, CWallet& wallet, uint32_t lockTime, int64_t mockTime, int64_t blockTime)
277
248
{
278
249
CMutableTransaction tx;
@@ -751,65 +722,5 @@ BOOST_FIXTURE_TEST_CASE(RemoveTxs, TestChain100Setup)
751
722
TestUnloadWallet (std::move (wallet));
752
723
}
753
724
754
- /* *
755
- * Checks a wallet invalid state where the inputs (prev-txs) of a new arriving transaction are not marked dirty,
756
- * while the transaction that spends them exist inside the in-memory wallet tx map (not stored on db due a db write failure).
757
- */
758
- BOOST_FIXTURE_TEST_CASE (wallet_sync_tx_invalid_state_test, TestingSetup)
759
- {
760
- CWallet wallet (m_node.chain .get (), " " , CreateMockableWalletDatabase ());
761
- {
762
- LOCK (wallet.cs_wallet );
763
- wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
764
- wallet.SetupDescriptorScriptPubKeyMans ();
765
- }
766
-
767
- // Add tx to wallet
768
- const auto op_dest{*Assert (wallet.GetNewDestination (OutputType::BECH32M, " " ))};
769
-
770
- CMutableTransaction mtx;
771
- mtx.vout .emplace_back (COIN, GetScriptForDestination (op_dest));
772
- mtx.vin .emplace_back (Txid::FromUint256 (m_rng.rand256 ()), 0 );
773
- const auto & tx_id_to_spend = wallet.AddToWallet (MakeTransactionRef (mtx), TxStateInMempool{})->GetHash ();
774
-
775
- {
776
- // Cache and verify available balance for the wtx
777
- LOCK (wallet.cs_wallet );
778
- const CWalletTx* wtx_to_spend = wallet.GetWalletTx (tx_id_to_spend);
779
- BOOST_CHECK_EQUAL (CachedTxGetAvailableCredit (wallet, *wtx_to_spend), 1 * COIN);
780
- }
781
-
782
- // Now the good case:
783
- // 1) Add a transaction that spends the previously created transaction
784
- // 2) Verify that the available balance of this new tx and the old one is updated (prev tx is marked dirty)
785
-
786
- mtx.vin .clear ();
787
- mtx.vin .emplace_back (tx_id_to_spend, 0 );
788
- wallet.transactionAddedToMempool (MakeTransactionRef (mtx));
789
- const auto good_tx_id{mtx.GetHash ()};
790
-
791
- {
792
- // Verify balance update for the new tx and the old one
793
- LOCK (wallet.cs_wallet );
794
- const CWalletTx* new_wtx = wallet.GetWalletTx (good_tx_id);
795
- BOOST_CHECK_EQUAL (CachedTxGetAvailableCredit (wallet, *new_wtx), 1 * COIN);
796
-
797
- // Now the old wtx
798
- const CWalletTx* wtx_to_spend = wallet.GetWalletTx (tx_id_to_spend);
799
- BOOST_CHECK_EQUAL (CachedTxGetAvailableCredit (wallet, *wtx_to_spend), 0 * COIN);
800
- }
801
-
802
- // Now the bad case:
803
- // 1) Make db always fail
804
- // 2) Try to add a transaction that spends the previously created transaction and
805
- // verify that we are not moving forward if the wallet cannot store it
806
- GetMockableDatabase (wallet).m_pass = false ;
807
- mtx.vin .clear ();
808
- mtx.vin .emplace_back (good_tx_id, 0 );
809
- BOOST_CHECK_EXCEPTION (wallet.transactionAddedToMempool (MakeTransactionRef (mtx)),
810
- std::runtime_error,
811
- HasReason (" DB error adding transaction to wallet, write failed" ));
812
- }
813
-
814
725
BOOST_AUTO_TEST_SUITE_END ()
815
726
} // namespace wallet
0 commit comments