Commit aee19d30 authored by aniket-engg's avatar aniket-engg Committed by Aniket

more type defs added in tests

parent c3a5ef3b
...@@ -3,13 +3,14 @@ import { helpers } from 'remix-lib' ...@@ -3,13 +3,14 @@ import { helpers } from 'remix-lib'
import { readFileSync } from 'fs' import { readFileSync } from 'fs'
import { join } from 'path' import { join } from 'path'
import { default as StatRunner } from '../../dist/src/solidity-analyzer' 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' import { install, require as requireNPMmodule } from 'npm-install-version'
install('solc@0.4.24') install('solc@0.4.24')
const solc = requireNPMmodule('solc@0.4.24') const solc = requireNPMmodule('solc@0.4.24')
const { compilerInput } = helpers.compiler const { compilerInput } = helpers.compiler
const folder: string = 'solidity-v0.4.24' 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[] = [ const testFiles: string[] = [
'KingOfTheEtherThrone.sol', 'KingOfTheEtherThrone.sol',
......
...@@ -3,13 +3,15 @@ import { helpers } from 'remix-lib' ...@@ -3,13 +3,15 @@ import { helpers } from 'remix-lib'
import { readFileSync } from 'fs' import { readFileSync } from 'fs'
import { join } from 'path' import { join } from 'path'
import { default as StatRunner } from '../../dist/src/solidity-analyzer' 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' import { install, require as requireNPMmodule } from 'npm-install-version'
install('solc@0.5.0') install('solc@0.5.0')
const compiler = requireNPMmodule('solc@0.5.0') const solc = requireNPMmodule('solc@0.5.0')
const { compilerInput } = helpers.compiler const { compilerInput } = helpers.compiler
const folder = 'solidity-v0.5' const folder: string = 'solidity-v0.5'
const testFiles = [ const testFiles: string[] = [
'KingOfTheEtherThrone.sol', 'KingOfTheEtherThrone.sol',
'assembly.sol', 'assembly.sol',
'ballot.sol', 'ballot.sol',
...@@ -38,19 +40,17 @@ const testFiles = [ ...@@ -38,19 +40,17 @@ const testFiles = [
'forLoopIteratesOverDynamicArray.sol' 'forLoopIteratesOverDynamicArray.sol'
] ]
var testFileAsts = {} var compilationResults: Record<string, CompilationResult> = {}
testFiles.forEach((fileName) => { testFiles.forEach((fileName) => {
var content = readFileSync(join(__dirname, 'test-contracts/' + folder, fileName), 'utf8') const content = readFileSync(join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
testFileAsts[fileName] = JSON.parse(compiler.compile(compilerInput(content))) 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) t.plan(testFiles.length)
const module: any = modules.thisLocal
const module = require('../../dist/src/solidity-analyzer/modules/thisLocal').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0, 'assembly.sol': 0,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -78,18 +78,15 @@ test('Integration test thisLocal.js', function (t) { ...@@ -78,18 +78,15 @@ test('Integration test thisLocal.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => { t.equal(report.length, lengthCheck[file], `${file} has right amount of thisLocal warnings`)
t.equal(report.length, lengthCheck[file], `${file} has right amount of this local warnings`)
}) })
}) })
test('Integration test checksEffectsInteraction.js', function (t) { test('Integration test checksEffectsInteraction module', function (t: test.Test) {
t.plan(testFiles.length) t.plan(testFiles.length)
const module: any = modules.checksEffectsInteraction
const module = require('../../dist/src/solidity-analyzer/modules/checksEffectsInteraction').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 1, 'KingOfTheEtherThrone.sol': 1,
'assembly.sol': 1, 'assembly.sol': 1,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -117,18 +114,15 @@ test('Integration test checksEffectsInteraction.js', function (t) { ...@@ -117,18 +114,15 @@ test('Integration test checksEffectsInteraction.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => { t.equal(report.length, lengthCheck[file], `${file} has right amount of checksEffectsInteraction warnings`)
t.equal(report.length, lengthCheck[file], `${file} has right amount of checks-effects-interaction warnings`)
}) })
}) })
test('Integration test constantFunctions.js', function (t) { test('Integration test constantFunctions module', function (t: test.Test) {
t.plan(testFiles.length) t.plan(testFiles.length)
const module: any = modules.constantFunctions
const module = require('../../dist/src/solidity-analyzer/modules/constantFunctions').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0, 'assembly.sol': 0,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -156,18 +150,15 @@ test('Integration test constantFunctions.js', function (t) { ...@@ -156,18 +150,15 @@ test('Integration test constantFunctions.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => { t.equal(report.length, lengthCheck[file], `${file} has right amount of constantFunctions warnings`)
t.equal(report.length, lengthCheck[file], `${file} has right amount of constant warnings`)
}) })
}) })
test('Integration test inlineAssembly.js', function (t) { test('Integration test inlineAssembly module', function (t: test.Test) {
t.plan(testFiles.length) t.plan(testFiles.length)
const module: any = modules.inlineAssembly
const module = require('../../dist/src/solidity-analyzer/modules/inlineAssembly').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 2, 'assembly.sol': 2,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -195,18 +186,15 @@ test('Integration test inlineAssembly.js', function (t) { ...@@ -195,18 +186,15 @@ test('Integration test inlineAssembly.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => { t.equal(report.length, lengthCheck[file], `${file} has right amount of inlineAssembly warnings`)
t.equal(report.length, lengthCheck[file], `${file} has right amount of inline assembly warnings`)
}) })
}) })
test('Integration test txOrigin.js', function (t) { test('Integration test txOrigin module', function (t: test.Test) {
t.plan(testFiles.length) t.plan(testFiles.length)
const module: any = modules.txOrigin
const module = require('../../dist/src/solidity-analyzer/modules/txOrigin').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 1, 'assembly.sol': 1,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -234,18 +222,15 @@ test('Integration test txOrigin.js', function (t) { ...@@ -234,18 +222,15 @@ test('Integration test txOrigin.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => { t.equal(report.length, lengthCheck[file], `${file} has right amount of txOrigin warnings`)
t.equal(report.length, lengthCheck[file], `${file} has right amount of tx.origin warnings`)
}) })
}) })
test('Integration test gasCosts.js', function (t) { test('Integration test gasCosts module', function (t: test.Test) {
t.plan(testFiles.length) t.plan(testFiles.length)
const module: any = modules.gasCosts
const module = require('../../dist/src/solidity-analyzer/modules/gasCosts').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 2, 'KingOfTheEtherThrone.sol': 2,
'assembly.sol': 2, 'assembly.sol': 2,
'ballot.sol': 3, 'ballot.sol': 3,
...@@ -273,18 +258,15 @@ test('Integration test gasCosts.js', function (t) { ...@@ -273,18 +258,15 @@ test('Integration test gasCosts.js', function (t) {
'etherTransferInLoop.sol': 3, 'etherTransferInLoop.sol': 3,
'forLoopIteratesOverDynamicArray.sol': 2 'forLoopIteratesOverDynamicArray.sol': 2
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => { t.equal(report.length, lengthCheck[file], `${file} has right amount of gasCosts warnings`)
t.equal(report.length, lengthCheck[file], `${file} has right amount of gasCost warnings`)
}) })
}) })
test('Integration test similarVariableNames.js', function (t) { test('Integration test similarVariableNames module', function (t: test.Test) {
t.plan(testFiles.length) t.plan(testFiles.length)
const module: any = modules.similarVariableNames
const module = require('../../dist/src/solidity-analyzer/modules/similarVariableNames').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0, 'assembly.sol': 0,
'ballot.sol': 2, 'ballot.sol': 2,
...@@ -312,18 +294,15 @@ test('Integration test similarVariableNames.js', function (t) { ...@@ -312,18 +294,15 @@ test('Integration test similarVariableNames.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of similarVariableNames warnings`) 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) t.plan(testFiles.length)
const module: any = require('../../dist/src/solidity-analyzer/modules/blockTimestamp').default
const module = require('../../dist/src/solidity-analyzer/modules/blockTimestamp').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 1, 'KingOfTheEtherThrone.sol': 1,
'assembly.sol': 0, 'assembly.sol': 0,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -351,18 +330,15 @@ test('Integration test blockTimestamp.js', function (t) { ...@@ -351,18 +330,15 @@ test('Integration test blockTimestamp.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of blockTimestamp warnings`) 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) t.plan(testFiles.length)
const module: any = modules.lowLevelCalls
const module = require('../../dist/src/solidity-analyzer/modules/lowLevelCalls').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 1, 'KingOfTheEtherThrone.sol': 1,
'assembly.sol': 1, 'assembly.sol': 1,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -390,18 +366,15 @@ test('Integration test lowLevelCalls.js', function (t) { ...@@ -390,18 +366,15 @@ test('Integration test lowLevelCalls.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of lowLevelCalls warnings`) 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) t.plan(testFiles.length)
const module: any = modules.blockBlockhash
const module = require('../../dist/src/solidity-analyzer/modules/blockBlockhash').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0, 'assembly.sol': 0,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -429,18 +402,15 @@ test('Integration test blockBlockhash.js', function (t) { ...@@ -429,18 +402,15 @@ test('Integration test blockBlockhash.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of blockBlockhash warnings`) 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) t.plan(testFiles.length)
const module: any = modules.selfdestruct
const module = require('../../dist/src/solidity-analyzer/modules/selfdestruct').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0, 'assembly.sol': 0,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -468,18 +438,15 @@ test('Integration test selfdestruct.js', function (t) { ...@@ -468,18 +438,15 @@ test('Integration test selfdestruct.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of selfdestruct warnings`) 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) t.plan(testFiles.length)
const module: any = modules.guardConditions
const module = require('../../dist/src/solidity-analyzer/modules/guardConditions').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 1, 'assembly.sol': 1,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -507,18 +474,15 @@ test('Integration test guardConditions.js', function (t) { ...@@ -507,18 +474,15 @@ test('Integration test guardConditions.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => { t.equal(report.length, lengthCheck[file], `${file} has right amount of guardConditions warnings`)
t.equal(report.length, lengthCheck[file], `${file} has right amount of guardCondition warnings`)
}) })
}) })
test('Integration test deleteDynamicArrays.js', function (t) { test('Integration test deleteDynamicArrays module', function (t: test.Test) {
t.plan(testFiles.length) t.plan(testFiles.length)
const module: any = modules.deleteDynamicArrays
const module = require('../../dist/src/solidity-analyzer/modules/deleteDynamicArrays').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0, 'assembly.sol': 0,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -546,18 +510,15 @@ test('Integration test deleteDynamicArrays.js', function (t) { ...@@ -546,18 +510,15 @@ test('Integration test deleteDynamicArrays.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of deleteDynamicArrays warnings`) 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) t.plan(testFiles.length)
const module: any = modules.deleteFromDynamicArray
const module = require('../../dist/src/solidity-analyzer/modules/deleteFromDynamicArray').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0, 'assembly.sol': 0,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -585,18 +546,15 @@ test('Integration test deleteFromDynamicArray.js', function (t) { ...@@ -585,18 +546,15 @@ test('Integration test deleteFromDynamicArray.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of deleteFromDynamicArray warnings`) 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) t.plan(testFiles.length)
const module: any = modules.assignAndCompare
const module = require('../../dist/src/solidity-analyzer/modules/assignAndCompare').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0, 'assembly.sol': 0,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -624,18 +582,15 @@ test('Integration test assignAndCompare.js', function (t) { ...@@ -624,18 +582,15 @@ test('Integration test assignAndCompare.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of assignAndCompare warnings`) 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) t.plan(testFiles.length)
const module: any = modules.intDivisionTruncate
const module = require('../../dist/src/solidity-analyzer/modules/intDivisionTruncate').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0, 'assembly.sol': 0,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -663,18 +618,15 @@ test('Integration test intDivisionTruncate.js', function (t) { ...@@ -663,18 +618,15 @@ test('Integration test intDivisionTruncate.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of intDivisionTruncate warnings`) 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) t.plan(testFiles.length)
const module: any = modules.erc20Decimals
const module = require('../../dist/src/solidity-analyzer/modules/erc20Decimals').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0, 'assembly.sol': 0,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -702,18 +654,15 @@ test('Integration test erc20Decimal.js', function (t) { ...@@ -702,18 +654,15 @@ test('Integration test erc20Decimal.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of erc20Decimals warnings`) 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) t.plan(testFiles.length)
const module: any = modules.stringBytesLength
const module = require('../../dist/src/solidity-analyzer/modules/stringBytesLength').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0, 'assembly.sol': 0,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -741,18 +690,15 @@ test('Integration test stringBytesLength.js', function (t) { ...@@ -741,18 +690,15 @@ test('Integration test stringBytesLength.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of stringBytesLength warnings`) 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) t.plan(testFiles.length)
const module: any = modules.etherTransferInLoop
const module = require('../../dist/src/solidity-analyzer/modules/etherTransferInLoop').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0, 'assembly.sol': 0,
'ballot.sol': 0, 'ballot.sol': 0,
...@@ -780,18 +726,15 @@ test('Integration test etherTransferInLoop.js', function (t) { ...@@ -780,18 +726,15 @@ test('Integration test etherTransferInLoop.js', function (t) {
'etherTransferInLoop.sol': 3, 'etherTransferInLoop.sol': 3,
'forLoopIteratesOverDynamicArray.sol': 0 'forLoopIteratesOverDynamicArray.sol': 0
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of etherTransferInLoop warnings`) 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) t.plan(testFiles.length)
const module = modules.forLoopIteratesOverDynamicArray
const module = require('../../dist/src/solidity-analyzer/modules/forLoopIteratesOverDynamicArray').default const lengthCheck: Record<string, number> = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0, 'assembly.sol': 0,
'ballot.sol': 2, 'ballot.sol': 2,
...@@ -819,19 +762,18 @@ test('Integration test forLoopIteratesOverDynamicArray.js', function (t) { ...@@ -819,19 +762,18 @@ test('Integration test forLoopIteratesOverDynamicArray.js', function (t) {
'etherTransferInLoop.sol': 0, 'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 2 'forLoopIteratesOverDynamicArray.sol': 2
} }
runModuleOnFiles(module, t, (file: string, report: AnalysisReportObj[]) => {
runModuleOnFiles(module, t, (file, report) => {
t.equal(report.length, lengthCheck[file], `${file} has right amount of forLoopIteratesOverDynamicArray warnings`) t.equal(report.length, lengthCheck[file], `${file} has right amount of forLoopIteratesOverDynamicArray warnings`)
}) })
}) })
// #################### Helpers // #################### Helpers
function runModuleOnFiles (Module, t, cb) { function runModuleOnFiles (Module: any, t: test.Test, cb: ((fname: string, report: AnalysisReportObj[]) => void)): void {
const statRunner = new StatRunner() const statRunner: StatRunner = new StatRunner()
testFiles.forEach((fileName) => { testFiles.forEach((fileName: string) => {
statRunner.runWithModuleList(testFileAsts[fileName], [{ name: new Module().name, mod: new Module() }], (reports) => { statRunner.runWithModuleList(compilationResults[fileName], [{ name: new Module().name, mod: new Module() }], (reports: AnalysisReport[]) => {
let report = reports[0].report let report: AnalysisReportObj[] = reports[0].report
if (report.some((x) => x['warning'].includes('INTERNAL ERROR'))) { if (report.some((x: AnalysisReportObj) => x['warning'].includes('INTERNAL ERROR'))) {
t.comment('Error while executing Module: ' + JSON.stringify(report)) t.comment('Error while executing Module: ' + JSON.stringify(report))
} }
cb(fileName, report) cb(fileName, report)
......
...@@ -3,7 +3,8 @@ import { helpers } from 'remix-lib' ...@@ -3,7 +3,8 @@ import { helpers } from 'remix-lib'
import { readFileSync } from 'fs' import { readFileSync } from 'fs'
import { join } from 'path' import { join } from 'path'
import { default as StatRunner } from '../../dist/src/solidity-analyzer' 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' import { install, require as requireNPMmodule } from 'npm-install-version'
install('solc@0.4.24') install('solc@0.4.24')
const compiler = requireNPMmodule('solc@0.4.24') const compiler = requireNPMmodule('solc@0.4.24')
...@@ -19,7 +20,7 @@ test('staticAnalysisIssues.functionParameterPassingError', function (t) { ...@@ -19,7 +20,7 @@ test('staticAnalysisIssues.functionParameterPassingError', function (t) {
// https://github.com/ethereum/remix-ide/issues/889#issuecomment-351746474 // https://github.com/ethereum/remix-ide/issues/889#issuecomment-351746474
t.plan(2) t.plan(2)
const res: CompilationResult = compile('functionParameters.sol') 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() const statRunner: StatRunner = new StatRunner()
t.doesNotThrow(() => { t.doesNotThrow(() => {
......
...@@ -4,6 +4,7 @@ import { readFileSync } from 'fs' ...@@ -4,6 +4,7 @@ import { readFileSync } from 'fs'
import { join } from 'path' import { join } from 'path'
import { default as StatRunner } from '../../dist/src/solidity-analyzer' import { default as StatRunner } from '../../dist/src/solidity-analyzer'
import { CompilationResult, AnalysisReportObj, AnalysisReport } from '../../src/types' import { CompilationResult, AnalysisReportObj, AnalysisReport } from '../../src/types'
import { checksEffectsInteraction } from '../../src/solidity-analyzer/modules/'
import { install, require as requireNPMmodule } from 'npm-install-version' import { install, require as requireNPMmodule } from 'npm-install-version'
install('solc@0.5.0') install('solc@0.5.0')
const compiler = requireNPMmodule('solc@0.5.0') const compiler = requireNPMmodule('solc@0.5.0')
...@@ -19,7 +20,7 @@ test('staticAnalysisIssues.functionParameterPassingError', function (t) { ...@@ -19,7 +20,7 @@ test('staticAnalysisIssues.functionParameterPassingError', function (t) {
// https://github.com/ethereum/remix-ide/issues/889#issuecomment-351746474 // https://github.com/ethereum/remix-ide/issues/889#issuecomment-351746474
t.plan(2) t.plan(2)
const res: CompilationResult = compile('functionParameters.sol') 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() const statRunner: StatRunner = new StatRunner()
t.doesNotThrow(() => { t.doesNotThrow(() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment