mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[isoltest] Allows odd-sized hex literals.
This commit is contained in:
parent
fe15db6537
commit
5ca991ac81
@ -101,7 +101,7 @@ contract C {
|
|||||||
// g1() -> FAILURE
|
// g1() -> FAILURE
|
||||||
// h(uint256,uint256): 1, -2 -> 3
|
// h(uint256,uint256): 1, -2 -> 3
|
||||||
// j(bool): true -> false
|
// j(bool): true -> false
|
||||||
// k(bytes32): 0x1001 -> 0x1001, 0x1001
|
// k(bytes32): 0x10001 -> 0x10001, 0x10001
|
||||||
// l(): hex"4200efef" -> 8
|
// l(): hex"4200efef" -> 8
|
||||||
// m(bytes): 32, 32, 0x20 -> 32, 32, 0x20
|
// m(bytes): 32, 32, 0x20 -> 32, 32, 0x20
|
||||||
// m(bytes): 32, 3, hex"AB33BB" -> 32, 3, left(0xAB33BB)
|
// m(bytes): 32, 3, hex"AB33BB" -> 32, 3, left(0xAB33BB)
|
||||||
|
@ -98,10 +98,7 @@ bytes BytesUtils::convertHexNumber(string const& _literal)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_literal.size() % 2)
|
return fromHex(_literal);
|
||||||
throw Error(Error::Type::ParserError, "Hex number encoding invalid.");
|
|
||||||
else
|
|
||||||
return fromHex(_literal);
|
|
||||||
}
|
}
|
||||||
catch (std::exception const&)
|
catch (std::exception const&)
|
||||||
{
|
{
|
||||||
@ -161,7 +158,9 @@ string BytesUtils::formatBoolean(bytes const& _bytes)
|
|||||||
|
|
||||||
string BytesUtils::formatHex(bytes const& _bytes)
|
string BytesUtils::formatHex(bytes const& _bytes)
|
||||||
{
|
{
|
||||||
|
soltestAssert(!_bytes.empty() && _bytes.size() <= 32, "");
|
||||||
u256 value = fromBigEndian<u256>(_bytes);
|
u256 value = fromBigEndian<u256>(_bytes);
|
||||||
|
|
||||||
return toCompactHexWithPrefix(value);
|
return toCompactHexWithPrefix(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,6 +404,27 @@ BOOST_AUTO_TEST_CASE(call_arguments_string)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(call_hex_number)
|
||||||
|
{
|
||||||
|
char const* source = R"(
|
||||||
|
// f(bytes32, bytes32): 0x616, 0x1042 -> 1
|
||||||
|
)";
|
||||||
|
auto const calls = parse(source);
|
||||||
|
BOOST_REQUIRE_EQUAL(calls.size(), 1);
|
||||||
|
testFunctionCall(
|
||||||
|
calls.at(0),
|
||||||
|
Mode::SingleLine,
|
||||||
|
"f(bytes32,bytes32)",
|
||||||
|
false,
|
||||||
|
fmt::encodeArgs(
|
||||||
|
fromHex("0x616"),
|
||||||
|
fromHex("0x1042")
|
||||||
|
),
|
||||||
|
fmt::encodeArgs(1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(call_return_string)
|
BOOST_AUTO_TEST_CASE(call_return_string)
|
||||||
{
|
{
|
||||||
char const* source = R"(
|
char const* source = R"(
|
||||||
@ -786,14 +807,6 @@ BOOST_AUTO_TEST_CASE(call_ether_type_invalid)
|
|||||||
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
|
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(call_hex_number_invalid)
|
|
||||||
{
|
|
||||||
char const* source = R"(
|
|
||||||
// f(bytes32, bytes32): 0x616, 0x042 -> 1
|
|
||||||
)";
|
|
||||||
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(call_signed_bool_invalid)
|
BOOST_AUTO_TEST_CASE(call_signed_bool_invalid)
|
||||||
{
|
{
|
||||||
char const* source = R"(
|
char const* source = R"(
|
||||||
|
@ -139,7 +139,8 @@ BOOST_AUTO_TEST_CASE(format_hex_singleline)
|
|||||||
BOOST_REQUIRE_EQUAL(test.format(), "// f(bytes32): 0x31 -> 0x31");
|
BOOST_REQUIRE_EQUAL(test.format(), "// f(bytes32): 0x31 -> 0x31");
|
||||||
|
|
||||||
bytes actualResult = fromHex("0x32");
|
bytes actualResult = fromHex("0x32");
|
||||||
bytes actualBytes = actualResult + bytes(32 - actualResult.size(), 0);
|
bytes actualBytes = bytes(32 - actualResult.size(), 0) + actualResult;
|
||||||
|
|
||||||
test.setRawBytes(actualBytes);
|
test.setRawBytes(actualBytes);
|
||||||
test.setFailure(false);
|
test.setFailure(false);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user