Add example mock test of CheckTransaction
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "primitives/transaction.h"
|
||||
@@ -24,3 +25,29 @@ TEST(checktransaction_tests, check_vpub_not_both_nonzero) {
|
||||
EXPECT_EQ(state.GetRejectReason(), "bad-txns-vpubs-both-nonzero");
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user