Skip to content

Commit 6320efb

Browse files
committed
Update wallet last processed index in every unit test that needs it
1 parent 4957051 commit 6320efb

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/wallet/test/wallet_shielded_balances_tests.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ struct FakeBlock
291291
CBlockIndex* pindex;
292292
};
293293

294-
FakeBlock SimpleFakeMine(CWalletTx& wtx, SaplingMerkleTree& currentTree)
294+
FakeBlock SimpleFakeMine(CWalletTx& wtx, SaplingMerkleTree& currentTree, CWallet& wallet)
295295
{
296296
FakeBlock fakeBlock;
297297
fakeBlock.block.nVersion = 8;
@@ -306,6 +306,7 @@ FakeBlock SimpleFakeMine(CWalletTx& wtx, SaplingMerkleTree& currentTree)
306306
fakeBlock.pindex->phashBlock = &mapBlockIndex.find(fakeBlock.block.GetHash())->first;
307307
chainActive.SetTip(fakeBlock.pindex);
308308
BOOST_CHECK(chainActive.Contains(fakeBlock.pindex));
309+
WITH_LOCK(wallet.cs_wallet, wallet.SetLastBlockProcessed(fakeBlock.pindex));
309310
wtx.SetConf(CWalletTx::Status::CONFIRMED, fakeBlock.pindex->GetBlockHash(), 0);
310311
return fakeBlock;
311312
}
@@ -347,7 +348,7 @@ BOOST_AUTO_TEST_CASE(GetShieldedAvailableCredit)
347348

348349
// 2) Confirm the tx
349350
SaplingMerkleTree tree;
350-
FakeBlock fakeBlock = SimpleFakeMine(wtxUpdated, tree);
351+
FakeBlock fakeBlock = SimpleFakeMine(wtxUpdated, tree, wallet);
351352
// Simulate receiving a new block and updating the witnesses/nullifiers
352353
wallet.IncrementNoteWitnesses(fakeBlock.pindex, &fakeBlock.block, tree);
353354
wallet.GetSaplingScriptPubKeyMan()->UpdateSaplingNullifierNoteMapForBlock(&fakeBlock.block);

src/wallet/test/wallet_tests.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ void removeTxFromMempool(CWalletTx& wtx)
320320
/**
321321
* Mimic block creation.
322322
*/
323-
CBlockIndex* SimpleFakeMine(CWalletTx& wtx, CBlockIndex* pprev = nullptr)
323+
CBlockIndex* SimpleFakeMine(CWalletTx& wtx, CWallet &wallet, CBlockIndex* pprev = nullptr)
324324
{
325325
CBlock block;
326326
block.vtx.emplace_back(wtx.tx);
@@ -332,6 +332,7 @@ CBlockIndex* SimpleFakeMine(CWalletTx& wtx, CBlockIndex* pprev = nullptr)
332332
fakeIndex->phashBlock = &mapBlockIndex.find(block.GetHash())->first;
333333
chainActive.SetTip(fakeIndex);
334334
BOOST_CHECK(chainActive.Contains(fakeIndex));
335+
WITH_LOCK(wallet.cs_wallet, wallet.SetLastBlockProcessed(fakeIndex));
335336
wtx.SetConf(CWalletTx::Status::CONFIRMED, fakeIndex->GetBlockHash(), 0);
336337
removeTxFromMempool(wtx);
337338
wtx.fInMempool = false;
@@ -442,7 +443,7 @@ BOOST_AUTO_TEST_CASE(cached_balances_tests)
442443
BOOST_CHECK_EQUAL(wallet.GetUnconfirmedBalance(), nCredit);
443444

444445
// 2) Confirm tx and verify
445-
SimpleFakeMine(wtxCredit);
446+
SimpleFakeMine(wtxCredit, wallet);
446447
BOOST_CHECK_EQUAL(wallet.GetUnconfirmedBalance(), 0);
447448
BOOST_CHECK_EQUAL(wtxCredit.GetAvailableCredit(), nCredit);
448449

src/wallet/wallet.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,22 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
644644
bool IsHDEnabled() const;
645645
//! Whether the wallet supports Sapling or not //
646646
bool IsSaplingUpgradeEnabled() const;
647-
//! Return the height of the last processed block
648-
int GetLastBlockHeight() const { return m_last_block_processed_height; }
647+
648+
/** Get last block processed height */
649+
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
650+
{
651+
AssertLockHeld(cs_wallet);
652+
assert(m_last_block_processed_height >= 0);
653+
return m_last_block_processed_height;
654+
};
655+
/** Set last block processed height, currently only use in unit test */
656+
void SetLastBlockProcessed(const CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
657+
{
658+
AssertLockHeld(cs_wallet);
659+
m_last_block_processed_height = pindex->nHeight;
660+
m_last_block_processed = pindex->GetBlockHash();
661+
m_last_block_processed_time = pindex->GetBlockTime();
662+
};
649663

650664
/* SPKM Helpers */
651665
const CKeyingMaterial& GetEncryptionKey() const;

0 commit comments

Comments
 (0)