aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2016-08-17 22:43:13 +0800
committerGitHub <noreply@github.com>2016-08-17 22:43:13 +0800
commitd6579a0a5f99425eae95329b77e07ea072122924 (patch)
tree210f3cf17b58c674060d834c6ae2dfe3ec3cd17a /test/libsolidity/SolidityEndToEndTest.cpp
parent6baa982a6a95189af8199e719e62314b1073aa62 (diff)
parent34f9a59f18dcf8601d910aef599b2589dc080e2d (diff)
downloaddexon-solidity-d6579a0a5f99425eae95329b77e07ea072122924.tar.gz
dexon-solidity-d6579a0a5f99425eae95329b77e07ea072122924.tar.zst
dexon-solidity-d6579a0a5f99425eae95329b77e07ea072122924.zip
Merge pull request #888 from chriseth/throwOnDivZero
Throw on division by zero.
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 48cb29a1..f20ea2cb 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -6209,6 +6209,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"(