Fix error message formatting in isoltest.

This commit is contained in:
chriseth 2020-10-13 12:55:46 +02:00
parent 8fd6de9403
commit fed6ea0125
4 changed files with 33 additions and 19 deletions

View File

@ -218,7 +218,7 @@ string BytesUtils::formatRawBytes(
auto it = _bytes.begin();
if (_bytes.size() != ContractABIUtils::encodingSize(_parameters))
parameters = ContractABIUtils::defaultParameters(ceil(_bytes.size() / 32));
parameters = ContractABIUtils::defaultParameters((_bytes.size() + 31) / 32);
else
parameters = _parameters;
@ -320,7 +320,7 @@ string BytesUtils::formatBytesRange(
auto it = _bytes.begin();
if (_bytes.size() != ContractABIUtils::encodingSize(_parameters))
parameters = ContractABIUtils::defaultParameters(ceil(_bytes.size() / 32));
parameters = ContractABIUtils::defaultParameters((_bytes.size() + 31) / 32);
else
parameters = _parameters;

View File

@ -20,6 +20,9 @@
#include <test/libsolidity/util/SoltestErrors.h>
#include <libsolutil/FunctionSelector.h>
#include <libsolutil/CommonData.h>
#include <liblangutil/Common.h>
#include <boost/algorithm/string.hpp>
@ -314,24 +317,35 @@ solidity::frontend::test::ParameterList ContractABIUtils::defaultParameters(size
return parameters;
}
solidity::frontend::test::ParameterList ContractABIUtils::failureParameters(bytes const _bytes)
solidity::frontend::test::ParameterList ContractABIUtils::failureParameters(bytes const& _bytes)
{
if (_bytes.empty())
return {};
else if (_bytes.size() < 4)
return {Parameter{bytes(), "", ABIType{ABIType::HexString, ABIType::AlignNone, _bytes.size()}, FormatInfo{}}};
else
{
ParameterList parameters;
parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::HexString, ABIType::AlignNone, 4}, FormatInfo{}});
if (_bytes.size() > 4)
uint64_t selector = fromBigEndian<uint64_t>(bytes{_bytes.begin(), _bytes.begin() + 4});
if (selector == selectorFromSignature32("Panic(uint256)"))
parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::Hex}, FormatInfo{}});
else if (selector == selectorFromSignature32("Error(string)"))
{
parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::Hex}, FormatInfo{}});
parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::UnsignedDec}, FormatInfo{}});
}
/// If _bytes contains at least a 1 byte message (function selector + tail pointer + message length + message)
/// append an additional string parameter to represent that message.
if (_bytes.size() > 68)
parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::String}, FormatInfo{}});
}
else
for (size_t i = 4; i < _bytes.size(); i += 32)
parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::HexString, ABIType::AlignNone, 32}, FormatInfo{}});
return parameters;
}
}
size_t ContractABIUtils::encodingSize(
solidity::frontend::test::ParameterList const& _parameters

View File

@ -65,7 +65,7 @@ public:
/// returned values in case of a failure. Creates an additional parameter
/// for the error message if _bytes is larger than 68 bytes
/// (function_selector + tail_ptr + message_length).
static ParameterList failureParameters(bytes const _bytes);
static ParameterList failureParameters(bytes const& _bytes);
/// Returns _count parameters with their type set to ABIType::UnsignedDec
/// and their size set to 32 bytes.

View File

@ -159,7 +159,7 @@ string TestFunctionCall::format(
BytesUtils::formatRawBytes(output, abiParams.value(), _linePrefix) :
BytesUtils::formatRawBytes(
output,
ContractABIUtils::defaultParameters(ceil(output.size() / 32)),
ContractABIUtils::defaultParameters((output.size() + 31) / 32),
_linePrefix
);
@ -248,7 +248,7 @@ string TestFunctionCall::formatBytesParameters(
}
else
{
ParameterList defaultParameters = ContractABIUtils::defaultParameters(ceil(_bytes.size() / 32));
ParameterList defaultParameters = ContractABIUtils::defaultParameters((_bytes.size() + 31) / 32);
ContractABIUtils::overwriteParameters(_errorReporter, defaultParameters, _parameters);
os << BytesUtils::formatBytesRange(_bytes, defaultParameters, _highlight);