Skip to content

Commit

Permalink
Extract constant cycle tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth authored and axic committed Apr 3, 2018
1 parent eb5b18e commit 8fdbd19
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
32 changes: 0 additions & 32 deletions test/libsolidity/SolidityNameAndTypeResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6260,38 +6260,6 @@ BOOST_AUTO_TEST_CASE(address_methods)
CHECK_SUCCESS(text);
}

BOOST_AUTO_TEST_CASE(cyclic_dependency_for_constants)
{
char const* text = R"(
contract C {
uint constant a = a;
}
)";
CHECK_ERROR(text, TypeError, "cyclic dependency via a");
text = R"(
contract C {
uint constant a = b * c;
uint constant b = 7;
uint constant c = b + uint(keccak256(d));
uint constant d = 2 + a;
}
)";
CHECK_ERROR_ALLOW_MULTI(text, TypeError, (std::vector<std::string>{
"a has a cyclic dependency via c",
"c has a cyclic dependency via d",
"d has a cyclic dependency via a"
}));
text = R"(
contract C {
uint constant a = b * c;
uint constant b = 7;
uint constant c = 4 + uint(keccak256(d));
uint constant d = 2 + b;
}
)";
CHECK_SUCCESS(text);
}

BOOST_AUTO_TEST_CASE(interface)
{
char const* text = R"(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract C {
uint constant a = a;
}
// ----
// TypeError: The value of the constant a has a cyclic dependency via a.
10 changes: 10 additions & 0 deletions test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
contract C {
uint constant a = b * c;
uint constant b = 7;
uint constant c = b + uint(keccak256(d));
uint constant d = 2 + a;
}
// ----
// TypeError: The value of the constant a has a cyclic dependency via c.
// TypeError: The value of the constant c has a cyclic dependency via d.
// TypeError: The value of the constant d has a cyclic dependency via a.
11 changes: 11 additions & 0 deletions test/libsolidity/syntaxTests/constants/cyclic_dependency_3.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
contract C {
uint constant x = a;
uint constant a = b * c;
uint constant b = c;
uint constant c = b;
}
// ----
// TypeError: The value of the constant x has a cyclic dependency via a.
// TypeError: The value of the constant a has a cyclic dependency via b.
// TypeError: The value of the constant b has a cyclic dependency via c.
// TypeError: The value of the constant c has a cyclic dependency via b.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
contract C {
uint constant a = b * c;
uint constant b = 7;
uint constant c = 4 + uint(keccak256(d));
uint constant d = 2 + b;
}

0 comments on commit 8fdbd19

Please sign in to comment.