diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-07-27 11:20:29 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-07-27 11:21:46 +0200 |
commit | 7075a52b67dc09c47142d987dcd089cc74bdcce6 (patch) | |
tree | ff197336be6a06ac2e10e65dd5fcc6a27d603e48 /src/wallet/test/util.cpp | |
parent | 1488f55fa57a1400a57be837b574183f019c7855 (diff) | |
parent | fe6dc76b7c9c5405f37464a3b19fcf82aaf22861 (diff) | |
download | bitcoin-7075a52b67dc09c47142d987dcd089cc74bdcce6.tar.xz |
Merge bitcoin/bitcoin#22155: wallet test: Add test for subtract fee from recipient behavior
fe6dc76b7c9c5405f37464a3b19fcf82aaf22861 wallet test: Add test for subtract fee from recipient behavior (Russell Yanofsky)
2565478c813fb7278153b113de4b9338fc186872 wallet test refactor: add CreateSyncedWallet function (Russell Yanofsky)
Pull request description:
This adds test coverage for wallet subtract from recipient behavior without changing it. Behavior seems to have changed recently in a minor way in #17331 without being noticed.
ACKs for top commit:
achow101:
ACK fe6dc76b7c9c5405f37464a3b19fcf82aaf22861
glozow:
ACK fe6dc76b7c9c5405f37464a3b19fcf82aaf22861
promag:
Code review ACK fe6dc76b7c9c5405f37464a3b19fcf82aaf22861.
Tree-SHA512: e00c5dfe467e4ccef5edb0dd4fff6c53f35a37828a4327bea2e166751e5ef971d519ffca7b8f735b12912bb4a547980626356bc1855981005aed1a6c2a57be0b
Diffstat (limited to 'src/wallet/test/util.cpp')
-rw-r--r-- | src/wallet/test/util.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/wallet/test/util.cpp b/src/wallet/test/util.cpp new file mode 100644 index 0000000000..c3061b93c0 --- /dev/null +++ b/src/wallet/test/util.cpp @@ -0,0 +1,38 @@ +// Copyright (c) 2021 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include <wallet/test/util.h> + +#include <chain.h> +#include <key.h> +#include <test/util/setup_common.h> +#include <wallet/wallet.h> +#include <wallet/walletdb.h> + +#include <boost/test/unit_test.hpp> + +#include <memory> + +std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key) +{ + auto wallet = std::make_unique<CWallet>(&chain, "", CreateMockWalletDatabase()); + { + LOCK2(wallet->cs_wallet, ::cs_main); + wallet->SetLastBlockProcessed(cchain.Height(), cchain.Tip()->GetBlockHash()); + } + wallet->LoadWallet(); + { + auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan(); + LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore); + spk_man->AddKeyPubKey(key, key.GetPubKey()); + } + WalletRescanReserver reserver(*wallet); + reserver.reserve(); + CWallet::ScanResult result = wallet->ScanForWalletTransactions(cchain.Genesis()->GetBlockHash(), 0 /* start_height */, {} /* max_height */, reserver, false /* update */); + BOOST_CHECK_EQUAL(result.status, CWallet::ScanResult::SUCCESS); + BOOST_CHECK_EQUAL(result.last_scanned_block, cchain.Tip()->GetBlockHash()); + BOOST_CHECK_EQUAL(*result.last_scanned_height, cchain.Height()); + BOOST_CHECK(result.last_failed_block.IsNull()); + return wallet; +} |