aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCJentzsch <jentzsch.software@gmail.com>2015-07-10 07:29:26 +0800
committerCJentzsch <jentzsch.software@gmail.com>2015-07-10 07:29:26 +0800
commit5d62ff11907e700d7b93f59a7eafe3defa39adc1 (patch)
treee69da94a54b12140fa249ca7aa8c7d2302b1ce63
parent8d6aa3bd509c54fad2e0f96588d468c9d4c93a7b (diff)
parent2173ad25a92156be73c8ef91e0fff285eb4d5c4d (diff)
downloaddexon-solidity-5d62ff11907e700d7b93f59a7eafe3defa39adc1.tar.gz
dexon-solidity-5d62ff11907e700d7b93f59a7eafe3defa39adc1.tar.zst
dexon-solidity-5d62ff11907e700d7b93f59a7eafe3defa39adc1.zip
Merge remote-tracking branch 'upstream/develop' into walletTestsUpdate
-rw-r--r--libsolidity/SolidityEndToEndTest.cpp45
-rw-r--r--libsolidity/SolidityNameAndTypeResolution.cpp15
-rw-r--r--libsolidity/solidityExecutionFramework.h6
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>