mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6263 from ethereum/soltest-output-sizes
[soltest] Print bytes range sizes
This commit is contained in:
commit
e07ca0d2ea
@ -124,13 +124,21 @@ string TestFunctionCall::formatBytesParameters(bytes const& _bytes, dev::solidit
|
|||||||
stringstream resultStream;
|
stringstream resultStream;
|
||||||
if (_bytes.empty())
|
if (_bytes.empty())
|
||||||
return {};
|
return {};
|
||||||
|
auto sizeFold = [](size_t const _a, Parameter const& _b) { return _a + _b.abiType.size; };
|
||||||
|
size_t encodingSize = std::accumulate(_params.begin(), _params.end(), size_t{0}, sizeFold);
|
||||||
|
|
||||||
|
soltestAssert(
|
||||||
|
encodingSize == _bytes.size(),
|
||||||
|
"Encoding does not match byte range: the call returned " +
|
||||||
|
to_string(_bytes.size()) + " bytes, but " +
|
||||||
|
to_string(encodingSize) + " bytes were expected."
|
||||||
|
);
|
||||||
|
|
||||||
auto it = _bytes.begin();
|
auto it = _bytes.begin();
|
||||||
for (auto const& param: _params)
|
for (auto const& param: _params)
|
||||||
{
|
{
|
||||||
long offset = static_cast<long>(param.abiType.size);
|
long offset = static_cast<long>(param.abiType.size);
|
||||||
auto offsetIter = it + offset;
|
auto offsetIter = it + offset;
|
||||||
soltestAssert(offsetIter <= _bytes.end(), "Byte range can not be extended past the end of given bytes.");
|
|
||||||
|
|
||||||
bytes byteRange{it, offsetIter};
|
bytes byteRange{it, offsetIter};
|
||||||
switch (param.abiType.type)
|
switch (param.abiType.type)
|
||||||
{
|
{
|
||||||
@ -176,7 +184,6 @@ string TestFunctionCall::formatBytesParameters(bytes const& _bytes, dev::solidit
|
|||||||
if (it != _bytes.end() && !(param.abiType.type == ABIType::None))
|
if (it != _bytes.end() && !(param.abiType.type == ABIType::None))
|
||||||
resultStream << ", ";
|
resultStream << ", ";
|
||||||
}
|
}
|
||||||
soltestAssert(it == _bytes.end(), "Parameter encoding too short for the given byte range.");
|
|
||||||
return resultStream.str();
|
return resultStream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user