Skip to content

Commit

Permalink
Remove reinitializers from validations
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Jan 15, 2025
1 parent de3b081 commit b4c9789
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 44 deletions.
36 changes: 0 additions & 36 deletions packages/core/contracts/test/ValidationsInitializer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ contract Parent_InitializerModifier is Initializable {
}
}

contract Parent_ReinitializerModifier is Initializable {
uint8 x;
function parentReinit() reinitializer(2) internal {
x = 1;
}
}

contract Parent__OnlyInitializingModifier is Initializable {
uint8 x;
function __Parent_init() onlyInitializing() internal {
Expand All @@ -53,20 +46,6 @@ contract Parent_InitializerName {
}
}

contract Parent_ReinitializeName {
uint8 x;
function reinitialize(uint64 version) internal {
x = 1;
}
}

contract Parent_ReinitializerName {
uint8 x;
function reinitializer(uint64 version) internal {
x = 1;
}
}

// ==== Child contracts ====

contract Child_Of_NoInitializer_Ok is Parent_NoInitializer {
Expand Down Expand Up @@ -99,21 +78,6 @@ contract Child_Of_InitializerModifier_Bad is Parent_InitializerModifier {
}
}

contract Child_Of_ReinitializerModifier_Ok is Parent_ReinitializerModifier {
uint y;
function initialize() public {
parentReinit();
y = 2;
}
}

contract Child_Of_ReinitializerModifier_Bad is Parent_ReinitializerModifier {
uint y;
function initialize() public {
y = 2;
}
}

contract Child_Of_OnlyInitializingModifier_Ok is Parent__OnlyInitializingModifier {
uint y;
function initialize() public {
Expand Down
6 changes: 0 additions & 6 deletions packages/core/src/validate-initializers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ testRejects('Child_Of_InitializerModifier_Bad', 'transparent', {
});
testAccepts('Child_Of_InitializerModifier_UsesSuper_Ok', 'transparent');

testAccepts('Child_Of_ReinitializerModifier_Ok', 'transparent');
testRejects('Child_Of_ReinitializerModifier_Bad', 'transparent', {
contains: ['Contract is missing initializer calls for one or more parent contracts: `Parent_ReinitializerModifier`'],
count: 1,
});

testAccepts('Child_Of_OnlyInitializingModifier_Ok', 'transparent');
testRejects('Child_Of_OnlyInitializingModifier_Bad', 'transparent', {
contains: [
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/validate/run/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ function getPossibleInitializers(contractDef: ContractDefinition, isParentContra
return fns.filter(
fnDef =>
(fnDef.modifiers.some(modifier =>

Check warning on line 259 in packages/core/src/validate/run/initializer.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎········['initializer',·'onlyInitializing'].includes(modifier.modifierName.name),⏎······` with `·['initializer',·'onlyInitializing'].includes(modifier.modifierName.name)`
['initializer', 'reinitializer', 'onlyInitializing'].includes(modifier.modifierName.name),
['initializer', 'onlyInitializing'].includes(modifier.modifierName.name),
) ||
['initialize', 'initializer', 'reinitialize', 'reinitializer'].includes(fnDef.name)) &&
['initialize', 'initializer'].includes(fnDef.name)) &&
// Skip virtual functions without a body, since that indicates an abstract function and is not itself an initializer
!(fnDef.virtual && !fnDef.body) &&
// Ignore private functions, since they cannot be called outside the contract
Expand Down

0 comments on commit b4c9789

Please sign in to comment.