aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDaniel Kirchner <daniel@ekpyron.org>2018-08-15 20:40:20 +0800
committerchriseth <chris@ethereum.org>2018-08-15 22:06:48 +0800
commit7ca0aaaf6f62aafd0fe36ae6b7dc777361ae40e3 (patch)
tree95019017cb653af8109ca7ac0b5f4216103eae3f /test
parent2ed793c4d345de909332651145265a21a04e92d1 (diff)
downloaddexon-solidity-7ca0aaaf6f62aafd0fe36ae6b7dc777361ae40e3.tar
dexon-solidity-7ca0aaaf6f62aafd0fe36ae6b7dc777361ae40e3.tar.gz
dexon-solidity-7ca0aaaf6f62aafd0fe36ae6b7dc777361ae40e3.tar.bz2
dexon-solidity-7ca0aaaf6f62aafd0fe36ae6b7dc777361ae40e3.tar.lz
dexon-solidity-7ca0aaaf6f62aafd0fe36ae6b7dc777361ae40e3.tar.xz
dexon-solidity-7ca0aaaf6f62aafd0fe36ae6b7dc777361ae40e3.tar.zst
dexon-solidity-7ca0aaaf6f62aafd0fe36ae6b7dc777361ae40e3.zip
Add ``staticcall`` to ``address``.
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp69
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp16
2 files changed, 85 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 8a334e5e..b3618ad9 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)
@@ -4215,6 +4228,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"(
@@ -12216,6 +12272,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..fbb2f09c 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -433,6 +433,22 @@ 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_SUITE_END()
}