Bitcoin Core  24.99.0
P2P Digital Currency
parse_iso8601.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
6 #include <test/fuzz/fuzz.h>
7 #include <util/time.h>
8 
9 #include <cassert>
10 #include <cstdint>
11 #include <string>
12 #include <vector>
13 
14 FUZZ_TARGET(parse_iso8601)
15 {
16  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
17 
18  const int64_t random_time = fuzzed_data_provider.ConsumeIntegral<int32_t>();
19  const std::string random_string = fuzzed_data_provider.ConsumeRemainingBytesAsString();
20 
21  const std::string iso8601_datetime = FormatISO8601DateTime(random_time);
22  (void)FormatISO8601Date(random_time);
23  const int64_t parsed_time_1 = ParseISO8601DateTime(iso8601_datetime);
24  if (random_time >= 0) {
25  assert(parsed_time_1 >= 0);
26  if (iso8601_datetime.length() == 20) {
27  assert(parsed_time_1 == random_time);
28  }
29  }
30 
31  const int64_t parsed_time_2 = ParseISO8601DateTime(random_string);
32  assert(parsed_time_2 >= 0);
33 }
std::string ConsumeRemainingBytesAsString()
FUZZ_TARGET(parse_iso8601)
std::string FormatISO8601Date(int64_t nTime)
Definition: time.cpp:132
int64_t ParseISO8601DateTime(const std::string &str)
Definition: time.cpp:145
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
Definition: time.cpp:119
assert(!tx.IsCoinBase())