You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/writing-upgradeable.adoc
+9-2Lines changed: 9 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -191,12 +191,19 @@ contract MyContract {
191
191
192
192
Do not leave an implementation contract uninitialized. An uninitialized implementation contract can be taken over by an attacker, which may impact the proxy. To prevent the implementation contract from being used, you should invoke the `_disableInitializers` function in the constructor to automatically lock it when it is deployed:
193
193
194
-
```
194
+
[source,solidity]
195
+
----
195
196
/// @custom:oz-upgrades-unsafe-allow constructor
196
197
constructor() {
197
198
_disableInitializers();
198
199
}
199
-
```
200
+
----
201
+
202
+
=== Validating Initializers
203
+
204
+
The OpenZeppelin Upgrades plugins will automatically detect specific issues with initializers in implementation contracts. These include checking if your implementation contract is missing an initializer when there are parent initializers that need to be called, if a parent initializer is not called, or if a parent initializer is called more than once. The plugins will also warn if parent initializers are not called in linearized order.
205
+
206
+
Reinitializers are not included in validations by default, because the Upgrades plugins cannot determine whether they are intended to be used for new deployments. If you want to validate a reinitializer function as an initializer that can be used for new deployments, annotate it with `@custom:oz-upgrades-validate-as-initializer`. Note that functions which cannot possibly be initializers are always ignored, such as private functions which cannot be called externally or by child contracts.
testAccepts('InitializationOrder_WrongOrder_Bad','transparent');// warn 'Expected initializers to be called for parent contracts in the following order: A, B, C'
112
+
testAccepts('InitializationOrder_WrongOrder_Bad','transparent');// warn 'Expected: A, B, C'
testAccepts('InitializationOrder_UnsafeAllowDuplicate_But_WrongOrder','transparent');// warn 'Expected initializers to be called for parent contracts in the following order: A, B, C'
133
+
testAccepts('InitializationOrder_UnsafeAllowDuplicate_But_WrongOrder','transparent');// warn 'Expected: A, B, C'
'Missing initializer calls for one or more parent contracts: `TransitiveGrandparent2`',// occurs twice: missing initializer for child, missing initializer for parent
179
201
],
180
202
count: 2,
181
-
});// warn 'Expected initializers to be called for parent contracts in the following order: TransitiveGrandparent2, TransitiveParent_Bad'
0 commit comments