everything in ts including tests & types defined

pull/7/head
aniket-engg 5 years ago committed by Aniket
parent 09308b50a9
commit c1c7105507
  1. 6
      remix-analyzer/index.ts
  2. 2
      remix-analyzer/package.json
  3. 58
      remix-analyzer/test/analysis/staticAnalysisCommon-test.ts
  4. 29
      remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.4.24.ts
  5. 29
      remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.5.0.ts
  6. 27
      remix-analyzer/test/analysis/staticAnalysisIssues-test-0.4.24.ts
  7. 27
      remix-analyzer/test/analysis/staticAnalysisIssues-test-0.5.0.ts
  8. 7
      remix-analyzer/test/tests.js
  9. 7
      remix-analyzer/test/tests.ts

@ -1,5 +1 @@
const CodeAnalysis = require('./src/solidity-analyzer')
module.exports = {
CodeAnalysis: CodeAnalysis
}
export { default as CodeAnalysis} from './src/solidity-analyzer'

@ -25,7 +25,7 @@
"scripts": {
"build": "tsc",
"lint": "standard",
"test": "tsc && npm run lint && tape ./test/tests.js"
"test": "tsc && npm run lint && ts-node node_modules/tape/bin/tape ./test/tests.ts"
},
"standard": {
"ignore": [

@ -1,6 +1,6 @@
var test = require('tape')
var common = require('../../dist/src/solidity-analyzer/modules/staticAnalysisCommon')
var { localCall, thisLocalCall, libCall, externalDirect, superLocal, assignment,
import { default as test} from "tape"
import * as common from '../../dist/src/solidity-analyzer/modules/staticAnalysisCommon'
const { localCall, thisLocalCall, libCall, externalDirect, superLocal, assignment,
inlineAssembly, forLoopNode, whileLoopNode, doWhileLoopNode, stateVariableContractNode,
functionDefinition, fullyQualifiedFunctionDefinition, selfdestruct, storageVariableNodes,
lowlevelCall, parameterFunction, parameterFunctionCall, inheritance, blockHashAccess } = require('./astBlocks')
@ -164,77 +164,77 @@ test('staticAnalysisCommon.getFunctionCallType', function (t) {
t.equal(common.getFunctionCallType(thisLocalCall), 'function (bytes32,address) returns (bool)', 'this local call returns correct type')
t.equal(common.getFunctionCallType(externalDirect), 'function () payable external returns (uint256)', 'external direct call returns correct type')
t.equal(common.getFunctionCallType(localCall), 'function (struct Ballot.Voter storage pointer)', 'local call returns correct type')
t.throws(() => common.getFunctionCallType({ name: 'MemberAccess' }), undefined, 'throws on wrong type')
t.throws(() => common.getFunctionCallType({ name: 'MemberAccess' }), Error, 'throws on wrong type')
})
test('staticAnalysisCommon.getEffectedVariableName', function (t) {
t.plan(3)
t.throws(() => common.getEffectedVariableName(inlineAssembly), 'staticAnalysisCommon.js: not an effect Node or inline assembly', 'get from inline assembly should throw')
t.throws(() => common.getEffectedVariableName(inlineAssembly), Error, 'staticAnalysisCommon.js: not an effect Node or inline assembly, get from inline assembly should throw')
t.ok(common.getEffectedVariableName(assignment) === 'c', 'get right name for assignment')
t.throws(() => common.getEffectedVariableName({ name: 'MemberAccess' }), undefined, 'should throw on all other nodes')
t.throws(() => common.getEffectedVariableName({ name: 'MemberAccess' }), Error, 'should throw on all other nodes')
})
test('staticAnalysisCommon.getLocalCallName', function (t) {
t.plan(3)
t.ok(common.getLocalCallName(localCall) === 'bli', 'getLocal call name from node')
t.throws(() => common.getLocalCallName(externalDirect), undefined, 'throws on other nodes')
t.throws(() => common.getLocalCallName(thisLocalCall), undefined, 'throws on other nodes')
t.throws(() => common.getLocalCallName(externalDirect), Error, 'throws on other nodes')
t.throws(() => common.getLocalCallName(thisLocalCall), Error, 'throws on other nodes')
})
test('staticAnalysisCommon.getThisLocalCallName', function (t) {
t.plan(3)
t.ok(common.getThisLocalCallName(thisLocalCall) === 'b', 'get this Local call name from node')
t.throws(() => common.getThisLocalCallName(externalDirect), undefined, 'throws on other nodes')
t.throws(() => common.getThisLocalCallName(localCall), undefined, 'throws on other nodes')
t.throws(() => common.getThisLocalCallName(externalDirect), Error, 'throws on other nodes')
t.throws(() => common.getThisLocalCallName(localCall), Error, 'throws on other nodes')
})
test('staticAnalysisCommon.getSuperLocalCallName', function (t) {
t.plan(4)
t.equal(common.getSuperLocalCallName(superLocal), 'duper', 'get local name from super local call')
t.throws(() => common.getSuperLocalCallName(thisLocalCall), 'throws on other nodes')
t.throws(() => common.getSuperLocalCallName(externalDirect), undefined, 'throws on other nodes')
t.throws(() => common.getSuperLocalCallName(localCall), undefined, 'throws on other nodes')
t.throws(() => common.getSuperLocalCallName(externalDirect), 'throws on other nodes')
t.throws(() => common.getSuperLocalCallName(localCall), 'throws on other nodes')
})
test('staticAnalysisCommon.getExternalDirectCallContractName', function (t) {
t.plan(3)
t.ok(common.getExternalDirectCallContractName(externalDirect) === 'InfoFeed', 'external direct call contract name from node')
t.throws(() => common.getExternalDirectCallContractName(thisLocalCall), undefined, 'throws on other nodes')
t.throws(() => common.getExternalDirectCallContractName(localCall), undefined, 'throws on other nodes')
t.throws(() => common.getExternalDirectCallContractName(thisLocalCall), Error, 'throws on other nodes')
t.throws(() => common.getExternalDirectCallContractName(localCall), Error, 'throws on other nodes')
})
test('staticAnalysisCommon.getThisLocalCallContractName', function (t) {
t.plan(3)
t.ok(common.getThisLocalCallContractName(thisLocalCall) === 'test', 'this local call contract name from node')
t.throws(() => common.getThisLocalCallContractName(localCall), undefined, 'throws on other nodes')
t.throws(() => common.getThisLocalCallContractName(externalDirect), undefined, 'throws on other nodes')
t.throws(() => common.getThisLocalCallContractName(localCall), Error, 'throws on other nodes')
t.throws(() => common.getThisLocalCallContractName(externalDirect), Error, 'throws on other nodes')
})
test('staticAnalysisCommon.getExternalDirectCallMemberName', function (t) {
t.plan(3)
t.ok(common.getExternalDirectCallMemberName(externalDirect) === 'info', 'external direct call name from node')
t.throws(() => common.getExternalDirectCallMemberName(thisLocalCall), undefined, 'throws on other nodes')
t.throws(() => common.getExternalDirectCallMemberName(localCall), undefined, 'throws on other nodes')
t.throws(() => common.getExternalDirectCallMemberName(thisLocalCall), Error, 'throws on other nodes')
t.throws(() => common.getExternalDirectCallMemberName(localCall), Error, 'throws on other nodes')
})
test('staticAnalysisCommon.getContractName', function (t) {
t.plan(2)
var contract = { name: 'ContractDefinition', attributes: { name: 'baz' } }
t.ok(common.getContractName(contract) === 'baz', 'returns right contract name')
t.throws(() => common.getContractName({ name: 'InheritanceSpecifier' }), undefined, 'throws on other nodes')
t.throws(() => common.getContractName({ name: 'InheritanceSpecifier' }), Error, 'throws on other nodes')
})
test('staticAnalysisCommon.getFunctionDefinitionName', function (t) {
t.plan(2)
var func = { name: 'FunctionDefinition', attributes: { name: 'foo' } }
t.ok(common.getFunctionDefinitionName(func) === 'foo', 'returns right contract name')
t.throws(() => common.getFunctionDefinitionName({ name: 'InlineAssembly' }), undefined, 'throws on other nodes')
t.throws(() => common.getFunctionDefinitionName({ name: 'InlineAssembly' }), Error, 'throws on other nodes')
})
test('staticAnalysisCommon.getInheritsFromName', function (t) {
t.plan(2)
t.ok(common.getInheritsFromName(inheritance) === 'r', 'returns right contract name')
t.throws(() => common.getInheritsFromName({ name: 'ElementaryTypeName' }), undefined, 'throws on other nodes')
t.throws(() => common.getInheritsFromName({ name: 'ElementaryTypeName' }), Error, 'throws on other nodes')
})
test('staticAnalysisCommon.getDeclaredVariableName', function (t) {
@ -242,7 +242,7 @@ test('staticAnalysisCommon.getDeclaredVariableName', function (t) {
t.ok(common.getDeclaredVariableName(storageVariableNodes.node1) === 'x', 'extract right variable name')
let node1 = JSON.parse(JSON.stringify(storageVariableNodes))
node1.node1.name = 'FunctionCall'
t.throws(() => common.getDeclaredVariableName(node1) === 'x', undefined, 'throw if wrong node')
t.throws(() => common.getDeclaredVariableName(node1) === 'x', Error, 'throw if wrong node')
})
test('staticAnalysisCommon.getStateVariableDeclarationsFormContractNode', function (t) {
@ -257,7 +257,7 @@ test('staticAnalysisCommon.getStateVariableDeclarationsFormContractNode', functi
test('staticAnalysisCommon.getFunctionOrModifierDefinitionParameterPart', function (t) {
t.plan(2)
t.ok(common.helpers.nodeType(common.getFunctionOrModifierDefinitionParameterPart(functionDefinition), 'ParameterList'), 'should return a parameterList')
t.throws(() => common.getFunctionOrModifierDefinitionParameterPart({ name: 'SourceUnit' }), undefined, 'throws on other nodes')
t.throws(() => common.getFunctionOrModifierDefinitionParameterPart({ name: 'SourceUnit' }), Error, 'throws on other nodes')
})
test('staticAnalysisCommon.getFunctionCallTypeParameterType', function (t) {
@ -265,19 +265,19 @@ test('staticAnalysisCommon.getFunctionCallTypeParameterType', function (t) {
t.ok(common.getFunctionCallTypeParameterType(thisLocalCall) === 'bytes32,address', 'this local call returns correct type')
t.ok(common.getFunctionCallTypeParameterType(externalDirect) === '', 'external direct call returns correct type')
t.ok(common.getFunctionCallTypeParameterType(localCall) === 'struct Ballot.Voter storage pointer', 'local call returns correct type')
t.throws(() => common.getFunctionCallTypeParameterType({ name: 'MemberAccess' }), undefined, 'throws on wrong type')
t.throws(() => common.getFunctionCallTypeParameterType({ name: 'MemberAccess' }), Error, 'throws on wrong type')
})
test('staticAnalysisCommon.getLibraryCallContractName', function (t) {
t.plan(2)
t.equal(common.getLibraryCallContractName(libCall), 'Set', 'should return correct contract name')
t.throws(() => common.getLibraryCallContractName({ name: 'Identifier' }), undefined, 'should throw on wrong node')
t.throws(() => common.getLibraryCallContractName({ name: 'Identifier' }), Error, 'should throw on wrong node')
})
test('staticAnalysisCommon.getLibraryCallMemberName', function (t) {
t.plan(2)
t.equal(common.getLibraryCallMemberName(libCall), 'insert', 'should return correct member name')
t.throws(() => common.getLibraryCallMemberName({ name: 'Identifier' }), undefined, 'should throw on wrong node')
t.throws(() => common.getLibraryCallMemberName({ name: 'Identifier' }), Error, 'should throw on wrong node')
})
test('staticAnalysisCommon.getFullQualifiedFunctionCallIdent', function (t) {
@ -286,15 +286,15 @@ test('staticAnalysisCommon.getFullQualifiedFunctionCallIdent', function (t) {
t.ok(common.getFullQualifiedFunctionCallIdent(contract, thisLocalCall) === 'test.b(bytes32,address)', 'this local call returns correct type')
t.ok(common.getFullQualifiedFunctionCallIdent(contract, externalDirect) === 'InfoFeed.info()', 'external direct call returns correct type')
t.ok(common.getFullQualifiedFunctionCallIdent(contract, localCall) === 'baz.bli(struct Ballot.Voter storage pointer)', 'local call returns correct type')
t.throws(() => common.getFullQualifiedFunctionCallIdent(contract, { name: 'MemberAccess' }), undefined, 'throws on wrong type')
t.throws(() => common.getFullQualifiedFunctionCallIdent(contract, { name: 'MemberAccess' }), Error, 'throws on wrong type')
})
test('staticAnalysisCommon.getFullQuallyfiedFuncDefinitionIdent', function (t) {
t.plan(3)
var contract = { name: 'ContractDefinition', attributes: { name: 'baz' } }
t.ok(common.getFullQuallyfiedFuncDefinitionIdent(contract, fullyQualifiedFunctionDefinition, ['uint256', 'bool']) === 'baz.getY(uint256,bool)', 'creates right signature')
t.throws(() => common.getFullQuallyfiedFuncDefinitionIdent(contract, { name: 'MemberAccess' }, ['uint256', 'bool']), undefined, 'throws on wrong nodes')
t.throws(() => common.getFullQuallyfiedFuncDefinitionIdent({ name: 'FunctionCall' }, fullyQualifiedFunctionDefinition, ['uint256', 'bool']), undefined, 'throws on wrong nodes')
t.throws(() => common.getFullQuallyfiedFuncDefinitionIdent(contract, { name: 'MemberAccess' }, ['uint256', 'bool']), Error, 'throws on wrong nodes')
t.throws(() => common.getFullQuallyfiedFuncDefinitionIdent({ name: 'FunctionCall' }, fullyQualifiedFunctionDefinition, ['uint256', 'bool']), Error, 'throws on wrong nodes')
})
test('staticAnalysisCommon.getLoopBlockStartIndex', function (t) {

@ -1,18 +1,15 @@
var test = require('tape')
var remixLib = require('remix-lib')
var StatRunner = require('../../dist/src/solidity-analyzer').default
var compilerInput = remixLib.helpers.compiler.compilerInput
const niv = require('npm-install-version')
niv.install('solc@0.4.24')
var compiler = niv.require('solc@0.4.24')
var fs = require('fs')
var path = require('path')
var folder = 'solidity-v0.4.24'
var testFiles = [
import { default as test} from "tape"
import { helpers } from 'remix-lib'
import { readFileSync } from 'fs'
import { join } from 'path'
import { default as StatRunner } from '../../dist/src/solidity-analyzer'
import { install, require as requireNPMmodule } from 'npm-install-version'
install('solc@0.4.24')
const compiler = requireNPMmodule('solc@0.4.24')
const {compilerInput } = helpers.compiler
const folder = 'solidity-v0.4.24'
const testFiles = [
'KingOfTheEtherThrone.sol',
'assembly.sol',
'ballot.sol',
@ -44,7 +41,7 @@ var testFiles = [
var testFileAsts = {}
testFiles.forEach((fileName) => {
var content = fs.readFileSync(path.join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
var content = readFileSync(join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
testFileAsts[fileName] = JSON.parse(compiler.compileStandardWrapper(compilerInput(content)))
})

@ -1,18 +1,15 @@
var test = require('tape')
var remixLib = require('remix-lib')
var StatRunner = require('../../dist/src/solidity-analyzer').default
var compilerInput = remixLib.helpers.compiler.compilerInput
const niv = require('npm-install-version')
niv.install('solc@0.5.0')
var compiler = niv.require('solc@0.5.0')
var fs = require('fs')
var path = require('path')
var folder = 'solidity-v0.5'
var testFiles = [
import { default as test} from "tape"
import { helpers } from 'remix-lib'
import { readFileSync } from 'fs'
import { join } from 'path'
import { default as StatRunner } from '../../dist/src/solidity-analyzer'
import { install, require as requireNPMmodule } from 'npm-install-version'
install('solc@0.5.0')
const compiler = requireNPMmodule('solc@0.5.0')
const {compilerInput } = helpers.compiler
const folder = 'solidity-v0.5'
const testFiles = [
'KingOfTheEtherThrone.sol',
'assembly.sol',
'ballot.sol',
@ -44,7 +41,7 @@ var testFiles = [
var testFileAsts = {}
testFiles.forEach((fileName) => {
var content = fs.readFileSync(path.join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
var content = readFileSync(join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
testFileAsts[fileName] = JSON.parse(compiler.compile(compilerInput(content)))
})

@ -1,19 +1,16 @@
var test = require('tape')
var remixLib = require('remix-lib')
var StatRunner = require('../../dist/src/solidity-analyzer').default
var compilerInput = remixLib.helpers.compiler.compilerInput
const niv = require('npm-install-version')
niv.install('solc@0.4.24')
var compiler = niv.require('solc@0.4.24')
var fs = require('fs')
var path = require('path')
var folder = 'solidity-v0.4.24'
import { default as test} from "tape"
import { helpers } from 'remix-lib'
import { readFileSync } from 'fs'
import { join } from 'path'
import { default as StatRunner } from '../../dist/src/solidity-analyzer'
import { install, require as requireNPMmodule } from 'npm-install-version'
install('solc@0.4.24')
const compiler = requireNPMmodule('solc@0.4.24')
const {compilerInput } = helpers.compiler
const folder = 'solidity-v0.4.24'
function compile (fileName) {
var content = fs.readFileSync(path.join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
var content = readFileSync(join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
return JSON.parse(compiler.compileStandardWrapper(compilerInput(content)))
}
@ -29,7 +26,7 @@ test('staticAnalysisIssues.functionParameterPassingError', function (t) {
t.doesNotThrow(() => {
statRunner.runWithModuleList(res, [{ name: new Module().name, mod: new Module() }], (reports) => {
})
}, true, 'Analysis should not throw')
}, 'Analysis should not throw')
statRunner.runWithModuleList(res, [{ name: new Module().name, mod: new Module() }], (reports) => {
t.ok(!reports.some((mod) => mod.report.some((rep) => rep.warning.includes('INTERNAL ERROR')), 'Should not have internal errors'))

@ -1,19 +1,16 @@
var test = require('tape')
var remixLib = require('remix-lib')
var StatRunner = require('../../dist/src/solidity-analyzer').default
var compilerInput = remixLib.helpers.compiler.compilerInput
const niv = require('npm-install-version')
niv.install('solc@0.5.0')
var compiler = niv.require('solc@0.5.0')
var fs = require('fs')
var path = require('path')
var folder = 'solidity-v0.5'
import { default as test} from "tape"
import { helpers } from 'remix-lib'
import { readFileSync } from 'fs'
import { join } from 'path'
import { default as StatRunner } from '../../dist/src/solidity-analyzer'
import { install, require as requireNPMmodule } from 'npm-install-version'
install('solc@0.5.0')
const compiler = requireNPMmodule('solc@0.5.0')
const {compilerInput } = helpers.compiler
const folder = 'solidity-v0.5'
function compile (fileName) {
var content = fs.readFileSync(path.join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
var content = readFileSync(join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
return JSON.parse(compiler.compile(compilerInput(content)))
}
@ -29,7 +26,7 @@ test('staticAnalysisIssues.functionParameterPassingError', function (t) {
t.doesNotThrow(() => {
statRunner.runWithModuleList(res, [{ name: new Module().name, mod: new Module() }], (reports) => {
})
}, true, 'Analysis should not throw')
}, 'Analysis should not throw')
statRunner.runWithModuleList(res, [{ name: new Module().name, mod: new Module() }], (reports) => {
t.ok(!reports.some((mod) => mod.report.some((rep) => rep.warning.includes('INTERNAL ERROR')), 'Should not have internal errors'))

@ -1,7 +0,0 @@
require('./analysis/staticAnalysisCommon-test.js')
require('./analysis/staticAnalysisIntegration-test-0.4.24.js')
require('./analysis/staticAnalysisIssues-test-0.4.24.js')
require('./analysis/staticAnalysisIntegration-test-0.5.0.js')
require('./analysis/staticAnalysisIssues-test-0.5.0.js')

@ -0,0 +1,7 @@
require('./analysis/staticAnalysisCommon-test')
require('./analysis/staticAnalysisIntegration-test-0.4.24')
require('./analysis/staticAnalysisIssues-test-0.4.24')
require('./analysis/staticAnalysisIntegration-test-0.5.0')
require('./analysis/staticAnalysisIssues-test-0.5.0')
Loading…
Cancel
Save