diff --git a/src/Makefile.gtest.include b/src/Makefile.gtest.include index e4e126866..ababfa557 100644 --- a/src/Makefile.gtest.include +++ b/src/Makefile.gtest.include @@ -32,6 +32,7 @@ zcash_gtest_SOURCES += \ gtest/test_random.cpp \ gtest/test_rpc.cpp \ gtest/test_transaction.cpp \ + gtest/test_validation.cpp \ gtest/test_circuit.cpp \ gtest/test_txid.cpp \ gtest/test_libzcash_utils.cpp \ diff --git a/src/gtest/test_validation.cpp b/src/gtest/test_validation.cpp new file mode 100644 index 000000000..21ed20d84 --- /dev/null +++ b/src/gtest/test_validation.cpp @@ -0,0 +1,63 @@ +#include + +#include "consensus/validation.h" +#include "main.h" + +// Fake an empty view +class FakeCoinsViewDB : public CCoinsView { +public: + FakeCoinsViewDB() {} + + bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const { + return false; + } + + bool GetNullifier(const uint256 &nf) const { + return false; + } + + bool GetCoins(const uint256 &txid, CCoins &coins) const { + return false; + } + + bool HaveCoins(const uint256 &txid) const { + return false; + } + + uint256 GetBestBlock() const { + uint256 a; + return a; + } + + uint256 GetBestAnchor() const { + uint256 a; + return a; + } + + bool BatchWrite(CCoinsMap &mapCoins, + const uint256 &hashBlock, + const uint256 &hashAnchor, + CAnchorsMap &mapAnchors, + CNullifiersMap &mapNullifiers) { + return false; + } + + bool GetStats(CCoinsStats &stats) const { + return false; + } +}; + +TEST(Validation, ContextualCheckInputsPassesWithCoinbase) { + // Create fake coinbase transaction + CMutableTransaction mtx; + mtx.vin.resize(1); + CTransaction tx(mtx); + ASSERT_TRUE(tx.IsCoinBase()); + + // Fake an empty view + FakeCoinsViewDB fakeDB; + CCoinsViewCache view(&fakeDB); + + CValidationState state; + EXPECT_TRUE(ContextualCheckInputs(tx, state, view, false, 0, false, Params(CBaseChainParams::MAIN).GetConsensus())); +}