mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix error message formatting in isoltest.
This commit is contained in:
parent
8fd6de9403
commit
fed6ea0125
@ -218,7 +218,7 @@ string BytesUtils::formatRawBytes(
|
|||||||
auto it = _bytes.begin();
|
auto it = _bytes.begin();
|
||||||
|
|
||||||
if (_bytes.size() != ContractABIUtils::encodingSize(_parameters))
|
if (_bytes.size() != ContractABIUtils::encodingSize(_parameters))
|
||||||
parameters = ContractABIUtils::defaultParameters(ceil(_bytes.size() / 32));
|
parameters = ContractABIUtils::defaultParameters((_bytes.size() + 31) / 32);
|
||||||
else
|
else
|
||||||
parameters = _parameters;
|
parameters = _parameters;
|
||||||
|
|
||||||
@ -320,7 +320,7 @@ string BytesUtils::formatBytesRange(
|
|||||||
auto it = _bytes.begin();
|
auto it = _bytes.begin();
|
||||||
|
|
||||||
if (_bytes.size() != ContractABIUtils::encodingSize(_parameters))
|
if (_bytes.size() != ContractABIUtils::encodingSize(_parameters))
|
||||||
parameters = ContractABIUtils::defaultParameters(ceil(_bytes.size() / 32));
|
parameters = ContractABIUtils::defaultParameters((_bytes.size() + 31) / 32);
|
||||||
else
|
else
|
||||||
parameters = _parameters;
|
parameters = _parameters;
|
||||||
|
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
|
|
||||||
#include <test/libsolidity/util/SoltestErrors.h>
|
#include <test/libsolidity/util/SoltestErrors.h>
|
||||||
|
|
||||||
|
#include <libsolutil/FunctionSelector.h>
|
||||||
|
#include <libsolutil/CommonData.h>
|
||||||
|
|
||||||
#include <liblangutil/Common.h>
|
#include <liblangutil/Common.h>
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
@ -314,23 +317,34 @@ solidity::frontend::test::ParameterList ContractABIUtils::defaultParameters(size
|
|||||||
return parameters;
|
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;
|
ParameterList parameters;
|
||||||
|
|
||||||
parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::HexString, ABIType::AlignNone, 4}, FormatInfo{}});
|
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::Hex}, FormatInfo{}});
|
||||||
parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::UnsignedDec}, 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)
|
/// 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.
|
/// append an additional string parameter to represent that message.
|
||||||
if (_bytes.size() > 68)
|
if (_bytes.size() > 68)
|
||||||
parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::String}, FormatInfo{}});
|
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;
|
return parameters;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ContractABIUtils::encodingSize(
|
size_t ContractABIUtils::encodingSize(
|
||||||
|
@ -65,7 +65,7 @@ public:
|
|||||||
/// returned values in case of a failure. Creates an additional parameter
|
/// returned values in case of a failure. Creates an additional parameter
|
||||||
/// for the error message if _bytes is larger than 68 bytes
|
/// for the error message if _bytes is larger than 68 bytes
|
||||||
/// (function_selector + tail_ptr + message_length).
|
/// (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
|
/// Returns _count parameters with their type set to ABIType::UnsignedDec
|
||||||
/// and their size set to 32 bytes.
|
/// and their size set to 32 bytes.
|
||||||
|
@ -159,7 +159,7 @@ string TestFunctionCall::format(
|
|||||||
BytesUtils::formatRawBytes(output, abiParams.value(), _linePrefix) :
|
BytesUtils::formatRawBytes(output, abiParams.value(), _linePrefix) :
|
||||||
BytesUtils::formatRawBytes(
|
BytesUtils::formatRawBytes(
|
||||||
output,
|
output,
|
||||||
ContractABIUtils::defaultParameters(ceil(output.size() / 32)),
|
ContractABIUtils::defaultParameters((output.size() + 31) / 32),
|
||||||
_linePrefix
|
_linePrefix
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ string TestFunctionCall::formatBytesParameters(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ParameterList defaultParameters = ContractABIUtils::defaultParameters(ceil(_bytes.size() / 32));
|
ParameterList defaultParameters = ContractABIUtils::defaultParameters((_bytes.size() + 31) / 32);
|
||||||
|
|
||||||
ContractABIUtils::overwriteParameters(_errorReporter, defaultParameters, _parameters);
|
ContractABIUtils::overwriteParameters(_errorReporter, defaultParameters, _parameters);
|
||||||
os << BytesUtils::formatBytesRange(_bytes, defaultParameters, _highlight);
|
os << BytesUtils::formatBytesRange(_bytes, defaultParameters, _highlight);
|
||||||
|
Loading…
Reference in New Issue
Block a user