Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified logic to select contract in case of multiple #12

Merged
merged 1 commit into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ const convertMythXReport2EsIssue = (report, sources) => {
};

const doReport = (data, issues) => {

const eslintIssues = issues
.map(report => convertMythXReport2EsIssue(report, data.sources))
.reduce((acc, curr) => acc.concat(curr), []);
Expand Down
67 changes: 36 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
"author": "Bernhard Mueller",
"license": "MIT",
"dependencies": {
"armlet": "^2.0.1",
"armlet": "^2.1.0",
"openzeppelin-solidity": "^2.1.3",
"remix-lib": "^0.4.1",
"solc": "^0.5.4"
"solc": "^0.5.5"
},
"bin": {
"sabre": "./sabre.js"
Expand All @@ -36,6 +37,6 @@
},
"devDependencies": {
"babel-eslint": "^10.0.1",
"eslint": "^5.14.1"
"eslint": "^5.15.1"
}
}
26 changes: 21 additions & 5 deletions sabre.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,30 @@ const getMythXReport = solidityCompiler => {
process.exit(-1);
}

if (compiled.contracts.inputfile.length === 0) {
let { inputfile } = compiled.contracts;
let contract, contractName;

if (inputfile.length === 0) {
console.log('No contracts found');
process.exit(-1);
}
} else if (inputfile.length === 1) {
contractName = Object.keys(inputfile)[0];
contract = inputfile[contractName];
} else {
/* Get the contract with largest bytecode object to generate MythX analysis report */

// Show report for only the first contract.
const contractName = Object.keys(compiled.contracts.inputfile)[0];
const contract = compiled.contracts.inputfile[contractName];
let bytecodes = {};

for (let key in inputfile) {
if (inputfile.hasOwnProperty(key)) {
bytecodes[inputfile[key].evm.bytecode.object.length] = key;
}
}

const largestBytecodeKey = Object.keys(bytecodes).reverse()[0];
contractName = bytecodes[largestBytecodeKey];
contract = inputfile[contractName];
}

/* Format data for MythX API */

Expand Down