Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
Show All 27 Lines | |||||
BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup) | BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup) | ||||
static void AddKey(CWallet &wallet, const CKey &key) { | static void AddKey(CWallet &wallet, const CKey &key) { | ||||
LOCK(wallet.cs_wallet); | LOCK(wallet.cs_wallet); | ||||
wallet.AddKeyPubKey(key, key.GetPubKey()); | wallet.AddKeyPubKey(key, key.GetPubKey()); | ||||
} | } | ||||
// Note: when backporting PR14957, see PR15321 and ensure both LockAnnotations | |||||
// are in place. | |||||
BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup) { | BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup) { | ||||
auto chain = interfaces::MakeChain(); | auto chain = interfaces::MakeChain(); | ||||
// Cap last block file size, and mine new block in a new block file. | // Cap last block file size, and mine new block in a new block file. | ||||
CBlockIndex *const nullBlock = nullptr; | CBlockIndex *const nullBlock = nullptr; | ||||
CBlockIndex *oldTip = chainActive.Tip(); | CBlockIndex *oldTip = chainActive.Tip(); | ||||
GetBlockFileInfo(oldTip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE; | GetBlockFileInfo(oldTip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE; | ||||
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | ||||
CBlockIndex *newTip = chainActive.Tip(); | CBlockIndex *newTip = chainActive.Tip(); | ||||
LockAnnotation lock(::cs_main); | |||||
auto locked_chain = chain->lock(); | auto locked_chain = chain->lock(); | ||||
// Verify ScanForWalletTransactions picks up transactions in both the old | // Verify ScanForWalletTransactions picks up transactions in both the old | ||||
// and new block files. | // and new block files. | ||||
{ | { | ||||
CWallet wallet(Params(), *chain, WalletLocation(), | CWallet wallet(Params(), *chain, WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
AddKey(wallet, coinbaseKey); | AddKey(wallet, coinbaseKey); | ||||
▲ Show 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | |||||
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; | ||||
tx.nLockTime = lockTime; | tx.nLockTime = lockTime; | ||||
SetMockTime(mockTime); | SetMockTime(mockTime); | ||||
CBlockIndex *block = nullptr; | CBlockIndex *block = nullptr; | ||||
if (blockTime > 0) { | if (blockTime > 0) { | ||||
LockAnnotation lock(::cs_main); | |||||
auto locked_chain = wallet.chain().lock(); | auto locked_chain = wallet.chain().lock(); | ||||
auto inserted = | auto inserted = | ||||
mapBlockIndex.emplace(BlockHash(GetRandHash()), new CBlockIndex); | mapBlockIndex.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; | ||||
▲ Show 20 Lines • Show All 183 Lines • Show Last 20 Lines |