// Copyright (c) 2019-2020 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include #include #include "cc/betprotocol.h" #include "cc/eval.h" #include "base58.h" #include "core_io.h" #include "key.h" #include "main.h" #include "script/cc.h" #include "primitives/transaction.h" #include "script/interpreter.h" #include "script/serverchecker.h" #include "testutils.h" extern int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); namespace TestEvalNotarisation { class EvalMock : public Eval { public: uint32_t nNotaries; uint8_t notaries[64][33]; std::map txs; std::map blocks; int32_t GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t timestamp) const { memcpy(pubkeys, notaries, sizeof(notaries)); return nNotaries; } bool GetTxUnconfirmed(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) const { auto r = txs.find(hash); if (r != txs.end()) { txOut = r->second; if (blocks.count(hash) > 0) hashBlock = hash; return true; } return false; } bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const { auto r = blocks.find(hash); if (r == blocks.end()) return false; blockIdx = r->second; return true; } }; //static auto noop = [&](CMutableTransaction &mtx){}; static auto noop = [](CMutableTransaction &mtx){}; template void SetupEval(EvalMock &eval, CMutableTransaction ¬ary, Modifier modify) { eval.nNotaries = komodo_notaries(eval.notaries, 780060, 1522946781); // make fake notary inputs notary.vin.resize(11); for (int i=0; i> proof); EXPECT_EQ(data.MoM, proof.branch.Exec(proofTxHash)); } TEST(TestEvalNotarisation, testInvalidNotaryPubkey) { EvalMock eval; CMutableTransaction notary(notaryTx); SetupEval(eval, notary, noop); memset(eval.notaries[10], 0, 33); NotarisationData data; ASSERT_FALSE(eval.GetNotarisationData(notary.GetHash(), data)); } */ TEST(TestEvalNotarisation, testInvalidNotarisationBadOpReturn) { EvalMock eval; CMutableTransaction notary(notaryTx); notary.vout[1].scriptPubKey = CScript() << OP_RETURN << 0; SetupEval(eval, notary, noop); NotarisationData data(0); ASSERT_FALSE(eval.GetNotarisationData(notary.GetHash(), data)); } TEST(TestEvalNotarisation, testInvalidNotarisationTxNotEnoughSigs) { EvalMock eval; CMutableTransaction notary(notaryTx); SetupEval(eval, notary, [](CMutableTransaction &tx) { tx.vin.resize(10); }); NotarisationData data(0); ASSERT_FALSE(eval.GetNotarisationData(notary.GetHash(), data)); } TEST(TestEvalNotarisation, testInvalidNotarisationTxDoesntExist) { EvalMock eval; CMutableTransaction notary(notaryTx); SetupEval(eval, notary, noop); NotarisationData data(0); ASSERT_FALSE(eval.GetNotarisationData(uint256(), data)); } TEST(TestEvalNotarisation, testInvalidNotarisationDupeNotary) { EvalMock eval; CMutableTransaction notary(notaryTx); SetupEval(eval, notary, [](CMutableTransaction &tx) { tx.vin[1] = tx.vin[3]; }); NotarisationData data(0); ASSERT_FALSE(eval.GetNotarisationData(notary.GetHash(), data)); } TEST(TestEvalNotarisation, testInvalidNotarisationInputNotCheckSig) { EvalMock eval; CMutableTransaction notary(notaryTx); SetupEval(eval, notary, [&](CMutableTransaction &tx) { int i = 1; CMutableTransaction txIn; txIn.vout.resize(1); txIn.vout[0].scriptPubKey << VCH(eval.notaries[i*2], 33) << OP_RETURN; notary.vin[i].prevout = COutPoint(txIn.GetHash(), 0); eval.txs[txIn.GetHash()] = CTransaction(txIn); }); NotarisationData data(0); ASSERT_FALSE(eval.GetNotarisationData(notary.GetHash(), data)); } } /* namespace TestEvalNotarisation */