Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
randomnetcat committed Aug 8, 2018
1 parent 06baee1 commit 17524b3
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 1 deletion.
100 changes: 100 additions & 0 deletions test/libsolidity/SolidityEndToEndTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12835,6 +12835,106 @@ BOOST_AUTO_TEST_CASE(write_storage_external)
ABI_CHECK(callContractFunction("h()"), encodeArgs(12));
}

BOOST_AUTO_TEST_CASE(modifier_area_simple)
{
char const* sourceCode = R"(
contract C {
modifier A(uint x) { require(x == 0); _; }
apply A(0) {
function f() public returns (uint) { return 1; }
}
apply A(1) {
function g() public returns (uint) { return 2; }
}
}
)";
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("f()"), encodeArgs(1));
ABI_CHECK(callContractFunction("g()"), encodeArgs());
}

BOOST_AUTO_TEST_CASE(modifier_area_nested)
{
char const* sourceCode = R"(
contract C {
modifier A(uint x) { require(x == 0); _; }
apply A(0) {
function f() public returns (uint) { return 1; }
apply A(1) {
function g() public returns (uint) { return 2; }
}
}
}
)";
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("f()"), encodeArgs(1));
ABI_CHECK(callContractFunction("g()"), encodeArgs());
}

BOOST_AUTO_TEST_CASE(modifier_area_nested_inverted)
{
char const* sourceCode = R"(
contract C {
modifier A(uint x) { require(x == 0); _; }
apply A(1) {
function f() public returns (uint) { return 1; }
apply A(0) {
function g() public returns (uint) { return 2; }
}
}
}
)";
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("f()"), encodeArgs());
ABI_CHECK(callContractFunction("g()"), encodeArgs());
}

BOOST_AUTO_TEST_CASE(modifier_area_extra_modifiers)
{
char const* sourceCode = R"(
contract C {
modifier A(uint x) { require(x == 0); _;}
modifier B(uint x, uint y) { require(x == y); _;}
apply A(0) B(1,1) {
function f() public B(2,2) returns (uint) { return 1; }
}
apply A(0) B(1,1) {
function g() public B(1,2) returns (uint) { return 2; }
}
apply A(0) B(1,2) {
function h() public B(2,2) returns (uint) { return 3; }
}
apply A(1) B(1,1) {
function i() public B(2,2) returns (uint) { return 4; }
}
}
)";
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("f()"), encodeArgs(1));
ABI_CHECK(callContractFunction("g()"), encodeArgs());
ABI_CHECK(callContractFunction("h()"), encodeArgs());
ABI_CHECK(callContractFunction("i()"), encodeArgs());
}

BOOST_AUTO_TEST_CASE(modifier_area_mutability)
{
char const* sourceCode = R"(
contract C {
apply payable {
function f() returns (uint256) {
return msg.value;
}
}
}
)";
compileAndRun(sourceCode);
ABI_CHECK(callContractFunctionWithValue("f()", 1337), encodeArgs(1337));
}

BOOST_AUTO_TEST_SUITE_END()

}
Expand Down
1 change: 0 additions & 1 deletion test/libsolidity/SolidityParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ BOOST_AUTO_TEST_CASE(keyword_is_reserved)
"abstract",
"after",
"alias",
"apply",
"auto",
"case",
"catch",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract C {
modifier A { _; }
apply A {}
}
// ----
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
contract C {
modifier A { _; }
apply A {
function f() {}
function g() {}
}
}
// ----
// Warning: (57-72): No visibility specified. Defaulting to "public".
// Warning: (81-96): No visibility specified. Defaulting to "public".
// Warning: (57-72): Function state mutability can be restricted to pure
// Warning: (81-96): Function state mutability can be restricted to pure
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
contract C {
modifier A { _; }
apply A {
function f() {}
}
}
// ----
// Warning: (57-72): No visibility specified. Defaulting to "public".
// Warning: (57-72): Function state mutability can be restricted to pure
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
contract C {
apply pure {
function f() view {}
}
}
// ----
// ParserError: (51-55): Cannot override modifier area's state mutability.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
contract C {
apply pure {
apply payable {}
}
}
// ----
// ParserError: (44-51): Cannot override parent modifier area's state mutability of "pure".
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
contract C {
apply payable {}
}
// ----
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
contract C {
apply pure {
function f() {}
function g() {}
}
}
// ----
// Warning: (38-53): No visibility specified. Defaulting to "public".
// Warning: (62-77): No visibility specified. Defaulting to "public".
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
contract C {
apply pure {
function f() {}
}
}
// ----
// Warning: (38-53): No visibility specified. Defaulting to "public".
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
contract C {
apply public {
function f() private {}
}
}
// ----
// ParserError: (53-60): Cannot override modifier area's visibility.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
contract C {
apply public {
apply private {}
}
}
// ----
// ParserError: (46-53): Cannot override parent modifier area's visibility of "public".
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
contract C {
apply public {}
}
// ----
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
contract C {
apply internal {
function f() {}
function g() {}
}
}
// ----
// Warning: (42-57): Function state mutability can be restricted to pure
// Warning: (66-81): Function state mutability can be restricted to pure
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
contract C {
apply private {
function f() {}
}
}
// ----
// Warning: (41-56): Function state mutability can be restricted to pure

0 comments on commit 17524b3

Please sign in to comment.