aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-02-16 23:55:21 +0800
committerchriseth <chris@ethereum.org>2018-02-22 22:17:30 +0800
commit388718b59f604c944be6816ba50068014e563fb0 (patch)
tree0a3c4bf2b04a6aaba2c4beb40252617384159662 /test/libsolidity/SolidityEndToEndTest.cpp
parent8fc9535d43df26001f7b34488d073c06fc4fd358 (diff)
downloaddexon-solidity-388718b59f604c944be6816ba50068014e563fb0.tar.gz
dexon-solidity-388718b59f604c944be6816ba50068014e563fb0.tar.zst
dexon-solidity-388718b59f604c944be6816ba50068014e563fb0.zip
Introduce emit statement.
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index d2528a67..3882e4ea 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -2967,6 +2967,29 @@ BOOST_AUTO_TEST_CASE(event)
}
}
+BOOST_AUTO_TEST_CASE(event_emit)
+{
+ char const* sourceCode = R"(
+ contract ClientReceipt {
+ event Deposit(address indexed _from, bytes32 indexed _id, uint _value);
+ function deposit(bytes32 _id) payable {
+ emit Deposit(msg.sender, _id, msg.value);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ u256 value(18);
+ u256 id(0x1234);
+ callContractFunctionWithValue("deposit(bytes32)", value, id);
+ 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::keccak256(string("Deposit(address,bytes32,uint256)")));
+ BOOST_CHECK_EQUAL(m_logs[0].topics[1], h256(m_sender, h256::AlignRight));
+ BOOST_CHECK_EQUAL(m_logs[0].topics[2], h256(id));
+}
+
BOOST_AUTO_TEST_CASE(event_no_arguments)
{
char const* sourceCode = R"(
@@ -3009,6 +3032,28 @@ BOOST_AUTO_TEST_CASE(event_access_through_base_name)
BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("x()")));
}
+BOOST_AUTO_TEST_CASE(event_access_through_base_name_emit)
+{
+ char const* sourceCode = R"(
+ contract A {
+ event x();
+ }
+ contract B is A {
+ function f() returns (uint) {
+ emit A.x();
+ return 1;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ callContractFunction("f()");
+ BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
+ BOOST_CHECK(m_logs[0].data.empty());
+ BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("x()")));
+}
+
BOOST_AUTO_TEST_CASE(events_with_same_name)
{
char const* sourceCode = R"(
@@ -3107,6 +3152,58 @@ BOOST_AUTO_TEST_CASE(events_with_same_name_inherited)
BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit(address,uint256)")));
}
+BOOST_AUTO_TEST_CASE(events_with_same_name_inherited_emit)
+{
+ char const* sourceCode = R"(
+ contract A {
+ event Deposit();
+ }
+
+ contract B {
+ event Deposit(address _addr);
+ }
+
+ contract ClientReceipt is A, B {
+ event Deposit(address _addr, uint _amount);
+ function deposit() returns (uint) {
+ emit Deposit();
+ return 1;
+ }
+ function deposit(address _addr) returns (uint) {
+ emit Deposit(_addr);
+ return 1;
+ }
+ function deposit(address _addr, uint _amount) returns (uint) {
+ emit Deposit(_addr, _amount);
+ return 1;
+ }
+ }
+ )";
+ u160 const c_loggedAddress = m_contractAddress;
+
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("deposit()"), encodeArgs(u256(1)));
+ BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
+ BOOST_CHECK(m_logs[0].data.empty());
+ BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit()")));
+
+ ABI_CHECK(callContractFunction("deposit(address)", c_loggedAddress), encodeArgs(u256(1)));
+ BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
+ BOOST_CHECK(m_logs[0].data == encodeArgs(c_loggedAddress));
+ BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit(address)")));
+
+ ABI_CHECK(callContractFunction("deposit(address,uint256)", c_loggedAddress, u256(100)), encodeArgs(u256(1)));
+ BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
+ BOOST_CHECK(m_logs[0].data == encodeArgs(c_loggedAddress, 100));
+ BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit(address,uint256)")));
+}
+
BOOST_AUTO_TEST_CASE(event_anonymous)
{
char const* sourceCode = R"(