From 46eb7b08d9fe52f73895bae46648a79cea15c64e Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 8 Jun 2015 11:47:57 +0200 Subject: [PATCH 1/3] added test Conflicts: test/libsolidity/SolidityEndToEndTest.cpp --- libsolidity/SolidityEndToEndTest.cpp | 51 ++++++++++++++++++---------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 89ed81e23..04ad40d75 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -567,7 +567,7 @@ BOOST_AUTO_TEST_CASE(strings) BOOST_AUTO_TEST_CASE(empty_string_on_stack) { char const* sourceCode = "contract test {\n" - " function run(bytes0 empty, uint8 inp) returns(uint16 a, bytes0 b, bytes4 c) {\n" + " function run(string empty, uint8 inp) external returns(uint16 a, string b, bytes4 c) {\n" " var x = \"abc\";\n" " var y = \"\";\n" " var z = inp;\n" @@ -3786,25 +3786,25 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_delete) BOOST_CHECK(m_state.storage(m_contractAddress).empty()); } -BOOST_AUTO_TEST_CASE(packed_storage_structs_with_bytes0) +BOOST_AUTO_TEST_CASE(packed_storage_structs_with_empty_string) { char const* sourceCode = R"( - contract C { - struct str { uint8 a; bytes0 b; uint8 c; } - uint8 a; - bytes0 x; - uint8 b; - str data; - function test() returns (bool) { - a = 2; - b = 3; - data.a = 4; - data.c = 5; - delete x; - delete data.b; - return a == 2 && b == 3 && data.a == 4 && data.c == 5; - } + contract C { + struct str { uint8 a; string b; uint8 c; } + uint8 a; + uint8 b; + str data; + function test() returns (bool) { + a = 2; + b = 3; + var x = ""; + data.a = 4; + data.c = 5; + delete x; + delete data.b; + return a == 2 && b == 3 && data.a == 4 && data.c == 5; } + } )"; compileAndRun(sourceCode); BOOST_CHECK(callContractFunction("test()") == encodeArgs(true)); @@ -4172,6 +4172,23 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) BOOST_CHECK(compileAndRunWthoutCheck(sourceCode, 0, "A").empty()); } +BOOST_AUTO_TEST_CASE(empty_string) +{ + char const* sourceCode = R"( + contract Foo { + var sEmpty = ""; + string sStateVar = "text"; + function Foo() + { + var sLocal = ""; + sEmpty = sLocal; + sLocal = s; + } + } + )"; + compileAndRun(sourceCode, 0, "Foo"); +} + BOOST_AUTO_TEST_CASE(positive_integers_to_signed) { char const* sourceCode = R"( From 1ac5f3c04d3df03df4ae2997c1a2ea0ced9f1311 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 8 Jun 2015 13:08:22 +0200 Subject: [PATCH 2/3] removed byte0 keyword --- libsolidity/SolidityEndToEndTest.cpp | 31 ------------------- libsolidity/SolidityNameAndTypeResolution.cpp | 3 +- 2 files changed, 1 insertion(+), 33 deletions(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 04ad40d75..a2c5556d1 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 = "contract test {\n" - " function run(string empty, uint8 inp) external returns(uint16 a, string b, bytes4 c) {\n" - " var x = \"abc\";\n" - " var y = \"\";\n" - " var z = inp;\n" - " a = z; b = y; c = x;" - " }\n" - "}\n"; - compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("run(bytes0,uint8)", string(), byte(0x02)) == encodeArgs(0x2, string(""), string("abc\0"))); -} - BOOST_AUTO_TEST_CASE(inc_dec_operators) { char const* sourceCode = R"( @@ -4172,23 +4158,6 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) BOOST_CHECK(compileAndRunWthoutCheck(sourceCode, 0, "A").empty()); } -BOOST_AUTO_TEST_CASE(empty_string) -{ - char const* sourceCode = R"( - contract Foo { - var sEmpty = ""; - string sStateVar = "text"; - function Foo() - { - var sLocal = ""; - sEmpty = sLocal; - sLocal = s; - } - } - )"; - compileAndRun(sourceCode, 0, "Foo"); -} - BOOST_AUTO_TEST_CASE(positive_integers_to_signed) { char const* sourceCode = R"( diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index 73bbcb162..ca89f42bc 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1579,7 +1579,6 @@ BOOST_AUTO_TEST_CASE(test_fromElementaryTypeName) BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt256) == *make_shared(256, IntegerType::Modifier::Unsigned)); BOOST_CHECK(*Type::fromElementaryTypeName(Token::Byte) == *make_shared(1)); - BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes0) == *make_shared(0)); BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes1) == *make_shared(1)); BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes2) == *make_shared(2)); BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes3) == *make_shared(3)); @@ -1673,7 +1672,7 @@ BOOST_AUTO_TEST_CASE(bytes0_array) bytes0[] illegalArray; } )"; - BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); + BOOST_CHECK_THROW(parseTextAndResolveNames(text), DeclarationError); } BOOST_AUTO_TEST_CASE(overloaded_function_cannot_resolve) From 4967535f8a9b46edfa029793e9d38125afd886cf Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Tue, 9 Jun 2015 11:55:19 +0200 Subject: [PATCH 3/3] cleaned up the tests --- libsolidity/SolidityEndToEndTest.cpp | 38 +++++++------------ libsolidity/SolidityNameAndTypeResolution.cpp | 10 ----- 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index a2c5556d1..fdd865e74 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -564,6 +564,20 @@ 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"( @@ -3772,30 +3786,6 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_delete) BOOST_CHECK(m_state.storage(m_contractAddress).empty()); } -BOOST_AUTO_TEST_CASE(packed_storage_structs_with_empty_string) -{ - char const* sourceCode = R"( - contract C { - struct str { uint8 a; string b; uint8 c; } - uint8 a; - uint8 b; - str data; - function test() returns (bool) { - a = 2; - b = 3; - var x = ""; - data.a = 4; - data.c = 5; - delete x; - delete data.b; - return a == 2 && b == 3 && data.a == 4 && data.c == 5; - } - } - )"; - compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("test()") == encodeArgs(true)); -} - BOOST_AUTO_TEST_CASE(overloaded_function_call_resolve_to_first) { char const* sourceCode = R"( diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index ca89f42bc..b078fe6a2 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1665,16 +1665,6 @@ BOOST_AUTO_TEST_CASE(local_const_variable) BOOST_CHECK_THROW(parseTextAndResolveNames(text), ParserError); } -BOOST_AUTO_TEST_CASE(bytes0_array) -{ - char const* text = R"( - contract Foo { - bytes0[] illegalArray; - } - )"; - BOOST_CHECK_THROW(parseTextAndResolveNames(text), DeclarationError); -} - BOOST_AUTO_TEST_CASE(overloaded_function_cannot_resolve) { char const* sourceCode = R"(