more type defs added in tests

pull/7/head
aniket-engg 5 years ago committed by Aniket
parent c3a5ef3b6a
commit aee19d3056
  1. 5
      remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.4.24.ts
  2. 260
      remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.5.0.ts
  3. 5
      remix-analyzer/test/analysis/staticAnalysisIssues-test-0.4.24.ts
  4. 3
      remix-analyzer/test/analysis/staticAnalysisIssues-test-0.5.0.ts

@ -3,13 +3,14 @@ import { helpers } from 'remix-lib'
import { readFileSync } from 'fs'
import { join } from 'path'
import { default as StatRunner } from '../../dist/src/solidity-analyzer'
import * as modules from '../../src/solidity-analyzer/modules/'
import { CompilationResult, AnalysisReportObj, AnalysisReport } from '../../src/types'
import { install, require as requireNPMmodule } from 'npm-install-version'
install('solc@0.4.24')
const solc = requireNPMmodule('solc@0.4.24')
const { compilerInput } = helpers.compiler
const folder: string = 'solidity-v0.4.24'
import * as modules from '../../src/solidity-analyzer/modules/'
import { CompilationResult, AnalysisReportObj, AnalysisReport, AnalyzerModule } from '../../src/types'
const testFiles: string[] = [
'KingOfTheEtherThrone.sol',

@ -3,13 +3,15 @@ import { helpers } from 'remix-lib'
import { readFileSync } from 'fs'
import { join } from 'path'
import { default as StatRunner } from '../../dist/src/solidity-analyzer'
import * as modules from '../../src/solidity-analyzer/modules/'
import { CompilationResult, AnalysisReportObj, AnalysisReport } from '../../src/types'
import { install, require as requireNPMmodule } from 'npm-install-version'
install('solc@0.5.0')
const compiler = requireNPMmodule('solc@0.5.0')
const solc = requireNPMmodule('solc@0.5.0')
const { compilerInput } = helpers.compiler
const folder = 'solidity-v0.5'
const folder: string = 'solidity-v0.5'
const testFiles = [
const testFiles: string[] = [
'KingOfTheEtherThrone.sol',
'assembly.sol',
'ballot.sol',
@ -38,19 +40,17 @@ const testFiles = [
'forLoopIteratesOverDynamicArray.sol'
]
var testFileAsts = {}
var compilationResults: Record<string, CompilationResult> = {}
testFiles.forEach((fileName) => {
var content = readFileSync(join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
testFileAsts[fileName] = JSON.parse(compiler.compile(compilerInput(content)))
const content = readFileSync(join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
compilationResults[fileName] = JSON.parse(solc.compile(compilerInput(content)))
})
test('Integration test thisLocal.js', function (t) {
test('Integration test thisLocal module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/thisLocal').default
const lengthCheck = {
const module: any = modules.thisLocal
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -78,18 +78,15 @@ test('Integration test thisLocal.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of this local warnings`)
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of thisLocal warnings`)
})
})
test('Integration test checksEffectsInteraction.js', function (t) {
test('Integration test checksEffectsInteraction module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/checksEffectsInteraction').default
const lengthCheck = {
const module: any = modules.checksEffectsInteraction
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 1,
'assembly.sol': 1,
'ballot.sol': 0,
@ -117,18 +114,15 @@ test('Integration test checksEffectsInteraction.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of checks-effects-interaction warnings`)
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of checksEffectsInteraction warnings`)
})
})
test('Integration test constantFunctions.js', function (t) {
test('Integration test constantFunctions module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/constantFunctions').default
const lengthCheck = {
const module: any = modules.constantFunctions
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -156,18 +150,15 @@ test('Integration test constantFunctions.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of constant warnings`)
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of constantFunctions warnings`)
})
})
test('Integration test inlineAssembly.js', function (t) {
test('Integration test inlineAssembly module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/inlineAssembly').default
const lengthCheck = {
const module: any = modules.inlineAssembly
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 2,
'ballot.sol': 0,
@ -195,18 +186,15 @@ test('Integration test inlineAssembly.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of inline assembly warnings`)
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of inlineAssembly warnings`)
})
})
test('Integration test txOrigin.js', function (t) {
test('Integration test txOrigin module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/txOrigin').default
const lengthCheck = {
const module: any = modules.txOrigin
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 1,
'ballot.sol': 0,
@ -234,18 +222,15 @@ test('Integration test txOrigin.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of tx.origin warnings`)
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of txOrigin warnings`)
})
})
test('Integration test gasCosts.js', function (t) {
test('Integration test gasCosts module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/gasCosts').default
const lengthCheck = {
const module: any = modules.gasCosts
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 2,
'assembly.sol': 2,
'ballot.sol': 3,
@ -273,18 +258,15 @@ test('Integration test gasCosts.js', function (t) {
'etherTransferInLoop.sol': 3,
'forLoopIteratesOverDynamicArray.sol': 2
}
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of gasCost warnings`)
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of gasCosts warnings`)
})
})
test('Integration test similarVariableNames.js', function (t) {
test('Integration test similarVariableNames module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/similarVariableNames').default
const lengthCheck = {
const module: any = modules.similarVariableNames
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 2,
@ -312,18 +294,15 @@ test('Integration test similarVariableNames.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of similarVariableNames warnings`)
})
})
test('Integration test blockTimestamp.js', function (t) {
test('Integration test blockTimestamp module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/blockTimestamp').default
const lengthCheck = {
const module: any = require('../../dist/src/solidity-analyzer/modules/blockTimestamp').default
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 1,
'assembly.sol': 0,
'ballot.sol': 0,
@ -351,18 +330,15 @@ test('Integration test blockTimestamp.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of blockTimestamp warnings`)
})
})
test('Integration test lowLevelCalls.js', function (t) {
test('Integration test lowLevelCalls module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/lowLevelCalls').default
const lengthCheck = {
const module: any = modules.lowLevelCalls
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 1,
'assembly.sol': 1,
'ballot.sol': 0,
@ -390,18 +366,15 @@ test('Integration test lowLevelCalls.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of lowLevelCalls warnings`)
})
})
test('Integration test blockBlockhash.js', function (t) {
test('Integration test blockBlockhash module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/blockBlockhash').default
const lengthCheck = {
const module: any = modules.blockBlockhash
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -429,18 +402,15 @@ test('Integration test blockBlockhash.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of blockBlockhash warnings`)
})
})
test('Integration test selfdestruct.js', function (t) {
test('Integration test selfdestruct module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/selfdestruct').default
const lengthCheck = {
const module: any = modules.selfdestruct
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -468,18 +438,15 @@ test('Integration test selfdestruct.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of selfdestruct warnings`)
})
})
test('Integration test guardConditions.js', function (t) {
test('Integration test guardConditions module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/guardConditions').default
const lengthCheck = {
const module: any = modules.guardConditions
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 1,
'ballot.sol': 0,
@ -507,18 +474,15 @@ test('Integration test guardConditions.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of guardCondition warnings`)
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of guardConditions warnings`)
})
})
test('Integration test deleteDynamicArrays.js', function (t) {
test('Integration test deleteDynamicArrays module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/deleteDynamicArrays').default
const lengthCheck = {
const module: any = modules.deleteDynamicArrays
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -546,18 +510,15 @@ test('Integration test deleteDynamicArrays.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of deleteDynamicArrays warnings`)
})
})
test('Integration test deleteFromDynamicArray.js', function (t) {
test('Integration test deleteFromDynamicArray module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/deleteFromDynamicArray').default
const lengthCheck = {
const module: any = modules.deleteFromDynamicArray
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -585,18 +546,15 @@ test('Integration test deleteFromDynamicArray.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of deleteFromDynamicArray warnings`)
})
})
test('Integration test assignAndCompare.js', function (t) {
test('Integration test assignAndCompare module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/assignAndCompare').default
const lengthCheck = {
const module: any = modules.assignAndCompare
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -624,18 +582,15 @@ test('Integration test assignAndCompare.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of assignAndCompare warnings`)
})
})
test('Integration test intDivisionTruncate.js', function (t) {
test('Integration test intDivisionTruncate module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/intDivisionTruncate').default
const lengthCheck = {
const module: any = modules.intDivisionTruncate
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -663,18 +618,15 @@ test('Integration test intDivisionTruncate.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of intDivisionTruncate warnings`)
})
})
test('Integration test erc20Decimal.js', function (t) {
test('Integration test erc20Decimal module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/erc20Decimals').default
const lengthCheck = {
const module: any = modules.erc20Decimals
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -702,18 +654,15 @@ test('Integration test erc20Decimal.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of erc20Decimals warnings`)
})
})
test('Integration test stringBytesLength.js', function (t) {
test('Integration test stringBytesLength module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/stringBytesLength').default
const lengthCheck = {
const module: any = modules.stringBytesLength
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -741,18 +690,15 @@ test('Integration test stringBytesLength.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of stringBytesLength warnings`)
})
})
test('Integration test etherTransferInLoop.js', function (t) {
test('Integration test etherTransferInLoop module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/etherTransferInLoop').default
const lengthCheck = {
const module: any = modules.etherTransferInLoop
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -780,18 +726,15 @@ test('Integration test etherTransferInLoop.js', function (t) {
'etherTransferInLoop.sol': 3,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of etherTransferInLoop warnings`)
})
})
test('Integration test forLoopIteratesOverDynamicArray.js', function (t) {
test('Integration test forLoopIteratesOverDynamicArray module', function (t: test.Test) {
t.plan(testFiles.length)
const module = require('../../dist/src/solidity-analyzer/modules/forLoopIteratesOverDynamicArray').default
const lengthCheck = {
const module = modules.forLoopIteratesOverDynamicArray
const lengthCheck: Record<string, number> = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 2,
@ -819,19 +762,18 @@ test('Integration test forLoopIteratesOverDynamicArray.js', function (t) {
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 2
}
runModuleOnFiles(module, t, (file, report) => {
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of forLoopIteratesOverDynamicArray warnings`)
})
})
// #################### Helpers
function runModuleOnFiles (Module, t, cb) {
const statRunner = new StatRunner()
testFiles.forEach((fileName) => {
statRunner.runWithModuleList(testFileAsts[fileName], [{ name: new Module().name, mod: new Module() }], (reports) => {
let report = reports[0].report
if (report.some((x) => x['warning'].includes('INTERNAL ERROR'))) {
function runModuleOnFiles (Module: any, t: test.Test, cb: ((fname: string, report: AnalysisReportObj[]) => void)): void {
const statRunner: StatRunner = new StatRunner()
testFiles.forEach((fileName: string) => {
statRunner.runWithModuleList(compilationResults[fileName], [{ name: new Module().name, mod: new Module() }], (reports: AnalysisReport[]) => {
let report: AnalysisReportObj[] = reports[0].report
if (report.some((x: AnalysisReportObj) => x['warning'].includes('INTERNAL ERROR'))) {
t.comment('Error while executing Module: ' + JSON.stringify(report))
}
cb(fileName, report)

@ -3,7 +3,8 @@ import { helpers } from 'remix-lib'
import { readFileSync } from 'fs'
import { join } from 'path'
import { default as StatRunner } from '../../dist/src/solidity-analyzer'
import { CompilationResult, AnalysisReportObj, AnalysisReport } from '../../src/types'
import { CompilationResult, AnalysisReportObj, AnalysisReport, AnalyzerModule } from '../../src/types'
import { checksEffectsInteraction } from '../../src/solidity-analyzer/modules/'
import { install, require as requireNPMmodule } from 'npm-install-version'
install('solc@0.4.24')
const compiler = requireNPMmodule('solc@0.4.24')
@ -19,7 +20,7 @@ test('staticAnalysisIssues.functionParameterPassingError', function (t) {
// https://github.com/ethereum/remix-ide/issues/889#issuecomment-351746474
t.plan(2)
const res: CompilationResult = compile('functionParameters.sol')
const Module = require('../../dist/src/solidity-analyzer/modules/checksEffectsInteraction').default
const Module: any = checksEffectsInteraction
const statRunner: StatRunner = new StatRunner()
t.doesNotThrow(() => {

@ -4,6 +4,7 @@ import { readFileSync } from 'fs'
import { join } from 'path'
import { default as StatRunner } from '../../dist/src/solidity-analyzer'
import { CompilationResult, AnalysisReportObj, AnalysisReport } from '../../src/types'
import { checksEffectsInteraction } from '../../src/solidity-analyzer/modules/'
import { install, require as requireNPMmodule } from 'npm-install-version'
install('solc@0.5.0')
const compiler = requireNPMmodule('solc@0.5.0')
@ -19,7 +20,7 @@ test('staticAnalysisIssues.functionParameterPassingError', function (t) {
// https://github.com/ethereum/remix-ide/issues/889#issuecomment-351746474
t.plan(2)
const res: CompilationResult = compile('functionParameters.sol')
const Module = require('../../dist/src/solidity-analyzer/modules/checksEffectsInteraction').default
const Module: any = checksEffectsInteraction
const statRunner: StatRunner = new StatRunner()
t.doesNotThrow(() => {

Loading…
Cancel
Save