Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
2cb6cf1c
Commit
2cb6cf1c
authored
Mar 17, 2020
by
aniket-engg
Committed by
Aniket
Mar 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
integration tests for 0.4.24 contracts updated
parent
56805303
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
980 additions
and
943 deletions
+980
-943
lowLevelCalls.ts
...x-analyzer/src/solidity-analyzer/modules/lowLevelCalls.ts
+15
-1
noReturn.ts
remix-analyzer/src/solidity-analyzer/modules/noReturn.ts
+2
-2
staticAnalysisCommon.ts
...zer/src/solidity-analyzer/modules/staticAnalysisCommon.ts
+43
-32
staticAnalysisCommon-test.ts
remix-analyzer/test/analysis/staticAnalysisCommon-test.ts
+13
-1
staticAnalysisIntegration-test-0.4.24.ts
...er/test/analysis/staticAnalysisIntegration-test-0.4.24.ts
+879
-879
staticAnalysisIssues-test-0.4.24.ts
...nalyzer/test/analysis/staticAnalysisIssues-test-0.4.24.ts
+28
-28
No files found.
remix-analyzer/src/solidity-analyzer/modules/lowLevelCalls.ts
View file @
2cb6cf1c
import
{
default
as
category
}
from
'./categories'
import
{
isLLCall
,
isLLDelegatecall
,
import
{
isLLCall
,
isLLDelegatecall
,
isLLCallcode
,
isLLCall04
,
isLLDelegatecall04
,
isLLSend04
,
isLLSend
,
lowLevelCallTypes
}
from
'./staticAnalysisCommon'
import
{
default
as
algorithm
}
from
'./algorithmCategories'
import
{
AnalyzerModule
,
ModuleAlgorithm
,
ModuleCategory
,
ReportObj
,
CompilationResult
,
MemberAccessAstNode
}
from
'./../../types'
...
...
@@ -26,6 +26,14 @@ export default class lowLevelCalls implements AnalyzerModule {
this
.
llcNodes
.
push
({
node
:
node
,
type
:
lowLevelCallTypes
.
DELEGATECALL
})
}
else
if
(
isLLSend
(
node
))
{
this
.
llcNodes
.
push
({
node
:
node
,
type
:
lowLevelCallTypes
.
SEND
})
}
else
if
(
isLLDelegatecall04
(
node
))
{
this
.
llcNodes
.
push
({
node
:
node
,
type
:
lowLevelCallTypes
.
DELEGATECALL
})
}
else
if
(
isLLSend04
(
node
))
{
this
.
llcNodes
.
push
({
node
:
node
,
type
:
lowLevelCallTypes
.
SEND
})
}
else
if
(
isLLCall04
(
node
))
{
this
.
llcNodes
.
push
({
node
:
node
,
type
:
lowLevelCallTypes
.
CALL
})
}
else
if
(
isLLCallcode
(
node
))
{
this
.
llcNodes
.
push
({
node
:
node
,
type
:
lowLevelCallTypes
.
CALLCODE
})
}
}
...
...
@@ -41,6 +49,12 @@ export default class lowLevelCalls implements AnalyzerModule {
morehref
=
'http://solidity.readthedocs.io/en/develop/control-structures.html?#external-function-calls'
// http://solidity.readthedocs.io/en/develop/frequently-asked-questions.html?#why-is-the-low-level-function-call-less-favorable-than-instantiating-a-contract-with-a-variable-contractb-b-and-executing-its-functions-b-dosomething
break
case
lowLevelCallTypes
.
CALLCODE
:
text
=
`use of "callcode": the use of low level "callcode" should be avoided whenever possible.
External code that is called can change the state of the calling contract and send ether from the caller's balance.
If this is wanted behaviour use the Solidity library feature if possible.`
morehref
=
'http://solidity.readthedocs.io/en/develop/contracts.html#libraries'
break
case
lowLevelCallTypes
.
DELEGATECALL
:
text
=
`use of "delegatecall": the use of low level "delegatecall" should be avoided whenever possible.
External code that is called can change the state of the calling contract and send ether from the caller's balance.
...
...
remix-analyzer/src/solidity-analyzer/modules/noReturn.ts
View file @
2cb6cf1c
...
...
@@ -26,12 +26,12 @@ export default class noReturn implements AnalyzerModule {
if
(
this
.
hasNamedAndUnnamedReturns
(
func
))
{
warnings
.
push
({
warning
:
`
${
funcName
}
: Mixing of named and unnamed return parameters is not advised.`
,
location
:
func
[
'src'
]
location
:
func
.
node
[
'src'
]
})
}
else
if
(
this
.
shouldReturn
(
func
)
&&
!
(
this
.
hasReturnStatement
(
func
)
||
(
this
.
hasNamedReturns
(
func
)
&&
this
.
hasAssignToAllNamedReturns
(
func
))))
{
warnings
.
push
({
warning
:
`
${
funcName
}
: Defines a return type but never explicitly returns a value.`
,
location
:
func
[
'src'
]
location
:
func
.
node
[
'src'
]
})
}
})
...
...
remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.ts
View file @
2cb6cf1c
...
...
@@ -81,7 +81,9 @@ const basicRegex = {
const
basicFunctionTypes
=
{
SEND
:
buildFunctionSignature
([
basicTypes
.
UINT
],
[
basicTypes
.
BOOL
],
false
),
'CALL-0.4'
:
buildFunctionSignature
([],
[
basicTypes
.
BOOL
],
true
),
CALL
:
buildFunctionSignature
([
basicTypes
.
BYTES_MEM
],
[
basicTypes
.
BOOL
,
basicTypes
.
BYTES_MEM
],
true
),
'DELEGATECALL-0.4'
:
buildFunctionSignature
([],
[
basicTypes
.
BOOL
],
false
),
DELEGATECALL
:
buildFunctionSignature
([
basicTypes
.
BYTES_MEM
],
[
basicTypes
.
BOOL
,
basicTypes
.
BYTES_MEM
],
false
),
TRANSFER
:
buildFunctionSignature
([
basicTypes
.
UINT
],
[],
false
)
}
...
...
@@ -107,7 +109,10 @@ const builtinFunctions = {
}
const
lowLevelCallTypes
=
{
'CALL-0.4'
:
{
ident
:
'call'
,
type
:
basicFunctionTypes
[
'CALL-0.4'
]
},
CALL
:
{
ident
:
'call'
,
type
:
basicFunctionTypes
.
CALL
},
CALLCODE
:
{
ident
:
'callcode'
,
type
:
basicFunctionTypes
[
'CALL-0.4'
]
},
'DELEGATECALL-0.4'
:
{
ident
:
'delegatecall'
,
type
:
basicFunctionTypes
[
'DELEGATECALL-0.4'
]
},
DELEGATECALL
:
{
ident
:
'delegatecall'
,
type
:
basicFunctionTypes
.
DELEGATECALL
},
SEND
:
{
ident
:
'send'
,
type
:
basicFunctionTypes
.
SEND
},
TRANSFER
:
{
ident
:
'transfer'
,
type
:
basicFunctionTypes
.
TRANSFER
}
...
...
@@ -626,8 +631,10 @@ function isStorageVariableDeclaration (node: VariableDeclarationAstNode): boolea
function
isInteraction
(
node
:
FunctionCallAstNode
):
boolean
{
// console.log('Inside isInteraction----------', node)
return
isLLCall
(
node
.
expression
)
||
isLLSend
(
node
.
expression
)
||
isExternalDirectCall
(
node
)
||
isTransfer
(
node
.
expression
)
||
// to cover case of address.call.value.gas , See: inheritance.sol
(
node
.
expression
&&
node
.
expression
.
expression
&&
isLLCall
(
node
.
expression
.
expression
))
isLLCall04
(
node
.
expression
)
||
isLLSend04
(
node
.
expression
)
||
// to cover case of address.call.value.gas , See: inheritance.sol
(
node
.
expression
&&
node
.
expression
.
expression
&&
isLLCall
(
node
.
expression
.
expression
))
||
(
node
.
expression
&&
node
.
expression
.
expression
&&
isLLCall04
(
node
.
expression
.
expression
))
}
/**
...
...
@@ -685,7 +692,7 @@ function isPayableFunction (node: FunctionDefinitionAstNode): boolean {
* @return {bool}
*/
function
isConstructor
(
node
:
FunctionDefinitionAstNode
):
boolean
{
return
node
.
kind
===
"constructor"
return
node
.
kind
===
"constructor"
// ||
}
/**
...
...
@@ -879,22 +886,26 @@ function isLocalCall (node: FunctionCallAstNode): boolean {
function
isLowLevelCall
(
node
:
MemberAccessAstNode
):
boolean
{
return
isLLCall
(
node
)
||
isLLDelegatecall
(
node
)
||
isLLSend
(
node
)
isLLSend
(
node
)
||
isLLSend04
(
node
)
||
isLLCallcode
(
node
)
||
isLLCall04
(
node
)
||
isLLDelegatecall04
(
node
)
}
/**
* True if low level send (solidity
>=
0.5)
* True if low level send (solidity
<
0.5)
* @node {ASTNode} some AstNode
* @return {bool}
*/
// function isLLSend050
(node: MemberAccessAstNode): boolean {
//
return isMemberAccess(node,
//
exactMatch(util.escapeRegExp(lowLevelCallTypes.SEND.type)),
// undefined, exactMatch(basicTypes.PAYABLE_
ADDRESS), exactMatch(lowLevelCallTypes.SEND.ident))
//
}
function
isLLSend04
(
node
:
MemberAccessAstNode
):
boolean
{
return
isMemberAccess
(
node
,
exactMatch
(
util
.
escapeRegExp
(
lowLevelCallTypes
.
SEND
.
type
)),
undefined
,
exactMatch
(
basicTypes
.
ADDRESS
),
exactMatch
(
lowLevelCallTypes
.
SEND
.
ident
))
}
/**
* True if low level send (solidity
<
0.5)
* True if low level send (solidity
>=
0.5)
* @node {ASTNode} some AstNode
* @return {bool}
*/
...
...
@@ -910,9 +921,6 @@ function isLLSend (node: MemberAccessAstNode): boolean {
* @return {bool}
*/
function
isLLCall
(
node
:
MemberAccessAstNode
):
boolean
{
// if(node && node.nodeType === 'MemberAccess' && node.memberName !== 'call' &&
// node.expression && node.expression.nodeType && nodeType(node.expression, exactMatch(nodeTypes.MEMBERACCESS)))
// node = node.expression;
return
isMemberAccess
(
node
,
exactMatch
(
util
.
escapeRegExp
(
lowLevelCallTypes
.
CALL
.
type
)),
undefined
,
exactMatch
(
basicTypes
.
ADDRESS
),
exactMatch
(
lowLevelCallTypes
.
CALL
.
ident
))
||
...
...
@@ -922,26 +930,26 @@ function isLLCall (node: MemberAccessAstNode): boolean {
}
/**
* True if low level payable call (solidity
>=
0.5)
* True if low level payable call (solidity
<
0.5)
* @node {ASTNode} some AstNode
* @return {bool}
*/
// function isLLCall050
(node: MemberAccessAstNode): boolean {
//
return isMemberAccess(node,
// exactMatch(util.escapeRegExp(lowLevelCallTypes['CALL-v0.5
'].type)),
// undefined, exactMatch(basicTypes.PAYABLE_ADDRESS), exactMatch(lowLevelCallTypes['CALL-v0.5
'].ident))
//
}
function
isLLCall04
(
node
:
MemberAccessAstNode
):
boolean
{
return
isMemberAccess
(
node
,
exactMatch
(
util
.
escapeRegExp
(
lowLevelCallTypes
[
'CALL-0.4
'
].
type
)),
undefined
,
exactMatch
(
basicTypes
.
ADDRESS
),
exactMatch
(
lowLevelCallTypes
[
'CALL-0.4
'
].
ident
))
}
/**
* True if low level callcode
* @node {ASTNode} some AstNode
* @return {bool}
*/
//
function isLLCallcode (node: MemberAccessAstNode): boolean {
//
return isMemberAccess(node,
//
exactMatch(util.escapeRegExp(lowLevelCallTypes.CALLCODE.type)),
//
undefined, exactMatch(basicTypes.ADDRESS), exactMatch(lowLevelCallTypes.CALLCODE.ident))
//
}
function
isLLCallcode
(
node
:
MemberAccessAstNode
):
boolean
{
return
isMemberAccess
(
node
,
exactMatch
(
util
.
escapeRegExp
(
lowLevelCallTypes
.
CALLCODE
.
type
)),
undefined
,
exactMatch
(
basicTypes
.
ADDRESS
),
exactMatch
(
lowLevelCallTypes
.
CALLCODE
.
ident
))
}
/**
* True if low level delegatecall
...
...
@@ -955,15 +963,15 @@ function isLLDelegatecall (node: MemberAccessAstNode): boolean {
}
/**
* True if low level delegatecall (solidity
>=
0.5)
* True if low level delegatecall (solidity
<
0.5)
* @node {ASTNode} some AstNode
* @return {bool}
*/
// function isLLDelegatecall050
(node: MemberAccessAstNode): boolean {
//
return isMemberAccess(node,
// exactMatch(util.escapeRegExp(lowLevelCallTypes.DELEGATECALL
.type)),
// undefined, matches(basicTypes.PAYABLE_ADDRESS, basicTypes.ADDRESS), exactMatch(lowLevelCallTypes.DELEGATECALL
.ident))
//
}
function
isLLDelegatecall04
(
node
:
MemberAccessAstNode
):
boolean
{
return
isMemberAccess
(
node
,
exactMatch
(
util
.
escapeRegExp
(
lowLevelCallTypes
[
'DELEGATECALL-0.4'
]
.
type
)),
undefined
,
matches
(
basicTypes
.
PAYABLE_ADDRESS
,
basicTypes
.
ADDRESS
),
exactMatch
(
lowLevelCallTypes
[
'DELEGATECALL-0.4'
]
.
ident
))
}
/**
* True if transfer call
...
...
@@ -1186,9 +1194,12 @@ export {
isTransfer
,
isLowLevelCall
,
isLLCall
,
// isLLCallcode as isLowLevelCallcodeInst,
isLLCall04
,
isLLCallcode
,
isLLDelegatecall
,
isLLDelegatecall04
,
isLLSend
,
isLLSend04
,
isExternalDirectCall
,
isFullyImplementedContract
,
isLibrary
,
...
...
remix-analyzer/test/analysis/staticAnalysisCommon-test.ts
View file @
2cb6cf1c
...
...
@@ -10,7 +10,7 @@ function escapeRegExp (str) {
}
test
(
'staticAnalysisCommon.helpers.buildFunctionSignature'
,
function
(
t
)
{
t
.
plan
(
8
)
t
.
plan
(
11
)
t
.
equal
(
common
.
helpers
.
buildFunctionSignature
([
common
.
basicTypes
.
UINT
,
common
.
basicTypes
.
ADDRESS
],
[
common
.
basicTypes
.
BOOL
],
false
),
'function (uint256,address) returns (bool)'
,
...
...
@@ -36,6 +36,14 @@ test('staticAnalysisCommon.helpers.buildFunctionSignature', function (t) {
'function (bytes memory) payable returns (bool,bytes memory)'
,
'check fixed call type'
)
t
.
equal
(
common
.
lowLevelCallTypes
[
'CALL-0.4'
].
type
,
'function () payable returns (bool)'
,
'check fixed call type for version before 0.5.0'
)
t
.
equal
(
common
.
lowLevelCallTypes
.
CALLCODE
.
type
,
'function () payable returns (bool)'
,
'check fixed callcode type'
)
t
.
equal
(
common
.
lowLevelCallTypes
.
SEND
.
type
,
'function (uint256) returns (bool)'
,
'check fixed send type'
)
...
...
@@ -43,6 +51,10 @@ test('staticAnalysisCommon.helpers.buildFunctionSignature', function (t) {
t
.
equal
(
common
.
lowLevelCallTypes
.
DELEGATECALL
.
type
,
'function (bytes memory) returns (bool,bytes memory)'
,
'check fixed call type'
)
t
.
equal
(
common
.
lowLevelCallTypes
[
'DELEGATECALL-0.4'
].
type
,
'function () returns (bool)'
,
'check fixed call type'
)
})
// #################### Node Identification Primitives
...
...
remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.4.24.ts
View file @
2cb6cf1c
//
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.4.24')
//
const compiler = requireNPMmodule('solc@0.4.24')
//
const {compilerInput } = helpers.compiler
//
const folder = 'solidity-v0.4.24'
//
const 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',
//
'selfdestruct.sol',
//
'deleteDynamicArray.sol',
//
'deleteFromDynamicArray.sol',
//
'blockLevelCompare.sol',
//
'intDivisionTruncate.sol',
//
'ERC20.sol',
//
'stringBytesLength.sol',
//
'etherTransferInLoop.sol',
//
'forLoopIteratesOverDynamicArray.sol'
//
]
//
var testFileAsts = {}
//
testFiles.forEach((fileName) => {
//
const content = readFileSync(join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
//
testFileAsts[fileName] = JSON.parse(compiler.compileStandardWrapper(compilerInput(content)))
//
})
//
test('Integration test thisLocal.js', function (t) {
//
t.plan(testFiles.length)
// var
module = require('../../dist/src/solidity-analyzer/modules/thisLocal').default
// 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,
//
'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
//
}
//
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)
// var
module = require('../../dist/src/solidity-analyzer/modules/checksEffectsInteraction').default
// 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,
//
'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
//
}
//
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)
// var
module = require('../../dist/src/solidity-analyzer/modules/constantFunctions').default
// var
lengthCheck = {
//
'KingOfTheEtherThrone.sol': 0,
//
'assembly.sol': 0,
//
'ballot.sol': 0,
//
'ballot_reentrant.sol': 0,
//
'ballot_withoutWarnings.sol': 0,
//
'cross_contract.sol': 1,
//
'inheritance.sol': 0,
//
'modifier1.sol': 1,
//
'modifier2.sol': 0,
//
'notReentrant.sol': 0,
//
'structReentrant.sol': 1,
//
'thisLocal.sol': 1,
//
'globals.sol': 0,
//
'library.sol': 3,
//
'transfer.sol': 0,
//
'ctor.sol': 0,
//
'forgottenReturn.sol': 0,
//
'selfdestruct.sol': 1,
//
'deleteDynamicArray.sol': 0,
//
'deleteFromDynamicArray.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) => {
//
t.equal(report.length, lengthCheck[file], `${file} has right amount of constant warnings`)
//
})
//
})
//
test('Integration test inlineAssembly.js', function (t) {
//
t.plan(testFiles.length)
// var
module = require('../../dist/src/solidity-analyzer/modules/inlineAssembly').default
// 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,
//
'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
//
}
//
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)
// var
module = require('../../dist/src/solidity-analyzer/modules/txOrigin').default
// 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,
//
'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
//
}
//
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)
// var
module = require('../../dist/src/solidity-analyzer/modules/gasCosts').default
// 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,
//
'thisLocal.sol': 1,
//
'globals.sol': 1,
//
'library.sol': 1,
//
'transfer.sol': 1,
//
'ctor.sol': 0,
//
'forgottenReturn.sol': 3,
//
'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
//
}
//
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)
// var
module = require('../../dist/src/solidity-analyzer/modules/similarVariableNames').default
// var
lengthCheck = {
//
'KingOfTheEtherThrone.sol': 0,
//
'assembly.sol': 0,
//
'ballot.sol': 2,
//
'ballot_reentrant.sol': 3,
//
'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,
//
'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
//
}
//
runModuleOnFiles(module, t, (file, report) => {
//
t.equal(report.length, lengthCheck[file], `${file} has right amount of similarVariableNames warnings`)
//
})
//
})
//
test('Integration test blockTimestamp.js', function (t) {
//
t.plan(testFiles.length)
// var
module = require('../../dist/src/solidity-analyzer/modules/blockTimestamp').default
// 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,
//
'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
//
}
//
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)
// var
module = require('../../dist/src/solidity-analyzer/modules/lowLevelCalls').default
// 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,
//
'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
//
}
//
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)
// var
module = require('../../dist/src/solidity-analyzer/modules/blockBlockhash').default
// 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,
//
'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
//
}
//
runModuleOnFiles(module, t, (file, report) => {
//
t.equal(report.length, lengthCheck[file], `${file} has right amount of blockBlockhash warnings`)
//
})
//
})
//
test('Integration test noReturn.js', function (t) {
//
t.plan(testFiles.length)
// var
module = require('../../dist/src/solidity-analyzer/modules/noReturn').default
// 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,
//
'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
//
}
//
runModuleOnFiles(module, t, (file, report) => {
//
t.equal(report.length, lengthCheck[file], `${file} has right amount of noReturn warnings`)
//
})
//
})
//
test('Integration test selfdestruct.js', function (t) {
//
t.plan(testFiles.length)
// var
module = require('../../dist/src/solidity-analyzer/modules/selfdestruct').default
// 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': 2,
//
'library.sol': 0,
//
'transfer.sol': 0,
//
'ctor.sol': 0,
//
'forgottenReturn.sol': 0,
//
'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
//
}
//
runModuleOnFiles(module, t, (file, report) => {
//
t.equal(report.length, lengthCheck[file], `${file} has right amount of selfdestruct warnings`)
//
})
//
})
//
test('Integration test guardConditions.js', function (t) {
//
t.plan(testFiles.length)
// var
module = require('../../dist/src/solidity-analyzer/modules/guardConditions').default
// 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,
//
'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
//
}
//
runModuleOnFiles(module, t, (file, report) => {
//
t.equal(report.length, lengthCheck[file], `${file} has right amount of guardCondition warnings`)
//
})
//
})
//
test('Integration test deleteDynamicArrays.js', function (t) {
//
t.plan(testFiles.length)
// var
module = require('../../dist/src/solidity-analyzer/modules/deleteDynamicArrays').default
// 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': 2,
//
'deleteFromDynamicArray.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) => {
//
t.equal(report.length, lengthCheck[file], `${file} has right amount of deleteDynamicArrays warnings`)
//
})
//
})
//
test('Integration test deleteFromDynamicArray.js', function (t) {
//
t.plan(testFiles.length)
// var
module = require('../../dist/src/solidity-analyzer/modules/deleteFromDynamicArray').default
// 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,
//
'etherTransferInLoop.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)
// var
module = require('../../dist/src/solidity-analyzer/modules/assignAndCompare').default
// 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': 0,
//
'blockLevelCompare.sol': 8,
//
'intDivisionTruncate.sol': 0,
//
'ERC20.sol': 0,
//
'stringBytesLength.sol': 0,
//
'etherTransferInLoop.sol': 0,
//
'forLoopIteratesOverDynamicArray.sol': 0
//
}
//
runModuleOnFiles(module, t, (file, report) => {
//
t.equal(report.length, lengthCheck[file], `${file} has right amount of assignAndCompare warnings`)
//
})
//
})
//
test('Integration test intDivisionTruncate.js', function (t) {
//
t.plan(testFiles.length)
// var
module = require('../../dist/src/solidity-analyzer/modules/intDivisionTruncate').default
// 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': 0,
//
'blockLevelCompare.sol': 0,
//
'intDivisionTruncate.sol': 2,
//
'ERC20.sol': 0,
//
'stringBytesLength.sol': 0,
//
'etherTransferInLoop.sol': 0,
//
'forLoopIteratesOverDynamicArray.sol': 0
//
}
//
runModuleOnFiles(module, t, (file, report) => {
//
t.equal(report.length, lengthCheck[file], `${file} has right amount of intDivisionTruncate warnings`)
//
})
//
})
//
test('Integration test erc20Decimal.js', function (t) {
//
t.plan(testFiles.length)
// var
module = require('../../dist/src/solidity-analyzer/modules/erc20Decimals').default
// 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': 0,
//
'blockLevelCompare.sol': 0,
//
'intDivisionTruncate.sol': 0,
//
'ERC20.sol': 1,
//
'stringBytesLength.sol': 0,
//
'etherTransferInLoop.sol': 0,
//
'forLoopIteratesOverDynamicArray.sol': 0
//
}
//
runModuleOnFiles(module, t, (file, report) => {
//
t.equal(report.length, lengthCheck[file], `${file} has right amount of erc20Decimals warnings`)
//
})
//
})
//
test('Integration test stringBytesLength.js', function (t) {
//
t.plan(testFiles.length)
// var
module = require('../../dist/src/solidity-analyzer/modules/stringBytesLength').default
// 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': 0,
//
'blockLevelCompare.sol': 0,
//
'intDivisionTruncate.sol': 0,
//
'ERC20.sol': 0,
//
'stringBytesLength.sol': 1,
//
'etherTransferInLoop.sol': 0,
//
'forLoopIteratesOverDynamicArray.sol': 0
//
}
//
runModuleOnFiles(module, t, (file, report) => {
//
t.equal(report.length, lengthCheck[file], `${file} has right amount of stringBytesLength warnings`)
//
})
//
})
//
test('Integration test etherTransferInLoop.js', function (t) {
//
t.plan(testFiles.length)
// var
module = require('../../dist/src/solidity-analyzer/modules/etherTransferInLoop').default
// 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': 0,
//
'blockLevelCompare.sol': 0,
//
'intDivisionTruncate.sol': 0,
//
'ERC20.sol': 0,
//
'stringBytesLength.sol': 0,
//
'etherTransferInLoop.sol': 3,
//
'forLoopIteratesOverDynamicArray.sol': 0
//
}
//
runModuleOnFiles(module, t, (file, report) => {
//
t.equal(report.length, lengthCheck[file], `${file} has right amount of etherTransferInLoop warnings`)
//
})
//
})
//
test('Integration test forLoopIteratesOverDynamicArray.js', function (t) {
//
t.plan(testFiles.length)
// var
module = require('../../dist/src/solidity-analyzer/modules/forLoopIteratesOverDynamicArray').default
// 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,
//
'etherTransferInLoop.sol': 0,
//
'forLoopIteratesOverDynamicArray.sol': 2
//
}
//
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()
//
testFiles.forEach((fileName) => {
//
statRunner.runWithModuleList(testFileAsts[fileName], [{ name: new Module().name, mod: new Module() }], (reports) => {
//
let report = reports[0].report
//
if (report.some((x) => x['warning'].includes('INTERNAL ERROR'))) {
//
t.comment('Error while executing Module: ' + JSON.stringify(report))
//
}
//
cb(fileName, report)
//
})
//
})
//
}
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.4.24'
)
const
compiler
=
requireNPMmodule
(
'solc@0.4.24'
)
const
{
compilerInput
}
=
helpers
.
compiler
const
folder
=
'solidity-v0.4.24'
const
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'
,
'selfdestruct.sol'
,
'deleteDynamicArray.sol'
,
'deleteFromDynamicArray.sol'
,
'blockLevelCompare.sol'
,
'intDivisionTruncate.sol'
,
'ERC20.sol'
,
'stringBytesLength.sol'
,
'etherTransferInLoop.sol'
,
'forLoopIteratesOverDynamicArray.sol'
]
// Latest AST was introduced in solidity v0.4.12
var
testFileAsts
=
{}
testFiles
.
forEach
((
fileName
)
=>
{
const
content
=
readFileSync
(
join
(
__dirname
,
'test-contracts/'
+
folder
,
fileName
),
'utf8'
)
testFileAsts
[
fileName
]
=
JSON
.
parse
(
compiler
.
compileStandardWrapper
(
compilerInput
(
content
)))
})
test
(
'Integration test thisLocal.js'
,
function
(
t
)
{
t
.
plan
(
testFiles
.
length
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/thisLocal'
).
default
const
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
,
'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
}
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
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/checksEffectsInteraction'
).
default
const
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
,
'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
}
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
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/constantFunctions'
).
default
const
lengthCheck
=
{
'KingOfTheEtherThrone.sol'
:
0
,
'assembly.sol'
:
0
,
'ballot.sol'
:
0
,
'ballot_reentrant.sol'
:
0
,
'ballot_withoutWarnings.sol'
:
0
,
'cross_contract.sol'
:
1
,
'inheritance.sol'
:
0
,
'modifier1.sol'
:
1
,
'modifier2.sol'
:
0
,
'notReentrant.sol'
:
0
,
'structReentrant.sol'
:
1
,
'thisLocal.sol'
:
1
,
'globals.sol'
:
0
,
'library.sol'
:
3
,
'transfer.sol'
:
0
,
'ctor.sol'
:
0
,
'forgottenReturn.sol'
:
0
,
'selfdestruct.sol'
:
1
,
'deleteDynamicArray.sol'
:
0
,
'deleteFromDynamicArray.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
)
=>
{
t
.
equal
(
report
.
length
,
lengthCheck
[
file
],
`
${
file
}
has right amount of constant warnings`
)
})
})
test
(
'Integration test inlineAssembly.js'
,
function
(
t
)
{
t
.
plan
(
testFiles
.
length
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/inlineAssembly'
).
default
const
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
,
'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
}
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
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/txOrigin'
).
default
const
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
,
'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
}
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
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/gasCosts'
).
default
const
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
,
'thisLocal.sol'
:
1
,
'globals.sol'
:
1
,
'library.sol'
:
1
,
'transfer.sol'
:
1
,
'ctor.sol'
:
0
,
'forgottenReturn.sol'
:
3
,
'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
}
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
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/similarVariableNames'
).
default
const
lengthCheck
=
{
'KingOfTheEtherThrone.sol'
:
0
,
'assembly.sol'
:
0
,
'ballot.sol'
:
2
,
'ballot_reentrant.sol'
:
3
,
'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
,
'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
}
runModuleOnFiles
(
module
,
t
,
(
file
,
report
)
=>
{
t
.
equal
(
report
.
length
,
lengthCheck
[
file
],
`
${
file
}
has right amount of similarVariableNames warnings`
)
})
})
test
(
'Integration test blockTimestamp.js'
,
function
(
t
)
{
t
.
plan
(
testFiles
.
length
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/blockTimestamp'
).
default
const
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
,
'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
}
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
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/lowLevelCalls'
).
default
const
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
,
'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
}
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
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/blockBlockhash'
).
default
const
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
,
'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
}
runModuleOnFiles
(
module
,
t
,
(
file
,
report
)
=>
{
t
.
equal
(
report
.
length
,
lengthCheck
[
file
],
`
${
file
}
has right amount of blockBlockhash warnings`
)
})
})
test
(
'Integration test noReturn.js'
,
function
(
t
)
{
t
.
plan
(
testFiles
.
length
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/noReturn'
).
default
const
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
,
'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
}
runModuleOnFiles
(
module
,
t
,
(
file
,
report
)
=>
{
t
.
equal
(
report
.
length
,
lengthCheck
[
file
],
`
${
file
}
has right amount of noReturn warnings`
)
})
})
test
(
'Integration test selfdestruct.js'
,
function
(
t
)
{
t
.
plan
(
testFiles
.
length
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/selfdestruct'
).
default
const
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'
:
2
,
'library.sol'
:
0
,
'transfer.sol'
:
0
,
'ctor.sol'
:
0
,
'forgottenReturn.sol'
:
0
,
'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
}
runModuleOnFiles
(
module
,
t
,
(
file
,
report
)
=>
{
t
.
equal
(
report
.
length
,
lengthCheck
[
file
],
`
${
file
}
has right amount of selfdestruct warnings`
)
})
})
test
(
'Integration test guardConditions.js'
,
function
(
t
)
{
t
.
plan
(
testFiles
.
length
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/guardConditions'
).
default
const
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
,
'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
}
runModuleOnFiles
(
module
,
t
,
(
file
,
report
)
=>
{
t
.
equal
(
report
.
length
,
lengthCheck
[
file
],
`
${
file
}
has right amount of guardCondition warnings`
)
})
})
test
(
'Integration test deleteDynamicArrays.js'
,
function
(
t
)
{
t
.
plan
(
testFiles
.
length
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/deleteDynamicArrays'
).
default
const
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'
:
2
,
'deleteFromDynamicArray.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
)
=>
{
t
.
equal
(
report
.
length
,
lengthCheck
[
file
],
`
${
file
}
has right amount of deleteDynamicArrays warnings`
)
})
})
test
(
'Integration test deleteFromDynamicArray.js'
,
function
(
t
)
{
t
.
plan
(
testFiles
.
length
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/deleteFromDynamicArray'
).
default
const
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
,
'etherTransferInLoop.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
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/assignAndCompare'
).
default
const
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'
:
0
,
'blockLevelCompare.sol'
:
8
,
'intDivisionTruncate.sol'
:
0
,
'ERC20.sol'
:
0
,
'stringBytesLength.sol'
:
0
,
'etherTransferInLoop.sol'
:
0
,
'forLoopIteratesOverDynamicArray.sol'
:
0
}
runModuleOnFiles
(
module
,
t
,
(
file
,
report
)
=>
{
t
.
equal
(
report
.
length
,
lengthCheck
[
file
],
`
${
file
}
has right amount of assignAndCompare warnings`
)
})
})
test
(
'Integration test intDivisionTruncate.js'
,
function
(
t
)
{
t
.
plan
(
testFiles
.
length
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/intDivisionTruncate'
).
default
const
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'
:
0
,
'blockLevelCompare.sol'
:
0
,
'intDivisionTruncate.sol'
:
2
,
'ERC20.sol'
:
0
,
'stringBytesLength.sol'
:
0
,
'etherTransferInLoop.sol'
:
0
,
'forLoopIteratesOverDynamicArray.sol'
:
0
}
runModuleOnFiles
(
module
,
t
,
(
file
,
report
)
=>
{
t
.
equal
(
report
.
length
,
lengthCheck
[
file
],
`
${
file
}
has right amount of intDivisionTruncate warnings`
)
})
})
test
(
'Integration test erc20Decimal.js'
,
function
(
t
)
{
t
.
plan
(
testFiles
.
length
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/erc20Decimals'
).
default
const
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'
:
0
,
'blockLevelCompare.sol'
:
0
,
'intDivisionTruncate.sol'
:
0
,
'ERC20.sol'
:
1
,
'stringBytesLength.sol'
:
0
,
'etherTransferInLoop.sol'
:
0
,
'forLoopIteratesOverDynamicArray.sol'
:
0
}
runModuleOnFiles
(
module
,
t
,
(
file
,
report
)
=>
{
t
.
equal
(
report
.
length
,
lengthCheck
[
file
],
`
${
file
}
has right amount of erc20Decimals warnings`
)
})
})
test
(
'Integration test stringBytesLength.js'
,
function
(
t
)
{
t
.
plan
(
testFiles
.
length
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/stringBytesLength'
).
default
const
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'
:
0
,
'blockLevelCompare.sol'
:
0
,
'intDivisionTruncate.sol'
:
0
,
'ERC20.sol'
:
0
,
'stringBytesLength.sol'
:
1
,
'etherTransferInLoop.sol'
:
0
,
'forLoopIteratesOverDynamicArray.sol'
:
0
}
runModuleOnFiles
(
module
,
t
,
(
file
,
report
)
=>
{
t
.
equal
(
report
.
length
,
lengthCheck
[
file
],
`
${
file
}
has right amount of stringBytesLength warnings`
)
})
})
test
(
'Integration test etherTransferInLoop.js'
,
function
(
t
)
{
t
.
plan
(
testFiles
.
length
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/etherTransferInLoop'
).
default
const
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'
:
0
,
'blockLevelCompare.sol'
:
0
,
'intDivisionTruncate.sol'
:
0
,
'ERC20.sol'
:
0
,
'stringBytesLength.sol'
:
0
,
'etherTransferInLoop.sol'
:
3
,
'forLoopIteratesOverDynamicArray.sol'
:
0
}
runModuleOnFiles
(
module
,
t
,
(
file
,
report
)
=>
{
t
.
equal
(
report
.
length
,
lengthCheck
[
file
],
`
${
file
}
has right amount of etherTransferInLoop warnings`
)
})
})
test
(
'Integration test forLoopIteratesOverDynamicArray.js'
,
function
(
t
)
{
t
.
plan
(
testFiles
.
length
)
const
module
=
require
(
'../../dist/src/solidity-analyzer/modules/forLoopIteratesOverDynamicArray'
).
default
const
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
,
'etherTransferInLoop.sol'
:
0
,
'forLoopIteratesOverDynamicArray.sol'
:
2
}
runModuleOnFiles
(
module
,
t
,
(
file
,
report
)
=>
{
t
.
equal
(
report
.
length
,
lengthCheck
[
file
],
`
${
file
}
has right amount of forLoopIteratesOverDynamicArray warnings`
)
})
})
// #################### Helpers
function
runModuleOnFiles
(
Module
,
t
,
cb
)
{
const
statRunner
=
new
StatRunner
()
testFiles
.
forEach
((
fileName
)
=>
{
statRunner
.
runWithModuleList
(
testFileAsts
[
fileName
],
[{
name
:
new
Module
().
name
,
mod
:
new
Module
()
}],
(
reports
)
=>
{
let
report
=
reports
[
0
].
report
if
(
report
.
some
((
x
)
=>
x
[
'warning'
].
includes
(
'INTERNAL ERROR'
)))
{
t
.
comment
(
'Error while executing Module: '
+
JSON
.
stringify
(
report
))
}
cb
(
fileName
,
report
)
})
})
}
remix-analyzer/test/analysis/staticAnalysisIssues-test-0.4.24.ts
View file @
2cb6cf1c
//
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.4.24')
//
const compiler = requireNPMmodule('solc@0.4.24')
// const {compilerInput
} = helpers.compiler
//
const folder = 'solidity-v0.4.24'
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.4.24'
)
const
compiler
=
requireNPMmodule
(
'solc@0.4.24'
)
const
{
compilerInput
}
=
helpers
.
compiler
const
folder
=
'solidity-v0.4.24'
//
function compile (fileName) {
//
const content = readFileSync(join(__dirname, 'test-contracts/' + folder, fileName), 'utf8')
//
return JSON.parse(compiler.compileStandardWrapper(compilerInput(content)))
//
}
function
compile
(
fileName
)
{
const
content
=
readFileSync
(
join
(
__dirname
,
'test-contracts/'
+
folder
,
fileName
),
'utf8'
)
return
JSON
.
parse
(
compiler
.
compileStandardWrapper
(
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'
))
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment