aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-04-16 19:10:50 +0800
committerGitHub <noreply@github.com>2018-04-16 19:10:50 +0800
commit533d08517f37496295e213194b489cd6ed15432b (patch)
tree936f79a7f70bd3b970a86463106ac87808bf8721 /test/libsolidity
parent8be19ad72bbdd7c934003c7d338f5511b6786921 (diff)
parent33fbf88707e69362bd5b6336860827a7b4d74440 (diff)
downloaddexon-solidity-533d08517f37496295e213194b489cd6ed15432b.tar.gz
dexon-solidity-533d08517f37496295e213194b489cd6ed15432b.tar.zst
dexon-solidity-533d08517f37496295e213194b489cd6ed15432b.zip
Merge pull request #3793 from ethereum/rationalNumberLimit
Rational number limit
Diffstat (limited to 'test/libsolidity')
-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.