From e7084d9e16d0b370cab29d1f9ba08f07844b55f5 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 12 Aug 2016 16:50:37 +0200 Subject: Throw on division by zero. --- test/libsolidity/SolidityEndToEndTest.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 3920d948..647199ea 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -6208,6 +6208,27 @@ BOOST_AUTO_TEST_CASE(addmod_mulmod) BOOST_CHECK(callContractFunction("test()") == encodeArgs(u256(0))); } +BOOST_AUTO_TEST_CASE(divisiod_by_zero) +{ + char const* sourceCode = R"( + contract C { + function div(uint a, uint b) returns (uint) { + return a / b; + } + function mod(uint a, uint b) returns (uint) { + return a % b; + } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("div(uint256,uint256)", 7, 2) == encodeArgs(u256(3))); + // throws + BOOST_CHECK(callContractFunction("div(uint256,uint256)", 7, 0) == encodeArgs()); + BOOST_CHECK(callContractFunction("mod(uint256,uint256)", 7, 2) == encodeArgs(u256(1))); + // throws + BOOST_CHECK(callContractFunction("mod(uint256,uint256)", 7, 0) == encodeArgs()); +} + BOOST_AUTO_TEST_CASE(string_allocation_bug) { char const* sourceCode = R"( -- cgit