Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Revise for armlet 2.0.0
Browse files Browse the repository at this point in the history
Note: we will need to change remove git version  in package.json before release
  • Loading branch information
rocky committed Feb 17, 2019
1 parent 63dd690 commit c66426e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
8 changes: 3 additions & 5 deletions helpers.js
Expand Up @@ -207,6 +207,7 @@ const doAnalysis = async (client, config, jsonFiles, contractNames = null, limit
}

try {
debugger
const {issues, status} = await client.analyzeWithStatus(analyzeOpts);
if (config.debug) {
config.logger.debug(`UUID for this job is ${status.uuid}`);
Expand Down Expand Up @@ -287,11 +288,9 @@ const getNotFoundContracts = (mythXIssuesObjects, contracts) => {
return contracts.filter(c => !mythxContracts.includes(c));
}

const getArmletClient = (apiKey, ethAddress, password, clientToolName = 'truffle') => {
const getArmletClient = (ethAddress, password, clientToolName = 'truffle') => {
const options = { clientToolName };
if (apiKey) {
options.apiKey = apiKey;
} else if (password && ethAddress) {
if (password && ethAddress) {
options.ethAddress = ethAddress;
options.password = password;
} else if (!password && !ethAddress) {
Expand Down Expand Up @@ -319,7 +318,6 @@ async function analyze(config) {
}

const client = getArmletClient(
process.env.MYTHX_API_KEY,
process.env.MYTHX_ETH_ADDRESS,
process.env.MYTHX_PASSWORD
)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.1",
"description": "MythX security analysis plugin for Truffle Framework",
"dependencies": {
"armlet": "^1.2.0",
"armlet": "git+ssh://git@github.com:consensys/armlet.git",
"configstore": "^4.0.0",
"js-yaml": "^3.12.1",
"mocha": "^5.2.0",
Expand Down
20 changes: 9 additions & 11 deletions test/test_helpers.js
Expand Up @@ -69,7 +69,7 @@ describe('helpers.js', function() {
for (const t of expected) {
compareTest(t[0], t[1], t[2], t[3], t[4]);
}
});
});

it('should sort and convert object to a string', () => {
const res = helpers.versionJSON2String({ mythx: '1.0.1', 'solc': '0.5.0', 'api': '1.0.0' });
Expand All @@ -88,7 +88,7 @@ describe('helpers.js', function() {
let doAnalysisStub;
let ghettoReportStub;
let getIssues;


beforeEach(() => {
getTruffleBuildJsonFilesStub = sinon.stub(trufstuf, 'getTruffleBuildJsonFiles');
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('helpers.js', function() {
getTruffleBuildJsonFilesStub.restore();
getIssues.restore();
});

it('should return error when passed value for limit is not a number', async () => {
config.limit = 'test';
await rewiredHelpers.analyze(config);
Expand Down Expand Up @@ -289,7 +289,10 @@ describe('helpers.js', function() {
let armletClient, stubAnalyze, debuggerStub;

beforeEach(() => {
armletClient = new armlet.Client({ apiKey: 'test' });
armletClient = new armlet.Client({
ethAddress: rewiredHelpers.trialEthAddress,
password: rewiredHelpers.trialPassword
});
stubAnalyze = sinon.stub(armletClient, 'analyzeWithStatus');
debuggerStub = sinon.stub();
});
Expand Down Expand Up @@ -583,13 +586,8 @@ describe('helpers.js', function() {
assert.equal(client.password, rewiredHelpers.trialPassword);
});

it('should create client instance with Api Key', () => {
const client = rewiredHelpers.getArmletClient('API_KEY');
assert.equal(client.accessToken, 'API_KEY');
});

it('should create client instance with ethAddress and password', () => {
const client = rewiredHelpers.getArmletClient(undefined, '0x123456789012345678901234', 'password');
const client = rewiredHelpers.getArmletClient('0x123456789012345678901234', 'password');
assert.equal(client.ethAddress, '0x123456789012345678901234');
assert.equal(client.password, 'password');
});
Expand All @@ -602,7 +600,7 @@ describe('helpers.js', function() {

it('should throw error if ethAddress is missing', () => {
assert.throws(() => {
rewiredHelpers.getArmletClient(undefined, undefined, 'password')
rewiredHelpers.getArmletClient('password', undefined)
});
});
});
Expand Down

0 comments on commit c66426e

Please sign in to comment.