Skip to content

Commit

Permalink
TestFunctionCall::formatRawParameters(): Ensure that uint8_t overload…
Browse files Browse the repository at this point in the history
… of toHex() is called

- Wrong overload results in isoltest padding each char to 32 bytes
  • Loading branch information
cameel committed Nov 15, 2021
1 parent 7334420 commit 90fdea9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
contract C {
function f(string memory s) external pure returns (string memory) {
return s;
}
}
// NOTE: The test is here to illustrate the problem with formatting control chars in strings in
// test expectations but unfortunately it can only be triggered manually. It does not test anything
// unless you introduce a difference in expectations to force isoltest to reformat them.
// ====
// compileViaYul: also
// ----
// f(string): 0x20, 16, "\xf0\x9f\x98\x83\xf0\x9f\x98\x83\xf0\x9f\x98\x83\xf0\x9f\x98\x83" -> 0x20, 16, "\xf0\x9f\x98\x83\xf0\x9f\x98\x83\xf0\x9f\x98\x83\xf0\x9f\x98\x83" # Input/Output: "😃😃😃😃" #
2 changes: 1 addition & 1 deletion test/libsolidity/util/BytesUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ string BytesUtils::formatString(bytes const& _bytes, size_t _cutOff)
if (isprint(v))
os << v;
else
os << "\\x" << toHex(v);
os << "\\x" << toHex(v, HexCase::Lower);
}
}
os << "\"";
Expand Down
4 changes: 3 additions & 1 deletion test/libsolidity/util/TestFunctionCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ string TestFunctionCall::formatRawParameters(
if (param.format.newline)
os << endl << _linePrefix << "// ";
for (auto const c: param.rawString)
os << (c >= ' ' ? string(1, c) : "\\x" + toHex(static_cast<uint8_t>(c)));
// NOTE: Even though we have a toHex() overload specifically for uint8_t, the compiler
// chooses the one for bytes if the second argument is omitted.
os << (c >= ' ' ? string(1, c) : "\\x" + toHex(static_cast<uint8_t>(c), HexCase::Lower));
if (&param != &_params.back())
os << ", ";
}
Expand Down

0 comments on commit 90fdea9

Please sign in to comment.