aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-08-12 22:50:37 +0800
committerchriseth <c@ethdev.com>2016-08-17 17:27:15 +0800
commite7084d9e16d0b370cab29d1f9ba08f07844b55f5 (patch)
tree2458f2cce57410fd6a8e5eb38d5792a48a8b8b9c /test
parente4578982c6e1a39ca3457ab1844be37b500dedda (diff)
downloaddexon-solidity-e7084d9e16d0b370cab29d1f9ba08f07844b55f5.tar
dexon-solidity-e7084d9e16d0b370cab29d1f9ba08f07844b55f5.tar.gz
dexon-solidity-e7084d9e16d0b370cab29d1f9ba08f07844b55f5.tar.bz2
dexon-solidity-e7084d9e16d0b370cab29d1f9ba08f07844b55f5.tar.lz
dexon-solidity-e7084d9e16d0b370cab29d1f9ba08f07844b55f5.tar.xz
dexon-solidity-e7084d9e16d0b370cab29d1f9ba08f07844b55f5.tar.zst
dexon-solidity-e7084d9e16d0b370cab29d1f9ba08f07844b55f5.zip
Throw on division by zero.
Diffstat (limited to 'test')
-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 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"(