@@ -34,7 +34,7 @@ static void AddKey(CWallet& wallet, const CKey& key)
3434 wallet.AddKeyPubKey (key, key.GetPubKey ());
3535}
3636
37- BOOST_FIXTURE_TEST_CASE (rescan , TestChain100Setup)
37+ BOOST_FIXTURE_TEST_CASE (scan_for_wallet_transactions , TestChain100Setup)
3838{
3939 auto chain = interfaces::MakeChain ();
4040
@@ -47,14 +47,27 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup)
4747
4848 auto locked_chain = chain->lock ();
4949
50+ // Verify ScanForWalletTransactions accomodates a null start block.
51+ {
52+ CWallet wallet (*chain, WalletLocation (), WalletDatabase::CreateDummy ());
53+ AddKey (wallet, coinbaseKey);
54+ WalletRescanReserver reserver (&wallet);
55+ reserver.reserve ();
56+ const CBlockIndex *stop_block = null_block + 1 , *failed_block = null_block + 1 ;
57+ BOOST_CHECK_EQUAL (wallet.ScanForWalletTransactions (nullptr , nullptr , reserver, failed_block, stop_block), CWallet::ScanResult::SUCCESS);
58+ BOOST_CHECK_EQUAL (failed_block, null_block);
59+ BOOST_CHECK_EQUAL (stop_block, null_block);
60+ BOOST_CHECK_EQUAL (wallet.GetImmatureBalance (), 0 );
61+ }
62+
5063 // Verify ScanForWalletTransactions picks up transactions in both the old
5164 // and new block files.
5265 {
5366 CWallet wallet (*chain, WalletLocation (), WalletDatabase::CreateDummy ());
5467 AddKey (wallet, coinbaseKey);
5568 WalletRescanReserver reserver (&wallet);
5669 reserver.reserve ();
57- const CBlockIndex *stop_block, *failed_block;
70+ const CBlockIndex *stop_block = null_block + 1 , *failed_block = null_block + 1 ;
5871 BOOST_CHECK_EQUAL (wallet.ScanForWalletTransactions (oldTip, nullptr , reserver, failed_block, stop_block), CWallet::ScanResult::SUCCESS);
5972 BOOST_CHECK_EQUAL (failed_block, null_block);
6073 BOOST_CHECK_EQUAL (stop_block, newTip);
@@ -72,13 +85,47 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup)
7285 AddKey (wallet, coinbaseKey);
7386 WalletRescanReserver reserver (&wallet);
7487 reserver.reserve ();
75- const CBlockIndex *stop_block, *failed_block;
88+ const CBlockIndex *stop_block = null_block + 1 , *failed_block = null_block + 1 ;
7689 BOOST_CHECK_EQUAL (wallet.ScanForWalletTransactions (oldTip, nullptr , reserver, failed_block, stop_block), CWallet::ScanResult::FAILURE);
7790 BOOST_CHECK_EQUAL (failed_block, oldTip);
7891 BOOST_CHECK_EQUAL (stop_block, newTip);
7992 BOOST_CHECK_EQUAL (wallet.GetImmatureBalance (), 50 * COIN);
8093 }
8194
95+ // Prune the remaining block file.
96+ PruneOneBlockFile (newTip->GetBlockPos ().nFile );
97+ UnlinkPrunedFiles ({newTip->GetBlockPos ().nFile });
98+
99+ // Verify ScanForWalletTransactions scans no blocks.
100+ {
101+ CWallet wallet (*chain, WalletLocation (), WalletDatabase::CreateDummy ());
102+ AddKey (wallet, coinbaseKey);
103+ WalletRescanReserver reserver (&wallet);
104+ reserver.reserve ();
105+ const CBlockIndex *stop_block = null_block + 1 , *failed_block = null_block + 1 ;
106+ BOOST_CHECK_EQUAL (wallet.ScanForWalletTransactions (oldTip, nullptr , reserver, failed_block, stop_block), CWallet::ScanResult::FAILURE);
107+ BOOST_CHECK_EQUAL (failed_block, newTip);
108+ BOOST_CHECK_EQUAL (stop_block, null_block);
109+ BOOST_CHECK_EQUAL (wallet.GetImmatureBalance (), 0 );
110+ }
111+ }
112+
113+ BOOST_FIXTURE_TEST_CASE (importmulti_rescan, TestChain100Setup)
114+ {
115+ auto chain = interfaces::MakeChain ();
116+
117+ // Cap last block file size, and mine new block in a new block file.
118+ CBlockIndex* oldTip = chainActive.Tip ();
119+ GetBlockFileInfo (oldTip->GetBlockPos ().nFile )->nSize = MAX_BLOCKFILE_SIZE;
120+ CreateAndProcessBlock ({}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ()));
121+ CBlockIndex* newTip = chainActive.Tip ();
122+
123+ auto locked_chain = chain->lock ();
124+
125+ // Prune the older block file.
126+ PruneOneBlockFile (oldTip->GetBlockPos ().nFile );
127+ UnlinkPrunedFiles ({oldTip->GetBlockPos ().nFile });
128+
82129 // Verify importmulti RPC returns failure for a key whose creation time is
83130 // before the missing block, and success for a key whose creation time is
84131 // after.
@@ -294,7 +341,7 @@ class ListCoinsTestingSetup : public TestChain100Setup
294341 WalletRescanReserver reserver (wallet.get ());
295342 reserver.reserve ();
296343 const CBlockIndex* const null_block = nullptr ;
297- const CBlockIndex *stop_block, *failed_block;
344+ const CBlockIndex *stop_block = null_block + 1 , *failed_block = null_block + 1 ;
298345 BOOST_CHECK_EQUAL (wallet->ScanForWalletTransactions (chainActive.Genesis (), nullptr , reserver, failed_block, stop_block), CWallet::ScanResult::SUCCESS);
299346 BOOST_CHECK_EQUAL (stop_block, chainActive.Tip ());
300347 BOOST_CHECK_EQUAL (failed_block, null_block);
0 commit comments