diff options
author | fanquake <fanquake@gmail.com> | 2022-09-28 12:10:38 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2022-10-01 11:41:53 +0100 |
commit | 079cf88c0df6de038b8f8933d55c0d17af007b43 (patch) | |
tree | 6cd3bfb3be86f446e275dd48f50fd469ff8554c7 /src/wallet/test/fuzz/parse_iso8601.cpp | |
parent | f59e91511a3aa8b2770eeec7034ddc1a9dec918b (diff) | |
download | bitcoin-079cf88c0df6de038b8f8933d55c0d17af007b43.tar.xz |
refactor: move Boost datetime usage to wallet
This means we don't need datetime in a --disable-wallet build, and it
isn't included in the kernel.
Diffstat (limited to 'src/wallet/test/fuzz/parse_iso8601.cpp')
-rw-r--r-- | src/wallet/test/fuzz/parse_iso8601.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/wallet/test/fuzz/parse_iso8601.cpp b/src/wallet/test/fuzz/parse_iso8601.cpp new file mode 100644 index 0000000000..5be248c2fb --- /dev/null +++ b/src/wallet/test/fuzz/parse_iso8601.cpp @@ -0,0 +1,34 @@ +// Copyright (c) 2019-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 <test/fuzz/FuzzedDataProvider.h> +#include <test/fuzz/fuzz.h> +#include <util/time.h> +#include <wallet/rpc/util.h> + +#include <cassert> +#include <cstdint> +#include <string> +#include <vector> + +FUZZ_TARGET(parse_iso8601) +{ + FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); + + const int64_t random_time = fuzzed_data_provider.ConsumeIntegral<int32_t>(); + const std::string random_string = fuzzed_data_provider.ConsumeRemainingBytesAsString(); + + const std::string iso8601_datetime = FormatISO8601DateTime(random_time); + (void)FormatISO8601Date(random_time); + const int64_t parsed_time_1 = wallet::ParseISO8601DateTime(iso8601_datetime); + if (random_time >= 0) { + assert(parsed_time_1 >= 0); + if (iso8601_datetime.length() == 20) { + assert(parsed_time_1 == random_time); + } + } + + const int64_t parsed_time_2 = wallet::ParseISO8601DateTime(random_string); + assert(parsed_time_2 >= 0); +} |