aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-02-15 20:04:40 +0800
committerchriseth <chris@ethereum.org>2018-02-15 20:52:17 +0800
commit2b5a5a8669cee8698f3f2cf970417a7123fbbe25 (patch)
treeeb5d78372cd7f849d7a6a2bc49cbb1280bf78ecc /test
parent5746e2d7d867440780ced524dd7e7c29149cf3e2 (diff)
downloaddexon-solidity-2b5a5a8669cee8698f3f2cf970417a7123fbbe25.tar.gz
dexon-solidity-2b5a5a8669cee8698f3f2cf970417a7123fbbe25.tar.zst
dexon-solidity-2b5a5a8669cee8698f3f2cf970417a7123fbbe25.zip
Make addmod and mulmod revert if the last argument is zero.
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 0611e71d..4d20f4f5 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -7459,6 +7459,33 @@ BOOST_AUTO_TEST_CASE(addmod_mulmod)
ABI_CHECK(callContractFunction("test()"), encodeArgs(u256(0)));
}
+BOOST_AUTO_TEST_CASE(addmod_mulmod_zero)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f() pure returns (uint) {
+ addmod(1, 2, 0);
+ return 2;
+ }
+ function g() pure returns (uint) {
+ mulmod(1, 2, 0);
+ return 2;
+ }
+ function h() pure returns (uint) {
+ mulmod(0, 1, 2);
+ mulmod(1, 0, 2);
+ addmod(0, 1, 2);
+ addmod(1, 0, 2);
+ return 2;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("f()"), encodeArgs());
+ ABI_CHECK(callContractFunction("g()"), encodeArgs());
+ ABI_CHECK(callContractFunction("h()"), encodeArgs(2));
+}
+
BOOST_AUTO_TEST_CASE(divisiod_by_zero)
{
char const* sourceCode = R"(