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
9114122e
Commit
9114122e
authored
Nov 15, 2019
by
aniket-engg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
types & suggested changes
parent
8471682c
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
248 additions
and
24 deletions
+248
-24
runTestFiles.ts
remix-tests/src/runTestFiles.ts
+9
-9
runTestSources.ts
remix-tests/src/runTestSources.ts
+10
-10
testRunner.ts
remix-tests/src/testRunner.ts
+5
-3
types.ts
remix-tests/src/types.ts
+223
-0
testRunner.ts
remix-tests/tests/testRunner.ts
+1
-2
No files found.
remix-tests/src/runTestFiles.ts
View file @
9114122e
import
async
from
'async'
import
fs
from
'./fileSystem'
import
{
runTest
}
from
'./testRunner'
import
{
TestResultInterface
,
ResultsInterface
}
from
'./types'
import
{
TestResultInterface
,
ResultsInterface
,
compilationInterface
,
ASTInterface
}
from
'./types'
import
colors
from
'colors'
import
Web3
=
require
(
'web3'
)
...
...
@@ -18,7 +18,7 @@ import { deployAll } from './deployer'
export
function
runTestFiles
(
filepath
:
string
,
isDirectory
:
boolean
,
web3
:
Web3
,
opts
?:
object
)
{
opts
=
opts
||
{}
le
t
sourceASTs
:
any
=
{}
cons
t
sourceASTs
:
any
=
{}
const
{
Signale
}
=
require
(
'signale'
)
// signale configuration
const
options
=
{
...
...
@@ -53,10 +53,9 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3,
function
compile
(
next
:
Function
)
{
compileFileOrFiles
(
filepath
,
isDirectory
,
{
accounts
},
next
)
},
function
deployAllContracts
(
compilationResult
,
asts
,
next
:
Function
)
{
function
deployAllContracts
(
compilationResult
:
compilationInterface
,
asts
:
ASTInterface
,
next
:
Function
)
{
// Extract AST of test contract file source
for
(
const
filename
in
asts
)
{
for
(
const
filename
in
asts
)
{
if
(
filename
.
includes
(
'_test.sol'
))
sourceASTs
[
filename
]
=
asts
[
filename
].
ast
}
...
...
@@ -67,8 +66,8 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3,
next
(
null
,
compilationResult
,
contracts
)
})
},
function
determineTestContractsToRun
(
compilationResult
,
contracts
,
next
:
Function
)
{
let
contractsToTest
:
any
[]
=
[]
function
determineTestContractsToRun
(
compilationResult
:
compilationInterface
,
contracts
:
any
,
next
:
Function
)
{
let
contractsToTest
:
string
[]
=
[]
let
contractsToTestDetails
:
any
[]
=
[]
const
gatherContractsFrom
=
function
(
filename
:
string
)
{
if
(
filename
.
indexOf
(
'_test.sol'
)
<
0
)
{
...
...
@@ -92,7 +91,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3,
}
next
(
null
,
contractsToTest
,
contractsToTestDetails
,
contracts
)
},
function
runTests
(
contractsToTest
,
contractsToTestDetails
,
contracts
,
next
:
Function
)
{
function
runTests
(
contractsToTest
:
string
[],
contractsToTestDetails
:
any
[],
contracts
:
any
,
next
:
Function
)
{
let
totalPassing
:
number
=
0
let
totalFailing
:
number
=
0
let
totalTime
:
number
=
0
...
...
@@ -118,7 +117,8 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3,
async
.
eachOfLimit
(
contractsToTest
,
1
,
(
contractName
:
string
,
index
,
cb
)
=>
{
try
{
runTest
(
contractName
,
contracts
[
contractName
],
contractsToTestDetails
[
index
],
sourceASTs
[
contracts
[
contractName
][
'filename'
]],
{
accounts
},
_testCallback
,
(
err
,
result
)
=>
{
const
fileAST
=
sourceASTs
[
contracts
[
contractName
][
'filename'
]]
runTest
(
contractName
,
contracts
[
contractName
],
contractsToTestDetails
[
index
],
fileAST
,
{
accounts
},
_testCallback
,
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
log
(
err
)
return
cb
(
err
)
...
...
remix-tests/src/runTestSources.ts
View file @
9114122e
...
...
@@ -8,7 +8,7 @@ import { TestResultInterface } from './types'
import
Web3
=
require
(
'web3'
)
import
{
Provider
}
from
'remix-simulator'
import
{
FinalResult
}
from
'./types'
import
{
FinalResult
,
SrcIfc
,
compilationInterface
,
ASTInterface
}
from
'./types'
const
createWeb3Provider
=
async
function
()
{
let
web3
=
new
Web3
()
...
...
@@ -29,9 +29,9 @@ const createWeb3Provider = async function () {
* @param importFileCb Import file callback
* @param opts Options
*/
export
async
function
runTestSources
(
contractSources
,
versionUrl
,
usingWorker
,
testCallback
,
resultCallback
,
finalCallback
,
importFileCb
,
opts
)
{
export
async
function
runTestSources
(
contractSources
:
SrcIfc
,
versionUrl
:
string
,
usingWorker
:
boolean
,
testCallback
:
Function
,
resultCallback
:
Function
,
finalCallback
:
any
,
importFileCb
:
Function
,
opts
:
any
)
{
opts
=
opts
||
{}
le
t
sourceASTs
:
any
=
{}
cons
t
sourceASTs
:
any
=
{}
let
web3
=
opts
.
web3
||
await
createWeb3Provider
()
let
accounts
=
opts
.
accounts
||
null
async
.
waterfall
([
...
...
@@ -45,9 +45,8 @@ export async function runTestSources(contractSources, versionUrl, usingWorker, t
function
compile
(
next
)
{
compileContractSources
(
contractSources
,
versionUrl
,
usingWorker
,
importFileCb
,
{
accounts
},
next
)
},
function
deployAllContracts
(
compilationResult
,
asts
,
next
)
{
for
(
const
filename
in
asts
)
{
function
deployAllContracts
(
compilationResult
:
compilationInterface
,
asts
:
ASTInterface
,
next
)
{
for
(
const
filename
in
asts
)
{
if
(
filename
.
includes
(
'_test.sol'
))
sourceASTs
[
filename
]
=
asts
[
filename
].
ast
}
...
...
@@ -59,8 +58,8 @@ export async function runTestSources(contractSources, versionUrl, usingWorker, t
next
(
null
,
compilationResult
,
contracts
)
})
},
function
determineTestContractsToRun
(
compilationResult
,
contracts
,
next
)
{
let
contractsToTest
:
any
[]
=
[]
function
determineTestContractsToRun
(
compilationResult
:
compilationInterface
,
contracts
:
any
,
next
)
{
let
contractsToTest
:
string
[]
=
[]
let
contractsToTestDetails
:
any
[]
=
[]
for
(
let
filename
in
compilationResult
)
{
...
...
@@ -74,7 +73,7 @@ export async function runTestSources(contractSources, versionUrl, usingWorker, t
}
next
(
null
,
contractsToTest
,
contractsToTestDetails
,
contracts
)
},
function
runTests
(
contractsToTest
,
contractsToTestDetails
,
contracts
,
next
)
{
function
runTests
(
contractsToTest
:
string
[],
contractsToTestDetails
:
any
[],
contracts
:
any
,
next
)
{
let
totalPassing
=
0
let
totalFailing
=
0
let
totalTime
=
0
...
...
@@ -96,7 +95,8 @@ export async function runTestSources(contractSources, versionUrl, usingWorker, t
}
async
.
eachOfLimit
(
contractsToTest
,
1
,
(
contractName
:
string
,
index
:
string
|
number
,
cb
:
ErrorCallback
)
=>
{
runTest
(
contractName
,
contracts
[
contractName
],
contractsToTestDetails
[
index
],
sourceASTs
[
contracts
[
contractName
][
'filename'
]],
{
accounts
},
_testCallback
,
(
err
,
result
)
=>
{
const
fileAST
=
sourceASTs
[
contracts
[
contractName
][
'filename'
]]
runTest
(
contractName
,
contracts
[
contractName
],
contractsToTestDetails
[
index
],
fileAST
,
{
accounts
},
_testCallback
,
(
err
,
result
)
=>
{
if
(
err
)
{
return
cb
(
err
)
}
...
...
remix-tests/src/testRunner.ts
View file @
9114122e
...
...
@@ -39,11 +39,13 @@ function getAvailableFunctions (fileAST: any, testContractName: string) {
*/
function
getTestFunctionsInterface
(
jsonInterface
:
any
,
funcList
:
string
[])
{
le
t
functionsInterface
:
any
[]
=
[]
cons
t
functionsInterface
:
any
[]
=
[]
const
specialFunctions
=
[
'beforeAll'
,
'beforeEach'
,
'afterAll'
,
'afterEach'
]
for
(
const
func
of
funcList
){
if
(
!
specialFunctions
.
includes
(
func
))
functionsInterface
.
push
(
jsonInterface
.
find
(
node
=>
node
.
type
===
'function'
&&
node
.
name
===
func
))
if
(
!
specialFunctions
.
includes
(
func
))
{
const
funcInterface
=
jsonInterface
.
find
(
node
=>
node
.
type
===
'function'
&&
node
.
name
===
func
)
functionsInterface
.
push
(
funcInterface
)
}
}
return
functionsInterface
}
...
...
remix-tests/src/types.ts
View file @
9114122e
...
...
@@ -37,3 +37,226 @@ export interface TestCbInterface {
export
interface
ResultCbInterface
{
(
error
:
Error
|
null
|
undefined
,
result
:
ResultsInterface
)
:
void
;
}
/** sources object with name of the file and content **/
////////////
// SOURCE //
////////////
export
interface
CompilationSource
{
/** Identifier of the source (used in source maps) */
id
:
number
/** The AST object */
ast
:
AstNode
/** The legacy AST object */
legacyAST
:
AstNodeLegacy
}
export
interface
AstNodeLegacy
{
id
:
number
name
:
string
src
:
string
children
?:
Array
<
AstNodeLegacy
>
attributes
?:
AstNodeAtt
}
export
interface
AstNodeAtt
{
operator
?:
string
string
?:
null
type
?:
string
value
?:
string
constant
?:
boolean
name
?:
string
public
?:
boolean
exportedSymbols
?:
Object
argumentTypes
?:
null
absolutePath
?:
string
[
x
:
string
]:
any
}
export
interface
AstNode
{
absolutePath
?:
string
exportedSymbols
?:
Object
id
:
number
nodeType
:
string
nodes
?:
Array
<
AstNode
>
src
:
string
literals
?:
Array
<
string
>
file
?:
string
scope
?:
number
sourceUnit
?:
number
symbolAliases
?:
Array
<
string
>
[
x
:
string
]:
any
}
export
interface
compilationInterface
{
[
fileName
:
string
]:
{
[
contract
:
string
]:
CompiledContract
}
}
export
interface
ASTInterface
{
[
contractName
:
string
]:
CompilationSource
}
export
interface
CompiledContract
{
/** The Ethereum Contract ABI. If empty, it is represented as an empty array. */
abi
:
ABIDescription
[]
// See the Metadata Output documentation (serialised JSON string)
metadata
:
string
/** User documentation (natural specification) */
userdoc
:
UserDocumentation
/** Developer documentation (natural specification) */
devdoc
:
DeveloperDocumentation
/** Intermediate representation (string) */
ir
:
string
/** EVM-related outputs */
evm
:
{
assembly
:
string
legacyAssembly
:
{}
/** Bytecode and related details. */
bytecode
:
BytecodeObject
deployedBytecode
:
BytecodeObject
/** The list of function hashes */
methodIdentifiers
:
{
[
functionIdentifier
:
string
]:
string
}
// Function gas estimates
gasEstimates
:
{
creation
:
{
codeDepositCost
:
string
executionCost
:
'infinite'
|
string
totalCost
:
'infinite'
|
string
}
external
:
{
[
functionIdentifier
:
string
]:
string
}
internal
:
{
[
functionIdentifier
:
string
]:
'infinite'
|
string
}
}
}
}
/////////
// ABI //
/////////
export
type
ABIDescription
=
FunctionDescription
|
EventDescription
export
interface
FunctionDescription
{
/** Type of the method. default is 'function' */
type
?:
'function'
|
'constructor'
|
'fallback'
/** The name of the function. Constructor and fallback function never have name */
name
?:
string
/** List of parameters of the method. Fallback function doesn’t have inputs. */
inputs
?:
ABIParameter
[]
/** List of the outputs parameters for the method, if any */
outputs
?:
ABIParameter
[]
/** State mutability of the method */
stateMutability
:
'pure'
|
'view'
|
'nonpayable'
|
'payable'
/** true if function accepts Ether, false otherwise. Default is false */
payable
?:
boolean
/** true if function is either pure or view, false otherwise. Default is false */
constant
?:
boolean
}
export
interface
EventDescription
{
type
:
'event'
name
:
string
inputs
:
ABIParameter
&
{
/** true if the field is part of the log’s topics, false if it one of the log’s data segment. */
indexed
:
boolean
}[]
/** true if the event was declared as anonymous. */
anonymous
:
boolean
}
export
interface
ABIParameter
{
/** The name of the parameter */
name
:
string
/** The canonical type of the parameter */
type
:
ABITypeParameter
/** Used for tuple types */
components
?:
ABIParameter
[]
}
export
type
ABITypeParameter
=
|
'uint'
|
'uint[]'
// TODO : add <M>
|
'int'
|
'int[]'
// TODO : add <M>
|
'address'
|
'address[]'
|
'bool'
|
'bool[]'
|
'fixed'
|
'fixed[]'
// TODO : add <M>
|
'ufixed'
|
'ufixed[]'
// TODO : add <M>
|
'bytes'
|
'bytes[]'
// TODO : add <M>
|
'function'
|
'function[]'
|
'tuple'
|
'tuple[]'
|
string
// Fallback
///////////////////////////
// NATURAL SPECIFICATION //
///////////////////////////
// Userdoc
export
interface
UserDocumentation
{
methods
:
UserMethodList
notice
:
string
}
export
type
UserMethodList
=
{
[
functionIdentifier
:
string
]:
UserMethodDoc
}
&
{
'constructor'
?:
string
}
export
interface
UserMethodDoc
{
notice
:
string
}
// Devdoc
export
interface
DeveloperDocumentation
{
author
:
string
title
:
string
details
:
string
methods
:
DevMethodList
}
export
interface
DevMethodList
{
[
functionIdentifier
:
string
]:
DevMethodDoc
}
export
interface
DevMethodDoc
{
author
:
string
details
:
string
return
:
string
params
:
{
[
param
:
string
]:
string
}
}
//////////////
// BYTECODE //
//////////////
export
interface
BytecodeObject
{
/** The bytecode as a hex string. */
object
:
string
/** Opcodes list */
opcodes
:
string
/** The source mapping as a string. See the source mapping definition. */
sourceMap
:
string
/** If given, this is an unlinked object. */
linkReferences
?:
{
[
contractName
:
string
]:
{
/** Byte offsets into the bytecode. */
[
library
:
string
]:
{
start
:
number
;
length
:
number
}[]
}
}
}
remix-tests/tests/testRunner.ts
View file @
9114122e
...
...
@@ -61,8 +61,7 @@ async function compileAndDeploy(filename: string, callback: Function) {
compileFileOrFiles
(
filename
,
false
,
{
accounts
},
next
)
},
function
deployAllContracts
(
compilationResult
:
object
,
asts
,
next
:
Function
):
void
{
for
(
const
filename
in
asts
)
{
for
(
const
filename
in
asts
)
{
if
(
filename
.
includes
(
'_test.sol'
))
sourceASTs
[
filename
]
=
asts
[
filename
].
ast
}
...
...
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