Skip to content
This repository was archived by the owner on Mar 3, 2021. It is now read-only.

Commit 3af34b2

Browse files
committed
remove remix-lib dep from remix-analyzer
1 parent cae4c1d commit 3af34b2

35 files changed

+25802
-28384
lines changed

Diff for: package-lock.json

+107-684
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"diff": "lerna diff",
99
"updated": "lerna updated",
10-
"bootstrap": "npm run build-ts-packages; lerna bootstrap",
10+
"bootstrap": "lerna bootstrap; npm run build-ts-packages",
1111
"build-ts-packages": "lerna run --scope 'remix-analyzer' --scope 'remix-astwalker' --scope 'remix-solidity' --scope 'remix-tests' --scope 'remix-url-resolver' build",
1212
"publish": "npm run build-ts-packages; lerna publish",
1313
"release": "lerna bootstrap; lerna publish;",

Diff for: remix-analyzer/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
}
2020
],
2121
"dependencies": {
22-
"remix-astwalker": "0.0.24",
23-
"remix-lib": "0.4.29"
22+
"remix-astwalker": "0.0.24"
2423
},
2524
"scripts": {
2625
"build": "tsc",

Diff for: remix-analyzer/src/solidity-analyzer/modules/similarVariableNames.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getDeclaredVariableName, getFullQuallyfiedFuncDefinitionIdent } from '.
33
import { default as algorithm } from './algorithmCategories'
44
import AbstractAst from './abstractAstView'
55
import { get } from 'fast-levenshtein'
6-
import { util } from 'remix-lib'
6+
import { escapeRegExp } from '../../util/helpers'
77
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, ContractHLAst, FunctionHLAst, VariableDeclarationAstNode, VisitFunction, ReportFunction} from './../../types'
88

99
interface SimilarRecord {
@@ -73,7 +73,7 @@ export default class similarVariableNames implements AnalyzerModule {
7373
}
7474

7575
private isCommonNrSuffixVersion (varName1: string, varName2: string): boolean {
76-
const ref: string = '^' + util.escapeRegExp(varName1.slice(0, -1)) + '[0-9]*$'
76+
const ref: string = '^' + escapeRegExp(varName1.slice(0, -1)) + '[0-9]*$'
7777
return varName2.match(ref) != null
7878
}
7979

Diff for: remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.ts

+17-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FunctionDefinitionAstNode, ModifierDefinitionAstNode, ParameterListAstN
44
WhileStatementAstNode, VariableDeclarationAstNode, ContractDefinitionAstNode, InheritanceSpecifierAstNode,
55
MemberAccessAstNode, BinaryOperationAstNode, FunctionCallAstNode, ExpressionStatementAstNode, UnaryOperationAstNode,
66
IdentifierAstNode, IndexAccessAstNode, BlockAstNode, AssignmentAstNode, InlineAssemblyAstNode, IfStatementAstNode } from "types"
7-
import { util } from 'remix-lib'
7+
import { concatWithSeperator, escapeRegExp } from '../../util/helpers'
88

