From b4c9789d8d245fc62780244fba43418ea4fad240 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Wed, 15 Jan 2025 13:28:25 -0500 Subject: [PATCH] Remove reinitializers from validations --- .../contracts/test/ValidationsInitializer.sol | 36 ------------------- .../core/src/validate-initializers.test.ts | 6 ---- packages/core/src/validate/run/initializer.ts | 4 +-- 3 files changed, 2 insertions(+), 44 deletions(-) diff --git a/packages/core/contracts/test/ValidationsInitializer.sol b/packages/core/contracts/test/ValidationsInitializer.sol index 7145af60c..fffbf265d 100644 --- a/packages/core/contracts/test/ValidationsInitializer.sol +++ b/packages/core/contracts/test/ValidationsInitializer.sol @@ -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 { @@ -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 { @@ -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 { diff --git a/packages/core/src/validate-initializers.test.ts b/packages/core/src/validate-initializers.test.ts index aeb35507f..f8054925b 100644 --- a/packages/core/src/validate-initializers.test.ts +++ b/packages/core/src/validate-initializers.test.ts @@ -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: [ diff --git a/packages/core/src/validate/run/initializer.ts b/packages/core/src/validate/run/initializer.ts index 9719e27f2..e3f1428eb 100644 --- a/packages/core/src/validate/run/initializer.ts +++ b/packages/core/src/validate/run/initializer.ts @@ -257,9 +257,9 @@ function getPossibleInitializers(contractDef: ContractDefinition, isParentContra return fns.filter( fnDef => (fnDef.modifiers.some(modifier => - ['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