From 0e85e35a7f5f8129672ac02b38771749f4e5d456 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Tue, 18 Oct 2016 16:05:16 +0200 Subject: test: Add an end-to-end test about multiple events of the same name See #1215 --- test/libsolidity/SolidityEndToEndTest.cpp | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 19161831..2411e7ff 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2792,6 +2792,47 @@ 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(events_with_same_name) +{ + char const* sourceCode = R"( + contract ClientReceipt { + event Deposit; + event Deposit(address _addr); + event Deposit(address _addr, uint _amount); + function deposit() { + Deposit(); + } + function deposit(address _addr) { + Deposit(_addr); + } + function deposit(address _addr, uint _amount) { + Deposit(_addr, _amount); + } + } + )"; + compileAndRun(sourceCode); + callContractFunction("deposit()"); + 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()"))); + + callContractFunction("deposit(0xabcdeabcdeabcdeabcde)"); + BOOST_REQUIRE_EQUAL(m_logs.size(), 2); + BOOST_CHECK_EQUAL(m_logs[1].address, m_contractAddress); + BOOST_CHECK(m_logs[1].data == encodeArgs(0)); + BOOST_REQUIRE_EQUAL(m_logs[1].topics.size(), 1); + BOOST_CHECK_EQUAL(m_logs[1].topics[0], dev::keccak256(string("Deposit(address)"))); + + callContractFunction("deposit(0xabcdeabcdeabcdeabcde, 100)"); + BOOST_REQUIRE_EQUAL(m_logs.size(), 3); + BOOST_CHECK_EQUAL(m_logs[2].address, m_contractAddress); + BOOST_CHECK(m_logs[2].data == encodeArgs(0,100)); + BOOST_REQUIRE_EQUAL(m_logs[2].topics.size(), 1); + BOOST_CHECK_EQUAL(m_logs[2].topics[0], dev::keccak256(string("Deposit(address,uint256)"))); +} + BOOST_AUTO_TEST_CASE(event_anonymous) { char const* sourceCode = R"( -- cgit From 133d1c05e1ea1ae505e84df4c0660942f614bb3a Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Wed, 19 Oct 2016 19:51:12 +0200 Subject: test: fixing inconsistent usage of end-to-end test framework --- test/libsolidity/SolidityEndToEndTest.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 2411e7ff..6163790b 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2761,6 +2761,7 @@ BOOST_AUTO_TEST_CASE(event_no_arguments) } } )"; + compileAndRun(sourceCode); callContractFunction("deposit()"); BOOST_REQUIRE_EQUAL(m_logs.size(), 1); @@ -2810,6 +2811,8 @@ BOOST_AUTO_TEST_CASE(events_with_same_name) } } )"; + u160 const c_loggedAddress = m_contractAddress; + compileAndRun(sourceCode); callContractFunction("deposit()"); BOOST_REQUIRE_EQUAL(m_logs.size(), 1); @@ -2818,17 +2821,17 @@ BOOST_AUTO_TEST_CASE(events_with_same_name) BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit()"))); - callContractFunction("deposit(0xabcdeabcdeabcdeabcde)"); + callContractFunction("deposit(address)", c_loggedAddress); BOOST_REQUIRE_EQUAL(m_logs.size(), 2); BOOST_CHECK_EQUAL(m_logs[1].address, m_contractAddress); - BOOST_CHECK(m_logs[1].data == encodeArgs(0)); + BOOST_CHECK(m_logs[1].data == encodeArgs(c_loggedAddress)); BOOST_REQUIRE_EQUAL(m_logs[1].topics.size(), 1); BOOST_CHECK_EQUAL(m_logs[1].topics[0], dev::keccak256(string("Deposit(address)"))); - callContractFunction("deposit(0xabcdeabcdeabcdeabcde, 100)"); + callContractFunction("deposit(address, uint256)", c_loggedAddress, u256(100)); BOOST_REQUIRE_EQUAL(m_logs.size(), 3); BOOST_CHECK_EQUAL(m_logs[2].address, m_contractAddress); - BOOST_CHECK(m_logs[2].data == encodeArgs(0,100)); + BOOST_CHECK(m_logs[2].data == encodeArgs(c_loggedAddress, 100)); BOOST_REQUIRE_EQUAL(m_logs[2].topics.size(), 1); BOOST_CHECK_EQUAL(m_logs[2].topics[0], dev::keccak256(string("Deposit(address,uint256)"))); } -- cgit From 4c09e81c3e60ddc43709656f9be4f991360b4108 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Wed, 19 Oct 2016 20:16:28 +0200 Subject: test: check the results of function calls in the test for multiple events of the same name --- test/libsolidity/SolidityEndToEndTest.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 6163790b..81cedfb0 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2800,35 +2800,38 @@ BOOST_AUTO_TEST_CASE(events_with_same_name) event Deposit; event Deposit(address _addr); event Deposit(address _addr, uint _amount); - function deposit() { + function deposit() returns (uint) { Deposit(); + return 1; } - function deposit(address _addr) { + function deposit(address _addr) returns (uint) { Deposit(_addr); + return 1; } - function deposit(address _addr, uint _amount) { + function deposit(address _addr, uint _amount) returns (uint) { Deposit(_addr, _amount); + return 1; } } )"; u160 const c_loggedAddress = m_contractAddress; compileAndRun(sourceCode); - callContractFunction("deposit()"); + BOOST_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()"))); - callContractFunction("deposit(address)", c_loggedAddress); + BOOST_CHECK(callContractFunction("deposit(address)", c_loggedAddress) == encodeArgs(u256(1))); BOOST_REQUIRE_EQUAL(m_logs.size(), 2); BOOST_CHECK_EQUAL(m_logs[1].address, m_contractAddress); BOOST_CHECK(m_logs[1].data == encodeArgs(c_loggedAddress)); BOOST_REQUIRE_EQUAL(m_logs[1].topics.size(), 1); BOOST_CHECK_EQUAL(m_logs[1].topics[0], dev::keccak256(string("Deposit(address)"))); - callContractFunction("deposit(address, uint256)", c_loggedAddress, u256(100)); + BOOST_CHECK(callContractFunction("deposit(address,uint256)", c_loggedAddress, u256(100)) == encodeArgs(u256(1))); BOOST_REQUIRE_EQUAL(m_logs.size(), 3); BOOST_CHECK_EQUAL(m_logs[2].address, m_contractAddress); BOOST_CHECK(m_logs[2].data == encodeArgs(c_loggedAddress, 100)); -- cgit From 567139486f45f69b22beb846fde7c9b27e1ebce0 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 2 Dec 2016 18:58:50 +0100 Subject: test: somehow log counting system has changed --- test/libsolidity/SolidityEndToEndTest.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 81cedfb0..c29ae6fc 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2825,18 +2825,18 @@ BOOST_AUTO_TEST_CASE(events_with_same_name) BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit()"))); BOOST_CHECK(callContractFunction("deposit(address)", c_loggedAddress) == encodeArgs(u256(1))); - BOOST_REQUIRE_EQUAL(m_logs.size(), 2); - BOOST_CHECK_EQUAL(m_logs[1].address, m_contractAddress); - BOOST_CHECK(m_logs[1].data == encodeArgs(c_loggedAddress)); - BOOST_REQUIRE_EQUAL(m_logs[1].topics.size(), 1); - BOOST_CHECK_EQUAL(m_logs[1].topics[0], dev::keccak256(string("Deposit(address)"))); + 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)"))); BOOST_CHECK(callContractFunction("deposit(address,uint256)", c_loggedAddress, u256(100)) == encodeArgs(u256(1))); - BOOST_REQUIRE_EQUAL(m_logs.size(), 3); - BOOST_CHECK_EQUAL(m_logs[2].address, m_contractAddress); - BOOST_CHECK(m_logs[2].data == encodeArgs(c_loggedAddress, 100)); - BOOST_REQUIRE_EQUAL(m_logs[2].topics.size(), 1); - BOOST_CHECK_EQUAL(m_logs[2].topics[0], dev::keccak256(string("Deposit(address,uint256)"))); + 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) -- cgit From 8dc306d62b1d7ef2816187175958ce4edab0170c Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 20 Jan 2017 14:11:06 +0100 Subject: test: add a test case about inheriting multiple events of the same name --- test/libsolidity/SolidityEndToEndTest.cpp | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index c29ae6fc..b2b5a25e 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2839,6 +2839,58 @@ BOOST_AUTO_TEST_CASE(events_with_same_name) BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit(address,uint256)"))); } +BOOST_AUTO_TEST_CASE(events_with_same_name_inherited) +{ + 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) { + Deposit(); + return 1; + } + function deposit(address _addr) returns (uint) { + Deposit(_addr); + return 1; + } + function deposit(address _addr, uint _amount) returns (uint) { + Deposit(_addr, _amount); + return 1; + } + } + )"; + u160 const c_loggedAddress = m_contractAddress; + + compileAndRun(sourceCode); + BOOST_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()"))); + + BOOST_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)"))); + + BOOST_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"( -- cgit