From 4043af1516b6a0844414f3cec551e6629ba0abee Mon Sep 17 00:00:00 2001 From: wanderer Date: Mon, 17 Nov 2014 15:27:30 -0500 Subject: added filler.json --- recursiveCreateFiller.json | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 recursiveCreateFiller.json diff --git a/recursiveCreateFiller.json b/recursiveCreateFiller.json new file mode 100644 index 00000000..0d18fb7a --- /dev/null +++ b/recursiveCreateFiller.json @@ -0,0 +1,35 @@ +{ + "recursiveCreate": { + "env": { + "previousHash": "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber": "0", + "currentGasLimit": "10000000", + "currentDifficulty": "256", + "currentTimestamp": 1, + "currentCoinbase": "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre": { + "095e7baea6a6c7c4c2dfeb977efac326af552d87": { + "balance": "20000000", + "nonce": 0, + "code": "{(CODECOPY 0 0 32)(CREATE 0 0 32)}", + "storage": {} + }, + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "1000000000000000000", + "nonce": 0, + "code": "", + "storage": {} + } + }, + "transaction": { + "nonce": "0", + "gasPrice": "1", + "gasLimit": "465224", + "to": "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value": "100000", + "secretKey": "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "data": "" + } + } +} -- cgit From 7df5ec34c778414079b879a5bd1ce3ec83cffa85 Mon Sep 17 00:00:00 2001 From: Paweł Bylica Date: Wed, 19 Nov 2014 13:13:19 +0100 Subject: In VM tests, check only if an exception occurred if an exception expected (no post state and output checking) --- TestHelper.cpp | 1 + vm.cpp | 77 +++++++++++++++++++++++++++++++++------------------------- 2 files changed, 45 insertions(+), 33 deletions(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index 1b13f9e8..114399a4 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -374,6 +374,7 @@ void executeTests(const string& _name, const string& _testPathAppendix, std::fun { BOOST_ERROR("Failed test with Exception: " << _e.what()); } + break; } } diff --git a/vm.cpp b/vm.cpp index cacbf94c..bdbe8155 100644 --- a/vm.cpp +++ b/vm.cpp @@ -300,6 +300,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) VM vm(fev.gas); u256 gas; + bool vmExceptionOccured = false; try { output = vm.go(fev, fev.simpleTrace()).toVector(); @@ -308,7 +309,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) catch (VMException const& _e) { cnote << "VM did throw an exception: " << diagnostic_information(_e); - gas = 0; + vmExceptionOccured = true; } catch (Exception const& _e) { @@ -342,48 +343,58 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) { o["env"] = mValue(fev.exportEnv()); o["exec"] = mValue(fev.exportExec()); - o["post"] = mValue(fev.exportState()); - o["callcreates"] = fev.exportCallCreates(); - o["out"] = "0x" + toHex(output); - fev.push(o, "gas", gas); + if (!vmExceptionOccured) + { + o["post"] = mValue(fev.exportState()); + o["callcreates"] = fev.exportCallCreates(); + o["out"] = "0x" + toHex(output); + fev.push(o, "gas", gas); + } } else { - BOOST_REQUIRE(o.count("post") > 0); - BOOST_REQUIRE(o.count("callcreates") > 0); - BOOST_REQUIRE(o.count("out") > 0); - BOOST_REQUIRE(o.count("gas") > 0); + if (o.count("post") > 0) // No exceptions expected + { + BOOST_CHECK(!vmExceptionOccured); - dev::test::FakeExtVM test; - test.importState(o["post"].get_obj()); - test.importCallCreates(o["callcreates"].get_array()); + BOOST_REQUIRE(o.count("post") > 0); + BOOST_REQUIRE(o.count("callcreates") > 0); + BOOST_REQUIRE(o.count("out") > 0); + BOOST_REQUIRE(o.count("gas") > 0); - checkOutput(output, o); + dev::test::FakeExtVM test; + test.importState(o["post"].get_obj()); + test.importCallCreates(o["callcreates"].get_array()); - BOOST_CHECK_EQUAL(toInt(o["gas"]), gas); + checkOutput(output, o); - auto& expectedAddrs = test.addresses; - auto& resultAddrs = fev.addresses; - for (auto&& expectedPair : expectedAddrs) - { - auto& expectedAddr = expectedPair.first; - auto resultAddrIt = resultAddrs.find(expectedAddr); - if (resultAddrIt == resultAddrs.end()) - BOOST_ERROR("Missing expected address " << expectedAddr); - else - { - auto& expectedState = expectedPair.second; - auto& resultState = resultAddrIt->second; - BOOST_CHECK_MESSAGE(std::get<0>(expectedState) == std::get<0>(resultState), expectedAddr << ": incorrect balance " << std::get<0>(resultState) << ", expected " << std::get<0>(expectedState)); - BOOST_CHECK_MESSAGE(std::get<1>(expectedState) == std::get<1>(resultState), expectedAddr << ": incorrect txCount " << std::get<1>(resultState) << ", expected " << std::get<1>(expectedState)); - BOOST_CHECK_MESSAGE(std::get<3>(expectedState) == std::get<3>(resultState), expectedAddr << ": incorrect code"); + BOOST_CHECK_EQUAL(toInt(o["gas"]), gas); - checkStorage(std::get<2>(expectedState), std::get<2>(resultState), expectedAddr); + auto& expectedAddrs = test.addresses; + auto& resultAddrs = fev.addresses; + for (auto&& expectedPair : expectedAddrs) + { + auto& expectedAddr = expectedPair.first; + auto resultAddrIt = resultAddrs.find(expectedAddr); + if (resultAddrIt == resultAddrs.end()) + BOOST_ERROR("Missing expected address " << expectedAddr); + else + { + auto& expectedState = expectedPair.second; + auto& resultState = resultAddrIt->second; + BOOST_CHECK_MESSAGE(std::get<0>(expectedState) == std::get<0>(resultState), expectedAddr << ": incorrect balance " << std::get<0>(resultState) << ", expected " << std::get<0>(expectedState)); + BOOST_CHECK_MESSAGE(std::get<1>(expectedState) == std::get<1>(resultState), expectedAddr << ": incorrect txCount " << std::get<1>(resultState) << ", expected " << std::get<1>(expectedState)); + BOOST_CHECK_MESSAGE(std::get<3>(expectedState) == std::get<3>(resultState), expectedAddr << ": incorrect code"); + + checkStorage(std::get<2>(expectedState), std::get<2>(resultState), expectedAddr); + } } - } - checkAddresses, bytes> > >(test.addresses, fev.addresses); - BOOST_CHECK(test.callcreates == fev.callcreates); + checkAddresses, bytes> > >(test.addresses, fev.addresses); + BOOST_CHECK(test.callcreates == fev.callcreates); + } + else // Exception expected + BOOST_CHECK(vmExceptionOccured); } } } -- cgit From 4f2008e8d8e93f4607eddea388c166141b60a792 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 19 Nov 2014 10:24:22 +0100 Subject: Special handling for constructor. --- solidityEndToEndTest.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/solidityEndToEndTest.cpp b/solidityEndToEndTest.cpp index 617cbabc..4e68103a 100644 --- a/solidityEndToEndTest.cpp +++ b/solidityEndToEndTest.cpp @@ -700,6 +700,28 @@ BOOST_AUTO_TEST_CASE(structs) BOOST_CHECK(callContractFunction(0) == bytes({0x01})); } +BOOST_AUTO_TEST_CASE(constructor) +{ + char const* sourceCode = "contract test {\n" + " mapping(uint => uint) data;\n" + " function test() {\n" + " data[7] = 8;\n" + " }\n" + " function get(uint key) returns (uint value) {\n" + " return data[key];" + " }\n" + "}\n"; + compileAndRun(sourceCode); + map data; + data[7] = 8; + auto get = [&](u256 const& _x) -> u256 + { + return data[_x]; + }; + testSolidityAgainstCpp(0, get, u256(6)); + testSolidityAgainstCpp(0, get, u256(7)); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit