Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
Show First 20 Lines • Show All 336 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup) { | ||||
wtx.MarkDirty(); | wtx.MarkDirty(); | ||||
BOOST_CHECK(spk_man->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey())); | BOOST_CHECK(spk_man->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey())); | ||||
BOOST_CHECK_EQUAL(wtx.GetImmatureCredit(), 50 * COIN); | BOOST_CHECK_EQUAL(wtx.GetImmatureCredit(), 50 * COIN); | ||||
} | } | ||||
static int64_t AddTx(CWallet &wallet, uint32_t lockTime, int64_t mockTime, | static int64_t AddTx(CWallet &wallet, uint32_t lockTime, int64_t mockTime, | ||||
int64_t blockTime) { | int64_t blockTime) { | ||||
CMutableTransaction tx; | CMutableTransaction tx; | ||||
CWalletTx::Confirmation confirm; | |||||
tx.nLockTime = lockTime; | tx.nLockTime = lockTime; | ||||
SetMockTime(mockTime); | SetMockTime(mockTime); | ||||
CBlockIndex *block = nullptr; | CBlockIndex *block = nullptr; | ||||
if (blockTime > 0) { | if (blockTime > 0) { | ||||
auto inserted = | auto inserted = | ||||
::BlockIndex().emplace(BlockHash(GetRandHash()), new CBlockIndex); | ::BlockIndex().emplace(BlockHash(GetRandHash()), new CBlockIndex); | ||||
assert(inserted.second); | assert(inserted.second); | ||||
const BlockHash &hash = inserted.first->first; | const BlockHash &hash = inserted.first->first; | ||||
block = inserted.first->second; | block = inserted.first->second; | ||||
block->nTime = blockTime; | block->nTime = blockTime; | ||||
block->phashBlock = &hash; | block->phashBlock = &hash; | ||||
confirm = {CWalletTx::Status::CONFIRMED, block->nHeight, hash, 0}; | |||||
} | } | ||||
CWalletTx wtx(&wallet, MakeTransactionRef(tx)); | |||||
LOCK(wallet.cs_wallet); | |||||
// 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()); | return wallet | ||||
if (it != wallet.mapWallet.end()) { | .AddToWallet(MakeTransactionRef(tx), confirm, | ||||
[&](CWalletTx &wtx, bool /* new_tx */) { | |||||
wtx.setUnconfirmed(); | wtx.setUnconfirmed(); | ||||
wallet.AddToWallet(wtx); | return true; | ||||
} | }) | ||||
if (block) { | ->nTimeSmart; | ||||
CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, | |||||
block->nHeight, block->GetBlockHash(), | |||||
0); | |||||
wtx.m_confirm = confirm; | |||||
} | |||||
wallet.AddToWallet(wtx); | |||||
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) { | ||||
// New transaction should use clock time if lower than block time. | // New transaction should use clock time if lower than block time. | ||||
BOOST_CHECK_EQUAL(AddTx(m_wallet, 1, 100, 120), 100); | BOOST_CHECK_EQUAL(AddTx(m_wallet, 1, 100, 120), 100); | ||||
▲ Show 20 Lines • Show All 323 Lines • Show Last 20 Lines |