aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorYoichi Hirai <i@yoichihirai.com>2017-03-15 17:03:35 +0800
committerGitHub <noreply@github.com>2017-03-15 17:03:35 +0800
commitd134fda0c05640992941087139316d2b8fb3f816 (patch)
treea26d7b2f78f6c167af83216545219d4e892f8e13 /test/libsolidity/SolidityEndToEndTest.cpp
parent64e00e5371e2620a0bbd945d37e799e1e0309668 (diff)
parent9f328ff749477106a569e679e5eeed5c7e78d29d (diff)
downloaddexon-solidity-d134fda0c05640992941087139316d2b8fb3f816.tar.gz
dexon-solidity-d134fda0c05640992941087139316d2b8fb3f816.tar.zst
dexon-solidity-d134fda0c05640992941087139316d2b8fb3f816.zip
Merge pull request #1729 from ethereum/constantvariables
Only allow pure expressions for constant state variables.
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp53
1 files changed, 52 insertions, 1 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 2a286cea..a4fab721 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -4542,7 +4542,6 @@ BOOST_AUTO_TEST_CASE(simple_constant_variables_test)
BOOST_AUTO_TEST_CASE(constant_variables)
{
- //for now constant specifier is valid only for uint, bytesXX, string and enums
char const* sourceCode = R"(
contract Foo {
uint constant x = 56;
@@ -4553,6 +4552,58 @@ BOOST_AUTO_TEST_CASE(constant_variables)
compileAndRun(sourceCode);
}
+BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_expression)
+{
+ char const* sourceCode = R"(
+ contract C {
+ uint constant x = 0x123 + 0x456;
+ function f() returns (uint) { return x + 1; }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs(0x123 + 0x456 + 1));
+}
+
+BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_keccak)
+{
+ char const* sourceCode = R"(
+ contract C {
+ bytes32 constant x = keccak256("abc");
+ function f() returns (bytes32) { return x; }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs(dev::keccak256("abc")));
+}
+
+// Disabled until https://github.com/ethereum/solidity/issues/715 is implemented
+//BOOST_AUTO_TEST_CASE(assignment_to_const_array_vars)
+//{
+// char const* sourceCode = R"(
+// contract C {
+// uint[3] constant x = [uint(1), 2, 3];
+// uint constant y = x[0] + x[1] + x[2];
+// function f() returns (uint) { return y; }
+// }
+// )";
+// compileAndRun(sourceCode);
+// BOOST_CHECK(callContractFunction("f()") == encodeArgs(1 + 2 + 3));
+//}
+
+// Disabled until https://github.com/ethereum/solidity/issues/715 is implemented
+//BOOST_AUTO_TEST_CASE(constant_struct)
+//{
+// char const* sourceCode = R"(
+// contract C {
+// struct S { uint x; uint[] y; }
+// S constant x = S(5, new uint[](4));
+// function f() returns (uint) { return x.x; }
+// }
+// )";
+// compileAndRun(sourceCode);
+// BOOST_CHECK(callContractFunction("f()") == encodeArgs(5));
+//}
+
BOOST_AUTO_TEST_CASE(packed_storage_structs_uint)
{
char const* sourceCode = R"(