-
Notifications
You must be signed in to change notification settings - Fork 454
/
Copy pathenv-artifacts.js
29 lines (26 loc) · 1019 Bytes
/
env-artifacts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const { HardhatError } = require('hardhat/internal/core/errors');
function isExpectedError(e, suffix) {
// HH700: Artifact not found - from https://hardhat.org/hardhat-runner/docs/errors#HH700
return HardhatError.isHardhatError(e) && e.number === 700 && suffix !== '';
}
// Modifies the artifact require functions so that instead of X it loads the XUpgradeable contract.
// This allows us to run the same test suite on both the original and the transpiled and renamed Upgradeable contracts.
extendEnvironment(hre => {
const suffixes = ['UpgradeableWithInit', 'Upgradeable', ''];
// Ethers
const originalReadArtifact = hre.artifacts.readArtifact;
hre.artifacts.readArtifact = async function (name) {
for (const suffix of suffixes) {
try {
return await originalReadArtifact.call(this, name + suffix);
} catch (e) {
if (isExpectedError(e, suffix)) {
continue;
} else {
throw e;
}
}
}
throw new Error('Unreachable');
};
});