Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
Show First 20 Lines • Show All 301 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup) { | ||||
auto locked_chain = chain->lock(); | auto locked_chain = chain->lock(); | ||||
LockAssertion lock(::cs_main); | LockAssertion lock(::cs_main); | ||||
LOCK(wallet.cs_wallet); | LOCK(wallet.cs_wallet); | ||||
AssertLockHeld(spk_man->cs_wallet); | AssertLockHeld(spk_man->cs_wallet); | ||||
wallet.SetLastBlockProcessed(::ChainActive().Height(), | wallet.SetLastBlockProcessed(::ChainActive().Height(), | ||||
::ChainActive().Tip()->GetBlockHash()); | ::ChainActive().Tip()->GetBlockHash()); | ||||
wtx.SetConf(CWalletTx::Status::CONFIRMED, | CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, | ||||
::ChainActive().Tip()->GetBlockHash(), 0); | ::ChainActive().Tip()->GetBlockHash(), 0); | ||||
wtx.m_confirm = confirm; | |||||
// Call GetImmatureCredit() once before adding the key to the wallet to | // Call GetImmatureCredit() once before adding the key to the wallet to | ||||
// cache the current immature credit amount, which is 0. | // cache the current immature credit amount, which is 0. | ||||
BOOST_CHECK_EQUAL(wtx.GetImmatureCredit(*locked_chain), Amount::zero()); | BOOST_CHECK_EQUAL(wtx.GetImmatureCredit(*locked_chain), Amount::zero()); | ||||
// Invalidate the cached value, add the key, and make sure a new immature | // Invalidate the cached value, add the key, and make sure a new immature | ||||
// credit amount is calculated. | // credit amount is calculated. | ||||
wtx.MarkDirty(); | wtx.MarkDirty(); | ||||
Show All 25 Lines | static int64_t AddTx(CWallet &wallet, uint32_t lockTime, int64_t mockTime, | ||||
// If transaction is already in map, to avoid inconsistencies, | // If transaction is already in map, to avoid inconsistencies, | ||||
// unconfirmation is needed before confirm again with different block. | // unconfirmation is needed before confirm again with different block. | ||||
std::map<TxId, CWalletTx>::iterator it = wallet.mapWallet.find(wtx.GetId()); | std::map<TxId, CWalletTx>::iterator it = wallet.mapWallet.find(wtx.GetId()); | ||||
if (it != wallet.mapWallet.end()) { | if (it != wallet.mapWallet.end()) { | ||||
wtx.setUnconfirmed(); | wtx.setUnconfirmed(); | ||||
wallet.AddToWallet(wtx); | wallet.AddToWallet(wtx); | ||||
} | } | ||||
if (block) { | if (block) { | ||||
wtx.SetConf(CWalletTx::Status::CONFIRMED, block->GetBlockHash(), 0); | CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, | ||||
block->GetBlockHash(), 0); | |||||
wtx.m_confirm = confirm; | |||||
} | } | ||||
wallet.AddToWallet(wtx); | wallet.AddToWallet(wtx); | ||||
return wallet.mapWallet.at(wtx.GetId()).nTimeSmart; | return wallet.mapWallet.at(wtx.GetId()).nTimeSmart; | ||||
} | } | ||||
// Simple test to verify assignment of CWalletTx::nSmartTime value. Could be | // Simple test to verify assignment of CWalletTx::nSmartTime value. Could be | ||||
// expanded to cover more corner cases of smart time logic. | // expanded to cover more corner cases of smart time logic. | ||||
BOOST_AUTO_TEST_CASE(ComputeTimeSmart) { | BOOST_AUTO_TEST_CASE(ComputeTimeSmart) { | ||||
▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | CWalletTx &AddTx(CRecipient recipient) { | ||||
GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
LOCK(wallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
wallet->SetLastBlockProcessed(wallet->GetLastBlockHeight() + 1, | wallet->SetLastBlockProcessed(wallet->GetLastBlockHeight() + 1, | ||||
::ChainActive().Tip()->GetBlockHash()); | ::ChainActive().Tip()->GetBlockHash()); | ||||
auto it = wallet->mapWallet.find(tx->GetId()); | auto it = wallet->mapWallet.find(tx->GetId()); | ||||
BOOST_CHECK(it != wallet->mapWallet.end()); | BOOST_CHECK(it != wallet->mapWallet.end()); | ||||
it->second.SetConf(CWalletTx::Status::CONFIRMED, | CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, | ||||
::ChainActive().Tip()->GetBlockHash(), 1); | ::ChainActive().Tip()->GetBlockHash(), | ||||
1); | |||||
it->second.m_confirm = confirm; | |||||
return it->second; | return it->second; | ||||
} | } | ||||
std::unique_ptr<interfaces::Chain> m_chain = | std::unique_ptr<interfaces::Chain> m_chain = | ||||
interfaces::MakeChain(m_node, Params()); | interfaces::MakeChain(m_node, Params()); | ||||
std::unique_ptr<CWallet> wallet; | std::unique_ptr<CWallet> wallet; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |