mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Purge using namespace std from test/libsolidity/util
This commit is contained in:
parent
fe1f9c640e
commit
fa394018c3
@ -45,6 +45,7 @@ NAMESPACE_STD_FREE_FILES=(
|
||||
test/libsolidity/*
|
||||
test/libsolidity/analysis/*
|
||||
test/libsolidity/interface/*
|
||||
test/libsolidity/util/*
|
||||
)
|
||||
|
||||
(
|
||||
|
@ -37,7 +37,6 @@ using namespace solidity;
|
||||
using namespace solidity::util;
|
||||
using namespace solidity::frontend;
|
||||
using namespace solidity::frontend::test;
|
||||
using namespace std;
|
||||
|
||||
bytes BytesUtils::alignLeft(bytes _bytes)
|
||||
{
|
||||
@ -73,7 +72,7 @@ bytes BytesUtils::applyAlign(
|
||||
}
|
||||
}
|
||||
|
||||
bytes BytesUtils::convertBoolean(string const& _literal)
|
||||
bytes BytesUtils::convertBoolean(std::string const& _literal)
|
||||
{
|
||||
if (_literal == "true")
|
||||
return bytes{true};
|
||||
@ -83,7 +82,7 @@ bytes BytesUtils::convertBoolean(string const& _literal)
|
||||
BOOST_THROW_EXCEPTION(TestParserError("Boolean literal invalid."));
|
||||
}
|
||||
|
||||
bytes BytesUtils::convertNumber(string const& _literal)
|
||||
bytes BytesUtils::convertNumber(std::string const& _literal)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -95,13 +94,13 @@ bytes BytesUtils::convertNumber(string const& _literal)
|
||||
}
|
||||
}
|
||||
|
||||
bytes BytesUtils::convertFixedPoint(string const& _literal, size_t& o_fractionalDigits)
|
||||
bytes BytesUtils::convertFixedPoint(std::string const& _literal, size_t& o_fractionalDigits)
|
||||
{
|
||||
size_t dotPos = _literal.find('.');
|
||||
o_fractionalDigits = dotPos < _literal.size() ? _literal.size() - dotPos : 0;
|
||||
bool negative = !_literal.empty() && _literal.at(0) == '-';
|
||||
// remove decimal point
|
||||
string valueInteger = _literal.substr(0, dotPos) + _literal.substr(dotPos + 1);
|
||||
std::string valueInteger = _literal.substr(0, dotPos) + _literal.substr(dotPos + 1);
|
||||
// erase leading zeros to avoid parsing as octal.
|
||||
while (!valueInteger.empty() && (valueInteger.at(0) == '0' || valueInteger.at(0) == '-'))
|
||||
valueInteger.erase(valueInteger.begin());
|
||||
@ -120,7 +119,7 @@ bytes BytesUtils::convertFixedPoint(string const& _literal, size_t& o_fractional
|
||||
}
|
||||
}
|
||||
|
||||
bytes BytesUtils::convertHexNumber(string const& _literal)
|
||||
bytes BytesUtils::convertHexNumber(std::string const& _literal)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -132,7 +131,7 @@ bytes BytesUtils::convertHexNumber(string const& _literal)
|
||||
}
|
||||
}
|
||||
|
||||
bytes BytesUtils::convertString(string const& _literal)
|
||||
bytes BytesUtils::convertString(std::string const& _literal)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -144,18 +143,18 @@ bytes BytesUtils::convertString(string const& _literal)
|
||||
}
|
||||
}
|
||||
|
||||
string BytesUtils::formatUnsigned(bytes const& _bytes)
|
||||
std::string BytesUtils::formatUnsigned(bytes const& _bytes)
|
||||
{
|
||||
stringstream os;
|
||||
std::stringstream os;
|
||||
|
||||
soltestAssert(!_bytes.empty() && _bytes.size() <= 32, "");
|
||||
|
||||
return fromBigEndian<u256>(_bytes).str();
|
||||
}
|
||||
|
||||
string BytesUtils::formatSigned(bytes const& _bytes)
|
||||
std::string BytesUtils::formatSigned(bytes const& _bytes)
|
||||
{
|
||||
stringstream os;
|
||||
std::stringstream os;
|
||||
|
||||
soltestAssert(!_bytes.empty() && _bytes.size() <= 32, "");
|
||||
|
||||
@ -167,9 +166,9 @@ string BytesUtils::formatSigned(bytes const& _bytes)
|
||||
return os.str();
|
||||
}
|
||||
|
||||
string BytesUtils::formatBoolean(bytes const& _bytes)
|
||||
std::string BytesUtils::formatBoolean(bytes const& _bytes)
|
||||
{
|
||||
stringstream os;
|
||||
std::stringstream os;
|
||||
u256 result = fromBigEndian<u256>(_bytes);
|
||||
|
||||
if (result == 0)
|
||||
@ -182,32 +181,32 @@ string BytesUtils::formatBoolean(bytes const& _bytes)
|
||||
return os.str();
|
||||
}
|
||||
|
||||
string BytesUtils::formatHex(bytes const& _bytes, bool _shorten)
|
||||
std::string BytesUtils::formatHex(bytes const& _bytes, bool _shorten)
|
||||
{
|
||||
soltestAssert(!_bytes.empty() && _bytes.size() <= 32, "");
|
||||
u256 value = fromBigEndian<u256>(_bytes);
|
||||
string output = toCompactHexWithPrefix(value);
|
||||
std::string output = toCompactHexWithPrefix(value);
|
||||
|
||||
if (_shorten)
|
||||
return output.substr(0, output.size() - countRightPaddedZeros(_bytes) * 2);
|
||||
return output;
|
||||
}
|
||||
|
||||
string BytesUtils::formatHexString(bytes const& _bytes)
|
||||
std::string BytesUtils::formatHexString(bytes const& _bytes)
|
||||
{
|
||||
stringstream os;
|
||||
std::stringstream os;
|
||||
|
||||
os << "hex\"" << util::toHex(_bytes) << "\"";
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
string BytesUtils::formatString(bytes const& _bytes, size_t _cutOff)
|
||||
std::string BytesUtils::formatString(bytes const& _bytes, size_t _cutOff)
|
||||
{
|
||||
stringstream os;
|
||||
std::stringstream os;
|
||||
|
||||
os << "\"";
|
||||
for (size_t i = 0; i < min(_cutOff, _bytes.size()); ++i)
|
||||
for (size_t i = 0; i < std::min(_cutOff, _bytes.size()); ++i)
|
||||
{
|
||||
auto const v = _bytes[i];
|
||||
switch (v)
|
||||
@ -232,7 +231,7 @@ string BytesUtils::formatString(bytes const& _bytes, size_t _cutOff)
|
||||
|
||||
std::string BytesUtils::formatFixedPoint(bytes const& _bytes, bool _signed, size_t _fractionalDigits)
|
||||
{
|
||||
string decimal;
|
||||
std::string decimal;
|
||||
bool negative = false;
|
||||
if (_signed)
|
||||
{
|
||||
@ -246,19 +245,19 @@ std::string BytesUtils::formatFixedPoint(bytes const& _bytes, bool _signed, size
|
||||
{
|
||||
size_t numDigits = decimal.length() - (negative ? 1 : 0);
|
||||
if (_fractionalDigits >= numDigits)
|
||||
decimal.insert(negative ? 1 : 0, string(_fractionalDigits + 1 - numDigits, '0'));
|
||||
decimal.insert(negative ? 1 : 0, std::string(_fractionalDigits + 1 - numDigits, '0'));
|
||||
decimal.insert(decimal.length() - _fractionalDigits, ".");
|
||||
}
|
||||
return decimal;
|
||||
}
|
||||
|
||||
string BytesUtils::formatRawBytes(
|
||||
std::string BytesUtils::formatRawBytes(
|
||||
bytes const& _bytes,
|
||||
solidity::frontend::test::ParameterList const& _parameters,
|
||||
string _linePrefix
|
||||
std::string _linePrefix
|
||||
)
|
||||
{
|
||||
stringstream os;
|
||||
std::stringstream os;
|
||||
ParameterList parameters;
|
||||
auto it = _bytes.begin();
|
||||
|
||||
@ -283,7 +282,7 @@ string BytesUtils::formatRawBytes(
|
||||
|
||||
for (auto const& parameter: parameters)
|
||||
{
|
||||
long actualSize = min(
|
||||
long actualSize = std::min(
|
||||
distance(it, _bytes.end()),
|
||||
static_cast<ParameterList::difference_type>(parameter.abiType.size)
|
||||
);
|
||||
@ -292,7 +291,7 @@ string BytesUtils::formatRawBytes(
|
||||
|
||||
os << _linePrefix << byteRange;
|
||||
if (¶meter != ¶meters.back())
|
||||
os << endl;
|
||||
os << std::endl;
|
||||
|
||||
it += actualSize;
|
||||
}
|
||||
@ -300,12 +299,12 @@ string BytesUtils::formatRawBytes(
|
||||
return os.str();
|
||||
}
|
||||
|
||||
string BytesUtils::formatBytes(
|
||||
std::string BytesUtils::formatBytes(
|
||||
bytes const& _bytes,
|
||||
ABIType const& _abiType
|
||||
)
|
||||
{
|
||||
stringstream os;
|
||||
std::stringstream os;
|
||||
|
||||
switch (_abiType.type)
|
||||
{
|
||||
@ -330,7 +329,7 @@ string BytesUtils::formatBytes(
|
||||
{
|
||||
auto entropy = [](std::string const& str) -> double {
|
||||
double result = 0;
|
||||
map<char, double> frequencies;
|
||||
std::map<char, double> frequencies;
|
||||
for (char c: str)
|
||||
frequencies[c]++;
|
||||
for (auto p: frequencies)
|
||||
@ -376,13 +375,13 @@ string BytesUtils::formatBytes(
|
||||
return os.str();
|
||||
}
|
||||
|
||||
string BytesUtils::formatBytesRange(
|
||||
std::string BytesUtils::formatBytesRange(
|
||||
bytes _bytes,
|
||||
solidity::frontend::test::ParameterList const& _parameters,
|
||||
bool _highlight
|
||||
)
|
||||
{
|
||||
stringstream os;
|
||||
std::stringstream os;
|
||||
ParameterList parameters;
|
||||
auto it = _bytes.begin();
|
||||
|
||||
@ -407,7 +406,7 @@ string BytesUtils::formatBytesRange(
|
||||
|
||||
for (auto const& parameter: parameters)
|
||||
{
|
||||
long actualSize = min(
|
||||
long actualSize = std::min(
|
||||
distance(it, _bytes.end()),
|
||||
static_cast<ParameterList::difference_type>(parameter.abiType.size)
|
||||
);
|
||||
|
@ -22,7 +22,6 @@
|
||||
|
||||
#include <libsolutil/CommonData.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity::util;
|
||||
using namespace solidity::test;
|
||||
|
||||
|
@ -20,22 +20,21 @@
|
||||
|
||||
#include <regex>
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity;
|
||||
using namespace solidity::frontend;
|
||||
|
||||
string test::withPreamble(string const& _sourceCode, bool _addAbicoderV1Pragma)
|
||||
std::string test::withPreamble(std::string const& _sourceCode, bool _addAbicoderV1Pragma)
|
||||
{
|
||||
static string const versionPragma = "pragma solidity >=0.0;\n";
|
||||
static string const licenseComment = "// SPDX-License-Identifier: GPL-3.0\n";
|
||||
static string const abicoderPragma = "pragma abicoder v1;\n";
|
||||
static std::string const versionPragma = "pragma solidity >=0.0;\n";
|
||||
static std::string const licenseComment = "// SPDX-License-Identifier: GPL-3.0\n";
|
||||
static std::string const abicoderPragma = "pragma abicoder v1;\n";
|
||||
|
||||
// NOTE: These checks are intentionally loose to match weird cases.
|
||||
// We can manually adjust a test case where this causes problem.
|
||||
bool licenseMissing = _sourceCode.find("SPDX-License-Identifier:") == string::npos;
|
||||
bool licenseMissing = _sourceCode.find("SPDX-License-Identifier:") == std::string::npos;
|
||||
bool abicoderMissing =
|
||||
_sourceCode.find("pragma experimental ABIEncoderV2;") == string::npos &&
|
||||
_sourceCode.find("pragma abicoder") == string::npos;
|
||||
_sourceCode.find("pragma experimental ABIEncoderV2;") == std::string::npos &&
|
||||
_sourceCode.find("pragma abicoder") == std::string::npos;
|
||||
|
||||
return
|
||||
versionPragma +
|
||||
@ -52,16 +51,16 @@ StringMap test::withPreamble(StringMap _sources, bool _addAbicoderV1Pragma)
|
||||
return _sources;
|
||||
}
|
||||
|
||||
string test::stripPreReleaseWarning(string const& _stderrContent)
|
||||
std::string test::stripPreReleaseWarning(std::string const& _stderrContent)
|
||||
{
|
||||
static regex const preReleaseWarningRegex{
|
||||
static std::regex const preReleaseWarningRegex{
|
||||
R"(Warning( \(3805\))?: This is a pre-release compiler version, please do not use it in production\.\n)"
|
||||
R"((\n)?)"
|
||||
};
|
||||
static regex const noOutputRegex{
|
||||
static std::regex const noOutputRegex{
|
||||
R"(Compiler run successful, no output requested\.\n)"
|
||||
};
|
||||
|
||||
string output = regex_replace(_stderrContent, preReleaseWarningRegex, "");
|
||||
return regex_replace(std::move(output), noOutputRegex, "");
|
||||
std::string output = std::regex_replace(_stderrContent, preReleaseWarningRegex, "");
|
||||
return std::regex_replace(std::move(output), noOutputRegex, "");
|
||||
}
|
||||
|
@ -41,96 +41,95 @@ using namespace solidity;
|
||||
using namespace solidity::util;
|
||||
using namespace solidity::langutil;
|
||||
using namespace solidity::frontend::test;
|
||||
using namespace std;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using ParameterList = solidity::frontend::test::ParameterList;
|
||||
|
||||
size_t arraySize(string const& _arrayType)
|
||||
size_t arraySize(std::string const& _arrayType)
|
||||
{
|
||||
auto leftBrack = _arrayType.find("[");
|
||||
auto rightBrack = _arrayType.rfind("]");
|
||||
|
||||
soltestAssert(
|
||||
leftBrack != string::npos &&
|
||||
rightBrack != string::npos &&
|
||||
leftBrack != std::string::npos &&
|
||||
rightBrack != std::string::npos &&
|
||||
rightBrack == _arrayType.size() - 1 &&
|
||||
leftBrack < rightBrack,
|
||||
""
|
||||
);
|
||||
|
||||
string size = _arrayType.substr(leftBrack + 1, rightBrack - leftBrack - 1);
|
||||
std::string size = _arrayType.substr(leftBrack + 1, rightBrack - leftBrack - 1);
|
||||
|
||||
return static_cast<size_t>(stoi(size));
|
||||
}
|
||||
|
||||
bool isBool(string const& _type)
|
||||
bool isBool(std::string const& _type)
|
||||
{
|
||||
return _type == "bool";
|
||||
}
|
||||
|
||||
bool isUint(string const& _type)
|
||||
bool isUint(std::string const& _type)
|
||||
{
|
||||
return regex_match(_type, regex{"uint\\d*"});
|
||||
return regex_match(_type, std::regex{"uint\\d*"});
|
||||
}
|
||||
|
||||
bool isInt(string const& _type)
|
||||
bool isInt(std::string const& _type)
|
||||
{
|
||||
return regex_match(_type, regex{"int\\d*"});
|
||||
return regex_match(_type, std::regex{"int\\d*"});
|
||||
}
|
||||
|
||||
bool isFixedBytes(string const& _type)
|
||||
bool isFixedBytes(std::string const& _type)
|
||||
{
|
||||
return regex_match(_type, regex{"bytes\\d+"});
|
||||
return regex_match(_type, std::regex{"bytes\\d+"});
|
||||
}
|
||||
|
||||
bool isBytes(string const& _type)
|
||||
bool isBytes(std::string const& _type)
|
||||
{
|
||||
return regex_match(_type, regex{"\\bbytes\\b"});
|
||||
return regex_match(_type, std::regex{"\\bbytes\\b"});
|
||||
}
|
||||
|
||||
bool isString(string const& _type)
|
||||
bool isString(std::string const& _type)
|
||||
{
|
||||
return _type == "string";
|
||||
}
|
||||
|
||||
bool isFixedBoolArray(string const& _type)
|
||||
bool isFixedBoolArray(std::string const& _type)
|
||||
{
|
||||
return regex_match(_type, regex{"bool\\[\\d+\\]"});
|
||||
return regex_match(_type, std::regex{"bool\\[\\d+\\]"});
|
||||
}
|
||||
|
||||
bool isFixedUintArray(string const& _type)
|
||||
bool isFixedUintArray(std::string const& _type)
|
||||
{
|
||||
return regex_match(_type, regex{"uint\\d*\\[\\d+\\]"});
|
||||
return regex_match(_type, std::regex{"uint\\d*\\[\\d+\\]"});
|
||||
}
|
||||
|
||||
bool isFixedIntArray(string const& _type)
|
||||
bool isFixedIntArray(std::string const& _type)
|
||||
{
|
||||
return regex_match(_type, regex{"int\\d*\\[\\d+\\]"});
|
||||
return regex_match(_type, std::regex{"int\\d*\\[\\d+\\]"});
|
||||
}
|
||||
|
||||
bool isFixedStringArray(string const& _type)
|
||||
bool isFixedStringArray(std::string const& _type)
|
||||
{
|
||||
return regex_match(_type, regex{"string\\[\\d+\\]"});
|
||||
return regex_match(_type, std::regex{"string\\[\\d+\\]"});
|
||||
}
|
||||
|
||||
bool isTuple(string const& _type)
|
||||
bool isTuple(std::string const& _type)
|
||||
{
|
||||
return _type == "tuple";
|
||||
}
|
||||
|
||||
bool isFixedTupleArray(string const& _type)
|
||||
bool isFixedTupleArray(std::string const& _type)
|
||||
{
|
||||
return regex_match(_type, regex{"tuple\\[\\d+\\]"});
|
||||
return regex_match(_type, std::regex{"tuple\\[\\d+\\]"});
|
||||
}
|
||||
|
||||
optional<ABIType> isFixedPoint(string const& type)
|
||||
std::optional<ABIType> isFixedPoint(std::string const& type)
|
||||
{
|
||||
optional<ABIType> fixedPointType;
|
||||
smatch matches;
|
||||
if (regex_match(type, matches, regex{"(u?)fixed(\\d+)x(\\d+)"}))
|
||||
std::optional<ABIType> fixedPointType;
|
||||
std::smatch matches;
|
||||
if (regex_match(type, matches, std::regex{"(u?)fixed(\\d+)x(\\d+)"}))
|
||||
{
|
||||
ABIType abiType(ABIType::SignedFixedPoint);
|
||||
if (matches[1].str() == "u")
|
||||
@ -141,10 +140,10 @@ optional<ABIType> isFixedPoint(string const& type)
|
||||
return fixedPointType;
|
||||
}
|
||||
|
||||
string functionSignatureFromABI(Json::Value const& _functionABI)
|
||||
std::string functionSignatureFromABI(Json::Value const& _functionABI)
|
||||
{
|
||||
auto inputs = _functionABI["inputs"];
|
||||
string signature = {_functionABI["name"].asString() + "("};
|
||||
std::string signature = {_functionABI["name"].asString() + "("};
|
||||
size_t parameterCount = 0;
|
||||
|
||||
for (auto const& input: inputs)
|
||||
@ -163,7 +162,7 @@ string functionSignatureFromABI(Json::Value const& _functionABI)
|
||||
std::optional<solidity::frontend::test::ParameterList> ContractABIUtils::parametersFromJsonOutputs(
|
||||
ErrorReporter& _errorReporter,
|
||||
Json::Value const& _contractABI,
|
||||
string const& _functionSignature
|
||||
std::string const& _functionSignature
|
||||
)
|
||||
{
|
||||
if (!_contractABI)
|
||||
@ -178,7 +177,7 @@ std::optional<solidity::frontend::test::ParameterList> ContractABIUtils::paramet
|
||||
|
||||
for (auto const& output: function["outputs"])
|
||||
{
|
||||
string type = output["type"].asString();
|
||||
std::string type = output["type"].asString();
|
||||
|
||||
ABITypes inplaceTypes;
|
||||
ABITypes dynamicTypes;
|
||||
@ -216,7 +215,7 @@ bool ContractABIUtils::appendTypesFromName(
|
||||
bool _isCompoundType
|
||||
)
|
||||
{
|
||||
string type = _functionOutput["type"].asString();
|
||||
std::string type = _functionOutput["type"].asString();
|
||||
if (isBool(type))
|
||||
_inplaceTypes.push_back(ABIType{ABIType::Boolean});
|
||||
else if (isUint(type))
|
||||
@ -245,16 +244,16 @@ bool ContractABIUtils::appendTypesFromName(
|
||||
_dynamicTypes += inplaceTypes + dynamicTypes;
|
||||
}
|
||||
else if (isFixedBoolArray(type))
|
||||
_inplaceTypes += vector<ABIType>(arraySize(type), ABIType{ABIType::Boolean});
|
||||
_inplaceTypes += std::vector<ABIType>(arraySize(type), ABIType{ABIType::Boolean});
|
||||
else if (isFixedUintArray(type))
|
||||
_inplaceTypes += vector<ABIType>(arraySize(type), ABIType{ABIType::UnsignedDec});
|
||||
_inplaceTypes += std::vector<ABIType>(arraySize(type), ABIType{ABIType::UnsignedDec});
|
||||
else if (isFixedIntArray(type))
|
||||
_inplaceTypes += vector<ABIType>(arraySize(type), ABIType{ABIType::SignedDec});
|
||||
_inplaceTypes += std::vector<ABIType>(arraySize(type), ABIType{ABIType::SignedDec});
|
||||
else if (isFixedStringArray(type))
|
||||
{
|
||||
_inplaceTypes.push_back(ABIType{ABIType::Hex});
|
||||
|
||||
_dynamicTypes += vector<ABIType>(arraySize(type), ABIType{ABIType::Hex});
|
||||
_dynamicTypes += std::vector<ABIType>(arraySize(type), ABIType{ABIType::Hex});
|
||||
|
||||
for (size_t i = 0; i < arraySize(type); i++)
|
||||
{
|
||||
@ -262,7 +261,7 @@ bool ContractABIUtils::appendTypesFromName(
|
||||
_dynamicTypes.push_back(ABIType{ABIType::String, ABIType::AlignLeft});
|
||||
}
|
||||
}
|
||||
else if (optional<ABIType> fixedPointType = isFixedPoint(type))
|
||||
else if (std::optional<ABIType> fixedPointType = isFixedPoint(type))
|
||||
_inplaceTypes.push_back(*fixedPointType);
|
||||
else if (isBytes(type))
|
||||
return false;
|
||||
@ -280,7 +279,7 @@ void ContractABIUtils::overwriteParameters(
|
||||
solidity::frontend::test::ParameterList const& _sourceParameters
|
||||
)
|
||||
{
|
||||
using namespace placeholders;
|
||||
using namespace std::placeholders;
|
||||
for (auto&& [source, target]: ranges::views::zip(_sourceParameters, _targetParameters))
|
||||
if (
|
||||
source.abiType.size != target.abiType.size ||
|
||||
@ -304,8 +303,8 @@ solidity::frontend::test::ParameterList ContractABIUtils::preferredParameters(
|
||||
{
|
||||
_errorReporter.warning(
|
||||
"Encoding does not match byte range. The call returned " +
|
||||
to_string(_bytes.size()) + " bytes, but " +
|
||||
to_string(encodingSize(_targetParameters)) + " bytes were expected."
|
||||
std::to_string(_bytes.size()) + " bytes, but " +
|
||||
std::to_string(encodingSize(_targetParameters)) + " bytes were expected."
|
||||
);
|
||||
return _sourceParameters;
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ using namespace solidity;
|
||||
using namespace solidity::util;
|
||||
using namespace solidity::frontend;
|
||||
using namespace solidity::frontend::test;
|
||||
using namespace std;
|
||||
|
||||
using Token = soltest::Token;
|
||||
|
||||
@ -54,9 +53,9 @@ char TestFileParser::Scanner::peek() const noexcept
|
||||
return *next;
|
||||
}
|
||||
|
||||
vector<solidity::frontend::test::FunctionCall> TestFileParser::parseFunctionCalls(size_t _lineOffset)
|
||||
std::vector<solidity::frontend::test::FunctionCall> TestFileParser::parseFunctionCalls(size_t _lineOffset)
|
||||
{
|
||||
vector<FunctionCall> calls;
|
||||
std::vector<FunctionCall> calls;
|
||||
if (!accept(Token::EOS))
|
||||
{
|
||||
soltestAssert(m_scanner.currentToken() == Token::Unknown, "");
|
||||
@ -84,8 +83,8 @@ vector<solidity::frontend::test::FunctionCall> TestFileParser::parseFunctionCall
|
||||
if (calls.empty())
|
||||
BOOST_THROW_EXCEPTION(TestParserError("Expected function call before gas usage filter."));
|
||||
|
||||
string runType = m_scanner.currentLiteral();
|
||||
if (set<string>{"ir", "irOptimized", "legacy", "legacyOptimized"}.count(runType) > 0)
|
||||
std::string runType = m_scanner.currentLiteral();
|
||||
if (std::set<std::string>{"ir", "irOptimized", "legacy", "legacyOptimized"}.count(runType) > 0)
|
||||
{
|
||||
m_scanner.scanNextToken();
|
||||
expect(Token::Colon);
|
||||
@ -104,7 +103,7 @@ vector<solidity::frontend::test::FunctionCall> TestFileParser::parseFunctionCall
|
||||
if (accept(Token::Library, true))
|
||||
{
|
||||
expect(Token::Colon);
|
||||
string libraryName;
|
||||
std::string libraryName;
|
||||
if (accept(Token::String))
|
||||
{
|
||||
call.libraryFile = m_scanner.currentLiteral();
|
||||
@ -184,7 +183,7 @@ vector<solidity::frontend::test::FunctionCall> TestFileParser::parseFunctionCall
|
||||
catch (TestParserError const& _e)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(
|
||||
TestParserError("Line " + to_string(_lineOffset + m_lineNumber) + ": " + _e.what())
|
||||
TestParserError("Line " + std::to_string(_lineOffset + m_lineNumber) + ": " + _e.what())
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -193,12 +192,12 @@ vector<solidity::frontend::test::FunctionCall> TestFileParser::parseFunctionCall
|
||||
return calls;
|
||||
}
|
||||
|
||||
vector<string> TestFileParser::parseFunctionCallSideEffects()
|
||||
std::vector<std::string> TestFileParser::parseFunctionCallSideEffects()
|
||||
{
|
||||
vector<string> result;
|
||||
std::vector<std::string> result;
|
||||
while (accept(Token::Tilde, false))
|
||||
{
|
||||
string effect = m_scanner.currentLiteral();
|
||||
std::string effect = m_scanner.currentLiteral();
|
||||
result.emplace_back(effect);
|
||||
soltestAssert(m_scanner.currentToken() == Token::Tilde, "");
|
||||
m_scanner.scanNextToken();
|
||||
@ -232,9 +231,9 @@ bool TestFileParser::expect(Token _token, bool const _advance)
|
||||
return true;
|
||||
}
|
||||
|
||||
pair<string, bool> TestFileParser::parseFunctionSignature()
|
||||
std::pair<std::string, bool> TestFileParser::parseFunctionSignature()
|
||||
{
|
||||
string signature;
|
||||
std::string signature;
|
||||
bool hasName = false;
|
||||
|
||||
if (accept(Token::Identifier, false))
|
||||
@ -250,7 +249,7 @@ pair<string, bool> TestFileParser::parseFunctionSignature()
|
||||
signature += formatToken(Token::LParen);
|
||||
expect(Token::LParen);
|
||||
|
||||
string parameters;
|
||||
std::string parameters;
|
||||
if (!accept(Token::RParen, false))
|
||||
parameters = parseIdentifierOrTuple();
|
||||
|
||||
@ -367,7 +366,7 @@ Parameter TestFileParser::parseParameter()
|
||||
BOOST_THROW_EXCEPTION(TestParserError("Invalid boolean literal."));
|
||||
|
||||
parameter.abiType = ABIType{ABIType::Boolean, ABIType::AlignRight, 32};
|
||||
string parsed = parseBoolean();
|
||||
std::string parsed = parseBoolean();
|
||||
parameter.rawString += parsed;
|
||||
parameter.rawBytes = BytesUtils::applyAlign(
|
||||
parameter.alignment,
|
||||
@ -381,7 +380,7 @@ Parameter TestFileParser::parseParameter()
|
||||
BOOST_THROW_EXCEPTION(TestParserError("Invalid hex number literal."));
|
||||
|
||||
parameter.abiType = ABIType{ABIType::Hex, ABIType::AlignRight, 32};
|
||||
string parsed = parseHexNumber();
|
||||
std::string parsed = parseHexNumber();
|
||||
parameter.rawString += parsed;
|
||||
parameter.rawBytes = BytesUtils::applyAlign(
|
||||
parameter.alignment,
|
||||
@ -396,7 +395,7 @@ Parameter TestFileParser::parseParameter()
|
||||
if (parameter.alignment != Parameter::Alignment::None)
|
||||
BOOST_THROW_EXCEPTION(TestParserError("Hex string literals cannot be aligned or padded."));
|
||||
|
||||
string parsed = parseString();
|
||||
std::string parsed = parseString();
|
||||
parameter.rawString += "hex\"" + parsed + "\"";
|
||||
parameter.rawBytes = BytesUtils::convertHexNumber(parsed);
|
||||
parameter.abiType = ABIType{
|
||||
@ -410,7 +409,7 @@ Parameter TestFileParser::parseParameter()
|
||||
if (parameter.alignment != Parameter::Alignment::None)
|
||||
BOOST_THROW_EXCEPTION(TestParserError("String literals cannot be aligned or padded."));
|
||||
|
||||
string parsed = parseString();
|
||||
std::string parsed = parseString();
|
||||
parameter.abiType = ABIType{ABIType::String, ABIType::AlignLeft, parsed.size()};
|
||||
parameter.rawString += "\"" + parsed + "\"";
|
||||
parameter.rawBytes = BytesUtils::applyAlign(
|
||||
@ -424,12 +423,12 @@ Parameter TestFileParser::parseParameter()
|
||||
auto type = isSigned ? ABIType::SignedDec : ABIType::UnsignedDec;
|
||||
|
||||
parameter.abiType = ABIType{type, ABIType::AlignRight, 32};
|
||||
string parsed = parseDecimalNumber();
|
||||
std::string parsed = parseDecimalNumber();
|
||||
parameter.rawString += parsed;
|
||||
if (isSigned)
|
||||
parsed = "-" + parsed;
|
||||
|
||||
if (parsed.find('.') == string::npos)
|
||||
if (parsed.find('.') == std::string::npos)
|
||||
parameter.rawBytes = BytesUtils::applyAlign(
|
||||
parameter.alignment,
|
||||
parameter.abiType,
|
||||
@ -458,9 +457,9 @@ Parameter TestFileParser::parseParameter()
|
||||
return parameter;
|
||||
}
|
||||
|
||||
string TestFileParser::parseIdentifierOrTuple()
|
||||
std::string TestFileParser::parseIdentifierOrTuple()
|
||||
{
|
||||
string identOrTuple;
|
||||
std::string identOrTuple;
|
||||
|
||||
auto parseArrayDimensions = [&]()
|
||||
{
|
||||
@ -499,43 +498,43 @@ string TestFileParser::parseIdentifierOrTuple()
|
||||
return identOrTuple;
|
||||
}
|
||||
|
||||
string TestFileParser::parseBoolean()
|
||||
std::string TestFileParser::parseBoolean()
|
||||
{
|
||||
string literal = m_scanner.currentLiteral();
|
||||
std::string literal = m_scanner.currentLiteral();
|
||||
expect(Token::Boolean);
|
||||
return literal;
|
||||
}
|
||||
|
||||
string TestFileParser::parseComment()
|
||||
std::string TestFileParser::parseComment()
|
||||
{
|
||||
string comment = m_scanner.currentLiteral();
|
||||
std::string comment = m_scanner.currentLiteral();
|
||||
if (accept(Token::Comment, true))
|
||||
return comment;
|
||||
return string{};
|
||||
return std::string{};
|
||||
}
|
||||
|
||||
string TestFileParser::parseDecimalNumber()
|
||||
std::string TestFileParser::parseDecimalNumber()
|
||||
{
|
||||
string literal = m_scanner.currentLiteral();
|
||||
std::string literal = m_scanner.currentLiteral();
|
||||
expect(Token::Number);
|
||||
return literal;
|
||||
}
|
||||
|
||||
string TestFileParser::parseHexNumber()
|
||||
std::string TestFileParser::parseHexNumber()
|
||||
{
|
||||
string literal = m_scanner.currentLiteral();
|
||||
std::string literal = m_scanner.currentLiteral();
|
||||
expect(Token::HexNumber);
|
||||
return literal;
|
||||
}
|
||||
|
||||
string TestFileParser::parseString()
|
||||
std::string TestFileParser::parseString()
|
||||
{
|
||||
string literal = m_scanner.currentLiteral();
|
||||
std::string literal = m_scanner.currentLiteral();
|
||||
expect(Token::String);
|
||||
return literal;
|
||||
}
|
||||
|
||||
void TestFileParser::Scanner::readStream(istream& _stream)
|
||||
void TestFileParser::Scanner::readStream(std::istream& _stream)
|
||||
{
|
||||
std::string line;
|
||||
// TODO: std::getline(..) removes newlines '\n', if present. This could be improved.
|
||||
@ -644,16 +643,16 @@ void TestFileParser::Scanner::scanNextToken()
|
||||
m_currentLiteral = "";
|
||||
}
|
||||
else
|
||||
BOOST_THROW_EXCEPTION(TestParserError("Unexpected character: '" + string{current()} + "'"));
|
||||
BOOST_THROW_EXCEPTION(TestParserError("Unexpected character: '" + std::string{current()} + "'"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (m_currentToken == Token::Whitespace);
|
||||
}
|
||||
|
||||
string TestFileParser::Scanner::readLine()
|
||||
std::string TestFileParser::Scanner::readLine()
|
||||
{
|
||||
string line;
|
||||
std::string line;
|
||||
// Right now the scanner discards all (real) new-lines '\n' in TestFileParser::Scanner::readStream(..).
|
||||
// Token::NewLine is defined as `//`, and NOT '\n'. We are just searching here for the next `/`.
|
||||
// Note that `/` anywhere else than at the beginning of a line is currently forbidden (TODO: until we fix newline handling).
|
||||
@ -666,9 +665,9 @@ string TestFileParser::Scanner::readLine()
|
||||
return line;
|
||||
}
|
||||
|
||||
string TestFileParser::Scanner::scanComment()
|
||||
std::string TestFileParser::Scanner::scanComment()
|
||||
{
|
||||
string comment;
|
||||
std::string comment;
|
||||
advance();
|
||||
|
||||
while (current() != '#')
|
||||
@ -679,9 +678,9 @@ string TestFileParser::Scanner::scanComment()
|
||||
return comment;
|
||||
}
|
||||
|
||||
string TestFileParser::Scanner::scanIdentifierOrKeyword()
|
||||
std::string TestFileParser::Scanner::scanIdentifierOrKeyword()
|
||||
{
|
||||
string identifier;
|
||||
std::string identifier;
|
||||
identifier += current();
|
||||
while (langutil::isIdentifierPart(peek()))
|
||||
{
|
||||
@ -691,9 +690,9 @@ string TestFileParser::Scanner::scanIdentifierOrKeyword()
|
||||
return identifier;
|
||||
}
|
||||
|
||||
string TestFileParser::Scanner::scanDecimalNumber()
|
||||
std::string TestFileParser::Scanner::scanDecimalNumber()
|
||||
{
|
||||
string number;
|
||||
std::string number;
|
||||
number += current();
|
||||
while (langutil::isDecimalDigit(peek()) || '.' == peek())
|
||||
{
|
||||
@ -703,9 +702,9 @@ string TestFileParser::Scanner::scanDecimalNumber()
|
||||
return number;
|
||||
}
|
||||
|
||||
string TestFileParser::Scanner::scanHexNumber()
|
||||
std::string TestFileParser::Scanner::scanHexNumber()
|
||||
{
|
||||
string number;
|
||||
std::string number;
|
||||
number += current();
|
||||
while (langutil::isHexDigit(peek()))
|
||||
{
|
||||
@ -715,9 +714,9 @@ string TestFileParser::Scanner::scanHexNumber()
|
||||
return number;
|
||||
}
|
||||
|
||||
string TestFileParser::Scanner::scanString()
|
||||
std::string TestFileParser::Scanner::scanString()
|
||||
{
|
||||
string str;
|
||||
std::string str;
|
||||
advance();
|
||||
|
||||
while (current() != '\"')
|
||||
@ -766,7 +765,7 @@ string TestFileParser::Scanner::scanString()
|
||||
// TODO: use fromHex() from CommonData
|
||||
char TestFileParser::Scanner::scanHexPart()
|
||||
{
|
||||
auto toLower = [](char _c) -> char { return tolower(_c, locale::classic()); };
|
||||
auto toLower = [](char _c) -> char { return tolower(_c, std::locale::classic()); };
|
||||
|
||||
advance(); // skip 'x'
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include <test/libsolidity/util/SoltestErrors.h>
|
||||
#include <test/libsolidity/util/TestFileParser.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity::util;
|
||||
using namespace solidity::test;
|
||||
|
||||
@ -43,23 +42,23 @@ using Mode = FunctionCall::DisplayMode;
|
||||
namespace
|
||||
{
|
||||
|
||||
vector<FunctionCall> parse(string const& _source, std::map<std::string, Builtin> const& _builtins = {})
|
||||
std::vector<FunctionCall> parse(std::string const& _source, std::map<std::string, Builtin> const& _builtins = {})
|
||||
{
|
||||
istringstream stream{_source, ios_base::out};
|
||||
std::istringstream stream{_source, std::ios_base::out};
|
||||
return TestFileParser{stream, _builtins}.parseFunctionCalls(0);
|
||||
}
|
||||
|
||||
void testFunctionCall(
|
||||
FunctionCall const& _call,
|
||||
FunctionCall::DisplayMode _mode,
|
||||
string _signature = "",
|
||||
std::string _signature = "",
|
||||
bool _failure = true,
|
||||
bytes _arguments = bytes{},
|
||||
bytes _expectations = bytes{},
|
||||
FunctionValue _value = { 0 },
|
||||
string _argumentComment = "",
|
||||
string _expectationComment = "",
|
||||
vector<string> _rawArguments = vector<string>{},
|
||||
std::string _argumentComment = "",
|
||||
std::string _expectationComment = "",
|
||||
std::vector<std::string> _rawArguments = std::vector<std::string>{},
|
||||
bool _isConstructor = false,
|
||||
bool _isLibrary = false
|
||||
)
|
||||
@ -242,7 +241,7 @@ BOOST_AUTO_TEST_CASE(call_revert_message)
|
||||
"f()",
|
||||
true,
|
||||
fmt::encodeArgs(),
|
||||
fromHex("08c379a0") + fmt::encodeDyn(string{"Revert"})
|
||||
fromHex("08c379a0") + fmt::encodeDyn(std::string{"Revert"})
|
||||
);
|
||||
}
|
||||
|
||||
@ -364,7 +363,7 @@ BOOST_AUTO_TEST_CASE(scanner_hex_values)
|
||||
)";
|
||||
auto const calls = parse(source);
|
||||
BOOST_REQUIRE_EQUAL(calls.size(), 1);
|
||||
testFunctionCall(calls.at(0), Mode::SingleLine, "f(uint256)", false, fmt::encodeArgs(string("\x20\x00\xff", 3)));
|
||||
testFunctionCall(calls.at(0), Mode::SingleLine, "f(uint256)", false, fmt::encodeArgs(std::string("\x20\x00\xff", 3)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scanner_hex_values_invalid1)
|
||||
@ -382,7 +381,7 @@ BOOST_AUTO_TEST_CASE(scanner_hex_values_invalid2)
|
||||
)";
|
||||
auto const calls = parse(source);
|
||||
BOOST_REQUIRE_EQUAL(calls.size(), 1);
|
||||
testFunctionCall(calls.at(0), Mode::SingleLine, "f(uint256)", false, fmt::encodeArgs(string("\x1", 1)));
|
||||
testFunctionCall(calls.at(0), Mode::SingleLine, "f(uint256)", false, fmt::encodeArgs(std::string("\x1", 1)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scanner_hex_values_invalid3)
|
||||
@ -447,7 +446,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_string)
|
||||
Mode::SingleLine,
|
||||
"f(string)",
|
||||
false,
|
||||
fmt::encodeDyn(string{"any"})
|
||||
fmt::encodeDyn(std::string{"any"})
|
||||
);
|
||||
}
|
||||
|
||||
@ -485,7 +484,7 @@ BOOST_AUTO_TEST_CASE(call_return_string)
|
||||
"f()",
|
||||
false,
|
||||
fmt::encodeArgs(),
|
||||
fmt::encodeDyn(string{"any"})
|
||||
fmt::encodeDyn(std::string{"any"})
|
||||
);
|
||||
}
|
||||
|
||||
@ -976,7 +975,7 @@ BOOST_AUTO_TEST_CASE(call_effects)
|
||||
// ~ bla bla
|
||||
// ~ bla bla bla
|
||||
)";
|
||||
vector<FunctionCall> calls = parse(source, builtins);
|
||||
std::vector<FunctionCall> calls = parse(source, builtins);
|
||||
BOOST_REQUIRE_EQUAL(calls.size(), 1);
|
||||
BOOST_REQUIRE_EQUAL(calls[0].expectedSideEffects.size(), 3);
|
||||
BOOST_REQUIRE_EQUAL(boost::trim_copy(calls[0].expectedSideEffects[0]), "bla");
|
||||
|
@ -28,33 +28,32 @@
|
||||
using namespace solidity;
|
||||
using namespace solidity::util;
|
||||
using namespace solidity::frontend::test;
|
||||
using namespace std;
|
||||
|
||||
using Token = soltest::Token;
|
||||
|
||||
string TestFunctionCall::format(
|
||||
std::string TestFunctionCall::format(
|
||||
ErrorReporter& _errorReporter,
|
||||
string const& _linePrefix,
|
||||
std::string const& _linePrefix,
|
||||
RenderMode _renderMode,
|
||||
bool const _highlight,
|
||||
bool const _interactivePrint
|
||||
) const
|
||||
{
|
||||
stringstream stream;
|
||||
std::stringstream stream;
|
||||
|
||||
bool highlight = !matchesExpectation() && _highlight;
|
||||
|
||||
auto formatOutput = [&](bool const _singleLine)
|
||||
{
|
||||
string ws = " ";
|
||||
string arrow = formatToken(Token::Arrow);
|
||||
string colon = formatToken(Token::Colon);
|
||||
string comma = formatToken(Token::Comma);
|
||||
string comment = formatToken(Token::Comment);
|
||||
string ether = formatToken(Token::Ether);
|
||||
string wei = formatToken(Token::Wei);
|
||||
string newline = formatToken(Token::Newline);
|
||||
string failure = formatToken(Token::Failure);
|
||||
std::string ws = " ";
|
||||
std::string arrow = formatToken(Token::Arrow);
|
||||
std::string colon = formatToken(Token::Colon);
|
||||
std::string comma = formatToken(Token::Comma);
|
||||
std::string comment = formatToken(Token::Comment);
|
||||
std::string ether = formatToken(Token::Ether);
|
||||
std::string wei = formatToken(Token::Wei);
|
||||
std::string newline = formatToken(Token::Newline);
|
||||
std::string failure = formatToken(Token::Failure);
|
||||
|
||||
if (m_call.kind == FunctionCall::Kind::Library)
|
||||
{
|
||||
@ -83,7 +82,7 @@ string TestFunctionCall::format(
|
||||
}
|
||||
if (!m_call.arguments.rawBytes().empty())
|
||||
{
|
||||
string output = formatRawParameters(m_call.arguments.parameters, _linePrefix);
|
||||
std::string output = formatRawParameters(m_call.arguments.parameters, _linePrefix);
|
||||
stream << colon;
|
||||
if (!m_call.arguments.parameters.at(0).format.newline)
|
||||
stream << ws;
|
||||
@ -107,17 +106,17 @@ string TestFunctionCall::format(
|
||||
}
|
||||
else
|
||||
{
|
||||
stream << endl << _linePrefix << newline << ws;
|
||||
stream << std::endl << _linePrefix << newline << ws;
|
||||
if (!m_call.arguments.comment.empty())
|
||||
{
|
||||
stream << comment << m_call.arguments.comment << comment;
|
||||
stream << endl << _linePrefix << newline << ws;
|
||||
stream << std::endl << _linePrefix << newline << ws;
|
||||
}
|
||||
stream << arrow;
|
||||
}
|
||||
|
||||
/// Format either the expected output or the actual result output
|
||||
string result;
|
||||
std::string result;
|
||||
if (_renderMode != RenderMode::ActualValuesExpectedGas)
|
||||
{
|
||||
bool const isFailure = m_call.expectations.failure;
|
||||
@ -162,7 +161,7 @@ string TestFunctionCall::format(
|
||||
m_call.signature
|
||||
);
|
||||
|
||||
string bytesOutput = abiParams ?
|
||||
std::string bytesOutput = abiParams ?
|
||||
BytesUtils::formatRawBytes(output, abiParams.value(), _linePrefix) :
|
||||
BytesUtils::formatRawBytes(
|
||||
output,
|
||||
@ -194,12 +193,12 @@ string TestFunctionCall::format(
|
||||
{
|
||||
if (!m_call.expectations.comment.empty())
|
||||
{
|
||||
stream << endl << _linePrefix << newline << ws;
|
||||
stream << std::endl << _linePrefix << newline << ws;
|
||||
stream << comment << m_call.expectations.comment << comment;
|
||||
}
|
||||
}
|
||||
|
||||
vector<string> sideEffects;
|
||||
std::vector<std::string> sideEffects;
|
||||
if (_renderMode == RenderMode::ExpectedValuesExpectedGas || _renderMode == RenderMode::ExpectedValuesActualGas)
|
||||
sideEffects = m_call.expectedSideEffects;
|
||||
else
|
||||
@ -221,10 +220,10 @@ string TestFunctionCall::format(
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
string TestFunctionCall::formatBytesParameters(
|
||||
std::string TestFunctionCall::formatBytesParameters(
|
||||
ErrorReporter& _errorReporter,
|
||||
bytes const& _bytes,
|
||||
string const& _signature,
|
||||
std::string const& _signature,
|
||||
solidity::frontend::test::ParameterList const& _parameters,
|
||||
bool _highlight,
|
||||
bool _failure
|
||||
@ -232,7 +231,7 @@ string TestFunctionCall::formatBytesParameters(
|
||||
{
|
||||
using ParameterList = solidity::frontend::test::ParameterList;
|
||||
|
||||
stringstream os;
|
||||
std::stringstream os;
|
||||
|
||||
if (_bytes.empty())
|
||||
return {};
|
||||
@ -281,7 +280,7 @@ string TestFunctionCall::formatBytesParameters(
|
||||
}
|
||||
}
|
||||
|
||||
string TestFunctionCall::formatFailure(
|
||||
std::string TestFunctionCall::formatFailure(
|
||||
ErrorReporter& _errorReporter,
|
||||
solidity::frontend::test::FunctionCall const& _call,
|
||||
bytes const& _output,
|
||||
@ -289,7 +288,7 @@ string TestFunctionCall::formatFailure(
|
||||
bool _highlight
|
||||
) const
|
||||
{
|
||||
stringstream os;
|
||||
std::stringstream os;
|
||||
|
||||
os << formatToken(Token::Failure);
|
||||
|
||||
@ -311,34 +310,34 @@ string TestFunctionCall::formatFailure(
|
||||
return os.str();
|
||||
}
|
||||
|
||||
string TestFunctionCall::formatRawParameters(
|
||||
std::string TestFunctionCall::formatRawParameters(
|
||||
solidity::frontend::test::ParameterList const& _params,
|
||||
std::string const& _linePrefix
|
||||
) const
|
||||
{
|
||||
stringstream os;
|
||||
std::stringstream os;
|
||||
for (auto const& param: _params)
|
||||
if (!param.rawString.empty())
|
||||
{
|
||||
if (param.format.newline)
|
||||
os << endl << _linePrefix << "// ";
|
||||
os << std::endl << _linePrefix << "// ";
|
||||
for (auto const c: param.rawString)
|
||||
// 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" + util::toHex(static_cast<uint8_t>(c), HexCase::Lower));
|
||||
os << (c >= ' ' ? std::string(1, c) : "\\x" + util::toHex(static_cast<uint8_t>(c), HexCase::Lower));
|
||||
if (¶m != &_params.back())
|
||||
os << ", ";
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
string TestFunctionCall::formatGasExpectations(
|
||||
string const& _linePrefix,
|
||||
std::string TestFunctionCall::formatGasExpectations(
|
||||
std::string const& _linePrefix,
|
||||
bool _useActualCost,
|
||||
bool _showDifference
|
||||
) const
|
||||
{
|
||||
stringstream os;
|
||||
std::stringstream os;
|
||||
for (auto const& [runType, gasUsed]: (_useActualCost ? m_gasCosts : m_call.expectations.gasUsed))
|
||||
if (!runType.empty())
|
||||
{
|
||||
@ -357,9 +356,9 @@ string TestFunctionCall::formatGasExpectations(
|
||||
percent = static_cast<int>(
|
||||
100.0 * (static_cast<double>(difference) / static_cast<double>(m_call.expectations.gasUsed.at(runType)))
|
||||
);
|
||||
os << endl << _linePrefix << "// gas " << runType << ": " << (gasUsed.str());
|
||||
os << std::endl << _linePrefix << "// gas " << runType << ": " << (gasUsed.str());
|
||||
if (_showDifference && differentResults && _useActualCost)
|
||||
os << " [" << showpos << difference << " (" << percent << "%)]";
|
||||
os << " [" << std::showpos << difference << " (" << percent << "%)]";
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
#include <test/libsolidity/util/TestFunctionCall.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity::util;
|
||||
using namespace solidity::test;
|
||||
|
||||
@ -39,8 +38,8 @@ BOOST_AUTO_TEST_CASE(format_unsigned_singleline)
|
||||
bytes expectedBytes = toBigEndian(u256{1});
|
||||
ABIType abiType{ABIType::UnsignedDec, ABIType::AlignRight, 32};
|
||||
Parameter param{expectedBytes, "1", abiType, FormatInfo{}};
|
||||
FunctionCallExpectations expectations{vector<Parameter>{param}, false, string{}, {}};
|
||||
FunctionCallArgs arguments{vector<Parameter>{param}, string{}};
|
||||
FunctionCallExpectations expectations{std::vector<Parameter>{param}, false, std::string{}, {}};
|
||||
FunctionCallArgs arguments{std::vector<Parameter>{param}, std::string{}};
|
||||
FunctionCall call{"f(uint8)", {0}, arguments, expectations};
|
||||
call.omitsArrow = false;
|
||||
|
||||
@ -59,8 +58,8 @@ BOOST_AUTO_TEST_CASE(format_unsigned_singleline_signed_encoding)
|
||||
bytes expectedBytes = toBigEndian(u256{1});
|
||||
ABIType abiType{ABIType::UnsignedDec, ABIType::AlignRight, 32};
|
||||
Parameter param{expectedBytes, "1", abiType, FormatInfo{}};
|
||||
FunctionCallExpectations expectations{vector<Parameter>{param}, false, string{}, {}};
|
||||
FunctionCallArgs arguments{vector<Parameter>{param}, string{}};
|
||||
FunctionCallExpectations expectations{std::vector<Parameter>{param}, false, std::string{}, {}};
|
||||
FunctionCallArgs arguments{std::vector<Parameter>{param}, std::string{}};
|
||||
FunctionCall call{"f(uint8)", {0}, arguments, expectations};
|
||||
call.omitsArrow = false;
|
||||
|
||||
@ -79,8 +78,8 @@ BOOST_AUTO_TEST_CASE(format_unsigned_multiline)
|
||||
bytes expectedBytes = toBigEndian(u256{1});
|
||||
ABIType abiType{ABIType::UnsignedDec, ABIType::AlignRight, 32};
|
||||
Parameter result{expectedBytes, "1", abiType, FormatInfo{}};
|
||||
FunctionCallExpectations expectations{vector<Parameter>{result}, false, string{}, {}};
|
||||
FunctionCallArgs arguments{vector<Parameter>{}, string{}};
|
||||
FunctionCallExpectations expectations{std::vector<Parameter>{result}, false, std::string{}, {}};
|
||||
FunctionCallArgs arguments{std::vector<Parameter>{}, std::string{}};
|
||||
FunctionCall call{"f(uint8)", {0}, arguments, expectations};
|
||||
call.omitsArrow = false;
|
||||
call.displayMode = FunctionCall::DisplayMode::MultiLine;
|
||||
@ -94,8 +93,8 @@ BOOST_AUTO_TEST_CASE(format_multiple_unsigned_singleline)
|
||||
bytes expectedBytes = toBigEndian(u256{1});
|
||||
ABIType abiType{ABIType::UnsignedDec, ABIType::AlignRight, 32};
|
||||
Parameter param{expectedBytes, "1", abiType, FormatInfo{}};
|
||||
FunctionCallExpectations expectations{vector<Parameter>{param, param}, false, string{}, {}};
|
||||
FunctionCallArgs arguments{vector<Parameter>{param, param}, string{}};
|
||||
FunctionCallExpectations expectations{std::vector<Parameter>{param, param}, false, std::string{}, {}};
|
||||
FunctionCallArgs arguments{std::vector<Parameter>{param, param}, std::string{}};
|
||||
FunctionCall call{"f(uint8, uint8)", {0}, arguments, expectations};
|
||||
call.omitsArrow = false;
|
||||
TestFunctionCall test{call};
|
||||
@ -108,8 +107,8 @@ BOOST_AUTO_TEST_CASE(format_signed_singleline)
|
||||
bytes expectedBytes = toBigEndian(u256{-1});
|
||||
ABIType abiType{ABIType::UnsignedDec, ABIType::AlignRight, 32};
|
||||
Parameter param{expectedBytes, "-1", abiType, FormatInfo{}};
|
||||
FunctionCallExpectations expectations{vector<Parameter>{param}, false, string{}, {}};
|
||||
FunctionCallArgs arguments{vector<Parameter>{param}, string{}};
|
||||
FunctionCallExpectations expectations{std::vector<Parameter>{param}, false, std::string{}, {}};
|
||||
FunctionCallArgs arguments{std::vector<Parameter>{param}, std::string{}};
|
||||
FunctionCall call{"f(int8)", {0}, arguments, expectations};
|
||||
call.omitsArrow = false;
|
||||
TestFunctionCall test{call};
|
||||
@ -128,8 +127,8 @@ BOOST_AUTO_TEST_CASE(format_hex_singleline)
|
||||
bytes expectedBytes = result + bytes(32 - result.size(), 0);
|
||||
ABIType abiType{ABIType::Hex, ABIType::AlignRight, 32};
|
||||
Parameter param{expectedBytes, "0x31", abiType, FormatInfo{}};
|
||||
FunctionCallExpectations expectations{vector<Parameter>{param}, false, string{}, {}};
|
||||
FunctionCallArgs arguments{vector<Parameter>{param}, string{}};
|
||||
FunctionCallExpectations expectations{std::vector<Parameter>{param}, false, std::string{}, {}};
|
||||
FunctionCallArgs arguments{std::vector<Parameter>{param}, std::string{}};
|
||||
FunctionCall call{"f(bytes32)", {0}, arguments, expectations};
|
||||
call.omitsArrow = false;
|
||||
TestFunctionCall test{call};
|
||||
@ -150,8 +149,8 @@ BOOST_AUTO_TEST_CASE(format_hex_string_singleline)
|
||||
bytes expectedBytes = fromHex("4200ef");
|
||||
ABIType abiType{ABIType::HexString, ABIType::AlignLeft, 3};
|
||||
Parameter param{expectedBytes, "hex\"4200ef\"", abiType, FormatInfo{}};
|
||||
FunctionCallExpectations expectations{vector<Parameter>{param}, false, string{}, {}};
|
||||
FunctionCallArgs arguments{vector<Parameter>{param}, string{}};
|
||||
FunctionCallExpectations expectations{std::vector<Parameter>{param}, false, std::string{}, {}};
|
||||
FunctionCallArgs arguments{std::vector<Parameter>{param}, std::string{}};
|
||||
FunctionCall call{"f(string)", {0}, arguments, expectations};
|
||||
call.omitsArrow = false;
|
||||
TestFunctionCall test{call};
|
||||
@ -164,8 +163,8 @@ BOOST_AUTO_TEST_CASE(format_bool_true_singleline)
|
||||
bytes expectedBytes = toBigEndian(u256{true});
|
||||
ABIType abiType{ABIType::Boolean, ABIType::AlignRight, 32};
|
||||
Parameter param{expectedBytes, "true", abiType, FormatInfo{}};
|
||||
FunctionCallExpectations expectations{vector<Parameter>{param}, false, string{}, {}};
|
||||
FunctionCallArgs arguments{vector<Parameter>{param}, string{}};
|
||||
FunctionCallExpectations expectations{std::vector<Parameter>{param}, false, std::string{}, {}};
|
||||
FunctionCallArgs arguments{std::vector<Parameter>{param}, std::string{}};
|
||||
FunctionCall call{"f(bool)", {0}, arguments, expectations};
|
||||
call.omitsArrow = false;
|
||||
TestFunctionCall test{call};
|
||||
@ -185,8 +184,8 @@ BOOST_AUTO_TEST_CASE(format_bool_false_singleline)
|
||||
bytes expectedBytes = toBigEndian(u256{false});
|
||||
ABIType abiType{ABIType::Boolean, ABIType::AlignRight, 32};
|
||||
Parameter param{expectedBytes, "false", abiType, FormatInfo{}};
|
||||
FunctionCallExpectations expectations{vector<Parameter>{param}, false, string{}, {}};
|
||||
FunctionCallArgs arguments{vector<Parameter>{param}, string{}};
|
||||
FunctionCallExpectations expectations{std::vector<Parameter>{param}, false, std::string{}, {}};
|
||||
FunctionCallArgs arguments{std::vector<Parameter>{param}, std::string{}};
|
||||
FunctionCall call{"f(bool)", {0}, arguments, expectations};
|
||||
call.omitsArrow = false;
|
||||
TestFunctionCall test{call};
|
||||
@ -199,8 +198,8 @@ BOOST_AUTO_TEST_CASE(format_bool_left_singleline)
|
||||
bytes expectedBytes = toBigEndian(u256{false});
|
||||
ABIType abiType{ABIType::Boolean, ABIType::AlignLeft, 32};
|
||||
Parameter param{expectedBytes, "left(false)", abiType, FormatInfo{}};
|
||||
FunctionCallExpectations expectations{vector<Parameter>{param}, false, string{}, {}};
|
||||
FunctionCallArgs arguments{vector<Parameter>{param}, string{}};
|
||||
FunctionCallExpectations expectations{std::vector<Parameter>{param}, false, std::string{}, {}};
|
||||
FunctionCallArgs arguments{std::vector<Parameter>{param}, std::string{}};
|
||||
FunctionCall call{"f(bool)", {0}, arguments, expectations};
|
||||
call.omitsArrow = false;
|
||||
TestFunctionCall test{call};
|
||||
@ -214,8 +213,8 @@ BOOST_AUTO_TEST_CASE(format_hex_number_right_singleline)
|
||||
bytes expectedBytes = result + bytes(32 - result.size(), 0);
|
||||
ABIType abiType{ABIType::Hex, ABIType::AlignRight, 32};
|
||||
Parameter param{expectedBytes, "right(0x42)", abiType, FormatInfo{}};
|
||||
FunctionCallExpectations expectations{vector<Parameter>{param}, false, string{}, {}};
|
||||
FunctionCallArgs arguments{vector<Parameter>{param}, string{}};
|
||||
FunctionCallExpectations expectations{std::vector<Parameter>{param}, false, std::string{}, {}};
|
||||
FunctionCallArgs arguments{std::vector<Parameter>{param}, std::string{}};
|
||||
FunctionCall call{"f(bool)", {0}, arguments, expectations};
|
||||
call.omitsArrow = false;
|
||||
TestFunctionCall test{call};
|
||||
@ -228,8 +227,8 @@ BOOST_AUTO_TEST_CASE(format_empty_byte_range)
|
||||
bytes expectedBytes;
|
||||
ABIType abiType{ABIType::None, ABIType::AlignNone, 0};
|
||||
Parameter param{expectedBytes, "1", abiType, FormatInfo{}};
|
||||
FunctionCallExpectations expectations{vector<Parameter>{param}, false, string{}, {}};
|
||||
FunctionCallArgs arguments{vector<Parameter>{}, string{}};
|
||||
FunctionCallExpectations expectations{std::vector<Parameter>{param}, false, std::string{}, {}};
|
||||
FunctionCallArgs arguments{std::vector<Parameter>{}, std::string{}};
|
||||
FunctionCall call{"f()", {0}, arguments, expectations};
|
||||
call.omitsArrow = false;
|
||||
TestFunctionCall test{call};
|
||||
@ -242,8 +241,8 @@ BOOST_AUTO_TEST_CASE(format_failure_singleline)
|
||||
bytes expectedBytes = toBigEndian(u256{1});
|
||||
ABIType abiType{ABIType::UnsignedDec, ABIType::AlignRight, 32};
|
||||
Parameter param{expectedBytes, "1", abiType, FormatInfo{}};
|
||||
FunctionCallExpectations expectations{vector<Parameter>{}, true, string{}, {}};
|
||||
FunctionCallArgs arguments{vector<Parameter>{param}, string{}};
|
||||
FunctionCallExpectations expectations{std::vector<Parameter>{}, true, std::string{}, {}};
|
||||
FunctionCallArgs arguments{std::vector<Parameter>{param}, std::string{}};
|
||||
FunctionCall call{"f(uint8)", {0}, arguments, expectations};
|
||||
call.omitsArrow = false;
|
||||
TestFunctionCall test{call};
|
||||
|
Loading…
Reference in New Issue
Block a user