logs and comments in remixd

pull/5370/head
aniket-engg 3 years ago committed by Aniket
parent 71e40b7f4c
commit c831bb0997
  1. 2
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx
  2. 24
      libs/remixd/src/services/slitherClient.ts

@ -213,7 +213,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const { currentVersion, optimize, evmVersion } = compilerState const { currentVersion, optimize, evmVersion } = compilerState
props.analysisModule.call('slither', 'analyse', state.file, { currentVersion, optimize, evmVersion }).then((result) => { props.analysisModule.call('slither', 'analyse', state.file, { currentVersion, optimize, evmVersion }).then((result) => {
if (result.status) { if (result.status) {
props.analysisModule.call('terminal', 'log', { type: 'info', value: `[Slither Analysis]: Success!! ${result.count} warnings found.` }) props.analysisModule.call('terminal', 'log', { type: 'info', value: `[Slither Analysis]: Analysis Completed!! ${result.count} warnings found.` })
const report = result.data const report = result.data
report.map((item) => { report.map((item) => {
let location: any = {} let location: any = {}

@ -50,27 +50,40 @@ export class SlitherClient extends PluginClient {
} }
const options = { cwd: this.currentSharedFolder, shell: true } const options = { cwd: this.currentSharedFolder, shell: true }
const { currentVersion, optimize, evmVersion } = compilerConfig const { currentVersion, optimize, evmVersion } = compilerConfig
if (currentVersion) { if (currentVersion && currentVersion.includes('+commit')) {
// Get compiler version with commit id e.g: 0.8.2+commit.661d110
const versionString: string = currentVersion.substring(0, currentVersion.indexOf('+commit') + 16) const versionString: string = currentVersion.substring(0, currentVersion.indexOf('+commit') + 16)
console.log('\x1b[32m%s\x1b[0m', `[Slither Analysis]: Compiler version is ${versionString}`)
// Check solc current installed version
const solcOutput: Buffer = execSync('solc --version', options) const solcOutput: Buffer = execSync('solc --version', options)
if (!solcOutput.toString().includes(versionString)) { if (!solcOutput.toString().includes(versionString)) {
console.log('\x1b[32m%s\x1b[0m', `[Slither Analysis]: Compiler version is different from installed solc version`)
// Get compiler version without commit id e.g: 0.8.2
const version: string = versionString.substring(0, versionString.indexOf('+commit')) const version: string = versionString.substring(0, versionString.indexOf('+commit'))
// List solc versions installed using solc-select
const solcSelectInstalledVersions: Buffer = execSync('solc-select versions', options) const solcSelectInstalledVersions: Buffer = execSync('solc-select versions', options)
// Check if required version is already installed
if (!solcSelectInstalledVersions.toString().includes(version)) { if (!solcSelectInstalledVersions.toString().includes(version)) {
console.log('\x1b[32m%s\x1b[0m', `[Slither Analysis]: Installing ${version} using solc-select`)
// Install required version
execSync(`solc-select install ${version}`, options) execSync(`solc-select install ${version}`, options)
} }
console.log('\x1b[32m%s\x1b[0m', `[Slither Analysis]: Setting ${version} as current solc version using solc-select`)
// Set solc current version as required version
execSync(`solc-select use ${version}`, options) execSync(`solc-select use ${version}`, options)
} } else console.log('\x1b[32m%s\x1b[0m', `[Slither Analysis]: Compiler version is same as installed solc version`)
} }
const outputFile: string = 'remix-slitherReport_' + Date.now() + '.json' const outputFile: string = 'remix-slitherReport_' + Date.now() + '.json'
const optimizeOption: string = optimize ? '--optimize ' : '' const optimizeOption: string = optimize ? '--optimize ' : ''
const evmOption: string = evmVersion ? `--evm-version ${evmVersion}` : '' const evmOption: string = evmVersion ? `--evm-version ${evmVersion}` : ''
const solcArgs: string = optimizeOption || evmOption ? `--solc-args '${optimizeOption}${evmOption}'` : '' const solcArgs: string = optimizeOption || evmOption ? `--solc-args '${optimizeOption}${evmOption}'` : ''
const cmd: string = `slither ${filePath} ${solcArgs} --json ${outputFile}` const cmd: string = `slither ${filePath} ${solcArgs} --json ${outputFile}`
console.log('\x1b[32m%s\x1b[0m', `[Slither Analysis]: Running Slither...`)
const child = spawn(cmd, options) const child = spawn(cmd, options)
const response = {} const response = {}
child.on('close', () => { child.on('close', () => {
const outputFileAbsPath: string = `${this.currentSharedFolder}/${outputFile}` const outputFileAbsPath: string = `${this.currentSharedFolder}/${outputFile}`
// Check if slither report file exists
if (existsSync(outputFileAbsPath)) { if (existsSync(outputFileAbsPath)) {
let report = readFileSync(outputFileAbsPath, 'utf8') let report = readFileSync(outputFileAbsPath, 'utf8')
report = JSON.parse(report) report = JSON.parse(report)
@ -83,13 +96,14 @@ export class SlitherClient extends PluginClient {
response['count'] = detectors.length response['count'] = detectors.length
response['data'] = this.transform(detectors) response['data'] = this.transform(detectors)
} }
console.log('\x1b[32m%s\x1b[0m', `[Slither Analysis]: Analysis Completed!! ${response['count']} warnings found.`)
resolve(response) resolve(response)
} else { } else {
console.log('[Slither Analysis]: Error in running Slither Analysis') console.log('\x1b[31m%s\x1b[0m', '[Slither Analysis]: Error in running Slither Analysis')
console.log(report['error']) console.log(report['error'])
reject(new Error('Error in running Slither Analysis. See remixd console.')) reject(new Error('Error in running Slither Analysis. See remixd console for details.'))
} }
} else reject(new Error('Error in generating Slither Analysis Report. See remixd console.')) } else reject(new Error('Error in generating Slither Analysis Report. See remixd console for details.'))
}) })
}) })
} }

Loading…
Cancel
Save