Fix .gitignore: stop tracking ignored files

This commit is contained in:
5t4l1n
2025-07-27 10:39:02 +05:30
parent b42747e9a3
commit 3a87ef0576
625 changed files with 88566 additions and 63 deletions
@@ -0,0 +1,24 @@
const { HardhatError } = require('hardhat/internal/core/errors');
// Modifies `artifacts.require(X)` 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(env => {
const artifactsRequire = env.artifacts.require;
env.artifacts.require = name => {
for (const suffix of ['UpgradeableWithInit', 'Upgradeable', '']) {
try {
return artifactsRequire(name + suffix);
} catch (e) {
// HH700: Artifact not found - from https://hardhat.org/hardhat-runner/docs/errors#HH700
if (HardhatError.isHardhatError(e) && e.number === 700 && suffix !== '') {
continue;
} else {
throw e;
}
}
}
throw new Error('Unreachable');
};
});
@@ -0,0 +1,10 @@
extendEnvironment(env => {
const { contract } = env;
env.contract = function (name, body) {
// remove the default account from the accounts list used in tests, in order
// to protect tests against accidentally passing due to the contract
// deployer being used subsequently as function caller
contract(name, accounts => body(accounts.slice(1)));
};
});
@@ -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;
});
@@ -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')),
);
@@ -0,0 +1,35 @@
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 ({ testFiles }, { config }) => {
if (testFiles.length !== 0) {
return testFiles;
}
const globAsync = require('glob');
const path = require('path');
const { promises: fs } = require('fs');
const { promisify } = require('util');
const glob = promisify(globAsync);
const hasProxies = await fs
.access(path.join(config.paths.sources, 'proxy/Proxy.sol'))
.then(() => true)
.catch(() => false);
return await glob(path.join(config.paths.tests, '**/*.js'), {
ignore: hasProxies
? []
: [
'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(config.paths.tests, p)),
});
});