aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-12-30 21:35:45 +0800
committerchriseth <chris@ethereum.org>2018-04-12 19:09:37 +0800
commitae1d040285d97c2be0eb9d3e94a983975459f879 (patch)
tree6431baa6efc9e58f76fa8ae2dc1a9468388628ec /test/libsolidity
parent3da16b3e8af41a1d743a94d2e19822e82440a63d (diff)
downloaddexon-solidity-ae1d040285d97c2be0eb9d3e94a983975459f879.tar
dexon-solidity-ae1d040285d97c2be0eb9d3e94a983975459f879.tar.gz
dexon-solidity-ae1d040285d97c2be0eb9d3e94a983975459f879.tar.bz2
dexon-solidity-ae1d040285d97c2be0eb9d3e94a983975459f879.tar.lz
dexon-solidity-ae1d040285d97c2be0eb9d3e94a983975459f879.tar.xz
dexon-solidity-ae1d040285d97c2be0eb9d3e94a983975459f879.tar.zst
dexon-solidity-ae1d040285d97c2be0eb9d3e94a983975459f879.zip
Allow error string for ``require``.
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 82ad2917..b6b26f49 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -10456,6 +10456,62 @@ BOOST_AUTO_TEST_CASE(revert_with_cause)
ABI_CHECK(callContractFunction("g()"), encodeArgs(0, 0x40, 0xa0, 0, 0x40, 44, "test1234567890123456789012345678901234567890"));
}
+BOOST_AUTO_TEST_CASE(require_with_message)
+{
+ char const* sourceCode = R"(
+ contract D {
+ bool flag = false;
+ string storageError = "abc";
+ function f(uint x) public {
+ require(x > 7, "failed");
+ }
+ function g() public {
+ // As a side-effect of internalFun, the flag will be set to true
+ // (even if the condition is true),
+ // but it will only throw in the next evaluation.
+ bool flagCopy = flag;
+ require(flagCopy == false, internalFun());
+ }
+ function internalFun() returns (string) {
+ flag = true;
+ return "only on second run";
+ }
+ function h() public {
+ require(false, storageError);
+ }
+ }
+ 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(uint x) public returns (bool, bytes) {
+ return forward(address(d), msg.data);
+ }
+ function g() public returns (bool, bytes) {
+ return forward(address(d), msg.data);
+ }
+ function h() public returns (bool, bytes) {
+ return forward(address(d), msg.data);
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("f(uint256)", 8), encodeArgs(1, 0x40, 0));
+ ABI_CHECK(callContractFunction("f(uint256)", 5), encodeArgs(0, 0x40, 0x80, 0, 0x40, 6, "failed"));
+ ABI_CHECK(callContractFunction("g()"), encodeArgs(1, 0x40, 0));
+ ABI_CHECK(callContractFunction("g()"), encodeArgs(0, 0x40, 0x80, 0, 0x40, 18 , "only on second run"));
+ ABI_CHECK(callContractFunction("h()"), encodeArgs(0, 0x40, 0x80, 0, 0x40, 3, "abc"));
+}
+
BOOST_AUTO_TEST_CASE(negative_stack_height)
{
// This code was causing negative stack height during code generation