forked from ethereum/solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencodeCall.sol
48 lines (43 loc) · 1.36 KB
/
encodeCall.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
interface I {
function fExternal(uint256 p, string memory t) external;
}
contract Other {
function fExternal(uint) external pure {}
function fPublic(uint) public pure {}
function fInternal(uint) internal pure {}
}
library L {
function fExternal(uint256 p, string memory t) external {}
function fInternal(uint256 p, string memory t) internal {}
}
contract Base {
function baseFunctionExternal(uint) external pure {}
}
contract C is Base {
function f(int a) public {}
function f2(int a, string memory b) public {}
function f4() public {}
function successFunctionArgsIntLiteralTuple() public view returns(bytes memory) {
return abi.encodeCall(this.f, (1));
}
function successFunctionArgsIntLiteral() public view returns(bytes memory) {
return abi.encodeCall(this.f, 1);
}
function successFunctionArgsLiteralTuple() public view returns(bytes memory) {
return abi.encodeCall(this.f2, (1, "test"));
}
function successFunctionArgsEmptyTuple() public view returns(bytes memory) {
return abi.encodeCall(this.f4, ());
}
function viaDeclaration() public pure returns (bytes memory) {
return bytes.concat(
abi.encodeCall(Other.fExternal, (1)),
abi.encodeCall(Other.fPublic, (1)),
abi.encodeCall(I.fExternal, (1, "123"))
);
}
function viaBaseDeclaration() public pure returns (bytes memory) {
return abi.encodeCall(Base.baseFunctionExternal, (1));
}
}
// ----