mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
partial Merge #20004: test: Add signet witness commitment section parse tests
fa29b5ae666bbb4c19188f0dcf8a1ba738aac624 test: Add signet witness commitment section parse tests (MarcoFalke) fa23308e9aad70c99a31f91d8556f1876ea02c04 Remove gArgs global from CreateChainParams to aid testing (MarcoFalke) Pull request description: ACKs for top commit: laanwj: ACK fa29b5ae666bbb4c19188f0dcf8a1ba738aac624 Tree-SHA512: f956407d690decbfb8178bcb8f101d107389fecc3aa7be515f7b0f5ceac26d798c165100f7ddf08cec569beabcc6514862dda23b667cc4fd0a784316784735c2
This commit is contained in:
parent
7048cb74ba
commit
bd63c19392
@ -34,7 +34,8 @@ static void DeserializeAndCheckBlockTest(benchmark::Bench& bench)
|
||||
char a = '\0';
|
||||
stream.write(&a, 1); // Prevent compaction
|
||||
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
ArgsManager bench_args;
|
||||
const auto chainParams = CreateChainParams(bench_args, CBaseChainParams::MAIN);
|
||||
|
||||
bench.unit("block").run([&] {
|
||||
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
|
||||
|
@ -1328,22 +1328,22 @@ const CChainParams &Params() {
|
||||
return *globalChainParams;
|
||||
}
|
||||
|
||||
std::unique_ptr<const CChainParams> CreateChainParams(const std::string& chain)
|
||||
std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const std::string& chain)
|
||||
{
|
||||
if (chain == CBaseChainParams::MAIN)
|
||||
return std::make_unique<CMainParams>();
|
||||
else if (chain == CBaseChainParams::TESTNET)
|
||||
return std::make_unique<CTestNetParams>();
|
||||
else if (chain == CBaseChainParams::DEVNET)
|
||||
return std::make_unique<CDevNetParams>(gArgs);
|
||||
else if (chain == CBaseChainParams::REGTEST)
|
||||
return std::make_unique<CRegTestParams>(gArgs);
|
||||
|
||||
if (chain == CBaseChainParams::MAIN) {
|
||||
return std::unique_ptr<CChainParams>(new CMainParams());
|
||||
} else if (chain == CBaseChainParams::TESTNET) {
|
||||
return std::unique_ptr<CChainParams>(new CTestNetParams());
|
||||
} else if (chain == CBaseChainParams::DEVNET) {
|
||||
return std::unique_ptr<CChainParams>(new CDevNetParams(args));
|
||||
} else if (chain == CBaseChainParams::REGTEST) {
|
||||
return std::unique_ptr<CChainParams>(new CRegTestParams(args));
|
||||
}
|
||||
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
||||
}
|
||||
|
||||
void SelectParams(const std::string& network)
|
||||
{
|
||||
SelectBaseParams(network);
|
||||
globalChainParams = CreateChainParams(network);
|
||||
globalChainParams = CreateChainParams(gArgs, network);
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ protected:
|
||||
* @returns a CChainParams* of the chosen chain.
|
||||
* @throws a std::runtime_error if the chain is not supported.
|
||||
*/
|
||||
std::unique_ptr<const CChainParams> CreateChainParams(const std::string& chain);
|
||||
std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const std::string& chain);
|
||||
|
||||
/**
|
||||
* Return the currently selected parameters. This won't change after app
|
||||
|
@ -1419,7 +1419,8 @@ static bool CheckService(const ProTx& proTx, TxValidationState& state)
|
||||
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-ipaddr");
|
||||
}
|
||||
|
||||
static int mainnetDefaultPort = CreateChainParams(CBaseChainParams::MAIN)->GetDefaultPort();
|
||||
// TODO: use real args here
|
||||
static int mainnetDefaultPort = CreateChainParams(ArgsManager{}, CBaseChainParams::MAIN)->GetDefaultPort();
|
||||
if (Params().NetworkIDString() == CBaseChainParams::MAIN) {
|
||||
if (proTx.addr.GetPort() != mainnetDefaultPort) {
|
||||
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-ipaddr-port");
|
||||
@ -1442,21 +1443,24 @@ static bool CheckPlatformFields(const ProTx& proTx, TxValidationState& state)
|
||||
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-platform-nodeid");
|
||||
}
|
||||
|
||||
static int mainnetPlatformP2PPort = CreateChainParams(CBaseChainParams::MAIN)->GetDefaultPlatformP2PPort();
|
||||
// TODO: use real args here
|
||||
static int mainnetPlatformP2PPort = CreateChainParams(ArgsManager{}, CBaseChainParams::MAIN)->GetDefaultPlatformP2PPort();
|
||||
if (Params().NetworkIDString() == CBaseChainParams::MAIN) {
|
||||
if (proTx.platformP2PPort != mainnetPlatformP2PPort) {
|
||||
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-platform-p2p-port");
|
||||
}
|
||||
}
|
||||
|
||||
static int mainnetPlatformHTTPPort = CreateChainParams(CBaseChainParams::MAIN)->GetDefaultPlatformHTTPPort();
|
||||
// TODO: use real args here
|
||||
static int mainnetPlatformHTTPPort = CreateChainParams(ArgsManager{}, CBaseChainParams::MAIN)->GetDefaultPlatformHTTPPort();
|
||||
if (Params().NetworkIDString() == CBaseChainParams::MAIN) {
|
||||
if (proTx.platformHTTPPort != mainnetPlatformHTTPPort) {
|
||||
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-platform-http-port");
|
||||
}
|
||||
}
|
||||
|
||||
static int mainnetDefaultP2PPort = CreateChainParams(CBaseChainParams::MAIN)->GetDefaultPort();
|
||||
// TODO: use real args here
|
||||
static int mainnetDefaultP2PPort = CreateChainParams(ArgsManager{}, CBaseChainParams::MAIN)->GetDefaultPort();
|
||||
if (proTx.platformP2PPort == mainnetDefaultP2PPort) {
|
||||
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-platform-p2p-port");
|
||||
}
|
||||
|
@ -497,9 +497,9 @@ void SetupServerArgs(NodeContext& node)
|
||||
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
|
||||
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
|
||||
const auto regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST);
|
||||
const auto defaultChainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
const auto testnetChainParams = CreateChainParams(CBaseChainParams::TESTNET);
|
||||
const auto regtestChainParams = CreateChainParams(CBaseChainParams::REGTEST);
|
||||
const auto defaultChainParams = CreateChainParams(argsman, CBaseChainParams::MAIN);
|
||||
const auto testnetChainParams = CreateChainParams(argsman, CBaseChainParams::TESTNET);
|
||||
const auto regtestChainParams = CreateChainParams(argsman, CBaseChainParams::REGTEST);
|
||||
|
||||
// Hidden Options
|
||||
std::vector<std::string> hidden_args = {"-dbcrashratio", "-forcecompactdb", "-printcrashinfo",
|
||||
|
@ -94,12 +94,12 @@ void PaymentServer::ipcParseCommandLine(interfaces::Node& node, int argc, char*
|
||||
SendCoinsRecipient r;
|
||||
if (GUIUtil::parseBitcoinURI(arg, &r) && !r.address.isEmpty())
|
||||
{
|
||||
auto tempChainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
auto tempChainParams = CreateChainParams(gArgs, CBaseChainParams::MAIN);
|
||||
|
||||
if (IsValidDestinationString(r.address.toStdString(), *tempChainParams)) {
|
||||
node.selectParams(CBaseChainParams::MAIN);
|
||||
} else {
|
||||
tempChainParams = CreateChainParams(CBaseChainParams::TESTNET);
|
||||
tempChainParams = CreateChainParams(gArgs, CBaseChainParams::TESTNET);
|
||||
if (IsValidDestinationString(r.address.toStdString(), *tempChainParams)) {
|
||||
node.selectParams(CBaseChainParams::TESTNET);
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ std::unique_ptr<const CChainParams> g_params;
|
||||
void initialize_versionbits()
|
||||
{
|
||||
// this is actually comparatively slow, so only do it once
|
||||
g_params = CreateChainParams(CBaseChainParams::MAIN);
|
||||
g_params = CreateChainParams(ArgsManager{}, CBaseChainParams::MAIN);
|
||||
assert(g_params != nullptr);
|
||||
}
|
||||
|
||||
|
@ -210,7 +210,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
|
||||
// NOTE: These tests rely on CreateNewBlock doing its own self-validation!
|
||||
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
{
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
|
||||
const CChainParams& chainparams = *chainParams;
|
||||
CScript scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate, pemptyblocktemplate;
|
||||
|
@ -14,7 +14,7 @@ BOOST_FIXTURE_TEST_SUITE(pow_tests, BasicTestingSetup)
|
||||
/* Test calculation of next difficulty target with DGW */
|
||||
BOOST_AUTO_TEST_CASE(get_next_work)
|
||||
{
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
|
||||
|
||||
// build the chain of 24 blocks
|
||||
CBlockIndex blockIndexLast;
|
||||
@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE(get_next_work)
|
||||
|
||||
// test special rules for slow blocks on devnet/testnet
|
||||
gArgs.SoftSetBoolArg("-devnet", true);
|
||||
const auto chainParamsDev = CreateChainParams(CBaseChainParams::DEVNET);
|
||||
const auto chainParamsDev = CreateChainParams(*m_node.args, CBaseChainParams::DEVNET);
|
||||
gArgs.ForceRemoveArg("devnet");
|
||||
|
||||
// make sure normal rules apply
|
||||
@ -142,7 +142,7 @@ BOOST_AUTO_TEST_CASE(get_next_work)
|
||||
/* Test the constraint on the upper bound for next work */
|
||||
// BOOST_AUTO_TEST_CASE(get_next_work_pow_limit)
|
||||
// {
|
||||
// const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
// const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
|
||||
|
||||
// int64_t nLastRetargetTime = 1231006505; // Block #0
|
||||
// CBlockIndex pindexLast;
|
||||
@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(get_next_work)
|
||||
/* Test the constraint on the lower bound for actual time taken */
|
||||
// BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual)
|
||||
// {
|
||||
// const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
// const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
|
||||
|
||||
// int64_t nLastRetargetTime = 1279008237; // Block #66528
|
||||
// CBlockIndex pindexLast;
|
||||
@ -168,7 +168,7 @@ BOOST_AUTO_TEST_CASE(get_next_work)
|
||||
/* Test the constraint on the upper bound for actual time taken */
|
||||
// BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
|
||||
// {
|
||||
// const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
// const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
|
||||
|
||||
// int64_t nLastRetargetTime = 1263163443; // NOTE: Not an actual block time
|
||||
// CBlockIndex pindexLast;
|
||||
@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE(get_next_work)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_negative_target)
|
||||
{
|
||||
const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
|
||||
const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus();
|
||||
uint256 hash;
|
||||
unsigned int nBits;
|
||||
nBits = UintToArith256(consensus.powLimit).GetCompact(true);
|
||||
@ -190,7 +190,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_negative_target)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_overflow_target)
|
||||
{
|
||||
const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
|
||||
const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus();
|
||||
uint256 hash;
|
||||
unsigned int nBits = ~0x00800000;
|
||||
hash.SetHex("0x1");
|
||||
@ -199,7 +199,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_overflow_target)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_too_easy_target)
|
||||
{
|
||||
const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
|
||||
const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus();
|
||||
uint256 hash;
|
||||
unsigned int nBits;
|
||||
arith_uint256 nBits_arith = UintToArith256(consensus.powLimit);
|
||||
@ -211,7 +211,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_too_easy_target)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_biger_hash_than_target)
|
||||
{
|
||||
const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
|
||||
const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus();
|
||||
uint256 hash;
|
||||
unsigned int nBits;
|
||||
arith_uint256 hash_arith = UintToArith256(consensus.powLimit);
|
||||
@ -223,7 +223,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_biger_hash_than_target)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_zero_target)
|
||||
{
|
||||
const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
|
||||
const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus();
|
||||
uint256 hash;
|
||||
unsigned int nBits;
|
||||
arith_uint256 hash_arith{0};
|
||||
@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_zero_target)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
|
||||
{
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
|
||||
std::vector<CBlockIndex> blocks(10000);
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
blocks[i].pprev = i ? &blocks[i - 1] : nullptr;
|
||||
|
@ -13,7 +13,7 @@ BOOST_FIXTURE_TEST_SUITE(subsidy_tests, TestingSetup)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(block_subsidy_test)
|
||||
{
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
|
||||
|
||||
uint32_t nPrevBits;
|
||||
int32_t nPrevHeight;
|
||||
|
@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(test_combiner_all)
|
||||
//! Test retrieval of valid assumeutxo values.
|
||||
BOOST_AUTO_TEST_CASE(test_assumeutxo)
|
||||
{
|
||||
const auto params = CreateChainParams(CBaseChainParams::REGTEST);
|
||||
const auto params = CreateChainParams(*m_node.args, CBaseChainParams::REGTEST);
|
||||
|
||||
// These heights don't have assumeutxo configurations associated, per the contents
|
||||
// of chainparams.cpp.
|
||||
|
@ -221,7 +221,7 @@ BOOST_AUTO_TEST_CASE(versionbits_test)
|
||||
}
|
||||
|
||||
// Sanity checks of version bit deployments
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
|
||||
const Consensus::Params &mainnetParams = chainParams->GetConsensus();
|
||||
for (int i=0; i<(int) Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) {
|
||||
uint32_t bitmask = g_versionbitscache.Mask(mainnetParams, static_cast<Consensus::DeploymentPos>(i));
|
||||
@ -248,7 +248,7 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
|
||||
{
|
||||
// Check that ComputeBlockVersion will set the appropriate bit correctly
|
||||
// on mainnet.
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
|
||||
const Consensus::Params &mainnetParams = chainParams->GetConsensus();
|
||||
|
||||
// Use the TESTDUMMY deployment for testing purposes.
|
||||
|
Loading…
Reference in New Issue
Block a user