mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
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.
This commit is contained in:
34
src/wallet/test/fuzz/parse_iso8601.cpp
Normal file
34
src/wallet/test/fuzz/parse_iso8601.cpp
Normal file
@@ -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);
|
||||
}
|
||||
24
src/wallet/test/rpc_util_tests.cpp
Normal file
24
src/wallet/test/rpc_util_tests.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2022 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 <wallet/rpc/util.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace wallet {
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(wallet_util_tests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_ParseISO8601DateTime)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(ParseISO8601DateTime("1970-01-01T00:00:00Z"), 0);
|
||||
BOOST_CHECK_EQUAL(ParseISO8601DateTime("1960-01-01T00:00:00Z"), 0);
|
||||
BOOST_CHECK_EQUAL(ParseISO8601DateTime("2000-01-01T00:00:01Z"), 946684801);
|
||||
BOOST_CHECK_EQUAL(ParseISO8601DateTime("2011-09-30T23:36:17Z"), 1317425777);
|
||||
BOOST_CHECK_EQUAL(ParseISO8601DateTime("2100-12-31T23:59:59Z"), 4133980799);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
} // namespace wallet
|
||||
Reference in New Issue
Block a user