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/syntaxTests/types/rational_number_array_index_limit.sol5
-rw-r--r--test/libsolidity/syntaxTests/types/rational_number_bitshift_limit.sol13
-rw-r--r--test/libsolidity/syntaxTests/types/rational_number_div_limit.sol9
-rw-r--r--test/libsolidity/syntaxTests/types/rational_number_exp_limit.sol50
-rw-r--r--test/libsolidity/syntaxTests/types/rational_number_literal_limit_1.sol9
-rw-r--r--test/libsolidity/syntaxTests/types/rational_number_literal_limit_2.sol9
-rw-r--r--test/libsolidity/syntaxTests/types/rational_number_literal_limit_3.sol9
-rw-r--r--test/libsolidity/syntaxTests/types/rational_number_mul_limit.sol9
9 files changed, 136 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index cbeca215..8440449c 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -102,6 +102,29 @@ BOOST_AUTO_TEST_CASE(exp_operator_const_signed)
ABI_CHECK(callContractFunction("f()", bytes()), toBigEndian(u256(-8)));
}
+BOOST_AUTO_TEST_CASE(exp_zero)
+{
+ char const* sourceCode = R"(
+ contract test {
+ function f(uint a) returns(uint d) { return a ** 0; }
+ }
+ )";
+ compileAndRun(sourceCode);
+ testContractAgainstCppOnRange("f(uint256)", [](u256 const&) -> u256 { return u256(1); }, 0, 16);
+}
+
+BOOST_AUTO_TEST_CASE(exp_zero_literal)
+{
+ char const* sourceCode = R"(
+ contract test {
+ function f() returns(uint d) { return 0 ** 0; }
+ }
+ )";
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("f()", bytes()), toBigEndian(u256(1)));
+}
+
+
BOOST_AUTO_TEST_CASE(conditional_expression_true_literal)
{
char const* sourceCode = R"(
diff --git a/test/libsolidity/syntaxTests/types/rational_number_array_index_limit.sol b/test/libsolidity/syntaxTests/types/rational_number_array_index_limit.sol
new file mode 100644
index 00000000..45ede998
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/rational_number_array_index_limit.sol
@@ -0,0 +1,5 @@
+contract c {
+ uint[2**253] data;
+}
+// ----
+// Warning: (17-34): Variable covers a large part of storage and thus makes collisions likely. Either use mappings or dynamic arrays and allow their size to be increased only in small quantities per transaction.
diff --git a/test/libsolidity/syntaxTests/types/rational_number_bitshift_limit.sol b/test/libsolidity/syntaxTests/types/rational_number_bitshift_limit.sol
new file mode 100644
index 00000000..94981aa0
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/rational_number_bitshift_limit.sol
@@ -0,0 +1,13 @@
+contract c {
+ function f() public pure {
+ int a;
+ a = 1 << 4095; // shift is fine, but result too large
+ a = 1 << 4096; // too large
+ a = (1E1233) << 2; // too large
+ }
+}
+// ----
+// TypeError: (71-80): Type int_const 5221...(1225 digits omitted)...5168 is not implicitly convertible to expected type int256.
+// TypeError: (133-142): Operator << not compatible with types int_const 1 and int_const 4096
+// TypeError: (169-182): Operator << not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const 2
+// TypeError: (169-182): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256.
diff --git a/test/libsolidity/syntaxTests/types/rational_number_div_limit.sol b/test/libsolidity/syntaxTests/types/rational_number_div_limit.sol
new file mode 100644
index 00000000..1b0b5f94
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/rational_number_div_limit.sol
@@ -0,0 +1,9 @@
+contract c {
+ function f() public pure {
+ int a;
+ a = 1/(2<<4094)/(2<<4094);
+ }
+}
+// ----
+// TypeError: (71-92): Operator / not compatible with types rational_const 1 / 5221...(1225 digits omitted)...5168 and int_const 5221...(1225 digits omitted)...5168
+// TypeError: (71-92): Type rational_const 1 / 5221...(1225 digits omitted)...5168 is not implicitly convertible to expected type int256. Try converting to type ufixed8x80 or use an explicit conversion.
diff --git a/test/libsolidity/syntaxTests/types/rational_number_exp_limit.sol b/test/libsolidity/syntaxTests/types/rational_number_exp_limit.sol
new file mode 100644
index 00000000..6785f580
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/rational_number_exp_limit.sol
@@ -0,0 +1,50 @@
+contract c {
+ function f() public pure {
+ int a;
+ a = 4 ** 4 ** 2 ** 4 ** 4 ** 4 ** 4;
+ a = -4 ** 4 ** 2 ** 4 ** 4 ** 4 ** 4 ** 4;
+ a = 4 ** (-(2 ** 4 ** 4 ** 4 ** 4 ** 4));
+ a = 0 ** 1E1233; // fine
+ a = 1 ** 1E1233; // fine
+ a = -1 ** 1E1233; // fine
+ a = 2 ** 1E1233;
+ a = -2 ** 1E1233;
+ a = 2 ** -1E1233;
+ a = -2 ** -1E1233;
+ a = 1E1233 ** 2;
+ a = -1E1233 ** 2;
+ a = 1E1233 ** -2;
+ a = -1E1233 ** -2;
+ a = 1E1233 ** 1E1233;
+ a = 1E1233 ** -1E1233;
+ a = -1E1233 ** 1E1233;
+ a = -1E1233 ** -1E1233;
+ }
+}
+// ----
+// TypeError: (71-102): Operator ** not compatible with types int_const 1797...(301 digits omitted)...7216 and int_const 4
+// TypeError: (71-102): Type int_const 1797...(301 digits omitted)...7216 is not implicitly convertible to expected type int256.
+// TypeError: (116-148): Operator ** not compatible with types int_const 1797...(301 digits omitted)...7216 and int_const 4
+// TypeError: (116-153): Operator ** not compatible with types int_const 1797...(301 digits omitted)...7216 and int_const 4
+// TypeError: (116-153): Type int_const 1797...(301 digits omitted)...7216 is not implicitly convertible to expected type int256.
+// TypeError: (167-203): Operator ** not compatible with types int_const 4 and int_const -179...(302 digits omitted)...7216
+// TypeError: (317-328): Operator ** not compatible with types int_const 2 and int_const 1000...(1226 digits omitted)...0000
+// TypeError: (342-354): Operator ** not compatible with types int_const -2 and int_const 1000...(1226 digits omitted)...0000
+// TypeError: (368-380): Operator ** not compatible with types int_const 2 and int_const -100...(1227 digits omitted)...0000
+// TypeError: (394-407): Operator ** not compatible with types int_const -2 and int_const -100...(1227 digits omitted)...0000
+// TypeError: (421-432): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const 2
+// TypeError: (421-432): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256.
+// TypeError: (446-458): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const 2
+// TypeError: (446-458): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256.
+// TypeError: (472-484): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const -2
+// TypeError: (472-484): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256.
+// TypeError: (498-511): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const -2
+// TypeError: (498-511): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256.
+// TypeError: (525-541): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const 1000...(1226 digits omitted)...0000
+// TypeError: (525-541): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256.
+// TypeError: (555-572): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const -100...(1227 digits omitted)...0000
+// TypeError: (555-572): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256.
+// TypeError: (586-603): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const 1000...(1226 digits omitted)...0000
+// TypeError: (586-603): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256.
+// TypeError: (617-635): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const -100...(1227 digits omitted)...0000
+// TypeError: (617-635): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256.
diff --git a/test/libsolidity/syntaxTests/types/rational_number_literal_limit_1.sol b/test/libsolidity/syntaxTests/types/rational_number_literal_limit_1.sol
new file mode 100644
index 00000000..233857a3
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/rational_number_literal_limit_1.sol
@@ -0,0 +1,9 @@
+contract c {
+ function bignum() public {
+ uint256 a;
+ a = 1e1233 / 1e1233; // 1e1233 is still fine
+ a = 1e1234; // 1e1234 is too big
+ }
+}
+// ----
+// TypeError: (128-134): Invalid literal value.
diff --git a/test/libsolidity/syntaxTests/types/rational_number_literal_limit_2.sol b/test/libsolidity/syntaxTests/types/rational_number_literal_limit_2.sol
new file mode 100644
index 00000000..16673924
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/rational_number_literal_limit_2.sol
@@ -0,0 +1,9 @@
+contract c {
+ function bignum() public {
+ uint a;
+ a = 134562324532464234452335168163516E1200 / 134562324532464234452335168163516E1200; // still fine
+ a = 1345623245324642344523351681635168E1200; // too large
+ }
+}
+// ----
+// TypeError: (179-218): Invalid literal value.
diff --git a/test/libsolidity/syntaxTests/types/rational_number_literal_limit_3.sol b/test/libsolidity/syntaxTests/types/rational_number_literal_limit_3.sol
new file mode 100644
index 00000000..5a696171
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/rational_number_literal_limit_3.sol
@@ -0,0 +1,9 @@
+contract c {
+ function bignum() public {
+ uint a;
+ a = 134562324532464.234452335168163517E1200 / 134562324532464.234452335168163517E1200; // still fine
+ a = 134562324532464.2344523351681635177E1200; // too large
+ }
+}
+// ----
+// TypeError: (181-221): Invalid literal value.
diff --git a/test/libsolidity/syntaxTests/types/rational_number_mul_limit.sol b/test/libsolidity/syntaxTests/types/rational_number_mul_limit.sol
new file mode 100644
index 00000000..bbed94b5
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/rational_number_mul_limit.sol
@@ -0,0 +1,9 @@
+contract c {
+ function f() public pure {
+ int a;
+ a = (1<<4095)*(1<<4095);
+ }
+}
+// ----
+// TypeError: (71-90): Operator * not compatible with types int_const 5221...(1225 digits omitted)...5168 and int_const 5221...(1225 digits omitted)...5168
+// TypeError: (71-90): Type int_const 5221...(1225 digits omitted)...5168 is not implicitly convertible to expected type int256.