mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Documents library view functions and adds unit test.
This commit is contained in:
parent
7d2dc14304
commit
4beabf6686
@ -485,7 +485,9 @@ Functions can be declared ``view`` in which case they promise not to modify the
|
|||||||
.. note::
|
.. note::
|
||||||
If the compiler's EVM target is Byzantium or newer (default) the opcode
|
If the compiler's EVM target is Byzantium or newer (default) the opcode
|
||||||
``STATICCALL`` is used for ``view`` functions which enforces the state
|
``STATICCALL`` is used for ``view`` functions which enforces the state
|
||||||
to stay unmodified as part of the EVM execution.
|
to stay unmodified as part of the EVM execution. For library ``view`` functions
|
||||||
|
``DELEGATECALL`` is used. Since they are executed in the context of the calling
|
||||||
|
contract, the static checker is extended to the library.
|
||||||
|
|
||||||
The following statements are considered modifying the state:
|
The following statements are considered modifying the state:
|
||||||
|
|
||||||
|
@ -4519,6 +4519,31 @@ BOOST_AUTO_TEST_CASE(library_call_protection)
|
|||||||
ABI_CHECK(callContractFunction("pu()"), encodeArgs(2));
|
ABI_CHECK(callContractFunction("pu()"), encodeArgs(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(library_staticcall_delegatecall)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
library Lib {
|
||||||
|
function x() public view returns (uint) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
contract Test {
|
||||||
|
uint t;
|
||||||
|
function f() public returns (uint) {
|
||||||
|
t = 2;
|
||||||
|
return this.g();
|
||||||
|
}
|
||||||
|
function g() public view returns (uint) {
|
||||||
|
return Lib.x();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
compileAndRun(sourceCode, 0, "Lib");
|
||||||
|
compileAndRun(sourceCode, 0, "Test", bytes(), map<string, Address>{{"Lib", m_contractAddress}});
|
||||||
|
ABI_CHECK(callContractFunction("f()"), encodeArgs(1));
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(store_bytes)
|
BOOST_AUTO_TEST_CASE(store_bytes)
|
||||||
{
|
{
|
||||||
// this test just checks that the copy loop does not mess up the stack
|
// this test just checks that the copy loop does not mess up the stack
|
||||||
|
Loading…
Reference in New Issue
Block a user