25#include <validation.h>
34#include <boost/test/unit_test.hpp>
52 mtx.vin.push_back({
CTxIn{from.GetHash(), index}});
55 std::map<COutPoint, Coin> coins;
56 coins[
mtx.vin[0].prevout].out = from.vout[index];
69 auto& desc =
descs.at(0);
79 wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
85 auto& desc{
descs.at(0)};
107 wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
128 wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
133 std::chrono::steady_clock::time_point
fake_time;
161 file_number =
oldTip->GetBlockPos().nFile;
173 wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
190 file_number =
newTip->GetBlockPos().nFile;
201 wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
227 std::vector<std::thread>
threads;
232 auto wallets = chain->getRwSetting(
"wallet");
308 std::vector<bilingual_str> warnings;
310 auto wallet{std::make_shared<CWallet>(chain.get(),
"", std::move(
database))};
318 const std::string
name{
strprintf(
"receive-requests-%i", format)};
320 BOOST_CHECK(!wallet->IsAddressPreviouslySpent(PKHash()));
321 WalletBatch batch{wallet->GetDatabase()};
331 BOOST_CHECK(wallet->IsAddressPreviouslySpent(PKHash()));
332 BOOST_CHECK(wallet->IsAddressPreviouslySpent(ScriptHash()));
333 auto requests = wallet->GetAddressReceiveRequests();
334 auto erequests = {
"val_rr11",
"val_rr20"};
337 BOOST_CHECK(batch.WriteAddressPreviouslySpent(PKHash(), false));
338 BOOST_CHECK(batch.EraseAddressData(ScriptHash()));
343 BOOST_CHECK(!wallet->IsAddressPreviouslySpent(PKHash()));
344 BOOST_CHECK(!wallet->IsAddressPreviouslySpent(ScriptHash()));
345 auto requests = wallet->GetAddressReceiveRequests();
346 auto erequests = {
"val_rr11"};
375 wallet->CommitTransaction(tx, {}, {});
386 auto it =
wallet->mapWallet.find(tx->GetHash());
397 std::string
coinbaseAddress = coinbaseKey.GetPubKey().GetID().ToString();
401 std::map<CTxDestination, std::vector<COutput>> list;
431 for (
const auto& group : list) {
432 for (
const auto& coin : group.second) {
434 wallet->LockCoin(coin.outpoint,
false);
455 LOCK(context.wallet->cs_wallet);
462 for (
uint32_t i = 0; i < wtx.
tx->vout.size(); i++) context.wallet->LockCoin({wtx.GetHash(), i},
false);
494 const std::shared_ptr<CWallet>
wallet = std::make_shared<CWallet>(
m_node.
chain.get(),
"", CreateMockableWalletDatabase());
496 wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
497 wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
545 std::string s(
e.what());
546 return s.find(
"Missing checksum") != std::string::npos;
553 vw << std::string(
"notadescriptor");
584 m_args.ForceSetArg(
"-unsafesqlitesync",
"1");
587 context.
args = &m_args;
619 m_coinbase_txns.push_back(CreateAndProcessBlock({},
GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]);
661 m_coinbase_txns.push_back(CreateAndProcessBlock({},
GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]);
685 context.
args = &m_args;
693 m_args.ForceSetArg(
"-unsafesqlitesync",
"1");
695 context.
args = &m_args;
702 m_coinbase_txns.push_back(CreateAndProcessBlock({},
GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]);
709 auto block_hash =
block_tx.GetHash();
710 auto prev_tx = m_coinbase_txns[0];
716 std::vector<Txid>
vHashIn{ block_hash };
int64_t CAmount
Amount in satoshis (Can be negative)
static constexpr CAmount COIN
The amount of satoshis in one BTC.
BOOST_FIXTURE_TEST_CASE(util_CheckValue, CheckValueTest)
static void AddTx(const CTransactionRef &tx, const CAmount &fee, CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
#define Assert(val)
Identity function.
The block chain is a tree shaped structure starting with the genesis block at the root,...
int nHeight
height of the entry in the chain. The genesis block has height 0
const uint256 * phashBlock
pointer to the hash of the block, if any. Memory is owned by this CBlockIndex
An encapsulated private key.
CPubKey GetPubKey() const
Compute the public key from a private key.
An encapsulated public key.
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
An input of a transaction.
Interface for managing multiple Chainstate objects, where each chainstate is associated with chainsta...
node::BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddCScript(const CScript &redeemScript)
virtual bool AddKey(const CKey &key)
Minimal stream for reading from an existing byte array by std::span.
constexpr bool IsNull() const
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
A transaction with a bunch of additional info that only the owner cares about.
CWalletTx & AddTx(CRecipient recipient)
std::unique_ptr< CWallet > wallet
Access to the wallet database.
Descriptor with some wallet metadata.
RAII object to check and reserve a wallet rescan.
static UniValue Parse(std::string_view raw, ParamFormat format=ParamFormat::JSON)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
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()
uint160 Hash160(const T1 &in1)
Compute the 160-bit hash an object.
CKey GenerateRandomKey(bool compressed) noexcept
std::string EncodeSecret(const CKey &key)
std::unique_ptr< Chain > MakeChain(node::NodeContext &node)
Return implementation of Chain interface.
@ MEMPOOL_NO_BROADCAST
Add the transaction to the mempool, but don't broadcast to anybody.
static const unsigned int MAX_BLOCKFILE_SIZE
The maximum size of a blk?????.dat file (since 0.8)
static CMutableTransaction TestSimpleSpend(const CTransaction &from, uint32_t index, const CKey &key, const CScript &pubkey)
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
util::Result< CreatedTransactionResult > CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, std::optional< unsigned int > change_pos, const CCoinControl &coin_control, bool sign)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
constexpr CAmount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
static bool RunWithinTxn(WalletBatch &batch, std::string_view process_desc, const std::function< bool(WalletBatch &)> &func)
BOOST_FIXTURE_TEST_CASE(wallet_coinsresult_test, BasicTestingSetup)
bool AddWalletSetting(interfaces::Chain &chain, const std::string &wallet_name)
Add wallet name to persistent configuration so it will be loaded on startup.
static const DatabaseFormat DATABASE_FORMATS[]
bool RemoveWalletSetting(interfaces::Chain &chain, const std::string &wallet_name)
Remove wallet name from persistent configuration so it will not be loaded on startup.
std::unique_ptr< interfaces::Handler > HandleLoadWallet(WalletContext &context, LoadWalletFn load_wallet)
std::unique_ptr< CWallet > CreateSyncedWallet(interfaces::Chain &chain, CChain &cchain, const CKey &key)
static const CAmount DEFAULT_TRANSACTION_MINFEE
-mintxfee default
void TestUnloadWallet(std::shared_ptr< CWallet > &&wallet)
static void AddTx(CWallet &wallet)
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error_string)
std::map< CTxDestination, std::vector< COutput > > ListCoins(const CWallet &wallet)
Return list of available coins and locked coins grouped by non-change output address.
BOOST_AUTO_TEST_CASE(bnb_test)
static void AddKey(CWallet &wallet, const CKey &key)
static const CAmount WALLET_INCREMENTAL_RELAY_FEE
minimum recommended increment for replacement txs
std::variant< TxStateConfirmed, TxStateInMempool, TxStateBlockConflicted, TxStateInactive, TxStateUnrecognized > TxState
All possible CWalletTx states.
std::shared_ptr< CWallet > TestLoadWallet(std::unique_ptr< WalletDatabase > database, WalletContext &context)
std::shared_ptr< CWallet > TestCreateWallet(std::unique_ptr< WalletDatabase > database, WalletContext &context, uint64_t create_flags)
bool malformed_descriptor(std::ios_base::failure e)
void TestCoinsResult(ListCoinsTest &context, OutputType out_type, CAmount amount, std::map< OutputType, size_t > &expected_coins_sizes)
void WaitForDeleteWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly delete the wallet.
static size_t CalculateNestedKeyhashInputSize(bool use_max_sig)
is a home for public enum and struct type definitions that are used internally by node code,...
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static constexpr auto OUTPUT_TYPES
int64_t GetVirtualTransactionInputSize(const CTxIn &txin, int64_t nSigOpCost, unsigned int bytes_per_sigop)
static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE
Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or rep...
static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE
Default for -minrelaytxfee, minimum relay fee for transactions.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
uint256 GetRandHash() noexcept
Generate a random uint256.
void SignTransaction(CMutableTransaction &mtx, const SigningProvider *keystore, const std::map< COutPoint, Coin > &coins, const UniValue &hashType, UniValue &result)
Sign a transaction with the given keystore and previous transactions.
bool(* handler)(const std::any &context, HTTPRequest *req, const std::string &strReq)
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
void UpdateInput(CTxIn &input, const SignatureData &data)
const BaseSignatureCreator & DUMMY_MAXIMUM_SIGNATURE_CREATOR
A signature creator that just produces 72-byte empty signatures.
const BaseSignatureCreator & DUMMY_SIGNATURE_CREATOR
A signature creator that just produces 71-byte empty signatures.
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
A mutable version of CTransaction.
std::vector< CTxOut > vout
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
Testing setup that configures a complete environment.
NodeContext struct containing references to chain state and connection state.
std::unique_ptr< ValidationSignals > validation_signals
Issues calls about blocks and transactions.
std::unique_ptr< ChainstateManager > chainman
std::unique_ptr< interfaces::Chain > chain
std::optional< int > last_scanned_height
uint256 last_scanned_block
Hash and height of most recent block that was successfully scanned.
uint256 last_failed_block
Height of the most recent block that could not be scanned due to read errors or pruning.
enum wallet::CWallet::ScanResult::@18 status
COutputs available for spending, stored by OutputType.
std::optional< DatabaseFormat > require_format
State of transaction confirmed in a block.
State of transaction not confirmed or conflicting with a known block and not in the mempool.
WalletContext struct containing references to state shared between CWallet instances,...
interfaces::Chain * chain
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
BOOST_CHECK_EQUAL_COLLECTIONS(R1L.begin(), R1L.end(), R1Array, R1Array+uint256::size())
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
std::shared_ptr< CWallet > m_wallet
static void AvailableCoins(benchmark::Bench &bench, const std::vector< OutputType > &output_type)