Interacting with UUPS Upgradeable Contracts in Test Throwing "Contract is not upgrade safe. Use of delegatecall is not allowed"

This looks like a bug in the Upgrades Plugins where the import is being validated against the wrong library.

The VaultFactory contract has a transitive dependency on Initializable from @openzeppelin/contracts-upgradeable. This is the correct dependency for upgradeable contracts.

But when the plugin does validation, it is also matching against Initializable from @openzeppelin/contracts (due to other contracts importing that version). The validation should match against the one from @openzeppelin/contracts-upgradeable instead.

Initializable (the non-upgradeable version) imports a function from Address, and Address has a delegatecall function and therefore triggers the error.


The root cause is the same as https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/240 since the Address function being imported in Initializable does not contain the delegatecall itself.

But some additional setup in your repo is causing the upgradeable and non-upgradeable library to be mixed up during validations -- this seems to be a separate issue in the plugins which is tracked in https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/263

UPDATE: this is fixed as of @openzeppelin/upgrades-core@1.20.4