Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
477 changes: 238 additions & 239 deletions src/Makefile.test.include

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/coinjoin/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ int CTransactionBuilder::GetSizeOfCompactSizeDiff(size_t nAdd) const

bool CTransactionBuilder::IsDust(CAmount nAmount) const
{
return ::IsDust(CTxOut(nAmount, ::GetScriptForDestination(tallyItem.txdest)), coinControl.m_discard_feerate.get());
return ::IsDust(CTxOut(nAmount, ::GetScriptForDestination(tallyItem.txdest)), coinControl.m_discard_feerate.value());
}

bool CTransactionBuilder::Commit(bilingual_str& strResult)
Expand Down
4 changes: 2 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1781,9 +1781,9 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
node.mempool = &::mempool;
assert(!node.chainman);
node.chainman = &g_chainman;
ChainstateManager& chainman = EnsureChainman(node);
ChainstateManager& chainman = *Assert(node.chainman);

node.peer_logic.reset(new PeerLogicValidation(node.connman.get(), node.banman.get(), *node.scheduler, *node.chainman, *node.mempool, args.GetBoolArg("-enablebip61", DEFAULT_ENABLE_BIP61)));
node.peer_logic.reset(new PeerLogicValidation(node.connman.get(), node.banman.get(), *node.scheduler, chainman, *node.mempool, args.GetBoolArg("-enablebip61", DEFAULT_ENABLE_BIP61)));
RegisterValidationInterface(node.peer_logic.get());

// sanitize comments per BIP-0014, format user agent and check total size
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <string>
#include <vector>

class ArgsManager;
class CBlock;
class CConnman;
class CFeeRate;
Expand Down
15 changes: 8 additions & 7 deletions src/interfaces/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
WalletTxStatus MakeWalletTxStatus(CWallet& wallet, const CWalletTx& wtx)
{
WalletTxStatus result;
result.block_height = wallet.chain().getBlockHeight(wtx.m_confirm.hashBlock).get_value_or(std::numeric_limits<int>::max());
result.block_height = wallet.chain().getBlockHeight(wtx.m_confirm.hashBlock).value_or(std::numeric_limits<int>::max());
result.blocks_to_maturity = wtx.GetBlocksToMaturity();
result.depth_in_main_chain = wtx.GetDepthInMainChain();
result.time_received = wtx.nTimeReceived;
Expand Down Expand Up @@ -395,7 +395,7 @@ class WalletImpl : public Wallet
return false;
}
balances = getBalances();
num_blocks = m_wallet->chain().getHeight().get_value_or(-1);
num_blocks = m_wallet->chain().getHeight().value_or(-1);
return true;
}
CAmount getBalance() override
Expand Down Expand Up @@ -558,10 +558,11 @@ class WalletImpl : public Wallet
class WalletClientImpl : public WalletClient
{
public:
WalletClientImpl(Chain& chain, std::vector<std::string> wallet_filenames)
WalletClientImpl(Chain& chain, ArgsManager& args, std::vector<std::string> wallet_filenames)
: m_wallet_filenames(std::move(wallet_filenames))
{
m_context.chain = &chain;
m_context.args = &args;
}
~WalletClientImpl() override { UnloadWallets(); }

Expand All @@ -577,7 +578,7 @@ class WalletClientImpl : public WalletClient
}
bool verify() override { return VerifyWallets(*m_context.chain, m_wallet_filenames); }
bool load() override { return LoadWallets(*m_context.chain, m_wallet_filenames); }
void start(CScheduler& scheduler) override { return StartWallets(scheduler); }
void start(CScheduler& scheduler) override { return StartWallets(scheduler, *Assert(m_context.args)); }
void flush() override { return FlushWallets(); }
void stop() override { return StopWallets(); }
void setMockTime(int64_t time) override { return SetMockTime(time); }
Expand Down Expand Up @@ -619,7 +620,7 @@ class WalletClientImpl : public WalletClient
}

WalletContext m_context;
std::vector<std::string> m_wallet_filenames;
const std::vector<std::string> m_wallet_filenames;
std::vector<std::unique_ptr<Handler>> m_rpc_handlers;
std::list<CRPCCommand> m_rpc_commands;
};
Expand All @@ -628,9 +629,9 @@ class WalletClientImpl : public WalletClient

std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet) { return wallet ? MakeUnique<WalletImpl>(wallet) : nullptr; }

