Bitcoin ABC 0.32.4
P2P Digital Currency
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#include <util/chaintype.h>
13#include <validation.h>
14
15#include <test/util/blockindex.h>
16#include <test/util/setup_common.h>
17
18#include <boost/test/unit_test.hpp>
19
20using namespace avalanche;
21
22struct StakingRewardsActivationTestingSetup : public TestingSetup {
24 const bool expectActivation) {
25 SelectParams(chain_type);
26 const Consensus::Params &params = Params().GetConsensus();
27
28 // Before Cowperthwaite activation
29 const auto activationHeight = params.cowperthwaiteHeight;
30
31 CBlockIndex block;
32 block.nHeight = activationHeight - 1;
33 BOOST_CHECK(!IsStakingRewardsActivated(params, &block));
34
35 block.nHeight = activationHeight;
37 expectActivation);
38
39 block.nHeight = activationHeight + 1;
41 expectActivation);
42 }
43};
44
45BOOST_AUTO_TEST_SUITE(stakingrewards_tests)
46
47BOOST_FIXTURE_TEST_CASE(isstakingrewardsactivated,
49 checkStakingRewardsActivation(ChainType::REGTEST, false);
50 checkStakingRewardsActivation(ChainType::TESTNET, false);
51 checkStakingRewardsActivation(ChainType::MAIN, true);
52}
53
54BOOST_FIXTURE_TEST_CASE(stakecontender_computeid, TestChain100Setup) {
55 ChainstateManager &chainman = *Assert(m_node.chainman);
56 const CBlockIndex *chaintip =
57 WITH_LOCK(chainman.GetMutex(), return chainman.ActiveTip());
58
59 ProofId proofid1 = ProofId::fromHex(
60 "979dbc3b1351ee12f91f537e04e61fdf93a73d5ebfc317bccd12643b8be87b02");
62 "36653907336187a889c93bd9c75c0f3302ad5b24bdc0df51b4eaef914853d480",
63 StakeContenderId(chaintip->GetAncestor(0)->GetBlockHash(), proofid1)
64 .ToString());
65
66 // Different prevblock should give different hash
68 "f8535480ac419d395127f592c13be827cbbced02614d2c06e4a599eb1cf43034",
69 StakeContenderId(chaintip->GetBlockHash(), proofid1).ToString());
70
71 // So should a different proof id
72 ProofId proofid2 = ProofId::fromHex(
73 "e01bac293ed39e8d5e06214e7fe0bceb9646ef253ce501dcd7a475f802ab07f1");
75 "e4cafd6af9987403999ae77f3c622027ce765679ab068d215884253b547590f2",
76 StakeContenderId(chaintip->GetBlockHash(), proofid2).ToString());
77}
78
79BOOST_AUTO_TEST_SUITE_END()
void SelectParams(const ChainType chain)
Sets the params returned by Params() to those for the given BIP70 chain name.
Definition: chainparams.cpp:50
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:21
ChainType
Definition: chaintype.h:11
#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
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
Definition: blockindex.cpp:62
BlockHash GetBlockHash() const
Definition: blockindex.h:130
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:98
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1186
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
Definition: validation.h:1318
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1444
std::string ToString() const
Definition: uint256.h:80
NodeContext & m_node
Definition: interfaces.cpp:822
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
#define BOOST_CHECK(expr)
Definition: object.cpp:17
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 ChainType chain_type, const bool expectActivation)
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