diff options
author | chriseth <chris@ethereum.org> | 2018-11-14 02:33:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-14 02:33:35 +0800 |
commit | 1d4f565a64988a3400847d2655ca24f73f234bc6 (patch) | |
tree | caaa6c26e307513505349b50ca4f2a8a9506752b /test/libsolidity/SolidityParser.cpp | |
parent | 59dbf8f1085b8b92e8b7eb0ce380cbeb642e97eb (diff) | |
parent | 91b6b8a88e76016e0324036cb7a7f9300a1e2439 (diff) | |
download | dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar.gz dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar.bz2 dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar.lz dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar.xz dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar.zst dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.zip |
Merge pull request #5416 from ethereum/develop
Merge develop into release for 0.5.0
Diffstat (limited to 'test/libsolidity/SolidityParser.cpp')
-rw-r--r-- | test/libsolidity/SolidityParser.cpp | 674 |
1 files changed, 32 insertions, 642 deletions
diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index 0c801cf6..5432e9b5 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -112,59 +112,13 @@ while(0) BOOST_AUTO_TEST_SUITE(SolidityParser) -BOOST_AUTO_TEST_CASE(multiple_return_param_trailing_comma) -{ - char const* text = R"( - contract test { - function() returns (uint a, uint b,) {} - } - )"; - CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); -} - -BOOST_AUTO_TEST_CASE(multiple_modifier_arg_trailing_comma) -{ - char const* text = R"( - contract test { - modifier modTest(uint a, uint b,) { _; } - function(uint a) {} - } - )"; - CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); -} - -BOOST_AUTO_TEST_CASE(multiple_event_arg_trailing_comma) -{ - char const* text = R"( - contract test { - event Test(uint a, uint b,); - function(uint a) {} - } - )"; - CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); -} - -BOOST_AUTO_TEST_CASE(two_exact_functions) -{ - char const* text = R"( - contract test { - function fun(uint a) returns(uint r) { return a; } - function fun(uint a) returns(uint r) { return a; } - } - )"; - // with support of overloaded functions, during parsing, - // we can't determine whether they match exactly, however - // it will throw DeclarationError in following stage. - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(function_natspec_documentation) { char const* text = R"( contract test { uint256 stateVar; /// This is a test function - function functionName(bytes32 input) returns (bytes32 out) {} + function functionName(bytes32 input) public returns (bytes32 out) {} } )"; BOOST_CHECK(successParse(text)); @@ -184,7 +138,7 @@ BOOST_AUTO_TEST_CASE(function_normal_comments) contract test { uint256 stateVar; // We won't see this comment - function functionName(bytes32 input) returns (bytes32 out) {} + function functionName(bytes32 input) public returns (bytes32 out) {} } )"; BOOST_CHECK(successParse(text)); @@ -203,13 +157,13 @@ BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation) contract test { uint256 stateVar; /// This is test function 1 - function functionName1(bytes32 input) returns (bytes32 out) {} + function functionName1(bytes32 input) public returns (bytes32 out) {} /// This is test function 2 - function functionName2(bytes32 input) returns (bytes32 out) {} + function functionName2(bytes32 input) public returns (bytes32 out) {} // nothing to see here - function functionName3(bytes32 input) returns (bytes32 out) {} + function functionName3(bytes32 input) public returns (bytes32 out) {} /// This is test function 4 - function functionName4(bytes32 input) returns (bytes32 out) {} + function functionName4(bytes32 input) public returns (bytes32 out) {} } )"; BOOST_CHECK(successParse(text)); @@ -239,7 +193,7 @@ BOOST_AUTO_TEST_CASE(multiline_function_documentation) uint256 stateVar; /// This is a test function /// and it has 2 lines - function functionName1(bytes32 input) returns (bytes32 out) {} + function functionName1(bytes32 input) public returns (bytes32 out) {} } )"; BOOST_CHECK(successParse(text)); @@ -266,7 +220,7 @@ BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body) } /// This is a test function /// and it has 2 lines - function fun(bytes32 input) returns (bytes32 out) {} + function fun(bytes32 input) public returns (bytes32 out) {} } )"; BOOST_CHECK(successParse(text)); @@ -334,57 +288,6 @@ BOOST_AUTO_TEST_CASE(natspec_docstring_after_signature) "Shouldn't get natspec docstring for this function"); } -BOOST_AUTO_TEST_CASE(struct_definition) -{ - char const* text = R"( - contract test { - uint256 stateVar; - struct MyStructName { - address addr; - uint256 count; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(mapping) -{ - char const* text = R"( - contract test { - mapping(address => bytes32) names; - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(mapping_in_struct) -{ - char const* text = R"( - contract test { - struct test_struct { - address addr; - uint256 count; - mapping(bytes32 => test_struct) self_reference; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(mapping_to_mapping_in_struct) -{ - char const* text = R"( - contract test { - struct test_struct { - address addr; - mapping (uint64 => mapping (bytes32 => uint)) complex_mapping; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(variable_definition) { char const* text = R"( @@ -440,112 +343,6 @@ BOOST_AUTO_TEST_CASE(complex_expression) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(exp_expression) -{ - char const* text = R"( - contract test { - function fun(uint256 a) { - uint256 x = 3 ** a; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(while_loop) -{ - char const* text = R"( - contract test { - function fun(uint256 a) { - while (true) { uint256 x = 1; break; continue; } x = 9; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(for_loop_vardef_initexpr) -{ - char const* text = R"( - contract test { - function fun(uint256 a) { - for (uint256 i = 0; i < 10; i++) { - uint256 x = i; break; continue; - } - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(for_loop_simple_initexpr) -{ - char const* text = R"( - contract test { - function fun(uint256 a) { - uint256 i =0; - for (i = 0; i < 10; i++) { - uint256 x = i; break; continue; - } - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(for_loop_simple_noexpr) -{ - char const* text = R"( - contract test { - function fun(uint256 a) { - uint256 i =0; - for (;;) { - uint256 x = i; break; continue; - } - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(for_loop_single_stmt_body) -{ - char const* text = R"( - contract test { - function fun(uint256 a) { - uint256 i = 0; - for (i = 0; i < 10; i++) - continue; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(if_statement) -{ - char const* text = R"( - contract test { - function fun(uint256 a) { - if (a >= 8) { return 2; } else { var b = 7; } - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(else_if_statement) -{ - char const* text = R"( - contract test { - function fun(uint256 a) returns (address b) { - if (a < 0) b = 0x67; else if (a == 0) b = 0x12; else b = 0x78; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(statement_starting_with_type_conversion) { char const* text = R"( @@ -673,275 +470,70 @@ BOOST_AUTO_TEST_CASE(contract_multiple_inheritance_with_arguments) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(placeholder_in_function_context) -{ - char const* text = R"( - contract c { - function fun() returns (uint r) { - var _ = 8; - return _ + 1; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(modifier) -{ - char const* text = R"( - contract c { - modifier mod { if (msg.sender == 0) _; } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(modifier_arguments) -{ - char const* text = R"( - contract c { - modifier mod(address a) { if (msg.sender == a) _; } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(modifier_invocation) -{ - char const* text = R"( - contract c { - modifier mod1(uint a) { if (msg.sender == a) _; } - modifier mod2 { if (msg.sender == 2) _; } - function f() mod1(7) mod2 { } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(fallback_function) -{ - char const* text = R"( - contract c { - function() { } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(event) -{ - char const* text = R"( - contract c { - event e(); - })"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(event_arguments) -{ - char const* text = R"( - contract c { - event e(uint a, bytes32 s); - })"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(event_arguments_indexed) -{ - char const* text = R"( - contract c { - event e(uint a, bytes32 indexed s, bool indexed b); - })"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(visibility_specifiers) -{ - char const* text = R"( - contract c { - uint private a; - uint internal b; - uint public c; - uint d; - function f() {} - function f_priv() private {} - function f_public() public {} - function f_internal() internal {} - })"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(multiple_visibility_specifiers) { char const* text = R"( contract c { uint private internal a; - })"; + } + )"; CHECK_PARSE_ERROR(text, "Visibility already specified as \"private\"."); text = R"( contract c { function f() private external {} - })"; + } + )"; CHECK_PARSE_ERROR(text, "Visibility already specified as \"private\"."); } -BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations) -{ - char const* text = R"( - contract c { - function c () - { - a = 1 wei; - b = 2 szabo; - c = 3 finney; - b = 4 ether; - } - uint256 a; - uint256 b; - uint256 c; - uint256 d; - })"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations_in_expressions) -{ - char const* text = R"( - contract c { - function c () - { - a = 1 wei * 100 wei + 7 szabo - 3; - } - uint256 a; - })"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(enum_valid_declaration) -{ - char const* text = R"( - contract c { - enum validEnum { Value1, Value2, Value3, Value4 } - function c () - { - a = foo.Value3; - } - uint256 a; - })"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(external_function) -{ - char const* text = R"( - contract c { - function x() external {} - })"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(arrays_in_storage) -{ - char const* text = R"( - contract c { - uint[10] a; - uint[] a2; - struct x { uint[2**20] b; y[0] c; } - struct y { uint d; mapping(uint=>x)[] e; } - })"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(arrays_in_events) -{ - char const* text = R"( - contract c { - event e(uint[10] a, bytes7[8] indexed b, c[3] x); - })"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(arrays_in_expressions) -{ - char const* text = R"( - contract c { - function f() { c[10] a = 7; uint8[10 * 2] x; } - })"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(multi_arrays) -{ - char const* text = R"( - contract c { - mapping(uint => mapping(uint => int8)[8][][9])[] x; - })"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(keyword_is_reserved) { auto keywords = { "abstract", "after", + "alias", + "apply", + "auto", "case", "catch", + "copyof", "default", + "define", "final", + "immutable", + "implements", "in", "inline", "let", + "macro", "match", + "mutable", "null", "of", + "override", + "partial", + "promise", + "reference", "relocatable", + "sealed", + "sizeof", "static", + "supports", "switch", "try", "type", - "typeof" + "typedef", + "typeof", + "unchecked" }; for (const auto& keyword: keywords) { auto text = std::string("contract ") + keyword + " {}"; - CHECK_PARSE_ERROR(text.c_str(), "Expected identifier but got reserved keyword"); + CHECK_PARSE_ERROR(text.c_str(), string("Expected identifier but got reserved keyword '") + keyword + "'"); } } -BOOST_AUTO_TEST_CASE(location_specifiers_for_params) -{ - char const* text = R"( - contract Foo { - function f(uint[] storage constant x, uint[] memory y) { } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(location_specifiers_for_locals) -{ - char const* text = R"( - contract Foo { - function f() { - uint[] storage x; - uint[] memory y; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(library_simple) -{ - char const* text = R"( - library Lib { - function f() { } - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(member_access_parser_ambiguity) { char const* text = R"( @@ -986,97 +578,6 @@ BOOST_AUTO_TEST_CASE(complex_import) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(from_is_not_keyword) -{ - // "from" is not a keyword although it is used as a keyword in import directives. - char const* text = R"( - contract from { - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(inline_array_declaration) -{ - char const* text = R"( - contract c { - uint[] a; - function f() returns (uint, uint) { - a = [1,2,3]; - return (a[3], [2,3,4][0]); - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(conditional_true_false_literal) -{ - char const* text = R"( - contract A { - function f() { - uint x = true ? 1 : 0; - uint y = false ? 0 : 1; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(conditional_with_constants) -{ - char const* text = R"( - contract A { - function f() { - uint x = 3 > 0 ? 3 : 0; - uint y = (3 > 0) ? 3 : 0; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(conditional_with_variables) -{ - char const* text = R"( - contract A { - function f() { - uint x = 3; - uint y = 1; - uint z = (x > y) ? x : y; - uint w = x > y ? x : y; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(conditional_multiple) -{ - char const* text = R"( - contract A { - function f() { - uint x = 3 < 0 ? 2 > 1 ? 2 : 1 : 7 > 2 ? 7 : 6; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(conditional_with_assignment) -{ - char const* text = R"( - contract A { - function f() { - uint y = 1; - uint x = 3 < 0 ? x = 3 : 6; - true ? x = 3 : 4; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(recursion_depth1) { string text("contract C { bytes"); @@ -1113,117 +614,6 @@ BOOST_AUTO_TEST_CASE(recursion_depth4) CHECK_PARSE_ERROR(text, "Maximum recursion depth reached during parsing"); } -BOOST_AUTO_TEST_CASE(declaring_fixed_and_ufixed_variables) -{ - char const* text = R"( - contract A { - fixed40x40 storeMe; - function f(ufixed x, fixed32x32 y) { - ufixed8x8 a; - fixed b; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(declaring_fixed_literal_variables) -{ - char const* text = R"( - contract A { - fixed40x40 pi = 3.14; - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(function_type_in_expression) -{ - char const* text = R"( - contract test { - function f(uint x, uint y) returns (uint a) {} - function g() { - function (uint, uint) internal returns (uint) f1 = f; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(function_type_as_storage_variable) -{ - char const* text = R"( - contract test { - function (uint, uint) internal returns (uint) f1; - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(function_type_as_storage_variable_with_assignment) -{ - char const* text = R"( - contract test { - function f(uint x, uint y) returns (uint a) {} - function (uint, uint) internal returns (uint) f1 = f; - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(function_type_in_struct) -{ - char const* text = R"( - contract test { - struct S { - function (uint x, uint y) internal returns (uint a) f; - function (uint, uint) external returns (uint) g; - uint d; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(function_type_as_parameter) -{ - char const* text = R"( - contract test { - function f(function(uint) external returns (uint) g) internal returns (uint a) { - return g(1); - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(calling_function) -{ - char const* text = R"( - contract test { - function f() { - function() returns(function() returns(function() returns(function() returns(uint)))) x; - uint y; - y = x()()()(); - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(mapping_and_array_of_functions) -{ - char const* text = R"( - contract test { - mapping (address => function() internal returns (uint)) a; - mapping (address => function() external) b; - mapping (address => function() external[]) c; - function() external[] d; - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_SUITE_END() } |