Implemented events with indexed function as parameter in Yul

This commit is contained in:
Harikrishnan Mulackal 2020-09-23 17:31:12 +02:00
parent 3970412422
commit fd02ccc68c
2 changed files with 32 additions and 13 deletions

View File

@ -929,6 +929,20 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
"(" << "(" <<
IRVariable(arg).commaSeparatedList() << IRVariable(arg).commaSeparatedList() <<
")"; ")";
else if (auto functionType = dynamic_cast<FunctionType const*>(paramTypes[i]))
{
solAssert(
IRVariable(arg).type() == *functionType &&
functionType->kind() == FunctionType::Kind::External &&
!functionType->bound(),
""
);
define(indexedArgs.emplace_back(m_context.newYulVariable(), *TypeProvider::fixedBytes(32))) <<
m_utils.combineExternalFunctionIdFunction() <<
"(" <<
IRVariable(arg).commaSeparatedList() <<
")\n";
}
else else
indexedArgs.emplace_back(convert(arg, *paramTypes[i])); indexedArgs.emplace_back(convert(arg, *paramTypes[i]));
} }

View File

@ -2463,21 +2463,26 @@ BOOST_AUTO_TEST_CASE(event_indexed_function)
} }
} }
)"; )";
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(); ALSO_VIA_YUL(
bytes address = m_contractAddress.asBytes(); DISABLE_EWASM_TESTRUN()
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)); compileAndRun(sourceCode);
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("Test(function)"))); 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) BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one)