aboutsummaryrefslogtreecommitdiffstats
path: root/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorliana <liana@ethdev.com>2015-01-14 20:52:03 +0800
committerliana <liana@ethdev.com>2015-01-15 18:59:58 +0800
commit3b7fff538943ae174282c5d02ca47a6d8167015d (patch)
treee6f3187d079569c77810d67d382c274adfe43fe0 /SolidityEndToEndTest.cpp
parentf8f1ec30f4b2fdb3215544276474ba92b71cffec (diff)
downloaddexon-solidity-3b7fff538943ae174282c5d02ca47a6d8167015d.tar.gz
dexon-solidity-3b7fff538943ae174282c5d02ca47a6d8167015d.tar.zst
dexon-solidity-3b7fff538943ae174282c5d02ca47a6d8167015d.zip
- added functionality to set values to 0 when deleting structure(not for mapping)
- added unit test Made some changes after Christian`s review on pull request - remove/edit comments - BoolType and ContractType return VoidType after delete - fixed constructor_arguments test - fixed set to 0 when deleting variable from stack - changed test case to test that
Diffstat (limited to 'SolidityEndToEndTest.cpp')
-rw-r--r--SolidityEndToEndTest.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp
index 9543497a..a733c2c4 100644
--- a/SolidityEndToEndTest.cpp
+++ b/SolidityEndToEndTest.cpp
@@ -772,6 +772,67 @@ BOOST_AUTO_TEST_CASE(struct_reference)
BOOST_CHECK(callContractFunction("check()") == encodeArgs(true));
}
+BOOST_AUTO_TEST_CASE(deleteStruct)
+{
+ char const* sourceCode = R"(
+ contract test {
+ struct topStruct {
+ nestedStruct nstr;
+ emptyStruct empty;
+ uint topValue;
+ mapping (uint => uint) topMapping;
+ }
+ uint toDelete;
+ topStruct str;
+ struct nestedStruct {
+ uint nestedValue;
+ mapping (uint => bool) nestedMapping;
+ }
+ struct emptyStruct{
+ }
+ function test(){
+ toDelete = 5;
+ str.topValue = 1;
+ str.topMapping[0] = 1;
+ str.topMapping[1] = 2;
+
+ str.nstr.nestedValue = 2;
+ str.nstr.nestedMapping[0] = true;
+ str.nstr.nestedMapping[1] = false;
+ uint v = 5;
+ delete v;
+ delete str;
+ delete toDelete;
+ }
+ function getToDelete() returns (uint res){
+ res = toDelete;
+ }
+ function getTopValue() returns(uint topValue){
+ topValue = str.topValue;
+ }
+ function getNestedValue() returns(uint nestedValue){
+ nestedValue = str.nstr.nestedValue;
+ }
+ function getTopMapping(uint index) returns(uint ret) {
+ ret = str.topMapping[index];
+ }
+ function getNestedMapping(uint index) returns(bool ret) {
+ return str.nstr.nestedMapping[index];
+ }
+ })";
+
+ compileAndRun(sourceCode);
+
+ BOOST_CHECK(callContractFunction("getToDelete()") == encodeArgs(0));
+ BOOST_CHECK(callContractFunction("getTopValue()") == encodeArgs(0));
+ BOOST_CHECK(callContractFunction("getNestedValue()") == encodeArgs(0));
+ // mapping values should be the same
+ BOOST_CHECK(callContractFunction("getTopMapping(uint256)", 0) == encodeArgs(1));
+ BOOST_CHECK(callContractFunction("getTopMapping(uint256)", 1) == encodeArgs(2));
+ BOOST_CHECK(callContractFunction("getNestedMapping(uint256)", 0) == encodeArgs(true));
+ BOOST_CHECK(callContractFunction("getNestedMapping(uint256)", 1) == encodeArgs(false));
+}
+
BOOST_AUTO_TEST_CASE(constructor)
{
char const* sourceCode = "contract test {\n"
@@ -1243,6 +1304,7 @@ BOOST_AUTO_TEST_CASE(constructor_arguments)
contract Helper {
string3 name;
bool flag;
+
function Helper(string3 x, bool f) {
name = x;
flag = f;