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
5e4e96e1
Commit
5e4e96e1
authored
Nov 20, 2018
by
0mkar
Committed by
yann300
Jan 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix conflicts
parent
4a18d355
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
289 deletions
+42
-289
compiler.js
remix-tests/src/compiler.js
+39
-45
index.js
remix-tests/src/index.js
+3
-244
No files found.
remix-tests/src/compiler.js
View file @
5e4e96e1
...
@@ -37,55 +37,49 @@ function compileFileOrFiles (filename, isDirectory, opts, cb) {
...
@@ -37,55 +37,49 @@ function compileFileOrFiles (filename, isDirectory, opts, cb) {
// TODO: for now assumes filepath dir contains all tests, later all this
// TODO: for now assumes filepath dir contains all tests, later all this
// should be replaced with remix's & browser solidity compiler code
// should be replaced with remix's & browser solidity compiler code
// https://github.com/mikeal/node-utils/blob/master/file/lib/main.js
// This logic is wrong
fs
.
walkSync
=
function
(
start
,
callback
)
{
// We should only look into current file if a full file name with path is given
fs
.
readdirSync
(
start
).
forEach
(
name
=>
{
// We should only walk through directory if a directory name is passed
if
(
name
===
'node_modules'
)
{
try
{
return
// hack
filepath
=
(
isDirectory
?
filename
:
path
.
dirname
(
filename
))
// walkSync only if it is a directory
fs
.
walkSync
(
filepath
,
foundpath
=>
{
// only process .sol files
if
(
foundpath
.
split
(
'.'
).
pop
()
===
'sol'
)
{
let
c
=
fs
.
readFileSync
(
foundpath
).
toString
()
const
s
=
/^
(
import
)\s[
'"
](
remix_tests.sol|tests.sol
)[
'"
]
;/gm
if
(
foundpath
.
indexOf
(
'_test.sol'
)
>
0
&&
c
.
regexIndexOf
(
s
)
<
0
)
{
c
=
c
.
replace
(
/
(
pragma solidity
\^?\d
+
\.\d
+
\.\d
+;
)
/
,
'$1
\
nimport
\'
remix_tests.sol
\'
;'
)
}
sources
[
foundpath
]
=
{
content
:
c
}
}
}
var
abspath
=
path
.
join
(
start
,
name
)
})
if
(
fs
.
statSync
(
abspath
).
isDirectory
())
{
}
catch
(
e
)
{
fs
.
walkSync
(
abspath
,
callback
)
throw
e
}
else
{
}
finally
{
callback
(
abspath
)
async
.
waterfall
([
function
loadCompiler
(
next
)
{
compiler
=
new
RemixCompiler
()
compiler
.
onInternalCompilerLoaded
()
// compiler.event.register('compilerLoaded', this, function (version) {
next
()
// });
},
function
doCompilation
(
next
)
{
compiler
.
event
.
register
(
'compilationFinished'
,
this
,
function
(
success
,
data
,
source
)
{
next
(
null
,
data
)
})
compiler
.
compile
(
sources
,
false
)
}
],
function
(
err
,
result
)
{
let
errors
=
(
result
.
errors
||
[]).
filter
((
e
)
=>
e
.
type
===
'Error'
||
e
.
severity
===
'error'
)
if
(
errors
.
length
>
0
)
{
if
(
!
isBrowser
)
require
(
'signale'
).
fatal
(
errors
)
return
cb
(
new
Error
(
'errors compiling'
))
}
}
cb
(
err
,
result
.
contracts
)
})
})
}
}
fs
.
walkSync
(
filepath
,
foundpath
=>
{
// only process .sol files
if
(
foundpath
.
split
(
'.'
).
pop
()
===
'sol'
)
{
let
c
=
fs
.
readFileSync
(
foundpath
).
toString
()
const
s
=
/^
(
import
)\s[
'"
](
remix_tests.sol|tests.sol
)[
'"
]
;/gm
if
(
foundpath
.
indexOf
(
'_test.sol'
)
>
0
&&
c
.
regexIndexOf
(
s
)
<
0
)
{
c
=
c
.
replace
(
/
(
pragma solidity
\^?\d
+
\.\d
+
\.\d
+;
)
/
,
'$1
\
nimport
\'
remix_tests.sol
\'
;'
)
}
sources
[
foundpath
]
=
{
content
:
c
}
}
})
async
.
waterfall
([
function
loadCompiler
(
next
)
{
compiler
=
new
RemixCompiler
()
compiler
.
onInternalCompilerLoaded
()
// compiler.event.register('compilerLoaded', this, function (version) {
next
()
// });
},
function
doCompilation
(
next
)
{
compiler
.
event
.
register
(
'compilationFinished'
,
this
,
function
(
success
,
data
,
source
)
{
next
(
null
,
data
)
})
compiler
.
compile
(
sources
,
false
)
}
],
function
(
err
,
result
)
{
let
errors
=
(
result
.
errors
||
[]).
filter
((
e
)
=>
e
.
type
===
'Error'
||
e
.
severity
===
'error'
)
if
(
errors
.
length
>
0
)
{
if
(
!
isBrowser
)
require
(
'signale'
).
fatal
(
errors
)
return
cb
(
new
Error
(
'errors compiling'
))
}
cb
(
err
,
result
.
contracts
)
})
}
}
function
compileContractSources
(
sources
,
importFileCb
,
opts
,
cb
)
{
function
compileContractSources
(
sources
,
importFileCb
,
opts
,
cb
)
{
...
...
remix-tests/src/index.js
View file @
5e4e96e1
const
async
=
require
(
'async'
)
const
runTestFiles
=
require
(
'./runTestFiles.js'
)
const
path
=
require
(
'path'
)
const
runTestSources
=
require
(
'./runTestSources.js'
)
const
fs
=
require
(
'fs'
)
const
TestRunner
=
require
(
'./testRunner.js'
)
require
(
'colors'
)
let
Compiler
=
require
(
'./compiler.js'
)
let
Deployer
=
require
(
'./deployer.js'
)
let
TestRunner
=
require
(
'./testRunner.js'
)
const
Web3
=
require
(
'web3'
)
const
Provider
=
require
(
'remix-simulator'
).
Provider
var
createWeb3Provider
=
function
()
{
let
web3
=
new
Web3
()
web3
.
setProvider
(
new
Provider
())
return
web3
}
var
runTestSources
=
function
(
contractSources
,
testCallback
,
resultCallback
,
finalCallback
,
importFileCb
,
opts
)
{
opts
=
opts
||
{}
let
web3
=
opts
.
web3
||
createWeb3Provider
()
let
accounts
=
opts
.
accounts
||
null
async
.
waterfall
([
function
getAccountList
(
next
)
{
if
(
accounts
)
return
next
()
web3
.
eth
.
getAccounts
((
_err
,
_accounts
)
=>
{
accounts
=
_accounts
next
()
})
},
function
compile
(
next
)
{
Compiler
.
compileContractSources
(
contractSources
,
importFileCb
,
{
accounts
},
next
)
},
function
deployAllContracts
(
compilationResult
,
next
)
{
Deployer
.
deployAll
(
compilationResult
,
web3
,
function
(
err
,
contracts
)
{
if
(
err
)
{
next
(
err
)
}
next
(
null
,
compilationResult
,
contracts
)
})
},
function
determineTestContractsToRun
(
compilationResult
,
contracts
,
next
)
{
let
contractsToTest
=
[]
let
contractsToTestDetails
=
[]
for
(
let
filename
in
compilationResult
)
{
if
(
filename
.
indexOf
(
'_test.sol'
)
<
0
)
{
continue
}
Object
.
keys
(
compilationResult
[
filename
]).
forEach
(
contractName
=>
{
contractsToTestDetails
.
push
(
compilationResult
[
filename
][
contractName
])
contractsToTest
.
push
(
contractName
)
})
}
next
(
null
,
contractsToTest
,
contractsToTestDetails
,
contracts
)
},
function
runTests
(
contractsToTest
,
contractsToTestDetails
,
contracts
,
next
)
{
let
totalPassing
=
0
let
totalFailing
=
0
let
totalTime
=
0
let
errors
=
[]
var
_testCallback
=
function
(
result
)
{
if
(
result
.
type
===
'testFailure'
)
{
errors
.
push
(
result
)
}
testCallback
(
result
)
}
var
_resultsCallback
=
function
(
_err
,
result
,
cb
)
{
resultCallback
(
_err
,
result
,
()
=>
{})
totalPassing
+=
result
.
passingNum
totalFailing
+=
result
.
failureNum
totalTime
+=
result
.
timePassed
cb
()
}
async
.
eachOfLimit
(
contractsToTest
,
1
,
(
contractName
,
index
,
cb
)
=>
{
TestRunner
.
runTest
(
contractName
,
contracts
[
contractName
],
contractsToTestDetails
[
index
],
{
accounts
},
_testCallback
,
(
err
,
result
)
=>
{
if
(
err
)
{
return
cb
(
err
)
}
_resultsCallback
(
null
,
result
,
cb
)
})
},
function
(
err
,
_results
)
{
if
(
err
)
{
return
next
(
err
)
}
let
finalResults
=
{}
finalResults
.
totalPassing
=
totalPassing
||
0
finalResults
.
totalFailing
=
totalFailing
||
0
finalResults
.
totalTime
=
totalTime
||
0
finalResults
.
errors
=
[]
errors
.
forEach
((
error
,
_index
)
=>
{
finalResults
.
errors
.
push
({
context
:
error
.
context
,
value
:
error
.
value
,
message
:
error
.
errMsg
})
})
next
(
null
,
finalResults
)
})
}
],
finalCallback
)
}
var
runTestFiles
=
function
(
filepath
,
isDirectory
,
web3
,
opts
)
{
opts
=
opts
||
{}
const
{
Signale
}
=
require
(
'signale'
)
// signale configuration
const
options
=
{
types
:
{
result
:
{
badge
:
'
\
t✓'
,
label
:
''
,
color
:
'greenBright'
},
name
:
{
badge
:
'
\
n
\
t◼'
,
label
:
''
,
color
:
'white'
},
error
:
{
badge
:
'
\
t✘'
,
label
:
''
,
color
:
'redBright'
}
}
}
const
signale
=
new
Signale
(
options
)
let
accounts
=
opts
.
accounts
||
null
async
.
waterfall
([
function
getAccountList
(
next
)
{
if
(
accounts
)
return
next
(
null
)
web3
.
eth
.
getAccounts
((
_err
,
_accounts
)
=>
{
accounts
=
_accounts
next
(
null
)
})
},
function
compile
(
next
)
{
Compiler
.
compileFileOrFiles
(
filepath
,
isDirectory
,
{
accounts
},
next
)
},
function
deployAllContracts
(
compilationResult
,
next
)
{
Deployer
.
deployAll
(
compilationResult
,
web3
,
function
(
err
,
contracts
)
{
if
(
err
)
{
next
(
err
)
}
next
(
null
,
compilationResult
,
contracts
)
})
},
function
determineTestContractsToRun
(
compilationResult
,
contracts
,
next
)
{
let
contractsToTest
=
[]
let
contractsToTestDetails
=
[]
const
gatherContractsFrom
=
(
filename
)
=>
{
if
(
filename
.
indexOf
(
'_test.sol'
)
<
0
)
{
return
}
Object
.
keys
(
compilationResult
[
path
.
basename
(
filename
)]).
forEach
(
contractName
=>
{
contractsToTest
.
push
(
contractName
)
contractsToTestDetails
.
push
(
compilationResult
[
path
.
basename
(
filename
)][
contractName
])
})
}
if
(
isDirectory
)
{
fs
.
walkSync
=
function
(
start
,
callback
)
{
fs
.
readdirSync
(
start
).
forEach
(
name
=>
{
if
(
name
===
'node_modules'
)
{
return
// hack
}
var
abspath
=
path
.
join
(
start
,
name
)
if
(
fs
.
statSync
(
abspath
).
isDirectory
())
{
fs
.
walkSync
(
abspath
,
callback
)
}
else
{
callback
(
abspath
)
}
})
}
fs
.
walkSync
(
filepath
,
foundpath
=>
{
gatherContractsFrom
(
foundpath
)
})
}
else
{
gatherContractsFrom
(
filepath
)
}
next
(
null
,
contractsToTest
,
contractsToTestDetails
,
contracts
)
},
function
runTests
(
contractsToTest
,
contractsToTestDetails
,
contracts
,
next
)
{
let
totalPassing
=
0
let
totalFailing
=
0
let
totalTime
=
0
let
errors
=
[]
var
testCallback
=
function
(
result
)
{
if
(
result
.
type
===
'contract'
)
{
signale
.
name
(
result
.
value
.
white
)
}
else
if
(
result
.
type
===
'testPass'
)
{
signale
.
result
(
result
.
value
)
}
else
if
(
result
.
type
===
'testFailure'
)
{
signale
.
result
(
result
.
value
.
red
)
errors
.
push
(
result
)
}
}
var
resultsCallback
=
function
(
_err
,
result
,
cb
)
{
totalPassing
+=
result
.
passingNum
totalFailing
+=
result
.
failureNum
totalTime
+=
result
.
timePassed
cb
()
}
async
.
eachOfLimit
(
contractsToTest
,
1
,
(
contractName
,
index
,
cb
)
=>
{
TestRunner
.
runTest
(
contractName
,
contracts
[
contractName
],
contractsToTestDetails
[
index
],
{
accounts
},
testCallback
,
(
err
,
result
)
=>
{
if
(
err
)
{
return
cb
(
err
)
}
resultsCallback
(
null
,
result
,
cb
)
})
},
function
(
err
,
_results
)
{
if
(
err
)
{
return
next
(
err
)
}
console
.
log
(
'
\
n'
)
if
(
totalPassing
>
0
)
{
console
.
log
((
' '
+
totalPassing
+
' passing '
).
green
+
(
'('
+
totalTime
+
's)'
).
grey
)
}
if
(
totalFailing
>
0
)
{
console
.
log
((
' '
+
totalFailing
+
' failing'
).
red
)
}
console
.
log
(
''
)
errors
.
forEach
((
error
,
index
)
=>
{
console
.
log
(
' '
+
(
index
+
1
)
+
') '
+
error
.
context
+
' '
+
error
.
value
)
console
.
log
(
''
)
console
.
log
((
'
\
t error: '
+
error
.
errMsg
).
red
)
})
console
.
log
(
''
)
next
()
})
}
],
function
()
{
})
}
module
.
exports
=
{
module
.
exports
=
{
runTestFiles
:
runTestFiles
,
runTestFiles
:
runTestFiles
,
...
...
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