mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
commit
7925610ab4
@ -1955,6 +1955,57 @@ BOOST_AUTO_TEST_CASE(super_in_constructor)
|
||||
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, hash32(msg.sender), _id);
|
||||
} else
|
||||
Deposit(hash32(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, hash32(_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()
|
||||
|
||||
}
|
||||
|
@ -680,6 +680,49 @@ BOOST_AUTO_TEST_CASE(private_state_variable)
|
||||
BOOST_CHECK_MESSAGE(function == nullptr, "Accessor function of a private variable should not exist");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(event)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract c {
|
||||
event e(uint indexed a, string3 indexed s, bool indexed b);
|
||||
function f() { e(2, "abc", true); }
|
||||
})";
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(event_too_many_indexed)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract c {
|
||||
event e(uint indexed a, string3 indexed b, bool indexed c, uint indexed d);
|
||||
function f() { e(2, "abc", true); }
|
||||
})";
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(event_call)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract c {
|
||||
event e(uint a, string3 indexed s, bool indexed b);
|
||||
function f() { e(2, "abc", true); }
|
||||
})";
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(event_inheritance)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract base {
|
||||
event e(uint a, string3 indexed s, bool indexed b);
|
||||
}
|
||||
contract c is base {
|
||||
function f() { e(2, "abc", true); }
|
||||
})";
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
@ -586,6 +586,33 @@ BOOST_AUTO_TEST_CASE(modifier_invocation)
|
||||
BOOST_CHECK_NO_THROW(parseText(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(event)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract c {
|
||||
event e();
|
||||
})";
|
||||
BOOST_CHECK_NO_THROW(parseText(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(event_arguments)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract c {
|
||||
event e(uint a, string32 s);
|
||||
})";
|
||||
BOOST_CHECK_NO_THROW(parseText(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(event_arguments_indexed)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract c {
|
||||
event e(uint a, string32 indexed s, bool indexed b);
|
||||
})";
|
||||
BOOST_CHECK_NO_THROW(parseText(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
@ -67,7 +67,6 @@ public:
|
||||
bytes const& callContractFunctionWithValue(std::string _sig, u256 const& _value,
|
||||
Args const&... _arguments)
|
||||
{
|
||||
|
||||
FixedHash<4> hash(dev::sha3(_sig));
|
||||
sendMessage(hash.asBytes() + encodeArgs(_arguments...), false, _value);
|
||||
return m_output;
|
||||
|
Loading…
Reference in New Issue
Block a user