aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-06-27 19:15:51 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-09-13 18:40:57 +0800
commit88946f9f03625fab345572c66b33ee3e05a07159 (patch)
tree329ca01f3e44018d0c3b328b155ddae8554649e9 /test/libsolidity
parent58f7a27ee0336423fa7dc76b8a160b78301bbdd2 (diff)
downloaddexon-solidity-88946f9f03625fab345572c66b33ee3e05a07159.tar
dexon-solidity-88946f9f03625fab345572c66b33ee3e05a07159.tar.gz
dexon-solidity-88946f9f03625fab345572c66b33ee3e05a07159.tar.bz2
dexon-solidity-88946f9f03625fab345572c66b33ee3e05a07159.tar.lz
dexon-solidity-88946f9f03625fab345572c66b33ee3e05a07159.tar.xz
dexon-solidity-88946f9f03625fab345572c66b33ee3e05a07159.tar.zst
dexon-solidity-88946f9f03625fab345572c66b33ee3e05a07159.zip
Add tests for function type sigs
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp24
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp81
2 files changed, 105 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 73dd7d22..f3d0fde3 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -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()
}
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 1fbc55a2..6576634f 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -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"(