99
type SpecialObjDetail = {
1010
obj: string
@@ -439,7 +439,7 @@ function getFullQualifiedFunctionCallIdent (contract: ContractDefinitionAstNode,
439439
}
440440

441441
function getFullQuallyfiedFuncDefinitionIdent (contract: ContractDefinitionAstNode, func: FunctionDefinitionAstNode, paramTypes: any[]): string {
442-
return getContractName(contract) + '.' + getFunctionDefinitionName(func) + '(' + util.concatWithSeperator(paramTypes, ',') + ')'
442+
return getContractName(contract) + '.' + getFunctionDefinitionName(func) + '(' + concatWithSeperator(paramTypes, ',') + ')'
443443
}
444444

445445
function getUnAssignedTopLevelBinOps (subScope: BlockAstNode | IfStatementAstNode | WhileStatementAstNode | ForStatementAstNode): ExpressionStatementAstNode[] {
@@ -665,7 +665,7 @@ function isConstructor (node: FunctionDefinitionAstNode): boolean {
665665
* @return {bool}
666666
*/
667667
function isIntDivision (node: BinaryOperationAstNode): boolean {
668-
return operator(node, exactMatch(util.escapeRegExp('/'))) && typeDescription(node.rightExpression, util.escapeRegExp('int'))
668+
return operator(node, exactMatch(escapeRegExp('/'))) && typeDescription(node.rightExpression, escapeRegExp('int'))
669669
}
670670

671671
/**
@@ -863,7 +863,7 @@ function isLowLevelCall (node: MemberAccessAstNode): boolean {
863863
*/
864864
function isLLSend04 (node: MemberAccessAstNode): boolean {
865865
return isMemberAccess(node,
866-
exactMatch(util.escapeRegExp(lowLevelCallTypes.SEND.type)),
866+
exactMatch(escapeRegExp(lowLevelCallTypes.SEND.type)),
867867
undefined, exactMatch(basicTypes.ADDRESS), exactMatch(lowLevelCallTypes.SEND.ident))
868868
}
869869

@@ -874,7 +874,7 @@ function isLLSend04 (node: MemberAccessAstNode): boolean {
874874
*/
875875
function isLLSend (node: MemberAccessAstNode): boolean {
876876
return isMemberAccess(node,
877-
exactMatch(util.escapeRegExp(lowLevelCallTypes.SEND.type)),
877+
exactMatch(escapeRegExp(lowLevelCallTypes.SEND.type)),
878878
undefined, exactMatch(basicTypes.PAYABLE_ADDRESS), exactMatch(lowLevelCallTypes.SEND.ident))
879879
}
880880

@@ -885,10 +885,10 @@ function isLLSend (node: MemberAccessAstNode): boolean {
885885
*/
886886
function isLLCall (node: MemberAccessAstNode): boolean {
887887
return isMemberAccess(node,
888-
exactMatch(util.escapeRegExp(lowLevelCallTypes.CALL.type)),
888+
exactMatch(escapeRegExp(lowLevelCallTypes.CALL.type)),
889889
undefined, exactMatch(basicTypes.ADDRESS), exactMatch(lowLevelCallTypes.CALL.ident)) ||
890890
isMemberAccess(node,
891-
exactMatch(util.escapeRegExp(lowLevelCallTypes.CALL.type)),
891+
exactMatch(escapeRegExp(lowLevelCallTypes.CALL.type)),
892892
undefined, exactMatch(basicTypes.PAYABLE_ADDRESS), exactMatch(lowLevelCallTypes.CALL.ident))
893893
}
894894

@@ -899,7 +899,7 @@ function isLLCall (node: MemberAccessAstNode): boolean {
899899
*/
900900
function isLLCall04 (node: MemberAccessAstNode): boolean {
901901
return isMemberAccess(node,
902-
exactMatch(util.escapeRegExp(lowLevelCallTypes['CALL-0.4'].type)),
902+
exactMatch(escapeRegExp(lowLevelCallTypes['CALL-0.4'].type)),
903903
undefined, exactMatch(basicTypes.ADDRESS), exactMatch(lowLevelCallTypes['CALL-0.4'].ident))
904904
}
905905

@@ -910,7 +910,7 @@ function isLLCall04 (node: MemberAccessAstNode): boolean {
910910
*/
911911
function isLLCallcode (node: MemberAccessAstNode): boolean {
912912
return isMemberAccess(node,
913-
exactMatch(util.escapeRegExp(lowLevelCallTypes.CALLCODE.type)),
913+
exactMatch(escapeRegExp(lowLevelCallTypes.CALLCODE.type)),
914914
undefined, exactMatch(basicTypes.ADDRESS), exactMatch(lowLevelCallTypes.CALLCODE.ident))
915915
}
916916

@@ -921,7 +921,7 @@ function isLLCallcode (node: MemberAccessAstNode): boolean {
921921
*/
922922
function isLLDelegatecall (node: MemberAccessAstNode): boolean {
923923
return isMemberAccess(node,
924-
exactMatch(util.escapeRegExp(lowLevelCallTypes.DELEGATECALL.type)),
924+
exactMatch(escapeRegExp(lowLevelCallTypes.DELEGATECALL.type)),
925925
undefined, matches(basicTypes.PAYABLE_ADDRESS, basicTypes.ADDRESS), exactMatch(lowLevelCallTypes.DELEGATECALL.ident))
926926
}
927927

@@ -932,7 +932,7 @@ function isLLDelegatecall (node: MemberAccessAstNode): boolean {
932932
*/
933933
function isLLDelegatecall04 (node: MemberAccessAstNode): boolean {
934934
return isMemberAccess(node,
935-
exactMatch(util.escapeRegExp(lowLevelCallTypes['DELEGATECALL-0.4'].type)),
935+
exactMatch(escapeRegExp(lowLevelCallTypes['DELEGATECALL-0.4'].type)),
936936
undefined, matches(basicTypes.PAYABLE_ADDRESS, basicTypes.ADDRESS), exactMatch(lowLevelCallTypes['DELEGATECALL-0.4'].ident))
937937
}
938938

@@ -943,12 +943,12 @@ function isLLDelegatecall04 (node: MemberAccessAstNode): boolean {
943943
*/
944944
function isTransfer (node: MemberAccessAstNode): boolean {
945945
return isMemberAccess(node,
946-
exactMatch(util.escapeRegExp(lowLevelCallTypes.TRANSFER.type)),
946+
exactMatch(escapeRegExp(lowLevelCallTypes.TRANSFER.type)),
947947
undefined, matches(basicTypes.ADDRESS, basicTypes.PAYABLE_ADDRESS), exactMatch(lowLevelCallTypes.TRANSFER.ident))
948948
}
949949

950950
function isStringToBytesConversion (node: FunctionCallAstNode): boolean {
951-
return isExplicitCast(node, util.escapeRegExp('string *'), util.escapeRegExp('bytes'))
951+
return isExplicitCast(node, escapeRegExp('string *'), escapeRegExp('bytes'))
952952
}
953953

954954
function isExplicitCast (node: FunctionCallAstNode, castFromType: string, castToType: string): boolean {
@@ -958,7 +958,7 @@ function isExplicitCast (node: FunctionCallAstNode, castFromType: string, castTo
958958
}
959959

960960
function isBytesLengthCheck (node: MemberAccessAstNode): boolean {
961-
return isMemberAccess(node, exactMatch(util.escapeRegExp(basicTypes.UINT)), undefined, util.escapeRegExp('bytes *'), 'length')
961+
return isMemberAccess(node, exactMatch(escapeRegExp(basicTypes.UINT)), undefined, escapeRegExp('bytes *'), 'length')
962962
}
963963

964964
/**
@@ -985,7 +985,7 @@ function isMemberAccess (node: MemberAccessAstNode, retType: string, accessor: s
985985
}
986986

987987
function isSpecialVariableAccess (node: MemberAccessAstNode, varType: SpecialObjDetail): boolean {
988-
return isMemberAccess(node, exactMatch(util.escapeRegExp(varType.type)), varType.obj, varType.obj, varType.member)
988+
return isMemberAccess(node, exactMatch(escapeRegExp(varType.type)), varType.obj, varType.obj, varType.member)
989989
}
990990

991991
// #################### Node Identification Primitives
@@ -1061,11 +1061,11 @@ function findFirstSubNodeLTR (node: any, type: string): any {
10611061
* @return {Boolean} isPayable
10621062
*/
10631063
function buildFunctionSignature (paramTypes: any[], returnTypes: any[], isPayable: boolean, additionalMods?: any): string {
1064-
return 'function (' + util.concatWithSeperator(paramTypes, ',') + ')' + ((isPayable) ? ' payable' : '') + ((additionalMods) ? ' ' + additionalMods : '') + ((returnTypes.length) ? ' returns (' + util.concatWithSeperator(returnTypes, ',') + ')' : '')
1064+
return 'function (' + concatWithSeperator(paramTypes, ',') + ')' + ((isPayable) ? ' payable' : '') + ((additionalMods) ? ' ' + additionalMods : '') + ((returnTypes.length) ? ' returns (' + concatWithSeperator(returnTypes, ',') + ')' : '')
10651065
}
10661066

10671067
function buildAbiSignature (funName: string, paramTypes: any[]): string {
1068-
return funName + '(' + util.concatWithSeperator(paramTypes, ',') + ')'
1068+
return funName + '(' + concatWithSeperator(paramTypes, ',') + ')'
10691069
}
10701070

10711071
const helpers = {

Diff for: remix-analyzer/src/util/helpers.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict'
2+
3+
export const groupBy = (arr, key) => {
4+
return arr.reduce((sum, item) => {
5+
const groupByVal = item[key]
6+
const groupedItems = sum[groupByVal] || []
7+
groupedItems.push(item)
8+
sum[groupByVal] = groupedItems
9+
return sum
10+
}, {})
11+
}
12+
13+
export const concatWithSeperator = (list, seperator) => {
14+
return list.reduce((sum, item) => sum + item + seperator, '').slice(0, -seperator.length)
15+
}
16+
17+
export const escapeRegExp = (str) => {
18+
return str.replace(/[-[\]/{}()+?.\\^$|]/g, '\\$&')
19+
}

Diff for: remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.4.24.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { default as test} from "tape"
2-
import { compilerInput } from '../util/compilerHelper'
2+
import { compilerInput } from '../../src/util/compilerHelper'
33
import { readFileSync } from 'fs'
44
import { join } from 'path'
55
import { default as StatRunner } from '../../dist/src/solidity-analyzer'

Diff for: remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.5.0.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { default as test} from "tape"
2-
import { compilerInput } from '../util/compilerHelper'
2+
import { compilerInput } from '../../src/util/compilerHelper'
33
import { readFileSync } from 'fs'
44
import { join } from 'path'
55
import { default as StatRunner } from '../../dist/src/solidity-analyzer'

Diff for: remix-analyzer/test/analysis/staticAnalysisIssues-test-0.4.24.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { default as test} from "tape"
22
import { readFileSync } from 'fs'
3-
import { compilerInput } from '../util/compilerHelper'
3+
import { compilerInput } from '../../src/util/compilerHelper'
44
import { join } from 'path'
55
import { default as StatRunner } from '../../dist/src/solidity-analyzer'
66
import { CompilationResult, AnalysisReportObj, AnalysisReport, AnalyzerModule } from '../../src/types'

Diff for: remix-analyzer/test/analysis/staticAnalysisIssues-test-0.5.0.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { checksEffectsInteraction } from '../../src/solidity-analyzer/modules/'
77
import { install, require as requireNPMmodule } from 'npm-install-version'
88
99
const compiler = requireNPMmodule('[email protected]')
10-
import { compilerInput } from '../util/compilerHelper'
10+
import { compilerInput } from '../../src/util/compilerHelper'
1111
const folder: string = 'solidity-v0.5'
1212

1313
function compile (fileName): CompilationResult {

Diff for: remix-analyzer/test/tests.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require('./util/test')
2+
13
require('./analysis/staticAnalysisCommon-test')
24

35
require('./analysis/staticAnalysisIntegration-test-0.4.24')

Diff for: remix-analyzer/test/util/test.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict'
2+
import { default as test} from "tape"
3+
import { concatWithSeperator, escapeRegExp, groupBy } from '../../src/util/helpers'
4+
5+
test('util.concatWithSeperator valid output', function (t) {
6+
t.plan(4)
7+
t.notEqual(concatWithSeperator(['a', 'b', 'c'], ','), 'a, b, c', 'Concat with comma should not produce spaces')
8+
t.equal(concatWithSeperator(['a', 'b', 'c'], ','), 'a,b,c', 'Concat with comma should not produce spaces')
9+
t.equal(concatWithSeperator(['a', 'b', 'c'], ', '), 'a, b, c', 'Concat with comma space should not produce trailing comma')
10+
t.equal(concatWithSeperator(['a', 'b', 'c'], '+'), 'a+b+c', 'Concat with plus')
11+
})
12+
13+
test('util.escapeRegExp', function (t) {
14+
t.plan(3)
15+
const original = 'function (uint256) returns (bool)'
16+
t.equal(escapeRegExp('abcd'), 'abcd', 'String with no regex')
17+
t.equal(escapeRegExp(original), 'function \\(uint256\\) returns \\(bool\\)', 'function string with regex')
18+
t.ok(new RegExp(escapeRegExp(original)).test(original), 'should still test for original string')
19+
})
20+
21+
test('util.groupBy on valid input', function (t) {
22+
t.plan(1)
23+
24+
const result = groupBy([
25+
{category: 'GAS', name: 'a'},
26+
{category: 'SEC', name: 'b'},
27+
{category: 'GAS', name: 'c'}
28+
29+
], 'category')
30+
31+
const expectedResult = {
32+
'GAS': [
33+
{category: 'GAS', name: 'a'},
34+
{category: 'GAS', name: 'c'}
35+
],
36+
'SEC': [
37+
{category: 'SEC', name: 'b'}
38+
]
39+
}
40+
41+
t.deepEqual(result, expectedResult)
42+
})
43+

Diff for: remix-analyzer/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"include": ["src", "index.ts"],
2+
"include": ["src", "index.ts", "test/util/test.ts"],
33
"compilerOptions": {
44
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
55
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */

0 commit comments

Comments
 (0)