]> Git Repo - VerusCoin.git/commitdiff
Add test for incorrect consensus logic
authorJack Grigg <[email protected]>
Wed, 14 Jun 2017 03:33:11 +0000 (15:33 +1200)
committerJack Grigg <[email protected]>
Fri, 16 Jun 2017 01:45:14 +0000 (13:45 +1200)
src/Makefile.gtest.include
src/gtest/test_validation.cpp [new file with mode: 0644]

index e4e126866765268b2cc22964b68e49e2b05bfdfc..ababfa5577e7645420d80b43233e6d8ef6fcb19d 100644 (file)
@@ -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 (file)
index 0000000..21ed20d
--- /dev/null
@@ -0,0 +1,63 @@
+#include <gtest/gtest.h>
+
+#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()));
+}
This page took 0.027031 seconds and 4 git commands to generate.