AccessManagedHarness.sol 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. IAccessManager(authority()).hashOperation(_msgSender(), address(this), SOME_FUNCTION_CALLDATA)
  15. );
  16. }
  17. function authority_canCall_immediate(address caller) public view returns (bool result) {
  18. (result, ) = AuthorityUtils.canCallWithDelay(authority(), caller, address(this), this.someFunction.selector);
  19. }
  20. function authority_canCall_delay(address caller) public view returns (uint32 result) {
  21. (, result) = AuthorityUtils.canCallWithDelay(authority(), caller, address(this), this.someFunction.selector);
  22. }
  23. function authority_getSchedule(address caller) public view returns (uint48) {
  24. IAccessManager manager = IAccessManager(authority());
  25. return manager.getSchedule(manager.hashOperation(caller, address(this), SOME_FUNCTION_CALLDATA));
  26. }
  27. function _hasCode(address account) public view returns (bool) {
  28. return account.code.length > 0;
  29. }
  30. }