Commit 38f61159 authored by Maurelian's avatar Maurelian Committed by GitHub

ctb: Add events and custom errors to LivenessModule (#10018)

* ctb: Add events and custom errors to LivenessModule

ctb: Use same event as Safe contract

* ctb: Used past tense event name OwnershipTransferredToFallback()
parent d72fb46d
...@@ -92,8 +92,8 @@ ...@@ -92,8 +92,8 @@
"sourceCodeHash": "0x9633cea9b66077e222f470439fe3e9a31f3e33b4f7a5618374c44310fd234b24" "sourceCodeHash": "0x9633cea9b66077e222f470439fe3e9a31f3e33b4f7a5618374c44310fd234b24"
}, },
"src/Safe/LivenessModule.sol": { "src/Safe/LivenessModule.sol": {
"initCodeHash": "0x0da844fb4dd22f252ff631524f01f45edf43bca7558fe45f71d711b79af01742", "initCodeHash": "0xcd8b76f70634330e242d4ff497bba1f8e0aaa11d7aecf9845090029c43027a7f",
"sourceCodeHash": "0x1afb1d392e8f6a58ff86ea7f648e0d1756d4ba8d0d964279d58a390deaa53b7e" "sourceCodeHash": "0x3b358b51fce4f1516191104d2e1f782c8ec3edecee63c502cc301671aa632b93"
}, },
"src/cannon/MIPS.sol": { "src/cannon/MIPS.sol": {
"initCodeHash": "0xaf2ac814f64ccf12e9c6738db7cef865f51f9e39f39105adef9fba11465f6ee1", "initCodeHash": "0xaf2ac814f64ccf12e9c6738db7cef865f51f9e39f39105adef9fba11465f6ee1",
......
...@@ -163,5 +163,24 @@ ...@@ -163,5 +163,24 @@
], ],
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
},
{
"anonymous": false,
"inputs": [],
"name": "OwnershipTransferredToFallback",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"name": "RemovedOwner",
"type": "event"
} }
] ]
\ No newline at end of file
...@@ -14,6 +14,12 @@ import { ISemver } from "src/universal/ISemver.sol"; ...@@ -14,6 +14,12 @@ import { ISemver } from "src/universal/ISemver.sol";
/// If the number of owners falls below the minimum number of owners, the ownership of the /// If the number of owners falls below the minimum number of owners, the ownership of the
/// safe will be transferred to the fallback owner. /// safe will be transferred to the fallback owner.
contract LivenessModule is ISemver { contract LivenessModule is ISemver {
/// @notice Emitted when an owner is removed due to insufficient liveness
event RemovedOwner(address indexed owner);
/// @notice Emitted when the fallback owner takes ownership
event OwnershipTransferredToFallback();
/// @notice The Safe contract instance /// @notice The Safe contract instance
Safe internal immutable SAFE; Safe internal immutable SAFE;
...@@ -178,6 +184,7 @@ contract LivenessModule is ISemver { ...@@ -178,6 +184,7 @@ contract LivenessModule is ISemver {
}), }),
"LivenessModule: failed to swap to fallback owner" "LivenessModule: failed to swap to fallback owner"
); );
emit OwnershipTransferredToFallback();
} }
/// @notice Removes the owner `owner` from the Safe and updates the threshold to `_threshold`. /// @notice Removes the owner `owner` from the Safe and updates the threshold to `_threshold`.
...@@ -194,6 +201,7 @@ contract LivenessModule is ISemver { ...@@ -194,6 +201,7 @@ contract LivenessModule is ISemver {
}), }),
"LivenessModule: failed to remove owner" "LivenessModule: failed to remove owner"
); );
emit RemovedOwner(_owner);
} }
/// @notice A FREI-PI invariant check enforcing requirements on number of owners and threshold. /// @notice A FREI-PI invariant check enforcing requirements on number of owners and threshold.
......
...@@ -15,7 +15,10 @@ import { LivenessGuard } from "src/Safe/LivenessGuard.sol"; ...@@ -15,7 +15,10 @@ import { LivenessGuard } from "src/Safe/LivenessGuard.sol";
contract LivenessModule_TestInit is Test, SafeTestTools { contract LivenessModule_TestInit is Test, SafeTestTools {
using SafeTestLib for SafeInstance; using SafeTestLib for SafeInstance;
// LivenessModule events
event SignersRecorded(bytes32 indexed txHash, address[] signers); event SignersRecorded(bytes32 indexed txHash, address[] signers);
event RemovedOwner(address indexed owner);
event OwnershipTransferredToFallback();
uint256 initTime = 10; uint256 initTime = 10;
uint256 livenessInterval = 30 days; uint256 livenessInterval = 30 days;
...@@ -286,6 +289,8 @@ contract LivenessModule_RemoveOwners_Test is LivenessModule_TestInit { ...@@ -286,6 +289,8 @@ contract LivenessModule_RemoveOwners_Test is LivenessModule_TestInit {
address ownerToRemove = safeInstance.owners[0]; address ownerToRemove = safeInstance.owners[0];
_warpPastLivenessInterval(); _warpPastLivenessInterval();
vm.expectEmit(address(livenessModule));
emit RemovedOwner(ownerToRemove);
_removeAnOwner(ownerToRemove, safeInstance.owners); _removeAnOwner(ownerToRemove, safeInstance.owners);
assertFalse(safeInstance.safe.isOwner(ownerToRemove)); assertFalse(safeInstance.safe.isOwner(ownerToRemove));
...@@ -303,6 +308,16 @@ contract LivenessModule_RemoveOwners_Test is LivenessModule_TestInit { ...@@ -303,6 +308,16 @@ contract LivenessModule_RemoveOwners_Test is LivenessModule_TestInit {
address[] memory prevOwners = safeInstance.getPrevOwners(ownersToRemove); address[] memory prevOwners = safeInstance.getPrevOwners(ownersToRemove);
_warpPastLivenessInterval(); _warpPastLivenessInterval();
for (uint256 i; i < ownersToRemove.length; i++) {
if (i != ownersToRemove.length - 1) {
vm.expectEmit(address(livenessModule));
emit RemovedOwner(ownersToRemove[i]);
}
}
vm.expectEmit(address(livenessModule));
emit OwnershipTransferredToFallback();
livenessModule.removeOwners(prevOwners, ownersToRemove); livenessModule.removeOwners(prevOwners, ownersToRemove);
assertEq(safeInstance.safe.getOwners().length, 1); assertEq(safeInstance.safe.getOwners().length, 1);
assertEq(safeInstance.safe.getOwners()[0], fallbackOwner); assertEq(safeInstance.safe.getOwners()[0], fallbackOwner);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment