diff options
author | chriseth <chris@ethereum.org> | 2018-08-16 06:13:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-16 06:13:21 +0800 |
commit | cc6fa6d61fb934617d088bb04766ef0dea614b4f (patch) | |
tree | 3256618e2b268924442ea55e45622313969bad80 /test/libsolidity | |
parent | c164f80ba6b1c6753450b59365d1e0f1633688db (diff) | |
parent | db48925907ef4b31025f83ca83298483c4860583 (diff) | |
download | dexon-solidity-cc6fa6d61fb934617d088bb04766ef0dea614b4f.tar dexon-solidity-cc6fa6d61fb934617d088bb04766ef0dea614b4f.tar.gz dexon-solidity-cc6fa6d61fb934617d088bb04766ef0dea614b4f.tar.bz2 dexon-solidity-cc6fa6d61fb934617d088bb04766ef0dea614b4f.tar.lz dexon-solidity-cc6fa6d61fb934617d088bb04766ef0dea614b4f.tar.xz dexon-solidity-cc6fa6d61fb934617d088bb04766ef0dea614b4f.tar.zst dexon-solidity-cc6fa6d61fb934617d088bb04766ef0dea614b4f.zip |
Merge pull request #4822 from ethereum/addressStaticCall
Add ``staticcall`` to ``address``.
Diffstat (limited to 'test/libsolidity')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 69 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 31 | ||||
-rw-r--r-- | test/libsolidity/ViewPureChecker.cpp | 21 |
3 files changed, 120 insertions, 1 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index ce3c4324..2bf20126 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3592,6 +3592,19 @@ BOOST_AUTO_TEST_CASE(default_fallback_throws) )YY"; compileAndRun(sourceCode); ABI_CHECK(callContractFunction("f()"), encodeArgs(0)); + + if (dev::test::Options::get().evmVersion().hasStaticCall()) + { + char const* sourceCode = R"YY( + contract A { + function f() public returns (bool) { + return address(this).staticcall(""); + } + } + )YY"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("f()"), encodeArgs(0)); + } } BOOST_AUTO_TEST_CASE(short_data_calls_fallback) @@ -4418,6 +4431,49 @@ BOOST_AUTO_TEST_CASE(generic_delegatecall) BOOST_CHECK_EQUAL(balanceAt(c_senderAddress), 50 + 11); } +BOOST_AUTO_TEST_CASE(generic_staticcall) +{ + if (dev::test::Options::get().evmVersion().hasStaticCall()) + { + char const* sourceCode = R"**( + contract A { + uint public x; + constructor() public { x = 42; } + function pureFunction(uint256 p) public pure returns (uint256) { return p; } + function viewFunction(uint256 p) public view returns (uint256) { return p + x; } + function nonpayableFunction(uint256 p) public returns (uint256) { x = p; return x; } + function assertFunction(uint256 p) public view returns (uint256) { assert(x == p); return x; } + } + contract C { + function f(address a) public view returns (bool) + { + return a.staticcall(abi.encodeWithSignature("pureFunction(uint256)", 23)); + } + function g(address a) public view returns (bool) + { + return a.staticcall(abi.encodeWithSignature("viewFunction(uint256)", 23)); + } + function h(address a) public view returns (bool) + { + return a.staticcall(abi.encodeWithSignature("nonpayableFunction(uint256)", 23)); + } + function i(address a, uint256 v) public view returns (bool) + { + return a.staticcall(abi.encodeWithSignature("assertFunction(uint256)", v)); + } + } + )**"; + compileAndRun(sourceCode, 0, "A"); + u160 const c_addressA = m_contractAddress; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f(address)", c_addressA), encodeArgs(true)); + ABI_CHECK(callContractFunction("g(address)", c_addressA), encodeArgs(true)); + ABI_CHECK(callContractFunction("h(address)", c_addressA), encodeArgs(false)); + ABI_CHECK(callContractFunction("i(address,uint256)", c_addressA, 42), encodeArgs(true)); + ABI_CHECK(callContractFunction("i(address,uint256)", c_addressA, 23), encodeArgs(false)); + } +} + BOOST_AUTO_TEST_CASE(library_call_in_homestead) { char const* sourceCode = R"( @@ -12419,6 +12475,19 @@ BOOST_AUTO_TEST_CASE(bare_call_invalid_address) compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1))); ABI_CHECK(callContractFunction("h()"), encodeArgs(u256(1))); + + if (dev::test::Options::get().evmVersion().hasStaticCall()) + { + char const* sourceCode = R"YY( + contract C { + function f() external returns (bool) { + return address(0x4242).staticcall(""); + } + } + )YY"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1))); + } } BOOST_AUTO_TEST_CASE(delegatecall_return_value) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 55e81867..387505a5 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -433,6 +433,37 @@ BOOST_AUTO_TEST_CASE(getter_is_memory_type) } } +BOOST_AUTO_TEST_CASE(address_staticcall) +{ + char const* sourceCode = R"( + contract C { + function f() public view returns(bool) { + return address(0x4242).staticcall(""); + } + } + )"; + + if (dev::test::Options::get().evmVersion().hasStaticCall()) + CHECK_SUCCESS_NO_WARNINGS(sourceCode); + else + CHECK_ERROR(sourceCode, TypeError, "\"staticcall\" is not supported by the VM version."); +} + +BOOST_AUTO_TEST_CASE(address_staticcall_value) +{ + if (dev::test::Options::get().evmVersion().hasStaticCall()) + { + char const* sourceCode = R"( + contract C { + function f() public view { + address(0x4242).staticcall.value; + } + } + )"; + CHECK_ERROR(sourceCode, TypeError, "Member \"value\" not found or not visible after argument-dependent lookup"); + } +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp index 299cd084..d993b92e 100644 --- a/test/libsolidity/ViewPureChecker.cpp +++ b/test/libsolidity/ViewPureChecker.cpp @@ -53,8 +53,11 @@ BOOST_AUTO_TEST_CASE(environment_access) "tx.origin", "tx.gasprice", "this", - "address(1).balance" + "address(1).balance", }; + if (dev::test::Options::get().evmVersion().hasStaticCall()) + view.emplace_back("address(0x4242).staticcall(\"\")"); + // ``block.blockhash`` and ``blockhash`` are tested separately below because their usage will // produce warnings that can't be handled in a generic way. vector<string> pure{ @@ -95,6 +98,22 @@ BOOST_AUTO_TEST_CASE(environment_access) ); } +BOOST_AUTO_TEST_CASE(address_staticcall) +{ + string text = R"( + contract C { + function i() view public returns (bool) { + return address(0x4242).staticcall(""); + } + } + )"; + if (!dev::test::Options::get().evmVersion().hasStaticCall()) + CHECK_ERROR(text, TypeError, "\"staticcall\" is not supported by the VM version."); + else + CHECK_SUCCESS_NO_WARNINGS(text); +} + + BOOST_AUTO_TEST_CASE(assembly_staticcall) { string text = R"( |