diff options
Diffstat (limited to 'test/libsolidity')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index a972cc86..d0c5285c 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -9882,6 +9882,64 @@ BOOST_AUTO_TEST_CASE(inlineasm_empty_let) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0), u256(0))); } +BOOST_AUTO_TEST_CASE(bare_call_invalid_address) +{ + char const* sourceCode = R"( + contract C { + /// Calling into non-existant account is successful (creates the account) + function f() external constant returns (bool) { + return address(0x4242).call(); + } + function g() external constant returns (bool) { + return address(0x4242).callcode(); + } + function h() external constant returns (bool) { + return address(0x4242).delegatecall(); + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(1))); + BOOST_CHECK(callContractFunction("g()") == encodeArgs(u256(1))); + BOOST_CHECK(callContractFunction("h()") == encodeArgs(u256(1))); +} + +BOOST_AUTO_TEST_CASE(delegatecall_return_value) +{ + char const* sourceCode = R"DELIMITER( + contract C { + uint value; + function set(uint _value) external { + value = _value; + } + function get() external constant returns (uint) { + return value; + } + function get_delegated() external constant returns (bool) { + return this.delegatecall(bytes4(sha3("get()"))); + } + function assert0() external constant { + assert(value == 0); + } + function assert0_delegated() external constant returns (bool) { + return this.delegatecall(bytes4(sha3("assert0()"))); + } + } + )DELIMITER"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("get()") == encodeArgs(u256(0))); + BOOST_CHECK(callContractFunction("assert0_delegated()") == encodeArgs(u256(1))); + BOOST_CHECK(callContractFunction("get_delegated()") == encodeArgs(u256(1))); + BOOST_CHECK(callContractFunction("set(uint256)", u256(1)) == encodeArgs()); + BOOST_CHECK(callContractFunction("get()") == encodeArgs(u256(1))); + BOOST_CHECK(callContractFunction("assert0_delegated()") == encodeArgs(u256(0))); + BOOST_CHECK(callContractFunction("get_delegated()") == encodeArgs(u256(1))); + BOOST_CHECK(callContractFunction("set(uint256)", u256(42)) == encodeArgs()); + BOOST_CHECK(callContractFunction("get()") == encodeArgs(u256(42))); + BOOST_CHECK(callContractFunction("assert0_delegated()") == encodeArgs(u256(0))); + BOOST_CHECK(callContractFunction("get_delegated()") == encodeArgs(u256(1))); +} + BOOST_AUTO_TEST_SUITE_END() } |