5#include <chainparams.h>
14#include <validation.h>
20#include <boost/test/unit_test.hpp>
29 CAmount nPreviousSubsidy = nInitialSubsidy * 2;
31 for (
int nHalvings = 0; nHalvings < maxHalvings; nHalvings++) {
32 int nHeight = nHalvings * consensusParams.nSubsidyHalvingInterval;
36 nPreviousSubsidy = nSubsidy;
63 nSum += nSubsidy * 1000;
72 signet_argsman.
ForceSetArg(
"-signetchallenge",
"51");
75 BOOST_CHECK(signet_params->GetConsensus().signet_challenge == std::vector<uint8_t>{OP_TRUE});
91 std::vector<uint8_t> witness_commitment_section_141{0xaa, 0x21, 0xa9, 0xed};
92 for (
int i = 0; i < 32; ++i) {
93 witness_commitment_section_141.push_back(0xff);
101 std::vector<uint8_t> witness_commitment_section_325{0xec, 0xc7, 0xda, 0xa2};
102 cb.
vout.at(0).scriptPubKey =
CScript{} <<
OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325;
108 witness_commitment_section_325.push_back(0x01);
109 witness_commitment_section_325.push_back(0x51);
110 cb.
vout.at(0).scriptPubKey =
CScript{} <<
OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325;
116 witness_commitment_section_325.push_back(0x00);
117 cb.
vout.at(0).scriptPubKey =
CScript{} <<
OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325;
123 witness_commitment_section_325.push_back(0x00);
124 cb.
vout.at(0).scriptPubKey =
CScript{} <<
OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325;
137 std::vector<int> bad_heights{0, 100, 111, 115, 209, 211};
139 for (
auto empty : bad_heights) {
140 const auto out = params->AssumeutxoForHeight(empty);
144 const auto out110 = *params->AssumeutxoForHeight(110);
145 BOOST_CHECK_EQUAL(out110.hash_serialized.ToString(),
"6657b736d4fe4db0cbc796789e812d5dba7f5c143764b1b6905612f1830609d1");
148 const auto out110_2 = *params->AssumeutxoForBlockhash(
uint256{
"696e92821f65549c7ee134edceeeeaaa4105647a3c4fd9f298c0aec0ab50425c"});
149 BOOST_CHECK_EQUAL(out110_2.hash_serialized.ToString(),
"6657b736d4fe4db0cbc796789e812d5dba7f5c143764b1b6905612f1830609d1");
157 auto is_mutated = [](
CBlock& block,
bool check_witness_root) {
164 auto is_not_mutated = [&is_mutated](
CBlock& block,
bool check_witness_root) {
165 return !is_mutated(block, check_witness_root);
174 auto create_coinbase_tx = [](
bool include_witness =
false) {
176 coinbase.
vin.resize(1);
177 if (include_witness) {
178 coinbase.
vin[0].scriptWitness.stack.resize(1);
179 coinbase.
vin[0].scriptWitness.stack[0] = std::vector<unsigned char>(32, 0x00);
182 coinbase.
vout.resize(1);
185 coinbase.
vout[0].scriptPubKey[1] = 0x24;
186 coinbase.
vout[0].scriptPubKey[2] = 0xaa;
187 coinbase.
vout[0].scriptPubKey[3] = 0x21;
188 coinbase.
vout[0].scriptPubKey[4] = 0xa9;
189 coinbase.
vout[0].scriptPubKey[5] = 0xed;
195 auto insert_witness_commitment = [](
CBlock& block,
uint256 commitment) {
196 assert(!block.
vtx.empty() && block.
vtx[0]->IsCoinBase() && !block.
vtx[0]->vout.empty());
200 memcpy(&mtx.vout[0].scriptPubKey[6], commitment.begin(), 32);
216 block.
vtx.push_back(create_coinbase_tx());
228 hasher.
write(block.
vtx[0]->GetHash());
229 hasher.
write(block.
vtx[1]->GetHash());
235 block.
vtx[1] = block.
vtx[0];
237 hasher.
write(block.
vtx[0]->GetHash());
238 hasher.
write(block.
vtx[1]->GetHash());
249 mtx.
vout[0].scriptPubKey.resize(4);
282 BOOST_CHECK(
DecodeHexTx(tx3,
"cdaf22d00002c6a7f848f8ae4d30054e61dcf3303d6fe01d282163341f06feecc10032b3160fcab87bdfe3ecfb769206ef2d991b92f8a268e423a6ef4d485f06",
true,
false));
311 block.
vtx.push_back(create_coinbase_tx(
true));
315 mtx.
vin[0].scriptWitness.stack.resize(1);
316 mtx.
vin[0].scriptWitness.stack[0] = {0};
329 insert_witness_commitment(block, commitment);
337 assert(!mtx.vin[0].scriptWitness.stack[0].empty());
338 ++mtx.vin[0].scriptWitness.stack[0][0];
347 insert_witness_commitment(block, commitment);
355 mtx.vin[0].scriptWitness.stack.resize(0);
bool MoneyRange(const CAmount &nValue)
int64_t CAmount
Amount in satoshis (Can be negative)
static constexpr CAmount COIN
The amount of satoshis in one BTC.
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const ChainType chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
const CChainParams & Params()
Return the currently selected parameters.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
bool m_checked_merkle_root
std::vector< CTransactionRef > vtx
bool m_checked_witness_commitment
A hasher class for Bitcoin's 256-bit hash (double SHA-256).
void Finalize(Span< unsigned char > output)
CHash256 & Write(Span< const unsigned char > input)
Serialized script, used inside transaction inputs and outputs.
A writer stream (for serialization) that computes a 256-bit hash.
void write(Span< const std::byte > src)
uint256 GetHash()
Compute the double-SHA256 hash of all data written to this object.
static std::optional< SignetTxs > Create(const CBlock &block, const CScript &challenge)
static constexpr size_t MINIMUM_WITNESS_COMMITMENT
Minimum size of a witness commitment structure.
bool DecodeHexTx(CMutableTransaction &tx, const std::string &hex_tx, bool try_no_witness=false, bool try_witness=true)
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
uint256 BlockWitnessMerkleRoot(const CBlock &block, bool *mutated)
Transaction validation functions.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static constexpr TransactionSerParams TX_NO_WITNESS
static CTransactionRef MakeTransactionRef(Tx &&txIn)
size_t GetSerializeSize(const T &t)
bool CheckSignetBlockSolution(const CBlock &block, const Consensus::Params &consensusParams)
Extract signature and check whether a block has a valid solution.
A mutable version of CTransaction.
std::vector< CTxOut > vout
Txid GetHash() const
Compute the hash of this CMutableTransaction.
Parameters that influence chain consensus.
int nSubsidyHalvingInterval
Testing setup that configures a complete environment.
bool IsBlockMutated(const CBlock &block, bool check_witness_root)
Check if a block has been mutated (with respect to its merkle root and witness commitments).
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
static void TestBlockSubsidyHalvings(const Consensus::Params &consensusParams)
BOOST_AUTO_TEST_CASE(block_subsidy_test)