From fb4b38a78e366da1b7e38c8d889921e0e9a21d40 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 13 Jan 2021 15:35:55 +0100 Subject: [PATCH] Extract some tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 44 ------------------- .../functionCall/failed_create.sol | 28 ++++++++++++ .../libraries/using_for_function_on_int.sol | 14 ++++++ 3 files changed, 42 insertions(+), 44 deletions(-) create mode 100644 test/libsolidity/semanticTests/functionCall/failed_create.sol create mode 100644 test/libsolidity/semanticTests/libraries/using_for_function_on_int.sol diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 604e83412..ddc34888c 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3989,22 +3989,6 @@ BOOST_AUTO_TEST_CASE(create_memory_array_allocation_size) } } -BOOST_AUTO_TEST_CASE(using_for_function_on_int) -{ - char const* sourceCode = R"( - library D { function double(uint self) public returns (uint) { return 2*self; } } - contract C { - using D for uint; - function f(uint a) public returns (uint) { - return a.double(); - } - } - )"; - compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); - ABI_CHECK(callContractFunction("f(uint256)", u256(9)), encodeArgs(u256(2 * 9))); -} - BOOST_AUTO_TEST_CASE(using_for_function_on_struct) { char const* sourceCode = R"( @@ -4176,34 +4160,6 @@ BOOST_AUTO_TEST_CASE(index_access_with_type_conversion) BOOST_CHECK(callContractFunction("f(uint256)", u256(0x101)).size() == 256 * 32); } -BOOST_AUTO_TEST_CASE(failed_create) -{ - char const* sourceCode = R"( - contract D { constructor() payable {} } - contract C { - uint public x; - constructor() payable {} - function f(uint amount) public returns (D) { - x++; - return (new D){value: amount}(); - } - function stack(uint depth) public returns (address) { - if (depth < 1024) - return this.stack(depth - 1); - else - return address(f(0)); - } - } - )"; - compileAndRun(sourceCode, 20, "C"); - BOOST_CHECK(callContractFunction("f(uint256)", 20) != encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(1))); - ABI_CHECK(callContractFunction("f(uint256)", 20), encodeArgs()); - ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(1))); - ABI_CHECK(callContractFunction("stack(uint256)", 1023), encodeArgs()); - ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(1))); -} - BOOST_AUTO_TEST_CASE(correctly_initialize_memory_array_in_constructor) { // Memory arrays are initialized using calldatacopy past the size of the calldata. diff --git a/test/libsolidity/semanticTests/functionCall/failed_create.sol b/test/libsolidity/semanticTests/functionCall/failed_create.sol new file mode 100644 index 000000000..6a567293c --- /dev/null +++ b/test/libsolidity/semanticTests/functionCall/failed_create.sol @@ -0,0 +1,28 @@ +contract D { constructor() payable {} } +contract C { + uint public x; + constructor() payable {} + function f(uint amount) public returns (D) { + x++; + return (new D){value: amount}(); + } + function stack(uint depth) public payable returns (address) { + if (depth > 0) + return this.stack(depth - 1); + else + return address(f(0)); + } +} +// ==== +// compileViaYul: also +// EVMVersion: >=byzantium +// ---- +// constructor(), 20 wei +// f(uint256): 20 -> 1370859564726510389319704988634906228201275401179 +// x() -> 1 +// f(uint256): 20 -> FAILURE +// x() -> 1 +// stack(uint256): 1023 -> FAILURE +// x() -> 1 +// stack(uint256): 10 -> 693016686122178122849713379390321835634789309880 +// x() -> 2 diff --git a/test/libsolidity/semanticTests/libraries/using_for_function_on_int.sol b/test/libsolidity/semanticTests/libraries/using_for_function_on_int.sol new file mode 100644 index 000000000..ffa07acc1 --- /dev/null +++ b/test/libsolidity/semanticTests/libraries/using_for_function_on_int.sol @@ -0,0 +1,14 @@ +library D { + function double(uint self) public returns (uint) { return 2 * self; } +} +contract C { + using D for uint; + function f(uint a) public returns (uint) { + return a.double(); + } +} +// ==== +// compileViaYul: also +// ---- +// library: D +// f(uint256): 9 -> 18