mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-19 09:53:47 +01:00
test: remove test-only uint256S
uint256S was previously deprecated for being unsafe. All non-test usage has already been removed in earlier commits. 1. Tests now use uint256::FromHex() or other constructors wherever possible without further modification. 2. Tests that can't use uint256::FromHex() because they use input with non-hex digit characters are a) modified by dropping the non-hex digit characters if that provides useful test coverage. b) dropped if the test without non-hex digit characters does not provide useful test coverage, e.g. because it is now duplicated. Additionally, use BOOST_CHECK_EQUAL where relevant on touched lines to make error messages more readable.
This commit is contained in:
parent
adc00ad728
commit
62cc4656e2
@ -37,7 +37,6 @@ FUZZ_TARGET(hex)
|
||||
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&) {
|
||||
|
@ -140,7 +140,7 @@ FUZZ_TARGET(integer, .init = initialize_integer)
|
||||
|
||||
const arith_uint256 au256 = UintToArith256(u256);
|
||||
assert(ArithToUint256(au256) == u256);
|
||||
assert(uint256S(au256.GetHex()) == u256);
|
||||
assert(uint256::FromHex(au256.GetHex()).value() == u256);
|
||||
(void)au256.bits();
|
||||
(void)au256.GetCompact(/* fNegative= */ false);
|
||||
(void)au256.GetCompact(/* fNegative= */ true);
|
||||
|
@ -92,18 +92,12 @@ BOOST_AUTO_TEST_CASE( basics ) // constructors, equality, inequality
|
||||
BOOST_CHECK_NE(MaxL, ZeroL); BOOST_CHECK_NE(MaxS, ZeroS);
|
||||
|
||||
// String Constructor and Copy Constructor
|
||||
BOOST_CHECK_EQUAL(uint256S("0x"+R1L.ToString()), R1L);
|
||||
BOOST_CHECK_EQUAL(uint256S("0x"+R2L.ToString()), R2L);
|
||||
BOOST_CHECK_EQUAL(uint256S("0x"+ZeroL.ToString()), ZeroL);
|
||||
BOOST_CHECK_EQUAL(uint256S("0x"+OneL.ToString()), OneL);
|
||||
BOOST_CHECK_EQUAL(uint256S("0x"+MaxL.ToString()), MaxL);
|
||||
BOOST_CHECK_EQUAL(uint256S(R1L.ToString()), R1L);
|
||||
BOOST_CHECK_EQUAL(uint256S(" 0x"+R1L.ToString()+" "), R1L);
|
||||
BOOST_CHECK_EQUAL(uint256S(" 0x"+R1L.ToString()+"-trash;%^& "), R1L);
|
||||
BOOST_CHECK_EQUAL(uint256S("\t \n \n \f\n\r\t\v\t 0x"+R1L.ToString()+" \t \n \n \f\n\r\t\v\t "), R1L);
|
||||
BOOST_CHECK_EQUAL(uint256S(""), ZeroL);
|
||||
BOOST_CHECK_EQUAL(uint256S("1"), OneL);
|
||||
BOOST_CHECK_EQUAL(R1L, uint256S(R1ArrayHex));
|
||||
BOOST_CHECK_EQUAL(uint256::FromHex(R1L.ToString()).value(), R1L);
|
||||
BOOST_CHECK_EQUAL(uint256::FromHex(R2L.ToString()).value(), R2L);
|
||||
BOOST_CHECK_EQUAL(uint256::FromHex(ZeroL.ToString()).value(), ZeroL);
|
||||
BOOST_CHECK_EQUAL(uint256::FromHex(OneL.ToString()).value(), OneL);
|
||||
BOOST_CHECK_EQUAL(uint256::FromHex(MaxL.ToString()).value(), MaxL);
|
||||
BOOST_CHECK_EQUAL(uint256::FromHex(R1ArrayHex).value(), R1L);
|
||||
BOOST_CHECK_EQUAL(uint256(R1L), R1L);
|
||||
BOOST_CHECK_EQUAL(uint256(ZeroL), ZeroL);
|
||||
BOOST_CHECK_EQUAL(uint256(OneL), OneL);
|
||||
@ -282,48 +276,20 @@ BOOST_AUTO_TEST_CASE( operator_with_self )
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wself-assign-overloaded"
|
||||
#endif
|
||||
arith_uint256 v = UintToArith256(uint256S("02"));
|
||||
arith_uint256 v{2};
|
||||
v *= v;
|
||||
BOOST_CHECK_EQUAL(v, UintToArith256(uint256S("04")));
|
||||
BOOST_CHECK_EQUAL(v, arith_uint256{4});
|
||||
v /= v;
|
||||
BOOST_CHECK_EQUAL(v, UintToArith256(uint256S("01")));
|
||||
BOOST_CHECK_EQUAL(v, arith_uint256{1});
|
||||
v += v;
|
||||
BOOST_CHECK_EQUAL(v, UintToArith256(uint256S("02")));
|
||||
BOOST_CHECK_EQUAL(v, arith_uint256{2});
|
||||
v -= v;
|
||||
BOOST_CHECK_EQUAL(v, UintToArith256(uint256S("0")));
|
||||
BOOST_CHECK_EQUAL(v, arith_uint256{0});
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse)
|
||||
{
|
||||
{
|
||||
std::string s_12{"0000000000000000000000000000000000000000000000000000000000000012"};
|
||||
BOOST_CHECK_EQUAL(uint256S("12\0").GetHex(), s_12);
|
||||
BOOST_CHECK_EQUAL(uint256S(std::string_view{"12\0", 3}).GetHex(), s_12);
|
||||
BOOST_CHECK_EQUAL(uint256S("0x12").GetHex(), s_12);
|
||||
BOOST_CHECK_EQUAL(uint256S(" 0x12").GetHex(), s_12);
|
||||
BOOST_CHECK_EQUAL(uint256S(" 12").GetHex(), s_12);
|
||||
}
|
||||
{
|
||||
std::string s_1{uint256::ONE.GetHex()};
|
||||
BOOST_CHECK_EQUAL(uint256S("1\0").GetHex(), s_1);
|
||||
BOOST_CHECK_EQUAL(uint256S(std::string_view{"1\0", 2}).GetHex(), s_1);
|
||||
BOOST_CHECK_EQUAL(uint256S("0x1").GetHex(), s_1);
|
||||
BOOST_CHECK_EQUAL(uint256S(" 0x1").GetHex(), s_1);
|
||||
BOOST_CHECK_EQUAL(uint256S(" 1").GetHex(), s_1);
|
||||
}
|
||||
{
|
||||
std::string s_0{uint256::ZERO.GetHex()};
|
||||
BOOST_CHECK_EQUAL(uint256S("\0").GetHex(), s_0);
|
||||
BOOST_CHECK_EQUAL(uint256S(std::string_view{"\0", 1}).GetHex(), s_0);
|
||||
BOOST_CHECK_EQUAL(uint256S("0x").GetHex(), s_0);
|
||||
BOOST_CHECK_EQUAL(uint256S(" 0x").GetHex(), s_0);
|
||||
BOOST_CHECK_EQUAL(uint256S(" ").GetHex(), s_0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemented as a templated function so it can be reused by other classes that have a FromHex()
|
||||
* method that wraps base_blob::FromHex(), such as transaction_identifier::FromHex().
|
||||
|
@ -199,14 +199,4 @@ public:
|
||||
static const uint256 ONE;
|
||||
};
|
||||
|
||||
/* uint256 from std::string_view, containing byte-reversed hex encoding.
|
||||
* DEPRECATED. Unlike FromHex this accepts any invalid input, thus it is fragile and deprecated!
|
||||
*/
|
||||
inline uint256 uint256S(std::string_view str)
|
||||
{
|
||||
uint256 rv;
|
||||
rv.SetHexDeprecated(str);
|
||||
return rv;
|
||||
}
|
||||
|
||||
#endif // BITCOIN_UINT256_H
|
||||
|
Loading…
Reference in New Issue
Block a user