env-artifacts.js 542 B

1234567891011121314151617181920
  1. const { HardhatError } = require('hardhat/internal/core/errors');
  2. extendEnvironment(env => {
  3. const artifactsRequire = env.artifacts.require;
  4. env.artifacts.require = (name) => {
  5. for (const suffix of ['UpgradeableWithInit', 'Upgradeable', '']) {
  6. try {
  7. return artifactsRequire(name + suffix);
  8. } catch (e) {
  9. if (HardhatError.isHardhatError(e) && e.number === 700 && suffix !== '') {
  10. continue;
  11. } else {
  12. throw e;
  13. }
  14. }
  15. }
  16. throw new Error('Unreachable');
  17. };
  18. });