Skip to content

Commit

Permalink
fix: remove deprecated call.value() statement
Browse files Browse the repository at this point in the history
  • Loading branch information
dbale-altoros committed Feb 7, 2023
1 parent 254b120 commit bc437e3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/rules/security/avoid-low-level-calls.md
Expand Up @@ -34,7 +34,6 @@ This rule accepts a string option of rule severity. Must be one of "error", "war

```solidity
anyAddress.call{value: 1 ether}("");
anyAddress.call.value(code)();
```

### 👎 Examples of **incorrect** code for this rule
Expand All @@ -45,6 +44,7 @@ anyAddress.call.value(code)();
anyAddress.call(code);
a.callcode(test1);
a.delegatecall(test1);
anyAddress.call.value(code)();
```

## Version
Expand Down
1 change: 0 additions & 1 deletion lib/common/tree-traversing.js
Expand Up @@ -77,7 +77,6 @@ TreeTraversing.typeOf = function typeOf(ctx) {

TreeTraversing.hasMethodCalls = function hasMethodCalls(node, methodNames) {
const text = node.memberName

return methodNames.includes(text)
}

Expand Down
7 changes: 6 additions & 1 deletion lib/rules/security/avoid-low-level-calls.js
Expand Up @@ -45,7 +45,12 @@ class AvoidLowLevelCallsChecker extends BaseChecker {
FunctionCall(node) {
switch (node.expression.type) {
case 'MemberAccess':
if (hasMethodCalls(node.expression, ['call', 'callcode', 'delegatecall'])) {
if (
// can add 'value' in the array of hasMethodCalls() and remove the || condition but seems out of place
hasMethodCalls(node.expression, ['call', 'callcode', 'delegatecall']) ||
(node.expression.expression.memberName === 'call' && // this is for anyAddress.call.value(code)()
node.expression.memberName === 'value')
) {
return this._warn(node)
}
case 'NameValueExpression':
Expand Down
4 changes: 1 addition & 3 deletions test/fixtures/security/low-level-calls.js
Expand Up @@ -2,10 +2,8 @@ const WARN_LOW_LEVEL_CODES = [
'anyAddress.call(code);',
'a.callcode(test1);',
'a.delegatecall(test1);',
]
const ALLOWED_LOW_LEVEL_CODES = [
'anyAddress.call{value: 1 ether}("");',
'anyAddress.call.value(code)();',
]
const ALLOWED_LOW_LEVEL_CODES = ['anyAddress.call{value: 1 ether}("");']

module.exports = [WARN_LOW_LEVEL_CODES, ALLOWED_LOW_LEVEL_CODES]
2 changes: 1 addition & 1 deletion test/rules/security/avoid-low-level-calls.js
Expand Up @@ -19,7 +19,7 @@ describe('Linter - avoid-low-level-calls', () => {
)

ALLOWED_LOW_LEVEL_CALLS.forEach((curCode) =>
it('should not return warn when code contains low level calls', () => {
it('should not return warn when code contains allowed low level calls', () => {
const report = linter.processStr(curCode, {
rules: { 'avoid-low-level-calls': 'warn' },
})
Expand Down

0 comments on commit bc437e3

Please sign in to comment.