diff options
author | chriseth <chris@ethereum.org> | 2017-07-12 21:44:27 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-07-20 05:13:42 +0800 |
commit | 72917c4f3513a73ae180767b854de8653be9a2f4 (patch) | |
tree | 667e1ab8943b068e6cfe961e1f0a9566a983aca4 /test/libsolidity | |
parent | 78769f3b39bccbfa02edec302a02377e8fa08a8d (diff) | |
download | dexon-solidity-72917c4f3513a73ae180767b854de8653be9a2f4.tar.gz dexon-solidity-72917c4f3513a73ae180767b854de8653be9a2f4.tar.zst dexon-solidity-72917c4f3513a73ae180767b854de8653be9a2f4.zip |
Cleanup fixed point type changes
Diffstat (limited to 'test/libsolidity')
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 154 |
1 files changed, 73 insertions, 81 deletions
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index d511ca02..4b29243a 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2290,6 +2290,9 @@ BOOST_AUTO_TEST_CASE(test_fromElementaryTypeName) BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 30, 0)) == *make_shared<FixedBytesType>(30)); BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 31, 0)) == *make_shared<FixedBytesType>(31)); BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 32, 0)) == *make_shared<FixedBytesType>(32)); + + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::Fixed, 0, 0)) == *make_shared<FixedPointType>(128, 19, FixedPointType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UFixed, 0, 0)) == *make_shared<FixedPointType>(128, 19, FixedPointType::Modifier::Unsigned)); } BOOST_AUTO_TEST_CASE(test_byte_is_alias_of_byte1) @@ -4033,7 +4036,7 @@ BOOST_AUTO_TEST_CASE(invalid_fixed_types_0x7_mxn) fixed0x7 a = .3; } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, DeclarationError, "Identifier not found"); } BOOST_AUTO_TEST_CASE(invalid_fixed_types_long_invalid_identifier) @@ -4043,7 +4046,7 @@ BOOST_AUTO_TEST_CASE(invalid_fixed_types_long_invalid_identifier) fixed99999999999999999999999999999999999999x7 b = 9.5; } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, DeclarationError, "Identifier not found"); } BOOST_AUTO_TEST_CASE(invalid_fixed_types_7x8_mxn) @@ -4053,7 +4056,7 @@ BOOST_AUTO_TEST_CASE(invalid_fixed_types_7x8_mxn) fixed7x8 c = 3.12345678; } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, DeclarationError, "Identifier not found"); } BOOST_AUTO_TEST_CASE(library_instances_cannot_be_used) @@ -4067,7 +4070,7 @@ BOOST_AUTO_TEST_CASE(library_instances_cannot_be_used) } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "Member \"l\" not found or not visible after argument-dependent lookup in library L"); } BOOST_AUTO_TEST_CASE(invalid_fixed_type_long) @@ -4079,7 +4082,7 @@ BOOST_AUTO_TEST_CASE(invalid_fixed_type_long) } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, DeclarationError, "Identifier not found"); } BOOST_AUTO_TEST_CASE(fixed_type_int_conversion) @@ -4087,8 +4090,8 @@ BOOST_AUTO_TEST_CASE(fixed_type_int_conversion) char const* text = R"( contract test { function f() { - uint128 a = 3; - int128 b = 4; + uint64 a = 3; + int64 b = 4; fixed c = b; ufixed d = a; c; d; @@ -4137,7 +4140,7 @@ BOOST_AUTO_TEST_CASE(invalid_int_implicit_conversion_from_fixed) } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "Type fixed128x19 is not implicitly convertible to expected type int256"); } BOOST_AUTO_TEST_CASE(rational_unary_operation) @@ -4145,12 +4148,23 @@ BOOST_AUTO_TEST_CASE(rational_unary_operation) char const* text = R"( contract test { function f() { + ufixed16x2 a = 3.25; + fixed16x2 b = -3.25; + a; b; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); + text = R"( + contract test { + function f() { ufixed16x2 a = +3.25; fixed16x2 b = -3.25; + a; b; } } )"; - CHECK_WARNING(text,"Use of unary + is deprecated"); + CHECK_WARNING(text, "Use of unary + is deprecated"); text = R"( contract test { function f(uint x) { @@ -4167,10 +4181,11 @@ BOOST_AUTO_TEST_CASE(leading_zero_rationals_convert) char const* text = R"( contract A { function f() { - ufixed16x8 a = 0.5; - ufixed256x56 b = 0.0000000000000006661338147750939242541790008544921875; - fixed16x8 c = -0.5; - fixed256x56 d = -0.0000000000000006661338147750939242541790008544921875; + ufixed16x2 a = 0.5; + ufixed256x52 b = 0.0000000000000006661338147750939242541790008544921875; + fixed16x2 c = -0.5; + fixed256x52 d = -0.0000000000000006661338147750939242541790008544921875; + a; b; c; d; } } )"; @@ -4188,6 +4203,7 @@ BOOST_AUTO_TEST_CASE(size_capabilities_of_fixed_point_types) fixed256x1 d = -123456781234567979695948382928485849359686494864095409282048094275023098123.5; fixed256x76 e = -0.93322335481643744342575580035176794825198893968114429702091846411734101080123; fixed256x79 g = -0.0001178860664374434257558003517679482519889396811442970209184641173410108012309; + a; b; c; d; e; g; } } )"; @@ -4199,8 +4215,8 @@ BOOST_AUTO_TEST_CASE(zero_handling) char const* text = R"( contract test { function f() { - fixed16x8 a = 0; - ufixed8x8 b = 0; + fixed16x2 a = 0; a; + ufixed32x1 b = 0; b; } } )"; @@ -4213,11 +4229,11 @@ BOOST_AUTO_TEST_CASE(fixed_type_invalid_implicit_conversion_size) contract test { function f() { ufixed a = 11/4; - ufixed248x8 b = a; + ufixed248x8 b = a; b; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "Type ufixed128x19 is not implicitly convertible to expected type ufixed248x8"); } BOOST_AUTO_TEST_CASE(fixed_type_invalid_implicit_conversion_lost_data) @@ -4225,11 +4241,11 @@ BOOST_AUTO_TEST_CASE(fixed_type_invalid_implicit_conversion_lost_data) char const* text = R"( contract test { function f() { - ufixed256x1 a = 1/3; + ufixed256x1 a = 1/3; a; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "is not implicitly convertible to expected type ufixed256x1"); } BOOST_AUTO_TEST_CASE(fixed_type_valid_explicit_conversions) @@ -4237,9 +4253,9 @@ BOOST_AUTO_TEST_CASE(fixed_type_valid_explicit_conversions) char const* text = R"( contract test { function f() { - ufixed256x80 a = ufixed256x80(1/3); - ufixed248x80 b = ufixed248x80(1/3); - ufixed8x1 c = ufixed8x1(1/3); + ufixed256x80 a = ufixed256x80(1/3); a; + ufixed248x80 b = ufixed248x80(1/3); b; + ufixed8x1 c = ufixed8x1(1/3); c; } } )"; @@ -4251,11 +4267,11 @@ BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_rational) char const* text = R"( contract test { function f() { - uint[3.5] a; + uint[3.5] a; a; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal"); } BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_signed_fixed_type) @@ -4263,11 +4279,11 @@ BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_signed_fixed_type) char const* text = R"( contract test { function f() { - uint[fixed(3.5)] a; + uint[fixed(3.5)] a; a; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal"); } BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_unsigned_fixed_type) @@ -4275,11 +4291,11 @@ BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_unsigned_fixed_type) char const* text = R"( contract test { function f() { - uint[ufixed(3.5)] a; + uint[ufixed(3.5)] a; a; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal"); } BOOST_AUTO_TEST_CASE(rational_to_bytes_implicit_conversion) @@ -4287,11 +4303,11 @@ BOOST_AUTO_TEST_CASE(rational_to_bytes_implicit_conversion) char const* text = R"( contract test { function f() { - bytes32 c = 3.2; + bytes32 c = 3.2; c; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "is not implicitly convertible to expected type bytes32"); } BOOST_AUTO_TEST_CASE(fixed_to_bytes_implicit_conversion) @@ -4300,11 +4316,11 @@ BOOST_AUTO_TEST_CASE(fixed_to_bytes_implicit_conversion) contract test { function f() { fixed a = 3.25; - bytes32 c = a; + bytes32 c = a; c; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "fixed128x19 is not implicitly convertible to expected type bytes32"); } BOOST_AUTO_TEST_CASE(mapping_with_fixed_literal) @@ -4351,7 +4367,7 @@ BOOST_AUTO_TEST_CASE(inline_array_rationals) char const* text = R"( contract test { function f() { - ufixed16x3[4] memory a = [3.5, 4.125, 2.5, 4.0]; + ufixed128x3[4] memory a = [ufixed128x3(3.5), 4.125, 2.5, 4.0]; } } )"; @@ -4368,7 +4384,7 @@ BOOST_AUTO_TEST_CASE(rational_index_access) } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "rational_const 1/2 is not implicitly convertible to expected type uint256"); } BOOST_AUTO_TEST_CASE(rational_to_fixed_literal_expression) @@ -4376,9 +4392,9 @@ BOOST_AUTO_TEST_CASE(rational_to_fixed_literal_expression) char const* text = R"( contract test { function f() { - ufixed8x8 a = 3.5 * 3; - ufixed8x8 b = 4 - 2.5; - ufixed16x8 c = 11 / 4; + ufixed64x8 a = 3.5 * 3; + ufixed64x8 b = 4 - 2.5; + ufixed64x8 c = 11 / 4; ufixed240x5 d = 599 + 0.21875; ufixed256x80 e = ufixed256x80(35.245 % 12.9); ufixed256x80 f = ufixed256x80(1.2 % 2); @@ -4399,7 +4415,7 @@ BOOST_AUTO_TEST_CASE(rational_as_exponent_value_signed) } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(rational_as_exponent_value_unsigned) @@ -4411,7 +4427,7 @@ BOOST_AUTO_TEST_CASE(rational_as_exponent_value_unsigned) } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(rational_as_exponent_half) @@ -4419,11 +4435,11 @@ BOOST_AUTO_TEST_CASE(rational_as_exponent_half) char const* text = R"( contract test { function f() { - ufixed24x24 b = 2 ** (1/2); + 2 ** (1/2); } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(rational_as_exponent_value_neg_quarter) @@ -4431,11 +4447,11 @@ BOOST_AUTO_TEST_CASE(rational_as_exponent_value_neg_quarter) char const* text = R"( contract test { function f() { - fixed40x40 c = 42 ** (-1/4); + 42 ** (-1/4); } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents_15) @@ -4443,23 +4459,11 @@ BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents_15) char const* text = R"( contract test { function f() { - ufixed a = 3 ** ufixed(1.5); - } - } - )"; - BOOST_CHECK(!success(text)); -} - -BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents_half) -{ - char const* text = R"( - contract test { - function f() { - ufixed b = 2 ** ufixed(1/2); + var a = 3 ** ufixed(1.5); } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents_neg) @@ -4467,23 +4471,11 @@ BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents_neg) char const* text = R"( contract test { function f() { - fixed c = 42 ** fixed(-1/4); - } - } - )"; - BOOST_CHECK(!success(text)); -} - -BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents_neg_decimal) -{ - char const* text = R"( - contract test { - function f() { - fixed d = 16 ** fixed(-0.5); + var c = 42 ** fixed(-1/4); } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(var_capable_of_holding_constant_rationals) @@ -4531,11 +4523,11 @@ BOOST_AUTO_TEST_CASE(rational_bitnot_unary_operation) char const* text = R"( contract test { function f() { - fixed a = ~3.5; + ~fixed(3.5); } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "cannot be applied"); } BOOST_AUTO_TEST_CASE(rational_bitor_binary_operation) @@ -4543,11 +4535,11 @@ BOOST_AUTO_TEST_CASE(rational_bitor_binary_operation) char const* text = R"( contract test { function f() { - fixed a = 1.5 | 3; + fixed(1.5) | 3; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(rational_bitxor_binary_operation) @@ -4555,11 +4547,11 @@ BOOST_AUTO_TEST_CASE(rational_bitxor_binary_operation) char const* text = R"( contract test { function f() { - fixed a = 1.75 ^ 3; + fixed(1.75) ^ 3; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(rational_bitand_binary_operation) @@ -4567,11 +4559,11 @@ BOOST_AUTO_TEST_CASE(rational_bitand_binary_operation) char const* text = R"( contract test { function f() { - fixed a = 1.75 & 3; + fixed(1.75) & 3; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(missing_bool_conversion) @@ -4591,7 +4583,7 @@ BOOST_AUTO_TEST_CASE(integer_and_fixed_interaction) char const* text = R"( contract test { function f() { - ufixed a = uint128(1) + ufixed(2); + ufixed a = uint64(1) + ufixed(2); } } )"; @@ -4621,7 +4613,7 @@ BOOST_AUTO_TEST_CASE(one_divided_by_three_integer_conversion) } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "is not implicitly convertible to expected type uint256. Try converting to type ufixed256x77"); } BOOST_AUTO_TEST_CASE(unused_return_value) |