mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-08 14:10:16 +02: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:
commit
e2d4e67a8f
@ -6,6 +6,7 @@
|
|||||||
#include <consensus/validation.h>
|
#include <consensus/validation.h>
|
||||||
#include <crypto/sha256.h>
|
#include <crypto/sha256.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>
|
||||||
@ -18,23 +19,17 @@ static void AssembleBlock(benchmark::Bench& bench)
|
|||||||
{
|
{
|
||||||
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
|
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
|
||||||
|
|
||||||
const std::vector<unsigned char> op_true{OP_TRUE};
|
|
||||||
CScriptWitness witness;
|
CScriptWitness witness;
|
||||||
witness.stack.push_back(op_true);
|
witness.stack.push_back(WITNESS_STACK_ELEM_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()}};
|
|
||||||
|
|
||||||
// Collect some loose transactions that spend the coinbases of our mined blocks
|
// Collect some loose transactions that spend the coinbases of our mined blocks
|
||||||
constexpr size_t NUM_BLOCKS{200};
|
constexpr size_t NUM_BLOCKS{200};
|
||||||
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, P2WSH_OP_TRUE));
|
||||||
tx.vin.back().scriptWitness = witness;
|
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)
|
if (NUM_BLOCKS - b >= COINBASE_MATURITY)
|
||||||
txs.at(b) = MakeTransactionRef(tx);
|
txs.at(b) = MakeTransactionRef(tx);
|
||||||
}
|
}
|
||||||
@ -48,7 +43,7 @@ static void AssembleBlock(benchmark::Bench& bench)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bench.run([&] {
|
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[] = {
|
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);
|
||||||
|
@ -199,23 +199,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();
|
||||||
@ -233,7 +230,7 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
|
|||||||
BOOST_CHECK(ExtractDestination(s, address));
|
BOOST_CHECK(ExtractDestination(s, address));
|
||||||
WitnessV0KeyHash keyhash;
|
WitnessV0KeyHash keyhash;
|
||||||
CHash160().Write(pubkey).Finalize(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
|
// TxoutType::WITNESS_V0_SCRIPTHASH
|
||||||
s.clear();
|
s.clear();
|
||||||
@ -241,7 +238,7 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
|
|||||||
CSHA256().Write(redeemScript.data(), redeemScript.size()).Finalize(scripthash.begin());
|
CSHA256().Write(redeemScript.data(), redeemScript.size()).Finalize(scripthash.begin());
|
||||||
s << OP_0 << ToByteVector(scripthash);
|
s << OP_0 << ToByteVector(scripthash);
|
||||||
BOOST_CHECK(ExtractDestination(s, address));
|
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
|
// TxoutType::WITNESS_UNKNOWN with unknown version
|
||||||
s.clear();
|
s.clear();
|
||||||
@ -251,7 +248,7 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
|
|||||||
unk.length = 33;
|
unk.length = 33;
|
||||||
unk.version = 1;
|
unk.version = 1;
|
||||||
std::copy(pubkey.begin(), pubkey.end(), unk.program);
|
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)
|
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(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();
|
||||||
@ -285,8 +281,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
|
||||||
@ -296,8 +291,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();
|
||||||
@ -309,10 +303,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…
x
Reference in New Issue
Block a user