mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Code generation for events.
This commit is contained in:
parent
a86a3a2452
commit
99a8f58ee3
@ -1955,6 +1955,57 @@ BOOST_AUTO_TEST_CASE(super_in_constructor)
|
|||||||
BOOST_CHECK(callContractFunction("f()") == encodeArgs(1 | 2 | 4 | 8));
|
BOOST_CHECK(callContractFunction("f()") == encodeArgs(1 | 2 | 4 | 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(event)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract ClientReceipt {
|
||||||
|
event Deposit(address indexed _from, hash indexed _id, uint _value);
|
||||||
|
function deposit(hash _id, bool _manually) {
|
||||||
|
if (_manually) {
|
||||||
|
hash s = 0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20;
|
||||||
|
log3(msg.value, s, hash(msg.sender), _id);
|
||||||
|
} else
|
||||||
|
Deposit(msg.sender, _id, msg.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
compileAndRun(sourceCode);
|
||||||
|
u256 value(18);
|
||||||
|
u256 id(0x1234);
|
||||||
|
for (bool manually: {true, false})
|
||||||
|
{
|
||||||
|
callContractFunctionWithValue("deposit(hash256,bool)", value, id, manually);
|
||||||
|
BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
|
||||||
|
BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
|
||||||
|
BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(value)));
|
||||||
|
BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 3);
|
||||||
|
BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::sha3(string("Deposit(address,hash256,uint256)")));
|
||||||
|
BOOST_CHECK_EQUAL(m_logs[0].topics[1], h256(m_sender));
|
||||||
|
BOOST_CHECK_EQUAL(m_logs[0].topics[2], h256(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(event_lots_of_data)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract ClientReceipt {
|
||||||
|
event Deposit(address _from, hash _id, uint _value, bool _flag);
|
||||||
|
function deposit(hash _id) {
|
||||||
|
Deposit(msg.sender, _id, msg.value, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
compileAndRun(sourceCode);
|
||||||
|
u256 value(18);
|
||||||
|
u256 id(0x1234);
|
||||||
|
callContractFunctionWithValue("deposit(hash256)", value, id);
|
||||||
|
BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
|
||||||
|
BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
|
||||||
|
BOOST_CHECK(m_logs[0].data == encodeArgs(m_sender, id, value, true));
|
||||||
|
BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
|
||||||
|
BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::sha3(string("Deposit(address,hash256,uint256,bool)")));
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,6 @@ public:
|
|||||||
bytes const& callContractFunctionWithValue(std::string _sig, u256 const& _value,
|
bytes const& callContractFunctionWithValue(std::string _sig, u256 const& _value,
|
||||||
Args const&... _arguments)
|
Args const&... _arguments)
|
||||||
{
|
{
|
||||||
|
|
||||||
FixedHash<4> hash(dev::sha3(_sig));
|
FixedHash<4> hash(dev::sha3(_sig));
|
||||||
sendMessage(hash.asBytes() + encodeArgs(_arguments...), false, _value);
|
sendMessage(hash.asBytes() + encodeArgs(_arguments...), false, _value);
|
||||||
return m_output;
|
return m_output;
|
||||||
|
Loading…
Reference in New Issue
Block a user