Merge pull request #10754 from ethereum/extractTwoTests

Extract some tests.
This commit is contained in:
chriseth 2021-01-14 15:05:38 +01:00 committed by GitHub
commit e61c4b411e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 44 deletions

View File

@ -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<string, h160>{{"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.

View File

@ -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

View File

@ -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