Merge pull request #10804 from ethereum/copyingBytesMultiassignSol2Yul

[Sol->Yul] Enabling copying_bytes_multiassign test via ir.
This commit is contained in:
chriseth 2021-01-18 13:23:47 +01:00 committed by GitHub
commit 6ac87a144e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 38 deletions

View File

@ -449,12 +449,11 @@ bool IRGeneratorForStatements::visit(Assignment const& _assignment)
writeToLValue(*m_currentLValue, value); writeToLValue(*m_currentLValue, value);
if ( if (dynamic_cast<ReferenceType const*>(&m_currentLValue->type))
m_currentLValue->type.category() != Type::Category::Struct && define(_assignment, readFromLValue(*m_currentLValue));
m_currentLValue->type.category() != Type::Category::Array && else if (*_assignment.annotation().type != *TypeProvider::emptyTuple())
*_assignment.annotation().type != *TypeProvider::emptyTuple()
)
define(_assignment, value); define(_assignment, value);
m_currentLValue.reset(); m_currentLValue.reset();
return false; return false;

View File

@ -2317,11 +2317,14 @@ BOOST_AUTO_TEST_CASE(bytes_from_calldata_to_memory)
} }
} }
)"; )";
compileAndRun(sourceCode); ALSO_VIA_YUL(
bytes calldata1 = FixedHash<4>(util::keccak256("f()")).asBytes() + bytes(61, 0x22) + bytes(12, 0x12); DISABLE_EWASM_TESTRUN();
sendMessage(calldata1, false); compileAndRun(sourceCode);
BOOST_CHECK(m_transactionSuccessful); bytes calldata1 = FixedHash<4>(util::keccak256("f()")).asBytes() + bytes(61, 0x22) + bytes(12, 0x12);
BOOST_CHECK(m_output == encodeArgs(util::keccak256(bytes{'a', 'b', 'c'} + calldata1))); sendMessage(calldata1, false);
BOOST_CHECK(m_transactionSuccessful);
BOOST_CHECK(m_output == encodeArgs(util::keccak256(bytes{'a', 'b', 'c'} + calldata1)));
);
} }
BOOST_AUTO_TEST_CASE(call_forward_bytes) BOOST_AUTO_TEST_CASE(call_forward_bytes)
@ -2342,15 +2345,18 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes)
bytes savedData; bytes savedData;
} }
)"; )";
compileAndRun(sourceCode, 0, "sender"); ALSO_VIA_YUL(
ABI_CHECK(callContractFunction("recv(uint256)", 7), bytes()); DISABLE_EWASM_TESTRUN();
ABI_CHECK(callContractFunction("val()"), encodeArgs(0)); compileAndRun(sourceCode, 0, "sender");
ABI_CHECK(callContractFunction("forward()"), encodeArgs(true)); ABI_CHECK(callContractFunction("recv(uint256)", 7), bytes());
ABI_CHECK(callContractFunction("val()"), encodeArgs(8)); ABI_CHECK(callContractFunction("val()"), encodeArgs(0));
ABI_CHECK(callContractFunction("clear()"), encodeArgs(true)); ABI_CHECK(callContractFunction("forward()"), encodeArgs(true));
ABI_CHECK(callContractFunction("val()"), encodeArgs(8)); ABI_CHECK(callContractFunction("val()"), encodeArgs(8));
ABI_CHECK(callContractFunction("forward()"), encodeArgs(true)); ABI_CHECK(callContractFunction("clear()"), encodeArgs(true));
ABI_CHECK(callContractFunction("val()"), encodeArgs(0x80)); ABI_CHECK(callContractFunction("val()"), encodeArgs(8));
ABI_CHECK(callContractFunction("forward()"), encodeArgs(true));
ABI_CHECK(callContractFunction("val()"), encodeArgs(0x80));
);
} }
BOOST_AUTO_TEST_CASE(call_forward_bytes_length) BOOST_AUTO_TEST_CASE(call_forward_bytes_length)
@ -2383,18 +2389,21 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes_length)
} }
} }
)"; )";
compileAndRun(sourceCode, 0, "sender"); ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN();
compileAndRun(sourceCode, 0, "sender");
// No additional data, just function selector // No additional data, just function selector
ABI_CHECK(callContractFunction("viaCalldata()"), encodeArgs(4)); ABI_CHECK(callContractFunction("viaCalldata()"), encodeArgs(4));
ABI_CHECK(callContractFunction("viaMemory()"), encodeArgs(4)); ABI_CHECK(callContractFunction("viaMemory()"), encodeArgs(4));
ABI_CHECK(callContractFunction("viaStorage()"), encodeArgs(4)); ABI_CHECK(callContractFunction("viaStorage()"), encodeArgs(4));
// Some additional unpadded data // Some additional unpadded data
bytes unpadded = asBytes(string("abc")); bytes unpadded = asBytes(string("abc"));
ABI_CHECK(callContractFunctionNoEncoding("viaCalldata()", unpadded), encodeArgs(7)); ABI_CHECK(callContractFunctionNoEncoding("viaCalldata()", unpadded), encodeArgs(7));
ABI_CHECK(callContractFunctionNoEncoding("viaMemory()", unpadded), encodeArgs(7)); ABI_CHECK(callContractFunctionNoEncoding("viaMemory()", unpadded), encodeArgs(7));
ABI_CHECK(callContractFunctionNoEncoding("viaStorage()", unpadded), encodeArgs(7)); ABI_CHECK(callContractFunctionNoEncoding("viaStorage()", unpadded), encodeArgs(7));
);
} }
BOOST_AUTO_TEST_CASE(copying_bytes_multiassign) BOOST_AUTO_TEST_CASE(copying_bytes_multiassign)
@ -2419,15 +2428,18 @@ BOOST_AUTO_TEST_CASE(copying_bytes_multiassign)
bytes savedData2; bytes savedData2;
} }
)"; )";
compileAndRun(sourceCode, 0, "sender"); ALSO_VIA_YUL(
ABI_CHECK(callContractFunction("recv(uint256)", 7), bytes()); DISABLE_EWASM_TESTRUN()
ABI_CHECK(callContractFunction("val()"), encodeArgs(0)); compileAndRun(sourceCode, 0, "sender");
ABI_CHECK(callContractFunction("forward(bool)", true), encodeArgs(true)); ABI_CHECK(callContractFunction("recv(uint256)", 7), bytes());
ABI_CHECK(callContractFunction("val()"), encodeArgs(8)); ABI_CHECK(callContractFunction("val()"), encodeArgs(0));
ABI_CHECK(callContractFunction("forward(bool)", false), encodeArgs(true)); ABI_CHECK(callContractFunction("forward(bool)", true), encodeArgs(true));
ABI_CHECK(callContractFunction("val()"), encodeArgs(16)); ABI_CHECK(callContractFunction("val()"), encodeArgs(8));
ABI_CHECK(callContractFunction("forward(bool)", true), encodeArgs(true)); ABI_CHECK(callContractFunction("forward(bool)", false), encodeArgs(true));
ABI_CHECK(callContractFunction("val()"), encodeArgs(0x80)); ABI_CHECK(callContractFunction("val()"), encodeArgs(16));
ABI_CHECK(callContractFunction("forward(bool)", true), encodeArgs(true));
ABI_CHECK(callContractFunction("val()"), encodeArgs(0x80));
);
} }
BOOST_AUTO_TEST_CASE(copy_from_calldata_removes_bytes_data) BOOST_AUTO_TEST_CASE(copy_from_calldata_removes_bytes_data)