From c6c994cb2b9af58b1c0e554255d1a3be785e8d56 Mon Sep 17 00:00:00 2001 From: stickies-v Date: Thu, 1 Aug 2024 16:35:41 +0100 Subject: [PATCH] test: remove test-only uint160S uint160S is a test-only function, and testing input that is not allowed in uint160::FromHex() is superfluous. Tests that can't use uint160::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. --- src/test/uint256_tests.cpp | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/test/uint256_tests.cpp b/src/test/uint256_tests.cpp index 2a516731e8f..972702819ee 100644 --- a/src/test/uint256_tests.cpp +++ b/src/test/uint256_tests.cpp @@ -61,14 +61,6 @@ static std::string ArrayToString(const unsigned char A[], unsigned int width) return Stream.str(); } -// Takes hex string in reverse byte order. -inline uint160 uint160S(std::string_view str) -{ - uint160 rv; - rv.SetHexDeprecated(str); - return rv; -} - BOOST_AUTO_TEST_CASE( basics ) // constructors, equality, inequality { // constructor uint256(vector): @@ -102,17 +94,12 @@ BOOST_AUTO_TEST_CASE( basics ) // constructors, equality, inequality BOOST_CHECK_EQUAL(uint256(ZeroL), ZeroL); BOOST_CHECK_EQUAL(uint256(OneL), OneL); - BOOST_CHECK_EQUAL(uint160S("0x"+R1S.ToString()), R1S); - BOOST_CHECK_EQUAL(uint160S("0x"+R2S.ToString()), R2S); - BOOST_CHECK_EQUAL(uint160S("0x"+ZeroS.ToString()), ZeroS); - BOOST_CHECK_EQUAL(uint160S("0x"+OneS.ToString()), OneS); - BOOST_CHECK_EQUAL(uint160S("0x"+MaxS.ToString()), MaxS); - BOOST_CHECK_EQUAL(uint160S(R1S.ToString()), R1S); - BOOST_CHECK_EQUAL(uint160S(" 0x"+R1S.ToString()+" "), R1S); - BOOST_CHECK_EQUAL(uint160S(" 0x"+R1S.ToString()+"-trash;%^& "), R1S); - BOOST_CHECK_EQUAL(uint160S(" \t \n \n \f\n\r\t\v\t 0x"+R1S.ToString()+" \t \n \n \f\n\r\t\v\t"), R1S); - BOOST_CHECK_EQUAL(uint160S(""), ZeroS); - BOOST_CHECK_EQUAL(R1S, uint160S(R1ArrayHex)); + BOOST_CHECK_EQUAL(uint160::FromHex(R1S.ToString()).value(), R1S); + BOOST_CHECK_EQUAL(uint160::FromHex(R2S.ToString()).value(), R2S); + BOOST_CHECK_EQUAL(uint160::FromHex(ZeroS.ToString()).value(), ZeroS); + BOOST_CHECK_EQUAL(uint160::FromHex(OneS.ToString()).value(), OneS); + BOOST_CHECK_EQUAL(uint160::FromHex(MaxS.ToString()).value(), MaxS); + BOOST_CHECK_EQUAL(uint160::FromHex(std::string_view{R1ArrayHex + 24, 40}).value(), R1S); BOOST_CHECK_EQUAL(uint160(R1S), R1S); BOOST_CHECK_EQUAL(uint160(ZeroS), ZeroS);