Skip to content

Commit

Permalink
Update CbTx in TestChainSetup
Browse files Browse the repository at this point in the history
We need to update the CbTx's merkle root for the masternode list here as
tests might add transactions into a block which cause the list to change.
  • Loading branch information
codablock committed Sep 5, 2018
1 parent 9674be8 commit d653ace
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/test/test_dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

#include "test/testutil.h"

#include "evo/specialtx.h"
#include "evo/deterministicmns.h"
#include "evo/cbtx.h"

#include <memory>

Expand Down Expand Up @@ -146,6 +148,22 @@ CBlock TestChainSetup::CreateBlock(const std::vector<CMutableTransaction>& txns,
block.vtx.resize(1);
BOOST_FOREACH(const CMutableTransaction& tx, txns)
block.vtx.push_back(MakeTransactionRef(tx));

// Manually update CbTx as we modified the block here
if (block.vtx[0]->nType == TRANSACTION_COINBASE) {
CCbTx cbTx;
if (!GetTxPayload(*block.vtx[0], cbTx)) {
BOOST_ASSERT(false);
}
CValidationState state;
if (!CalcCbTxMerkleRootMNList(block, chainActive.Tip(), cbTx.merkleRootMNList, state)) {
BOOST_ASSERT(false);
}
CMutableTransaction tmpTx = *block.vtx[0];
SetTxPayload(tmpTx, cbTx);
block.vtx[0] = MakeTransactionRef(tmpTx);
}

// IncrementExtraNonce creates a valid coinbase and merkleRoot
unsigned int extraNonce = 0;
IncrementExtraNonce(&block, chainActive.Tip(), extraNonce);
Expand Down

0 comments on commit d653ace

Please sign in to comment.