mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
Merge bitcoin/bitcoin#21840: test: Misc refactor to get rid of &foo[0] raw pointers
fa8a88849c08c810a82338bf0e70738eb6748906 bench: Remove duplicate constants (MarcoFalke) 000098f9647cd2e21660603b7d7a8f623f70f673 test: Use throwing variant accessor (MarcoFalke) fa2197c8b3178787d99e2acb5c3c717df14ddabf test: Use loop to register RPCs (MarcoFalke) Pull request description: Simplify test code ACKs for top commit: Empact: Code Review ACK fa8a88849c08c810a82338bf0e70738eb6748906 practicalswift: cr ACK fa8a88849c08c810a82338bf0e70738eb6748906 promag: Code review ACK fa8a88849c08c810a82338bf0e70738eb6748906. Tree-SHA512: 6a5bebaa9a3f43e9c332f4fbff606e9ece6dc8b95a769980082cc022f8e9bde6083c1e4a0145dcbf3741f514d6e97b4198f201a1bf1370ebf43bd3a5c0f85981
This commit is contained in:
parent
7522ee9868
commit
5d10b41302
@ -7,6 +7,7 @@
|
|||||||
#include <consensus/validation.h>
|
#include <consensus/validation.h>
|
||||||
#include <script/standard.h>
|
#include <script/standard.h>
|
||||||
#include <test/util/mining.h>
|
#include <test/util/mining.h>
|
||||||
|
#include <test/util/script.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <test/util/wallet.h>
|
#include <test/util/wallet.h>
|
||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
@ -31,7 +32,7 @@ static void AssembleBlock(benchmark::Bench& bench)
|
|||||||
std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
|
std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
|
||||||
for (size_t b{0}; b < NUM_BLOCKS; ++b) {
|
for (size_t b{0}; b < NUM_BLOCKS; ++b) {
|
||||||
CMutableTransaction tx;
|
CMutableTransaction tx;
|
||||||
tx.vin.push_back(MineBlock(test_setup->m_node, SCRIPT_PUB));
|
tx.vin.push_back(MineBlock(test_setup->m_node, P2SH_OP_TRUE));
|
||||||
tx.vin.back().scriptSig = scriptSig;
|
tx.vin.back().scriptSig = scriptSig;
|
||||||
tx.vout.emplace_back(1337, SCRIPT_PUB);
|
tx.vout.emplace_back(1337, SCRIPT_PUB);
|
||||||
if (NUM_BLOCKS - b >= COINBASE_MATURITY)
|
if (NUM_BLOCKS - b >= COINBASE_MATURITY)
|
||||||
@ -47,7 +48,7 @@ static void AssembleBlock(benchmark::Bench& bench)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bench.minEpochIterations(700).run([&] {
|
bench.minEpochIterations(700).run([&] {
|
||||||
PrepareBlock(test_setup->m_node, SCRIPT_PUB);
|
PrepareBlock(test_setup->m_node, P2SH_OP_TRUE);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
|
|
||||||
#include <llmq/context.h>
|
|
||||||
|
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -37,14 +35,16 @@ static RPCHelpMan rpcNestedTest_rpc()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const CRPCCommand vRPCCommands[] = {
|
static const CRPCCommand vRPCCommands[] = {
|
||||||
{"test", &rpcNestedTest_rpc},
|
{"rpcNestedTest", &rpcNestedTest_rpc},
|
||||||
};
|
};
|
||||||
|
|
||||||
void RPCNestedTests::rpcNestedTests()
|
void RPCNestedTests::rpcNestedTests()
|
||||||
{
|
{
|
||||||
// do some test setup
|
// do some test setup
|
||||||
// could be moved to a more generic place when we add more tests on QT level
|
// could be moved to a more generic place when we add more tests on QT level
|
||||||
tableRPC.appendCommand("rpcNestedTest", &vRPCCommands[0]);
|
for (const auto& c : vRPCCommands) {
|
||||||
|
tableRPC.appendCommand(c.name, &c);
|
||||||
|
}
|
||||||
|
|
||||||
TestingSetup test;
|
TestingSetup test;
|
||||||
m_node.setContext(&test.m_node);
|
m_node.setContext(&test.m_node);
|
||||||
|
@ -159,23 +159,20 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
|
|||||||
s.clear();
|
s.clear();
|
||||||
s << ToByteVector(pubkey) << OP_CHECKSIG;
|
s << ToByteVector(pubkey) << OP_CHECKSIG;
|
||||||
BOOST_CHECK(ExtractDestination(s, address));
|
BOOST_CHECK(ExtractDestination(s, address));
|
||||||
BOOST_CHECK(std::get_if<PKHash>(&address) &&
|
BOOST_CHECK(std::get<PKHash>(address) == PKHash(pubkey));
|
||||||
*std::get_if<PKHash>(&address) == PKHash(pubkey));
|
|
||||||
|
|
||||||
// TxoutType::PUBKEYHASH
|
// TxoutType::PUBKEYHASH
|
||||||
s.clear();
|
s.clear();
|
||||||
s << OP_DUP << OP_HASH160 << ToByteVector(pubkey.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
|
s << OP_DUP << OP_HASH160 << ToByteVector(pubkey.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||||
BOOST_CHECK(ExtractDestination(s, address));
|
BOOST_CHECK(ExtractDestination(s, address));
|
||||||
BOOST_CHECK(std::get_if<PKHash>(&address) &&
|
BOOST_CHECK(std::get<PKHash>(address) == PKHash(pubkey));
|
||||||
*std::get_if<PKHash>(&address) == PKHash(pubkey));
|
|
||||||
|
|
||||||
// TxoutType::SCRIPTHASH
|
// TxoutType::SCRIPTHASH
|
||||||
CScript redeemScript(s); // initialize with leftover P2PKH script
|
CScript redeemScript(s); // initialize with leftover P2PKH script
|
||||||
s.clear();
|
s.clear();
|
||||||
s << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL;
|
s << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL;
|
||||||
BOOST_CHECK(ExtractDestination(s, address));
|
BOOST_CHECK(ExtractDestination(s, address));
|
||||||
BOOST_CHECK(std::get_if<ScriptHash>(&address) &&
|
BOOST_CHECK(std::get<ScriptHash>(address) == ScriptHash(redeemScript));
|
||||||
*std::get_if<ScriptHash>(&address) == ScriptHash(redeemScript));
|
|
||||||
|
|
||||||
// TxoutType::MULTISIG
|
// TxoutType::MULTISIG
|
||||||
s.clear();
|
s.clear();
|
||||||
@ -209,8 +206,7 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
|
|||||||
BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEY);
|
BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEY);
|
||||||
BOOST_CHECK_EQUAL(addresses.size(), 1U);
|
BOOST_CHECK_EQUAL(addresses.size(), 1U);
|
||||||
BOOST_CHECK_EQUAL(nRequired, 1);
|
BOOST_CHECK_EQUAL(nRequired, 1);
|
||||||
BOOST_CHECK(std::get_if<PKHash>(&addresses[0]) &&
|
BOOST_CHECK(std::get<PKHash>(addresses[0]) == PKHash(pubkeys[0]));
|
||||||
*std::get_if<PKHash>(&addresses[0]) == PKHash(pubkeys[0]));
|
|
||||||
|
|
||||||
// TxoutType::PUBKEYHASH
|
// TxoutType::PUBKEYHASH
|
||||||
s.clear();
|
s.clear();
|
||||||
@ -219,8 +215,7 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
|
|||||||
BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEYHASH);
|
BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEYHASH);
|
||||||
BOOST_CHECK_EQUAL(addresses.size(), 1U);
|
BOOST_CHECK_EQUAL(addresses.size(), 1U);
|
||||||
BOOST_CHECK_EQUAL(nRequired, 1);
|
BOOST_CHECK_EQUAL(nRequired, 1);
|
||||||
BOOST_CHECK(std::get_if<PKHash>(&addresses[0]) &&
|
BOOST_CHECK(std::get<PKHash>(addresses[0]) == PKHash(pubkeys[0]));
|
||||||
*std::get_if<PKHash>(&addresses[0]) == PKHash(pubkeys[0]));
|
|
||||||
|
|
||||||
// TxoutType::SCRIPTHASH
|
// TxoutType::SCRIPTHASH
|
||||||
CScript redeemScript(s); // initialize with leftover P2PKH script
|
CScript redeemScript(s); // initialize with leftover P2PKH script
|
||||||
@ -230,8 +225,7 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
|
|||||||
BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
|
BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
|
||||||
BOOST_CHECK_EQUAL(addresses.size(), 1U);
|
BOOST_CHECK_EQUAL(addresses.size(), 1U);
|
||||||
BOOST_CHECK_EQUAL(nRequired, 1);
|
BOOST_CHECK_EQUAL(nRequired, 1);
|
||||||
BOOST_CHECK(std::get_if<ScriptHash>(&addresses[0]) &&
|
BOOST_CHECK(std::get<ScriptHash>(addresses[0]) == ScriptHash(redeemScript));
|
||||||
*std::get_if<ScriptHash>(&addresses[0]) == ScriptHash(redeemScript));
|
|
||||||
|
|
||||||
// TxoutType::MULTISIG
|
// TxoutType::MULTISIG
|
||||||
s.clear();
|
s.clear();
|
||||||
@ -243,10 +237,8 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
|
|||||||
BOOST_CHECK_EQUAL(whichType, TxoutType::MULTISIG);
|
BOOST_CHECK_EQUAL(whichType, TxoutType::MULTISIG);
|
||||||
BOOST_CHECK_EQUAL(addresses.size(), 2U);
|
BOOST_CHECK_EQUAL(addresses.size(), 2U);
|
||||||
BOOST_CHECK_EQUAL(nRequired, 2);
|
BOOST_CHECK_EQUAL(nRequired, 2);
|
||||||
BOOST_CHECK(std::get_if<PKHash>(&addresses[0]) &&
|
BOOST_CHECK(std::get<PKHash>(addresses[0]) == PKHash(pubkeys[0]));
|
||||||
*std::get_if<PKHash>(&addresses[0]) == PKHash(pubkeys[0]));
|
BOOST_CHECK(std::get<PKHash>(addresses[1]) == PKHash(pubkeys[1]));
|
||||||
BOOST_CHECK(std::get_if<PKHash>(&addresses[1]) &&
|
|
||||||
*std::get_if<PKHash>(&addresses[1]) == PKHash(pubkeys[1]));
|
|
||||||
|
|
||||||
// TxoutType::NULL_DATA
|
// TxoutType::NULL_DATA
|
||||||
s.clear();
|
s.clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user