parent
7ac924cdb7
commit
80f4cdcf8f
|
@ -5,6 +5,7 @@ bin_PROGRAMS += zcash-gtest
|
||||||
zcash_gtest_SOURCES = \
|
zcash_gtest_SOURCES = \
|
||||||
gtest/main.cpp \
|
gtest/main.cpp \
|
||||||
gtest/utils.cpp \
|
gtest/utils.cpp \
|
||||||
|
gtest/test_checkblock.cpp \
|
||||||
gtest/test_checktransaction.cpp \
|
gtest/test_checktransaction.cpp \
|
||||||
gtest/json_test_vectors.cpp \
|
gtest/json_test_vectors.cpp \
|
||||||
gtest/json_test_vectors.h \
|
gtest/json_test_vectors.h \
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#ifndef BITCOIN_CONSENSUS_CONSENSUS_H
|
#ifndef BITCOIN_CONSENSUS_CONSENSUS_H
|
||||||
#define BITCOIN_CONSENSUS_CONSENSUS_H
|
#define BITCOIN_CONSENSUS_CONSENSUS_H
|
||||||
|
|
||||||
|
/** The minimum allowed block version (network rule) */
|
||||||
|
static const int32_t MIN_BLOCK_VERSION = 4;
|
||||||
/** The minimum allowed transaction version (network rule) */
|
/** The minimum allowed transaction version (network rule) */
|
||||||
static const int32_t MIN_TX_VERSION = 1;
|
static const int32_t MIN_TX_VERSION = 1;
|
||||||
/** The maximum allowed size for a serialized block, in bytes (network rule) */
|
/** The maximum allowed size for a serialized block, in bytes (network rule) */
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
|
#include "consensus/validation.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
class MockCValidationState : public CValidationState {
|
||||||
|
public:
|
||||||
|
MOCK_METHOD5(DoS, bool(int level, bool ret,
|
||||||
|
unsigned char chRejectCodeIn, std::string strRejectReasonIn,
|
||||||
|
bool corruptionIn));
|
||||||
|
MOCK_METHOD3(Invalid, bool(bool ret,
|
||||||
|
unsigned char _chRejectCode, std::string _strRejectReason));
|
||||||
|
MOCK_METHOD1(Error, bool(std::string strRejectReasonIn));
|
||||||
|
MOCK_CONST_METHOD0(IsValid, bool());
|
||||||
|
MOCK_CONST_METHOD0(IsInvalid, bool());
|
||||||
|
MOCK_CONST_METHOD0(IsError, bool());
|
||||||
|
MOCK_CONST_METHOD1(IsInvalid, bool(int &nDoSOut));
|
||||||
|
MOCK_CONST_METHOD0(CorruptionPossible, bool());
|
||||||
|
MOCK_CONST_METHOD0(GetRejectCode, unsigned char());
|
||||||
|
MOCK_CONST_METHOD0(GetRejectReason, std::string());
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(CheckBlock, VersionTooLow) {
|
||||||
|
CBlock block;
|
||||||
|
block.nVersion = 1;
|
||||||
|
|
||||||
|
MockCValidationState state;
|
||||||
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "version-too-low", false)).Times(1);
|
||||||
|
EXPECT_FALSE(CheckBlock(block, state, false, false));
|
||||||
|
}
|
|
@ -2940,6 +2940,11 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne
|
||||||
|
|
||||||
bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW)
|
bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW)
|
||||||
{
|
{
|
||||||
|
// Check block version
|
||||||
|
if (block.nVersion < MIN_BLOCK_VERSION)
|
||||||
|
return state.DoS(100, error("CheckBlockHeader(): block version too low"),
|
||||||
|
REJECT_INVALID, "version-too-low");
|
||||||
|
|
||||||
// Check Equihash solution is valid
|
// Check Equihash solution is valid
|
||||||
if (fCheckPOW && !CheckEquihashSolution(&block, Params()))
|
if (fCheckPOW && !CheckEquihashSolution(&block, Params()))
|
||||||
return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),
|
return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),
|
||||||
|
|
Loading…
Reference in New Issue