Require and Assert.

This commit is contained in:
chriseth
2017-03-14 14:21:33 +01:00
parent 9aab3b8639
commit 47cd8964b8
7 changed files with 50 additions and 28 deletions
+24 -18
View File
@@ -9133,24 +9133,30 @@ BOOST_AUTO_TEST_CASE(invalid_instruction)
BOOST_CHECK(callContractFunction("f()") == encodeArgs());
}
//BOOST_AUTO_TEST_CASE(assert)
//{
// char const* sourceCode = R"(
// contract C {
// function f() {
// assert(false);
// }
// function g(bool val) returns (bool) {
// assert(val == true);
// return true;
// }
// }
// )";
// compileAndRun(sourceCode, 0, "C");
// BOOST_CHECK(callContractFunction("f()") == encodeArgs());
// BOOST_CHECK(callContractFunction("g(bool)", false) == encodeArgs());
// BOOST_CHECK(callContractFunction("g(bool)", true) == encodeArgs(true));
//}
BOOST_AUTO_TEST_CASE(assert_require)
{
char const* sourceCode = R"(
contract C {
function f() {
assert(false);
}
function g(bool val) returns (bool) {
assert(val == true);
return true;
}
function h(bool val) returns (bool) {
require(val);
return true;
}
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunction("f()") == encodeArgs());
BOOST_CHECK(callContractFunction("g(bool)", false) == encodeArgs());
BOOST_CHECK(callContractFunction("g(bool)", true) == encodeArgs(true));
BOOST_CHECK(callContractFunction("h(bool)", false) == encodeArgs());
BOOST_CHECK(callContractFunction("h(bool)", true) == encodeArgs(true));
}
BOOST_AUTO_TEST_CASE(revert)
{