Skip to content

Commit 37f0b3b

Browse files
ernestognwAmxxfrangio
committed
Improve AccessManager tests (#4613)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Francisco Giordano <fg@frang.io> (cherry picked from commit baf0e91)
1 parent e49fcbe commit 37f0b3b

File tree

8 files changed

+3284
-932
lines changed

8 files changed

+3284
-932
lines changed

contracts/access/manager/AccessManager.sol

Lines changed: 80 additions & 50 deletions
Large diffs are not rendered by default.

contracts/access/manager/IAccessManager.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ interface IAccessManager {
3030
event OperationCanceled(bytes32 indexed operationId, uint32 indexed nonce);
3131

3232
event RoleLabel(uint64 indexed roleId, string label);
33+
/**
34+
* @dev Emitted when `account` is granted `roleId`.
35+
*
36+
* NOTE: The meaning of the `since` argument depends on the `newMember` argument.
37+
* If the role is granted to a new member, the `since` argument indicates when the account becomes a member of the role,
38+
* otherwise it indicates the execution delay for this account and roleId is updated.
39+
*/
3340
event RoleGranted(uint64 indexed roleId, address indexed account, uint32 delay, uint48 since, bool newMember);
3441
event RoleRevoked(uint64 indexed roleId, address indexed account);
3542
event RoleAdminChanged(uint64 indexed roleId, uint64 indexed admin);

contracts/mocks/AccessManagedTarget.sol

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
pragma solidity ^0.8.20;
44

55
import {AccessManaged} from "../access/manager/AccessManaged.sol";
6+
import {StorageSlot} from "../utils/StorageSlot.sol";
67

78
abstract contract AccessManagedTarget is AccessManaged {
89
event CalledRestricted(address caller);
@@ -17,6 +18,16 @@ abstract contract AccessManagedTarget is AccessManaged {
1718
emit CalledUnrestricted(msg.sender);
1819
}
1920

21+
function setIsConsumingScheduledOp(bool isConsuming, bytes32 slot) external {
22+
// Memory layout is 0x....<_consumingSchedule (boolean)><authority (address)>
23+
bytes32 mask = bytes32(uint256(1 << 160));
24+
if (isConsuming) {
25+
StorageSlot.getBytes32Slot(slot).value |= mask;
26+
} else {
27+
StorageSlot.getBytes32Slot(slot).value &= ~mask;
28+
}
29+
}
30+
2031
fallback() external {
2132
emit CalledFallback(msg.sender);
2233
}

contracts/utils/types/Time.sol

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,26 @@ library Time {
9797
* enforce the old delay at the moment of the update. Returns the updated Delay object and the timestamp when the
9898
* new delay becomes effective.
9999
*/
100-
function withUpdate(Delay self, uint32 newValue, uint32 minSetback) internal view returns (Delay, uint48) {
100+
function withUpdate(
101+
Delay self,
102+
uint32 newValue,
103+
uint32 minSetback
104+
) internal view returns (Delay updatedDelay, uint48 effect) {
101105
uint32 value = self.get();
102106
uint32 setback = uint32(Math.max(minSetback, value > newValue ? value - newValue : 0));
103-
uint48 effect = timestamp() + setback;
107+
effect = timestamp() + setback;
104108
return (pack(value, newValue, effect), effect);
105109
}
106110

107111
/**
108112
* @dev Split a delay into its components: valueBefore, valueAfter and effect (transition timepoint).
109113
*/
110-
function unpack(Delay self) internal pure returns (uint32, uint32, uint48) {
114+
function unpack(Delay self) internal pure returns (uint32 valueBefore, uint32 valueAfter, uint48 effect) {
111115
uint112 raw = Delay.unwrap(self);
112116

113-
uint32 valueAfter = uint32(raw);
114-
uint32 valueBefore = uint32(raw >> 32);
115-
uint48 effect = uint48(raw >> 64);
117+
valueAfter = uint32(raw);
118+
valueBefore = uint32(raw >> 32);
119+
effect = uint48(raw >> 64);
116120

117121
return (valueBefore, valueAfter, effect);
118122
}

scripts/upgradeable/transpile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ VERSION="$(jq -r .version contracts/package.json)"
66
DIRNAME="$(dirname -- "${BASH_SOURCE[0]}")"
77

88
bash "$DIRNAME/patch-apply.sh"
9-
sed -i "s/<package-version>/$VERSION/g" contracts/package.json
9+
sed -i'' -e "s/<package-version>/$VERSION/g" "contracts/package.json"
1010
git add contracts/package.json
1111

1212
npm run clean

0 commit comments

Comments
 (0)