@ -29,10 +29,12 @@ var testFiles = [
'forgottenReturn.sol' ,
'selfdestruct.sol' ,
'deleteDynamicArray.sol' ,
'deleteFromDynamicArray.sol' ,
'blockLevelCompare.sol' ,
'intDivisionTruncate.sol' ,
'ERC20.sol' ,
'stringBytesLength.sol'
'stringBytesLength.sol' ,
'forLoopIteratesOverDynamicArray.sol'
]
var testFileAsts = { }
@ -67,10 +69,12 @@ test('Integration test thisLocal.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -103,10 +107,12 @@ test('Integration test checksEffectsInteraction.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -139,10 +145,12 @@ test('Integration test constantFunctions.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 1 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -175,10 +183,12 @@ test('Integration test inlineAssembly.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -211,10 +221,12 @@ test('Integration test txOrigin.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -247,10 +259,12 @@ test('Integration test gasCosts.js', function (t) {
'forgottenReturn.sol' : 3 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 2 ,
'deleteFromDynamicArray.sol' : 1 ,
'blockLevelCompare.sol' : 1 ,
'intDivisionTruncate.sol' : 1 ,
'ERC20.sol' : 2 ,
'stringBytesLength.sol' : 1
'stringBytesLength.sol' : 1 ,
'forLoopIteratesOverDynamicArray.sol' : 1
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -283,10 +297,12 @@ test('Integration test similarVariableNames.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 1 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -319,10 +335,12 @@ test('Integration test inlineAssembly.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -355,10 +373,12 @@ test('Integration test blockTimestamp.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -391,10 +411,12 @@ test('Integration test lowLevelCalls.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -427,10 +449,12 @@ test('Integration test blockBlockhash.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -463,10 +487,12 @@ test('Integration test noReturn.js', function (t) {
'forgottenReturn.sol' : 1 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -499,10 +525,12 @@ test('Integration test selfdestruct.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 3 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'ERC20.sol' : 0 ,
'intDivisionTruncate.sol' : 5 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -535,10 +563,12 @@ test('Integration test guardConditions.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 1 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 1 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -571,10 +601,12 @@ test('Integration test deleteDynamicArrays.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 2 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -582,6 +614,44 @@ test('Integration test deleteDynamicArrays.js', function (t) {
} )
} )
test ( 'Integration test deleteFromDynamicArray.js' , function ( t ) {
t . plan ( testFiles . length )
var module = require ( '../../src/solidity-analyzer/modules/deleteFromDynamicArray' )
var lengthCheck = {
'KingOfTheEtherThrone.sol' : 0 ,
'assembly.sol' : 0 ,
'ballot.sol' : 0 ,
'ballot_reentrant.sol' : 0 ,
'ballot_withoutWarnings.sol' : 0 ,
'cross_contract.sol' : 0 ,
'inheritance.sol' : 0 ,
'modifier1.sol' : 0 ,
'modifier2.sol' : 0 ,
'notReentrant.sol' : 0 ,
'structReentrant.sol' : 0 ,
'thisLocal.sol' : 0 ,
'globals.sol' : 0 ,
'library.sol' : 0 ,
'transfer.sol' : 0 ,
'ctor.sol' : 0 ,
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 1 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
t . equal ( report . length , lengthCheck [ file ] , ` ${ file } has right amount of deleteFromDynamicArray warnings ` )
} )
} )
test ( 'Integration test assignAndCompare.js' , function ( t ) {
t . plan ( testFiles . length )
@ -607,10 +677,12 @@ test('Integration test assignAndCompare.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 8 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -643,10 +715,12 @@ test('Integration test intDivisionTruncate.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 2 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -679,10 +753,12 @@ test('Integration test erc20Decimal.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 1 ,
'stringBytesLength.sol' : 0
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -715,10 +791,12 @@ test('Integration test stringBytesLength.js', function (t) {
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 1
'stringBytesLength.sol' : 1 ,
'forLoopIteratesOverDynamicArray.sol' : 0
}
runModuleOnFiles ( module , t , ( file , report ) => {
@ -726,6 +804,44 @@ test('Integration test stringBytesLength.js', function (t) {
} )
} )
test ( 'Integration test forLoopIteratesOverDynamicArray.js' , function ( t ) {
t . plan ( testFiles . length )
var module = require ( '../../src/solidity-analyzer/modules/forLoopIteratesOverDynamicArray' )
var lengthCheck = {
'KingOfTheEtherThrone.sol' : 0 ,
'assembly.sol' : 0 ,
'ballot.sol' : 2 ,
'ballot_reentrant.sol' : 1 ,
'ballot_withoutWarnings.sol' : 0 ,
'cross_contract.sol' : 0 ,
'inheritance.sol' : 0 ,
'modifier1.sol' : 0 ,
'modifier2.sol' : 0 ,
'notReentrant.sol' : 0 ,
'structReentrant.sol' : 0 ,
'thisLocal.sol' : 0 ,
'globals.sol' : 0 ,
'library.sol' : 0 ,
'transfer.sol' : 0 ,
'ctor.sol' : 0 ,
'forgottenReturn.sol' : 0 ,
'selfdestruct.sol' : 0 ,
'deleteDynamicArray.sol' : 0 ,
'deleteFromDynamicArray.sol' : 0 ,
'blockLevelCompare.sol' : 0 ,
'intDivisionTruncate.sol' : 0 ,
'ERC20.sol' : 0 ,
'stringBytesLength.sol' : 0 ,
'forLoopIteratesOverDynamicArray.sol' : 1
}
runModuleOnFiles ( module , t , ( file , report ) => {
t . equal ( report . length , lengthCheck [ file ] , ` ${ file } has right amount of forLoopIteratesOverDynamicArray warnings ` )
} )
} )
// #################### Helpers
function runModuleOnFiles ( module , t , cb ) {
var statRunner = new StatRunner ( )