Skip to content

Commit 586ebba

Browse files
author
Mike-CZ
committed
Make ownable compatible with OpenZeppelin
1 parent ef69d9f commit 586ebba

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

contracts/ownership/Ownable.sol

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ contract Ownable is Initializable {
1515
address private _owner;
1616

1717
/**
18-
* @dev The caller is not the owner.
18+
* @dev The caller account is not authorized to perform an operation.
1919
*/
20-
error NotOwner();
20+
error OwnableUnauthorizedAccount(address account);
2121

2222
/**
23-
* @dev Given zero address.
23+
* @dev The owner is not a valid owner account. (eg. `address(0)`)
2424
*/
25-
error ZeroAddress();
25+
error OwnableInvalidOwner(address owner);
2626

2727
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
2828

@@ -46,7 +46,7 @@ contract Ownable is Initializable {
4646
*/
4747
modifier onlyOwner() {
4848
if (!isOwner()) {
49-
revert NotOwner();
49+
revert OwnableUnauthorizedAccount(msg.sender);
5050
}
5151
_;
5252
}
@@ -83,7 +83,7 @@ contract Ownable is Initializable {
8383
*/
8484
function _transferOwnership(address newOwner) internal {
8585
if (newOwner == address(0)) {
86-
revert ZeroAddress();
86+
revert OwnableInvalidOwner(address(0));
8787
}
8888
emit OwnershipTransferred(_owner, newOwner);
8989
_owner = newOwner;

test/NodeDriver.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('NodeDriver', () => {
4040
const account = ethers.Wallet.createRandom();
4141
await expect(this.nodeDriverAuth.connect(this.nonOwner).migrateTo(account)).to.be.revertedWithCustomError(
4242
this.nodeDriverAuth,
43-
'NotOwner',
43+
'OwnableUnauthorizedAccount',
4444
);
4545
});
4646
});
@@ -55,7 +55,7 @@ describe('NodeDriver', () => {
5555
const address = ethers.Wallet.createRandom();
5656
await expect(
5757
this.nodeDriverAuth.connect(this.nonOwner).copyCode(this.sfc, address),
58-
).to.be.revertedWithCustomError(this.nodeDriverAuth, 'NotOwner');
58+
).to.be.revertedWithCustomError(this.nodeDriverAuth, 'OwnableUnauthorizedAccount');
5959
});
6060
});
6161

@@ -69,7 +69,7 @@ describe('NodeDriver', () => {
6969
it('Should revert when not owner', async function () {
7070
await expect(this.nodeDriverAuth.connect(this.nonOwner).updateNetworkVersion(1)).to.be.revertedWithCustomError(
7171
this.nodeDriverAuth,
72-
'NotOwner',
72+
'OwnableUnauthorizedAccount',
7373
);
7474
});
7575
});
@@ -82,7 +82,7 @@ describe('NodeDriver', () => {
8282
it('Should revert when not owner', async function () {
8383
await expect(this.nodeDriverAuth.connect(this.nonOwner).advanceEpochs(10)).to.be.revertedWithCustomError(
8484
this.nodeDriverAuth,
85-
'NotOwner',
85+
'OwnableUnauthorizedAccount',
8686
);
8787
});
8888
});

test/SFC.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,14 @@ describe('SFC', () => {
292292
it('Should revert when transferring ownership if not owner', async function () {
293293
await expect(this.sfc.connect(this.user).transferOwnership(ethers.ZeroAddress)).to.be.revertedWithCustomError(
294294
this.nodeDriverAuth,
295-
'NotOwner',
295+
'OwnableUnauthorizedAccount',
296296
);
297297
});
298298

299299
it('Should revert when transferring ownership to zero address', async function () {
300-
await expect(this.sfc.transferOwnership(ethers.ZeroAddress)).to.be.revertedWithCustomError(
301-
this.nodeDriverAuth,
302-
'ZeroAddress',
303-
);
300+
await expect(this.sfc.transferOwnership(ethers.ZeroAddress))
301+
.to.be.revertedWithCustomError(this.nodeDriverAuth, 'OwnableInvalidOwner')
302+
.withArgs(ethers.ZeroAddress);
304303
});
305304
});
306305

0 commit comments

Comments
 (0)