diff options
author | chriseth <chris@ethereum.org> | 2019-01-17 21:58:31 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2019-01-18 03:36:48 +0800 |
commit | 2a0d4f358c6114740bb9fe063bc2620bd2d8724a (patch) | |
tree | c023dc4d5f7ddbd8edb7095ca004c682277da1c5 /test | |
parent | 29f6aa7d560a7d82a9088489e663a079a3b41f73 (diff) | |
download | dexon-solidity-2a0d4f358c6114740bb9fe063bc2620bd2d8724a.tar dexon-solidity-2a0d4f358c6114740bb9fe063bc2620bd2d8724a.tar.gz dexon-solidity-2a0d4f358c6114740bb9fe063bc2620bd2d8724a.tar.bz2 dexon-solidity-2a0d4f358c6114740bb9fe063bc2620bd2d8724a.tar.lz dexon-solidity-2a0d4f358c6114740bb9fe063bc2620bd2d8724a.tar.xz dexon-solidity-2a0d4f358c6114740bb9fe063bc2620bd2d8724a.tar.zst dexon-solidity-2a0d4f358c6114740bb9fe063bc2620bd2d8724a.zip |
Add test for content of creationCode and runtimeCode.
Diffstat (limited to 'test')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 6f420466..38be5ae7 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -14242,8 +14242,8 @@ BOOST_AUTO_TEST_CASE(code_access) uint crLen = type(D).creationCode.length; uint runLen = type(D).runtimeCode.length; require(runLen < crLen); - require(crLen >= 0x95 && crLen < 0xd0); - require(runLen >= 0x7a && runLen < 0xb0); + require(crLen >= 0x20); + require(runLen >= 0x20); return true; } function creation() public pure returns (bytes memory) { @@ -14298,6 +14298,49 @@ BOOST_AUTO_TEST_CASE(code_access_create) 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() } |