Commit d8d41bcb authored by OptimismBot's avatar OptimismBot Committed by GitHub

Merge pull request #6240 from ethereum-optimism/cleanup/ctb-remove-glob-dep

contracts-bedrock: remove glob dependency
parents af8a1ff5 d5bc9c13
......@@ -48,7 +48,6 @@
"@typescript-eslint/parser": "^5.60.1",
"ds-test": "github:dapphub/ds-test#c9ce3f25bde29fc5eb9901842bf02850dfd2d084",
"forge-std": "github:foundry-rs/forge-std#e8a047e3f40f13fa37af6fe14e6e06283d9a060e",
"glob": "^7.1.6",
"solhint": "^3.4.1",
"solhint-plugin-prettier": "^0.0.5",
"ts-node": "^10.9.1",
......
import fs from 'fs'
import { glob } from 'glob'
import path from 'path'
import { execSync } from 'child_process'
/**
* Series of function name checks.
......@@ -59,27 +59,67 @@ const checks: Array<{
* Script for checking that all test functions are named correctly.
*/
const main = async () => {
const result = execSync('forge config --json')
const config = JSON.parse(result.toString())
const out = config.out || 'out'
const paths = []
const readFilesRecursively = (dir: string) => {
const files = fs.readdirSync(dir)
for (const file of files) {
const filePath = path.join(dir, file)
const fileStat = fs.statSync(filePath)
if (fileStat.isDirectory()) {
readFilesRecursively(filePath)
} else {
paths.push(filePath)
}
}
}
readFilesRecursively(out)
console.log('Success:')
const errors: string[] = []
const files = glob.sync('./forge-artifacts/**/*.t.sol/*Test*.json')
for (const file of files) {
const artifact = JSON.parse(fs.readFileSync(file, 'utf8'))
for (const filepath of paths) {
const artifact = JSON.parse(fs.readFileSync(filepath, 'utf8'))
let isTest = false
for (const element of artifact.abi) {
// Skip non-functions and functions that don't start with "test".
if (element.type !== 'function' || !element.name.startsWith('test')) {
continue
if (element.name === 'IS_TEST') {
isTest = true
break
}
}
if (isTest) {
let success = true
for (const element of artifact.abi) {
// Skip non-functions and functions that don't start with "test".
if (element.type !== 'function' || !element.name.startsWith('test')) {
continue
}
// Check the rest.
for (const { check, error } of checks) {
if (!check(element.name.split('_'))) {
errors.push(`in ${file} function ${element.name}: ${error}`)
// Check the rest.
for (const { check, error } of checks) {
if (!check(element.name.split('_'))) {
errors.push(`${filepath} function ${element.name}: ${error}`)
success = false
}
}
}
if (success) {
console.log(` - ${path.parse(filepath).name}`)
}
}
}
if (errors.length > 0) {
console.error(...errors)
console.error(errors.join('\n'))
process.exit(1)
}
}
......
......@@ -277,9 +277,6 @@ importers:
forge-std:
specifier: github:foundry-rs/forge-std#e8a047e3f40f13fa37af6fe14e6e06283d9a060e
version: github.com/foundry-rs/forge-std/e8a047e3f40f13fa37af6fe14e6e06283d9a060e
glob:
specifier: ^7.1.6
version: 7.1.6
solhint:
specifier: ^3.4.1
version: 3.4.1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment