aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz
diff options
context:
space:
mode:
authorbrunoerg <brunoely.gc@gmail.com>2023-11-07 10:44:25 -0300
committerbrunoerg <brunoely.gc@gmail.com>2023-11-20 15:57:56 -0300
commit641dddf01812407d163520def83f5975413691e4 (patch)
treefc1f51d2c5e901627dff2456ab9e2edafd2f48f4 /src/test/fuzz
parent2e1833ca1341ab4dc92508a59181aa6c7c38db88 (diff)
fuzz: create ConsumeCoins
Diffstat (limited to 'src/test/fuzz')
-rw-r--r--src/test/fuzz/script_sign.cpp13
-rw-r--r--src/test/fuzz/util.cpp18
-rw-r--r--src/test/fuzz/util.h2
3 files changed, 21 insertions, 12 deletions
diff --git a/src/test/fuzz/script_sign.cpp b/src/test/fuzz/script_sign.cpp
index 0944c91c4a..9c2966e0cb 100644
--- a/src/test/fuzz/script_sign.cpp
+++ b/src/test/fuzz/script_sign.cpp
@@ -125,18 +125,7 @@ FUZZ_TARGET(script_sign, .init = initialize_script_sign)
}
(void)signature_creator.CreateSig(provider, vch_sig, address, ConsumeScript(fuzzed_data_provider), fuzzed_data_provider.PickValueInArray({SigVersion::BASE, SigVersion::WITNESS_V0}));
}
- std::map<COutPoint, Coin> coins;
- LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
- const std::optional<COutPoint> outpoint = ConsumeDeserializable<COutPoint>(fuzzed_data_provider);
- if (!outpoint) {
- break;
- }
- const std::optional<Coin> coin = ConsumeDeserializable<Coin>(fuzzed_data_provider);
- if (!coin) {
- break;
- }
- coins[*outpoint] = *coin;
- }
+ std::map<COutPoint, Coin> coins{ConsumeCoins(fuzzed_data_provider)};
std::map<int, bilingual_str> input_errors;
(void)SignTransaction(sign_transaction_tx_to, &provider, coins, fuzzed_data_provider.ConsumeIntegral<int>(), input_errors);
}
diff --git a/src/test/fuzz/util.cpp b/src/test/fuzz/util.cpp
index 87ca2f6aed..4ce78d125a 100644
--- a/src/test/fuzz/util.cpp
+++ b/src/test/fuzz/util.cpp
@@ -164,6 +164,24 @@ uint32_t ConsumeSequence(FuzzedDataProvider& fuzzed_data_provider) noexcept
fuzzed_data_provider.ConsumeIntegral<uint32_t>();
}
+std::map<COutPoint, Coin> ConsumeCoins(FuzzedDataProvider& fuzzed_data_provider) noexcept
+{
+ std::map<COutPoint, Coin> coins;
+ LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
+ const std::optional<COutPoint> outpoint{ConsumeDeserializable<COutPoint>(fuzzed_data_provider)};
+ if (!outpoint) {
+ break;
+ }
+ const std::optional<Coin> coin{ConsumeDeserializable<Coin>(fuzzed_data_provider)};
+ if (!coin) {
+ break;
+ }
+ coins[*outpoint] = *coin;
+ }
+
+ return coins;
+}
+
CTxDestination ConsumeTxDestination(FuzzedDataProvider& fuzzed_data_provider) noexcept
{
CTxDestination tx_destination;
diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h
index 0ad2ed6128..9e360a4217 100644
--- a/src/test/fuzz/util.h
+++ b/src/test/fuzz/util.h
@@ -181,6 +181,8 @@ template <typename WeakEnumType, size_t size>
return UintToArith256(ConsumeUInt256(fuzzed_data_provider));
}
+[[nodiscard]] std::map<COutPoint, Coin> ConsumeCoins(FuzzedDataProvider& fuzzed_data_provider) noexcept;
+
[[nodiscard]] CTxDestination ConsumeTxDestination(FuzzedDataProvider& fuzzed_data_provider) noexcept;
[[nodiscard]] CKey ConsumePrivateKey(FuzzedDataProvider& fuzzed_data_provider, std::optional<bool> compressed = std::nullopt) noexcept;