env-artifacts.js 850 B

123456789101112131415161718192021222324
  1. const { HardhatError } = require('hardhat/internal/core/errors');
  2. // Modifies `artifacts.require(X)` so that instead of X it loads the XUpgradeable contract.
  3. // This allows us to run the same test suite on both the original and the transpiled and renamed Upgradeable contracts.
  4. extendEnvironment(env => {
  5. const artifactsRequire = env.artifacts.require;
  6. env.artifacts.require = name => {
  7. for (const suffix of ['UpgradeableWithInit', 'Upgradeable', '']) {
  8. try {
  9. return artifactsRequire(name + suffix);
  10. } catch (e) {
  11. // HH700: Artifact not found - from https://hardhat.org/hardhat-runner/docs/errors#HH700
  12. if (HardhatError.isHardhatError(e) && e.number === 700 && suffix !== '') {
  13. continue;
  14. } else {
  15. throw e;
  16. }
  17. }
  18. }
  19. throw new Error('Unreachable');
  20. };
  21. });