From d006006c576fc9b08cfc54aeb6ea17b6710b017c Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Wed, 20 May 2015 17:57:41 +0200 Subject: [PATCH 1/5] added tests to check references to struct type. --- libsolidity/SolidityEndToEndTest.cpp | 87 ++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 90ce20d26..f9870a9ad 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4023,9 +4023,96 @@ BOOST_AUTO_TEST_CASE(overwriting_inheritance) BOOST_CHECK(callContractFunction("checkOk()") == encodeArgs(6)); } +BOOST_AUTO_TEST_CASE(struct_assign_reference_to_struct) +{ + char const* sourceCode = R"( + contract test { + struct testStruct + { + uint m_value; + } + testStruct data1; + testStruct data2; + testStruct data3; + function test() + { + data1.m_value = 2; + } + function assign() returns (uint ret_local, uint ret_global, uint ret_global3, uint ret_global1) + { + testStruct x = data1; //x is a reference data1..m_value == 2 as well as x.m_value = 2 + data2 = data1; // should copy data. data2.m_value == 2 + + ret_local = x.m_value; // = 2 + ret_global = data2.m_value; // = 2 + + x.m_value = 3; + data3 = x; //should copy the data. data3.m_value == 3 + ret_global3 = data3.m_value; // = 3 + ret_global1 = data1.m_value; // =3 + } + } + )"; + compileAndRun(sourceCode, 0, "test"); + BOOST_CHECK(callContractFunction("assign()") == encodeArgs(2, 2, 3, 3)); +} + +BOOST_AUTO_TEST_CASE(struct_delete_member) +{ + char const* sourceCode = R"( + contract test { + struct testStruct + { + uint m_value; + } + testStruct data1; + function test() + { + data1.m_value = 2; + } + function deleteMember() returns (uint ret_value) + { + testStruct x = data1; //should not copy the data. data1.m_value == 2 but x.m_value = 0 + x.m_value = 4; + delete x.m_value; + ret_value = x.m_value; + } + } + )"; + compileAndRun(sourceCode, 0, "test"); + auto res = callContractFunction("deleteMember()"); + BOOST_CHECK(callContractFunction("deleteMember()") == encodeArgs(0)); +} + +BOOST_AUTO_TEST_CASE(struct_delete_struct_in_mapping) +{ + char const* sourceCode = R"( + contract test { + struct testStruct + { + uint m_value; + } + mapping (uint => testStruct) campaigns; + + function test() + { + campaigns[0].m_value = 2; + } + function deleteIt() returns (uint) + { + delete campaigns[0]; + return campaigns[0].m_value; + } + } + )"; + compileAndRun(sourceCode, 0, "test"); + auto res = callContractFunction("deleteIt()"); + BOOST_CHECK(callContractFunction("deleteIt()") == encodeArgs(0)); +} BOOST_AUTO_TEST_SUITE_END() } } } // end namespaces + From 007c88216bf20967c685baadd00cd4a0bebf5941 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Wed, 20 May 2015 18:05:51 +0200 Subject: [PATCH 2/5] Update SolidityEndToEndTest.cpp --- libsolidity/SolidityEndToEndTest.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index f9870a9ad..c900fff4c 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4115,4 +4115,3 @@ BOOST_AUTO_TEST_SUITE_END() } } } // end namespaces - From a92591e5193b42200163b907b3ef4e36b08636ce Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Wed, 20 May 2015 18:35:05 +0200 Subject: [PATCH 3/5] style fix --- libsolidity/SolidityEndToEndTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index c900fff4c..6b7007a29 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4040,7 +4040,7 @@ BOOST_AUTO_TEST_CASE(struct_assign_reference_to_struct) } function assign() returns (uint ret_local, uint ret_global, uint ret_global3, uint ret_global1) { - testStruct x = data1; //x is a reference data1..m_value == 2 as well as x.m_value = 2 + testStruct x = data1; //x is a reference data1.m_value == 2 as well as x.m_value = 2 data2 = data1; // should copy data. data2.m_value == 2 ret_local = x.m_value; // = 2 @@ -4049,7 +4049,7 @@ BOOST_AUTO_TEST_CASE(struct_assign_reference_to_struct) x.m_value = 3; data3 = x; //should copy the data. data3.m_value == 3 ret_global3 = data3.m_value; // = 3 - ret_global1 = data1.m_value; // =3 + ret_global1 = data1.m_value; // = 3 } } )"; From 19262c12cf0ed9fe4377410e25706effe5d92716 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Wed, 20 May 2015 18:38:52 +0200 Subject: [PATCH 4/5] Update SolidityEndToEndTest.cpp --- libsolidity/SolidityEndToEndTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 6b7007a29..88a3613ad 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4049,7 +4049,7 @@ BOOST_AUTO_TEST_CASE(struct_assign_reference_to_struct) x.m_value = 3; data3 = x; //should copy the data. data3.m_value == 3 ret_global3 = data3.m_value; // = 3 - ret_global1 = data1.m_value; // = 3 + ret_global1 = data1.m_value; // = 3. Changed due to the assignment to x.m_value } } )"; From e38eefa9f6116fc5e993c78b305e70f7076dda62 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Wed, 20 May 2015 18:40:00 +0200 Subject: [PATCH 5/5] Update SolidityEndToEndTest.cpp --- libsolidity/SolidityEndToEndTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 88a3613ad..503615a5a 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4075,7 +4075,7 @@ BOOST_AUTO_TEST_CASE(struct_delete_member) testStruct x = data1; //should not copy the data. data1.m_value == 2 but x.m_value = 0 x.m_value = 4; delete x.m_value; - ret_value = x.m_value; + ret_value = data1.m_value; } } )";