From 4043af1516b6a0844414f3cec551e6629ba0abee Mon Sep 17 00:00:00 2001 From: wanderer Date: Mon, 17 Nov 2014 15:27:30 -0500 Subject: [PATCH 1/6] 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 000000000..0d18fb7a5 --- /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": "" + } + } +} From a461498300624766da2a3637e3b4bd483b67a01a Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Tue, 18 Nov 2014 18:50:40 +0100 Subject: [PATCH 2/6] solidity scanner takes triple slash doc comments into account - Conditionally scanning for the documentation comments and gettings their contents. - Adding tests for this functionality of the scanner --- solidityScanner.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/solidityScanner.cpp b/solidityScanner.cpp index d714699a0..28f52d3af 100644 --- a/solidityScanner.cpp +++ b/solidityScanner.cpp @@ -153,6 +153,50 @@ BOOST_AUTO_TEST_CASE(ambiguities) BOOST_CHECK_EQUAL(scanner.next(), Token::SHL); } +BOOST_AUTO_TEST_CASE(documentation_comments_parsed_begin) +{ + Scanner scanner(CharStream("/// Send $(value / 1000) chocolates to the user"), false); + BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::COMMENT_LITERAL); + BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), " Send $(value / 1000) chocolates to the user"); +} + +BOOST_AUTO_TEST_CASE(documentation_comments_skipped_begin) +{ + Scanner scanner(CharStream("/// Send $(value / 1000) chocolates to the user")); + BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS); +} + +BOOST_AUTO_TEST_CASE(documentation_comments_parsed) +{ + Scanner scanner(CharStream("some other tokens /// Send $(value / 1000) chocolates to the user")); + BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::IDENTIFIER); + BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER); + BOOST_CHECK_EQUAL(scanner.next(false), Token::IDENTIFIER); + BOOST_CHECK_EQUAL(scanner.next(false), Token::COMMENT_LITERAL); + BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), " Send $(value / 1000) chocolates to the user"); +} + +BOOST_AUTO_TEST_CASE(documentation_comments_skipped) +{ + Scanner scanner(CharStream("some other tokens /// Send $(value / 1000) chocolates to the user")); + BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::IDENTIFIER); + BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER); + BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER); + BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); +} + +BOOST_AUTO_TEST_CASE(comment_before_eos) +{ + Scanner scanner(CharStream("//")); + BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS); +} + +BOOST_AUTO_TEST_CASE(documentation_comment_before_eos) +{ + Scanner scanner(CharStream("///"), false); + BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::COMMENT_LITERAL); + BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), ""); +} BOOST_AUTO_TEST_SUITE_END() From 7df5ec34c778414079b879a5bd1ce3ec83cffa85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 19 Nov 2014 13:13:19 +0100 Subject: [PATCH 3/6] In VM tests, check only if an exception occurred if an exception expected (no post state and output checking) --- TestHelper.cpp | 1 + vm.cpp | 81 ++++++++++++++++++++++++++++---------------------- 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index 1b13f9e82..114399a49 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 cacbf94cc..bdbe8155d 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); - - dev::test::FakeExtVM test; - test.importState(o["post"].get_obj()); - test.importCallCreates(o["callcreates"].get_array()); - - checkOutput(output, o); - - BOOST_CHECK_EQUAL(toInt(o["gas"]), gas); - - auto& expectedAddrs = test.addresses; - auto& resultAddrs = fev.addresses; - for (auto&& expectedPair : expectedAddrs) + if (o.count("post") > 0) // No exceptions expected { - auto& expectedAddr = expectedPair.first; - auto resultAddrIt = resultAddrs.find(expectedAddr); - if (resultAddrIt == resultAddrs.end()) - BOOST_ERROR("Missing expected address " << expectedAddr); - else + BOOST_CHECK(!vmExceptionOccured); + + BOOST_REQUIRE(o.count("post") > 0); + BOOST_REQUIRE(o.count("callcreates") > 0); + BOOST_REQUIRE(o.count("out") > 0); + BOOST_REQUIRE(o.count("gas") > 0); + + dev::test::FakeExtVM test; + test.importState(o["post"].get_obj()); + test.importCallCreates(o["callcreates"].get_array()); + + checkOutput(output, o); + + BOOST_CHECK_EQUAL(toInt(o["gas"]), gas); + + auto& expectedAddrs = test.addresses; + auto& resultAddrs = fev.addresses; + for (auto&& expectedPair : expectedAddrs) { - 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"); + 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); + 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); } } } From 4f2008e8d8e93f4607eddea388c166141b60a792 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 19 Nov 2014 10:24:22 +0100 Subject: [PATCH 4/6] Special handling for constructor. --- solidityEndToEndTest.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/solidityEndToEndTest.cpp b/solidityEndToEndTest.cpp index 617cbabc9..4e68103ac 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() } From 6275b1ee93e5f4174a0ddd6da525dd9ca74edc09 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 19 Nov 2014 16:21:42 +0100 Subject: [PATCH 5/6] documentation comments are now always skipped but saved as special tokens at the Scanner --- solidityScanner.cpp | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/solidityScanner.cpp b/solidityScanner.cpp index 28f52d3af..1a2299f37 100644 --- a/solidityScanner.cpp +++ b/solidityScanner.cpp @@ -154,35 +154,20 @@ BOOST_AUTO_TEST_CASE(ambiguities) } BOOST_AUTO_TEST_CASE(documentation_comments_parsed_begin) -{ - Scanner scanner(CharStream("/// Send $(value / 1000) chocolates to the user"), false); - BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::COMMENT_LITERAL); - BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), " Send $(value / 1000) chocolates to the user"); -} - -BOOST_AUTO_TEST_CASE(documentation_comments_skipped_begin) { Scanner scanner(CharStream("/// Send $(value / 1000) chocolates to the user")); BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS); + BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), " Send $(value / 1000) chocolates to the user"); } BOOST_AUTO_TEST_CASE(documentation_comments_parsed) -{ - Scanner scanner(CharStream("some other tokens /// Send $(value / 1000) chocolates to the user")); - BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::IDENTIFIER); - BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER); - BOOST_CHECK_EQUAL(scanner.next(false), Token::IDENTIFIER); - BOOST_CHECK_EQUAL(scanner.next(false), Token::COMMENT_LITERAL); - BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), " Send $(value / 1000) chocolates to the user"); -} - -BOOST_AUTO_TEST_CASE(documentation_comments_skipped) { Scanner scanner(CharStream("some other tokens /// Send $(value / 1000) chocolates to the user")); BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::IDENTIFIER); BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER); BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER); BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); + BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), " Send $(value / 1000) chocolates to the user"); } BOOST_AUTO_TEST_CASE(comment_before_eos) @@ -193,9 +178,9 @@ BOOST_AUTO_TEST_CASE(comment_before_eos) BOOST_AUTO_TEST_CASE(documentation_comment_before_eos) { - Scanner scanner(CharStream("///"), false); - BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::COMMENT_LITERAL); - BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), ""); + Scanner scanner(CharStream("///")); + BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS); + BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), ""); } BOOST_AUTO_TEST_SUITE_END() From 70a5c84095ae7051b1ab92ed42b2d947ce4fe9a3 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 20 Nov 2014 23:18:05 +0100 Subject: [PATCH 6/6] extra comments scanning test --- solidityScanner.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/solidityScanner.cpp b/solidityScanner.cpp index 1a2299f37..573affe6d 100644 --- a/solidityScanner.cpp +++ b/solidityScanner.cpp @@ -174,6 +174,7 @@ BOOST_AUTO_TEST_CASE(comment_before_eos) { Scanner scanner(CharStream("//")); BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS); + BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), ""); } BOOST_AUTO_TEST_CASE(documentation_comment_before_eos) @@ -183,6 +184,16 @@ BOOST_AUTO_TEST_CASE(documentation_comment_before_eos) BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), ""); } +BOOST_AUTO_TEST_CASE(comments_mixed_in_sequence) +{ + Scanner scanner(CharStream("hello_world ///documentation comment \n" + "//simple comment \n" + "<<")); + BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::IDENTIFIER); + BOOST_CHECK_EQUAL(scanner.next(), Token::SHL); + BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "documentation comment "); +} + BOOST_AUTO_TEST_SUITE_END() }