Skip to content

Commit

Permalink
Generate the config from collected files
Browse files Browse the repository at this point in the history
  • Loading branch information
gvladika committed Aug 16, 2024
1 parent 328602a commit 847c436
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions test-mutation/gambitTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import os from 'os'
import * as path from 'path'
import * as fs from 'fs'
import * as fsExtra from 'fs-extra'
import { readdir } from 'node:fs/promises'

const GAMBIT_OUT = 'gambit_out/'
const CONTRACTS_DIR = 'contracts'
const TEST_ITEMS = [
'contracts',
'foundry.toml',
Expand Down Expand Up @@ -45,6 +43,8 @@ runMutationTesting().catch(error => {
async function runMutationTesting() {
const startTime = Date.now()

await _generateConfigForGithubCI()

console.log('====== Generating mutants')
const mutants: Mutant[] = await _generateMutants()

Expand Down Expand Up @@ -189,6 +189,12 @@ function _printResults(results: TestResult[]) {
console.log(`Survived: ${survivedCount} (${survivedPercentage}%)`)
}

////////////////////////////////////////////////////////////////////

// GAMBIT CONFIG GENERATION

////////////////////////////////////////////////////////////////////

async function _generateConfigForGithubCI() {
const solidityDirs = [
path.join(__dirname, '../contracts/tokenbridge/ethereum'),
Expand All @@ -197,7 +203,26 @@ async function _generateConfigForGithubCI() {
]
const solidityFiles = await _findSolidityFiles(solidityDirs)

console.log(solidityFiles)
// Construct the JSON array
const jsonConfig = solidityFiles.map(file => ({
filename: file,
sourceroot: '..',
solc_remappings: [
'@openzeppelin=../node_modules/@openzeppelin',
'@arbitrum=../node_modules/@arbitrum',
],
num_mutants: 4,
random_seed: true,
}))

// Write the result to a JSON file
const outputFilePath = path.join(__dirname, 'config_for_github_ci.json')
await fs.promises.writeFile(
outputFilePath,
JSON.stringify(jsonConfig, null, 2),
'utf-8'
)
console.log(`Generated JSON file: ${outputFilePath}`)
}

async function _findSolidityFiles(directories: string[]): Promise<string[]> {
Expand All @@ -212,8 +237,8 @@ async function _findSolidityFiles(directories: string[]): Promise<string[]> {
// Recursively explore subdirectory
await exploreDirectory(fullPath)
} else if (entry.isFile() && path.extname(fullPath) === '.sol') {
// If it's a .sol file, add to the list
solidityFiles.push(fullPath)
const relativePath = path.relative(__dirname, fullPath)
solidityFiles.push(relativePath)
}
}
}
Expand Down

0 comments on commit 847c436

Please sign in to comment.