Skip to content

Commit

Permalink
Fix for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
psolstice committed Sep 2, 2024
1 parent 29666c7 commit a1e9870
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,15 +1052,15 @@ class CRegTestParams : public CChainParams {
consensus.stage2DevelopmentFundShare = 15;
consensus.stage2ZnodeShare = 35;

consensus.stage3StartTime = INT_MAX;
consensus.stage3StartBlock = 2000;
consensus.stage3StartTime = 0;
consensus.stage3StartBlock = 1500;
consensus.stage3DevelopmentFundShare = 15;
consensus.stage3CommunityFundShare = 10;
consensus.stage3MasternodeShare = 50;
consensus.stage3DevelopmentFundAddress = "TGEGf26GwyUBE2P2o2beBAfE9Y438dCp5t"; // private key cMrz8Df36VR9TvZjtvSqLPhUQR7pcpkXRXaLNYUxfkKsRuCzHpAN
consensus.stage3CommunityFundAddress = "TJmPzeJF4DECrBwUftc265U7rTPxKmpa4F"; // private key cTyPWqTMM1CgT5qy3K3LSgC1H6Q2RHvnXZHvjWtKB4vq9qXqKmMu

consensus.stage4StartBlock = consensus.nSubsidyHalvingSecond;
consensus.stage4StartBlock = consensus.nSubsidyHalvingSecond + 500;
consensus.stage4CommunityFundShare = 15;
consensus.stage4DevelopmentFundShare = 25;
consensus.stage4MasternodeShare = 50;
Expand Down
43 changes: 23 additions & 20 deletions src/test/firsthalving_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ BOOST_FIXTURE_TEST_CASE(devpayout, TestChainDIP3BeforeActivationSetup)

consensusParams.nSubsidyHalvingFirst = 600;
consensusParams.stage3StartTime = INT_MAX;
consensusParams.nSubsidyHalvingSecond = 620;
consensusParams.nSubsidyHalvingSecond = consensusParams.stage4StartBlock = 620;
consensusParams.nSubsidyHalvingInterval = 10;

CScript devPayoutScript = GenerateRandomAddress();
Expand Down Expand Up @@ -225,6 +225,8 @@ BOOST_FIXTURE_TEST_CASE(devpayout, TestChainDIP3BeforeActivationSetup)

// initiate stage3
consensusParams.stage3StartTime = GetTime();
consensusParams.stage3StartBlock = chainActive.Height();

// for stage3 there is dev payout and community payout
for (int i=610; i<620; i++) {
CBlock block = CreateAndProcessBlock({}, coinbaseKey);
Expand Down Expand Up @@ -259,39 +261,39 @@ BOOST_FIXTURE_TEST_CASE(devpayout, TestChainDIP3BeforeActivationSetup)
CAmount nValue;
auto dmnPayout = FindPayoutDmn(block, nValue);

BOOST_ASSERT(dmnPayout != nullptr && nValue == 3125*COIN/1000); // 3.125 (6.25*0.5)
// stage 4: no real halving here
BOOST_ASSERT(dmnPayout != nullptr && nValue == 625*COIN/100); // 6.25

// there should be no more payment to devs fund
for (const CTxOut &txout: block.vtx[0]->vout) {
BOOST_ASSERT(txout.scriptPubKey != GetScriptForDestination(CBitcoinAddress(consensusParams.stage2DevelopmentFundAddress).Get()));
}

// miner's reward should be 6.25-3.125 = 3.125
BOOST_ASSERT(block.vtx[0]->vout[0].nValue == 3125*COIN/1000);
// should be only 2 vouts in coinbase
BOOST_ASSERT(block.vtx[0]->vout.size() == 2);
// miner's reward should be 1.25 (10%)
BOOST_ASSERT(block.vtx[0]->vout[0].nValue == 125*COIN/100);

bool paymentToDevFound = false, paymentToCommunityFound = false;
for (const CTxOut &txout: block.vtx[0]->vout) {
if (txout.scriptPubKey == GetScriptForDestination(CBitcoinAddress(consensusParams.stage3DevelopmentFundAddress).Get())) {
BOOST_ASSERT(txout.nValue == 3125*COIN/1000); // 25/2*0.25
paymentToDevFound = true;
}
if (txout.scriptPubKey == GetScriptForDestination(CBitcoinAddress(consensusParams.stage3CommunityFundAddress).Get())) {
BOOST_ASSERT(txout.nValue == 1875*COIN/1000); // 25/2*0.15
paymentToCommunityFound = true;
}
}
BOOST_ASSERT(paymentToDevFound && paymentToCommunityFound);
}

// the third halving should occur at block 630
// tail emission should occur at block 630
CBlock block = CreateAndProcessBlock({}, coinbaseKey);
deterministicMNManager->UpdatedBlockTip(chainActive.Tip());

CAmount nValue;
auto dmnPayout = FindPayoutDmn(block, nValue);

BOOST_ASSERT(dmnPayout != nullptr && nValue == 3125*COIN/1000/2); // 3.125/2 (3.125*0.5)

// there should be no more payment to devs/community funds fund
for (const CTxOut &txout: block.vtx[0]->vout) {
BOOST_ASSERT(txout.scriptPubKey != GetScriptForDestination(CBitcoinAddress(consensusParams.stage2DevelopmentFundAddress).Get()) &&
txout.scriptPubKey != GetScriptForDestination(CBitcoinAddress(consensusParams.stage3DevelopmentFundAddress).Get()) &&
txout.scriptPubKey != GetScriptForDestination(CBitcoinAddress(consensusParams.stage3CommunityFundAddress).Get()));
}

// miner's reward should be 3.125/2
BOOST_ASSERT(block.vtx[0]->vout[0].nValue == 3125*COIN/1000/2);
// should be only 2 vouts in coinbase
BOOST_ASSERT(block.vtx[0]->vout.size() == 2);
BOOST_ASSERT(dmnPayout != nullptr && nValue == COIN);

consensusParams = consensusParamsBackup;
}
Expand All @@ -303,6 +305,7 @@ BOOST_FIXTURE_TEST_CASE(devpayoutverification, TestChainDIP3BeforeActivationSetu

consensusParams.nSubsidyHalvingFirst = 600;
consensusParams.nSubsidyHalvingSecond = 610;
consensusParams.stage3StartTime = INT_MAX;
consensusParams.nSubsidyHalvingInterval = 10;

// skip to block 600
Expand Down
15 changes: 14 additions & 1 deletion src/test/mtp_halving_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,17 @@ CScript scriptPubKeyMtpHalving;


struct MtpHalvingTestingSetup : public TestingSetup {
MtpHalvingTestingSetup() : TestingSetup(CBaseChainParams::REGTEST)
Consensus::Params &mutableParams;
Consensus::Params oldParams;

MtpHalvingTestingSetup() : TestingSetup(CBaseChainParams::REGTEST), mutableParams(const_cast<Consensus::Params&>(Params().GetConsensus()))
{
oldParams = mutableParams;

// disable stage 3 stuff for now
mutableParams.stage3StartTime = INT_MAX;
mutableParams.stage3StartBlock = INT_MAX;

CPubKey newKey;
BOOST_CHECK(pwalletMain->GetKeyFromPool(newKey));

Expand All @@ -66,6 +75,10 @@ struct MtpHalvingTestingSetup : public TestingSetup {
}
}

~MtpHalvingTestingSetup() {
mutableParams = oldParams;
}

CBlock CreateBlock(const CScript& scriptPubKeyMtpHalving, bool mtp = false) {
const CChainParams& chainparams = Params();
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKeyMtpHalving);
Expand Down

0 comments on commit a1e9870

Please sign in to comment.