Tests for revert with reason string.

This commit is contained in:
chriseth
2018-04-12 13:09:37 +02:00
parent 012ab37fe3
commit a06249c984
2 changed files with 53 additions and 1 deletions
+37
View File
@@ -10419,6 +10419,43 @@ BOOST_AUTO_TEST_CASE(revert)
ABI_CHECK(callContractFunction("a()"), encodeArgs(u256(42)));
}
BOOST_AUTO_TEST_CASE(revert_with_cause)
{
char const* sourceCode = R"(
contract D {
function f() public {
revert("test123");
}
function g() public {
revert("test1234567890123456789012345678901234567890");
}
}
contract C {
D d = new D();
function forward(address target, bytes data) internal returns (bool success, bytes retval) {
uint retsize;
assembly {
success := call(not(0), target, 0, add(data, 0x20), mload(data), 0, 0)
retsize := returndatasize()
}
retval = new bytes(retsize);
assembly {
returndatacopy(add(retval, 0x20), 0, returndatasize())
}
}
function f() public returns (bool, bytes) {
return forward(address(d), msg.data);
}
function g() public returns (bool, bytes) {
return forward(address(d), msg.data);
}
}
)";
compileAndRun(sourceCode, 0, "C");
ABI_CHECK(callContractFunction("f()"), encodeArgs(0, 0x40, 0x80, 0, 0x40, 7, "test123"));
ABI_CHECK(callContractFunction("g()"), encodeArgs(0, 0x40, 0xa0, 0, 0x40, 44, "test1234567890123456789012345678901234567890"));
}
BOOST_AUTO_TEST_CASE(negative_stack_height)
{
// This code was causing negative stack height during code generation