From bdf05bf8a0d980af299dc508cbe721b38a02a503 Mon Sep 17 00:00:00 2001 From: Djordje Mijovic Date: Fri, 6 Nov 2020 14:29:43 +0100 Subject: [PATCH] Moving try catch test to semantic tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 53 ------------------- .../tryCatch/try_catch_library_call.sol | 45 ++++++++++++++++ 2 files changed, 45 insertions(+), 53 deletions(-) create mode 100644 test/libsolidity/semanticTests/tryCatch/try_catch_library_call.sol diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index c497c46b2..3072d2038 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -6690,59 +6690,6 @@ BOOST_AUTO_TEST_CASE(dirty_scratch_space_prior_to_constant_optimiser) ); } -BOOST_AUTO_TEST_CASE(try_catch_library_call) -{ - char const* sourceCode = R"( - library L { - struct S { uint x; } - function integer(uint t, bool b) public view returns (uint) { - if (b) { - return t; - } else { - revert("failure"); - } - } - function stru(S storage t, bool b) public view returns (uint) { - if (b) { - return t.x; - } else { - revert("failure"); - } - } - } - contract C { - using L for L.S; - L.S t; - function f(bool b) public returns (uint, string memory) { - uint x = 8; - try L.integer(x, b) returns (uint _x) { - return (_x, ""); - } catch Error(string memory message) { - return (18, message); - } - } - function g(bool b) public returns (uint, string memory) { - t.x = 9; - try t.stru(b) returns (uint x) { - return (x, ""); - } catch Error(string memory message) { - return (19, message); - } - } - } - )"; - if (solidity::test::CommonOptions::get().evmVersion().supportsReturndata()) - { - compileAndRun(sourceCode, 0, "L", bytes()); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"L", m_contractAddress}}); - - ABI_CHECK(callContractFunction("f(bool)", true), encodeArgs(8, 0x40, 0)); - ABI_CHECK(callContractFunction("f(bool)", false), encodeArgs(18, 0x40, 7, "failure")); - ABI_CHECK(callContractFunction("g(bool)", true), encodeArgs(9, 0x40, 0)); - ABI_CHECK(callContractFunction("g(bool)", false), encodeArgs(19, 0x40, 7, "failure")); - } -} - BOOST_AUTO_TEST_CASE(strip_reason_strings) { char const* sourceCode = R"( diff --git a/test/libsolidity/semanticTests/tryCatch/try_catch_library_call.sol b/test/libsolidity/semanticTests/tryCatch/try_catch_library_call.sol new file mode 100644 index 000000000..e7bad76b0 --- /dev/null +++ b/test/libsolidity/semanticTests/tryCatch/try_catch_library_call.sol @@ -0,0 +1,45 @@ +library L { + struct S { uint x; } + function integer(uint t, bool b) public view returns (uint) { + if (b) { + return t; + } else { + revert("failure"); + } + } + function stru(S storage t, bool b) public view returns (uint) { + if (b) { + return t.x; + } else { + revert("failure"); + } + } +} +contract C { + using L for L.S; + L.S t; + function f(bool b) public returns (uint, string memory) { + uint x = 8; + try L.integer(x, b) returns (uint _x) { + return (_x, ""); + } catch Error(string memory message) { + return (18, message); + } + } + function g(bool b) public returns (uint, string memory) { + t.x = 9; + try t.stru(b) returns (uint x) { + return (x, ""); + } catch Error(string memory message) { + return (19, message); + } + } +} +// ==== +// EVMVersion: >=byzantium +// ---- +// library: L +// f(bool): true -> 8, 0x40, 0 +// f(bool): false -> 18, 0x40, 7, "failure" +// g(bool): true -> 9, 0x40, 0 +// g(bool): false -> 19, 0x40, 7, "failure"