Skip to content

Commit a78c229

Browse files
committed
tests: Place into mapWallet in coinselector_tests
Instead of using AddToWallet so that making a COutput will work, directly add the transaction into wallet.mapWallet. This bypasses many checks that AddToWallet will do which are pointless and just slow down this test.
1 parent 224e90d commit a78c229

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/wallet/test/coinselector_tests.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,18 @@ static void add_coin(std::vector<COutput>& coins, CWallet& wallet, const CAmount
7171
// so stop vin being empty, and cache a non-zero Debit to fake out IsFromMe()
7272
tx.vin.resize(1);
7373
}
74-
CWalletTx* wtx = wallet.AddToWallet(MakeTransactionRef(std::move(tx)), /* confirm= */ {});
74+
uint256 txid = tx.GetHash();
75+
76+
LOCK(wallet.cs_wallet);
77+
auto ret = wallet.mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(txid), std::forward_as_tuple(MakeTransactionRef(std::move(tx))));
78+
assert(ret.second);
79+
CWalletTx& wtx = (*ret.first).second;
7580
if (fIsFromMe)
7681
{
77-
wtx->m_amounts[CWalletTx::DEBIT].Set(ISMINE_SPENDABLE, 1);
78-
wtx->m_is_cache_empty = false;
82+
wtx.m_amounts[CWalletTx::DEBIT].Set(ISMINE_SPENDABLE, 1);
83+
wtx.m_is_cache_empty = false;
7984
}
80-
COutput output(wallet, *wtx, nInput, nAge, true /* spendable */, true /* solvable */, true /* safe */);
85+
COutput output(wallet, wtx, nInput, nAge, true /* spendable */, true /* solvable */, true /* safe */);
8186
coins.push_back(output);
8287
}
8388

0 commit comments

Comments
 (0)