From d2332769d3e87b3500638591c23241ebd942fbb1 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 30 Sep 2015 17:21:15 +0200 Subject: Test for internal types. --- test/libsolidity/SolidityEndToEndTest.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 86caacb6..c40a027a 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5354,6 +5354,35 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_as_return_type) ); } +BOOST_AUTO_TEST_CASE(internal_types_in_library) +{ + char const* sourceCode = R"( + library Lib { + function find(uint16[] storage _haystack, uint16 _needle) constant returns (uint) + { + for (uint i = 0; i < _haystack.length; ++i) + if (_haystack[i] == _needle) + return i; + return uint(-1); + } + } + contract Test { + mapping(string => uint16[]) data; + function f() returns (uint a, uint b) + { + data["abc"].length = 20; + data["abc"][4] = 9; + data["abc"][17] = 3; + a = Lib.find(data["abc"], 9); + b = Lib.find(data["abc"], 3); + } + } + )"; + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(4), u256(17))); +} + BOOST_AUTO_TEST_CASE(short_strings) { // This test verifies that the byte array encoding that combines length and data works -- cgit From ce25ddfa6a9b8cfff08b4a05591dcc3b4a8b63cc Mon Sep 17 00:00:00 2001 From: chriseth Date: Sun, 4 Oct 2015 11:05:57 +0200 Subject: Encode storage items correctly for library calls. --- test/libsolidity/SolidityEndToEndTest.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index c40a027a..26185b41 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5383,6 +5383,32 @@ BOOST_AUTO_TEST_CASE(internal_types_in_library) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(4), u256(17))); } +BOOST_AUTO_TEST_CASE(differentiate_storage_and_memory_in_libraries) +{ + char const* sourceCode = R"( + library Lib { + function f(uint[] storage x) returns (uint) { return 1; } + function f(uint[] memory x) returns (uint) { return 2; } + } + contract Test { + uint[] data; + function f() returns (uint a,) + { + uint[] memory d = data; + Lib.f(d) + data["abc"].length = 20; + data["abc"][4] = 9; + data["abc"][17] = 3; + a = Lib.find(data["abc"], 9); + b = Lib.find(data["abc"], 3); + } + } + )"; + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(4), u256(17))); +} + BOOST_AUTO_TEST_CASE(short_strings) { // This test verifies that the byte array encoding that combines length and data works -- cgit From bc609c55c0fa622a68fa9718c55046416c201b1d Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 5 Oct 2015 17:19:23 +0200 Subject: Compute canonical names of types for function signatures. --- test/libsolidity/SolidityEndToEndTest.cpp | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 26185b41..c40a027a 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5383,32 +5383,6 @@ BOOST_AUTO_TEST_CASE(internal_types_in_library) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(4), u256(17))); } -BOOST_AUTO_TEST_CASE(differentiate_storage_and_memory_in_libraries) -{ - char const* sourceCode = R"( - library Lib { - function f(uint[] storage x) returns (uint) { return 1; } - function f(uint[] memory x) returns (uint) { return 2; } - } - contract Test { - uint[] data; - function f() returns (uint a,) - { - uint[] memory d = data; - Lib.f(d) - data["abc"].length = 20; - data["abc"][4] = 9; - data["abc"][17] = 3; - a = Lib.find(data["abc"], 9); - b = Lib.find(data["abc"], 3); - } - } - )"; - compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); - BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(4), u256(17))); -} - BOOST_AUTO_TEST_CASE(short_strings) { // This test verifies that the byte array encoding that combines length and data works -- cgit From bf5b387954f93371e2c8fc77c01cbc709f570954 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 6 Oct 2015 12:35:10 +0200 Subject: Provide access to scoped structs. --- test/libsolidity/SolidityEndToEndTest.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index c40a027a..b46b405d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5383,6 +5383,33 @@ BOOST_AUTO_TEST_CASE(internal_types_in_library) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(4), u256(17))); } +BOOST_AUTO_TEST_CASE(using_library_structs) +{ + char const* sourceCode = R"( + library Lib { + struct Data { uint a; uint[] b; } + function set(Data storage _s) + { + _s.a = 7; + _s.b.length = 20; + _s.b[19] = 8; + } + } + contract Test { + mapping(string => Lib.Data) data; + function f() returns (uint a, uint b) + { + Lib.set(data["abc"]); + a = data["abc"].a; + b = data["abc"].b[19]; + } + } + )"; + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(7), u256(8))); +} + BOOST_AUTO_TEST_CASE(short_strings) { // This test verifies that the byte array encoding that combines length and data works -- cgit From 99351aebe0c9ebbb06e34c18ecc19bc0c87d9d54 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 6 Oct 2015 14:13:07 +0200 Subject: Compiler version stamp. --- test/libsolidity/SolidityEndToEndTest.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index b46b405d..3cfe4975 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5539,6 +5539,17 @@ BOOST_AUTO_TEST_CASE(calldata_offset) BOOST_CHECK(callContractFunction("last()", encodeArgs()) == encodeDyn(string("nd"))); } +BOOST_AUTO_TEST_CASE(version_stamp_for_libraries) +{ + char const* sourceCode = "library lib {}"; + m_optimize = true; + bytes runtimeCode = compileAndRun(sourceCode, 0, "lib"); + BOOST_CHECK(runtimeCode.size() >= 8); + BOOST_CHECK_EQUAL(runtimeCode[0], int(eth::Instruction::PUSH6)); // might change once we switch to 1.x.x + BOOST_CHECK_EQUAL(runtimeCode[1], 1); // might change once we switch away from x.1.x + BOOST_CHECK_EQUAL(runtimeCode[7], int(eth::Instruction::POP)); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit