5#include <blockfilter.h>
25#include <boost/test/unit_test.hpp>
75 wallet.SetLastBlockProcessed(newTip->nHeight, newTip->GetBlockHash());
79 std::chrono::steady_clock::time_point fake_time;
80 reserver.
setNow([&] { fake_time += 60
s;
return fake_time; });
86 BOOST_REQUIRE(!locator.
IsNull());
100 BOOST_REQUIRE(!locator.
IsNull());
138 file_number = newTip->GetBlockPos().nFile;
168 BOOST_REQUIRE(filter_index.Init());
176 const int stale_height{stale_block->
nHeight};
178 BOOST_REQUIRE(
m_node.
chainman->ActiveChainstate().InvalidateBlock(state, stale_block));
180 CreateAndProcessBlock({}, replacement_script);
181 CreateAndProcessBlock({}, replacement_script);
182 BOOST_REQUIRE(filter_index.BlockUntilSyncedToCurrentChain());
185 BOOST_REQUIRE(!
m_node.
chainman->ActiveChain().Contains(*stale_block));
186 BOOST_REQUIRE_EQUAL(
m_node.
chainman->ActiveChain().Height(), stale_height + 1);
191 BOOST_REQUIRE(filter_index.LookupFilter(stale_block, filter));
205 ScanResult result =
wallet.Scanner().Scan(stale_hash, stale_height, {}, reserver,
false);
224 ScanResult result =
wallet.Scanner().Scan(stale_hash, stale_height, {}, reserver,
false);
252 ScanResult result =
wallet.Scanner().Scan(stale_hash, stale_height, {}, reserver,
false);
273 genesis_hash =
m_node.
chainman->ActiveChain().Genesis()->GetBlockHash();
287 ScanResult result =
wallet.Scanner().Scan(genesis_hash, 0, {}, reserver,
false);
329 uint256 genesis_hash, max_hash, tip_hash;
330 int max_height, tip_height;
333 genesis_hash =
m_node.
chainman->ActiveChain().Genesis()->GetBlockHash();
336 max_height = tip_height - 2;
337 max_hash =
m_node.
chainman->ActiveChain()[max_height]->GetBlockHash();
347 wallet.SetLastBlockProcessed(tip_height, tip_hash);
352 ScanResult result =
wallet.Scanner().Scan(genesis_hash, 0, max_height, reserver,
false);
368 wallet.SetLastBlockProcessed(tip_height, tip_hash);
373 ScanResult result =
wallet.Scanner().Scan(tip_hash, tip_height, tip_height, reserver,
false);
386 int start_tip_height{0};
392 wallet.SetLastBlockProcessed(start_tip_height,
m_node.
chainman->ActiveChain().Tip()->GetBlockHash());
393 genesis_hash =
m_node.
chainman->ActiveChain().Genesis()->GetBlockHash();
402 bool extended{
false};
403 auto handler =
wallet.ShowProgress.connect([&](
const std::string&,
int) {
404 if (extended)
return;
411 wallet.SetLastBlockProcessed(new_tip->
nHeight, new_tip_hash);
416 ScanResult result =
wallet.Scanner().Scan(genesis_hash, 0, {}, reserver,
false);
426 uint256 genesis_hash, tip_hash;
434 genesis_hash =
m_node.
chainman->ActiveChain().Genesis()->GetBlockHash();
442 std::chrono::steady_clock::time_point fake_time;
443 reserver.
setNow([&] { fake_time += 60
s;
return fake_time; });
446 ScanResult result =
wallet.Scanner().Scan(genesis_hash, 0, max_height, reserver,
false);
493 bool scan_logged{
false};
494 DebugLogHelper scan_check{
"Rescan started from block", [&](
const std::string*
s) {
495 if (
s) scan_logged =
true;
511 BOOST_REQUIRE(filter_index.Init());
515 uint256 genesis_hash, tip_hash;
521 genesis_hash =
m_node.
chainman->ActiveChain().Genesis()->GetBlockHash();
524 tip_hash = tip->GetBlockHash();
525 wallet.SetLastBlockProcessed(tip_height, tip_hash);
527 BOOST_REQUIRE(!filter_index.LookupFilter(tip, filter));
532 bool fast_scan_logged{
false};
533 DebugLogHelper scan_check{
"fast variant using block filters", [&](
const std::string*
s) {
534 if (
s) fast_scan_logged =
true;
537 ScanResult result =
wallet.Scanner().Scan(genesis_hash, 0, {}, reserver,
false);
538 BOOST_REQUIRE(fast_scan_logged);
557 m_args.ForceSetArg(
"-unsafesqlitesync",
"1");
568 constexpr int NEW_BLOCKS{5};
569 for (
int i = 0; i < NEW_BLOCKS; ++i) {
constexpr CAmount COIN
The amount of satoshis in one BTC.
bool DestroyBlockFilterIndex(BlockFilterType filter_type)
Destroy the block filter index with the given type.
BlockFilterIndex * GetBlockFilterIndex(BlockFilterType filter_type)
Get a block filter index by type.
bool InitBlockFilterIndex(std::function< std::unique_ptr< interfaces::Chain >()> make_chain, BlockFilterType filter_type, size_t n_cache_size, bool f_memory, bool f_wipe)
Initialize a block filter index for the given type if one does not already exist.
constexpr int64_t TIMESTAMP_WINDOW
Timestamp window used as a grace period by code that compares external timestamps (such as timestamps...
#define Assert(val)
Identity function.
Complete block filter struct as defined in BIP 157.
BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of bloc...
The block chain is a tree shaped structure starting with the genesis block at the root,...
uint256 GetBlockHash() const
int64_t GetBlockTimeMax() const
int nHeight
height of the entry in the chain. The genesis block has height 0
FlatFilePos GetBlockPos() const EXCLUSIVE_LOCKS_REQUIRED(
Serialized script, used inside transaction inputs and outputs.
constexpr bool IsNull() const
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Access to the wallet database.
RAII object to check and reserve a wallet rescan.
bool reserve(bool with_passphrase=false)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(headers.FindFirst("key"), "value")
CKey GenerateRandomKey(bool compressed) noexcept
std::unique_ptr< Chain > MakeChain(node::NodeContext &node)
Return implementation of Chain interface.
constexpr unsigned int MAX_BLOCKFILE_SIZE
The maximum size of a blk?????.dat file (since 0.8)
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase()
BOOST_FIXTURE_TEST_CASE(wallet_coinsresult_test, BasicTestingSetup)
void TestUnloadWallet(std::shared_ptr< CWallet > &&wallet)
void AddKey(CWallet &wallet, const CKey &key)
std::shared_ptr< CWallet > TestLoadWallet(std::unique_ptr< WalletDatabase > database, WalletContext &context)
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse, bool include_nonmempool)
std::shared_ptr< CWallet > TestCreateWallet(std::unique_ptr< WalletDatabase > database, WalletContext &context, uint64_t create_flags)
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
#define BOOST_CHECK(expr)
bool(* handler)(const std::any &context, HTTPRequest *req, const std::string &strReq)
static bool GetPubKey(const SigningProvider &provider, const SignatureData &sigdata, const CKeyID &address, CPubKey &pubkey)
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
std::vector< uint256 > vHave
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
Testing setup that configures a complete environment.
std::unique_ptr< ChainstateManager > chainman
std::unique_ptr< interfaces::Chain > chain
uint256 last_scanned_block
Hash and height of most recent block that was successfully scanned.
enum wallet::ScanResult::@19 status
std::optional< int > last_scanned_height
uint256 last_failed_block
Height of the most recent block that could not be scanned due to read errors or pruning.
WalletContext struct containing references to state shared between CWallet instances,...
interfaces::Chain * chain
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
void StopIndex(BaseIndex &index, node::NodeContext &node)
Drain validation callbacks before stopping an index, matching Shutdown() in init.cpp.
std::shared_ptr< CWallet > wallet