Skip to content

Commit f889dcb

Browse files
committed
test : updating wallet's last block processed manually.
1 parent 45c9471 commit f889dcb

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/test/librust/sapling_rpc_wallet_tests.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,13 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_taddr_to_sapling)
429429
auto blockHash = block.GetHash();
430430
CBlockIndex fakeIndex {block};
431431
fakeIndex.nHeight = 1;
432-
mapBlockIndex.insert(std::make_pair(blockHash, &fakeIndex));
432+
BlockMap::iterator mi = mapBlockIndex.emplace(blockHash, &fakeIndex).first;
433+
fakeIndex.phashBlock = &((*mi).first);
433434
chainActive.SetTip(&fakeIndex);
434435
BOOST_CHECK(chainActive.Contains(&fakeIndex));
435436
BOOST_CHECK_EQUAL(1, chainActive.Height());
436-
wtx.m_confirm = CWalletTx::Confirmation(CWalletTx::Status::CONFIRMED, fakeIndex.nHeight, blockHash, 0);
437-
pwalletMain->LoadToWallet(wtx);
437+
std::vector<CTransactionRef> vtxConflicted;
438+
pwalletMain->BlockConnected(std::make_shared<CBlock>(block), mi->second, vtxConflicted);
438439
BOOST_CHECK_MESSAGE(pwalletMain->GetAvailableBalance() > 0, "tx not confirmed");
439440

440441
// Context that shieldsendmany requires

src/test/librust/sapling_wallet_tests.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ BOOST_AUTO_TEST_CASE(SaplingNullifierIsSpent) {
351351
BOOST_CHECK(chainActive.Contains(&fakeIndex));
352352
BOOST_CHECK_EQUAL(0, chainActive.Height());
353353

354-
wtx.m_confirm = CWalletTx::Confirmation(CWalletTx::Status::CONFIRMED, 0, block.GetHash(), 0);
355-
wallet.LoadToWallet(wtx);
354+
std::vector<CTransactionRef> vtxConflicted;
355+
wallet.BlockConnected(std::make_shared<CBlock>(block), mi->second, vtxConflicted);
356356

357357
// Verify note has been spent
358358
BOOST_CHECK(wallet.GetSaplingScriptPubKeyMan()->IsSaplingSpent(nullifier));
@@ -421,6 +421,7 @@ BOOST_AUTO_TEST_CASE(NavigateFromSaplingNullifierToNote) {
421421
wallet.LoadToWallet(wtx);
422422

423423
// Verify dummy note is now spent, as AddToWallet invokes AddToSpends()
424+
wallet.SetLastBlockProcessed(mi->second);
424425
BOOST_CHECK(wallet.GetSaplingScriptPubKeyMan()->IsSaplingSpent(nullifier));
425426

426427
// Test invariant: no witnesses means no nullifier.
@@ -520,6 +521,7 @@ BOOST_AUTO_TEST_CASE(SpentSaplingNoteIsFromMe) {
520521
// in the output descriptions of wtx.
521522
wallet.IncrementNoteWitnesses(&fakeIndex, &block, saplingTree);
522523
wallet.GetSaplingScriptPubKeyMan()->UpdateSaplingNullifierNoteMapForBlock(&block);
524+
wallet.SetLastBlockProcessed(mi->second);
523525

524526
// Retrieve the updated wtx from wallet
525527
wtx = wallet.mapWallet.at(wtx.GetHash());
@@ -590,6 +592,7 @@ BOOST_AUTO_TEST_CASE(SpentSaplingNoteIsFromMe) {
590592
wtx2.SetSaplingNoteData(saplingNoteData2);
591593
wtx2.m_confirm = CWalletTx::Confirmation(CWalletTx::Status::CONFIRMED, fakeIndex2.nHeight, block2.GetHash(), 0);
592594
wallet.LoadToWallet(wtx2);
595+
wallet.SetLastBlockProcessed(mi2->second);
593596

594597
// Verify note B is spent. AddToWallet invokes AddToSpends which updates mapTxSaplingNullifiers
595598
BOOST_CHECK(wallet.GetSaplingScriptPubKeyMan()->IsSaplingSpent(nullifier2));

src/wallet/test/wallet_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ BOOST_AUTO_TEST_CASE(cached_balances_tests)
420420
LOCK2(cs_main, wallet.cs_wallet);
421421
wallet.SetMinVersion(FEATURE_PRE_SPLIT_KEYPOOL);
422422
wallet.SetupSPKM(false);
423+
wallet.SetLastBlockProcessed(chainActive.Tip());
423424

424425
// Receive balance from an external source
425426
CTxDestination receivingAddr;

0 commit comments

Comments
 (0)