std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, std::vector<std::string> wallet_filenames)
std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, ArgsManager& args, std::vector<std::string> wallet_filenames)
{
return MakeUnique<WalletClientImpl>(chain, std::move(wallet_filenames));
return MakeUnique<WalletClientImpl>(chain, args, std::move(wallet_filenames));
}

} // namespace interfaces
2 changes: 1 addition & 1 deletion src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet);

//! Return implementation of ChainClient interface for a wallet client. This
//! function will be undefined in builds where ENABLE_WALLET is false.
std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, std::vector<std::string> wallet_filenames);
std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, ArgsManager& args, std::vector<std::string> wallet_filenames);

} // namespace interfaces

Expand Down
1 change: 0 additions & 1 deletion src/llmq/snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ class CQuorumRotationInfo

size_t cnt = ReadCompactSize(s);
for ([[maybe_unused]] const auto _ : irange::range(cnt)) {
uint256 hash;
CFinalCommitment qc;
::Unserialize(s, qc);
lastCommitmentPerIndex.push_back(std::move(qc));
Expand Down
6 changes: 0 additions & 6 deletions src/node/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,4 @@ struct NodeContext {
~NodeContext();
};

inline ChainstateManager& EnsureChainman(const NodeContext& node)
{
assert(node.chainman);
return *node.chainman;
}

#endif // BITCOIN_NODE_CONTEXT_H
16 changes: 5 additions & 11 deletions src/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,16 @@
#ifndef BITCOIN_OPTIONAL_H
#define BITCOIN_OPTIONAL_H

#include <optional>
#include <utility>

#include <boost/optional.hpp>

//! Substitute for C++17 std::optional
//! DEPRECATED use std::optional in new code.
template <typename T>
using Optional = boost::optional<T>;

//! Substitute for C++17 std::make_optional
template <typename T>
Optional<T> MakeOptional(bool condition, T&& value)
{
return boost::make_optional(condition, std::forward<T>(value));
}
using Optional = std::optional<T>;

//! Substitute for C++17 std::nullopt
static auto& nullopt = boost::none;
//! DEPRECATED use std::nullopt in new code.
static auto& nullopt = std::nullopt;

#endif // BITCOIN_OPTIONAL_H
6 changes: 4 additions & 2 deletions src/psbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <psbt.h>
#include <util/check.h>
#include <util/strencodings.h>

bool PartiallySignedTransaction::IsNull() const
Expand Down Expand Up @@ -165,7 +166,8 @@ void PSBTOutput::Merge(const PSBTOutput& output)

void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index)
{
const CTxOut& out = psbt.tx->vout.at(index);
CMutableTransaction& tx = *Assert(psbt.tx);
const CTxOut& out = tx.vout.at(index);
PSBTOutput& psbt_out = psbt.outputs.at(index);

// Fill a SignatureData with output info
Expand All @@ -175,7 +177,7 @@ void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransactio
// Construct a would-be spend of this output, to update sigdata with.
// Note that ProduceSignature is used to fill in metadata (not actual signatures),
// so provider does not need to provide any private keys (it can be a HidingSigningProvider).
MutableTransactionSignatureCreator creator(psbt.tx.get_ptr(), /* index */ 0, out.nValue, SIGHASH_ALL);
MutableTransactionSignatureCreator creator(&tx, /* index */ 0, out.nValue, SIGHASH_ALL);
ProduceSignature(provider, creator, out.scriptPubKey, sigdata);

// Put redeem_script, key paths, into PSBTOutput.
Expand Down
5 changes: 3 additions & 2 deletions src/qt/test/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};

// This is all you need to run all the tests
int main(int argc, char *argv[])
int main(int argc, char* argv[])
{
// Initialize persistent globals with the testing setup state for sanity.
// E.g. -datadir in gArgs is set to a temp directory dummy value (instead
Expand All @@ -55,7 +55,6 @@ int main(int argc, char *argv[])
}

NodeContext node_context;
node_context.args = &::gArgs; // TODO: remove this patchfix to solve unexplained test failure
std::unique_ptr<interfaces::Node> node = interfaces::MakeNode(&node_context);

bool fInvalid = false;
Expand All @@ -74,6 +73,8 @@ int main(int argc, char *argv[])
BitcoinApplication app(*node);
app.setApplicationName("Dash-Qt-test");

node->setupServerArgs(); // Make gArgs available in the NodeContext
node->context()->args->ClearArgs(); // Clear added args again
AppTests app_tests(app);
if (QTest::qExec(&app_tests) != 0) {
fInvalid = true;
Expand Down
5 changes: 4 additions & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ CTxMemPool& EnsureMemPool(const util::Ref& context)
ChainstateManager& EnsureChainman(const util::Ref& context)
{
NodeContext& node = EnsureNodeContext(context);
return EnsureChainman(node);
if (!node.chainman) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "Node chainman not found");
}
return *node.chainman;
}

