mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-03 07:52:33 +02:00
Merge bitcoin/bitcoin#21840: test: Misc refactor to get rid of &foo[0] raw pointers
fa8a88849c
bench: Remove duplicate constants (MarcoFalke)000098f964
test: Use throwing variant accessor (MarcoFalke)fa2197c8b3
test: Use loop to register RPCs (MarcoFalke) Pull request description: Simplify test code ACKs for top commit: Empact: Code Review ACKfa8a88849c
practicalswift: cr ACKfa8a88849c
promag: Code review ACKfa8a88849c
. Tree-SHA512: 6a5bebaa9a3f43e9c332f4fbff606e9ece6dc8b95a769980082cc022f8e9bde6083c1e4a0145dcbf3741f514d6e97b4198f201a1bf1370ebf43bd3a5c0f85981
This commit is contained in:
commit
e2d4e67a8f
@ -6,6 +6,7 @@
|
||||
#include <consensus/validation.h>
|
||||
#include <crypto/sha256.h>
|
||||
#include <test/util/mining.h>
|
||||
#include <test/util/script.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/wallet.h>
|
||||
#include <txmempool.h>
|
||||
@ -18,23 +19,17 @@ static void AssembleBlock(benchmark::Bench& bench)
|
||||
{
|
||||
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
|
||||
|
||||
const std::vector<unsigned char> op_true{OP_TRUE};
|
||||
CScriptWitness witness;
|
||||
witness.stack.push_back(op_true);
|
||||
|
||||
uint256 witness_program;
|
||||
CSHA256().Write(&op_true[0], op_true.size()).Finalize(witness_program.begin());
|
||||
|
||||
const CScript SCRIPT_PUB{CScript(OP_0) << std::vector<unsigned char>{witness_program.begin(), witness_program.end()}};
|
||||
witness.stack.push_back(WITNESS_STACK_ELEM_OP_TRUE);
|
||||
|
||||
// Collect some loose transactions that spend the coinbases of our mined blocks
|
||||
constexpr size_t NUM_BLOCKS{200};
|
||||
std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
|
||||
for (size_t b{0}; b < NUM_BLOCKS; ++b) {
|
||||
CMutableTransaction tx;
|
||||
tx.vin.push_back(MineBlock(test_setup->m_node, SCRIPT_PUB));
|
||||
tx.vin.push_back(MineBlock(test_setup->m_node, P2WSH_OP_TRUE));
|
||||
tx.vin.back().scriptWitness = witness;
|
||||
tx.vout.emplace_back(1337, SCRIPT_PUB);
|
||||
tx.vout.emplace_back(1337, P2WSH_OP_TRUE);
|
||||
if (NUM_BLOCKS - b >= COINBASE_MATURITY)
|
||||
txs.at(b) = MakeTransactionRef(tx);
|
||||
}
|
||||
@ -48,7 +43,7 @@ static void AssembleBlock(benchmark::Bench& bench)
|
||||
}
|
||||
|
||||
bench.run([&] {
|
||||
PrepareBlock(test_setup->m_node, SCRIPT_PUB);
|
||||
PrepareBlock(test_setup->m_node, P2WSH_OP_TRUE);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -35,14 +35,16 @@ static RPCHelpMan rpcNestedTest_rpc()
|
||||
}
|
||||
|
||||
static const CRPCCommand vRPCCommands[] = {
|
||||
{"test", &rpcNestedTest_rpc},
|
||||
{"rpcNestedTest", &rpcNestedTest_rpc},
|
||||
};
|
||||
|
||||
void RPCNestedTests::rpcNestedTests()
|
||||
{
|
||||
// do some test setup
|
||||
// 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;
|
||||
m_node.setContext(&test.m_node);
|
||||
|
@ -199,23 +199,20 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
|
||||
s.clear();
|
||||
s << ToByteVector(pubkey) << OP_CHECKSIG;
|
||||
BOOST_CHECK(ExtractDestination(s, address));
|
||||
BOOST_CHECK(std::get_if<PKHash>(&address) &&
|
||||
*std::get_if<PKHash>(&address) == PKHash(pubkey));
|
||||
BOOST_CHECK(std::get<PKHash>(address) == PKHash(pubkey));
|
||||
|
||||
// TxoutType::PUBKEYHASH
|
||||
s.clear();
|
||||
s << OP_DUP << OP_HASH160 << ToByteVector(pubkey.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
BOOST_CHECK(ExtractDestination(s, address));
|
||||
BOOST_CHECK(std::get_if<PKHash>(&address) &&
|
||||
*std::get_if<PKHash>(&address) == PKHash(pubkey));
|
||||
BOOST_CHECK(std::get<PKHash>(address) == PKHash(pubkey));
|
||||
|
||||
// TxoutType::SCRIPTHASH
|
||||
CScript redeemScript(s); // initialize with leftover P2PKH script
|
||||
s.clear();
|
||||
s << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL;
|
||||
BOOST_CHECK(ExtractDestination(s, address));
|
||||
BOOST_CHECK(std::get_if<ScriptHash>(&address) &&
|
||||
*std::get_if<ScriptHash>(&address) == ScriptHash(redeemScript));
|
||||
BOOST_CHECK(std::get<ScriptHash>(address) == ScriptHash(redeemScript));
|
||||
|
||||
// TxoutType::MULTISIG
|
||||
s.clear();
|
||||
@ -233,7 +230,7 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
|
||||
BOOST_CHECK(ExtractDestination(s, address));
|
||||
WitnessV0KeyHash keyhash;
|
||||
CHash160().Write(pubkey).Finalize(keyhash);
|
||||
BOOST_CHECK(std::get_if<WitnessV0KeyHash>(&address) && *std::get_if<WitnessV0KeyHash>(&address) == keyhash);
|
||||
BOOST_CHECK(std::get<WitnessV0KeyHash>(address) == keyhash);
|
||||
|
||||
// TxoutType::WITNESS_V0_SCRIPTHASH
|
||||
s.clear();
|
||||
@ -241,7 +238,7 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
|
||||
CSHA256().Write(redeemScript.data(), redeemScript.size()).Finalize(scripthash.begin());
|
||||
s << OP_0 << ToByteVector(scripthash);
|
||||
BOOST_CHECK(ExtractDestination(s, address));
|
||||
BOOST_CHECK(std::get_if<WitnessV0ScriptHash>(&address) && *std::get_if<WitnessV0ScriptHash>(&address) == scripthash);
|
||||
BOOST_CHECK(std::get<WitnessV0ScriptHash>(address) == scripthash);
|
||||
|
||||
// TxoutType::WITNESS_UNKNOWN with unknown version
|
||||
s.clear();
|
||||
@ -251,7 +248,7 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
|
||||
unk.length = 33;
|
||||
unk.version = 1;
|
||||
std::copy(pubkey.begin(), pubkey.end(), unk.program);
|
||||
BOOST_CHECK(std::get_if<WitnessUnknown>(&address) && *std::get_if<WitnessUnknown>(&address) == unk);
|
||||
BOOST_CHECK(std::get<WitnessUnknown>(address) == unk);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
|
||||
@ -275,8 +272,7 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
|
||||
BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEY);
|
||||
BOOST_CHECK_EQUAL(addresses.size(), 1U);
|
||||
BOOST_CHECK_EQUAL(nRequired, 1);
|
||||
BOOST_CHECK(std::get_if<PKHash>(&addresses[0]) &&
|
||||
*std::get_if<PKHash>(&addresses[0]) == PKHash(pubkeys[0]));
|
||||
BOOST_CHECK(std::get<PKHash>(addresses[0]) == PKHash(pubkeys[0]));
|
||||
|
||||
// TxoutType::PUBKEYHASH
|
||||
s.clear();
|
||||
@ -285,8 +281,7 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
|
||||
BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEYHASH);
|
||||
BOOST_CHECK_EQUAL(addresses.size(), 1U);
|
||||
BOOST_CHECK_EQUAL(nRequired, 1);
|
||||
BOOST_CHECK(std::get_if<PKHash>(&addresses[0]) &&
|
||||
*std::get_if<PKHash>(&addresses[0]) == PKHash(pubkeys[0]));
|
||||
BOOST_CHECK(std::get<PKHash>(addresses[0]) == PKHash(pubkeys[0]));
|
||||
|
||||
// TxoutType::SCRIPTHASH
|
||||
CScript redeemScript(s); // initialize with leftover P2PKH script
|
||||
@ -296,8 +291,7 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
|
||||
BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
|
||||
BOOST_CHECK_EQUAL(addresses.size(), 1U);
|
||||
BOOST_CHECK_EQUAL(nRequired, 1);
|
||||
BOOST_CHECK(std::get_if<ScriptHash>(&addresses[0]) &&
|
||||
*std::get_if<ScriptHash>(&addresses[0]) == ScriptHash(redeemScript));
|
||||
BOOST_CHECK(std::get<ScriptHash>(addresses[0]) == ScriptHash(redeemScript));
|
||||
|
||||
// TxoutType::MULTISIG
|
||||
s.clear();
|
||||
@ -309,10 +303,8 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
|
||||
BOOST_CHECK_EQUAL(whichType, TxoutType::MULTISIG);
|
||||
BOOST_CHECK_EQUAL(addresses.size(), 2U);
|
||||
BOOST_CHECK_EQUAL(nRequired, 2);
|
||||
BOOST_CHECK(std::get_if<PKHash>(&addresses[0]) &&
|
||||
*std::get_if<PKHash>(&addresses[0]) == PKHash(pubkeys[0]));
|
||||
BOOST_CHECK(std::get_if<PKHash>(&addresses[1]) &&
|
||||
*std::get_if<PKHash>(&addresses[1]) == PKHash(pubkeys[1]));
|
||||
BOOST_CHECK(std::get<PKHash>(addresses[0]) == PKHash(pubkeys[0]));
|
||||
BOOST_CHECK(std::get<PKHash>(addresses[1]) == PKHash(pubkeys[1]));
|
||||
|
||||
// TxoutType::NULL_DATA
|
||||
s.clear();
|
||||
|
Loading…
Reference in New Issue
Block a user