mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[SMTChecker] Support to Bool variables
This commit is contained in:
@@ -329,6 +329,104 @@ BOOST_AUTO_TEST_CASE(ways_to_merge_variables)
|
||||
CHECK_WARNING(text, "Assertion violation happens here");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(bool_simple)
|
||||
{
|
||||
string text = R"(
|
||||
contract C {
|
||||
function f(bool x) public pure {
|
||||
assert(x);
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_WARNING(text, "Assertion violation happens here");
|
||||
text = R"(
|
||||
contract C {
|
||||
function f(bool x, bool y) public pure {
|
||||
assert(x == y);
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_WARNING(text, "Assertion violation happens here");
|
||||
text = R"(
|
||||
contract C {
|
||||
function f(bool x, bool y) public pure {
|
||||
bool z = x || y;
|
||||
assert(!(x && y) || z);
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS_NO_WARNINGS(text);
|
||||
text = R"(
|
||||
contract C {
|
||||
function f(bool x) public pure {
|
||||
if(x) {
|
||||
assert(x);
|
||||
} else {
|
||||
assert(!x);
|
||||
}
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS_NO_WARNINGS(text);
|
||||
text = R"(
|
||||
contract C {
|
||||
function f(bool x) public pure {
|
||||
bool y = x;
|
||||
assert(x == y);
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS_NO_WARNINGS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(bool_int_mixed)
|
||||
{
|
||||
string text = R"(
|
||||
contract C {
|
||||
function f(bool x) public pure {
|
||||
uint a;
|
||||
if(x)
|
||||
a = 1;
|
||||
assert(!x || a > 0);
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS_NO_WARNINGS(text);
|
||||
text = R"(
|
||||
contract C {
|
||||
function f(bool x, uint a) public pure {
|
||||
require(!x || a > 0);
|
||||
uint b = a;
|
||||
assert(!x || b > 0);
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS_NO_WARNINGS(text);
|
||||
text = R"(
|
||||
contract C {
|
||||
function f(bool x, bool y) public pure {
|
||||
uint a;
|
||||
if (x) {
|
||||
if (y) {
|
||||
a = 0;
|
||||
} else {
|
||||
a = 1;
|
||||
}
|
||||
} else {
|
||||
if (y) {
|
||||
a = 1;
|
||||
} else {
|
||||
a = 0;
|
||||
}
|
||||
}
|
||||
bool xor_x_y = (x && !y) || (!x && y);
|
||||
assert(!xor_x_y || a > 0);
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS_NO_WARNINGS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(while_loop_simple)
|
||||
{
|
||||
// Check that variables are cleared
|
||||
|
||||
Reference in New Issue
Block a user