diff options
Diffstat (limited to 'test/libsolidity/SolidityParser.cpp')
-rw-r--r-- | test/libsolidity/SolidityParser.cpp | 487 |
1 files changed, 1 insertions, 486 deletions
diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index 100b3662..0c801cf6 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -112,93 +112,6 @@ while(0) BOOST_AUTO_TEST_SUITE(SolidityParser) -BOOST_AUTO_TEST_CASE(empty_function) -{ - char const* text = R"( - contract test { - uint256 stateVar; - function functionName(bytes20 arg1, address addr) constant - returns (int id) - { } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(no_function_params) -{ - char const* text = R"( - contract test { - uint256 stateVar; - function functionName() {} - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(single_function_param) -{ - char const* text = R"( - contract test { - uint256 stateVar; - function functionName(bytes32 input) returns (bytes32 out) {} - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(single_function_param_trailing_comma) -{ - char const* text = R"( - contract test { - function(uint a,) {} - } - )"; - CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); -} - -BOOST_AUTO_TEST_CASE(single_return_param_trailing_comma) -{ - char const* text = R"( - contract test { - function() returns (uint a,) {} - } - )"; - CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); -} - -BOOST_AUTO_TEST_CASE(single_modifier_arg_trailing_comma) -{ - char const* text = R"( - contract test { - modifier modTest(uint a,) { _; } - function(uint a) {} - } - )"; - CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); -} - -BOOST_AUTO_TEST_CASE(single_event_arg_trailing_comma) -{ - char const* text = R"( - contract test { - event Test(uint a,); - function(uint a) {} - } - )"; - CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); -} - -BOOST_AUTO_TEST_CASE(multiple_function_param_trailing_comma) -{ - char const* text = R"( - contract test { - function(uint a, uint b,) {} - } - )"; - CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); -} - BOOST_AUTO_TEST_CASE(multiple_return_param_trailing_comma) { char const* text = R"( @@ -231,49 +144,6 @@ BOOST_AUTO_TEST_CASE(multiple_event_arg_trailing_comma) CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); } -BOOST_AUTO_TEST_CASE(function_no_body) -{ - char const* text = R"( - contract test { - function functionName(bytes32 input) returns (bytes32 out); - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(missing_parameter_name_in_named_args) -{ - char const* text = R"( - contract test { - function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; } - function b() returns (uint r) { r = a({: 1, : 2, : 3}); } - } - )"; - CHECK_PARSE_ERROR(text, "Expected identifier"); -} - -BOOST_AUTO_TEST_CASE(missing_argument_in_named_args) -{ - char const* text = R"( - contract test { - function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; } - function b() returns (uint r) { r = a({a: , b: , c: }); } - } - )"; - CHECK_PARSE_ERROR(text, "Expected primary expression"); -} - -BOOST_AUTO_TEST_CASE(trailing_comma_in_named_args) -{ - char const* text = R"( - contract test { - function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; } - function b() returns (uint r) { r = a({a: 1, b: 2, c: 3, }); } - } - )"; - CHECK_PARSE_ERROR(text, "Unexpected trailing comma"); -} - BOOST_AUTO_TEST_CASE(two_exact_functions) { char const* text = R"( @@ -288,17 +158,6 @@ BOOST_AUTO_TEST_CASE(two_exact_functions) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(overloaded_functions) -{ - char const* text = R"( - contract test { - function fun(uint a) returns(uint r) { return a; } - function fun(uint a, uint b) returns(uint r) { return a + b; } - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(function_natspec_documentation) { char const* text = R"( @@ -557,18 +416,6 @@ BOOST_AUTO_TEST_CASE(variable_definition_with_initialization) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(variable_definition_in_mapping) -{ - char const* text = R"( - contract test { - function fun() { - mapping(var=>bytes32) d; - } - } - )"; - CHECK_PARSE_ERROR(text, "Expected elementary type name for mapping key type"); -} - BOOST_AUTO_TEST_CASE(operator_expression) { char const* text = R"( @@ -849,16 +696,6 @@ BOOST_AUTO_TEST_CASE(modifier) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(modifier_without_semicolon) -{ - char const* text = R"( - contract c { - modifier mod { if (msg.sender == 0) _ } - } - )"; - CHECK_PARSE_ERROR(text, "Expected token Semicolon got"); -} - BOOST_AUTO_TEST_CASE(modifier_arguments) { char const* text = R"( @@ -918,16 +755,6 @@ BOOST_AUTO_TEST_CASE(event_arguments_indexed) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(event_with_no_argument_list_fails) -{ - char const* text = R"( - contract c { - event e; - } - )"; - CHECK_PARSE_ERROR(text, "Expected token LParen got 'Semicolon'"); -} - BOOST_AUTO_TEST_CASE(visibility_specifiers) { char const* text = R"( @@ -958,40 +785,6 @@ BOOST_AUTO_TEST_CASE(multiple_visibility_specifiers) CHECK_PARSE_ERROR(text, "Visibility already specified as \"private\"."); } -BOOST_AUTO_TEST_CASE(multiple_statemutability_specifiers) -{ - char const* text = R"( - contract c { - function f() payable payable {} - })"; - CHECK_PARSE_ERROR(text, "State mutability already specified as \"payable\"."); - text = R"( - contract c { - function f() constant constant {} - })"; - CHECK_PARSE_ERROR(text, "State mutability already specified as \"view\"."); - text = R"( - contract c { - function f() constant view {} - })"; - CHECK_PARSE_ERROR(text, "State mutability already specified as \"view\"."); - text = R"( - contract c { - function f() payable constant {} - })"; - CHECK_PARSE_ERROR(text, "State mutability already specified as \"payable\"."); - text = R"( - contract c { - function f() pure payable {} - })"; - CHECK_PARSE_ERROR(text, "State mutability already specified as \"pure\"."); - text = R"( - contract c { - function f() pure constant {} - })"; - CHECK_PARSE_ERROR(text, "State mutability already specified as \"pure\"."); -} - BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations) { char const* text = R"( @@ -1038,24 +831,6 @@ BOOST_AUTO_TEST_CASE(enum_valid_declaration) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(empty_enum_declaration) -{ - char const* text = R"( - contract c { - enum foo { } - })"; - CHECK_PARSE_ERROR(text, "enum with no members is not allowed"); -} - -BOOST_AUTO_TEST_CASE(malformed_enum_declaration) -{ - char const* text = R"( - contract c { - enum foo { WARNING,} - })"; - CHECK_PARSE_ERROR(text, "Expected Identifier after"); -} - BOOST_AUTO_TEST_CASE(external_function) { char const* text = R"( @@ -1065,15 +840,6 @@ BOOST_AUTO_TEST_CASE(external_function) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(external_variable) -{ - char const* text = R"( - contract c { - uint external x; - })"; - CHECK_PARSE_ERROR(text, "Expected identifier"); -} - BOOST_AUTO_TEST_CASE(arrays_in_storage) { char const* text = R"( @@ -1113,15 +879,6 @@ BOOST_AUTO_TEST_CASE(multi_arrays) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(constant_is_keyword) -{ - char const* text = R"( - contract Foo { - uint constant = 4; - })"; - CHECK_PARSE_ERROR(text, "Expected identifier"); -} - BOOST_AUTO_TEST_CASE(keyword_is_reserved) { auto keywords = { @@ -1148,19 +905,10 @@ BOOST_AUTO_TEST_CASE(keyword_is_reserved) for (const auto& keyword: keywords) { auto text = std::string("contract ") + keyword + " {}"; - CHECK_PARSE_ERROR(text.c_str(), "Expected identifier"); + CHECK_PARSE_ERROR(text.c_str(), "Expected identifier but got reserved keyword"); } } -BOOST_AUTO_TEST_CASE(var_array) -{ - char const* text = R"( - contract Foo { - function f() { var[] a; } - })"; - CHECK_PARSE_ERROR(text, "Expected identifier"); -} - BOOST_AUTO_TEST_CASE(location_specifiers_for_params) { char const* text = R"( @@ -1184,47 +932,6 @@ BOOST_AUTO_TEST_CASE(location_specifiers_for_locals) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(location_specifiers_for_state) -{ - char const* text = R"( - contract Foo { - uint[] memory x; - })"; - CHECK_PARSE_ERROR(text, "Expected identifier"); -} - -BOOST_AUTO_TEST_CASE(location_specifiers_with_var) -{ - char const* text = R"( - contract Foo { - function f() { var memory x; } - })"; - CHECK_PARSE_ERROR(text, "Location specifier needs explicit type name"); -} - -BOOST_AUTO_TEST_CASE(empty_comment) -{ - char const* text = R"( - // - contract test - {} - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(comment_end_with_double_star) -{ - char const* text = R"( - contract C1 { - /** - **/ - } - contract C2 {} - )"; - BOOST_CHECK(successParse(text)); -} - - BOOST_AUTO_TEST_CASE(library_simple) { char const* text = R"( @@ -1235,68 +942,6 @@ BOOST_AUTO_TEST_CASE(library_simple) BOOST_CHECK(successParse(text)); } - -BOOST_AUTO_TEST_CASE(local_const_variable) -{ - char const* text = R"( - contract Foo { - function localConst() returns (uint ret) - { - uint constant local = 4; - return local; - } - })"; - CHECK_PARSE_ERROR(text, "Expected token Semicolon"); -} - -BOOST_AUTO_TEST_CASE(multi_variable_declaration) -{ - char const* text = R"( - contract C { - function f() { - var (a,b,c) = g(); - var (d) = 2; - var (,e) = 3; - var (f,) = 4; - var (x,,) = g(); - var (,y,) = g(); - var () = g(); - var (,,) = g(); - } - function g() returns (uint, uint, uint) {} - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(tuples) -{ - char const* text = R"( - contract C { - function f() { - uint a = (1); - var (b,) = (1,); - var (c,d) = (1, 2 + a); - var (e,) = (1, 2, b); - (a) = 3; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(tuples_without_commas) -{ - char const* text = R"( - contract C { - function f() { - var a = (2 2); - } - } - )"; - CHECK_PARSE_ERROR(text, "Expected token Comma"); -} - BOOST_AUTO_TEST_CASE(member_access_parser_ambiguity) { char const* text = R"( @@ -1365,34 +1010,6 @@ BOOST_AUTO_TEST_CASE(inline_array_declaration) BOOST_CHECK(successParse(text)); } - -BOOST_AUTO_TEST_CASE(inline_array_empty_cells_check_lvalue) -{ - char const* text = R"( - contract c { - uint[] a; - function f() returns (uint) { - a = [,2,3]; - return (a[0]); - } - } - )"; - CHECK_PARSE_ERROR(text, "Expected expression"); -} - -BOOST_AUTO_TEST_CASE(inline_array_empty_cells_check_without_lvalue) -{ - char const* text = R"( - contract c { - uint[] a; - function f() returns (uint, uint) { - return ([3, ,4][0]); - } - } - )"; - CHECK_PARSE_ERROR(text, "Expected expression"); -} - BOOST_AUTO_TEST_CASE(conditional_true_false_literal) { char const* text = R"( @@ -1520,38 +1137,6 @@ BOOST_AUTO_TEST_CASE(declaring_fixed_literal_variables) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(no_double_radix_in_fixed_literal) -{ - char const* text = R"( - contract A { - fixed40x40 pi = 3.14.15; - } - )"; - CHECK_PARSE_ERROR(text, "Expected token Semicolon"); -} - -BOOST_AUTO_TEST_CASE(invalid_fixed_conversion_leading_zeroes_check) -{ - char const* text = R"( - contract test { - function f() { - fixed a = 1.0x2; - } - } - )"; - CHECK_PARSE_ERROR(text, "Expected primary expression"); -} - -BOOST_AUTO_TEST_CASE(payable_accessor) -{ - char const* text = R"( - contract test { - uint payable x; - } - )"; - CHECK_PARSE_ERROR(text, "Expected identifier"); -} - BOOST_AUTO_TEST_CASE(function_type_in_expression) { char const* text = R"( @@ -1575,16 +1160,6 @@ BOOST_AUTO_TEST_CASE(function_type_as_storage_variable) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(function_type_as_storage_variable_with_modifiers) -{ - char const* text = R"( - contract test { - function (uint, uint) modifier1() returns (uint) f1; - } - )"; - CHECK_PARSE_ERROR(text, "Expected token LBrace"); -} - BOOST_AUTO_TEST_CASE(function_type_as_storage_variable_with_assignment) { char const* text = R"( @@ -1649,66 +1224,6 @@ BOOST_AUTO_TEST_CASE(mapping_and_array_of_functions) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(function_type_state_variable) -{ - char const* text = R"( - contract test { - function() x; - function() y = x; - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(scientific_notation) -{ - char const* text = R"( - contract test { - uint256 a = 2e10; - uint256 b = 2E10; - uint256 c = 200e-2; - uint256 d = 2E10 wei; - uint256 e = 2.5e10; - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(interface) -{ - char const* text = R"( - interface Interface { - function f(); - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(newInvalidTypeName) -{ - char const* text = R"( - contract C { - function f() { - new var; - } - } - )"; - CHECK_PARSE_ERROR(text, "Expected explicit type name"); -} - -BOOST_AUTO_TEST_CASE(emitWithoutEvent) -{ - char const* text = R"( - contract C { - event A(); - function f() { - emit A; - } - } - )"; - CHECK_PARSE_ERROR(text, "Expected token LParen got 'Semicolon'"); -} - BOOST_AUTO_TEST_SUITE_END() } |