diff options
author | Yoichi Hirai <i@yoichihirai.com> | 2016-11-15 22:29:31 +0800 |
---|---|---|
committer | Yoichi Hirai <i@yoichihirai.com> | 2016-11-24 18:31:45 +0800 |
commit | d4173cd54a7012456267cbabbd6c809f0d6763cb (patch) | |
tree | c0ce1e6ec1be3aaab41b1d051a873d986ae48aa3 | |
parent | d49904c92a890b058a46031c0c872f7b4abe936b (diff) | |
download | dexon-solidity-d4173cd54a7012456267cbabbd6c809f0d6763cb.tar.gz dexon-solidity-d4173cd54a7012456267cbabbd6c809f0d6763cb.tar.zst dexon-solidity-d4173cd54a7012456267cbabbd6c809f0d6763cb.zip |
test: add a test about trying to log an event with too big enum values
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index c7c627be..8b1c4836 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -4539,6 +4539,40 @@ BOOST_AUTO_TEST_CASE(invalid_enum_compared) BOOST_CHECK(callContractFunction("test_neq()") == encodeArgs()); } +BOOST_AUTO_TEST_CASE(invalid_enum_logged) +{ + char const* sourceCode = R"( + contract C { + enum X { A, B } + event Log(X); + + function test_log() returns (uint) { + X garbled = X.A; + assembly { + garbled := 5 + } + Log(garbled); + return 1; + } + function test_log_ok() returns (uint) { + X x = X.A; + Log(x); + return 1; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("test_log_ok()") == encodeArgs(u256(1))); + BOOST_REQUIRE_EQUAL(m_logs.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); + BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); + BOOST_REQUIRE_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Log(uint8)"))); + BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(0))); + + // should throw + BOOST_CHECK(callContractFunction("test_log()") == encodeArgs()); +} + BOOST_AUTO_TEST_CASE(invalid_enum_as_external_ret) { char const* sourceCode = R"( |