Bitcoin ABC 0.30.7
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
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) {
23 SelectParams(net);
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
33 block.nHeight = activationHeight;
35 expectActivation);
36
37 block.nHeight = activationHeight + 1;
39 expectActivation);
40 }
41};
42
43BOOST_AUTO_TEST_SUITE(stakingrewards_tests)
44
45BOOST_FIXTURE_TEST_CASE(isstakingrewardsactivated,
47 checkStakingRewardsActivation("regtest", false);
48 checkStakingRewardsActivation("test", false);
49 checkStakingRewardsActivation("main", true);
50}
51
52BOOST_FIXTURE_TEST_CASE(stakecontender_computeid, TestChain100Setup) {
53 ChainstateManager &chainman = *Assert(m_node.chainman);
54 const CBlockIndex *chaintip =
55 WITH_LOCK(chainman.GetMutex(), return chainman.ActiveTip());
56
57 ProofId proofid1 = ProofId::fromHex(
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
70 ProofId proofid2 = ProofId::fromHex(
71 "e01bac293ed39e8d5e06214e7fe0bceb9646ef253ce501dcd7a475f802ab07f1");
73 "e4cafd6af9987403999ae77f3c622027ce765679ab068d215884253b547590f2",
74 StakeContenderId(chaintip->GetBlockHash(), proofid2).ToString());
75}
76
77BOOST_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:78
BlockHash GetBlockHash() const
Definition: blockindex.h:146
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...
Definition: validation.h:1219
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
Definition: validation.h:1343
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1435
std::string ToString() const
Definition: uint256.h:80
NodeContext & m_node
Definition: interfaces.cpp:785
#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