From 3109df5616796282786706738994a5b97b8a5a38 Mon Sep 17 00:00:00 2001 From: Jeremy Rubin Date: Sat, 11 Sep 2021 23:03:11 -0700 Subject: [PATCH] [TESTS] Add CTV Hash Computation Unit Test & Mutation Tester --- src/Makefile.test.include | 2 + src/script/interpreter.cpp | 7 + src/test/ctvhash_tests.cpp | 211 ++++ src/test/data/ctvhash.json | 2204 ++++++++++++++++++++++++++++++++++++ 4 files changed, 2424 insertions(+) create mode 100644 src/test/ctvhash_tests.cpp create mode 100644 src/test/data/ctvhash.json diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 9fe2a3cf8a63f..8457f76cc35fe 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -19,6 +19,7 @@ JSON_TEST_FILES = \ test/data/bip341_wallet_vectors.json \ test/data/base58_encode_decode.json \ test/data/blockfilters.json \ + test/data/ctvhash.json \ test/data/key_io_valid.json \ test/data/key_io_invalid.json \ test/data/script_tests.json \ @@ -87,6 +88,7 @@ BITCOIN_TESTS =\ test/compilerbug_tests.cpp \ test/compress_tests.cpp \ test/crypto_tests.cpp \ + test/ctvhash_tests.cpp \ test/cuckoocache_tests.cpp \ test/dbwrapper_tests.cpp \ test/denialofservice_tests.cpp \ diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 0a407d18c4274..e9aae91b8655a 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1498,6 +1498,13 @@ uint256 GetDefaultCheckTemplateVerifyHash(const TxType& tx, const uint256& outpu GetDefaultCheckTemplateVerifyHashWithScript(tx, outputs_hash, sequences_hash, GetScriptSigsSHA256(tx), input_index); } +template +uint256 GetDefaultCheckTemplateVerifyHash(const CTransaction& tx, const uint256& outputs_hash, const uint256& sequences_hash, + const uint32_t input_index); +template +uint256 GetDefaultCheckTemplateVerifyHash(const CMutableTransaction& tx, const uint256& outputs_hash, const uint256& sequences_hash, + const uint32_t input_index); + template void PrecomputedTransactionData::Init(const T& txTo, std::vector&& spent_outputs, bool force) { diff --git a/src/test/ctvhash_tests.cpp b/src/test/ctvhash_tests.cpp new file mode 100644 index 0000000000000..46f5ffd65e737 --- /dev/null +++ b/src/test/ctvhash_tests.cpp @@ -0,0 +1,211 @@ +// Copyright (c) 2013-2021 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include +#include