github.com/0xPolygon/supernets2-node@v0.0.0-20230711153321-2fe574524eaa/test/contracts/auto/Caller.sol (about)

     1  // SPDX-License-Identifier: GPL-3.0
     2  pragma solidity >=0.7.0 <0.9.0;
     3  
     4  contract Caller {
     5      function call(address _contract, uint _num) public payable {
     6          bool ok;
     7          (ok, ) = _contract.call(
     8              abi.encodeWithSignature("setVars(uint256)", _num)
     9          );
    10          require(ok, "failed to perform call");
    11      }
    12  
    13      function delegateCall(address _contract, uint _num) public payable {
    14          bool ok;
    15          (ok, ) = _contract.delegatecall(
    16              abi.encodeWithSignature("setVars(uint256)", _num)
    17          );
    18          require(ok, "failed to perform delegate call");
    19      }
    20  
    21      function staticCall(address _contract) public payable {
    22          bool ok;
    23          bytes memory result;
    24          (ok, result) = _contract.staticcall(
    25              abi.encodeWithSignature("getVars()")
    26          );
    27          require(ok, "failed to perform static call");
    28  
    29          uint256 num;
    30          address sender;
    31          uint256 value;
    32  
    33          (num, sender, value) = abi.decode(result, (uint256, address, uint256));
    34      }
    35  
    36      function invalidStaticCallMoreParameters(address _contract) public {
    37          bool ok;
    38          (ok,) = _contract.staticcall(
    39              abi.encodeWithSignature("getVarsAndVariable(uint256)", 1, 2)
    40          );
    41          require(!ok, "static call was supposed to fail with more parameters");
    42      }
    43  
    44      function invalidStaticCallLessParameters(address _contract) public {
    45          bool ok;
    46          (ok,) = _contract.staticcall(
    47              abi.encodeWithSignature("getVarsAndVariable(uint256)")
    48          );
    49          require(!ok, "static call was supposed to fail with less parameters");
    50      }
    51  
    52      function invalidStaticCallWithInnerCall(address _contract) public {
    53          bool ok;
    54          (ok,) = _contract.staticcall(
    55              abi.encodeWithSignature("getVarsAndVariable(uint256)")
    56          );
    57          require(!ok, "static call was supposed to fail with less parameters");
    58      }
    59  
    60      function multiCall(address _contract, uint _num) public payable {
    61          call(_contract, _num);
    62          delegateCall(_contract, _num);
    63          staticCall(_contract);
    64      }
    65  
    66      function preEcrecover_0() public {
    67          bytes32 messHash = 0x456e9aea5e197a1f1af7a3e85a3212fa4049a3ba34c2289b4c860fc0b0c64ef3;
    68          uint8 v = 28;
    69          bytes32 r = 0x9242685bf161793cc25603c231bc2f568eb630ea16aa137d2664ac8038825608;
    70          bytes32 s = 0x4f8ae3bd7535248d0bd448298cc2e2071e56992d0774dc340c368ae950852ada;
    71  
    72          ecrecover(messHash, v, r, s);
    73      } 
    74  }