Commit 69f3cce1 authored by Maurelian's avatar Maurelian

refactor(ctb): Add _onlySafe function

parent 3f6470e7
...@@ -47,6 +47,11 @@ contract LivenessGuard is ISemver, BaseGuard { ...@@ -47,6 +47,11 @@ contract LivenessGuard is ISemver, BaseGuard {
SAFE = _safe; SAFE = _safe;
} }
/// @notice Internal function to ensure that only the Safe can call certain functions.
function _onlySafe() internal view {
require(msg.sender == address(SAFE), "LivenessGuard: only Safe can call this function");
}
/// @notice Records the most recent time which any owner has signed a transaction. /// @notice Records the most recent time which any owner has signed a transaction.
/// @dev Called by the Safe contract before execution of a transaction. /// @dev Called by the Safe contract before execution of a transaction.
function checkTransaction( function checkTransaction(
...@@ -65,7 +70,7 @@ contract LivenessGuard is ISemver, BaseGuard { ...@@ -65,7 +70,7 @@ contract LivenessGuard is ISemver, BaseGuard {
external external
{ {
msgSender; // silence unused variable warning msgSender; // silence unused variable warning
require(msg.sender == address(SAFE), "LivenessGuard: only Safe can call this function"); _onlySafe();
// Cache the set of owners prior to execution. // Cache the set of owners prior to execution.
// This will be used in the checkAfterExecution method. // This will be used in the checkAfterExecution method.
...@@ -106,8 +111,7 @@ contract LivenessGuard is ISemver, BaseGuard { ...@@ -106,8 +111,7 @@ contract LivenessGuard is ISemver, BaseGuard {
/// 1. Add new owners to the lastLive mapping /// 1. Add new owners to the lastLive mapping
/// 2. Delete removed owners from the lastLive mapping /// 2. Delete removed owners from the lastLive mapping
function checkAfterExecution(bytes32, bool) external { function checkAfterExecution(bytes32, bool) external {
require(msg.sender == address(SAFE), "LivenessGuard: only Safe can call this function"); _onlySafe();
// Get the current set of owners // Get the current set of owners
address[] memory ownersAfter = SAFE.getOwners(); address[] memory ownersAfter = SAFE.getOwners();
...@@ -132,7 +136,7 @@ contract LivenessGuard is ISemver, BaseGuard { ...@@ -132,7 +136,7 @@ contract LivenessGuard is ISemver, BaseGuard {
/// @notice Enables an owner to demonstrate liveness by calling this method directly. /// @notice Enables an owner to demonstrate liveness by calling this method directly.
/// This is useful for owners who have not recently signed a transaction via the Safe. /// This is useful for owners who have not recently signed a transaction via the Safe.
function showLiveness() external { function showLiveness() external {
require(SAFE.isOwner(msg.sender), "LivenessGuard: only Safe owners may demontstrate liveness"); require(SAFE.isOwner(msg.sender), "LivenessGuard: only Safe owners may demonstrate liveness");
lastLive[msg.sender] = block.timestamp; lastLive[msg.sender] = block.timestamp;
emit OwnerRecorded(0x0, msg.sender); emit OwnerRecorded(0x0, msg.sender);
......
...@@ -93,7 +93,7 @@ contract LivenessGuard_CheckAfterExecution_Test is LivenessGuard_TestInit { } ...@@ -93,7 +93,7 @@ contract LivenessGuard_CheckAfterExecution_Test is LivenessGuard_TestInit { }
contract LivenessGuard_ShowLiveness_TestFail is LivenessGuard_TestInit { contract LivenessGuard_ShowLiveness_TestFail is LivenessGuard_TestInit {
/// @dev Tests that the showLiveness function reverts if the caller is not an owner /// @dev Tests that the showLiveness function reverts if the caller is not an owner
function test_showLiveness_callIsNotSafeOwner_reverts() external { function test_showLiveness_callIsNotSafeOwner_reverts() external {
vm.expectRevert("LivenessGuard: only Safe owners can call this function"); vm.expectRevert("LivenessGuard: only Safe owners may demonstrate liveness");
livenessGuard.showLiveness(); livenessGuard.showLiveness();
} }
} }
......
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