0.5.0 contracts integration tests updated

pull/7/head
aniket-engg 5 years ago committed by Aniket
parent 5200069579
commit 56805303ba
  1. 10
      remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.ts
  2. 381
      remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.5.0.ts
  3. 56
      remix-analyzer/test/analysis/staticAnalysisIssues-test-0.5.0.ts

@ -448,18 +448,18 @@ function getFullQuallyfiedFuncDefinitionIdent (contract: ContractDefinitionAstNo
function getUnAssignedTopLevelBinOps (subScope: BlockAstNode | IfStatementAstNode | WhileStatementAstNode | ForStatementAstNode): ExpressionStatementAstNode[] {
let result: ExpressionStatementAstNode[] = []
if(subScope.nodeType === 'Block')
if(subScope && subScope.nodeType === 'Block')
result = subScope.statements.filter(isBinaryOpInExpression)
// for 'without braces' loops
else if (subScope && subScope.nodeType && isSubScopeStatement(subScope)) {
if (subScope.nodeType === 'IfStatement'){
if((subScope.trueBody.nodeType === "ExpressionStatement" && isBinaryOpInExpression(subScope.trueBody)))
if((subScope.trueBody && subScope.trueBody.nodeType === "ExpressionStatement" && isBinaryOpInExpression(subScope.trueBody)))
result.push(subScope.trueBody)
if (subScope.falseBody.nodeType === "ExpressionStatement" && isBinaryOpInExpression(subScope.falseBody))
if (subScope.falseBody && subScope.falseBody.nodeType === "ExpressionStatement" && isBinaryOpInExpression(subScope.falseBody))
result.push(subScope.falseBody)
}
else {
if(subScope.body.nodeType === "ExpressionStatement" && isBinaryOpInExpression(subScope.body))
if(subScope.body && subScope.body.nodeType === "ExpressionStatement" && isBinaryOpInExpression(subScope.body))
result.push(subScope.body)
}
}
@ -982,7 +982,7 @@ function isStringToBytesConversion (node: FunctionCallAstNode): boolean {
function isExplicitCast (node: FunctionCallAstNode, castFromType: string, castToType: string): boolean {
return node.kind === "typeConversion" &&
nodeType(node.expression, exactMatch(nodeTypes.ELEMENTARYTYPENAMEEXPRESSION)) && node.expression.typeName.name === castToType &&
nodeType(node.expression, exactMatch(nodeTypes.ELEMENTARYTYPENAMEEXPRESSION)) && node.expression.typeName === castToType &&
nodeType(node.arguments[0], exactMatch(nodeTypes.IDENTIFIER)) && typeDescription(node.arguments[0], castFromType)
}

@ -6,7 +6,7 @@ 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 { compilerInput } = helpers.compiler
const folder = 'solidity-v0.5'
const testFiles = [
@ -30,12 +30,12 @@ const testFiles = [
'selfdestruct.sol',
'deleteDynamicArray.sol',
'deleteFromDynamicArray.sol',
// 'blockLevelCompare.sol',
// 'intDivisionTruncate.sol',
// 'ERC20.sol',
// 'stringBytesLength.sol',
// 'etherTransferInLoop.sol',
// 'forLoopIteratesOverDynamicArray.sol'
'blockLevelCompare.sol',
'intDivisionTruncate.sol',
'ERC20.sol',
'stringBytesLength.sol',
'etherTransferInLoop.sol',
'forLoopIteratesOverDynamicArray.sol'
]
var testFileAsts = {}
@ -45,16 +45,12 @@ testFiles.forEach((fileName) => {
testFileAsts[fileName] = JSON.parse(compiler.compile(compilerInput(content)))
})
// console.log(testFileAsts['ballot.sol'].sources['test.sol'].ast.nodes[1].nodes)
test('Integration test thisLocal.js', function (t) {
// console.log('testFileAsts---------',testFileAsts)
// t.plan(testFiles.length)
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/thisLocal').default
const module = require('../../dist/src/solidity-analyzer/modules/thisLocal').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -75,12 +71,12 @@ test('Integration test thisLocal.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -89,11 +85,11 @@ test('Integration test thisLocal.js', function (t) {
})
test('Integration test checksEffectsInteraction.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/checksEffectsInteraction').default
const module = require('../../dist/src/solidity-analyzer/modules/checksEffectsInteraction').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 1,
'assembly.sol': 1,
'ballot.sol': 0,
@ -114,12 +110,12 @@ test('Integration test checksEffectsInteraction.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -128,11 +124,11 @@ test('Integration test checksEffectsInteraction.js', function (t) {
})
test('Integration test constantFunctions.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/constantFunctions').default
const module = require('../../dist/src/solidity-analyzer/modules/constantFunctions').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -153,12 +149,12 @@ test('Integration test constantFunctions.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -167,11 +163,11 @@ test('Integration test constantFunctions.js', function (t) {
})
test('Integration test inlineAssembly.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/inlineAssembly').default
const module = require('../../dist/src/solidity-analyzer/modules/inlineAssembly').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 2,
'ballot.sol': 0,
@ -192,12 +188,12 @@ test('Integration test inlineAssembly.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -206,11 +202,11 @@ test('Integration test inlineAssembly.js', function (t) {
})
test('Integration test txOrigin.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/txOrigin').default
const module = require('../../dist/src/solidity-analyzer/modules/txOrigin').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 1,
'ballot.sol': 0,
@ -231,12 +227,12 @@ test('Integration test txOrigin.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -245,11 +241,11 @@ test('Integration test txOrigin.js', function (t) {
})
test('Integration test gasCosts.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/gasCosts').default
const module = require('../../dist/src/solidity-analyzer/modules/gasCosts').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 2,
'assembly.sol': 2,
'ballot.sol': 3,
@ -270,12 +266,12 @@ test('Integration test gasCosts.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 2,
'deleteFromDynamicArray.sol': 1,
// 'blockLevelCompare.sol': 1,
// 'intDivisionTruncate.sol': 1,
// 'ERC20.sol': 2,
// 'stringBytesLength.sol': 1,
// 'etherTransferInLoop.sol': 3,
// 'forLoopIteratesOverDynamicArray.sol': 2
'blockLevelCompare.sol': 1,
'intDivisionTruncate.sol': 1,
'ERC20.sol': 2,
'stringBytesLength.sol': 1,
'etherTransferInLoop.sol': 3,
'forLoopIteratesOverDynamicArray.sol': 2
}
runModuleOnFiles(module, t, (file, report) => {
@ -284,11 +280,11 @@ test('Integration test gasCosts.js', function (t) {
})
test('Integration test similarVariableNames.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/similarVariableNames').default
const module = require('../../dist/src/solidity-analyzer/modules/similarVariableNames').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 2,
@ -309,12 +305,12 @@ test('Integration test similarVariableNames.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 1,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -323,11 +319,11 @@ test('Integration test similarVariableNames.js', function (t) {
})
test('Integration test blockTimestamp.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/blockTimestamp').default
const module = require('../../dist/src/solidity-analyzer/modules/blockTimestamp').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 1,
'assembly.sol': 0,
'ballot.sol': 0,
@ -348,12 +344,12 @@ test('Integration test blockTimestamp.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -362,11 +358,11 @@ test('Integration test blockTimestamp.js', function (t) {
})
test('Integration test lowLevelCalls.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/lowLevelCalls').default
const module = require('../../dist/src/solidity-analyzer/modules/lowLevelCalls').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 1,
'assembly.sol': 1,
'ballot.sol': 0,
@ -387,12 +383,12 @@ test('Integration test lowLevelCalls.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -401,11 +397,11 @@ test('Integration test lowLevelCalls.js', function (t) {
})
test('Integration test blockBlockhash.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/blockBlockhash').default
const module = require('../../dist/src/solidity-analyzer/modules/blockBlockhash').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -426,12 +422,12 @@ test('Integration test blockBlockhash.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -440,11 +436,11 @@ test('Integration test blockBlockhash.js', function (t) {
})
test('Integration test selfdestruct.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/selfdestruct').default
const module = require('../../dist/src/solidity-analyzer/modules/selfdestruct').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -465,12 +461,12 @@ test('Integration test selfdestruct.js', function (t) {
'selfdestruct.sol': 3,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'ERC20.sol': 0,
// 'intDivisionTruncate.sol': 5,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'ERC20.sol': 0,
'intDivisionTruncate.sol': 5,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -479,11 +475,11 @@ test('Integration test selfdestruct.js', function (t) {
})
test('Integration test guardConditions.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/guardConditions').default
const module = require('../../dist/src/solidity-analyzer/modules/guardConditions').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 1,
'ballot.sol': 0,
@ -504,12 +500,12 @@ test('Integration test guardConditions.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 1,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 1,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 1,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -518,11 +514,11 @@ test('Integration test guardConditions.js', function (t) {
})
test('Integration test deleteDynamicArrays.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/deleteDynamicArrays').default
const module = require('../../dist/src/solidity-analyzer/modules/deleteDynamicArrays').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -543,12 +539,12 @@ test('Integration test deleteDynamicArrays.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 2,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -557,11 +553,11 @@ test('Integration test deleteDynamicArrays.js', function (t) {
})
test('Integration test deleteFromDynamicArray.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/deleteFromDynamicArray').default
const module = require('../../dist/src/solidity-analyzer/modules/deleteFromDynamicArray').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -582,12 +578,12 @@ test('Integration test deleteFromDynamicArray.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 1,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -596,11 +592,11 @@ test('Integration test deleteFromDynamicArray.js', function (t) {
})
test('Integration test assignAndCompare.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/assignAndCompare').default
const module = require('../../dist/src/solidity-analyzer/modules/assignAndCompare').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -621,12 +617,12 @@ test('Integration test assignAndCompare.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 8,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 8,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -635,11 +631,11 @@ test('Integration test assignAndCompare.js', function (t) {
})
test('Integration test intDivisionTruncate.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/intDivisionTruncate').default
const module = require('../../dist/src/solidity-analyzer/modules/intDivisionTruncate').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -660,12 +656,12 @@ test('Integration test intDivisionTruncate.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 2,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 2,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -674,11 +670,11 @@ test('Integration test intDivisionTruncate.js', function (t) {
})
test('Integration test erc20Decimal.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/erc20Decimals').default
const module = require('../../dist/src/solidity-analyzer/modules/erc20Decimals').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -699,12 +695,12 @@ test('Integration test erc20Decimal.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 1,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 1,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -713,11 +709,11 @@ test('Integration test erc20Decimal.js', function (t) {
})
test('Integration test stringBytesLength.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/stringBytesLength').default
const module = require('../../dist/src/solidity-analyzer/modules/stringBytesLength').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -738,12 +734,12 @@ test('Integration test stringBytesLength.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 1,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 0,
'stringBytesLength.sol': 1,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -752,11 +748,11 @@ test('Integration test stringBytesLength.js', function (t) {
})
test('Integration test etherTransferInLoop.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/etherTransferInLoop').default
const module = require('../../dist/src/solidity-analyzer/modules/etherTransferInLoop').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 0,
@ -777,12 +773,12 @@ test('Integration test etherTransferInLoop.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 3,
// 'forLoopIteratesOverDynamicArray.sol': 0
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 3,
'forLoopIteratesOverDynamicArray.sol': 0
}
runModuleOnFiles(module, t, (file, report) => {
@ -791,11 +787,11 @@ test('Integration test etherTransferInLoop.js', function (t) {
})
test('Integration test forLoopIteratesOverDynamicArray.js', function (t) {
t.plan(20)
t.plan(testFiles.length)
var module = require('../../dist/src/solidity-analyzer/modules/forLoopIteratesOverDynamicArray').default
const module = require('../../dist/src/solidity-analyzer/modules/forLoopIteratesOverDynamicArray').default
var lengthCheck = {
const lengthCheck = {
'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0,
'ballot.sol': 2,
@ -816,12 +812,12 @@ test('Integration test forLoopIteratesOverDynamicArray.js', function (t) {
'selfdestruct.sol': 0,
'deleteDynamicArray.sol': 0,
'deleteFromDynamicArray.sol': 0,
// 'blockLevelCompare.sol': 0,
// 'intDivisionTruncate.sol': 0,
// 'ERC20.sol': 0,
// 'stringBytesLength.sol': 0,
// 'etherTransferInLoop.sol': 0,
// 'forLoopIteratesOverDynamicArray.sol': 2
'blockLevelCompare.sol': 0,
'intDivisionTruncate.sol': 0,
'ERC20.sol': 0,
'stringBytesLength.sol': 0,
'etherTransferInLoop.sol': 0,
'forLoopIteratesOverDynamicArray.sol': 2
}
runModuleOnFiles(module, t, (file, report) => {
@ -831,11 +827,10 @@ test('Integration test forLoopIteratesOverDynamicArray.js', function (t) {
// #################### Helpers
function runModuleOnFiles (Module, t, cb) {
var statRunner = new StatRunner()
const statRunner = new StatRunner()
testFiles.forEach((fileName) => {
statRunner.runWithModuleList(testFileAsts[fileName], [{ name: new Module().name, mod: new Module() }], (reports) => {
let report = reports[0].report
// console.log('reports----', report)
if (report.some((x) => x['warning'].includes('INTERNAL ERROR'))) {
t.comment('Error while executing Module: ' + JSON.stringify(report))
}

@ -1,32 +1,32 @@
// 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'
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) {
// const content = readFileSync(join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
// return JSON.parse(compiler.compile(compilerInput(content)))
// }
function compile (fileName) {
const content = readFileSync(join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
return JSON.parse(compiler.compile(compilerInput(content)))
}
// test('staticAnalysisIssues.functionParameterPassingError', function (t) {
// // https://github.com/ethereum/remix-ide/issues/889#issuecomment-351746474
// t.plan(2)
// const res = compile('functionParameters.sol')
// const Module = require('../../dist/src/solidity-analyzer/modules/checksEffectsInteraction').default
// const statRunner = new StatRunner()
test('staticAnalysisIssues.functionParameterPassingError', function (t) {
// https://github.com/ethereum/remix-ide/issues/889#issuecomment-351746474
t.plan(2)
const res = compile('functionParameters.sol')
const Module = require('../../dist/src/solidity-analyzer/modules/checksEffectsInteraction').default
const statRunner = new StatRunner()
// t.doesNotThrow(() => {
// statRunner.runWithModuleList(res, [{ name: new Module().name, mod: new Module() }], (reports) => {
// })
// }, 'Analysis should not throw')
t.doesNotThrow(() => {
statRunner.runWithModuleList(res, [{ name: new Module().name, mod: new Module() }], (reports) => {
})
}, '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'))
// })
// })
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'))
})
})

Loading…
Cancel
Save