From ac77d20ee36c4d4b13d90926c0447a8cc4459edf Mon Sep 17 00:00:00 2001 From: liana Date: Fri, 16 Jan 2015 12:55:49 +0100 Subject: [PATCH] Corrected "delete" for local variables i.e. set them to 0 Added test case --- SolidityEndToEndTest.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index a733c2c43..ad537750e 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -799,8 +799,6 @@ BOOST_AUTO_TEST_CASE(deleteStruct) str.nstr.nestedValue = 2; str.nstr.nestedMapping[0] = true; str.nstr.nestedMapping[1] = false; - uint v = 5; - delete v; delete str; delete toDelete; } @@ -833,6 +831,37 @@ BOOST_AUTO_TEST_CASE(deleteStruct) BOOST_CHECK(callContractFunction("getNestedMapping(uint256)", 1) == encodeArgs(false)); } +BOOST_AUTO_TEST_CASE(deleteLocal) +{ + char const* sourceCode = R"( + contract test { + function delLocal() returns (uint res){ + uint v = 5; + delete v; + res = v; + } + })"; + + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("delLocal()") == encodeArgs(0)); +} + +BOOST_AUTO_TEST_CASE(deleteLocals) +{ + char const* sourceCode = R"( + contract test { + function delLocal() returns (uint res){ + uint v = 5; + uint w = 6; + delete v; + res = w; + } + })"; + + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("delLocal()") == encodeArgs(6)); +} + BOOST_AUTO_TEST_CASE(constructor) { char const* sourceCode = "contract test {\n"