Move beneficiary zero address check to Ownable (#4531)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
5
.changeset/clever-bats-kick.md
Normal file
5
.changeset/clever-bats-kick.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'openzeppelin-solidity': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
`Ownable`: Prevent using address(0) as the initial owner.
|
||||||
@ -36,6 +36,9 @@ abstract contract Ownable is Context {
|
|||||||
* @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.
|
||||||
*/
|
*/
|
||||||
constructor(address initialOwner) {
|
constructor(address initialOwner) {
|
||||||
|
if (initialOwner == address(0)) {
|
||||||
|
revert OwnableInvalidOwner(address(0));
|
||||||
|
}
|
||||||
_transferOwnership(initialOwner);
|
_transferOwnership(initialOwner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,11 +31,6 @@ contract VestingWallet is Context, Ownable {
|
|||||||
event EtherReleased(uint256 amount);
|
event EtherReleased(uint256 amount);
|
||||||
event ERC20Released(address indexed token, uint256 amount);
|
event ERC20Released(address indexed token, uint256 amount);
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev The `beneficiary` is not a valid account.
|
|
||||||
*/
|
|
||||||
error VestingWalletInvalidBeneficiary(address beneficiary);
|
|
||||||
|
|
||||||
uint256 private _released;
|
uint256 private _released;
|
||||||
mapping(address token => uint256) private _erc20Released;
|
mapping(address token => uint256) private _erc20Released;
|
||||||
uint64 private immutable _start;
|
uint64 private immutable _start;
|
||||||
@ -46,10 +41,6 @@ contract VestingWallet is Context, Ownable {
|
|||||||
* vesting duration of the vesting wallet.
|
* vesting duration of the vesting wallet.
|
||||||
*/
|
*/
|
||||||
constructor(address beneficiary, uint64 startTimestamp, uint64 durationSeconds) payable Ownable(beneficiary) {
|
constructor(address beneficiary, uint64 startTimestamp, uint64 durationSeconds) payable Ownable(beneficiary) {
|
||||||
if (beneficiary == address(0)) {
|
|
||||||
revert VestingWalletInvalidBeneficiary(address(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
_start = startTimestamp;
|
_start = startTimestamp;
|
||||||
_duration = durationSeconds;
|
_duration = durationSeconds;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,10 @@ contract('Ownable', function (accounts) {
|
|||||||
this.ownable = await Ownable.new(owner);
|
this.ownable = await Ownable.new(owner);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('rejects zero address for initialOwner', async function () {
|
||||||
|
await expectRevertCustomError(Ownable.new(constants.ZERO_ADDRESS), 'OwnableInvalidOwner', [constants.ZERO_ADDRESS]);
|
||||||
|
});
|
||||||
|
|
||||||
it('has an owner', async function () {
|
it('has an owner', async function () {
|
||||||
expect(await this.ownable.owner()).to.equal(owner);
|
expect(await this.ownable.owner()).to.equal(owner);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -23,7 +23,7 @@ contract('VestingWallet', function (accounts) {
|
|||||||
it('rejects zero address for beneficiary', async function () {
|
it('rejects zero address for beneficiary', async function () {
|
||||||
await expectRevertCustomError(
|
await expectRevertCustomError(
|
||||||
VestingWallet.new(constants.ZERO_ADDRESS, this.start, duration),
|
VestingWallet.new(constants.ZERO_ADDRESS, this.start, duration),
|
||||||
'VestingWalletInvalidBeneficiary',
|
'OwnableInvalidOwner',
|
||||||
[constants.ZERO_ADDRESS],
|
[constants.ZERO_ADDRESS],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user