diff options
Diffstat (limited to 'test/libsolidity/SolidityNameAndTypeResolution.cpp')
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 471 |
1 files changed, 0 insertions, 471 deletions
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 293f5f44..18a414e0 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -975,139 +975,6 @@ BOOST_AUTO_TEST_CASE(super_excludes_current_contract) CHECK_ERROR(text, TypeError, "Member \"f\" not found or not visible after argument-dependent lookup in contract super B"); } -BOOST_AUTO_TEST_CASE(function_modifier_invocation) -{ - char const* text = R"( - contract B { - function f() mod1(2, true) mod2("0123456") pure public { } - modifier mod1(uint a, bool b) { if (b) _; } - modifier mod2(bytes7 a) { while (a == "1234567") _; } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(invalid_function_modifier_type) -{ - char const* text = R"( - contract B { - function f() mod1(true) public { } - modifier mod1(uint a) { if (a > 0) _; } - } - )"; - CHECK_ERROR(text, TypeError, "Invalid type for argument in modifier invocation. Invalid implicit conversion from bool to uint256 requested."); -} - -BOOST_AUTO_TEST_CASE(function_modifier_invocation_parameters) -{ - char const* text = R"( - contract B { - function f(uint8 a) mod1(a, true) mod2(r) public returns (bytes7 r) { } - modifier mod1(uint a, bool b) { if (b) _; } - modifier mod2(bytes7 a) { while (a == "1234567") _; } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(function_modifier_invocation_local_variables) -{ - char const* text = R"( - contract B { - function f() mod(x) pure public { uint x = 7; } - modifier mod(uint a) { if (a > 0) _; } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(function_modifier_invocation_local_variables050) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract B { - function f() mod(x) pure public { uint x = 7; } - modifier mod(uint a) { if (a > 0) _; } - } - )"; - CHECK_ERROR(text, DeclarationError, "Undeclared identifier."); -} - -BOOST_AUTO_TEST_CASE(function_modifier_double_invocation) -{ - char const* text = R"( - contract B { - function f(uint x) mod(x) mod(2) public { } - modifier mod(uint a) { if (a > 0) _; } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(base_constructor_double_invocation) -{ - char const* text = R"( - contract C { function C(uint a) public {} } - contract B is C { - function B() C(2) C(2) public {} - } - )"; - CHECK_ERROR(text, DeclarationError, "Base constructor already provided"); -} - -BOOST_AUTO_TEST_CASE(legal_modifier_override) -{ - char const* text = R"( - contract A { modifier mod(uint a) { _; } } - contract B is A { modifier mod(uint a) { _; } } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(illegal_modifier_override) -{ - char const* text = R"( - contract A { modifier mod(uint a) { _; } } - contract B is A { modifier mod(uint8 a) { _; } } - )"; - CHECK_ERROR(text, TypeError, "Override changes modifier signature."); -} - -BOOST_AUTO_TEST_CASE(modifier_overrides_function) -{ - char const* text = R"( - contract A { modifier mod(uint a) { _; } } - contract B is A { function mod(uint a) public { } } - )"; - CHECK_ALLOW_MULTI(text, (vector<pair<Error::Type, string>>{ - {Error::Type::DeclarationError, "Identifier already declared"}, - {Error::Type::TypeError, "Override changes modifier to function"} - })); -} - -BOOST_AUTO_TEST_CASE(function_overrides_modifier) -{ - char const* text = R"( - contract A { function mod(uint a) public { } } - contract B is A { modifier mod(uint a) { _; } } - )"; - CHECK_ALLOW_MULTI(text, (vector<pair<Error::Type, string>>{ - {Error::Type::DeclarationError, "Identifier already declared"}, - {Error::Type::TypeError, "Override changes function to modifier"} - })); -} - -BOOST_AUTO_TEST_CASE(modifier_returns_value) -{ - char const* text = R"( - contract A { - function f(uint a) mod(2) public returns (uint r) { } - modifier mod(uint a) { _; return 7; } - } - )"; - CHECK_ERROR(text, TypeError, "Return arguments not allowed."); -} - BOOST_AUTO_TEST_CASE(state_variable_accessors) { char const* text = R"( @@ -4176,21 +4043,6 @@ BOOST_AUTO_TEST_CASE(conditional_with_all_types) CHECK_SUCCESS(text); } -BOOST_AUTO_TEST_CASE(constructor_call_invalid_arg_count) -{ - // This caused a segfault in an earlier version - char const* text = R"( - contract C { - function C(){} - } - contract D is C { - function D() C(5){} - } - )"; - - CHECK_ERROR(text, TypeError, "Wrong argument count for modifier invocation: 1 arguments given but expected 0."); -} - BOOST_AUTO_TEST_CASE(index_access_for_bytes) { char const* text = R"( @@ -5055,16 +4907,6 @@ BOOST_AUTO_TEST_CASE(no_warn_about_callcode_as_function) CHECK_SUCCESS_NO_WARNINGS(text); } -BOOST_AUTO_TEST_CASE(modifier_without_underscore) -{ - char const* text = R"( - contract test { - modifier m() {} - } - )"; - CHECK_ERROR(text, SyntaxError, "Modifier body does not contain '_'."); -} - BOOST_AUTO_TEST_CASE(payable_in_library) { char const* text = R"( @@ -5264,319 +5106,6 @@ BOOST_AUTO_TEST_CASE(using_directive_for_missing_selftype) CHECK_ERROR(text, TypeError, "Member \"b\" not found or not visible after argument-dependent lookup in bytes memory"); } -BOOST_AUTO_TEST_CASE(function_type) -{ - char const* text = R"( - contract C { - function f() public { - function(uint) returns (uint) x; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(function_type_parameter) -{ - char const* text = R"( - contract C { - function f(function(uint) external returns (uint) g) public returns (function(uint) external returns (uint)) { - return g; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(function_type_returned) -{ - char const* text = R"( - contract C { - function f() public returns (function(uint) external returns (uint) g) { - return g; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(private_function_type) -{ - char const* text = R"( - contract C { - function f() public { - function(uint) private returns (uint) x; - } - } - )"; - CHECK_ERROR(text, TypeError, "Invalid visibility, can only be \"external\" or \"internal\"."); -} - -BOOST_AUTO_TEST_CASE(public_function_type) -{ - char const* text = R"( - contract C { - function f() public { - function(uint) public returns (uint) x; - } - } - )"; - CHECK_ERROR(text, TypeError, "Invalid visibility, can only be \"external\" or \"internal\"."); -} - -BOOST_AUTO_TEST_CASE(payable_internal_function_type) -{ - char const* text = R"( - contract C { - function (uint) internal payable returns (uint) x; - } - )"; - CHECK_ERROR(text, TypeError, "Only external function types can be payable."); -} - -BOOST_AUTO_TEST_CASE(payable_internal_function_type_is_not_fatal) -{ - char const* text = R"( - contract C { - function (uint) internal payable returns (uint) x; - - function g() { - x = g; - } - } - )"; - CHECK_ERROR_ALLOW_MULTI(text, TypeError, (std::vector<std::string>{"Only external function types can be payable."})); -} - -BOOST_AUTO_TEST_CASE(call_value_on_non_payable_function_type) -{ - char const* text = R"( - contract C { - function (uint) external returns (uint) x; - function f() public { - x.value(2)(); - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"value\" not found or not visible after argument-dependent lookup in function (uint256) external returns (uint256) - did you forget the \"payable\" modifier?"); -} - -BOOST_AUTO_TEST_CASE(external_function_type_returning_internal) -{ - char const* text = R"( - contract C { - function() external returns (function () internal) x; - } - )"; - CHECK_ERROR(text, TypeError, "Internal type cannot be used for external function type."); -} - -BOOST_AUTO_TEST_CASE(external_function_type_taking_internal) -{ - char const* text = R"( - contract C { - function(function () internal) external x; - } - )"; - CHECK_ERROR(text, TypeError, "Internal type cannot be used for external function type."); -} - -BOOST_AUTO_TEST_CASE(call_value_on_payable_function_type) -{ - char const* text = R"( - contract C { - function (uint) external payable returns (uint) x; - function f() public { - x.value(2)(1); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(internal_function_as_external_parameter) -{ - // It should not be possible to give internal functions - // as parameters to external functions. - char const* text = R"( - contract C { - function f(function(uint) internal returns (uint) x) public { - } - } - )"; - CHECK_ERROR(text, TypeError, "Internal or recursive type is not allowed for public or external functions."); -} - -BOOST_AUTO_TEST_CASE(internal_function_returned_from_public_function) -{ - // It should not be possible to return internal functions from external functions. - char const* text = R"( - contract C { - function f() public returns (function(uint) internal returns (uint) x) { - } - } - )"; - CHECK_ERROR(text, TypeError, "Internal or recursive type is not allowed for public or external functions."); -} - -BOOST_AUTO_TEST_CASE(internal_function_as_external_parameter_in_library_internal) -{ - char const* text = R"( - library L { - function f(function(uint) internal returns (uint) x) internal { - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(internal_function_as_external_parameter_in_library_external) -{ - char const* text = R"( - library L { - function f(function(uint) internal returns (uint) x) public { - } - } - )"; - CHECK_ERROR(text, TypeError, "Internal or recursive type is not allowed for public or external functions."); -} - -BOOST_AUTO_TEST_CASE(function_type_arrays) -{ - char const* text = R"( - contract C { - function(uint) external returns (uint)[] public x; - function(uint) internal returns (uint)[10] y; - function f() public { - function(uint) returns (uint)[10] memory a; - function(uint) returns (uint)[10] storage b = y; - function(uint) external returns (uint)[] memory c; - c = new function(uint) external returns (uint)[](200); - a; b; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(delete_function_type) -{ - char const* text = R"( - contract C { - function(uint) external returns (uint) x; - function(uint) internal returns (uint) y; - function f() public { - delete x; - var a = y; - delete a; - delete y; - var c = f; - delete c; - function(uint) internal returns (uint) g; - delete g; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(delete_function_type_invalid) -{ - char const* text = R"( - contract C { - function f() public { - delete f; - } - } - )"; - CHECK_ERROR(text, TypeError, "Expression has to be an lvalue."); -} - -BOOST_AUTO_TEST_CASE(delete_external_function_type_invalid) -{ - char const* text = R"( - contract C { - function f() public { - delete this.f; - } - } - )"; - CHECK_ERROR(text, TypeError, "Expression has to be an lvalue."); -} - -BOOST_AUTO_TEST_CASE(external_function_to_function_type_calldata_parameter) -{ - // This is a test that checks that the type of the `bytes` parameter is - // correctly changed from its own type `bytes calldata` to `bytes memory` - // when converting to a function type. - char const* text = R"( - contract C { - function f(function(bytes memory) external g) public { } - function callback(bytes) external {} - function g() public { - f(this.callback); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(external_function_type_to_address) -{ - char const* text = R"( - contract C { - function f() public returns (address) { - return address(this.f); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(internal_function_type_to_address) -{ - char const* text = R"( - contract C { - function f() public returns (address) { - return address(f); - } - } - )"; - CHECK_ERROR(text, TypeError, "Explicit type conversion not allowed"); -} - -BOOST_AUTO_TEST_CASE(external_function_type_to_uint) -{ - char const* text = R"( - contract C { - function f() public returns (uint) { - return uint(this.f); - } - } - )"; - CHECK_ERROR(text, TypeError, "Explicit type conversion not allowed"); -} - -BOOST_AUTO_TEST_CASE(warn_function_type_parameters_with_names) -{ - char const* text = R"( - contract C { - function(uint a) f; - } - )"; - CHECK_WARNING(text, "Naming function type parameters is deprecated."); -} - -BOOST_AUTO_TEST_CASE(warn_function_type_return_parameters_with_names) -{ - char const* text = R"( - contract C { - function(uint) returns (bool ret) f; - } - )"; - CHECK_WARNING(text, "Naming function type return parameters is deprecated."); -} - BOOST_AUTO_TEST_CASE(shift_constant_left_negative_rvalue) { char const* text = R"( |