aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp21
-rw-r--r--test/libsolidity/SolidityExpressionCompiler.cpp8
2 files changed, 29 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"(
diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp
index 967b2907..e9a05745 100644
--- a/test/libsolidity/SolidityExpressionCompiler.cpp
+++ b/test/libsolidity/SolidityExpressionCompiler.cpp
@@ -323,7 +323,15 @@ BOOST_AUTO_TEST_CASE(arithmetics)
byte(Instruction::OR),
byte(Instruction::SUB),
byte(Instruction::ADD),
+ byte(Instruction::DUP2),
+ byte(Instruction::ISZERO),
+ byte(Instruction::PUSH1), 0x2,
+ byte(Instruction::JUMPI),
byte(Instruction::MOD),
+ byte(Instruction::DUP2),
+ byte(Instruction::ISZERO),
+ byte(Instruction::PUSH1), 0x2,
+ byte(Instruction::JUMPI),
byte(Instruction::DIV),
byte(Instruction::MUL)});
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());