Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
stakingrewards_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2023 The Bitcoin developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
8#include <chainparams.h>
10#include <net_processing.h>
12
13#include <test/util/blockindex.h>
14#include <test/util/setup_common.h>
15
16#include <boost/test/unit_test.hpp>
17
18using namespace avalanche;
19
20struct StakingRewardsActivationTestingSetup : public TestingSetup {
21 void checkStakingRewardsActivation(const std::string &net,
22 const bool expectActivation) {
24 const Consensus::Params &params = Params().GetConsensus();
25
26 // Before Cowperthwaite activation
27 const auto activationHeight = params.cowperthwaiteHeight;
28
29 CBlockIndex block;
30 block.nHeight = activationHeight - 1;
31 BOOST_CHECK(!IsStakingRewardsActivated(params, &block));
32
36
37 block.nHeight = activationHeight + 1;
40 }
41};
42
44
47 checkStakingRewardsActivation("regtest", false);
48 checkStakingRewardsActivation("test", false);
49 checkStakingRewardsActivation("main", true);
50}
51
53 ChainstateManager &chainman = *Assert(m_node.chainman);
54 const CBlockIndex *chaintip =
55 WITH_LOCK(chainman.GetMutex(), return chainman.ActiveTip());
56
58 "979dbc3b1351ee12f91f537e04e61fdf93a73d5ebfc317bccd12643b8be87b02");
60 "36653907336187a889c93bd9c75c0f3302ad5b24bdc0df51b4eaef914853d480",
61 StakeContenderId(chaintip->GetAncestor(0)->GetBlockHash(), proofid1)
62 .ToString());
63
64 // Different prevblock should give different hash
66 "f8535480ac419d395127f592c13be827cbbced02614d2c06e4a599eb1cf43034",
67 StakeContenderId(chaintip->GetBlockHash(), proofid1).ToString());
68
69 // So should a different proof id
71 "e01bac293ed39e8d5e06214e7fe0bceb9646ef253ce501dcd7a475f802ab07f1");
73 "e4cafd6af9987403999ae77f3c622027ce765679ab068d215884253b547590f2",
74 StakeContenderId(chaintip->GetBlockHash(), proofid2).ToString());
75}
76
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given BIP70 chain name.
const CChainParams & Params()
Return the currently selected parameters.
#define Assert(val)
Identity function.
Definition check.h:84
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition blockindex.h:25
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition blockindex.h:38
const Consensus::Params & GetConsensus() const
Definition chainparams.h:92
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
std::string ToString() const
Definition uint256.h:80
NodeContext & m_node
#define BOOST_CHECK_EQUAL(v1, v2)
Definition object.cpp:18
#define BOOST_CHECK(expr)
Definition object.cpp:17
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
bool IsStakingRewardsActivated(const Consensus::Params &params, const CBlockIndex *pprev)
BOOST_FIXTURE_TEST_CASE(isstakingrewardsactivated, StakingRewardsActivationTestingSetup)
Parameters that influence chain consensus.
Definition params.h:34
int cowperthwaiteHeight
Block height at which the Cowperthwaite activation becomes active.
Definition params.h:63
void checkStakingRewardsActivation(const std::string &net, const bool expectActivation)
static ProofId fromHex(const std::string &str)
Definition proofid.h:21
StakeContenderIds are unique for each block to ensure that the peer polling for their acceptance has ...
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition sync.h:357