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
0e561c94
Commit
0e561c94
authored
Feb 09, 2019
by
Omkara
Committed by
0mkar
Mar 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update contract to sol v0.5.0, add more typings, make runTestFiles work
parent
368f9113
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
60 deletions
+73
-60
simple_storage.sol
remix-tests/examples/simple_storage.sol
+0
-1
package.json
remix-tests/package.json
+2
-0
run.ts
remix-tests/src/run.ts
+5
-7
runTestFiles.ts
remix-tests/src/runTestFiles.ts
+43
-33
runTestSources.ts
remix-tests/src/runTestSources.ts
+2
-3
testRunner.ts
remix-tests/src/testRunner.ts
+21
-16
No files found.
remix-tests/examples/simple_storage.sol
View file @
0e561c94
...
...
@@ -13,5 +13,4 @@ contract SimpleStorage {
function get() public view returns (uint retVal) {
return storedData;
}
}
remix-tests/package.json
View file @
0e561c94
...
...
@@ -38,6 +38,7 @@
"homepage"
:
"https://github.com/ethereum/remix-tests#readme"
,
"dependencies"
:
{
"@types/async"
:
"^2.4.0"
,
"@types/colors"
:
"^1.2.1"
,
"@types/web3"
:
"^1.0.18"
,
"async"
:
"^2.6.0"
,
"change-case"
:
"^3.0.1"
,
...
...
@@ -54,6 +55,7 @@
"yo-yoify"
:
"latest"
},
"devDependencies"
:
{
"@types/commander"
:
"^2.12.2"
,
"@types/mocha"
:
"^5.2.5"
,
"@types/node"
:
"^10.12.21"
,
"babel-preset-es2017"
:
"^6.24.1"
,
...
...
remix-tests/src/run.ts
View file @
0e561c94
#!/usr/bin/env ts-node
const
commander
=
require
(
'commander'
)
import
commander
from
'commander'
import
Web3
from
'web3'
import
{
runTestFiles
}
from
'./runTestFiles'
import
fs
from
'./fileSystem'
const
Provider
=
require
(
'remix-simulator'
).
Provider
import
Log
=
require
(
'./logger'
)
import
Log
from
'./logger'
const
logger
=
new
Log
()
const
log
=
logger
.
logger
require
(
'colors'
)
import
colors
from
'colors'
// parse verbosity
function
mapVerbosity
(
v
)
{
function
mapVerbosity
(
v
:
number
)
{
const
levels
=
{
0
:
'error'
,
1
:
'warn'
,
...
...
@@ -39,7 +37,7 @@ commander
.
option
(
'-v, --verbose <level>'
,
'run with verbosity'
,
mapVerbosity
)
.
action
(
function
(
filename
)
{
// Console message
console
.
log
(
(
'
\
n
\
t👁 :: Running remix-tests - Unit testing for solidity :: 👁
\
t
\
n'
),
'color: white'
)
console
.
log
(
colors
.
white
(
'
\
n
\
t👁
\
t:: Running remix-tests - Unit testing for solidity ::
\
t👁
\
n'
)
)
// set logger verbosity
if
(
commander
.
verbose
)
{
logger
.
setVerbosity
(
commander
.
verbose
)
...
...
remix-tests/src/runTestFiles.ts
View file @
0e561c94
import
async
=
require
(
'async'
)
import
path
=
require
(
'path'
)
import
async
from
'async'
import
fs
from
'./fileSystem'
import
{
runTest
}
from
'./testRunner'
require
(
'colors'
)
import
{
runTest
,
TestResultInterface
,
ResultsInterface
}
from
'./testRunner'
import
colors
from
'colors'
import
Web3
from
'web3'
import
Compiler
=
require
(
'./compiler'
)
import
Deployer
=
require
(
'./deployer'
)
import
{
compileFileOrFiles
}
from
'./compiler'
import
{
deployAll
}
from
'./deployer'
export
function
runTestFiles
(
filepath
,
isDirectory
,
web3
,
opts
=
{}
)
{
export
function
runTestFiles
(
filepath
:
string
,
isDirectory
:
boolean
,
web3
:
Web3
,
opts
?:
object
)
{
opts
=
opts
||
{}
const
{
Signale
}
=
require
(
'signale'
)
// signale configuration
...
...
@@ -33,38 +33,42 @@ export function runTestFiles(filepath, isDirectory, web3, opts = {}) {
const
signale
=
new
Signale
(
options
)
let
accounts
=
opts
[
'accounts'
]
||
null
async
.
waterfall
([
function
getAccountList
(
next
)
{
function
getAccountList
(
next
:
Function
)
{
if
(
accounts
)
return
next
(
null
)
web3
.
eth
.
getAccounts
((
_err
,
_accounts
)
=>
{
web3
.
eth
.
getAccounts
((
_err
:
Error
|
null
|
undefined
,
_accounts
)
=>
{
accounts
=
_accounts
next
(
null
)
})
},
function
compile
(
next
)
{
Compiler
.
compileFileOrFiles
(
filepath
,
isDirectory
,
{
accounts
},
next
)
function
compile
(
next
:
Function
)
{
compileFileOrFiles
(
filepath
,
isDirectory
,
{
accounts
},
next
)
},
function
deployAllContracts
(
compilationResult
,
next
)
{
Deployer
.
deployAll
(
compilationResult
,
web3
,
function
(
err
,
contracts
)
{
function
deployAllContracts
(
compilationResult
,
next
:
Function
)
{
deployAll
(
compilationResult
,
web3
,
(
err
,
contracts
)
=>
{
if
(
err
)
{
next
(
err
)
}
next
(
null
,
compilationResult
,
contracts
)
})
},
function
determineTestContractsToRun
(
compilationResult
,
contracts
,
next
)
{
function
determineTestContractsToRun
(
compilationResult
,
contracts
,
next
:
Function
)
{
let
contractsToTest
:
any
[]
=
[]
let
contractsToTestDetails
:
any
[]
=
[]
const
gatherContractsFrom
=
(
filename
)
=>
{
const
gatherContractsFrom
=
function
(
filename
:
string
)
{
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
])
})
try
{
Object
.
keys
(
compilationResult
[
filename
]).
forEach
(
contractName
=>
{
contractsToTest
.
push
(
contractName
)
contractsToTestDetails
.
push
(
compilationResult
[
filename
][
contractName
])
})
}
catch
(
e
)
{
console
.
error
(
e
)
}
}
if
(
isDirectory
)
{
fs
.
walkSync
(
filepath
,
foundpath
=>
{
fs
.
walkSync
(
filepath
,
(
foundpath
:
string
)
=>
{
gatherContractsFrom
(
foundpath
)
})
}
else
{
...
...
@@ -72,13 +76,14 @@ export function runTestFiles(filepath, isDirectory, web3, opts = {}) {
}
next
(
null
,
contractsToTest
,
contractsToTestDetails
,
contracts
)
},
function
runTests
(
contractsToTest
,
contractsToTestDetails
,
contracts
,
next
)
{
let
totalPassing
=
0
let
totalFailing
=
0
let
totalTime
=
0
function
runTests
(
contractsToTest
,
contractsToTestDetails
,
contracts
,
next
:
Function
)
{
let
totalPassing
:
number
=
0
let
totalFailing
:
number
=
0
let
totalTime
:
number
=
0
let
errors
:
any
[]
=
[]
var
testCallback
=
function
(
result
)
{
var
_testCallback
=
function
(
err
:
Error
|
null
|
undefined
,
result
:
TestResultInterface
)
{
if
(
err
)
throw
err
;
if
(
result
.
type
===
'contract'
)
{
signale
.
name
(
result
.
value
.
white
)
}
else
if
(
result
.
type
===
'testPass'
)
{
...
...
@@ -88,20 +93,25 @@ export function runTestFiles(filepath, isDirectory, web3, opts = {}) {
errors
.
push
(
result
)
}
}
var
resultsCallback
=
function
(
_err
,
result
,
cb
)
{
var
_resultsCallback
=
(
_err
:
Error
|
null
|
undefined
,
result
:
ResultsInterface
,
cb
)
=>
{
totalPassing
+=
result
.
passingNum
totalFailing
+=
result
.
failureNum
totalTime
+=
result
.
timePassed
cb
()
}
async
.
eachOfLimit
(
contractsToTest
,
1
,
(
contractName
,
index
,
cb
)
=>
{
runTest
(
contractName
,
contracts
(
contractName
),
contractsToTestDetails
[
index
],
{
accounts
},
testCallback
,
(
err
,
result
)
=>
{
async
.
eachOfLimit
(
contractsToTest
,
1
,
(
contractName
:
string
,
index
,
cb
)
=>
{
try
{
runTest
(
contractName
,
contracts
[
contractName
],
contractsToTestDetails
[
index
],
{
accounts
},
_testCallback
,
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
log
(
err
)
return
cb
(
err
)
}
resultsCallback
(
null
,
result
,
cb
)
_
resultsCallback
(
null
,
result
,
cb
)
})
}
catch
(
e
)
{
console
.
error
(
e
)
}
},
function
(
err
)
{
if
(
err
)
{
return
next
(
err
)
...
...
@@ -109,23 +119,23 @@ export function runTestFiles(filepath, isDirectory, web3, opts = {}) {
console
.
log
(
'
\
n'
)
if
(
totalPassing
>
0
)
{
console
.
log
(
(
'%c '
+
totalPassing
+
' passing '
)
+
(
'%c('
+
totalTime
+
's)'
),
'color: green'
,
'color: grey'
)
console
.
log
(
colors
.
green
(
totalPassing
+
' passing '
)
+
colors
.
grey
(
'('
+
totalTime
+
's)'
)
)
}
if
(
totalFailing
>
0
)
{
console
.
log
(
(
'%c '
+
totalFailing
+
' failing'
),
'color: red'
)
console
.
log
(
colors
.
red
(
totalFailing
+
' failing'
)
)
}
console
.
log
(
''
)
errors
.
forEach
((
error
,
index
)
=>
{
console
.
log
(
' '
+
(
index
+
1
)
+
') '
+
error
.
context
+
' '
+
error
.
value
)
console
.
log
(
''
)
console
.
log
(
(
'%c
\
t error: '
+
error
.
errMsg
),
'color: red'
)
console
.
log
(
colors
.
red
(
'
\
t error: '
+
error
.
errMsg
)
)
})
console
.
log
(
''
)
next
()
})
}
],
function
()
{
],
()
=>
{
})
}
remix-tests/src/runTestSources.ts
View file @
0e561c94
...
...
@@ -37,7 +37,7 @@ export function runTestSources(contractSources, testCallback, resultCallback, fi
compileContractSources
(
contractSources
,
importFileCb
,
opts
,
next
)
},
function
deployAllContracts
(
compilationResult
,
next
)
{
deployAll
(
compilationResult
,
web3
,
function
(
err
,
contracts
)
{
deployAll
(
compilationResult
,
web3
,
(
err
,
contracts
)
=>
{
if
(
err
)
{
next
(
err
)
}
...
...
@@ -58,10 +58,9 @@ export function runTestSources(contractSources, testCallback, resultCallback, fi
contractsToTest
.
push
(
contractName
)
})
}
next
(
null
,
contractsToTest
,
contractsToTestDetails
,
contracts
)
},
function
runTests
(
contractsToTest
,
contractsToTestDetails
,
contracts
,
next
)
{
function
runTests
(
contractsToTest
,
contractsToTestDetails
,
contracts
,
next
)
{
let
totalPassing
=
0
let
totalFailing
=
0
let
totalTime
=
0
...
...
remix-tests/src/testRunner.ts
View file @
0e561c94
...
...
@@ -2,7 +2,7 @@ import async from 'async'
import
*
as
changeCase
from
'change-case'
import
Web3
from
'web3'
interface
CbReturn
Interface
{
export
interface
TestResult
Interface
{
type
:
string
,
value
:
any
,
time
?:
number
,
...
...
@@ -10,13 +10,19 @@ interface CbReturnInterface {
errMsg
?:
string
filename
?:
string
}
interface
RunListInterface
{
name
:
string
,
type
:
string
,
constant
:
boolean
,
signature
?:
any
}
export
interface
ResultsInterface
{
passingNum
:
number
,
failureNum
:
number
,
timePassed
:
number
}
export
interface
TestCbInterface
{
(
error
:
Error
|
null
|
undefined
,
result
?:
CbReturn
Interface
)
:
void
;
(
error
:
Error
|
null
|
undefined
,
result
:
TestResult
Interface
)
:
void
;
}
export
interface
ResultCbInterface
{
(
error
:
Error
|
null
|
undefined
,
result
:
ResultsInterface
)
:
void
;
...
...
@@ -47,27 +53,27 @@ function getTestFunctions (jsonInterface) {
return
jsonInterface
.
filter
((
x
)
=>
specialFunctions
.
indexOf
(
x
.
name
)
<
0
&&
x
.
type
===
'function'
)
}
function
createRunList
(
jsonInterface
)
{
function
createRunList
(
jsonInterface
):
RunListInterface
[]
{
let
availableFunctions
=
getAvailableFunctions
(
jsonInterface
)
let
testFunctions
=
getTestFunctions
(
jsonInterface
)
let
runList
:
any
[]
=
[]
let
runList
:
RunListInterface
[]
=
[]
if
(
availableFunctions
.
indexOf
(
'beforeAll'
)
>=
0
)
{
runList
.
push
({
name
:
'beforeAll'
,
type
:
'internal'
,
constant
:
false
})
runList
.
push
({
name
:
'beforeAll'
,
type
:
'internal'
,
constant
:
false
})
}
for
(
let
func
of
testFunctions
)
{
if
(
availableFunctions
.
indexOf
(
'beforeEach'
)
>=
0
)
{
runList
.
push
({
name
:
'beforeEach'
,
type
:
'internal'
,
constant
:
false
})
runList
.
push
({
name
:
'beforeEach'
,
type
:
'internal'
,
constant
:
false
})
}
runList
.
push
({
name
:
func
.
name
,
signature
:
func
.
signature
,
type
:
'test'
,
constant
:
func
.
constant
})
runList
.
push
({
name
:
func
.
name
,
signature
:
func
.
signature
,
type
:
'test'
,
constant
:
func
.
constant
})
if
(
availableFunctions
.
indexOf
(
'afterEach'
)
>=
0
)
{
runList
.
push
({
name
:
'afterEach'
,
type
:
'internal'
,
constant
:
false
})
runList
.
push
({
name
:
'afterEach'
,
type
:
'internal'
,
constant
:
false
})
}
}
if
(
availableFunctions
.
indexOf
(
'afterAll'
)
>=
0
)
{
runList
.
push
({
name
:
'afterAll'
,
type
:
'internal'
,
constant
:
false
})
runList
.
push
({
name
:
'afterAll'
,
type
:
'internal'
,
constant
:
false
})
}
return
runList
...
...
@@ -90,7 +96,7 @@ export function runTest(testName, testObject: any, contractDetails: any, opts: a
signale
.
warn
(
'e.g: the following code won
\'
t work in the current context:'
)
signale
.
warn
(
'TestsAccounts.getAccount('
+
opts
.
accounts
.
length
+
')'
)
}
const
resp
:
CbReturn
Interface
=
{
const
resp
:
TestResult
Interface
=
{
type
:
'contract'
,
value
:
testName
,
filename
:
testObject
.
filename
...
...
@@ -113,7 +119,7 @@ export function runTest(testName, testObject: any, contractDetails: any, opts: a
method
.
call
(
sendParams
).
then
((
result
)
=>
{
let
time
=
Math
.
ceil
((
Date
.
now
()
-
startTime
)
/
1000.0
)
if
(
result
)
{
const
resp
:
CbReturn
Interface
=
{
const
resp
:
TestResult
Interface
=
{
type
:
'testPass'
,
value
:
changeCase
.
sentenceCase
(
func
.
name
),
time
:
time
,
...
...
@@ -123,7 +129,7 @@ export function runTest(testName, testObject: any, contractDetails: any, opts: a
passingNum
+=
1
timePassed
+=
time
}
else
{
const
resp
:
CbReturn
Interface
=
{
const
resp
:
TestResult
Interface
=
{
type
:
'testFailure'
,
value
:
changeCase
.
sentenceCase
(
func
.
name
),
time
:
time
,
...
...
@@ -147,7 +153,7 @@ export function runTest(testName, testObject: any, contractDetails: any, opts: a
if
(
event
.
raw
.
topics
.
indexOf
(
topic
)
>=
0
)
{
var
testEvent
=
web3
.
eth
.
abi
.
decodeParameters
([
'bool'
,
'string'
],
event
.
raw
.
data
)
if
(
!
testEvent
[
0
])
{
const
resp
:
CbReturn
Interface
=
{
const
resp
:
TestResult
Interface
=
{
type
:
'testFailure'
,
value
:
changeCase
.
sentenceCase
(
func
.
name
),
time
:
time
,
...
...
@@ -163,7 +169,7 @@ export function runTest(testName, testObject: any, contractDetails: any, opts: a
}
if
(
testPassed
)
{
const
resp
:
CbReturn
Interface
=
{
const
resp
:
TestResult
Interface
=
{
type
:
'testPass'
,
value
:
changeCase
.
sentenceCase
(
func
.
name
),
time
:
time
,
...
...
@@ -175,8 +181,7 @@ export function runTest(testName, testObject: any, contractDetails: any, opts: a
return
next
()
}
catch
(
err
)
{
console
.
log
(
'error!'
)
console
.
dir
(
err
)
console
.
error
(
err
)
return
next
(
err
)
}
}).
on
(
'error'
,
function
(
err
:
Error
|
null
|
undefined
)
{
...
...
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