aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorbrunoerg <brunoely.gc@gmail.com>2023-09-30 11:53:39 -0300
committerbrunoerg <brunoely.gc@gmail.com>2023-10-13 08:55:12 -0300
commitff8e2fc2e2416f6f3b84cdb40db8ac168596b579 (patch)
treece05ef6c6faab7ff2858792d463f34237a49a804 /src/test
parentc5f2a757d736f14d27ac5256a9df887cd2f174f1 (diff)
fuzz: add coverage for `bitcoinconsensus_verify_script_with_spent_outputs`
Co-authored-by: Antonie Poinsot <darosior@protonmail.com>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/fuzz/script_bitcoin_consensus.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/fuzz/script_bitcoin_consensus.cpp b/src/test/fuzz/script_bitcoin_consensus.cpp
index fcd66b234e..846389863d 100644
--- a/src/test/fuzz/script_bitcoin_consensus.cpp
+++ b/src/test/fuzz/script_bitcoin_consensus.cpp
@@ -28,4 +28,23 @@ FUZZ_TARGET(script_bitcoin_consensus)
}
(void)bitcoinconsensus_verify_script(random_bytes_1.data(), random_bytes_1.size(), random_bytes_2.data(), random_bytes_2.size(), n_in, flags, err_p);
(void)bitcoinconsensus_verify_script_with_amount(random_bytes_1.data(), random_bytes_1.size(), money, random_bytes_2.data(), random_bytes_2.size(), n_in, flags, err_p);
+
+ std::vector<UTXO> spent_outputs;
+ std::vector<std::vector<unsigned char>> spent_spks;
+ if (n_in <= 24386) {
+ spent_outputs.reserve(n_in);
+ spent_spks.reserve(n_in);
+ for (size_t i = 0; i < n_in; ++i) {
+ spent_spks.push_back(ConsumeRandomLengthByteVector(fuzzed_data_provider));
+ const CAmount value{ConsumeMoney(fuzzed_data_provider)};
+ const auto spk_size{static_cast<unsigned>(spent_spks.back().size())};
+ spent_outputs.push_back({.scriptPubKey = spent_spks.back().data(), .scriptPubKeySize = spk_size, .value = value});
+ }
+ }
+
+ const auto spent_outs_size{static_cast<unsigned>(spent_outputs.size())};
+
+ (void)bitcoinconsensus_verify_script_with_spent_outputs(
+ random_bytes_1.data(), random_bytes_1.size(), money, random_bytes_2.data(), random_bytes_2.size(),
+ spent_outputs.data(), spent_outs_size, n_in, flags, err_p);
}