From 92419943d3810f3868ee06fc07dba26b8811782f Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 13 Feb 2015 11:30:59 +0100 Subject: [PATCH 01/14] style - auto --- vm.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vm.cpp b/vm.cpp index faab48129..66925f929 100644 --- a/vm.cpp +++ b/vm.cpp @@ -525,7 +525,7 @@ BOOST_AUTO_TEST_CASE(vmPerformanceTest) dev::test::executeTests("vmPerformanceTest", "/VMTests", dev::test::doVMTests); auto end = chrono::steady_clock::now(); - chrono::milliseconds duration(chrono::duration_cast(end - start)); + auto duration(chrono::duration_cast(end - start)); cnote << "test duration: " << duration.count() << " milliseconds.\n"; } } @@ -543,7 +543,7 @@ BOOST_AUTO_TEST_CASE(vmInputLimitsTest1) dev::test::executeTests("vmInputLimitsTest1", "/VMTests", dev::test::doVMTests); auto end = chrono::steady_clock::now(); - chrono::milliseconds duration(chrono::duration_cast(end - start)); + auto duration(chrono::duration_cast(end - start)); cnote << "test duration: " << duration.count() << " milliseconds.\n"; } } From 14b67bc0ffd7a3ee8fc4629e8cfb93e33e095858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 13 Feb 2015 14:56:27 +0100 Subject: [PATCH 02/14] Performance tests: more ackermann calls, fibonacci. - ackermann(3, 1) - ackermann(3, 2) - fibonacci(10) - fibonacci(16) Contract code included: PerformanceTester.sol --- PerformaceTester.sol | 17 +++++ vmPerformanceTestFiller.json | 131 ++++++++++++++++++++++++++++++++--- 2 files changed, 137 insertions(+), 11 deletions(-) create mode 100644 PerformaceTester.sol diff --git a/PerformaceTester.sol b/PerformaceTester.sol new file mode 100644 index 000000000..3b1202cea --- /dev/null +++ b/PerformaceTester.sol @@ -0,0 +1,17 @@ +contract PerformanceTester { + function ackermann(uint m, uint n) returns (uint) { + if (m == 0) + return n + 1; + + if (n == 0) + return ackermann(m - 1, 1); + + return ackermann(m - 1, ackermann(m, n - 1)); + } + + function fibonacci(uint n) returns (uint) { + if (n == 0 || n == 1) + return n; + return fibonacci(n - 1) + fibonacci(n - 2); + } +} \ No newline at end of file diff --git a/vmPerformanceTestFiller.json b/vmPerformanceTestFiller.json index 7cfe659d5..3292916ec 100644 --- a/vmPerformanceTestFiller.json +++ b/vmPerformanceTestFiller.json @@ -1,4 +1,62 @@ { + "ackermann31": { + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "100000000000", + "currentDifficulty" : "256", + "currentTimestamp" : "1", + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "nonce" : "0", + "//" : "PerformanceTester.sol", + "code" : "0x60e060020a6000350480632839e92814601e57806361047ff414603457005b602a6004356024356047565b8060005260206000f35b603d6004356099565b8060005260206000f35b600082600014605457605e565b8160010190506093565b81600014606957607b565b60756001840360016047565b90506093565b609060018403608c85600186036047565b6047565b90505b92915050565b6000816000148060a95750816001145b60b05760b7565b81905060cf565b60c1600283036099565b60cb600184036099565b0190505b91905056", + "storage": {} + } + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000", + "//" : "ackermann(3, 1)", + "data" : "0x2839e92800000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001", + "gasPrice" : "100000000000000", + "gas" : "10000" + } + }, + "ackermann32": { + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "100000000000", + "currentDifficulty" : "256", + "currentTimestamp" : "1", + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "nonce" : "0", + "//" : "PerformanceTester.sol", + "code" : "0x60e060020a6000350480632839e92814601e57806361047ff414603457005b602a6004356024356047565b8060005260206000f35b603d6004356099565b8060005260206000f35b600082600014605457605e565b8160010190506093565b81600014606957607b565b60756001840360016047565b90506093565b609060018403608c85600186036047565b6047565b90505b92915050565b6000816000148060a95750816001145b60b05760b7565b81905060cf565b60c1600283036099565b60cb600184036099565b0190505b91905056", + "storage": {} + } + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000", + "//" : "ackermann(3, 2)", + "data" : "0x2839e92800000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000002", + "gasPrice" : "100000000000000", + "gas" : "100000" + } + }, "ackermann33": { "env" : { "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", @@ -12,16 +70,8 @@ "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "balance" : "1000000000000000000", "nonce" : "0", - "//" : "contract PerformanceTester {", - "//" : " function ackermann(uint m, uint n) returns (uint) {", - "//" : " if (m == 0)", - "//" : " return n + 1;", - "//" : " if (n == 0)", - "//" : " return ackermann(m - 1, 1);", - "//" : " return ackermann(m - 1, ackermann(m, n - 1));", - "//" : " }", - "//" : "}", - "code" : "0x60e060020a6000350480632839e92814601457005b6020600435602435602a565b8060005260206000f35b6000826000146037576041565b8160010190506076565b81600014604c57605e565b6058600184036001602a565b90506076565b607360018403606f8560018603602a565b602a565b90505b9291505056", + "//" : "PerformanceTester.sol", + "code" : "0x60e060020a6000350480632839e92814601e57806361047ff414603457005b602a6004356024356047565b8060005260206000f35b603d6004356099565b8060005260206000f35b600082600014605457605e565b8160010190506093565b81600014606957607b565b60756001840360016047565b90506093565b609060018403608c85600186036047565b6047565b90505b92915050565b6000816000148060a95750816001145b60b05760b7565b81905060cf565b60c1600283036099565b60cb600184036099565b0190505b91905056", "storage": {} } }, @@ -30,9 +80,68 @@ "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", "value" : "1000000000000000000", + "//" : "ackermann(3, 3)", "data" : "0x2839e92800000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003", "gasPrice" : "100000000000000", - "gas" : "100000000000" + "gas" : "100000" + } + }, + "fibonacci10": { + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "100000000000", + "currentDifficulty" : "256", + "currentTimestamp" : "1", + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "nonce" : "0", + "//" : "PerformanceTester.sol", + "code" : "0x60e060020a6000350480632839e92814601e57806361047ff414603457005b602a6004356024356047565b8060005260206000f35b603d6004356099565b8060005260206000f35b600082600014605457605e565b8160010190506093565b81600014606957607b565b60756001840360016047565b90506093565b609060018403608c85600186036047565b6047565b90505b92915050565b6000816000148060a95750816001145b60b05760b7565b81905060cf565b60c1600283036099565b60cb600184036099565b0190505b91905056", + "storage": {} + } + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000", + "//" : "fibonacci(10)", + "data" : "0x61047ff4000000000000000000000000000000000000000000000000000000000000000a", + "gasPrice" : "100000000000000", + "gas" : "100000" + } + }, + "fibonacci16": { + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "100000000000", + "currentDifficulty" : "256", + "currentTimestamp" : "1", + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "nonce" : "0", + "//" : "PerformanceTester.sol", + "code" : "0x60e060020a6000350480632839e92814601e57806361047ff414603457005b602a6004356024356047565b8060005260206000f35b603d6004356099565b8060005260206000f35b600082600014605457605e565b8160010190506093565b81600014606957607b565b60756001840360016047565b90506093565b609060018403608c85600186036047565b6047565b90505b92915050565b6000816000148060a95750816001145b60b05760b7565b81905060cf565b60c1600283036099565b60cb600184036099565b0190505b91905056", + "storage": {} + } + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000", + "//" : "fibonacci(16)", + "data" : "0x61047ff40000000000000000000000000000000000000000000000000000000000000010", + "gasPrice" : "100000000000000", + "gas" : "100000000" } } } From f8772007c8656855df409d7bc4a35662ae023c14 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 11 Feb 2015 11:23:57 +0100 Subject: [PATCH 03/14] Changes required for upgrade to jsonrpccpp 0.4.2 --- webthreestubclient.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/webthreestubclient.h b/webthreestubclient.h index 1836f6506..02f5b5e40 100644 --- a/webthreestubclient.h +++ b/webthreestubclient.h @@ -10,7 +10,7 @@ class WebThreeStubClient : public jsonrpc::Client { public: - WebThreeStubClient(jsonrpc::IClientConnector &conn) : jsonrpc::Client(conn) {} + WebThreeStubClient(jsonrpc::IClientConnector &conn, jsonrpc::clientVersion_t type = jsonrpc::JSONRPC_CLIENT_V2) : jsonrpc::Client(conn, type) {} std::string web3_sha3(const std::string& param1) throw (jsonrpc::JsonRpcException) { @@ -52,7 +52,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool eth_setListening(const bool& param1) throw (jsonrpc::JsonRpcException) + bool eth_setListening(bool param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -72,7 +72,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool eth_setMining(const bool& param1) throw (jsonrpc::JsonRpcException) + bool eth_setMining(bool param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -122,7 +122,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool eth_setDefaultBlock(const int& param1) throw (jsonrpc::JsonRpcException) + bool eth_setDefaultBlock(int param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -233,7 +233,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_blockByNumber(const int& param1) throw (jsonrpc::JsonRpcException) + Json::Value eth_blockByNumber(int param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -243,7 +243,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_transactionByHash(const std::string& param1, const int& param2) throw (jsonrpc::JsonRpcException) + Json::Value eth_transactionByHash(const std::string& param1, int param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -254,7 +254,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_transactionByNumber(const int& param1, const int& param2) throw (jsonrpc::JsonRpcException) + Json::Value eth_transactionByNumber(int param1, int param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -265,7 +265,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_uncleByHash(const std::string& param1, const int& param2) throw (jsonrpc::JsonRpcException) + Json::Value eth_uncleByHash(const std::string& param1, int param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -276,7 +276,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_uncleByNumber(const int& param1, const int& param2) throw (jsonrpc::JsonRpcException) + Json::Value eth_uncleByNumber(int param1, int param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -347,7 +347,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool eth_uninstallFilter(const int& param1) throw (jsonrpc::JsonRpcException) + bool eth_uninstallFilter(int param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -357,7 +357,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_changed(const int& param1) throw (jsonrpc::JsonRpcException) + Json::Value eth_changed(int param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -367,7 +367,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_filterLogs(const int& param1) throw (jsonrpc::JsonRpcException) + Json::Value eth_filterLogs(int param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -515,7 +515,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool shh_uninstallFilter(const int& param1) throw (jsonrpc::JsonRpcException) + bool shh_uninstallFilter(int param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -525,7 +525,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value shh_changed(const int& param1) throw (jsonrpc::JsonRpcException) + Json::Value shh_changed(int param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -537,4 +537,4 @@ class WebThreeStubClient : public jsonrpc::Client } }; -#endif //JSONRPC_CPP_WEBTHREESTUBCLIENT_H_ +#endif //JSONRPC_CPP_STUB_WEBTHREESTUBCLIENT_H_ From 76d659dbe244c0934a0c3ca0284f2562d1872957 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Tue, 10 Feb 2015 14:51:40 +0100 Subject: [PATCH 04/14] Adding test for Enum Parsing --- SolidityParser.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/SolidityParser.cpp b/SolidityParser.cpp index 84f36170f..035bfd789 100644 --- a/SolidityParser.cpp +++ b/SolidityParser.cpp @@ -703,6 +703,20 @@ BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations_in_expression BOOST_CHECK_NO_THROW(parseTextExplainError(text)); } +BOOST_AUTO_TEST_CASE(enum_declaration) +{ + char const* text = R"( + contract c { + enum foo { WARNING, NOTICE, ERROR, CRITICAL }; + function c () + { + a = foo.CRITICAL; + } + uint256 a; + })"; + BOOST_CHECK_NO_THROW(parseTextExplainError(text)); +} + BOOST_AUTO_TEST_SUITE_END() } From bb30e9184b37d736e588be51a20fdf9758c3ef57 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 11 Feb 2015 16:37:46 +0100 Subject: [PATCH 05/14] Introducing EnumType and some Parser tests --- SolidityParser.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/SolidityParser.cpp b/SolidityParser.cpp index 035bfd789..291ec6051 100644 --- a/SolidityParser.cpp +++ b/SolidityParser.cpp @@ -717,6 +717,20 @@ BOOST_AUTO_TEST_CASE(enum_declaration) BOOST_CHECK_NO_THROW(parseTextExplainError(text)); } +BOOST_AUTO_TEST_CASE(empty_enum_declaration) +{ + char const* text = R"( + contract c { + enum foo { }; + function c () + { + a = 5; + } + uint256 a; + })"; + BOOST_CHECK_NO_THROW(parseTextExplainError(text)); +} + BOOST_AUTO_TEST_SUITE_END() } From 850350e7bc7dc037fff617331056ffcb9504b96f Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 11 Feb 2015 17:23:13 +0100 Subject: [PATCH 06/14] Disallow trailing comma in Enum Declaration --- SolidityParser.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/SolidityParser.cpp b/SolidityParser.cpp index 291ec6051..07ec2dcfa 100644 --- a/SolidityParser.cpp +++ b/SolidityParser.cpp @@ -731,6 +731,20 @@ BOOST_AUTO_TEST_CASE(empty_enum_declaration) BOOST_CHECK_NO_THROW(parseTextExplainError(text)); } +BOOST_AUTO_TEST_CASE(malformed_enum_declaration) +{ + char const* text = R"( + contract c { + enum foo { WARNING,}; + function c () + { + a = foo.CRITICAL; + } + uint256 a; + })"; + BOOST_CHECK_THROW(parseText(text), ParserError); +} + BOOST_AUTO_TEST_SUITE_END() } From 60e839954ed2816f5b138e1bab618ebd58ad87ed Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 11 Feb 2015 21:40:47 +0100 Subject: [PATCH 07/14] Enums NameAndTypeResolution - WIP - Also adding an EndToEnd enum test --- SolidityEndToEndTest.cpp | 20 ++++++++++++++++++++ SolidityNameAndTypeResolution.cpp | 15 +++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index 259123db6..7fa7dd251 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -2499,6 +2499,26 @@ BOOST_AUTO_TEST_CASE(struct_copy_via_local) BOOST_CHECK(callContractFunction("test()") == encodeArgs(true)); } +BOOST_AUTO_TEST_CASE(using_enums) +{ + char const* sourceCode = R"( + contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }; + function test() + { + choices = ActionChoices.GoStraight; + } + function getChoice() returns (uint d) + { + d = choices; + } + ActionChoices choices; + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("getChoice()") == encodeArgs(2)); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index 3ead6f1c5..490ab3be5 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -991,6 +991,21 @@ BOOST_AUTO_TEST_CASE(exp_operator_exponent_too_big) })"; BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } +BOOST_AUTO_TEST_CASE(enum_member_access) +{ + char const* text = R"( + contract test { + struct foo { uint256 x;} + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }; + function test() + { + choices = ActionChoices.GoStraight; + } + ActionChoices choices; + } + )"; + BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text)); +} BOOST_AUTO_TEST_SUITE_END() From d8535eb4ea322e3d5a9f69c953fd22a1ae3f5d8d Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 12 Feb 2015 15:19:04 +0100 Subject: [PATCH 08/14] Correcting and testing enum member access --- SolidityNameAndTypeResolution.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index 490ab3be5..34f51a4ce 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -991,11 +991,11 @@ BOOST_AUTO_TEST_CASE(exp_operator_exponent_too_big) })"; BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } + BOOST_AUTO_TEST_CASE(enum_member_access) { char const* text = R"( contract test { - struct foo { uint256 x;} enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }; function test() { @@ -1007,6 +1007,21 @@ BOOST_AUTO_TEST_CASE(enum_member_access) BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text)); } +BOOST_AUTO_TEST_CASE(enum_invalid_member_access) +{ + char const* text = R"( + contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }; + function test() + { + choices = ActionChoices.RunAroundWavingYourHands; + } + ActionChoices choices; + } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() } From fe725fbb49ec661fb1c5e9c3f8b58bbf6dd9e0cb Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 12 Feb 2015 17:59:52 +0100 Subject: [PATCH 09/14] Enum type conversion and member value access. - Added tests for the type conversion part. - Enum member value access still needs some work --- SolidityEndToEndTest.cpp | 2 +- SolidityNameAndTypeResolution.cpp | 34 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index 7fa7dd251..551607df2 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -2510,7 +2510,7 @@ BOOST_AUTO_TEST_CASE(using_enums) } function getChoice() returns (uint d) { - d = choices; + d = uint256(choices); } ActionChoices choices; } diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index 34f51a4ce..9399280b0 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -1022,6 +1022,40 @@ BOOST_AUTO_TEST_CASE(enum_invalid_member_access) BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); } +BOOST_AUTO_TEST_CASE(enum_explicit_conversion_is_okay) +{ + char const* text = R"( + contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }; + function test() + { + a = uint256(ActionChoices.GoStraight); + b = uint64(ActionChoices.Sit); + } + uint256 a; + uint64 b; + } + )"; + BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text)); +} + +BOOST_AUTO_TEST_CASE(enum_implicit_conversion_is_not_okay) +{ + char const* text = R"( + contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }; + function test() + { + a = ActionChoices.GoStraight; + b = ActionChoices.Sit; + } + uint256 a; + uint64 b; + } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() } From 3dd00cbdd8cedfef9b8db4750a4ec3e712eb42cd Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Fri, 13 Feb 2015 13:32:18 +0100 Subject: [PATCH 10/14] Enum Value member access should now work properly - Also detection of duplicate enum values and tests for them have been added --- SolidityNameAndTypeResolution.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index 9399280b0..e7482d661 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -1056,6 +1056,23 @@ BOOST_AUTO_TEST_CASE(enum_implicit_conversion_is_not_okay) BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); } +BOOST_AUTO_TEST_CASE(enum_duplicate_values) +{ + char const* text = R"( + contract test { + enum ActionChoices { GoLeft, GoRight, GoLeft, Sit }; + function test() + { + a = 1; + b = 2; + } + uint256 a; + uint64 b; + } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() } From afc328210e60e0528b84d7c92c0adc66920f292a Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Fri, 13 Feb 2015 15:59:30 +0100 Subject: [PATCH 11/14] Indentation fixes --- SolidityNameAndTypeResolution.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index e7482d661..051b3dce7 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -1063,8 +1063,8 @@ BOOST_AUTO_TEST_CASE(enum_duplicate_values) enum ActionChoices { GoLeft, GoRight, GoLeft, Sit }; function test() { - a = 1; - b = 2; + a = 1; + b = 2; } uint256 a; uint64 b; From 9dedbb41541b1a7c7849f2d601915e3bcc767b70 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Fri, 13 Feb 2015 22:52:04 +0100 Subject: [PATCH 12/14] Addressing issues with Enums in Solidity --- SolidityNameAndTypeResolution.cpp | 7 ------- SolidityParser.cpp | 16 +++------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index 051b3dce7..c912939fc 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -1061,13 +1061,6 @@ BOOST_AUTO_TEST_CASE(enum_duplicate_values) char const* text = R"( contract test { enum ActionChoices { GoLeft, GoRight, GoLeft, Sit }; - function test() - { - a = 1; - b = 2; - } - uint256 a; - uint64 b; } )"; BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); diff --git a/SolidityParser.cpp b/SolidityParser.cpp index 07ec2dcfa..702d1d6db 100644 --- a/SolidityParser.cpp +++ b/SolidityParser.cpp @@ -703,14 +703,14 @@ BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations_in_expression BOOST_CHECK_NO_THROW(parseTextExplainError(text)); } -BOOST_AUTO_TEST_CASE(enum_declaration) +BOOST_AUTO_TEST_CASE(enum_valid_declaration) { char const* text = R"( contract c { - enum foo { WARNING, NOTICE, ERROR, CRITICAL }; + enum validEnum { Value1, Value2, Value3, Value4 }; function c () { - a = foo.CRITICAL; + a = foo.Value3; } uint256 a; })"; @@ -722,11 +722,6 @@ BOOST_AUTO_TEST_CASE(empty_enum_declaration) char const* text = R"( contract c { enum foo { }; - function c () - { - a = 5; - } - uint256 a; })"; BOOST_CHECK_NO_THROW(parseTextExplainError(text)); } @@ -736,11 +731,6 @@ BOOST_AUTO_TEST_CASE(malformed_enum_declaration) char const* text = R"( contract c { enum foo { WARNING,}; - function c () - { - a = foo.CRITICAL; - } - uint256 a; })"; BOOST_CHECK_THROW(parseText(text), ParserError); } From 8e9a9ad5e9c4ab4fe08626ef3972983b69b198a4 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Fri, 13 Feb 2015 23:14:58 +0100 Subject: [PATCH 13/14] Explicit conversion from int to Enum --- SolidityNameAndTypeResolution.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index c912939fc..f3edfc313 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -1039,6 +1039,23 @@ BOOST_AUTO_TEST_CASE(enum_explicit_conversion_is_okay) BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text)); } +BOOST_AUTO_TEST_CASE(int_to_enum_explicit_conversion_is_okay) +{ + char const* text = R"( + contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }; + function test() + { + a = 2; + b = ActionChoices(a); + } + uint256 a; + ActionChoices b; + } + )"; + BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text)); +} + BOOST_AUTO_TEST_CASE(enum_implicit_conversion_is_not_okay) { char const* text = R"( From 9836d58df8372fe13590c61ad8ebce7cfbe32015 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Fri, 13 Feb 2015 23:47:55 +0100 Subject: [PATCH 14/14] Removing ';' from the end of EnumDefinition --- SolidityEndToEndTest.cpp | 2 +- SolidityNameAndTypeResolution.cpp | 12 ++++++------ SolidityParser.cpp | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index 551607df2..2ef2b8038 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -2503,7 +2503,7 @@ BOOST_AUTO_TEST_CASE(using_enums) { char const* sourceCode = R"( contract test { - enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }; + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } function test() { choices = ActionChoices.GoStraight; diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index f3edfc313..ec49a42d1 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -996,7 +996,7 @@ BOOST_AUTO_TEST_CASE(enum_member_access) { char const* text = R"( contract test { - enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }; + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } function test() { choices = ActionChoices.GoStraight; @@ -1011,7 +1011,7 @@ BOOST_AUTO_TEST_CASE(enum_invalid_member_access) { char const* text = R"( contract test { - enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }; + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } function test() { choices = ActionChoices.RunAroundWavingYourHands; @@ -1026,7 +1026,7 @@ BOOST_AUTO_TEST_CASE(enum_explicit_conversion_is_okay) { char const* text = R"( contract test { - enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }; + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } function test() { a = uint256(ActionChoices.GoStraight); @@ -1043,7 +1043,7 @@ BOOST_AUTO_TEST_CASE(int_to_enum_explicit_conversion_is_okay) { char const* text = R"( contract test { - enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }; + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } function test() { a = 2; @@ -1060,7 +1060,7 @@ BOOST_AUTO_TEST_CASE(enum_implicit_conversion_is_not_okay) { char const* text = R"( contract test { - enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }; + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } function test() { a = ActionChoices.GoStraight; @@ -1077,7 +1077,7 @@ BOOST_AUTO_TEST_CASE(enum_duplicate_values) { char const* text = R"( contract test { - enum ActionChoices { GoLeft, GoRight, GoLeft, Sit }; + enum ActionChoices { GoLeft, GoRight, GoLeft, Sit } } )"; BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); diff --git a/SolidityParser.cpp b/SolidityParser.cpp index 702d1d6db..af82f612a 100644 --- a/SolidityParser.cpp +++ b/SolidityParser.cpp @@ -707,7 +707,7 @@ BOOST_AUTO_TEST_CASE(enum_valid_declaration) { char const* text = R"( contract c { - enum validEnum { Value1, Value2, Value3, Value4 }; + enum validEnum { Value1, Value2, Value3, Value4 } function c () { a = foo.Value3; @@ -721,7 +721,7 @@ BOOST_AUTO_TEST_CASE(empty_enum_declaration) { char const* text = R"( contract c { - enum foo { }; + enum foo { } })"; BOOST_CHECK_NO_THROW(parseTextExplainError(text)); } @@ -730,7 +730,7 @@ BOOST_AUTO_TEST_CASE(malformed_enum_declaration) { char const* text = R"( contract c { - enum foo { WARNING,}; + enum foo { WARNING,} })"; BOOST_CHECK_THROW(parseText(text), ParserError); }