AccessManagedHarness.sol 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3. import "../patched/access/manager/IAccessManager.sol";
  4. import "../patched/access/manager/AccessManaged.sol";
  5. contract AccessManagedHarness is AccessManaged {
  6. bytes internal SOME_FUNCTION_CALLDATA = abi.encodeCall(this.someFunction, ());
  7. constructor(address initialAuthority) AccessManaged(initialAuthority) {}
  8. function someFunction() public restricted() {
  9. // Sanity for FV: the msg.data when calling this function should be the same as the data used when checking
  10. // the schedule. This is a reformulation of `msg.data == SOME_FUNCTION_CALLDATA` that focuses on the operation
  11. // hash for this call.
  12. require(
  13. IAccessManager(authority()).hashOperation(_msgSender(), address(this), msg.data)
  14. ==
  15. IAccessManager(authority()).hashOperation(_msgSender(), address(this), SOME_FUNCTION_CALLDATA)
  16. );
  17. }
  18. function authority_canCall_immediate(address caller) public view returns (bool result) {
  19. (result,) = AuthorityUtils.canCallWithDelay(authority(), caller, address(this), this.someFunction.selector);
  20. }
  21. function authority_canCall_delay(address caller) public view returns (uint32 result) {
  22. (,result) = AuthorityUtils.canCallWithDelay(authority(), caller, address(this), this.someFunction.selector);
  23. }
  24. function authority_getSchedule(address caller) public view returns (uint48) {
  25. IAccessManager manager = IAccessManager(authority());
  26. return manager.getSchedule(manager.hashOperation(caller, address(this), SOME_FUNCTION_CALLDATA));
  27. }
  28. }