aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2019-01-10 19:11:55 +0800
committerchriseth <chris@ethereum.org>2019-01-18 03:36:48 +0800
commit44237211d1032c739636ab60a558521d60023b88 (patch)
treec308b23d77514733c9e2e35591411557a1924451 /test/libsolidity/SolidityEndToEndTest.cpp
parent6de10cb9da3a81befb050ba9b883bfd4b0524cf6 (diff)
downloaddexon-solidity-44237211d1032c739636ab60a558521d60023b88.tar.gz
dexon-solidity-44237211d1032c739636ab60a558521d60023b88.tar.zst
dexon-solidity-44237211d1032c739636ab60a558521d60023b88.zip
Tests.
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 8d219d16..6f420466 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -14234,6 +14234,70 @@ BOOST_AUTO_TEST_CASE(base_access_to_function_type_variables)
ABI_CHECK(callContractFunction("h()"), encodeArgs(2));
}
+BOOST_AUTO_TEST_CASE(code_access)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function lengths() public pure returns (bool) {
+ 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);
+ return true;
+ }
+ function creation() public pure returns (bytes memory) {
+ return type(D).creationCode;
+ }
+ function runtime() public pure returns (bytes memory) {
+ return type(D).runtimeCode;
+ }
+ function runtimeAllocCheck() public pure returns (bytes memory) {
+ uint[] memory a = new uint[](2);
+ bytes memory c = type(D).runtimeCode;
+ uint[] memory b = new uint[](2);
+ a[0] = 0x1111;
+ a[1] = 0x2222;
+ b[0] = 0x3333;
+ b[1] = 0x4444;
+ return c;
+ }
+ }
+ contract D {
+ function f() public pure returns (uint) { return 7; }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("lengths()"), encodeArgs(true));
+ bytes codeCreation = callContractFunction("creation()");
+ bytes codeRuntime1 = callContractFunction("runtime()");
+ bytes codeRuntime2 = callContractFunction("runtimeAllocCheck()");
+ ABI_CHECK(codeRuntime1, codeRuntime2);
+}
+
+BOOST_AUTO_TEST_CASE(code_access_create)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function test() public returns (uint) {
+ bytes memory c = type(D).creationCode;
+ D d;
+ assembly {
+ d := create(0, add(c, 0x20), mload(c))
+ }
+ return d.f();
+ }
+ }
+ contract D {
+ uint x;
+ constructor() public { x = 7; }
+ function f() public view returns (uint) { return x; }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("test()"), encodeArgs(7));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}