mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
fad0cf6f26refactor: Use std::ranges::equal in GetNetworkForMagic (MarcoFalke)fadf0a7e15refactor: Remove Span operator==, Use std::ranges::equal (MarcoFalke) Pull request description: `std::span` removed the comparison operators, so it makes sense to remove them for the `Span` "backport" as well. Using `std::ranges::equal` also has the benefit that some `Span` temporary constructions can now be dropped. This is required to move from `Span` toward `std::span`. ACKs for top commit: hodlinator: Untested Code Review re-ACKfad0cf6stickies-v: ACKfad0cf6f26TheCharlatan: ACKfad0cf6f26Tree-SHA512: 5b9d1826ceac2aabae2295bc89893dd23ac3a1cc0d41988331cdbdc21be531aa91795d5273819f349f79648c6c4f30ed31af6e7a3816153e92080061b92ffe00
50 lines
1.6 KiB
C++
50 lines
1.6 KiB
C++
// 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 <core_io.h>
|
|
#include <primitives/block.h>
|
|
#include <pubkey.h>
|
|
#include <rpc/util.h>
|
|
#include <test/fuzz/fuzz.h>
|
|
#include <uint256.h>
|
|
#include <univalue.h>
|
|
#include <util/strencodings.h>
|
|
#include <util/transaction_identifier.h>
|
|
|
|
#include <algorithm>
|
|
#include <cassert>
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
FUZZ_TARGET(hex)
|
|
{
|
|
const std::string random_hex_string(buffer.begin(), buffer.end());
|
|
const std::vector<unsigned char> data = ParseHex(random_hex_string);
|
|
const std::vector<std::byte> bytes{ParseHex<std::byte>(random_hex_string)};
|
|
assert(std::ranges::equal(AsBytes(Span{data}), bytes));
|
|
const std::string hex_data = HexStr(data);
|
|
if (IsHex(random_hex_string)) {
|
|
assert(ToLower(random_hex_string) == hex_data);
|
|
}
|
|
if (uint256::FromHex(random_hex_string)) {
|
|
assert(random_hex_string.length() == 64);
|
|
assert(Txid::FromHex(random_hex_string));
|
|
assert(Wtxid::FromHex(random_hex_string));
|
|
assert(uint256::FromUserHex(random_hex_string));
|
|
}
|
|
if (const auto result{uint256::FromUserHex(random_hex_string)}) {
|
|
assert(uint256::FromHex(result->ToString()));
|
|
}
|
|
(void)uint256S(random_hex_string);
|
|
try {
|
|
(void)HexToPubKey(random_hex_string);
|
|
} catch (const UniValue&) {
|
|
}
|
|
CBlockHeader block_header;
|
|
(void)DecodeHexBlockHeader(block_header, random_hex_string);
|
|
CBlock block;
|
|
(void)DecodeHexBlk(block, random_hex_string);
|
|
}
|