Skip to content

Commit

Permalink
Add basic FillNewBlock test for empty mempool case
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Oct 31, 2016
1 parent ae1098a commit 2d1ecee
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Makefile.gtest.include
Expand Up @@ -9,6 +9,7 @@ zcash_gtest_SOURCES = \
gtest/test_checktransaction.cpp \
gtest/json_test_vectors.cpp \
gtest/json_test_vectors.h \
gtest/test_fillnewblock.cpp \
gtest/test_foundersreward.cpp \
gtest/test_wallet_zkeys.cpp \
gtest/test_jsonspirit.cpp \
Expand Down
53 changes: 53 additions & 0 deletions src/gtest/test_fillnewblock.cpp
@@ -0,0 +1,53 @@
#include <gtest/gtest.h>

#include "chain.h"
#include "main.h"
#include "miner.h"
#include "primitives/block.h"
#include "script/script.h"

std::function<void(const uint256, double&, CAmount&)> noopApplyDeltas = []
(const uint256 hash, double &dPriorityDelta, CAmount &nFeeDelta) {
// No-op
};

TEST(FillNewBlock, EmptyMemPool) {
SelectParams(CBaseChainParams::MAIN);
const CChainParams& chainparams = Params();
CScript scriptDummy = CScript() << OP_TRUE;

auto prevHash = GetRandHash();
CBlockIndex indexPrev;
indexPrev.nHeight = 50;
indexPrev.phashBlock = &prevHash;

std::map<uint256, CTxMemPoolEntry> mapTx;

CBlock block;
std::vector<CAmount> vTxFees;
std::vector<int64_t> vTxSigOps;
FillNewBlock(&block, &indexPrev,
scriptDummy, chainparams,
vTxFees, vTxSigOps,
mapTx, noopApplyDeltas,
DEFAULT_BLOCK_MAX_SIZE,
DEFAULT_BLOCK_PRIORITY_SIZE,
DEFAULT_BLOCK_MIN_SIZE);

EXPECT_EQ(1, block.vtx.size());
EXPECT_EQ(1, vTxFees.size());
EXPECT_EQ(1, vTxSigOps.size());

const CTransaction& cb = block.vtx[0];
EXPECT_EQ(scriptDummy, cb.vout[0].scriptPubKey);
EXPECT_EQ(chainparams.GetFoundersRewardScriptAtHeight(51), cb.vout[1].scriptPubKey);

CAmount subsidy = GetBlockSubsidy(51, chainparams.GetConsensus());
CAmount fr = subsidy / 5;
subsidy -= fr;
EXPECT_EQ(subsidy, cb.vout[0].nValue);
EXPECT_EQ(fr, cb.vout[1].nValue);

EXPECT_EQ(0, vTxFees[0]);
EXPECT_EQ(0, vTxSigOps[0]);
}

0 comments on commit 2d1ecee

Please sign in to comment.