You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
867 lines
24 KiB
867 lines
24 KiB
7 years ago
|
var test = require('tape')
|
||
7 years ago
|
var remixLib = require('remix-lib')
|
||
7 years ago
|
|
||
6 years ago
|
var StatRunner = require('../../src/solidity-analyzer')
|
||
7 years ago
|
var compilerInput = remixLib.helpers.compiler.compilerInput
|
||
7 years ago
|
|
||
6 years ago
|
const niv = require('npm-install-version')
|
||
|
niv.install('solc@0.5.0')
|
||
|
var compiler = niv.require('solc@0.5.0')
|
||
7 years ago
|
|
||
|
var fs = require('fs')
|
||
|
var path = require('path')
|
||
6 years ago
|
var folder = 'solidity-v0.5'
|
||
7 years ago
|
|
||
|
var testFiles = [
|
||
|
'KingOfTheEtherThrone.sol',
|
||
|
'assembly.sol',
|
||
|
'ballot.sol',
|
||
|
'ballot_reentrant.sol',
|
||
|
'ballot_withoutWarnings.sol',
|
||
|
'cross_contract.sol',
|
||
|
'inheritance.sol',
|
||
|
'modifier1.sol',
|
||
|
'modifier2.sol',
|
||
|
'notReentrant.sol',
|
||
|
'structReentrant.sol',
|
||
|
'thisLocal.sol',
|
||
|
'globals.sol',
|
||
|
'library.sol',
|
||
|
'transfer.sol',
|
||
|
'ctor.sol',
|
||
|
'forgottenReturn.sol',
|
||
7 years ago
|
'selfdestruct.sol',
|
||
7 years ago
|
'deleteDynamicArray.sol',
|
||
6 years ago
|
'deleteFromDynamicArray.sol',
|
||
7 years ago
|
'blockLevelCompare.sol',
|
||
6 years ago
|
'intDivisionTruncate.sol',
|
||
6 years ago
|
'ERC20.sol',
|
||
6 years ago
|
'stringBytesLength.sol',
|
||
|
'forLoopIteratesOverDynamicArray.sol'
|
||
7 years ago
|
]
|
||
|
|
||
|
var testFileAsts = {}
|
||
|
|
||
|
testFiles.forEach((fileName) => {
|
||
6 years ago
|
var content = fs.readFileSync(path.join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
|
||
6 years ago
|
testFileAsts[fileName] = JSON.parse(compiler.compile(compilerInput(content)))
|
||
7 years ago
|
})
|
||
|
|
||
|
test('Integration test thisLocal.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/thisLocal')
|
||
7 years ago
|
|
||
|
var lengthCheck = {
|
||
|
'KingOfTheEtherThrone.sol': 0,
|
||
|
'assembly.sol': 0,
|
||
|
'ballot.sol': 0,
|
||
|
'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': 1,
|
||
|
'globals.sol': 0,
|
||
|
'library.sol': 0,
|
||
|
'transfer.sol': 0,
|
||
|
'ctor.sol': 0,
|
||
|
'forgottenReturn.sol': 0,
|
||
7 years ago
|
'selfdestruct.sol': 0,
|
||
7 years ago
|
'deleteDynamicArray.sol': 0,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 0,
|
||
6 years ago
|
'intDivisionTruncate.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of this local warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
test('Integration test checksEffectsInteraction.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/checksEffectsInteraction')
|
||
7 years ago
|
|
||
|
var lengthCheck = {
|
||
|
'KingOfTheEtherThrone.sol': 1,
|
||
|
'assembly.sol': 1,
|
||
|
'ballot.sol': 0,
|
||
|
'ballot_reentrant.sol': 1,
|
||
|
'ballot_withoutWarnings.sol': 0,
|
||
|
'cross_contract.sol': 0,
|
||
|
'inheritance.sol': 1,
|
||
|
'modifier1.sol': 0,
|
||
|
'modifier2.sol': 0,
|
||
|
'notReentrant.sol': 0,
|
||
|
'structReentrant.sol': 1,
|
||
|
'thisLocal.sol': 0,
|
||
|
'globals.sol': 1,
|
||
|
'library.sol': 1,
|
||
|
'transfer.sol': 1,
|
||
|
'ctor.sol': 0,
|
||
|
'forgottenReturn.sol': 0,
|
||
7 years ago
|
'selfdestruct.sol': 0,
|
||
7 years ago
|
'deleteDynamicArray.sol': 0,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 0,
|
||
6 years ago
|
'intDivisionTruncate.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of checks-effects-interaction warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
test('Integration test constantFunctions.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/constantFunctions')
|
||
7 years ago
|
|
||
|
var lengthCheck = {
|
||
|
'KingOfTheEtherThrone.sol': 0,
|
||
|
'assembly.sol': 0,
|
||
|
'ballot.sol': 0,
|
||
|
'ballot_reentrant.sol': 0,
|
||
|
'ballot_withoutWarnings.sol': 0,
|
||
6 years ago
|
'cross_contract.sol': 0,
|
||
7 years ago
|
'inheritance.sol': 0,
|
||
|
'modifier1.sol': 1,
|
||
|
'modifier2.sol': 0,
|
||
|
'notReentrant.sol': 0,
|
||
7 years ago
|
'structReentrant.sol': 1,
|
||
7 years ago
|
'thisLocal.sol': 1,
|
||
|
'globals.sol': 0,
|
||
7 years ago
|
'library.sol': 3,
|
||
7 years ago
|
'transfer.sol': 0,
|
||
|
'ctor.sol': 0,
|
||
|
'forgottenReturn.sol': 0,
|
||
6 years ago
|
'selfdestruct.sol': 0,
|
||
7 years ago
|
'deleteDynamicArray.sol': 0,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 0,
|
||
6 years ago
|
'intDivisionTruncate.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of constant warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
test('Integration test inlineAssembly.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/inlineAssembly')
|
||
7 years ago
|
|
||
|
var lengthCheck = {
|
||
|
'KingOfTheEtherThrone.sol': 0,
|
||
|
'assembly.sol': 2,
|
||
|
'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,
|
||
7 years ago
|
'selfdestruct.sol': 0,
|
||
7 years ago
|
'deleteDynamicArray.sol': 0,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 0,
|
||
6 years ago
|
'intDivisionTruncate.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of inline assembly warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
test('Integration test txOrigin.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/txOrigin')
|
||
7 years ago
|
|
||
|
var lengthCheck = {
|
||
|
'KingOfTheEtherThrone.sol': 0,
|
||
|
'assembly.sol': 1,
|
||
|
'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': 1,
|
||
|
'library.sol': 0,
|
||
|
'transfer.sol': 0,
|
||
|
'ctor.sol': 0,
|
||
|
'forgottenReturn.sol': 0,
|
||
7 years ago
|
'selfdestruct.sol': 0,
|
||
7 years ago
|
'deleteDynamicArray.sol': 0,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 0,
|
||
6 years ago
|
'intDivisionTruncate.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of tx.origin warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
test('Integration test gasCosts.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/gasCosts')
|
||
7 years ago
|
|
||
|
var lengthCheck = {
|
||
|
'KingOfTheEtherThrone.sol': 2,
|
||
|
'assembly.sol': 2,
|
||
|
'ballot.sol': 3,
|
||
|
'ballot_reentrant.sol': 2,
|
||
|
'ballot_withoutWarnings.sol': 0,
|
||
|
'cross_contract.sol': 1,
|
||
|
'inheritance.sol': 1,
|
||
|
'modifier1.sol': 0,
|
||
|
'modifier2.sol': 1,
|
||
|
'notReentrant.sol': 1,
|
||
|
'structReentrant.sol': 1,
|
||
7 years ago
|
'thisLocal.sol': 1,
|
||
7 years ago
|
'globals.sol': 1,
|
||
|
'library.sol': 1,
|
||
|
'transfer.sol': 1,
|
||
|
'ctor.sol': 0,
|
||
|
'forgottenReturn.sol': 3,
|
||
7 years ago
|
'selfdestruct.sol': 0,
|
||
7 years ago
|
'deleteDynamicArray.sol': 2,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 1,
|
||
7 years ago
|
'blockLevelCompare.sol': 1,
|
||
6 years ago
|
'intDivisionTruncate.sol': 1,
|
||
6 years ago
|
'ERC20.sol': 2,
|
||
6 years ago
|
'stringBytesLength.sol': 1,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 1
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of gasCost warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
test('Integration test similarVariableNames.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/similarVariableNames')
|
||
7 years ago
|
|
||
|
var lengthCheck = {
|
||
|
'KingOfTheEtherThrone.sol': 0,
|
||
|
'assembly.sol': 0,
|
||
|
'ballot.sol': 2,
|
||
6 years ago
|
'ballot_reentrant.sol': 11,
|
||
7 years ago
|
'ballot_withoutWarnings.sol': 0,
|
||
|
'cross_contract.sol': 0,
|
||
|
'inheritance.sol': 0,
|
||
|
'modifier1.sol': 0,
|
||
|
'modifier2.sol': 0,
|
||
|
'notReentrant.sol': 1,
|
||
|
'structReentrant.sol': 0,
|
||
|
'thisLocal.sol': 0,
|
||
|
'globals.sol': 0,
|
||
|
'library.sol': 0,
|
||
|
'transfer.sol': 0,
|
||
|
'ctor.sol': 1,
|
||
|
'forgottenReturn.sol': 0,
|
||
7 years ago
|
'selfdestruct.sol': 0,
|
||
7 years ago
|
'deleteDynamicArray.sol': 1,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 0,
|
||
6 years ago
|
'intDivisionTruncate.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of similarVariableNames warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
test('Integration test inlineAssembly.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/inlineAssembly')
|
||
7 years ago
|
|
||
|
var lengthCheck = {
|
||
|
'KingOfTheEtherThrone.sol': 0,
|
||
|
'assembly.sol': 2,
|
||
|
'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,
|
||
7 years ago
|
'selfdestruct.sol': 0,
|
||
7 years ago
|
'deleteDynamicArray.sol': 0,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 0,
|
||
6 years ago
|
'intDivisionTruncate.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of inlineAssembly warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
test('Integration test blockTimestamp.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/blockTimestamp')
|
||
7 years ago
|
|
||
|
var lengthCheck = {
|
||
|
'KingOfTheEtherThrone.sol': 1,
|
||
|
'assembly.sol': 0,
|
||
|
'ballot.sol': 0,
|
||
|
'ballot_reentrant.sol': 3,
|
||
|
'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': 2,
|
||
|
'library.sol': 0,
|
||
|
'transfer.sol': 0,
|
||
|
'ctor.sol': 0,
|
||
|
'forgottenReturn.sol': 0,
|
||
7 years ago
|
'selfdestruct.sol': 0,
|
||
7 years ago
|
'deleteDynamicArray.sol': 0,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 0,
|
||
6 years ago
|
'intDivisionTruncate.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of blockTimestamp warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
test('Integration test lowLevelCalls.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/lowLevelCalls')
|
||
7 years ago
|
|
||
|
var lengthCheck = {
|
||
|
'KingOfTheEtherThrone.sol': 1,
|
||
|
'assembly.sol': 1,
|
||
|
'ballot.sol': 0,
|
||
|
'ballot_reentrant.sol': 7,
|
||
|
'ballot_withoutWarnings.sol': 0,
|
||
|
'cross_contract.sol': 1,
|
||
|
'inheritance.sol': 1,
|
||
|
'modifier1.sol': 0,
|
||
|
'modifier2.sol': 0,
|
||
|
'notReentrant.sol': 1,
|
||
|
'structReentrant.sol': 1,
|
||
|
'thisLocal.sol': 2,
|
||
|
'globals.sol': 1,
|
||
|
'library.sol': 1,
|
||
|
'transfer.sol': 0,
|
||
|
'ctor.sol': 0,
|
||
|
'forgottenReturn.sol': 0,
|
||
7 years ago
|
'selfdestruct.sol': 0,
|
||
7 years ago
|
'deleteDynamicArray.sol': 0,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 0,
|
||
6 years ago
|
'intDivisionTruncate.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of lowLevelCalls warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
test('Integration test blockBlockhash.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/blockBlockhash')
|
||
7 years ago
|
|
||
|
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, // was 1 !! @TODO
|
||
|
'library.sol': 0,
|
||
|
'transfer.sol': 0,
|
||
|
'ctor.sol': 0,
|
||
|
'forgottenReturn.sol': 0,
|
||
7 years ago
|
'selfdestruct.sol': 0,
|
||
7 years ago
|
'deleteDynamicArray.sol': 0,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 0,
|
||
6 years ago
|
'intDivisionTruncate.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of blockBlockhash warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
6 years ago
|
/*
|
||
|
|
||
|
! No return gives compilation error with solidity 0.5.0
|
||
|
|
||
7 years ago
|
test('Integration test noReturn.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/noReturn')
|
||
7 years ago
|
|
||
|
var lengthCheck = {
|
||
|
'KingOfTheEtherThrone.sol': 0,
|
||
|
'assembly.sol': 1,
|
||
|
'ballot.sol': 0,
|
||
|
'ballot_reentrant.sol': 0,
|
||
|
'ballot_withoutWarnings.sol': 0,
|
||
|
'cross_contract.sol': 0,
|
||
|
'inheritance.sol': 0,
|
||
|
'modifier1.sol': 1,
|
||
|
'modifier2.sol': 0,
|
||
|
'notReentrant.sol': 0,
|
||
|
'structReentrant.sol': 0,
|
||
|
'thisLocal.sol': 1,
|
||
|
'globals.sol': 0,
|
||
|
'library.sol': 0,
|
||
|
'transfer.sol': 0,
|
||
|
'ctor.sol': 0,
|
||
|
'forgottenReturn.sol': 1,
|
||
7 years ago
|
'selfdestruct.sol': 0,
|
||
7 years ago
|
'deleteDynamicArray.sol': 0,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 0,
|
||
6 years ago
|
'intDivisionTruncate.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of noReturn warnings`)
|
||
|
})
|
||
|
})
|
||
6 years ago
|
*/
|
||
7 years ago
|
|
||
|
test('Integration test selfdestruct.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/selfdestruct')
|
||
7 years ago
|
|
||
|
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,
|
||
6 years ago
|
'globals.sol': 2,
|
||
7 years ago
|
'library.sol': 0,
|
||
|
'transfer.sol': 0,
|
||
|
'ctor.sol': 0,
|
||
|
'forgottenReturn.sol': 0,
|
||
6 years ago
|
'selfdestruct.sol': 3,
|
||
7 years ago
|
'deleteDynamicArray.sol': 0,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'intDivisionTruncate.sol': 5,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of selfdestruct warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
7 years ago
|
test('Integration test guardConditions.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/guardConditions')
|
||
7 years ago
|
|
||
|
var lengthCheck = {
|
||
|
'KingOfTheEtherThrone.sol': 0,
|
||
|
'assembly.sol': 1,
|
||
|
'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': 1,
|
||
|
'library.sol': 0,
|
||
|
'transfer.sol': 0,
|
||
|
'ctor.sol': 0,
|
||
|
'forgottenReturn.sol': 0,
|
||
7 years ago
|
'selfdestruct.sol': 0,
|
||
7 years ago
|
'deleteDynamicArray.sol': 1,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 0,
|
||
6 years ago
|
'intDivisionTruncate.sol': 1,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of guardCondition warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
7 years ago
|
test('Integration test deleteDynamicArrays.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/deleteDynamicArrays')
|
||
7 years ago
|
|
||
|
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,
|
||
7 years ago
|
'deleteDynamicArray.sol': 2,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 0,
|
||
6 years ago
|
'intDivisionTruncate.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of deleteDynamicArrays warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
6 years ago
|
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,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
6 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of deleteFromDynamicArray warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
7 years ago
|
test('Integration test assignAndCompare.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/assignAndCompare')
|
||
7 years ago
|
|
||
|
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,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 8,
|
||
6 years ago
|
'intDivisionTruncate.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of assignAndCompare warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
7 years ago
|
test('Integration test intDivisionTruncate.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/intDivisionTruncate')
|
||
7 years ago
|
|
||
|
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,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
7 years ago
|
'blockLevelCompare.sol': 0,
|
||
6 years ago
|
'intDivisionTruncate.sol': 2,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
7 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of intDivisionTruncate warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
6 years ago
|
test('Integration test erc20Decimal.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/erc20Decimals')
|
||
6 years ago
|
|
||
|
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,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
6 years ago
|
'blockLevelCompare.sol': 0,
|
||
|
'intDivisionTruncate.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 1,
|
||
6 years ago
|
'stringBytesLength.sol': 0,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
6 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of erc20Decimals warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
6 years ago
|
test('Integration test stringBytesLength.js', function (t) {
|
||
|
t.plan(testFiles.length)
|
||
|
|
||
6 years ago
|
var module = require('../../src/solidity-analyzer/modules/stringBytesLength')
|
||
6 years ago
|
|
||
|
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,
|
||
6 years ago
|
'deleteFromDynamicArray.sol': 0,
|
||
6 years ago
|
'blockLevelCompare.sol': 0,
|
||
|
'intDivisionTruncate.sol': 0,
|
||
6 years ago
|
'ERC20.sol': 0,
|
||
6 years ago
|
'stringBytesLength.sol': 1,
|
||
|
'forLoopIteratesOverDynamicArray.sol': 0
|
||
6 years ago
|
}
|
||
|
|
||
|
runModuleOnFiles(module, t, (file, report) => {
|
||
|
t.equal(report.length, lengthCheck[file], `${file} has right amount of stringBytesLength warnings`)
|
||
|
})
|
||
|
})
|
||
|
|
||
6 years ago
|
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`)
|
||
|
})
|
||
|
})
|
||
|
|
||
7 years ago
|
// #################### Helpers
|
||
|
function runModuleOnFiles (module, t, cb) {
|
||
|
var statRunner = new StatRunner()
|
||
|
|
||
|
testFiles.forEach((fileName) => {
|
||
|
statRunner.runWithModuleList(testFileAsts[fileName], [{ name: module.name, mod: new module.Module() }], (reports) => {
|
||
7 years ago
|
let report = reports[0].report
|
||
|
if (report.some((x) => x['warning'].includes('INTERNAL ERROR'))) {
|
||
|
t.comment('Error while executing Module: ' + JSON.stringify(report))
|
||
|
}
|
||
|
cb(fileName, report)
|
||
7 years ago
|
})
|
||
|
})
|
||
|
}
|