diff options
-rw-r--r-- | libsolidity/SolidityEndToEndTest.cpp | 45 | ||||
-rw-r--r-- | libsolidity/SolidityNameAndTypeResolution.cpp | 15 | ||||
-rw-r--r-- | libsolidity/solidityExecutionFramework.h | 6 |
3 files changed, 51 insertions, 15 deletions
diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 3ddb0552..ad217546 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -564,20 +564,6 @@ BOOST_AUTO_TEST_CASE(strings) BOOST_CHECK(callContractFunction("pipeThrough(bytes2,bool)", string("\0\x02", 2), true) == encodeArgs(string("\0\x2", 2), true)); } -BOOST_AUTO_TEST_CASE(empty_string_on_stack) -{ - char const* sourceCode = R"( - contract test { - function run() external returns(bytes2 ret) { - var y = ""; - ret = y; - } - } - )"; - compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("run()") == encodeArgs(byte(0x00))); -} - BOOST_AUTO_TEST_CASE(inc_dec_operators) { char const* sourceCode = R"( @@ -5001,6 +4987,37 @@ BOOST_AUTO_TEST_CASE(struct_named_constructor) BOOST_CHECK(callContractFunction("s()") == encodeArgs(u256(1), true)); } +BOOST_AUTO_TEST_CASE(literal_strings) +{ + char const* sourceCode = R"( + contract Test { + string public long; + string public medium; + string public short; + string public empty; + function f() returns (string) { + long = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; + medium = "01234567890123456789012345678901234567890123456789012345678901234567890123456789"; + short = "123"; + empty = ""; + return "Hello, World!"; + } + } + )"; + compileAndRun(sourceCode, 0, "Test"); + string longStr = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; + string medium = "01234567890123456789012345678901234567890123456789012345678901234567890123456789"; + string shortStr = "123"; + string hello = "Hello, World!"; + + BOOST_CHECK(callContractFunction("f()") == encodeDyn(hello)); + BOOST_CHECK(callContractFunction("long()") == encodeDyn(longStr)); + BOOST_CHECK(callContractFunction("medium()") == encodeDyn(medium)); + BOOST_CHECK(callContractFunction("short()") == encodeDyn(shortStr)); + BOOST_CHECK(callContractFunction("empty()") == encodeDyn(string())); +} + + BOOST_AUTO_TEST_SUITE_END() } diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index 50fcdbbe..1e40ee4f 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/libsolidity/SolidityNameAndTypeResolution.cpp @@ -283,7 +283,7 @@ BOOST_AUTO_TEST_CASE(large_string_literal) char const* text = "contract test {\n" " function f() { var x = \"123456789012345678901234567890123\"; }" "}\n"; - BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); + BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); } BOOST_AUTO_TEST_CASE(balance) @@ -2097,6 +2097,19 @@ BOOST_AUTO_TEST_CASE(struct_named_constructor) BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode)); } +BOOST_AUTO_TEST_CASE(literal_strings) +{ + char const* text = R"( + contract Foo { + function f() { + string memory long = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; + string memory short = "123"; + } + } + )"; + BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/libsolidity/solidityExecutionFramework.h b/libsolidity/solidityExecutionFramework.h index 200940a4..03a201c7 100644 --- a/libsolidity/solidityExecutionFramework.h +++ b/libsolidity/solidityExecutionFramework.h @@ -145,6 +145,12 @@ public: { return bytes(); } + //@todo might be extended in the future + template <class Arg> + static bytes encodeDyn(Arg const& _arg) + { + return encodeArgs(u256(0x20), u256(_arg.size()), _arg); + } private: template <class CppFunction, class... Args> |