aboutsummaryrefslogtreecommitdiffstats
path: root/SolidityNameAndTypeResolution.cpp
diff options
context:
space:
mode:
authorwinsvega <winsvega@mail.ru>2015-02-18 18:17:11 +0800
committerwinsvega <winsvega@mail.ru>2015-02-18 18:17:11 +0800
commit2f73e8e6bc1f586a0b40dc873ee6b5237f7e0b15 (patch)
tree89857832a67777a8792089c2b34ed8b005f29a3f /SolidityNameAndTypeResolution.cpp
parent2d7194cc58e2544e398166853b45879b376c7bf4 (diff)
parent7cf233bd9e0b70254bcce01d0f5c4a2399a3677d (diff)
downloaddexon-solidity-2f73e8e6bc1f586a0b40dc873ee6b5237f7e0b15.tar
dexon-solidity-2f73e8e6bc1f586a0b40dc873ee6b5237f7e0b15.tar.gz
dexon-solidity-2f73e8e6bc1f586a0b40dc873ee6b5237f7e0b15.tar.bz2
dexon-solidity-2f73e8e6bc1f586a0b40dc873ee6b5237f7e0b15.tar.lz
dexon-solidity-2f73e8e6bc1f586a0b40dc873ee6b5237f7e0b15.tar.xz
dexon-solidity-2f73e8e6bc1f586a0b40dc873ee6b5237f7e0b15.tar.zst
dexon-solidity-2f73e8e6bc1f586a0b40dc873ee6b5237f7e0b15.zip
Merge branch 'develop' of https://github.com/ethereum/cpp-ethereum into develop
Diffstat (limited to 'SolidityNameAndTypeResolution.cpp')
-rw-r--r--SolidityNameAndTypeResolution.cpp173
1 files changed, 172 insertions, 1 deletions
diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp
index d013f5c5..6b337ac7 100644
--- a/SolidityNameAndTypeResolution.cpp
+++ b/SolidityNameAndTypeResolution.cpp
@@ -332,7 +332,7 @@ BOOST_AUTO_TEST_CASE(assignment_to_struct)
" data = a;\n"
" }\n"
"}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
+ BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
}
BOOST_AUTO_TEST_CASE(returns_in_constructor)
@@ -992,6 +992,177 @@ 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 {
+ enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }
+ function test()
+ {
+ choices = ActionChoices.GoStraight;
+ }
+ ActionChoices choices;
+ }
+ )";
+ 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_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(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"(
+ 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_CASE(enum_duplicate_values)
+{
+ char const* text = R"(
+ contract test {
+ enum ActionChoices { GoLeft, GoRight, GoLeft, Sit }
+ }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(text), DeclarationError);
+}
+
+BOOST_AUTO_TEST_CASE(private_visibility)
+{
+ char const* sourceCode = R"(
+ contract base {
+ function f() private {}
+ }
+ contract derived is base {
+ function g() { f(); }
+ }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), DeclarationError);
+}
+
+BOOST_AUTO_TEST_CASE(private_visibility_via_explicit_base_access)
+{
+ char const* sourceCode = R"(
+ contract base {
+ function f() private {}
+ }
+ contract derived is base {
+ function g() { base.f(); }
+ }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(external_visibility)
+{
+ char const* sourceCode = R"(
+ contract c {
+ function f() external {}
+ function g() { f(); }
+ }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), DeclarationError);
+}
+
+BOOST_AUTO_TEST_CASE(external_base_visibility)
+{
+ char const* sourceCode = R"(
+ contract base {
+ function f() external {}
+ }
+ contract derived is base {
+ function g() { base.f(); }
+ }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(external_argument_assign)
+{
+ char const* sourceCode = R"(
+ contract c {
+ function f(uint a) external { a = 1; }
+ }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(external_argument_increment)
+{
+ char const* sourceCode = R"(
+ contract c {
+ function f(uint a) external { a++; }
+ }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(external_argument_delete)
+{
+ char const* sourceCode = R"(
+ contract c {
+ function f(uint a) external { delete a; }
+ }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
+}
+
BOOST_AUTO_TEST_SUITE_END()
}