Merge pull request #9106 from ethereum/develop

Merge develop into breaking.
This commit is contained in:
chriseth
2020-06-03 13:51:28 +02:00
committed by GitHub
100 changed files with 1027 additions and 563 deletions
+1 -20
View File
@@ -64,25 +64,6 @@ TestCase::TestResult ABIJsonTest::run(ostream& _stream, string const& _linePrefi
m_obtainedResult += jsonPrettyPrint(compiler.contractABI(contractName)) + "\n";
first = false;
}
if (m_expectation != m_obtainedResult)
{
string nextIndentLevel = _linePrefix + " ";
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::CYAN}) << _linePrefix << "Expected result:" << endl;
printIndented(_stream, m_expectation, nextIndentLevel);
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::CYAN}) << _linePrefix << "Obtained result:" << endl;
printIndented(_stream, m_obtainedResult, nextIndentLevel);
return TestResult::Failure;
}
return TestResult::Success;
}
void ABIJsonTest::printSource(ostream& _stream, string const& _linePrefix, bool const) const
{
printIndented(_stream, m_source, _linePrefix);
}
void ABIJsonTest::printUpdatedExpectations(ostream& _stream, string const& _linePrefix) const
{
printIndented(_stream, m_obtainedResult, _linePrefix);
return checkResult(_stream, _linePrefix, _formatted);
}
-8
View File
@@ -36,14 +36,6 @@ public:
ABIJsonTest(std::string const& _filename);
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override;
void printSource(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) const override;
void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix) const override;
private:
std::string m_source;
std::string m_expectation;
std::string m_obtainedResult;
};
}
-1
View File
@@ -41,7 +41,6 @@ public:
void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix) const override;
private:
std::vector<std::pair<std::string, std::string>> m_sources;
std::string m_expectation;
std::string m_expectationLegacy;
std::string m_astFilename;
std::string m_legacyAstFilename;
+4 -24
View File
@@ -107,13 +107,13 @@ void printAssemblyLocations(AssemblyItems const& _items)
cout <<
"\t\tvector<SourceLocation>(" <<
_repetitions <<
", SourceLocation(" <<
", SourceLocation{" <<
_loc.start <<
", " <<
_loc.end <<
", make_shared<string>(\"" <<
_loc.source->name() <<
"\"))) +" << endl;
"\")}) +" << endl;
};
vector<SourceLocation> locations;
@@ -175,33 +175,13 @@ BOOST_AUTO_TEST_CASE(location_test)
vector<SourceLocation> locations;
if (solidity::test::CommonOptions::get().optimize)
locations =
vector<SourceLocation>(4, SourceLocation{2, 82, sourceCode}) +
vector<SourceLocation>(1, SourceLocation{5, 14, codegenCharStream}) +
vector<SourceLocation>(3, SourceLocation{2, 4, codegenCharStream}) +
vector<SourceLocation>(1, SourceLocation{27, 28, codegenCharStream}) +
vector<SourceLocation>(1, SourceLocation{24, 25, codegenCharStream}) +
vector<SourceLocation>(1, SourceLocation{17, 29, codegenCharStream}) +
vector<SourceLocation>(1, SourceLocation{2, 4, codegenCharStream}) +
vector<SourceLocation>(16, SourceLocation{2, 82, sourceCode}) +
vector<SourceLocation>(1, SourceLocation{12, 13, codegenCharStream}) +
vector<SourceLocation>(1, SourceLocation{9, 10, codegenCharStream}) +
vector<SourceLocation>(1, SourceLocation{2, 14, codegenCharStream}) +
vector<SourceLocation>(31, SourceLocation{2, 82, sourceCode}) +
vector<SourceLocation>(21, SourceLocation{20, 79, sourceCode}) +
vector<SourceLocation>(1, SourceLocation{72, 74, sourceCode}) +
vector<SourceLocation>(2, SourceLocation{20, 79, sourceCode});
else
locations =
vector<SourceLocation>(4, SourceLocation{2, 82, sourceCode}) +
vector<SourceLocation>(1, SourceLocation{5, 14, codegenCharStream}) +
vector<SourceLocation>(3, SourceLocation{2, 4, codegenCharStream}) +
vector<SourceLocation>(1, SourceLocation{27, 28, codegenCharStream}) +
vector<SourceLocation>(1, SourceLocation{24, 25, codegenCharStream}) +
vector<SourceLocation>(1, SourceLocation{17, 29, codegenCharStream}) +
vector<SourceLocation>(1, SourceLocation{2, 4, codegenCharStream}) +
vector<SourceLocation>(hasShifts ? 16 : 17, SourceLocation{2, 82, sourceCode}) +
vector<SourceLocation>(1, SourceLocation{12, 13, codegenCharStream}) +
vector<SourceLocation>(1, SourceLocation{9, 10, codegenCharStream}) +
vector<SourceLocation>(1, SourceLocation{2, 14, codegenCharStream}) +
vector<SourceLocation>(hasShifts ? 31 : 32, SourceLocation{2, 82, sourceCode}) +
vector<SourceLocation>(24, SourceLocation{20, 79, sourceCode}) +
vector<SourceLocation>(1, SourceLocation{49, 58, sourceCode}) +
vector<SourceLocation>(1, SourceLocation{72, 74, sourceCode}) +
-1
View File
@@ -47,7 +47,6 @@ private:
bool m_optimise = false;
bool m_optimiseYul = false;
size_t m_optimiseRuns = 200;
std::string m_source;
std::map<std::string, std::map<std::string, std::string>> m_expectations;
};
+2
View File
@@ -62,6 +62,8 @@ SemanticTest::SemanticTest(string const& _filename, langutil::EVMVersion _evmVer
{
m_runWithYul = false;
m_runWithoutYul = true;
// Do not try to run via yul if explicitly denied.
m_enforceViaYul = false;
}
else
BOOST_THROW_EXCEPTION(runtime_error("Invalid compileViaYul value: " + choice + "."));
@@ -66,20 +66,15 @@ bytes SolidityExecutionFramework::compileContract(
if (m_compileViaYul)
{
yul::AssemblyStack asmStack(
m_evmVersion,
yul::AssemblyStack::Language::StrictAssembly,
// Ignore optimiser settings here because we need Yul optimisation to
// get code that does not exhaust the stack.
OptimiserSettings::full()
);
if (!asmStack.parseAndAnalyze("", m_compiler.yulIROptimized(contractName)))
{
langutil::SourceReferenceFormatter formatter(std::cerr);
m_evmVersion,
yul::AssemblyStack::Language::StrictAssembly,
// Ignore optimiser settings here because we need Yul optimisation to
// get code that does not exhaust the stack.
OptimiserSettings::full()
);
bool analysisSuccessful = asmStack.parseAndAnalyze("", m_compiler.yulIROptimized(contractName));
solAssert(analysisSuccessful, "Code that passed analysis in CompilerStack can't have errors");
for (auto const& error: m_compiler.errors())
formatter.printErrorInformation(*error);
BOOST_ERROR("Assembly contract failed. IR: " + m_compiler.yulIROptimized({}));
}
asmStack.optimize();
obj = std::move(*asmStack.assemble(yul::AssemblyStack::Machine::EVM).bytecode);
}
+17 -17
View File
@@ -370,15 +370,15 @@ BOOST_AUTO_TEST_CASE(basic_compilation)
BOOST_CHECK(contract["evm"]["assembly"].isString());
BOOST_CHECK(contract["evm"]["assembly"].asString().find(
" /* \"fileA\":0:14 contract A { } */\n mstore(0x40, 0x80)\n "
"callvalue\n /* \"--CODEGEN--\":5:14 */\n dup1\n "
"/* \"--CODEGEN--\":2:4 */\n iszero\n tag_1\n jumpi\n "
"/* \"--CODEGEN--\":27:28 */\n 0x00\n /* \"--CODEGEN--\":24:25 */\n "
"dup1\n /* \"--CODEGEN--\":17:29 */\n revert\n /* \"--CODEGEN--\":2:4 */\n"
"tag_1:\n /* \"fileA\":0:14 contract A { } */\n pop\n dataSize(sub_0)\n dup1\n "
"callvalue\n dup1\n "
"iszero\n tag_1\n jumpi\n "
"0x00\n "
"dup1\n revert\n"
"tag_1:\n pop\n dataSize(sub_0)\n dup1\n "
"dataOffset(sub_0)\n 0x00\n codecopy\n 0x00\n return\nstop\n\nsub_0: assembly {\n "
"/* \"fileA\":0:14 contract A { } */\n mstore(0x40, 0x80)\n "
"/* \"--CODEGEN--\":12:13 */\n 0x00\n /* \"--CODEGEN--\":9:10 */\n "
"dup1\n /* \"--CODEGEN--\":2:14 */\n revert\n\n auxdata: 0xa26469706673582212"
"/* \"fileA\":0:14 contract A { } */\n mstore(0x40, 0x80)\n "
"0x00\n "
"dup1\n revert\n\n auxdata: 0xa26469706673582212"
) == 0);
BOOST_CHECK(contract["evm"]["gasEstimates"].isObject());
BOOST_CHECK_EQUAL(contract["evm"]["gasEstimates"].size(), 1);
@@ -402,15 +402,15 @@ BOOST_AUTO_TEST_CASE(basic_compilation)
"{\"begin\":0,\"end\":14,\"name\":\"PUSH\",\"source\":0,\"value\":\"40\"},"
"{\"begin\":0,\"end\":14,\"name\":\"MSTORE\",\"source\":0},"
"{\"begin\":0,\"end\":14,\"name\":\"CALLVALUE\",\"source\":0},"
"{\"begin\":5,\"end\":14,\"name\":\"DUP1\",\"source\":-1},"
"{\"begin\":2,\"end\":4,\"name\":\"ISZERO\",\"source\":-1},"
"{\"begin\":2,\"end\":4,\"name\":\"PUSH [tag]\",\"source\":-1,\"value\":\"1\"},"
"{\"begin\":2,\"end\":4,\"name\":\"JUMPI\",\"source\":-1},"
"{\"begin\":27,\"end\":28,\"name\":\"PUSH\",\"source\":-1,\"value\":\"0\"},"
"{\"begin\":24,\"end\":25,\"name\":\"DUP1\",\"source\":-1},"
"{\"begin\":17,\"end\":29,\"name\":\"REVERT\",\"source\":-1},"
"{\"begin\":2,\"end\":4,\"name\":\"tag\",\"source\":-1,\"value\":\"1\"},"
"{\"begin\":2,\"end\":4,\"name\":\"JUMPDEST\",\"source\":-1},"
"{\"begin\":0,\"end\":14,\"name\":\"DUP1\",\"source\":0},"
"{\"begin\":0,\"end\":14,\"name\":\"ISZERO\",\"source\":0},"
"{\"begin\":0,\"end\":14,\"name\":\"PUSH [tag]\",\"source\":0,\"value\":\"1\"},"
"{\"begin\":0,\"end\":14,\"name\":\"JUMPI\",\"source\":0},"
"{\"begin\":0,\"end\":14,\"name\":\"PUSH\",\"source\":0,\"value\":\"0\"},"
"{\"begin\":0,\"end\":14,\"name\":\"DUP1\",\"source\":0},"
"{\"begin\":0,\"end\":14,\"name\":\"REVERT\",\"source\":0},"
"{\"begin\":0,\"end\":14,\"name\":\"tag\",\"source\":0,\"value\":\"1\"},"
"{\"begin\":0,\"end\":14,\"name\":\"JUMPDEST\",\"source\":0},"
"{\"begin\":0,\"end\":14,\"name\":\"POP\",\"source\":0},"
"{\"begin\":0,\"end\":14,\"name\":\"PUSH #[$]\",\"source\":0,\"value\":\"0000000000000000000000000000000000000000000000000000000000000000\"},"
"{\"begin\":0,\"end\":14,\"name\":\"DUP1\",\"source\":0},"
@@ -0,0 +1,27 @@
pragma experimental SMTChecker;
contract C {
struct S {
int[] b;
}
S s;
struct T {
S s;
}
T t;
function f() public {
s.b.push();
t.s.b.push();
}
}
// ----
// Warning: (72-75): Assertion checker does not yet support the type of this variable.
// Warning: (100-103): Assertion checker does not yet support the type of this variable.
// Warning: (130-133): Assertion checker does not yet support this expression.
// Warning: (130-131): Assertion checker does not yet implement type struct C.S storage ref
// Warning: (130-133): Assertion checker does not yet implement this expression.
// Warning: (144-149): Assertion checker does not yet support this expression.
// Warning: (144-147): Assertion checker does not yet implement type struct C.S storage ref
// Warning: (144-147): Assertion checker does not yet support this expression.
// Warning: (144-145): Assertion checker does not yet implement type struct C.T storage ref
// Warning: (144-149): Assertion checker does not yet implement this expression.
@@ -0,0 +1,33 @@
pragma experimental SMTChecker;
contract C {
struct S {
int[] b;
}
S s;
struct T {
S[] s;
}
T t;
function f() public {
s.b.push();
t.s.push();
t.s[0].b.push();
}
}
// ----
// Warning: (72-75): Assertion checker does not yet support the type of this variable.
// Warning: (102-105): Assertion checker does not yet support the type of this variable.
// Warning: (132-135): Assertion checker does not yet support this expression.
// Warning: (132-133): Assertion checker does not yet implement type struct C.S storage ref
// Warning: (132-135): Assertion checker does not yet implement this expression.
// Warning: (146-149): Assertion checker does not yet support this expression.
// Warning: (146-147): Assertion checker does not yet implement type struct C.T storage ref
// Warning: (146-156): Assertion checker does not yet implement type struct C.S storage ref
// Warning: (146-149): Assertion checker does not yet implement this expression.
// Warning: (160-168): Assertion checker does not yet support this expression.
// Warning: (160-163): Assertion checker does not yet support this expression.
// Warning: (160-161): Assertion checker does not yet implement type struct C.T storage ref
// Warning: (160-166): Assertion checker does not yet implement type struct C.S storage ref
// Warning: (160-166): Assertion checker does not yet implement this expression.
// Warning: (160-168): Assertion checker does not yet implement this expression.
@@ -0,0 +1,12 @@
pragma experimental SMTChecker;
contract C {
function g() public returns (uint) {
try this.g() returns (uint x) { x; }
catch Error(string memory s) { s; }
}
}
// ====
// EVMVersion: >=byzantium
// ----
// Warning: (98-121): Assertion checker does not support try/catch clauses.
// Warning: (124-159): Assertion checker does not support try/catch clauses.
@@ -0,0 +1,14 @@
pragma experimental SMTChecker;
contract C {
function f() public {
try this.f() {}
catch (bytes memory x) {
x;
}
}
}
// ====
// EVMVersion: >=byzantium
// ----
// Warning: (83-85): Assertion checker does not support try/catch clauses.
// Warning: (88-122): Assertion checker does not support try/catch clauses.
@@ -0,0 +1,5 @@
pragma experimental SMTChecker;
contract c {
bool b = (f() == 0) && (f() == 0);
function f() internal returns (uint) {}
}
@@ -0,0 +1,12 @@
pragma experimental SMTChecker;
contract c {
uint x;
function f() internal returns (uint) {
x = x + 1;
}
bool b = (f() > 0) || (f() > 0);
}
// ----
// Warning: (100-105): Overflow (resulting value larger than 2**256 - 1) happens here
// Warning: (100-105): Underflow (resulting value less than 0) happens here
// Warning: (100-105): Overflow (resulting value larger than 2**256 - 1) happens here
@@ -0,0 +1,18 @@
pragma experimental SMTChecker;
contract C {
function f() public pure {
int8 x = 1;
int8 y = 0;
assert(x & y != 0);
x = -1; y = 3;
assert(x & y == 3);
y = -1;
int8 z = x & y;
assert(z == -1);
y = 127;
assert(x & y == 127);
}
}
// ----
// Warning: (104-122): Assertion violation happens here
@@ -0,0 +1,12 @@
pragma experimental SMTChecker;
contract C {
function f() public pure {
assert(1 & 0 != 0);
assert(-1 & 3 == 3);
assert(-1 & -1 == -1);
assert(-1 & 127 == 127);
}
}
// ----
// Warning: (76-94): Assertion violation happens here
@@ -0,0 +1,18 @@
pragma experimental SMTChecker;
contract C {
function f() public pure {
uint8 x = 1;
uint16 y = 0;
assert(x & y != 0);
x = 0xff;
y = 0xffff;
assert(x & y == 0xff);
assert(x & y == 0xffff);
assert(x & y == 0x0000);
}
}
// ----
// Warning: (107-125): Assertion violation happens here
// Warning: (180-203): Assertion violation happens here
// Warning: (207-230): Assertion violation happens here
@@ -0,0 +1,42 @@
pragma experimental SMTChecker;
contract C {
uint[] a;
uint[][] b;
function f(uint x, uint y, uint v) public {
a[x] = v;
delete a;
assert(a[y] == 0);
}
function g(uint x, uint y, uint v) public {
b[x][y] = v;
delete b;
assert(b[y][x] == 0);
}
function h(uint x, uint y, uint v) public {
b[x][y] = v;
delete b[x];
// Not necessarily the case.
assert(b[y][x] == 0);
}
function i(uint x, uint y, uint v) public {
b[x][y] = v;
delete b[y];
assert(b[y][x] == 0);
}
function j(uint x, uint y, uint z, uint v) public {
b[x][y] = v;
delete b[z];
// Not necessarily the case.
assert(b[y][x] == 0);
}
function setA(uint x, uint y) public {
a[x] = y;
}
function setB(uint x, uint y, uint z) public {
b[x][y] = z;
}
}
// ----
// Warning: (372-392): Assertion violation happens here
// Warning: (617-637): Assertion violation happens here
@@ -0,0 +1,19 @@
pragma experimental SMTChecker;
contract C
{
struct S {
uint x;
}
mapping (uint => S) smap;
function f(uint y, uint v) public {
if (0==1)
smap[y] = S(v);
}
}
// ----
// Warning: (140-144): Condition is always false.
// Warning: (149-156): Assertion checker does not yet implement type struct C.S storage ref
// Warning: (159-160): Assertion checker does not yet implement type type(struct C.S storage pointer)
// Warning: (159-163): Assertion checker does not yet implement type struct C.S memory
// Warning: (159-163): Assertion checker does not yet implement this expression.
// Warning: (149-163): Assertion checker does not yet implement type struct C.S storage ref
@@ -0,0 +1,11 @@
contract A {
function f() virtual internal {}
}
contract B is A {
function f() virtual override internal {}
function h() pure internal { f; }
}
contract C is B {
function f() override internal {}
function i() pure internal { f; }
}
@@ -0,0 +1,8 @@
contract C {
function f() public pure {
assembly {
pop(add(add(1, 2), c))
}
}
int constant c = 1;
}
@@ -0,0 +1,12 @@
contract C {
function f() {
assembly {
c := add(add(1, 2), c)
}
}
int constant c = 0 + 1;
}
// ----
// SyntaxError: (15-83): No visibility specified. Did you intend to add "public"?
// TypeError: (71-72): Constant variables with non-literal values cannot be forward referenced from inline assembly.
// TypeError: (51-52): Constant variables cannot be assigned to.
@@ -13,7 +13,7 @@ contract C {
// ====
// EVMVersion: =petersburg
// ----
// TypeError: (101-108): The "chainid" instruction is only available for Istanbul-compatible VMs (you are currently compiling for "petersburg").
// TypeError: (101-108): The "chainid" instruction is only available for Istanbul-compatible VMs (you are currently compiling for "petersburg").
// DeclarationError: (95-110): Variable count does not match number of values (1 vs. 0)
// TypeError: (215-226): The "selfbalance" instruction is only available for Istanbul-compatible VMs (you are currently compiling for "petersburg").
// TypeError: (215-226): The "selfbalance" instruction is only available for Istanbul-compatible VMs (you are currently compiling for "petersburg").
// DeclarationError: (209-228): Variable count does not match number of values (1 vs. 0)
+4 -4
View File
@@ -81,7 +81,7 @@ bytes BytesUtils::convertBoolean(string const& _literal)
else if (_literal == "false")
return bytes{false};
else
throw Error(Error::Type::ParserError, "Boolean literal invalid.");
throw TestParserError("Boolean literal invalid.");
}
bytes BytesUtils::convertNumber(string const& _literal)
@@ -92,7 +92,7 @@ bytes BytesUtils::convertNumber(string const& _literal)
}
catch (std::exception const&)
{
throw Error(Error::Type::ParserError, "Number encoding invalid.");
throw TestParserError("Number encoding invalid.");
}
}
@@ -104,7 +104,7 @@ bytes BytesUtils::convertHexNumber(string const& _literal)
}
catch (std::exception const&)
{
throw Error(Error::Type::ParserError, "Hex number encoding invalid.");
throw TestParserError("Hex number encoding invalid.");
}
}
@@ -116,7 +116,7 @@ bytes BytesUtils::convertString(string const& _literal)
}
catch (std::exception const&)
{
throw Error(Error::Type::ParserError, "String encoding invalid.");
throw TestParserError("String encoding invalid.");
}
}
+9
View File
@@ -30,6 +30,15 @@ namespace solidity::frontend::test
while (false)
class TestParserError: virtual public util::Exception
{
public:
explicit TestParserError(std::string const& _description)
{
*this << util::errinfo_comment(_description);
}
};
/**
* Representation of a notice, warning or error that can occur while
* formatting and therefore updating an interactive function call test.
+19 -22
View File
@@ -18,6 +18,7 @@
#include <test/libsolidity/util/TestFileParser.h>
#include <test/libsolidity/util/BytesUtils.h>
#include <test/libsolidity/util/SoltestErrors.h>
#include <test/Common.h>
#include <liblangutil/Common.h>
@@ -128,9 +129,9 @@ vector<solidity::frontend::test::FunctionCall> TestFileParser::parseFunctionCall
calls.emplace_back(std::move(call));
}
catch (Error const& _e)
catch (TestParserError const& _e)
{
throw Error{_e.type(), "Line " + to_string(_lineOffset + m_lineNumber) + ": " + _e.what()};
throw TestParserError("Line " + to_string(_lineOffset + m_lineNumber) + ": " + _e.what());
}
}
}
@@ -150,8 +151,7 @@ bool TestFileParser::accept(soltest::Token _token, bool const _expect)
bool TestFileParser::expect(soltest::Token _token, bool const _advance)
{
if (m_scanner.currentToken() != _token || m_scanner.currentToken() == Token::Invalid)
throw Error(
Error::Type::ParserError,
throw TestParserError(
"Unexpected " + formatToken(m_scanner.currentToken()) + ": \"" +
m_scanner.currentLiteral() + "\". " +
"Expected \"" + formatToken(_token) + "\"."
@@ -187,10 +187,10 @@ pair<string, bool> TestFileParser::parseFunctionSignature()
parameters += parseIdentifierOrTuple();
}
if (accept(Token::Arrow, true))
throw Error(Error::Type::ParserError, "Invalid signature detected: " + signature);
throw TestParserError("Invalid signature detected: " + signature);
if (!hasName && !parameters.empty())
throw Error(Error::Type::ParserError, "Signatures without a name cannot have parameters: " + signature);
throw TestParserError("Signatures without a name cannot have parameters: " + signature);
else
signature += parameters;
@@ -207,7 +207,7 @@ FunctionValue TestFileParser::parseFunctionCallValue()
u256 value{ parseDecimalNumber() };
Token token = m_scanner.currentToken();
if (token != Token::Ether && token != Token::Wei)
throw Error(Error::Type::ParserError, "Invalid value unit provided. Coins can be wei or ether.");
throw TestParserError("Invalid value unit provided. Coins can be wei or ether.");
m_scanner.scanNextToken();
@@ -216,7 +216,7 @@ FunctionValue TestFileParser::parseFunctionCallValue()
}
catch (std::exception const&)
{
throw Error(Error::Type::ParserError, "Ether value encoding invalid.");
throw TestParserError("Ether value encoding invalid.");
}
}
@@ -226,7 +226,7 @@ FunctionCallArgs TestFileParser::parseFunctionCallArguments()
auto param = parseParameter();
if (param.abiType.type == ABIType::None)
throw Error(Error::Type::ParserError, "No argument provided.");
throw TestParserError("No argument provided.");
arguments.parameters.emplace_back(param);
while (accept(Token::Comma, true))
@@ -290,7 +290,7 @@ Parameter TestFileParser::parseParameter()
if (accept(Token::Boolean))
{
if (isSigned)
throw Error(Error::Type::ParserError, "Invalid boolean literal.");
throw TestParserError("Invalid boolean literal.");
parameter.abiType = ABIType{ABIType::Boolean, ABIType::AlignRight, 32};
string parsed = parseBoolean();
@@ -304,7 +304,7 @@ Parameter TestFileParser::parseParameter()
else if (accept(Token::HexNumber))
{
if (isSigned)
throw Error(Error::Type::ParserError, "Invalid hex number literal.");
throw TestParserError("Invalid hex number literal.");
parameter.abiType = ABIType{ABIType::Hex, ABIType::AlignRight, 32};
string parsed = parseHexNumber();
@@ -318,9 +318,9 @@ Parameter TestFileParser::parseParameter()
else if (accept(Token::Hex, true))
{
if (isSigned)
throw Error(Error::Type::ParserError, "Invalid hex string literal.");
throw TestParserError("Invalid hex string literal.");
if (parameter.alignment != Parameter::Alignment::None)
throw Error(Error::Type::ParserError, "Hex string literals cannot be aligned or padded.");
throw TestParserError("Hex string literals cannot be aligned or padded.");
string parsed = parseString();
parameter.rawString += "hex\"" + parsed + "\"";
@@ -332,9 +332,9 @@ Parameter TestFileParser::parseParameter()
else if (accept(Token::String))
{
if (isSigned)
throw Error(Error::Type::ParserError, "Invalid string literal.");
throw TestParserError("Invalid string literal.");
if (parameter.alignment != Parameter::Alignment::None)
throw Error(Error::Type::ParserError, "String literals cannot be aligned or padded.");
throw TestParserError("String literals cannot be aligned or padded.");
string parsed = parseString();
parameter.abiType = ABIType{ABIType::String, ABIType::AlignLeft, parsed.size()};
@@ -364,7 +364,7 @@ Parameter TestFileParser::parseParameter()
else if (accept(Token::Failure, true))
{
if (isSigned)
throw Error(Error::Type::ParserError, "Invalid failure literal.");
throw TestParserError("Invalid failure literal.");
parameter.abiType = ABIType{ABIType::Failure, ABIType::AlignRight, 0};
parameter.rawBytes = bytes{};
@@ -555,10 +555,7 @@ void TestFileParser::Scanner::scanNextToken()
else if (isEndOfLine())
token = make_pair(Token::EOS, "EOS");
else
throw Error(
Error::Type::ParserError,
"Unexpected character: '" + string{current()} + "'"
);
throw TestParserError("Unexpected character: '" + string{current()} + "'");
break;
}
}
@@ -651,7 +648,7 @@ string TestFileParser::Scanner::scanString()
str += scanHexPart();
break;
default:
throw Error(Error::Type::ParserError, "Invalid or escape sequence found in string literal.");
throw TestParserError("Invalid or escape sequence found in string literal.");
}
}
else
@@ -673,7 +670,7 @@ char TestFileParser::Scanner::scanHexPart()
else if (tolower(current()) >= 'a' && tolower(current()) <= 'f')
value = tolower(current()) - 'a' + 10;
else
throw Error(Error::Type::ParserError, "\\x used with no following hex digits.");
throw TestParserError("\\x used with no following hex digits.");
advance();
if (current() == '"')
+25 -24
View File
@@ -25,6 +25,7 @@
#include <liblangutil/Exceptions.h>
#include <test/ExecutionFramework.h>
#include <test/libsolidity/util/SoltestErrors.h>
#include <test/libsolidity/util/TestFileParser.h>
using namespace std;
@@ -365,7 +366,7 @@ BOOST_AUTO_TEST_CASE(scanner_hex_values_invalid1)
char const* source = R"(
// f(uint256): "\x" ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(scanner_hex_values_invalid2)
@@ -383,7 +384,7 @@ BOOST_AUTO_TEST_CASE(scanner_hex_values_invalid3)
char const* source = R"(
// f(uint256): "\xZ" ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(scanner_hex_values_invalid4)
@@ -391,7 +392,7 @@ BOOST_AUTO_TEST_CASE(scanner_hex_values_invalid4)
char const* source = R"(
// f(uint256): "\xZZ" ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_hex_string)
@@ -741,7 +742,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_hex_string_left_align)
char const* source = R"(
// f(bytes): left(hex"4200ef") ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_hex_string_right_align)
@@ -749,7 +750,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_hex_string_right_align)
char const* source = R"(
// f(bytes): right(hex"4200ef") ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_newline_invalid)
@@ -757,7 +758,7 @@ BOOST_AUTO_TEST_CASE(call_newline_invalid)
char const* source = R"(
/
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_invalid)
@@ -765,7 +766,7 @@ BOOST_AUTO_TEST_CASE(call_invalid)
char const* source = R"(
/ f() ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_signature_invalid)
@@ -773,7 +774,7 @@ BOOST_AUTO_TEST_CASE(call_signature_invalid)
char const* source = R"(
// f(uint8,) -> FAILURE
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_tuple_invalid)
@@ -781,7 +782,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_tuple_invalid)
char const* source = R"(
// f((uint8,) -> FAILURE
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_tuple_invalid_empty)
@@ -789,7 +790,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_tuple_invalid_empty)
char const* source = R"(
// f(uint8, ()) -> FAILURE
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_tuple_invalid_parantheses)
@@ -797,14 +798,14 @@ BOOST_AUTO_TEST_CASE(call_arguments_tuple_invalid_parantheses)
char const* source = R"(
// f((uint8,() -> FAILURE
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_ether_value_expectations_missing)
{
char const* source = R"(
// f(), 0)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_invalid)
@@ -812,7 +813,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_invalid)
char const* source = R"(
// f(uint256): abc -> 1
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_invalid_decimal)
@@ -820,7 +821,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_invalid_decimal)
char const* source = R"(
// sig(): 0.h3 ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_ether_value_invalid)
@@ -828,7 +829,7 @@ BOOST_AUTO_TEST_CASE(call_ether_value_invalid)
char const* source = R"(
// f(uint256), abc : 1 -> 1
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_ether_value_invalid_decimal)
@@ -836,7 +837,7 @@ BOOST_AUTO_TEST_CASE(call_ether_value_invalid_decimal)
char const* source = R"(
// sig(): 0.1hd ether ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_ether_type_invalid)
@@ -844,7 +845,7 @@ BOOST_AUTO_TEST_CASE(call_ether_type_invalid)
char const* source = R"(
// f(uint256), 2 btc : 1 -> 1
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_signed_bool_invalid)
@@ -852,7 +853,7 @@ BOOST_AUTO_TEST_CASE(call_signed_bool_invalid)
char const* source = R"(
// f() -> -true
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_signed_failure_invalid)
@@ -860,7 +861,7 @@ BOOST_AUTO_TEST_CASE(call_signed_failure_invalid)
char const* source = R"(
// f() -> -FAILURE
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_signed_hex_number_invalid)
@@ -868,7 +869,7 @@ BOOST_AUTO_TEST_CASE(call_signed_hex_number_invalid)
char const* source = R"(
// f() -> -0x42
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_colon)
@@ -877,7 +878,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_colon)
// h256():
// -> 1
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_newline_colon)
@@ -887,7 +888,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_newline_colon)
// :
// -> 1
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arrow_missing)
@@ -895,7 +896,7 @@ BOOST_AUTO_TEST_CASE(call_arrow_missing)
char const* source = R"(
// h256() FAILURE
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_unexpected_character)
@@ -903,7 +904,7 @@ BOOST_AUTO_TEST_CASE(call_unexpected_character)
char const* source = R"(
// f() -> ??
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(constructor)