/* Calculate the difficulty for a given block index.
Expand Down
6 changes: 2 additions & 4 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,16 +1075,14 @@ static UniValue getspentinfo(const JSONRPCRequest& request)

static UniValue mockscheduler(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
RPCHelpMan{"mockscheduler",
RPCHelpMan{"mockscheduler",
"\nBump the scheduler into the future (-regtest only)\n",
{
{"delta_time", RPCArg::Type::NUM, RPCArg::Optional::NO, "Number of seconds to forward the scheduler into the future." },
},
RPCResults{},
RPCExamples{""},
}.ToString());
}.Check(request);

if (!Params().IsMockableChain()) {
throw std::runtime_error("mockscheduler is for regression testing (-regtest mode) only");
Expand Down
4 changes: 1 addition & 3 deletions src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1466,13 +1466,11 @@ uint256 SignatureHash(const CScript& scriptCode, const T& txTo, unsigned int nIn
{
assert(nIn < txTo.vin.size());

static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));

// Check for invalid use of SIGHASH_SINGLE
if ((nHashType & 0x1f) == SIGHASH_SINGLE) {
if (nIn >= txTo.vout.size()) {
// nOut out of range
return one;
return uint256::ONE;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/blockfilter_index_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool BuildChainTestingSetup::BuildChain(const CBlockIndex* pindex,
CBlockHeader header = block->GetBlockHeader();

CValidationState state;
if (!EnsureChainman(m_node).ProcessNewBlockHeaders({header}, state, Params(), &pindex, nullptr)) {
if (!Assert(m_node.chainman)->ProcessNewBlockHeaders({header}, state, Params(), &pindex, nullptr)) {
return false;
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
uint256 chainA_last_header = last_header;
for (size_t i = 0; i < 2; i++) {
const auto& block = chainA[i];
BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
}
for (size_t i = 0; i < 2; i++) {
const auto& block = chainA[i];
Expand All @@ -189,7 +189,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
uint256 chainB_last_header = last_header;
for (size_t i = 0; i < 3; i++) {
const auto& block = chainB[i];
BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
}
for (size_t i = 0; i < 3; i++) {
const auto& block = chainB[i];
Expand Down Expand Up @@ -220,7 +220,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
// Reorg back to chain A.
for (size_t i = 2; i < 4; i++) {
const auto& block = chainA[i];
BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
}

// Check that chain A and B blocks can be retrieved.
Expand Down
12 changes: 6 additions & 6 deletions src/test/bls_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ BOOST_AUTO_TEST_CASE(bls_sig_tests)
sk1.MakeNewKey();
sk2.MakeNewKey();

uint256 msgHash1 = uint256S("0000000000000000000000000000000000000000000000000000000000000001");
uint256 msgHash2 = uint256S("0000000000000000000000000000000000000000000000000000000000000002");
uint256 msgHash1 = uint256::ONE;
uint256 msgHash2 = uint256::TWO;

auto sig1 = sk1.Sign(msgHash1);
auto sig2 = sk2.Sign(msgHash1);
Expand All @@ -61,8 +61,8 @@ BOOST_AUTO_TEST_CASE(bls_key_agg_tests)

BOOST_CHECK(ag_pk == ag_sk.GetPublicKey());

uint256 msgHash1 = uint256S("0000000000000000000000000000000000000000000000000000000000000001");
uint256 msgHash2 = uint256S("0000000000000000000000000000000000000000000000000000000000000002");
uint256 msgHash1 = uint256::ONE;
uint256 msgHash2 = uint256::TWO;

auto sig = ag_sk.Sign(msgHash1);
BOOST_CHECK(sig.VerifyInsecure(ag_pk, msgHash1));
Expand Down Expand Up @@ -101,8 +101,8 @@ BOOST_AUTO_TEST_CASE(bls_key_agg_vec_tests)
BOOST_CHECK(ag_sk.IsValid());
BOOST_CHECK(ag_pk.IsValid());

uint256 msgHash1 = uint256S("0000000000000000000000000000000000000000000000000000000000000001");
uint256 msgHash2 = uint256S("0000000000000000000000000000000000000000000000000000000000000002");
uint256 msgHash1 = uint256::ONE;
uint256 msgHash2 = uint256::TWO;

auto sig = ag_sk.Sign(msgHash1);
BOOST_CHECK(sig.VerifyInsecure(ag_pk, msgHash1));
Expand Down
12 changes: 6 additions & 6 deletions src/test/evo_deterministicmns_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ BOOST_FIXTURE_TEST_CASE(dip3_activation, TestChainDIP3BeforeActivationSetup)

// We start one block before DIP3 activation, so mining a block with a DIP3 transaction should fail
auto block = std::make_shared<CBlock>(CreateBlock(txns, coinbaseKey));
EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr);
Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr);
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight);
BOOST_ASSERT(block->GetHash() != ::ChainActive().Tip()->GetBlockHash());
BOOST_ASSERT(!deterministicMNManager->GetListAtChainTip().HasMN(tx.GetHash()));
Expand All @@ -255,7 +255,7 @@ BOOST_FIXTURE_TEST_CASE(dip3_activation, TestChainDIP3BeforeActivationSetup)
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight + 1);
// Mining a block with a DIP3 transaction should succeed now
block = std::make_shared<CBlock>(CreateBlock(txns, coinbaseKey));
BOOST_ASSERT(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
BOOST_ASSERT(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight + 2);
BOOST_CHECK_EQUAL(block->GetHash(), ::ChainActive().Tip()->GetBlockHash());
Expand Down Expand Up @@ -470,7 +470,7 @@ BOOST_FIXTURE_TEST_CASE(dip3_test_mempool_reorg, TestChainDIP3Setup)
SignTransaction(*m_node.mempool, tx_collateral, coinbaseKey);

auto block = std::make_shared<CBlock>(CreateBlock({tx_collateral}, coinbaseKey));
BOOST_ASSERT(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
BOOST_ASSERT(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight + 1);
BOOST_CHECK_EQUAL(block->GetHash(), ::ChainActive().Tip()->GetBlockHash());
Expand Down Expand Up @@ -600,7 +600,7 @@ BOOST_FIXTURE_TEST_CASE(dip3_verify_db, TestChainDIP3Setup)
SignTransaction(*m_node.mempool, tx_collateral, coinbaseKey);

auto block = std::make_shared<CBlock>(CreateBlock({tx_collateral}, coinbaseKey));
BOOST_ASSERT(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
BOOST_ASSERT(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight + 1);
BOOST_CHECK_EQUAL(block->GetHash(), ::ChainActive().Tip()->GetBlockHash());
Expand Down Expand Up @@ -631,7 +631,7 @@ BOOST_FIXTURE_TEST_CASE(dip3_verify_db, TestChainDIP3Setup)
auto tx_reg_hash = tx_reg.GetHash();

block = std::make_shared<CBlock>(CreateBlock({tx_reg}, coinbaseKey));
BOOST_ASSERT(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
BOOST_ASSERT(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight + 2);
BOOST_CHECK_EQUAL(block->GetHash(), ::ChainActive().Tip()->GetBlockHash());
Expand All @@ -643,7 +643,7 @@ BOOST_FIXTURE_TEST_CASE(dip3_verify_db, TestChainDIP3Setup)
auto proUpRevTx = CreateProUpRevTx(*m_node.mempool, collateral_utxos, tx_reg_hash, operatorKey, collateralKey);

block = std::make_shared<CBlock>(CreateBlock({proUpRevTx}, coinbaseKey));
BOOST_ASSERT(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
BOOST_ASSERT(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight + 3);
BOOST_CHECK_EQUAL(block->GetHash(), ::ChainActive().Tip()->GetBlockHash());
Expand Down
2 changes: 1 addition & 1 deletion src/test/miner_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
}
}
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);
BOOST_CHECK(EnsureChainman(m_node).ProcessNewBlock(chainparams, shared_pblock, true, nullptr));
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(chainparams, shared_pblock, true, nullptr));
pblock->hashPrevBlock = pblock->GetHash();
};

Expand Down
5 changes: 2 additions & 3 deletions src/test/sighash_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ extern UniValue read_json(const std::string& jsondata);
// Old script.cpp SignatureHash function
uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
{
static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
if (nIn >= txTo.vin.size())
{
return one;
return uint256::ONE;
}
CMutableTransaction txTmp(txTo);

Expand Down Expand Up @@ -56,7 +55,7 @@ uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, un
unsigned int nOut = nIn;
if (nOut >= txTmp.vout.size())
{
return one;
return uint256::ONE;
}
txTmp.vout.resize(nOut+1);
for (unsigned int i = 0; i < nOut; i++)
Expand Down
Loading