Rename custom error AleadyInitialized → InvalidInitialization (#4592)
This commit is contained in:
@ -79,7 +79,7 @@ abstract contract Initializable {
|
|||||||
/**
|
/**
|
||||||
* @dev The contract is already initialized.
|
* @dev The contract is already initialized.
|
||||||
*/
|
*/
|
||||||
error AlreadyInitialized();
|
error InvalidInitialization();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev The contract is not initializing.
|
* @dev The contract is not initializing.
|
||||||
@ -118,7 +118,7 @@ abstract contract Initializable {
|
|||||||
bool construction = initialized == 1 && address(this).code.length == 0;
|
bool construction = initialized == 1 && address(this).code.length == 0;
|
||||||
|
|
||||||
if (!initialSetup && !construction) {
|
if (!initialSetup && !construction) {
|
||||||
revert AlreadyInitialized();
|
revert InvalidInitialization();
|
||||||
}
|
}
|
||||||
$._initialized = 1;
|
$._initialized = 1;
|
||||||
if (isTopLevelCall) {
|
if (isTopLevelCall) {
|
||||||
@ -154,7 +154,7 @@ abstract contract Initializable {
|
|||||||
InitializableStorage storage $ = _getInitializableStorage();
|
InitializableStorage storage $ = _getInitializableStorage();
|
||||||
|
|
||||||
if ($._initializing || $._initialized >= version) {
|
if ($._initializing || $._initialized >= version) {
|
||||||
revert AlreadyInitialized();
|
revert InvalidInitialization();
|
||||||
}
|
}
|
||||||
$._initialized = version;
|
$._initialized = version;
|
||||||
$._initializing = true;
|
$._initializing = true;
|
||||||
@ -194,7 +194,7 @@ abstract contract Initializable {
|
|||||||
InitializableStorage storage $ = _getInitializableStorage();
|
InitializableStorage storage $ = _getInitializableStorage();
|
||||||
|
|
||||||
if ($._initializing) {
|
if ($._initializing) {
|
||||||
revert AlreadyInitialized();
|
revert InvalidInitialization();
|
||||||
}
|
}
|
||||||
if ($._initialized != type(uint64).max) {
|
if ($._initialized != type(uint64).max) {
|
||||||
$._initialized = type(uint64).max;
|
$._initialized = type(uint64).max;
|
||||||
|
|||||||
@ -42,13 +42,13 @@ contract('Initializable', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('initializer does not run again', async function () {
|
it('initializer does not run again', async function () {
|
||||||
await expectRevertCustomError(this.contract.initialize(), 'AlreadyInitialized', []);
|
await expectRevertCustomError(this.contract.initialize(), 'InvalidInitialization', []);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('nested under an initializer', function () {
|
describe('nested under an initializer', function () {
|
||||||
it('initializer modifier reverts', async function () {
|
it('initializer modifier reverts', async function () {
|
||||||
await expectRevertCustomError(this.contract.initializerNested(), 'AlreadyInitialized', []);
|
await expectRevertCustomError(this.contract.initializerNested(), 'InvalidInitialization', []);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('onlyInitializing modifier succeeds', async function () {
|
it('onlyInitializing modifier succeeds', async function () {
|
||||||
@ -100,9 +100,9 @@ contract('Initializable', function () {
|
|||||||
|
|
||||||
it('cannot nest reinitializers', async function () {
|
it('cannot nest reinitializers', async function () {
|
||||||
expect(await this.contract.counter()).to.be.bignumber.equal('0');
|
expect(await this.contract.counter()).to.be.bignumber.equal('0');
|
||||||
await expectRevertCustomError(this.contract.nestedReinitialize(2, 2), 'AlreadyInitialized', []);
|
await expectRevertCustomError(this.contract.nestedReinitialize(2, 2), 'InvalidInitialization', []);
|
||||||
await expectRevertCustomError(this.contract.nestedReinitialize(2, 3), 'AlreadyInitialized', []);
|
await expectRevertCustomError(this.contract.nestedReinitialize(2, 3), 'InvalidInitialization', []);
|
||||||
await expectRevertCustomError(this.contract.nestedReinitialize(3, 2), 'AlreadyInitialized', []);
|
await expectRevertCustomError(this.contract.nestedReinitialize(3, 2), 'InvalidInitialization', []);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can chain reinitializers', async function () {
|
it('can chain reinitializers', async function () {
|
||||||
@ -121,18 +121,18 @@ contract('Initializable', function () {
|
|||||||
describe('contract locking', function () {
|
describe('contract locking', function () {
|
||||||
it('prevents initialization', async function () {
|
it('prevents initialization', async function () {
|
||||||
await this.contract.disableInitializers();
|
await this.contract.disableInitializers();
|
||||||
await expectRevertCustomError(this.contract.initialize(), 'AlreadyInitialized', []);
|
await expectRevertCustomError(this.contract.initialize(), 'InvalidInitialization', []);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prevents re-initialization', async function () {
|
it('prevents re-initialization', async function () {
|
||||||
await this.contract.disableInitializers();
|
await this.contract.disableInitializers();
|
||||||
await expectRevertCustomError(this.contract.reinitialize(255), 'AlreadyInitialized', []);
|
await expectRevertCustomError(this.contract.reinitialize(255), 'InvalidInitialization', []);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can lock contract after initialization', async function () {
|
it('can lock contract after initialization', async function () {
|
||||||
await this.contract.initialize();
|
await this.contract.initialize();
|
||||||
await this.contract.disableInitializers();
|
await this.contract.disableInitializers();
|
||||||
await expectRevertCustomError(this.contract.reinitialize(255), 'AlreadyInitialized', []);
|
await expectRevertCustomError(this.contract.reinitialize(255), 'InvalidInitialization', []);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -207,8 +207,8 @@ contract('Initializable', function () {
|
|||||||
|
|
||||||
describe('disabling initialization', function () {
|
describe('disabling initialization', function () {
|
||||||
it('old and new patterns in bad sequence', async function () {
|
it('old and new patterns in bad sequence', async function () {
|
||||||
await expectRevertCustomError(DisableBad1.new(), 'AlreadyInitialized', []);
|
await expectRevertCustomError(DisableBad1.new(), 'InvalidInitialization', []);
|
||||||
await expectRevertCustomError(DisableBad2.new(), 'AlreadyInitialized', []);
|
await expectRevertCustomError(DisableBad2.new(), 'InvalidInitialization', []);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('old and new patterns in good sequence', async function () {
|
it('old and new patterns in good sequence', async function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user