-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfuzz.ts
executable file
·51 lines (43 loc) · 1.41 KB
/
fuzz.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env ts-node
import { parallelMap, sequentialMap } from './libs/utils/promise'
import { readFileAsYaml } from './libs/utils/yaml/readFileAsYaml'
import { writeFileAsYaml } from './libs/utils/yaml/writeFileAsYaml'
import { clone } from 'remeda'
import { file } from 'tmp-promise'
import childProcess from 'child_process'
import { promisify } from 'util'
import { debug } from './libs/utils/debug'
const execFile = promisify(childProcess.execFile)
interface EchidnaConfig {
mode: string
}
const modes = ['overflow', 'assertion']
const contracts = ['FairpoolTestEchidna', 'ERC20EnumerableTestEchidna', 'SharedOwnershipTest']
async function main() {
const config: EchidnaConfig = await readFileAsYaml('.echidna.yml')
return parallelMap(modes, fuzzMode(config))
}
const fuzzMode = (config: EchidnaConfig) => async (mode: string) => {
const $config = clone(config)
$config.mode = mode
return sequentialMap(contracts, fuzzContract($config))
}
const fuzzContract = (config: EchidnaConfig) => async (contract: string) => {
const { path, cleanup } = await file()
await writeFileAsYaml(path, config)
debug(__filename, fuzzContract, config.mode, contract, path)
const result = await execFile('echidna-test', [
'--config',
path,
'--contract',
contract,
`contracts/${contract}.sol`,
])
.finally(cleanup)
return result
}
main()
.catch(e => {
console.error(e)
process.exit(1)
})