dexorder
This commit is contained in:
3
lib_openzeppelin_contracts/hardhat/async-test-sanity.js
Normal file
3
lib_openzeppelin_contracts/hardhat/async-test-sanity.js
Normal file
@@ -0,0 +1,3 @@
|
||||
process.on('unhandledRejection', reason => {
|
||||
throw new Error(reason);
|
||||
});
|
||||
29
lib_openzeppelin_contracts/hardhat/env-artifacts.js
Normal file
29
lib_openzeppelin_contracts/hardhat/env-artifacts.js
Normal file
@@ -0,0 +1,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');
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
// Warnings about unreachable code are emitted with a source location that corresponds to the unreachable code.
|
||||
// We have some testing contracts that purposely cause unreachable code, but said code is in the library contracts, and
|
||||
// with hardhat-ignore-warnings we are not able to selectively ignore them without potentially ignoring relevant
|
||||
// warnings that we don't want to miss.
|
||||
// Thus, we need to handle these warnings separately. We force Hardhat to compile them in a separate compilation job and
|
||||
// then ignore the warnings about unreachable code that come from that compilation job.
|
||||
|
||||
const { task } = require('hardhat/config');
|
||||
const {
|
||||
TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE,
|
||||
TASK_COMPILE_SOLIDITY_COMPILE,
|
||||
} = require('hardhat/builtin-tasks/task-names');
|
||||
|
||||
const marker = Symbol('unreachable');
|
||||
const markedCache = new WeakMap();
|
||||
|
||||
task(TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE, async (params, _, runSuper) => {
|
||||
const job = await runSuper(params);
|
||||
// If the file is in the unreachable directory, we make a copy of the config and mark it, which will cause it to get
|
||||
// compiled separately (along with the other marked files).
|
||||
if (params.file.sourceName.startsWith('contracts/mocks/') && /\bunreachable\b/.test(params.file.sourceName)) {
|
||||
const originalConfig = job.solidityConfig;
|
||||
let markedConfig = markedCache.get(originalConfig);
|
||||
if (markedConfig === undefined) {
|
||||
markedConfig = { ...originalConfig, [marker]: true };
|
||||
markedCache.set(originalConfig, markedConfig);
|
||||
}
|
||||
job.solidityConfig = markedConfig;
|
||||
}
|
||||
return job;
|
||||
});
|
||||
|
||||
const W_UNREACHABLE_CODE = '5740';
|
||||
|
||||
task(TASK_COMPILE_SOLIDITY_COMPILE, async (params, _, runSuper) => {
|
||||
const marked = params.compilationJob.solidityConfig[marker];
|
||||
const result = await runSuper(params);
|
||||
if (marked) {
|
||||
result.output = {
|
||||
...result.output,
|
||||
errors: result.output.errors?.filter(e => e.severity !== 'warning' || e.errorCode !== W_UNREACHABLE_CODE),
|
||||
};
|
||||
}
|
||||
return result;
|
||||
});
|
||||
18
lib_openzeppelin_contracts/hardhat/remappings.js
Normal file
18
lib_openzeppelin_contracts/hardhat/remappings.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const fs = require('fs');
|
||||
const { task } = require('hardhat/config');
|
||||
const { TASK_COMPILE_GET_REMAPPINGS } = require('hardhat/builtin-tasks/task-names');
|
||||
|
||||
task(TASK_COMPILE_GET_REMAPPINGS).setAction((taskArgs, env, runSuper) =>
|
||||
runSuper().then(remappings =>
|
||||
Object.assign(
|
||||
remappings,
|
||||
Object.fromEntries(
|
||||
fs
|
||||
.readFileSync('remappings.txt', 'utf-8')
|
||||
.split('\n')
|
||||
.filter(Boolean)
|
||||
.map(line => line.trim().split('=')),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
6
lib_openzeppelin_contracts/hardhat/skip-foundry-tests.js
Normal file
6
lib_openzeppelin_contracts/hardhat/skip-foundry-tests.js
Normal file
@@ -0,0 +1,6 @@
|
||||
const { subtask } = require('hardhat/config');
|
||||
const { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } = require('hardhat/builtin-tasks/task-names');
|
||||
|
||||
subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(async (_, __, runSuper) =>
|
||||
(await runSuper()).filter(path => !path.endsWith('.t.sol')),
|
||||
);
|
||||
25
lib_openzeppelin_contracts/hardhat/task-test-get-files.js
Normal file
25
lib_openzeppelin_contracts/hardhat/task-test-get-files.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const { internalTask } = require('hardhat/config');
|
||||
const { TASK_TEST_GET_TEST_FILES } = require('hardhat/builtin-tasks/task-names');
|
||||
|
||||
// Modifies `hardhat test` to skip the proxy tests after proxies are removed by the transpiler for upgradeability.
|
||||
|
||||
internalTask(TASK_TEST_GET_TEST_FILES).setAction(async (args, hre, runSuper) => {
|
||||
const path = require('path');
|
||||
const { promises: fs } = require('fs');
|
||||
|
||||
const hasProxies = await fs
|
||||
.access(path.join(hre.config.paths.sources, 'proxy/Proxy.sol'))
|
||||
.then(() => true)
|
||||
.catch(() => false);
|
||||
|
||||
const ignoredIfProxy = [
|
||||
'proxy/beacon/BeaconProxy.test.js',
|
||||
'proxy/beacon/UpgradeableBeacon.test.js',
|
||||
'proxy/ERC1967/ERC1967Proxy.test.js',
|
||||
'proxy/transparent/ProxyAdmin.test.js',
|
||||
'proxy/transparent/TransparentUpgradeableProxy.test.js',
|
||||
'proxy/utils/UUPSUpgradeable.test.js',
|
||||
].map(p => path.join(hre.config.paths.tests, p));
|
||||
|
||||
return (await runSuper(args)).filter(file => hasProxies || !ignoredIfProxy.includes(file));
|
||||
});
|
||||
Reference in New Issue
Block a user