-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
pragma solidity >=0.8.0; | ||
|
||
/// @notice Simple single owner authorization mixin. | ||
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/auth/Owned.sol) | ||
abstract contract Owned { | ||
/*////////////////////////////////////////////////////////////// | ||
EVENTS | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
event OwnerUpdated(address indexed user, address indexed newOwner); | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
OWNERSHIP STORAGE | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
address public owner; | ||
|
||
modifier onlyOwner() virtual { | ||
require(msg.sender == owner, "UNAUTHORIZED"); | ||
|
||
_; | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
CONSTRUCTOR | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
constructor(address _owner) { | ||
owner = _owner; | ||
|
||
emit OwnerUpdated(address(0), _owner); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
OWNERSHIP LOGIC | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
function setOwner(address newOwner) public virtual onlyOwner { | ||
owner = newOwner; | ||
|
||
emit OwnerUpdated(msg.sender, newOwner); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
pragma solidity 0.8.10; | ||
|
||
import {DSTestPlus} from "./utils/DSTestPlus.sol"; | ||
import {MockOwned} from "./utils/mocks/MockOwned.sol"; | ||
|
||
contract OwnedTest is DSTestPlus { | ||
MockOwned mockOwned; | ||
|
||
function setUp() public { | ||
mockOwned = new MockOwned(); | ||
} | ||
|
||
function testSetOwner() public { | ||
testSetOwner(address(0xBEEF)); | ||
} | ||
|
||
function testCallFunctionAsNonOwner() public { | ||
testCallFunctionAsNonOwner(address(0)); | ||
} | ||
|
||
function testCallFunctionAsOwner() public { | ||
mockOwned.updateFlag(); | ||
} | ||
|
||
function testSetOwner(address newOwner) public { | ||
mockOwned.setOwner(newOwner); | ||
|
||
assertEq(mockOwned.owner(), newOwner); | ||
} | ||
|
||
function testCallFunctionAsNonOwner(address owner) public { | ||
hevm.assume(owner != address(this)); | ||
|
||
mockOwned.setOwner(owner); | ||
|
||
hevm.expectRevert("UNAUTHORIZED"); | ||
mockOwned.updateFlag(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
pragma solidity >=0.8.0; | ||
|
||
import {Owned} from "../../../auth/Owned.sol"; | ||
|
||
contract MockOwned is Owned(msg.sender) { | ||
bool public flag; | ||
|
||
function updateFlag() public virtual onlyOwner { | ||
flag = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters