diff options
author | chriseth <c@ethdev.com> | 2015-05-21 00:41:34 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-05-21 00:41:34 +0800 |
commit | e5a4a8fca4832dff79227dc6ed667b7f1c879faf (patch) | |
tree | 4d5306d451cd46a59cdd157402273dbb0f49352b /libsolidity | |
parent | 42a36548e2c6575bd83213861ebece85d2048aa5 (diff) | |
parent | e38eefa9f6116fc5e993c78b305e70f7076dda62 (diff) | |
download | dexon-solidity-e5a4a8fca4832dff79227dc6ed667b7f1c879faf.tar.gz dexon-solidity-e5a4a8fca4832dff79227dc6ed667b7f1c879faf.tar.zst dexon-solidity-e5a4a8fca4832dff79227dc6ed667b7f1c879faf.zip |
Merge pull request #1988 from LianaHus/sol_Check_ref_problems_for_structs
Check: Reference problems concerning structs
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/SolidityEndToEndTest.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 90ce20d2..503615a5 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4023,6 +4023,92 @@ 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. Changed due to the assignment to x.m_value + } + } + )"; + 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 = data1.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() |