The home for Hyperlane core contracts, sdk packages, and other infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
hyperlane-monorepo/solidity/test/exhaustiveversion.test.ts

63 lines
1.7 KiB

import { CompilerOutputContract } from 'hardhat/types';
import { readFile, readdir } from 'node:fs/promises';
import { basename, join } from 'node:path';
const EXCLUDE_PATTERNS: RegExp[] = [
/\.dbg/g,
/interfaces\//g,
/libs\//g,
/Abstract/g,
/Test/g,
/Mock/g,
/Versioned/g,
// also abstract
/ECDSAServiceManagerBase/g,
/ECDSAStakeRegistryStorage/g,
];
const REQUIRED_METHOD = 'PACKAGE_VERSION';
// https://stackoverflow.com/questions/5827612/node-js-fs-readdir-recursive-directory-search
const walk = async (dirPath) =>
Promise.all(
await readdir(dirPath, { withFileTypes: true }).then((entries) =>
entries.map((entry) => {
const childPath = join(dirPath, entry.name);
return entry.isDirectory() ? walk(childPath) : childPath;
}),
),
);
const artifacts = (await walk('artifacts/contracts')).flat(
Number.POSITIVE_INFINITY,
);
const filtered = artifacts.filter((path: string) =>
EXCLUDE_PATTERNS.every((excluded) => path.match(excluded) === null),
);
const results = await Promise.all(
filtered.map(async (path) => {
const content = await readFile(path, 'utf-8');
const compilerOutput: CompilerOutputContract = JSON.parse(content);
return [
path,
compilerOutput.abi &&
compilerOutput.abi.some((elem) => elem.name === REQUIRED_METHOD),
];
}),
);
const missing = results.filter(([, included]) => !included);
if (missing.length > 0) {
console.error(
`Missing ${REQUIRED_METHOD} method in the following contracts:`,
);
const contracts = missing.map(([path]) =>
basename(path).replace('.json', ''),
);
console.error(contracts.map((contract) => ` - ${contract}`).join('\n'));
process.exit(1);
}
console.log('All contracts have the required method');