|
| 1 | +import { readFileSync, readdirSync } from 'node:fs' |
| 2 | +import { dirname, join } from 'node:path' |
| 3 | +import { fileURLToPath } from 'node:url' |
| 4 | +import { |
| 5 | + AssetHubProxyTypes, |
| 6 | + CollectivesProxyTypes, |
| 7 | + CoretimeProxyTypes, |
| 8 | + KusamaProxyTypes, |
| 9 | + PeopleProxyTypes, |
| 10 | + PolkadotProxyTypes, |
| 11 | +} from '../packages/shared/src/helpers/proxyTypes.js' |
| 12 | + |
| 13 | +type ProxyTypeMap = Record<string, number> |
| 14 | + |
| 15 | +interface NetworkProxyTypes { |
| 16 | + name: string |
| 17 | + proxyTypes: ProxyTypeMap |
| 18 | +} |
| 19 | + |
| 20 | +const networks: NetworkProxyTypes[] = [ |
| 21 | + { name: 'Polkadot', proxyTypes: PolkadotProxyTypes }, |
| 22 | + { name: 'Kusama', proxyTypes: KusamaProxyTypes }, |
| 23 | + { name: 'AssetHubPolkadot', proxyTypes: AssetHubProxyTypes }, |
| 24 | + { name: 'AssetHubKusama', proxyTypes: AssetHubProxyTypes }, |
| 25 | + { name: 'CollectivesPolkadot', proxyTypes: CollectivesProxyTypes }, |
| 26 | + { name: 'CoretimePolkadot', proxyTypes: CoretimeProxyTypes }, |
| 27 | + { name: 'CoretimeKusama', proxyTypes: CoretimeProxyTypes }, |
| 28 | + { name: 'PeoplePolkadot', proxyTypes: PeopleProxyTypes }, |
| 29 | + { name: 'PeopleKusama', proxyTypes: PeopleProxyTypes }, |
| 30 | +] |
| 31 | + |
| 32 | +function findProxyTestSnapshots(dir: string): string[] { |
| 33 | + const files: string[] = [] |
| 34 | + const entries = readdirSync(dir, { withFileTypes: true }) |
| 35 | + |
| 36 | + for (const entry of entries) { |
| 37 | + const fullPath = join(dir, entry.name) |
| 38 | + if (entry.isDirectory()) { |
| 39 | + files.push(...findProxyTestSnapshots(fullPath)) |
| 40 | + } else if (entry.isFile() && entry.name.endsWith('proxy.e2e.test.ts.snap')) { |
| 41 | + files.push(fullPath) |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + return files |
| 46 | +} |
| 47 | + |
| 48 | +function checkProxyTypeTests(network: NetworkProxyTypes, snapshotFiles: string[]): void { |
| 49 | + console.log(`\nChecking ${network.name} proxy type test coverage:`) |
| 50 | + |
| 51 | + const proxyTypes = network.proxyTypes |
| 52 | + const missingTests: string[] = [] |
| 53 | + |
| 54 | + const proxyTypesToCheck = Object.keys(proxyTypes) |
| 55 | + |
| 56 | + // Filter snapshots for this network |
| 57 | + const networkSnapshots = snapshotFiles.filter((file) => file.includes(network.name)) |
| 58 | + |
| 59 | + for (const proxyTypeName of proxyTypesToCheck) { |
| 60 | + const allowed = networkSnapshots.some((file) => |
| 61 | + readFileSync(file, 'utf-8').includes(`allowed proxy calls for ${proxyTypeName}`), |
| 62 | + ) |
| 63 | + const forbidden = networkSnapshots.some((file) => |
| 64 | + readFileSync(file, 'utf-8').includes(`forbidden proxy calls for ${proxyTypeName}`), |
| 65 | + ) |
| 66 | + |
| 67 | + if (!allowed) missingTests.push(`${proxyTypeName} (allowed tests missing)`) |
| 68 | + if (!forbidden) missingTests.push(`${proxyTypeName} (forbidden tests missing)`) |
| 69 | + } |
| 70 | + |
| 71 | + if (missingTests.length === 0) { |
| 72 | + console.log('✅ All proxy types have both allowed and forbidden test coverage') |
| 73 | + } else { |
| 74 | + console.log('❌ Missing test coverage for:') |
| 75 | + missingTests.forEach((test) => console.log(` - ${test}`)) |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +function main() { |
| 80 | + const rootDir = join(dirname(fileURLToPath(import.meta.url)), '..') |
| 81 | + const snapshotFiles = findProxyTestSnapshots(rootDir) |
| 82 | + console.log(snapshotFiles) |
| 83 | + |
| 84 | + console.log('Proxy Type Test Coverage Checker') |
| 85 | + console.log('===============================') |
| 86 | + |
| 87 | + for (const network of networks) { |
| 88 | + checkProxyTypeTests(network, snapshotFiles) |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +main() |
0 commit comments