Add tests for function type sigs

This commit is contained in:
Alex Beregszaszi 2017-06-27 12:15:51 +01:00
parent 58f7a27ee0
commit 88946f9f03
2 changed files with 105 additions and 0 deletions

View File

@ -10051,6 +10051,30 @@ BOOST_AUTO_TEST_CASE(delegatecall_return_value)
BOOST_CHECK(callContractFunction("get_delegated()") == encodeArgs(u256(1)));
}
BOOST_AUTO_TEST_CASE(function_types_sig)
{
char const* sourceCode = R"(
contract C {
function f() returns (bytes4) {
return this.f.sig;
}
function g() returns (bytes4) {
function () external returns (bytes4) fun = this.f;
return fun.sig;
}
function h() returns (bytes4) {
function () external returns (bytes4) fun = this.f;
var funvar = fun;
return funvar.sig;
}
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunction("f()") == fromHex("0x26121ff0"));
BOOST_CHECK(callContractFunction("g()") == fromHex("0x26121ff0"));
BOOST_CHECK(callContractFunction("h()") == fromHex("0x26121ff0"));
}
BOOST_AUTO_TEST_SUITE_END()
}

View File

@ -6285,6 +6285,87 @@ BOOST_AUTO_TEST_CASE(modifiers_access_storage_pointer)
CHECK_SUCCESS_NO_WARNINGS(text);
}
BOOST_AUTO_TEST_CASE(function_types_sig)
{
char const* text = R"(
contract C {
function f() returns (bytes4) {
return f.sig;
}
}
)";
CHECK_ERROR(text, TypeError, "Member \"sig\" not found");
text = R"(
contract C {
function g() internal {
}
function f() returns (bytes4) {
return g.sig;
}
}
)";
CHECK_ERROR(text, TypeError, "Member \"sig\" not found");
text = R"(
contract C {
function f() returns (bytes4) {
function () g;
return g.sig;
}
}
)";
CHECK_ERROR(text, TypeError, "Member \"sig\" not found");
text = R"(
contract C {
function f() returns (bytes4) {
return this.f.sig;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
text = R"(
contract C {
function f() external returns (bytes4) {
return this.f.sig;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
text = R"(
contract C {
function h() external {
}
function f() external returns (bytes4) {
var g = this.h;
return g.sig;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
text = R"(
contract C {
function h() external {
}
function f() external returns (bytes4) {
function () external g = this.h;
return g.sig;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
text = R"(
contract C {
function h() external {
}
function f() external returns (bytes4) {
function () external g = this.h;
var i = g;
return i.sig;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
}
BOOST_AUTO_TEST_CASE(using_this_in_constructor)
{
char const* text = R"(