aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiana Husikyan <liana@ethdev.com>2015-05-20 23:57:41 +0800
committerLiana Husikyan <liana@ethdev.com>2015-05-20 23:57:41 +0800
commitd006006c576fc9b08cfc54aeb6ea17b6710b017c (patch)
tree4a62a499d3f02a19b408d2cf560a3b0bf20dfe2d
parentb0d5cbf6983030c4e4fb48c45e1602880069b063 (diff)
downloaddexon-solidity-d006006c576fc9b08cfc54aeb6ea17b6710b017c.tar.gz
dexon-solidity-d006006c576fc9b08cfc54aeb6ea17b6710b017c.tar.zst
dexon-solidity-d006006c576fc9b08cfc54aeb6ea17b6710b017c.zip
added tests to check references to struct type.
-rw-r--r--libsolidity/SolidityEndToEndTest.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp
index 90ce20d2..f9870a9a 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
+