Skip to content

Commit

Permalink
Test initializer visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Dec 10, 2024
1 parent d8bcedd commit 210c71b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
28 changes: 24 additions & 4 deletions packages/core/contracts/test/ValidationsInitializer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ contract Parent__OnlyInitializingModifier is Initializable {
}

contract Parent_InitializeName {
function initialize() public virtual {}
function initialize() internal virtual {}
}

contract Parent_InitializerName {
function initializer() public {}
function initializer() internal {}
}

contract Parent_ReinitializeName {
function reinitialize(uint64 version) public {}
function reinitialize(uint64 version) internal {}
}

contract Parent_ReinitializerName {
function reinitializer(uint64 version) public {}
function reinitializer(uint64 version) internal {}
}

// ==== Child contracts ====
Expand Down Expand Up @@ -220,4 +220,24 @@ contract InitializationOrder_Duplicate_UnsafeAllow_Call is A, B, C, Parent_NoIni
__B_init();
__C_init();
}
}

// ==== Initializer visibility ====

contract Parent_PrivateInitializer {
function initialize() private {} // not considered an initializer because it's private
}

contract Parent_PublicInitializer {
function initialize() public {} // does not strictly need to be called by child
}

contract Child_Of_ParentPrivateInitializer_Ok is Parent_PrivateInitializer { // no initializer required since parent initializer is private
}

contract Child_Of_ParentPublicInitializer_Ok is Parent_PublicInitializer { // no initializer required since parent initializer is public
}

contract Child_Has_PrivateInitializer_Bad is Parent__OnlyInitializingModifier { // parent has internal initializer, but child has private
function initialize() private {}
}
4 changes: 4 additions & 0 deletions packages/core/src/validate-initializers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,7 @@ testValid('InitializationOrder_Duplicate_UnsafeAllow_Contract', 'transparent', t
testValid('InitializationOrder_Duplicate_UnsafeAllow_Function', 'transparent', true);
testValid('InitializationOrder_Duplicate_UnsafeAllow_Call', 'transparent', true);
testOverride('InitializationOrder_Duplicate_Bad', 'transparent', { unsafeAllow: ['duplicate-initializer-call'] }, true);

testValid('Child_Of_ParentPrivateInitializer_Ok', 'transparent', true);
testValid('Child_Of_ParentPublicInitializer_Ok', 'transparent', true);
testValid('Child_Has_PrivateInitializer_Bad', 'transparent', false, 'Contract is missing an initializer');

0 comments on commit 210c71b

Please sign in to comment.