diff options
author | practicalswift <practicalswift@users.noreply.github.com> | 2019-12-19 19:26:42 +0000 |
---|---|---|
committer | practicalswift <practicalswift@users.noreply.github.com> | 2019-12-19 20:20:05 +0000 |
commit | bcad0144eff3192cb54f65fa7737be53e03f8b0f (patch) | |
tree | 54fc0519bf9694237147fa6fcb504bd852fe855d /src/test/fuzz | |
parent | 3e949380725ca32be6c9812a926727b0a45723a9 (diff) | |
download | bitcoin-bcad0144eff3192cb54f65fa7737be53e03f8b0f.tar.xz |
tests: Add fuzzing harness for DecodeHexTx(...)
Diffstat (limited to 'src/test/fuzz')
-rw-r--r-- | src/test/fuzz/decode_tx.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/fuzz/decode_tx.cpp b/src/test/fuzz/decode_tx.cpp new file mode 100644 index 0000000000..09c4ff05df --- /dev/null +++ b/src/test/fuzz/decode_tx.cpp @@ -0,0 +1,31 @@ +// Copyright (c) 2019 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 <core_io.h> +#include <primitives/transaction.h> +#include <test/fuzz/fuzz.h> +#include <util/strencodings.h> + +#include <cassert> +#include <cstdint> +#include <string> +#include <vector> + +void test_one_input(const std::vector<uint8_t>& buffer) +{ + const std::string tx_hex = HexStr(std::string{buffer.begin(), buffer.end()}); + CMutableTransaction mtx; + const bool result_none = DecodeHexTx(mtx, tx_hex, false, false); + const bool result_try_witness = DecodeHexTx(mtx, tx_hex, false, true); + const bool result_try_witness_and_maybe_no_witness = DecodeHexTx(mtx, tx_hex, true, true); + const bool result_try_no_witness = DecodeHexTx(mtx, tx_hex, true, false); + assert(!result_none); + if (result_try_witness_and_maybe_no_witness) { + assert(result_try_no_witness || result_try_witness); + } + // if (result_try_no_witness) { // Uncomment when https://github.com/bitcoin/bitcoin/pull/17775 is merged + if (result_try_witness) { // Remove stop-gap when https://github.com/bitcoin/bitcoin/pull/17775 is merged + assert(result_try_witness_and_maybe_no_witness); + } +} |