Branch data Line data Source code
# 1 : : // Copyright (c) 2021 The Bitcoin Core developers
# 2 : : // Distributed under the MIT software license, see the accompanying
# 3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
# 4 : :
# 5 : : #include <wallet/test/util.h>
# 6 : :
# 7 : : #include <chain.h>
# 8 : : #include <key.h>
# 9 : : #include <key_io.h>
# 10 : : #include <test/util/setup_common.h>
# 11 : : #include <wallet/wallet.h>
# 12 : : #include <wallet/walletdb.h>
# 13 : :
# 14 : : #include <boost/test/unit_test.hpp>
# 15 : :
# 16 : : #include <memory>
# 17 : :
# 18 : : namespace wallet {
# 19 : : std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, ArgsManager& args, const CKey& key)
# 20 : 2 : {
# 21 : 2 : auto wallet = std::make_unique<CWallet>(&chain, "", args, CreateMockWalletDatabase());
# 22 : 2 : {
# 23 : 2 : LOCK2(wallet->cs_wallet, ::cs_main);
# 24 : 2 : wallet->SetLastBlockProcessed(cchain.Height(), cchain.Tip()->GetBlockHash());
# 25 : 2 : }
# 26 : 2 : wallet->LoadWallet();
# 27 : 2 : {
# 28 : 2 : LOCK(wallet->cs_wallet);
# 29 : 2 : wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
# 30 : 2 : wallet->SetupDescriptorScriptPubKeyMans();
# 31 : :
# 32 : 2 : FlatSigningProvider provider;
# 33 : 2 : std::string error;
# 34 : 2 : std::unique_ptr<Descriptor> desc = Parse("combo(" + EncodeSecret(key) + ")", provider, error, /* require_checksum=*/ false);
# 35 : 2 : assert(desc);
# 36 : 0 : WalletDescriptor w_desc(std::move(desc), 0, 0, 1, 1);
# 37 [ - + ]: 2 : if (!wallet->AddWalletDescriptor(w_desc, provider, "", false)) assert(false);
# 38 : 2 : }
# 39 : 0 : WalletRescanReserver reserver(*wallet);
# 40 : 2 : reserver.reserve();
# 41 : 2 : CWallet::ScanResult result = wallet->ScanForWalletTransactions(cchain.Genesis()->GetBlockHash(), 0 /* start_height */, {} /* max_height */, reserver, false /* update */);
# 42 : 2 : BOOST_CHECK_EQUAL(result.status, CWallet::ScanResult::SUCCESS);
# 43 : 2 : BOOST_CHECK_EQUAL(result.last_scanned_block, cchain.Tip()->GetBlockHash());
# 44 : 2 : BOOST_CHECK_EQUAL(*result.last_scanned_height, cchain.Height());
# 45 : 2 : BOOST_CHECK(result.last_failed_block.IsNull());
# 46 : 2 : return wallet;
# 47 : 2 : }
# 48 : : } // namespace wallet
|