run.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env node
  2. // USAGE:
  3. // node certora/run.js [CONFIG]* [--all]
  4. // EXAMPLES:
  5. // node certora/run.js --all
  6. // node certora/run.js ERC721
  7. // node certora/run.js certora/specs/ERC721.conf
  8. const glob = require('glob');
  9. const fs = require('fs');
  10. const pLimit = require('p-limit').default;
  11. const { hideBin } = require('yargs/helpers');
  12. const yargs = require('yargs/yargs');
  13. const { exec } = require('child_process');
  14. const { argv } = yargs(hideBin(process.argv))
  15. .env('')
  16. .options({
  17. all: {
  18. type: 'boolean',
  19. },
  20. parallel: {
  21. alias: 'p',
  22. type: 'number',
  23. default: 4,
  24. },
  25. verbose: {
  26. alias: 'v',
  27. type: 'count',
  28. default: 0,
  29. },
  30. });
  31. const pattern = 'certora/specs/*.conf';
  32. const limit = pLimit(argv.parallel);
  33. if (argv._.length == 0 && !argv.all) {
  34. console.error(`Warning: No specs requested. Did you forget to toggle '--all'?`);
  35. process.exitCode = 1;
  36. } else {
  37. Promise.all(
  38. (argv.all ? glob.sync(pattern) : argv._.map(name => (fs.existsSync(name) ? name : pattern.replace('*', name)))).map(
  39. (conf, i, { length }) =>
  40. limit(
  41. () =>
  42. new Promise(resolve => {
  43. if (argv.verbose) console.log(`[${i + 1}/${length}] Running ${conf}`);
  44. exec(`certoraRun ${conf}`, (error, stdout, stderr) => {
  45. const match = stdout.match(
  46. 'https://prover.certora.com/output/[a-z0-9]+/[a-z0-9]+[?]anonymousKey=[a-z0-9]+',
  47. );
  48. if (error) {
  49. console.error(`[ERR] ${conf} failed with:\n${stderr || stdout}`);
  50. process.exitCode = 1;
  51. } else if (match) {
  52. console.log(`${conf} - ${match[0]}`);
  53. } else {
  54. console.error(`[ERR] Could not parse stdout for ${conf}:\n${stdout}`);
  55. process.exitCode = 1;
  56. }
  57. resolve();
  58. });
  59. }),
  60. ),
  61. ),
  62. );
  63. }