Skip to content

Commit

Permalink
fix: update ownable with guardian (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra authored Jan 30, 2025
1 parent 1422f3e commit 275365e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/forge-std
4 changes: 2 additions & 2 deletions src/contracts/access-control/OwnableWithGuardian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {IWithGuardian} from './interfaces/IWithGuardian.sol';
abstract contract OwnableWithGuardian is Ownable, IWithGuardian {
address private _guardian;

constructor(address initialOwner) Ownable(initialOwner) {
_updateGuardian(_msgSender());
constructor(address initialOwner, address initialGuardian) Ownable(initialOwner) {
_updateGuardian(initialGuardian);
}

modifier onlyGuardian() {
Expand Down
16 changes: 14 additions & 2 deletions src/contracts/access-control/UpgradeableOwnableWithGuardian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,21 @@ abstract contract UpgradeableOwnableWithGuardian is OwnableUpgradeable, IWithGua
}

/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
* @dev Initializes the contract setting the address provided by the deployer as the initial owner & guardian.
* @param initialOwner The address of the initial owner
* @param initialGuardian The address of the initial guardian
*/
function __Ownable_With_Guardian_init(address initialGuardian) internal onlyInitializing {
function __Ownable_With_Guardian_init(
address initialOwner,
address initialGuardian
) internal onlyInitializing {
__Ownable_init_unchained(initialOwner);
__Ownable_With_Guardian_init_unchained(initialGuardian);
}

function __Ownable_With_Guardian_init_unchained(
address initialGuardian
) internal onlyInitializing {
_updateGuardian(initialGuardian);
}

Expand Down
4 changes: 2 additions & 2 deletions test/OwnableWithGuardian.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'forge-std/Test.sol';
import {OwnableWithGuardian, IWithGuardian} from '../src/contracts/access-control/OwnableWithGuardian.sol';

contract ImplOwnableWithGuardian is OwnableWithGuardian {
constructor(address initialOwner) OwnableWithGuardian(initialOwner) {}
constructor(address initialOwner, address guardian) OwnableWithGuardian(initialOwner, guardian) {}

function mock_onlyGuardian() external onlyGuardian {}

Expand All @@ -19,7 +19,7 @@ contract TestOfOwnableWithGuardian is Test {
address guardian = makeAddr('guardian');

function setUp() public {
withGuardian = new ImplOwnableWithGuardian(address(this));
withGuardian = new ImplOwnableWithGuardian(address(this), address(this));
assertEq(withGuardian.owner(), address(this));
assertEq(withGuardian.guardian(), address(this));
withGuardian.transferOwnership(owner);
Expand Down
3 changes: 1 addition & 2 deletions test/UpgradeableOwnableWithGuardian.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {UpgradeableOwnableWithGuardian, IWithGuardian} from '../src/contracts/ac

contract ImplOwnableWithGuardian is UpgradeableOwnableWithGuardian {
function initialize(address owner, address guardian) public initializer {
__Ownable_init(owner);
__Ownable_With_Guardian_init(guardian);
__Ownable_With_Guardian_init(owner, guardian);
}

function mock_onlyGuardian() external onlyGuardian {}
Expand Down

0 comments on commit 275365e

Please sign in to comment.