mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add test for content of creationCode and runtimeCode.
This commit is contained in:
parent
29f6aa7d56
commit
2a0d4f358c
@ -14242,8 +14242,8 @@ BOOST_AUTO_TEST_CASE(code_access)
|
|||||||
uint crLen = type(D).creationCode.length;
|
uint crLen = type(D).creationCode.length;
|
||||||
uint runLen = type(D).runtimeCode.length;
|
uint runLen = type(D).runtimeCode.length;
|
||||||
require(runLen < crLen);
|
require(runLen < crLen);
|
||||||
require(crLen >= 0x95 && crLen < 0xd0);
|
require(crLen >= 0x20);
|
||||||
require(runLen >= 0x7a && runLen < 0xb0);
|
require(runLen >= 0x20);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
function creation() public pure returns (bytes memory) {
|
function creation() public pure returns (bytes memory) {
|
||||||
@ -14298,6 +14298,49 @@ BOOST_AUTO_TEST_CASE(code_access_create)
|
|||||||
ABI_CHECK(callContractFunction("test()"), encodeArgs(7));
|
ABI_CHECK(callContractFunction("test()"), encodeArgs(7));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(code_access_content)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract C {
|
||||||
|
function testRuntime() public returns (bool) {
|
||||||
|
D d = new D();
|
||||||
|
bytes32 runtimeHash = keccak256(type(D).runtimeCode);
|
||||||
|
bytes32 otherHash;
|
||||||
|
uint size;
|
||||||
|
assembly {
|
||||||
|
size := extcodesize(d)
|
||||||
|
extcodecopy(d, mload(0x40), 0, size)
|
||||||
|
otherHash := keccak256(mload(0x40), size)
|
||||||
|
}
|
||||||
|
require(size == type(D).runtimeCode.length);
|
||||||
|
require(runtimeHash == otherHash);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
function testCreation() public returns (bool) {
|
||||||
|
D d = new D();
|
||||||
|
bytes32 creationHash = keccak256(type(D).creationCode);
|
||||||
|
require(creationHash == d.x());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
contract D {
|
||||||
|
bytes32 public x;
|
||||||
|
constructor() public {
|
||||||
|
bytes32 codeHash;
|
||||||
|
assembly {
|
||||||
|
let size := codesize()
|
||||||
|
codecopy(mload(0x40), 0, size)
|
||||||
|
codeHash := keccak256(mload(0x40), size)
|
||||||
|
}
|
||||||
|
x = codeHash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
compileAndRun(sourceCode, 0, "C");
|
||||||
|
ABI_CHECK(callContractFunction("testRuntime()"), encodeArgs(true));
|
||||||
|
ABI_CHECK(callContractFunction("testCreation()"), encodeArgs(true));
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user