-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scaffold repo scripts, add Slither (#3)
* WIP: scripts * Added inquirer and multiple output types * Update .gitignore Co-authored-by: Lucas <[email protected]> * added option for CI and other PR feedback * Update scripts/slither.ts * Update scripts/slither.ts * Add ts-node, add slither script * Remove await * Blankline Co-authored-by: Lucas Janon <[email protected]>
- Loading branch information
1 parent
ea11bc6
commit d651c44
Showing
5 changed files
with
438 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import fs from "fs"; | ||
import inquirer from "inquirer"; | ||
import { execSync } from "node:child_process"; | ||
import path from "node:path"; | ||
|
||
const projectRoot = path.join(__dirname, "../"); | ||
const solcVersion = "0.8.9"; | ||
const timestamp = Date.now(); | ||
const packageNames = ["protocol-contracts", "example-contracts"]; | ||
|
||
async function getPackageName() { | ||
let packageName; | ||
|
||
if (process.env.CI) { | ||
packageName = process.argv[2]; | ||
|
||
if (!packageNames.includes(packageName)) { | ||
console.error(`${packageName} is not a valid package name.`); | ||
console.error(`Valid package names are: ${packageNames.join(", ")}`); | ||
process.exit(1); | ||
} | ||
|
||
return packageName; | ||
} else { | ||
packageName = await inquirer.prompt([ | ||
{ | ||
type: "list", | ||
message: "Which set of contracts would you like to test?", | ||
name: "contracts", | ||
choices: packageNames, | ||
}, | ||
]); | ||
|
||
return packageName.contracts; | ||
} | ||
} | ||
|
||
const run = async (command: string) => { | ||
try { | ||
console.log("Starting -- This may take a few minutes..."); | ||
|
||
execSync(command, { | ||
encoding: "utf-8", | ||
stdio: "inherit", | ||
}); | ||
|
||
console.log("Results output to the console and saved to slither-output/ in Markdown, JSON, and SARIF formats."); | ||
} catch (error: any) { | ||
console.error("Error: Docker Failed To Run"); | ||
console.error(`${error}`); | ||
} | ||
}; | ||
|
||
function runSlither(packageName: string) { | ||
const dockerCommand = `cd /home/trufflecon/packages/${packageName} && \ | ||
solc-select use ${solcVersion} && \ | ||
slither --json ../../scripts/slither-results/${packageName}-${timestamp}.json \ | ||
--sarif ../../scripts/slither-results/${packageName}-${timestamp}.sarif \ | ||
--checklist ./ | tee ../../scripts/slither-results/${packageName}-${timestamp}.md`; | ||
|
||
run(`docker run -v "${projectRoot}":/home/trufflecon trailofbits/eth-security-toolbox -c "${dockerCommand}"`); | ||
} | ||
|
||
async function main() { | ||
const packageName = await getPackageName(); | ||
|
||
runSlither(packageName); | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.