aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp23
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp437
-rw-r--r--test/libsolidity/SolidityParser.cpp46
3 files changed, 475 insertions, 31 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 9df64cdc..c3bac3d7 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -6631,6 +6631,29 @@ BOOST_AUTO_TEST_CASE(delete_on_array_of_structs)
// This code interprets x as an array length and thus will go out of gas.
// neither of the two should throw due to out-of-bounds access
BOOST_CHECK(callContractFunction("f()") == encodeArgs(true));
+
+}
+
+BOOST_AUTO_TEST_CASE(fixed_data_type)
+{
+ char const* sourceCode = R"(
+ contract C {
+ fixed public pi = 3.141592;
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+}
+
+BOOST_AUTO_TEST_CASE(fixed_data_type_expression)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f(fixed a) returns (fixed) {
+ return (a + 3);
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
}
BOOST_AUTO_TEST_CASE(internal_library_function)
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 9c411781..b3679305 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -1330,15 +1330,6 @@ BOOST_AUTO_TEST_CASE(overflow_caused_by_ether_units)
BOOST_CHECK(expectError(sourceCode) == Error::Type::TypeError);
}
-BOOST_AUTO_TEST_CASE(exp_operator_negative_exponent)
-{
- char const* sourceCode = R"(
- contract test {
- function f() returns(uint d) { return 2 ** -3; }
- })";
- BOOST_CHECK(expectError(sourceCode) == Error::Type::TypeError);
-}
-
BOOST_AUTO_TEST_CASE(exp_operator_exponent_too_big)
{
char const* sourceCode = R"(
@@ -2229,18 +2220,6 @@ BOOST_AUTO_TEST_CASE(literal_strings)
BOOST_CHECK(success(text));
}
-BOOST_AUTO_TEST_CASE(invalid_integer_literal_fraction)
-{
- char const* text = R"(
- contract Foo {
- function f() {
- var x = 1.20;
- }
- }
- )";
- BOOST_CHECK(expectError(text) == Error::Type::TypeError);
-}
-
BOOST_AUTO_TEST_CASE(invalid_integer_literal_exp)
{
char const* text = R"(
@@ -2792,8 +2771,8 @@ BOOST_AUTO_TEST_CASE(inline_array_declaration_and_passing_implicit_conversion)
uint8 x = 7;
uint16 y = 8;
uint32 z = 9;
- uint32[3] memory ending = [x, y, z];
- return (ending[1]);
+ uint32[3] memory ending = [x, y, z];
+ return (ending[1]);
}
}
)";
@@ -3230,27 +3209,45 @@ BOOST_AUTO_TEST_CASE(int10abc_is_identifier)
BOOST_CHECK(success(text));
}
-BOOST_AUTO_TEST_CASE(invalid_fixed_types)
+BOOST_AUTO_TEST_CASE(library_functions_do_not_have_value)
{
char const* text = R"(
+ library L { function l() {} }
contract test {
function f() {
- fixed0x7 a = .3;
- fixed99999999999999999999999999999999999999x7 b = 9.5;
+ L.l.value;
}
}
)";
BOOST_CHECK(!success(text));
}
-BOOST_AUTO_TEST_CASE(library_functions_do_not_have_value)
+
+BOOST_AUTO_TEST_CASE(invalid_fixed_types_0x7_mxn)
{
char const* text = R"(
- library L { function l() {} }
contract test {
- function f() {
- L.l.value;
- }
+ fixed0x7 a = .3;
+ }
+ )";
+ BOOST_CHECK(!success(text));
+}
+
+BOOST_AUTO_TEST_CASE(invalid_fixed_types_long_invalid_identifier)
+{
+ char const* text = R"(
+ contract test {
+ fixed99999999999999999999999999999999999999x7 b = 9.5;
+ }
+ )";
+ BOOST_CHECK(!success(text));
+}
+
+BOOST_AUTO_TEST_CASE(invalid_fixed_types_7x8_mxn)
+{
+ char const* text = R"(
+ contract test {
+ fixed7x8 c = 3.12345678;
}
)";
BOOST_CHECK(!success(text));
@@ -3282,6 +3279,384 @@ BOOST_AUTO_TEST_CASE(invalid_fixed_type_long)
BOOST_CHECK(!success(text));
}
+BOOST_AUTO_TEST_CASE(valid_fixed_types)
+{
+ char const* text = R"(
+ contract test {
+ function f(){
+ fixed8x8 a = 87654321.12345678;
+ fixed16x16 b = a**2;
+ fixed24x24 c = b**3;
+ fixed32x32 d = b**2;
+ fixed40x40 e = a**5;
+ }
+ }
+ )";
+
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(fixed_type_int_conversion)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ uint128 a = 3;
+ int128 b = 4;
+ fixed c = b;
+ ufixed d = a;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(fixed_type_const_int_conversion)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed c = 3;
+ ufixed d = 4;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(fixed_type_literal)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed a = 3.14;
+ ufixed d = 2.555555;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(fixed_type_literal_expression)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed a = 3.14 * 3;
+ ufixed b = 4 - 2.555555;
+ fixed c = 1.0 / 3.0;
+ ufixed d = 599 + .5367;
+ ufixed e = 35.245 % 12.9;
+ ufixed f = 1.2 % 2.00000;
+ fixed g = 2 ** -2;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(uint_array_declaration_with_fixed_type)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ uint[fixed(3.56)] a;
+ }
+ }
+ )";
+ BOOST_CHECK(!success(text));
+}
+
+
+BOOST_AUTO_TEST_CASE(array_declaration_with_fixed_literal)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ uint[3.56] a;
+ }
+ }
+ )";
+ BOOST_CHECK(!success(text));
+}
+
+BOOST_AUTO_TEST_CASE(mapping_with_fixed_literal)
+{
+ char const* text = R"(
+ contract test {
+ mapping(fixed => string) fixedString;
+ function f() {
+ fixedString[3.14] = "Pi";
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(inline_array_fixed_type)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed[3] memory a = [fixed(3.5), fixed(4.1234), fixed(967.32)];
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(inline_array_fixed_literals)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ ufixed8x16[3] memory a = [3.5, 4.1234, 2.5];
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(zero_and_eight_variants_fixed)
+{
+ char const* text = R"(
+ contract A {
+ fixed8x0 someInt = 4;
+ fixed0x8 half = 0.5;
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(size_capabilities_of_fixed_point_types)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ ufixed0x8 a = 0.12345678;
+ ufixed8x0 b = 12345678.0;
+ ufixed0x8 c = 0.00000009;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(var_capable_of_holding_constant_rationals)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ var a = 0.12345678;
+ var b = 12345678.0;
+ var c = 0.00000009;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(invalid_rational_exponent_usage)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed8x8 a = 3 ** 1.5;
+ fixed24x24 b = 2 ** (1/2);
+ fixed40x40 c = 42 ** (-1/4);
+ fixed48x48 d = 16 ** -0.33;
+ }
+ }
+ )";
+ BOOST_CHECK(!success(text));
+}
+
+BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed a = 3 ** fixed(1.5);
+ fixed b = 2 ** fixed(1/2);
+ fixed c = 42 ** fixed(-1/4);
+ fixed d = 16 ** fixed(-0.33);
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(rational_unary_operation)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed a = +3.5134;
+ fixed b = -2.5145;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(rational_bitnot_unary_operation)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed a = ~3.56;
+ }
+ }
+ )";
+ BOOST_CHECK(!success(text));
+}
+
+BOOST_AUTO_TEST_CASE(rational_bitor_binary_operation)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed a = 1.56 | 3;
+ }
+ }
+ )";
+ BOOST_CHECK(!success(text));
+}
+
+BOOST_AUTO_TEST_CASE(rational_bitxor_binary_operation)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed a = 1.56 ^ 3;
+ }
+ }
+ )";
+ BOOST_CHECK(!success(text));
+}
+
+BOOST_AUTO_TEST_CASE(rational_bitand_binary_operation)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed a = 1.56 & 3;
+ }
+ }
+ )";
+ BOOST_CHECK(!success(text));
+}
+
+BOOST_AUTO_TEST_CASE(fixed_type_int_conversion)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ uint128 a = 3;
+ int128 b = 4;
+ fixed c = b;
+ ufixed d = a;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(fixed_type_const_int_conversion)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed c = 3;
+ ufixed d = 4;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(fixed_type_literal)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed a = 3.14;
+ ufixed d = 2.555555;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(fixed_type_literal_expression)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed a = 3.14 * 3;
+ ufixed b = 4 - 2.555555;
+ fixed c = 1.0 / 3.0;
+ ufixed d = 599 + .5367;
+ ufixed e = 35.245 % 12.9;
+ ufixed g = 1.2 % 2.00000;
+ //ufixed f = 2.222 ** 3.333;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(fixed_type_literal_seconds_and_wei)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed a = 3.14 wei;
+ ufixed b = 4.5 seconds;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(array_declaration_with_fixed_literal)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ uint[3.56] a;
+ }
+ }
+ )";
+ BOOST_CHECK(!success(text));
+}
+
+BOOST_AUTO_TEST_CASE(inline_array_fixed_literals)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed[3] memory a = [3.5, 4.1234, 967.32];
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(size_capabilities_of_fixed_point_types)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed0x8 a = 0.12345678;
+ fixed8x0 b = 12345678.0;
+ fixed0x8 c = 0.00000009;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp
index e43b026c..909d18c9 100644
--- a/test/libsolidity/SolidityParser.cpp
+++ b/test/libsolidity/SolidityParser.cpp
@@ -1177,6 +1177,52 @@ BOOST_AUTO_TEST_CASE(conditional_with_assignment)
BOOST_CHECK(successParse(text));
}
+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(no_double_radix_in_fixed_literal)
+{
+ char const* text = R"(
+ contract A {
+ fixed40x40 pi = 3.14.15;
+ }
+ )";
+ BOOST_CHECK(!successParse(text));
+}
+
+BOOST_AUTO_TEST_CASE(invalid_fixed_conversion_leading_zeroes_check)
+{
+ char const* text = R"(
+ contract test {
+ function f() {
+ fixed a = 1.0x2;
+ }
+ }
+ )";
+ BOOST_CHECK(!successParse(text));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}