CallReceiverMock.sol 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3. contract CallReceiverMock {
  4. event MockFunctionCalled();
  5. event MockFunctionCalledWithArgs(uint256 a, uint256 b);
  6. event MockFunctionCalledExtra(address caller, uint256 value);
  7. uint256[] private _array;
  8. function mockFunction() public payable returns (string memory) {
  9. emit MockFunctionCalled();
  10. return "0x1234";
  11. }
  12. function mockFunctionEmptyReturn() public payable {
  13. emit MockFunctionCalled();
  14. }
  15. function mockFunctionWithArgs(uint256 a, uint256 b) public payable returns (string memory) {
  16. emit MockFunctionCalledWithArgs(a, b);
  17. return "0x1234";
  18. }
  19. function mockFunctionNonPayable() public returns (string memory) {
  20. emit MockFunctionCalled();
  21. return "0x1234";
  22. }
  23. function mockStaticFunction() public pure returns (string memory) {
  24. return "0x1234";
  25. }
  26. function mockFunctionRevertsNoReason() public payable {
  27. revert();
  28. }
  29. function mockFunctionRevertsReason() public payable {
  30. revert("CallReceiverMock: reverting");
  31. }
  32. function mockFunctionThrows() public payable {
  33. assert(false);
  34. }
  35. function mockFunctionOutOfGas() public payable {
  36. for (uint256 i = 0; ; ++i) {
  37. _array.push(i);
  38. }
  39. }
  40. function mockFunctionWritesStorage(bytes32 slot, bytes32 value) public returns (string memory) {
  41. assembly {
  42. sstore(slot, value)
  43. }
  44. return "0x1234";
  45. }
  46. function mockFunctionExtra() public payable {
  47. emit MockFunctionCalledExtra(msg.sender, msg.value);
  48. }
  49. }
  50. contract CallReceiverMockTrustingForwarder is CallReceiverMock {
  51. address private _trustedForwarder;
  52. constructor(address trustedForwarder_) {
  53. _trustedForwarder = trustedForwarder_;
  54. }
  55. function isTrustedForwarder(address forwarder) public view virtual returns (bool) {
  56. return forwarder == _trustedForwarder;
  57. }
  58. }