partial bitcoin#21606: Extend psbt fuzz target a bit

excludes CountPSBTUnsignedInputs from the PSBT fuzzing test series
This commit is contained in:
Kittywhiskers Van Gogh 2024-01-18 21:00:08 +00:00 committed by pasta
parent 75118f3291
commit eed4f193a8
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984

View File

@ -2,6 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <node/psbt.h>
@ -9,6 +10,7 @@
#include <pubkey.h>
#include <script/script.h>
#include <streams.h>
#include <util/check.h>
#include <version.h>
#include <cstdint>
@ -18,10 +20,10 @@
FUZZ_TARGET(psbt)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
PartiallySignedTransaction psbt_mut;
const std::string raw_psbt{buffer.begin(), buffer.end()};
std::string error;
if (!DecodeRawPSBT(psbt_mut, raw_psbt, error)) {
if (!DecodeRawPSBT(psbt_mut, fuzzed_data_provider.ConsumeRandomLengthString(), error)) {
return;
}
const PartiallySignedTransaction psbt = psbt_mut;
@ -66,6 +68,20 @@ FUZZ_TARGET(psbt)
const PartiallySignedTransaction psbt_from_tx{result};
}
PartiallySignedTransaction psbt_merge;
if (!DecodeRawPSBT(psbt_merge, fuzzed_data_provider.ConsumeRandomLengthString(), error)) {
psbt_merge = psbt;
}
psbt_mut = psbt;
(void)psbt_mut.Merge(psbt);
(void)psbt_mut.Merge(psbt_merge);
psbt_mut = psbt;
(void)CombinePSBTs(psbt_mut, {psbt_mut, psbt_merge});
psbt_mut = psbt;
for (unsigned int i = 0; i < psbt_merge.tx->vin.size(); ++i) {
(void)psbt_mut.AddInput(psbt_merge.tx->vin[i], psbt_merge.inputs[i]);
}
for (unsigned int i = 0; i < psbt_merge.tx->vout.size(); ++i) {
Assert(psbt_mut.AddOutput(psbt_merge.tx->vout[i], psbt_merge.outputs[i]));
}
psbt_mut.unknown.insert(psbt_merge.unknown.begin(), psbt_merge.unknown.end());
}