aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2017-03-01 23:34:29 +0800
committerchriseth <c@ethdev.com>2017-03-13 20:29:51 +0800
commitbde913f088c873cba75db30b2d463f50f9dfe862 (patch)
tree3023583c6feac767e0972e65eb5d2b59b9e4a282
parentef8b56a05823e39ffc2577af653200f22d6b15a1 (diff)
downloaddexon-solidity-bde913f088c873cba75db30b2d463f50f9dfe862.tar.gz
dexon-solidity-bde913f088c873cba75db30b2d463f50f9dfe862.tar.zst
dexon-solidity-bde913f088c873cba75db30b2d463f50f9dfe862.zip
Some new tests for constant variables.
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 865fd0c5..aef93e92 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -2173,6 +2173,56 @@ BOOST_AUTO_TEST_CASE(assigning_value_to_const_variable)
CHECK_ERROR(text, TypeError, "");
}
+BOOST_AUTO_TEST_CASE(assigning_state_to_const_variable)
+{
+ char const* text = R"(
+ contract C {
+ address constant x = msg.sender;
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Expression is not compile-time constant.");
+}
+
+BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_conversion)
+{
+ char const* text = R"(
+ contract C {
+ C constant x = C(0x123);
+ }
+ )";
+ CHECK_SUCCESS(text);
+}
+
+BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_expression)
+{
+ char const* text = R"(
+ contract C {
+ uint constant x = 0x123 + 9x456;
+ }
+ )";
+ CHECK_SUCCESS(text);
+}
+
+BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_keccak)
+{
+ char const* text = R"(
+ contract C {
+ bytes32 constant x = keccak("abc");
+ }
+ )";
+ CHECK_SUCCESS(text);
+}
+
+BOOST_AUTO_TEST_CASE(assignment_to_const_array_vars)
+{
+ char const* text = R"(
+ contract C {
+ uint[3] memory constant x = [1, 2, 3];
+ }
+ )";
+ CHECK_SUCCESS(text);
+}
+
BOOST_AUTO_TEST_CASE(complex_const_variable)
{
//for now constant specifier is valid only for uint bytesXX and enums