aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-10-05 21:23:25 +0800
committerchriseth <chris@ethereum.org>2017-11-30 08:20:21 +0800
commit19e067465a058ca9f40238cb3a928a1113531c9d (patch)
tree6b4f83892d5fd76194bd3794669cc59f02e86d37 /test
parentffb3a3c06c4d436aaf03efccf31301b472cd8137 (diff)
downloaddexon-solidity-19e067465a058ca9f40238cb3a928a1113531c9d.tar
dexon-solidity-19e067465a058ca9f40238cb3a928a1113531c9d.tar.gz
dexon-solidity-19e067465a058ca9f40238cb3a928a1113531c9d.tar.bz2
dexon-solidity-19e067465a058ca9f40238cb3a928a1113531c9d.tar.lz
dexon-solidity-19e067465a058ca9f40238cb3a928a1113531c9d.tar.xz
dexon-solidity-19e067465a058ca9f40238cb3a928a1113531c9d.tar.zst
dexon-solidity-19e067465a058ca9f40238cb3a928a1113531c9d.zip
Unary operators and division.
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SMTChecker.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/test/libsolidity/SMTChecker.cpp b/test/libsolidity/SMTChecker.cpp
index 667d666b..7aa555e9 100644
--- a/test/libsolidity/SMTChecker.cpp
+++ b/test/libsolidity/SMTChecker.cpp
@@ -458,6 +458,91 @@ BOOST_AUTO_TEST_CASE(for_loop)
CHECK_WARNING(text, "Assertion violation");
}
+BOOST_AUTO_TEST_CASE(division)
+{
+ string text = R"(
+ contract C {
+ function f(uint x, uint y) public pure returns (uint) {
+ return x / y;
+ }
+ }
+ )";
+ CHECK_WARNING(text, "Division by zero");
+ text = R"(
+ contract C {
+ function f(uint x, uint y) public pure returns (uint) {
+ require(y != 0);
+ return x / y;
+ }
+ }
+ )";
+ CHECK_SUCCESS_NO_WARNINGS(text);
+ text = R"(
+ contract C {
+ function f(int x, int y) public pure returns (int) {
+ require(y != 0);
+ return x / y;
+ }
+ }
+ )";
+ CHECK_WARNING(text, "Overflow");
+ text = R"(
+ contract C {
+ function f(int x, int y) public pure returns (int) {
+ require(y != 0);
+ require(y != -1);
+ return x / y;
+ }
+ }
+ )";
+ CHECK_SUCCESS_NO_WARNINGS(text);
+}
+
+BOOST_AUTO_TEST_CASE(division_truncates_correctly)
+{
+ string text = R"(
+ contract C {
+ function f(uint x, uint y) public pure {
+ x = 7;
+ y = 2;
+ assert(x / y == 3);
+ }
+ }
+ )";
+ CHECK_SUCCESS_NO_WARNINGS(text);
+ text = R"(
+ contract C {
+ function f(int x, int y) public pure {
+ x = 7;
+ y = 2;
+ assert(x / y == 3);
+ }
+ }
+ )";
+ CHECK_SUCCESS_NO_WARNINGS(text);
+ text = R"(
+ contract C {
+ function f(int x, int y) public pure {
+ x = -7;
+ y = 2;
+ assert(x / y == -3);
+ }
+ }
+ )";
+ CHECK_SUCCESS_NO_WARNINGS(text);
+ text = R"(
+ contract C {
+ function f(int x, int y) public pure {
+ x = -7;
+ y = -2;
+ int r = x / y;
+ assert(r == 3);
+ }
+ }
+ )";
+ CHECK_SUCCESS_NO_WARNINGS(text);
+}
+
BOOST_AUTO_TEST_SUITE_END()
}