7
7
// node certora/run.js AccessControl
8
8
// node certora/run.js AccessControlHarness:AccessControl
9
9
10
- const proc = require ( 'child_process' ) ;
11
- const { PassThrough } = require ( 'stream' ) ;
12
- const events = require ( 'events' ) ;
13
-
14
- const argv = require ( 'yargs' )
10
+ import { spawn } from 'child_process' ;
11
+ import { PassThrough } from 'stream' ;
12
+ import { once } from 'events' ;
13
+ import path from 'path' ;
14
+ import yargs from 'yargs' ;
15
+ import { hideBin } from 'yargs/helpers' ;
16
+ import pLimit from 'p-limit' ;
17
+ import fs from 'fs/promises' ;
18
+
19
+ const argv = yargs ( hideBin ( process . argv ) )
15
20
. env ( '' )
16
21
. options ( {
17
22
all : {
@@ -21,7 +26,7 @@ const argv = require('yargs')
21
26
spec : {
22
27
alias : 's' ,
23
28
type : 'string' ,
24
- default : __dirname + '/ specs.json',
29
+ default : path . resolve ( import . meta . dirname , ' specs.json') ,
25
30
} ,
26
31
parallel : {
27
32
alias : 'p' ,
@@ -38,18 +43,20 @@ const argv = require('yargs')
38
43
type : 'array' ,
39
44
default : [ ] ,
40
45
} ,
41
- } ) . argv ;
46
+ } )
47
+ . parse ( ) ;
42
48
43
49
function match ( entry , request ) {
44
50
const [ reqSpec , reqContract ] = request . split ( ':' ) . reverse ( ) ;
45
51
return entry . spec == reqSpec && ( ! reqContract || entry . contract == reqContract ) ;
46
52
}
47
53
48
- const specs = require ( argv . spec ) . filter ( s => argv . all || argv . _ . some ( r => match ( s , r ) ) ) ;
49
- const limit = require ( 'p-limit' ) ( argv . parallel ) ;
54
+ const specs = JSON . parse ( fs . readFileSync ( argv . spec , 'utf8' ) ) . filter ( s => argv . all || argv . _ . some ( r => match ( s , r ) ) ) ;
55
+
56
+ const limit = pLimit ( argv . parallel ) ;
50
57
51
58
if ( argv . _ . length == 0 && ! argv . all ) {
52
- console . error ( `Warning: No specs requested. Did you forgot to toggle '--all'?` ) ;
59
+ console . error ( `Warning: No specs requested. Did you forget to toggle '--all'?` ) ;
53
60
}
54
61
55
62
for ( const r of argv . _ ) {
@@ -64,12 +71,13 @@ if (process.exitCode) {
64
71
}
65
72
66
73
for ( const { spec, contract, files, options = [ ] } of specs ) {
67
- limit (
68
- runCertora ,
69
- spec ,
70
- contract ,
71
- files ,
72
- [ ...options , ...argv . options ] . flatMap ( opt => opt . split ( ' ' ) ) ,
74
+ limit ( ( ) =>
75
+ runCertora (
76
+ spec ,
77
+ contract ,
78
+ files ,
79
+ [ ...options , ...argv . options ] . flatMap ( opt => opt . split ( ' ' ) ) ,
80
+ ) ,
73
81
) ;
74
82
}
75
83
@@ -79,7 +87,7 @@ async function runCertora(spec, contract, files, options = []) {
79
87
if ( argv . verbose ) {
80
88
console . log ( 'Running:' , args . join ( ' ' ) ) ;
81
89
}
82
- const child = proc . spawn ( 'certoraRun' , args ) ;
90
+ const child = spawn ( 'certoraRun' , args ) ;
83
91
84
92
const stream = new PassThrough ( ) ;
85
93
const output = collect ( stream ) ;
@@ -103,7 +111,7 @@ async function runCertora(spec, contract, files, options = []) {
103
111
} ) ;
104
112
105
113
// wait for process end
106
- const [ code , signal ] = await events . once ( child , 'exit' ) ;
114
+ const [ code , signal ] = await once ( child , 'exit' ) ;
107
115
108
116
// error
109
117
if ( code || signal ) {
0 commit comments