diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-09-19 14:42:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-19 14:42:32 +0800 |
commit | 1fc71bd75841850ee04d151e9bfbf938928b276a (patch) | |
tree | 5eddbf47309bf3de25d7150b845dd353691e022e /test/libsolidity | |
parent | 3a9a9db6d688f3a1ef3bbcb0a378bbd14779abde (diff) | |
parent | ada68bcee66690f3511db14306d6bdff6e1f7dc5 (diff) | |
download | dexon-solidity-1fc71bd75841850ee04d151e9bfbf938928b276a.tar.gz dexon-solidity-1fc71bd75841850ee04d151e9bfbf938928b276a.tar.zst dexon-solidity-1fc71bd75841850ee04d151e9bfbf938928b276a.zip |
Merge pull request #2920 from ethereum/fixConstantBytes
Allow constant byte arrays.
Diffstat (limited to 'test/libsolidity')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 24 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 12 |
2 files changed, 36 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index f885b0d3..bdac8278 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -10076,6 +10076,30 @@ BOOST_AUTO_TEST_CASE(function_types_sig) BOOST_CHECK(callContractFunction("h()") == encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes()))); } +BOOST_AUTO_TEST_CASE(constant_string) +{ + char const* sourceCode = R"( + contract C { + bytes constant a = "\x03\x01\x02"; + bytes constant b = hex"030102"; + string constant c = "hello"; + function f() returns (bytes) { + return a; + } + function g() returns (bytes) { + return b; + } + function h() returns (bytes) { + return bytes(c); + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f()") == encodeDyn(string("\x03\x01\x02"))); + BOOST_CHECK(callContractFunction("g()") == encodeDyn(string("\x03\x01\x02"))); + BOOST_CHECK(callContractFunction("h()") == encodeDyn(string("hello"))); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 85acd8bf..2ca3a562 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2385,6 +2385,18 @@ BOOST_AUTO_TEST_CASE(assignment_to_const_array_vars) CHECK_ERROR(text, TypeError, "implemented"); } +BOOST_AUTO_TEST_CASE(assignment_to_const_string_bytes) +{ + char const* text = R"( + contract C { + bytes constant a = "\x00\x01\x02"; + bytes constant b = hex"000102"; + string constant c = "hello"; + } + )"; + CHECK_SUCCESS(text); +} + BOOST_AUTO_TEST_CASE(constant_struct) { char const* text = R"( |