diff options
author | Gav Wood <i@gavwood.com> | 2015-01-09 14:32:28 +0800 |
---|---|---|
committer | Gav Wood <i@gavwood.com> | 2015-01-09 14:32:28 +0800 |
commit | 541156241f5fa4848757a87aff2bb522632f3b77 (patch) | |
tree | 498b4350aaa1332f2e63cc5c1d05ba04f86ec6e1 /SolidityEndToEndTest.cpp | |
parent | a9680e8ffe8ebdc54bf7172b6412ce97c4d95dc7 (diff) | |
download | dexon-solidity-541156241f5fa4848757a87aff2bb522632f3b77.tar dexon-solidity-541156241f5fa4848757a87aff2bb522632f3b77.tar.gz dexon-solidity-541156241f5fa4848757a87aff2bb522632f3b77.tar.bz2 dexon-solidity-541156241f5fa4848757a87aff2bb522632f3b77.tar.lz dexon-solidity-541156241f5fa4848757a87aff2bb522632f3b77.tar.xz dexon-solidity-541156241f5fa4848757a87aff2bb522632f3b77.tar.zst dexon-solidity-541156241f5fa4848757a87aff2bb522632f3b77.zip |
Unit testing for log in Solidity.
Diffstat (limited to 'SolidityEndToEndTest.cpp')
-rw-r--r-- | SolidityEndToEndTest.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index 9559e370..2820b354 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -849,6 +849,98 @@ BOOST_AUTO_TEST_CASE(send_ether) BOOST_CHECK_EQUAL(m_state.balance(address), amount); } +BOOST_AUTO_TEST_CASE(log0) +{ + char const* sourceCode = "contract test {\n" + " function a() {\n" + " log0(1);\n" + " }\n" + "}\n"; + u256 amount(130); + compileAndRun(sourceCode, amount + 1); + u160 address(23); + callContractFunction(0, address, amount); + BOOST_CHECK_EQUAL(m_logs.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); + BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1))); + BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 0); +} + +BOOST_AUTO_TEST_CASE(log1) +{ + char const* sourceCode = "contract test {\n" + " function a() {\n" + " log1(1, 2);\n" + " }\n" + "}\n"; + u256 amount(130); + compileAndRun(sourceCode, amount + 1); + u160 address(23); + callContractFunction(0, address, amount); + BOOST_CHECK_EQUAL(m_logs.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); + BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1))); + BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].topics[0], h256(u256(2))); +} + +BOOST_AUTO_TEST_CASE(log2) +{ + char const* sourceCode = "contract test {\n" + " function a() {\n" + " log2(1, 2, 3);\n" + " }\n" + "}\n"; + u256 amount(130); + compileAndRun(sourceCode, amount + 1); + u160 address(23); + callContractFunction(0, address, amount); + BOOST_CHECK_EQUAL(m_logs.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); + BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1))); + BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 2); + for (unsigned i = 0; i < 2; ++i) + BOOST_CHECK_EQUAL(m_logs[0].topics[i], h256(u256(i + 2))); +} + +BOOST_AUTO_TEST_CASE(log3) +{ + char const* sourceCode = "contract test {\n" + " function a() {\n" + " log3(1, 2, 3, 4);\n" + " }\n" + "}\n"; + u256 amount(130); + compileAndRun(sourceCode, amount + 1); + u160 address(23); + callContractFunction(0, address, amount); + BOOST_CHECK_EQUAL(m_logs.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); + BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1))); + BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 3); + for (unsigned i = 0; i < 3; ++i) + BOOST_CHECK_EQUAL(m_logs[0].topics[i], h256(u256(i + 2))); +} + +BOOST_AUTO_TEST_CASE(log4) +{ + char const* sourceCode = "contract test {\n" + " function a() {\n" + " log4(1, 2, 3, 4, 5);\n" + " }\n" + "}\n"; + u256 amount(130); + compileAndRun(sourceCode, amount + 1); + u160 address(23); + callContractFunction(0, address, amount); + BOOST_CHECK_EQUAL(m_logs.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); + BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1))); + BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 4); + for (unsigned i = 0; i < 4; ++i) + BOOST_CHECK_EQUAL(m_logs[0].topics[i], h256(u256(i + 2))); +} + BOOST_AUTO_TEST_CASE(suicide) { char const* sourceCode = "contract test {\n" |