Skip to content

Commit

Permalink
Use exact match when checking for deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio committed May 22, 2018
1 parent 990d86c commit 138ab0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/rules/security/avoid-deprecations.js
Expand Up @@ -8,13 +8,13 @@ class AvoidDeprecationsChecker extends BaseChecker {
}

exitIdentifier(ctx) {
const text = ctx.getText();
const identifier = ctx.Identifier().toString();

if (text.includes('sha3')) {
if (identifier === 'sha3') {
this.error(ctx, 'avoid-sha3', 'Use "keccak256" instead of deprecated "sha3"');
}

if (text.includes('suicide')) {
if (identifier === 'suicide') {
this.error(ctx, 'avoid-suicide', 'Use "selfdestruct" instead of deprecated "suicide"');
}
}
Expand All @@ -26,4 +26,4 @@ class AvoidDeprecationsChecker extends BaseChecker {
}


module.exports = AvoidDeprecationsChecker;
module.exports = AvoidDeprecationsChecker;
11 changes: 11 additions & 0 deletions test/security-rules.js
Expand Up @@ -116,6 +116,17 @@ describe('Linter - SecurityRules', function () {
assert.ok(report.reports[0].message.includes('deprecate'));
}));

const ALMOST_DEPRECATION_ERRORS = ['sha33("test");', 'throwing;', 'suicides();'];

ALMOST_DEPRECATION_ERRORS.forEach(curText =>
it(`should not return error when doing ${curText}`, function () {
const code = funcWith(curText);

const report = linter.processStr(code, noIndent());

assert.equal(report.errorCount, 0);
}));

it('should return error that multiple send calls used in transation', function () {
const code = funcWith(`
uint aRes = a.send(1);
Expand Down

0 comments on commit 138ab0b

Please sign in to comment.