Implemented events with function type as one of its indexed parameters

This commit is contained in:
Harikrishnan Mulackal
2020-09-30 12:11:38 +02:00
parent 7a86a61b08
commit 3970412422
5 changed files with 89 additions and 5 deletions
+27
View File
@@ -2453,6 +2453,33 @@ BOOST_AUTO_TEST_CASE(event_indexed_string)
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("E(string,uint256[4])")));
}
BOOST_AUTO_TEST_CASE(event_indexed_function)
{
char const* sourceCode = R"(
contract C {
event Test(function() external indexed);
function f() public {
emit Test(this.f);
}
}
)";
compileAndRun(sourceCode);
callContractFunction("f()");
BOOST_REQUIRE_EQUAL(numLogs(), 1);
BOOST_CHECK_EQUAL(logAddress(0), m_contractAddress);
BOOST_CHECK(logData(0) == bytes());
BOOST_REQUIRE_EQUAL(numLogTopics(0), 2);
bytes functionHash = util::keccak256("f()").asBytes();
bytes address = m_contractAddress.asBytes();
bytes selector = bytes(functionHash.cbegin(), functionHash.cbegin() + 4);
bytes padding = bytes(8, 0);
bytes functionABI = address + selector + padding;
BOOST_CHECK_EQUAL(logTopic(0, 1).hex(), util::toHex(functionABI));
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("Test(function)")));
}
BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one)
{
char const* sourceCode = R"(
@@ -0,0 +1,6 @@
contract C {
event Test(function() external indexed);
function f() public {
emit Test(this.f);
}
}
@@ -0,0 +1,35 @@
library L {
function f() public {
int x = 1;
}
}
contract C {
event Test(function() external indexed);
function g() public {
Test(L.f);
}
}
contract D {
event Test(function() external);
function f() public {
Test(L.f);
}
}
contract E {
event Test(function() external indexed);
using L for D;
function k() public {
Test(D.f);
}
}
// ----
// TypeError 9553: (140-143): Invalid type for argument in function call. Invalid implicit conversion from function () to function () external requested.
// TypeError 9553: (230-233): Invalid type for argument in function call. Invalid implicit conversion from function () to function () external requested.
// TypeError 9553: (345-348): Invalid type for argument in function call. Invalid implicit conversion from function D.f() to function () external requested.