diff options
author | chriseth <c@ethdev.com> | 2016-08-12 22:50:37 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-08-17 17:27:15 +0800 |
commit | e7084d9e16d0b370cab29d1f9ba08f07844b55f5 (patch) | |
tree | 2458f2cce57410fd6a8e5eb38d5792a48a8b8b9c /test | |
parent | e4578982c6e1a39ca3457ab1844be37b500dedda (diff) | |
download | dexon-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.cpp | 21 |
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"( |