2016-04-13 15:52:24 -07:00
|
|
|
#include <gtest/gtest.h>
|
2016-06-15 16:01:55 -07:00
|
|
|
#include <gmock/gmock.h>
|
2016-04-13 15:52:24 -07:00
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "primitives/transaction.h"
|
|
|
|
#include "consensus/validation.h"
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, check_vpub_not_both_nonzero) {
|
|
|
|
CMutableTransaction tx;
|
|
|
|
tx.nVersion = 2;
|
|
|
|
|
|
|
|
{
|
|
|
|
// Ensure that values within the pour are well-formed.
|
|
|
|
CMutableTransaction newTx(tx);
|
|
|
|
CValidationState state;
|
|
|
|
state.SetPerformPourVerification(false); // don't verify the snark
|
|
|
|
|
|
|
|
newTx.vpour.push_back(CPourTx());
|
|
|
|
|
|
|
|
CPourTx *pourtx = &newTx.vpour[0];
|
|
|
|
pourtx->vpub_old = 1;
|
|
|
|
pourtx->vpub_new = 1;
|
|
|
|
|
|
|
|
EXPECT_FALSE(CheckTransaction(newTx, state));
|
|
|
|
EXPECT_EQ(state.GetRejectReason(), "bad-txns-vpubs-both-nonzero");
|
|
|
|
}
|
|
|
|
}
|
2016-06-15 16:01:55 -07:00
|
|
|
|
|
|
|
class MockCValidationState : public CValidationState {
|
|
|
|
public:
|
|
|
|
MOCK_METHOD5(DoS, bool(int level, bool ret,
|
|
|
|
unsigned char chRejectCodeIn, std::string strRejectReasonIn,
|
|
|
|
bool corruptionIn));
|
|
|
|
MOCK_METHOD1(SetPerformPourVerification, bool(bool pourVerifyIn));
|
|
|
|
MOCK_METHOD0(PerformPourVerification, bool());
|
|
|
|
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(checktransaction_tests, mock_proof_of_concept) {
|
|
|
|
CTransaction tx;
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(10, false, REJECT_INVALID, "bad-txns-vin-empty", false)).Times(1);
|
|
|
|
CheckTransaction(tx, state);
|
|
|
|
}
|