From f8772007c8656855df409d7bc4a35662ae023c14 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 11 Feb 2015 11:23:57 +0100 Subject: [PATCH 01/15] 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 02/15] 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 03/15] 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 04/15] 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 05/15] 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 06/15] 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 07/15] 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 08/15] 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 09/15] 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 10/15] 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 11/15] 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 12/15] 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); } From 31425a1fc0a75d353d89744cc11d9fcfd4d2a4b1 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 14 Feb 2015 03:06:50 +0100 Subject: [PATCH 13/15] Some changes to enums. --- SolidityNameAndTypeResolution.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index ec49a42d1..d6e4ed516 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -1080,7 +1080,7 @@ BOOST_AUTO_TEST_CASE(enum_duplicate_values) enum ActionChoices { GoLeft, GoRight, GoLeft, Sit } } )"; - BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); + BOOST_CHECK_THROW(parseTextAndResolveNames(text), DeclarationError); } BOOST_AUTO_TEST_SUITE_END() From 600b38224ea1592af9a8348b082abb996ee5ef76 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 14 Feb 2015 03:22:49 +0100 Subject: [PATCH 14/15] Forced cleanup for conversion to enum. --- SolidityEndToEndTest.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index 2ef2b8038..0325c4c6a 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -2519,6 +2519,21 @@ BOOST_AUTO_TEST_CASE(using_enums) BOOST_CHECK(callContractFunction("getChoice()") == encodeArgs(2)); } +BOOST_AUTO_TEST_CASE(constructing_enums_from_ints) +{ + char const* sourceCode = R"( + contract c { + enum Truth { False, True } + function test() returns (uint) + { + return uint(Truth(uint8(0x701))); + } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(1)); +} + BOOST_AUTO_TEST_SUITE_END() } From 44103be9b0963e1394b8db4172bdc59c0f1a0eda Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 16 Feb 2015 17:15:04 +0100 Subject: [PATCH 15/15] Removing events from Solidity Interface --- SolidityInterface.cpp | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/SolidityInterface.cpp b/SolidityInterface.cpp index 78de2356a..a73c118bb 100644 --- a/SolidityInterface.cpp +++ b/SolidityInterface.cpp @@ -111,24 +111,6 @@ BOOST_AUTO_TEST_CASE(exclude_fallback_function) BOOST_CHECK_EQUAL(getSourcePart(contract), "contract test{}"); } -BOOST_AUTO_TEST_CASE(event) -{ - ContractDefinition const& contract = checkInterface( - "contract test { event Event; }"); - BOOST_REQUIRE_EQUAL(1, contract.getEvents().size()); - BOOST_CHECK_EQUAL(getSourcePart(*contract.getEvents().front()), - "event Event;"); -} - -BOOST_AUTO_TEST_CASE(event_arguments) -{ - ContractDefinition const& contract = checkInterface( - "contract test { event Event(uint a, uint indexed b); }"); - BOOST_REQUIRE_EQUAL(1, contract.getEvents().size()); - BOOST_CHECK_EQUAL(getSourcePart(*contract.getEvents().front()), - "event Event(uint256 a,uint256 indexed b);"); -} - BOOST_AUTO_TEST_CASE(events) { char const* sourceCode = "contract test {\n" @@ -137,10 +119,8 @@ BOOST_AUTO_TEST_CASE(events) " event e2(); \n" "}\n"; ContractDefinition const& contract = checkInterface(sourceCode); - set expectation({"event e1(uint256 b,address indexed c);", "event e2;"}); - BOOST_REQUIRE_EQUAL(2, contract.getEvents().size()); - BOOST_CHECK(expectation == set({getSourcePart(*contract.getEvents().at(0)), - getSourcePart(*contract.getEvents().at(1))})); + // events should not appear in the Solidity Interface + BOOST_REQUIRE_EQUAL(0, contract.getEvents().size()); } BOOST_AUTO_TEST_CASE(inheritance) @@ -155,12 +135,8 @@ BOOST_AUTO_TEST_CASE(inheritance) " event derivedEvent(uint indexed evtArgDerived); \n" " }"; ContractDefinition const& contract = checkInterface(sourceCode); - set expectedEvents({"event derivedEvent(uint256 indexed evtArgDerived);", - "event baseEvent(string32 indexed evtArgBase);"}); set expectedFunctions({"function baseFunction(uint256 p)returns(uint256 i){}", "function derivedFunction(string32 p)returns(string32 i){}"}); - BOOST_CHECK(expectedEvents == set({getSourcePart(*contract.getEvents().at(0)), - getSourcePart(*contract.getEvents().at(1))})); BOOST_REQUIRE_EQUAL(2, contract.getDefinedFunctions().size()); BOOST_CHECK(expectedFunctions == set({getSourcePart(*contract.getDefinedFunctions().at(0)), getSourcePart(*contract.getDefinedFunctions().at(1))}));