Bitcoin ABC 0.31.2
P2P Digital Currency
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 <validation.h>
13
14#include <test/util/blockindex.h>
15#include <test/util/setup_common.h>
16
17#include <boost/test/unit_test.hpp>
18
19using namespace avalanche;
20
21struct StakingRewardsActivationTestingSetup : public TestingSetup {
22 void checkStakingRewardsActivation(const std::string &net,
23 const bool expectActivation) {
24 SelectParams(net);
25 const Consensus::Params &params = Params().GetConsensus();
26
27 // Before Cowperthwaite activation
28 const auto activationHeight = params.cowperthwaiteHeight;
29
30 CBlockIndex block;
31 block.nHeight = activationHeight - 1;
32 BOOST_CHECK(!IsStakingRewardsActivated(params, &block));
33
34 block.nHeight = activationHeight;
36 expectActivation);
37
38 block.nHeight = activationHeight + 1;
40 expectActivation);
41 }
42};
43
44BOOST_AUTO_TEST_SUITE(stakingrewards_tests)
45
46BOOST_FIXTURE_TEST_CASE(isstakingrewardsactivated,
48 checkStakingRewardsActivation("regtest", false);
49 checkStakingRewardsActivation("test", false);
50 checkStakingRewardsActivation("main", true);
51}
52
53BOOST_FIXTURE_TEST_CASE(stakecontender_computeid, TestChain100Setup) {
54 ChainstateManager &chainman = *Assert(m_node.chainman);
55 const CBlockIndex *chaintip =
56 WITH_LOCK(chainman.GetMutex(), return chainman.ActiveTip());
57
58 ProofId proofid1 = ProofId::fromHex(
59 "979dbc3b1351ee12f91f537e04e61fdf93a73d5ebfc317bccd12643b8be87b02");
61 "36653907336187a889c93bd9c75c0f3302ad5b24bdc0df51b4eaef914853d480",
62 StakeContenderId(chaintip->GetAncestor(0)->GetBlockHash(), proofid1)
63 .ToString());
64
65 // Different prevblock should give different hash
67 "f8535480ac419d395127f592c13be827cbbced02614d2c06e4a599eb1cf43034",
68 StakeContenderId(chaintip->GetBlockHash(), proofid1).ToString());
69
70 // So should a different proof id
71 ProofId proofid2 = ProofId::fromHex(
72 "e01bac293ed39e8d5e06214e7fe0bceb9646ef253ce501dcd7a475f802ab07f1");
74 "e4cafd6af9987403999ae77f3c622027ce765679ab068d215884253b547590f2",
75 StakeContenderId(chaintip->GetBlockHash(), proofid2).ToString());
76}
77
78BOOST_AUTO_TEST_SUITE_END()
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given BIP70 chain name.
Definition: chainparams.cpp:51
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:19
#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:97
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1149
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
Definition: validation.h:1279
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1404
std::string ToString() const
Definition: uint256.h:80
NodeContext & m_node
Definition: interfaces.cpp:815
#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 std::string &net, 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