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
ddc83035
Unverified
Commit
ddc83035
authored
Nov 18, 2019
by
Aniket
Committed by
GitHub
Nov 18, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1329 from ethereum/tests_sequence
sequence for tests
parents
b109475b
9114122e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
382 additions
and
76 deletions
+382
-76
compiler.ts
remix-tests/src/compiler.ts
+21
-3
runTestFiles.ts
remix-tests/src/runTestFiles.ts
+25
-10
runTestSources.ts
remix-tests/src/runTestSources.ts
+25
-8
testRunner.ts
remix-tests/src/testRunner.ts
+50
-21
types.ts
remix-tests/src/types.ts
+223
-0
simple_storage_test.sol
remix-tests/tests/examples_2/simple_storage_test.sol
+4
-4
testRunner.ts
remix-tests/tests/testRunner.ts
+34
-30
No files found.
remix-tests/src/compiler.ts
View file @
ddc83035
...
...
@@ -72,7 +72,16 @@ function processFile(filePath: string, sources: SrcIfc, isRoot: boolean = false)
const
userAgent
=
(
typeof
(
navigator
)
!==
'undefined'
)
&&
navigator
.
userAgent
?
navigator
.
userAgent
.
toLowerCase
()
:
'-'
const
isBrowser
=
!
(
typeof
(
window
)
===
'undefined'
||
userAgent
.
indexOf
(
' electron/'
)
>
-
1
)
// TODO: replace this with remix's own compiler code
/**
* @dev Compile file or files before running tests (used for CLI execution)
* @param filename Name of file
* @param isDirectory True, if path is a directory
* @param opts Options
* @param cb Callback
*
* TODO: replace this with remix's own compiler code
*/
export
function
compileFileOrFiles
(
filename
:
string
,
isDirectory
:
boolean
,
opts
:
any
,
cb
:
Function
)
{
let
compiler
:
any
const
accounts
:
string
[]
=
opts
.
accounts
||
[]
...
...
@@ -125,11 +134,20 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts:
if
(
!
isBrowser
)
require
(
'signale'
).
fatal
(
errors
)
return
cb
(
errors
)
}
cb
(
err
,
result
.
contracts
)
cb
(
err
,
result
.
contracts
,
result
.
sources
)
//return callback with contract details & ASTs
})
}
}
/**
* @dev Compile contract source before running tests (used for IDE tests execution)
* @param sources sources
* @param versionUrl url of selected compiler version to load
* @param usingWorker if true, load compiler using web worker
* @param importFileCb Import file callback
* @param opts Options
* @param cb Callback
*/
export
function
compileContractSources
(
sources
:
SrcIfc
,
versionUrl
:
any
,
usingWorker
:
boolean
,
importFileCb
:
any
,
opts
:
any
,
cb
:
Function
)
{
let
compiler
,
filepath
:
string
const
accounts
:
string
[]
=
opts
.
accounts
||
[]
...
...
@@ -172,6 +190,6 @@ export function compileContractSources(sources: SrcIfc, versionUrl: any, usingWo
if
(
!
isBrowser
)
require
(
'signale'
).
fatal
(
errors
)
return
cb
(
errors
)
}
cb
(
err
,
result
.
contracts
)
cb
(
err
,
result
.
contracts
,
result
.
sources
)
// return callback with contract details & ASTs
})
}
remix-tests/src/runTestFiles.ts
View file @
ddc83035
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'
)
import
{
compileFileOrFiles
}
from
'./compiler'
import
{
deployAll
}
from
'./deployer'
/**
* @dev run test contract files (used for CLI)
* @param filepath Path of file
* @param isDirectory True, if path is a directory
* @param web3 Web3
* @param opts Options
*/
export
function
runTestFiles
(
filepath
:
string
,
isDirectory
:
boolean
,
web3
:
Web3
,
opts
?:
object
)
{
opts
=
opts
||
{}
const
sourceASTs
:
any
=
{}
const
{
Signale
}
=
require
(
'signale'
)
// signale configuration
const
options
=
{
...
...
@@ -44,7 +53,12 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3,
function
compile
(
next
:
Function
)
{
compileFileOrFiles
(
filepath
,
isDirectory
,
{
accounts
},
next
)
},
function
deployAllContracts
(
compilationResult
,
next
:
Function
)
{
function
deployAllContracts
(
compilationResult
:
compilationInterface
,
asts
:
ASTInterface
,
next
:
Function
)
{
// Extract AST of test contract file source
for
(
const
filename
in
asts
)
{
if
(
filename
.
includes
(
'_test.sol'
))
sourceASTs
[
filename
]
=
asts
[
filename
].
ast
}
deployAll
(
compilationResult
,
web3
,
(
err
,
contracts
)
=>
{
if
(
err
)
{
next
(
err
)
...
...
@@ -52,18 +66,18 @@ 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
)
{
return
}
try
{
Object
.
keys
(
compilationResult
[
filename
]).
forEach
(
contractName
=>
{
contractsToTest
.
push
(
contractName
)
contractsToTestDetails
.
push
(
compilationResult
[
filename
][
contractName
])
})
Object
.
keys
(
compilationResult
[
filename
]).
forEach
(
contractName
=>
{
contractsToTest
.
push
(
contractName
)
contractsToTestDetails
.
push
(
compilationResult
[
filename
][
contractName
])
})
}
catch
(
e
)
{
console
.
error
(
e
)
}
...
...
@@ -77,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
...
...
@@ -103,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
],
{
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 @
ddc83035
...
...
@@ -4,11 +4,11 @@ require('colors')
import
{
compileContractSources
}
from
'./compiler'
import
{
deployAll
}
from
'./deployer'
import
{
runTest
}
from
'./testRunner'
import
{
TestResultInterface
,
ResultsInterface
}
from
'./types'
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
()
...
...
@@ -18,8 +18,20 @@ const createWeb3Provider = async function () {
return
web3
}
export
async
function
runTestSources
(
contractSources
,
versionUrl
,
usingWorker
,
testCallback
,
resultCallback
,
finalCallback
,
importFileCb
,
opts
)
{
/**
* @dev Run tests from source of a test contract file (used for IDE)
* @param contractSources Sources of contract
* @param versionUrl url of selected compiler version to load
* @param usingWorker if true, load compiler using web worker
* @param testCallback Test callback
* @param resultCallback Result Callback
* @param finalCallback Final Callback
* @param importFileCb Import file callback
* @param opts Options
*/
export
async
function
runTestSources
(
contractSources
:
SrcIfc
,
versionUrl
:
string
,
usingWorker
:
boolean
,
testCallback
:
Function
,
resultCallback
:
Function
,
finalCallback
:
any
,
importFileCb
:
Function
,
opts
:
any
)
{
opts
=
opts
||
{}
const
sourceASTs
:
any
=
{}
let
web3
=
opts
.
web3
||
await
createWeb3Provider
()
let
accounts
=
opts
.
accounts
||
null
async
.
waterfall
([
...
...
@@ -33,7 +45,11 @@ export async function runTestSources(contractSources, versionUrl, usingWorker, t
function
compile
(
next
)
{
compileContractSources
(
contractSources
,
versionUrl
,
usingWorker
,
importFileCb
,
{
accounts
},
next
)
},
function
deployAllContracts
(
compilationResult
,
next
)
{
function
deployAllContracts
(
compilationResult
:
compilationInterface
,
asts
:
ASTInterface
,
next
)
{
for
(
const
filename
in
asts
)
{
if
(
filename
.
includes
(
'_test.sol'
))
sourceASTs
[
filename
]
=
asts
[
filename
].
ast
}
deployAll
(
compilationResult
,
web3
,
(
err
,
contracts
)
=>
{
if
(
err
)
{
next
(
err
)
...
...
@@ -42,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
)
{
...
...
@@ -57,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
...
...
@@ -79,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
],
{
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 @
ddc83035
...
...
@@ -19,25 +19,55 @@ function getOverridedSender (userdoc, signature: string, methodIdentifiers) {
return
fullName
&&
accountIndex
?
accountIndex
[
1
]
:
null
}
function
getAvailableFunctions
(
jsonInterface
)
{
return
jsonInterface
.
reverse
().
filter
((
x
)
=>
x
.
type
===
'function'
).
map
((
x
)
=>
x
.
name
)
/**
* @dev returns functions of a test contract file in same sequence they appear in file (using passed AST)
* @param fileAST AST of test contract file source
* @param testContractName Name of test contract
*/
function
getAvailableFunctions
(
fileAST
:
any
,
testContractName
:
string
)
{
const
contractAST
:
any
[]
=
fileAST
.
nodes
.
filter
(
node
=>
node
.
name
===
testContractName
&&
node
.
nodeType
===
'ContractDefinition'
)
const
funcNodes
:
any
[]
=
contractAST
[
0
].
nodes
.
filter
(
node
=>
node
.
kind
===
'function'
&&
node
.
nodeType
===
"FunctionDefinition"
)
const
funcList
:
string
[]
=
funcNodes
.
map
(
node
=>
node
.
name
)
return
funcList
;
}
function
getTestFunctions
(
jsonInterface
)
{
let
specialFunctions
=
[
'beforeAll'
,
'beforeEach'
,
'afterAll'
,
'afterEach'
]
return
jsonInterface
.
filter
((
x
)
=>
specialFunctions
.
indexOf
(
x
.
name
)
<
0
&&
x
.
type
===
'function'
)
/**
* @dev returns ABI of passed method list from passed interface
* @param jsonInterface Json Interface
* @param funcList Methods to extract the interface of
*/
function
getTestFunctionsInterface
(
jsonInterface
:
any
,
funcList
:
string
[])
{
const
functionsInterface
:
any
[]
=
[]
const
specialFunctions
=
[
'beforeAll'
,
'beforeEach'
,
'afterAll'
,
'afterEach'
]
for
(
const
func
of
funcList
){
if
(
!
specialFunctions
.
includes
(
func
))
{
const
funcInterface
=
jsonInterface
.
find
(
node
=>
node
.
type
===
'function'
&&
node
.
name
===
func
)
functionsInterface
.
push
(
funcInterface
)
}
}
return
functionsInterface
}
function
createRunList
(
jsonInterface
):
RunListInterface
[]
{
let
availableFunctions
=
getAvailableFunctions
(
jsonInterface
)
let
testFunctions
=
getTestFunctions
(
jsonInterface
)
/**
* @dev Prepare a list of tests to run using test contract file ABI, AST & contract name
* @param jsonInterface File JSON interface
* @param fileAST File AST
* @param testContractName Test contract name
*/
function
createRunList
(
jsonInterface
:
any
,
fileAST
:
any
,
testContractName
:
string
):
RunListInterface
[]
{
const
availableFunctions
:
string
[]
=
getAvailableFunctions
(
fileAST
,
testContractName
)
const
testFunctionsInterface
:
any
[]
=
getTestFunctionsInterface
(
jsonInterface
,
availableFunctions
)
let
runList
:
RunListInterface
[]
=
[]
if
(
availableFunctions
.
indexOf
(
'beforeAll'
)
>=
0
)
{
runList
.
push
({
name
:
'beforeAll'
,
type
:
'internal'
,
constant
:
false
})
}
for
(
let
func
of
testFunctions
)
{
for
(
const
func
of
testFunctionsInterface
)
{
if
(
availableFunctions
.
indexOf
(
'beforeEach'
)
>=
0
)
{
runList
.
push
({
name
:
'beforeEach'
,
type
:
'internal'
,
constant
:
false
})
}
...
...
@@ -54,13 +84,12 @@ function createRunList (jsonInterface): RunListInterface[] {
return
runList
}
export
function
runTest
(
testName
,
testObject
:
any
,
contractDetails
:
any
,
opts
:
any
,
testCallback
:
TestCbInterface
,
resultsCallback
:
ResultCbInterface
)
{
let
runList
=
createRunList
(
testObject
.
_jsonInterface
)
export
function
runTest
(
testName
,
testObject
:
any
,
contractDetails
:
any
,
fileAST
:
any
,
opts
:
any
,
testCallback
:
TestCbInterface
,
resultsCallback
:
ResultCbInterface
)
{
const
runList
:
RunListInterface
[]
=
createRunList
(
testObject
.
_jsonInterface
,
fileAST
,
testName
)
let
passingNum
:
number
=
0
let
failureNum
:
number
=
0
let
timePassed
:
number
=
0
le
t
web3
=
new
Web3
()
cons
t
web3
=
new
Web3
()
const
accts
:
TestResultInterface
=
{
type
:
'accountList'
,
...
...
@@ -87,11 +116,11 @@ export function runTest (testName, testObject: any, contractDetails: any, opts:
let
sendParams
if
(
sender
)
sendParams
=
{
from
:
sender
}
le
t
method
=
testObject
.
methods
[
func
.
name
].
apply
(
testObject
.
methods
[
func
.
name
],
[])
le
t
startTime
=
Date
.
now
()
cons
t
method
=
testObject
.
methods
[
func
.
name
].
apply
(
testObject
.
methods
[
func
.
name
],
[])
cons
t
startTime
=
Date
.
now
()
if
(
func
.
constant
)
{
method
.
call
(
sendParams
).
then
((
result
)
=>
{
le
t
time
=
(
Date
.
now
()
-
startTime
)
/
1000.0
cons
t
time
=
(
Date
.
now
()
-
startTime
)
/
1000.0
if
(
result
)
{
const
resp
:
TestResultInterface
=
{
type
:
'testPass'
,
...
...
@@ -118,12 +147,12 @@ export function runTest (testName, testObject: any, contractDetails: any, opts:
}
else
{
method
.
send
(
sendParams
).
on
(
'receipt'
,
(
receipt
)
=>
{
try
{
le
t
time
:
number
=
(
Date
.
now
()
-
startTime
)
/
1000.0
le
t
topic
=
Web3
.
utils
.
sha3
(
'AssertionEvent(bool,string)'
)
cons
t
time
:
number
=
(
Date
.
now
()
-
startTime
)
/
1000.0
cons
t
topic
=
Web3
.
utils
.
sha3
(
'AssertionEvent(bool,string)'
)
let
testPassed
:
boolean
=
false
for
(
le
t
i
in
receipt
.
events
)
{
le
t
event
=
receipt
.
events
[
i
]
for
(
cons
t
i
in
receipt
.
events
)
{
cons
t
event
=
receipt
.
events
[
i
]
if
(
event
.
raw
.
topics
.
indexOf
(
topic
)
>=
0
)
{
const
testEvent
=
web3
.
eth
.
abi
.
decodeParameters
([
'bool'
,
'string'
],
event
.
raw
.
data
)
if
(
!
testEvent
[
0
])
{
...
...
@@ -160,7 +189,7 @@ export function runTest (testName, testObject: any, contractDetails: any, opts:
}
}).
on
(
'error'
,
function
(
err
:
any
)
{
console
.
error
(
err
)
le
t
time
:
number
=
(
Date
.
now
()
-
startTime
)
/
1000.0
cons
t
time
:
number
=
(
Date
.
now
()
-
startTime
)
/
1000.0
const
resp
:
TestResultInterface
=
{
type
:
'testFailure'
,
value
:
changeCase
.
sentenceCase
(
func
.
name
),
...
...
remix-tests/src/types.ts
View file @
ddc83035
...
...
@@ -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/examples_2/simple_storage_test.sol
View file @
ddc83035
...
...
@@ -13,11 +13,11 @@ contract MyTest {
i += 1;
}
function initialValueShouldBe
2
00() public returns (bool) {
return Assert.equal(foo.get(),
2
00, "initial value is not correct");
function initialValueShouldBe
1
00() public returns (bool) {
return Assert.equal(foo.get(),
1
00, "initial value is not correct");
}
function value
ShouldBe1
00() public returns (bool) {
return Assert.equal(foo.get(),
1
00, "value is not correct after first execution");
function value
IsSet2
00() public returns (bool) {
return Assert.equal(foo.get(),
2
00, "value is not correct after first execution");
}
}
remix-tests/tests/testRunner.ts
View file @
ddc83035
...
...
@@ -37,7 +37,6 @@ function deepEqualExcluding(a: any, b: any, excludedKeys: string[]) {
let
aStripped
:
any
=
removeKeysFromObject
(
a
,
excludedKeys
);
let
bStripped
:
any
=
removeKeysFromObject
(
b
,
excludedKeys
);
assert
.
deepEqual
(
aStripped
,
bStripped
)
}
...
...
@@ -46,6 +45,7 @@ let provider = new Provider()
async
function
compileAndDeploy
(
filename
:
string
,
callback
:
Function
)
{
let
web3
:
Web3
=
new
Web3
()
let
sourceASTs
:
any
=
{}
await
provider
.
init
()
web3
.
setProvider
(
provider
)
let
compilationData
:
object
...
...
@@ -60,7 +60,11 @@ async function compileAndDeploy(filename: string, callback: Function) {
function
compile
(
next
:
Function
):
void
{
compileFileOrFiles
(
filename
,
false
,
{
accounts
},
next
)
},
function
deployAllContracts
(
compilationResult
:
object
,
next
:
Function
):
void
{
function
deployAllContracts
(
compilationResult
:
object
,
asts
,
next
:
Function
):
void
{
for
(
const
filename
in
asts
)
{
if
(
filename
.
includes
(
'_test.sol'
))
sourceASTs
[
filename
]
=
asts
[
filename
].
ast
}
try
{
compilationData
=
compilationResult
deployAll
(
compilationResult
,
web3
,
next
)
...
...
@@ -69,7 +73,7 @@ async function compileAndDeploy(filename: string, callback: Function) {
}
}
],
function
(
_err
:
Error
|
null
|
undefined
,
contracts
:
any
):
void
{
callback
(
null
,
compilationData
,
contracts
,
accounts
)
callback
(
null
,
compilationData
,
contracts
,
sourceASTs
,
accounts
)
})
}
...
...
@@ -98,11 +102,11 @@ describe('testRunner', () => {
describe
(
'#runTest'
,
()
=>
{
describe
(
'test with beforeAll'
,
()
=>
{
le
t
filename
:
string
=
'tests/examples_1/simple_storage_test.sol'
cons
t
filename
:
string
=
'tests/examples_1/simple_storage_test.sol'
before
((
done
)
=>
{
compileAndDeploy
(
filename
,
(
_err
:
Error
|
null
|
undefined
,
compilationData
:
object
,
contracts
:
any
,
accounts
:
string
[])
=>
{
runTest
(
'MyTest'
,
contracts
.
MyTest
,
compilationData
[
filename
][
'MyTest'
],
{
accounts
},
testCallback
,
resultsCallback
(
done
))
compileAndDeploy
(
filename
,
(
_err
:
Error
|
null
|
undefined
,
compilationData
:
object
,
contracts
:
any
,
a
sts
:
any
,
a
ccounts
:
string
[])
=>
{
runTest
(
'MyTest'
,
contracts
.
MyTest
,
compilationData
[
filename
][
'MyTest'
],
asts
[
filename
],
{
accounts
},
testCallback
,
resultsCallback
(
done
))
})
})
...
...
@@ -120,20 +124,20 @@ describe('testRunner', () => {
deepEqualExcluding
(
tests
,
[
{
type
:
'accountList'
,
value
:
accounts
},
{
type
:
'contract'
,
value
:
'MyTest'
,
filename
:
'tests/examples_1/simple_storage_test.sol'
},
{
type
:
'testPass'
,
value
:
'Initial value should be100'
,
context
:
'MyTest'
},
{
type
:
'testPass'
,
value
:
'Initial value should not be200'
,
context
:
'MyTest'
},
{
type
:
'testFailure'
,
value
:
'Should trigger one fail'
,
errMsg
:
'uint test 1 fails'
,
context
:
'MyTest'
},
{
type
:
'testPass'
,
value
:
'Should trigger one pass'
,
context
:
'MyTest'
},
{
type
:
'testPass'
,
value
:
'Initial value should be100'
,
context
:
'MyTest'
}
],
[
'time'
,
'value'
])
{
type
:
'testPass'
,
value
:
'Should trigger one pass'
,
context
:
'MyTest'
}
],
[
'time'
])
})
})
describe
(
'test with beforeEach'
,
function
()
{
let
filename
=
'tests/examples_2/simple_storage_test.sol'
const
filename
:
string
=
'tests/examples_2/simple_storage_test.sol'
before
(
function
(
done
)
{
compileAndDeploy
(
filename
,
function
(
_err
:
Error
|
null
|
undefined
,
compilationData
:
object
,
contracts
:
any
,
accounts
:
string
[])
{
runTest
(
'MyTest'
,
contracts
.
MyTest
,
compilationData
[
filename
][
'MyTest'
],
{
accounts
},
testCallback
,
resultsCallback
(
done
))
compileAndDeploy
(
filename
,
function
(
_err
:
Error
|
null
|
undefined
,
compilationData
:
object
,
contracts
:
any
,
a
sts
:
any
,
a
ccounts
:
string
[])
{
runTest
(
'MyTest'
,
contracts
.
MyTest
,
compilationData
[
filename
][
'MyTest'
],
asts
[
filename
],
{
accounts
},
testCallback
,
resultsCallback
(
done
))
})
})
...
...
@@ -151,19 +155,19 @@ describe('testRunner', () => {
deepEqualExcluding
(
tests
,
[
{
type
:
'accountList'
,
value
:
accounts
},
{
type
:
'contract'
,
value
:
'MyTest'
,
filename
:
'tests/examples_2/simple_storage_test.sol'
},
{
type
:
'testPass'
,
value
:
'
V
alue should be100'
,
context
:
'MyTest'
},
{
type
:
'testPass'
,
value
:
'
Initial value should be
200'
,
context
:
'MyTest'
}
{
type
:
'testPass'
,
value
:
'
Initial v
alue should be100'
,
context
:
'MyTest'
},
{
type
:
'testPass'
,
value
:
'
Value is set
200'
,
context
:
'MyTest'
}
],
[
'time'
])
})
})
// Test string equality
describe
(
'test string equality'
,
function
()
{
let
filename
=
'tests/examples_3/simple_string_test.sol'
const
filename
:
string
=
'tests/examples_3/simple_string_test.sol'
before
(
function
(
done
)
{
compileAndDeploy
(
filename
,
(
_err
,
compilationData
,
contracts
,
accounts
)
=>
{
runTest
(
'StringTest'
,
contracts
.
StringTest
,
compilationData
[
filename
][
'StringTest'
],
{
accounts
},
testCallback
,
resultsCallback
(
done
))
compileAndDeploy
(
filename
,
function
(
_err
:
Error
|
null
|
undefined
,
compilationData
:
object
,
contracts
:
any
,
asts
:
any
,
accounts
:
string
[])
{
runTest
(
'StringTest'
,
contracts
.
StringTest
,
compilationData
[
filename
][
'StringTest'
],
asts
[
filename
],
{
accounts
},
testCallback
,
resultsCallback
(
done
))
})
})
...
...
@@ -177,19 +181,19 @@ describe('testRunner', () => {
deepEqualExcluding
(
tests
,
[
{
type
:
'accountList'
,
value
:
accounts
},
{
type
:
'contract'
,
value
:
'StringTest'
,
filename
:
'tests/examples_3/simple_string_test.sol'
},
{
type
:
'testPass'
,
value
:
'
Value should not be hello wordl
'
,
context
:
'StringTest'
},
{
type
:
'testPass'
,
value
:
'
Initial value should be hello world
'
,
context
:
'StringTest'
}
{
type
:
'testPass'
,
value
:
'
Initial value should be hello world
'
,
context
:
'StringTest'
},
{
type
:
'testPass'
,
value
:
'
Value should not be hello wordl
'
,
context
:
'StringTest'
}
],
[
'time'
])
})
})
// Test multiple directory import in test contract
describe
(
'test multiple directory import in test contract'
,
function
()
{
let
filename
=
'tests/examples_5/test/simple_storage_test.sol'
const
filename
:
string
=
'tests/examples_5/test/simple_storage_test.sol'
before
(
function
(
done
)
{
compileAndDeploy
(
filename
,
(
_err
,
compilationData
,
contracts
,
accounts
)
=>
{
runTest
(
'StorageResolveTest'
,
contracts
.
StorageResolveTest
,
compilationData
[
filename
][
'StorageResolveTest'
],
{
accounts
},
testCallback
,
resultsCallback
(
done
))
compileAndDeploy
(
filename
,
function
(
_err
:
Error
|
null
|
undefined
,
compilationData
:
object
,
contracts
:
any
,
asts
:
any
,
accounts
:
string
[])
{
runTest
(
'StorageResolveTest'
,
contracts
.
StorageResolveTest
,
compilationData
[
filename
][
'StorageResolveTest'
],
asts
[
filename
],
{
accounts
},
testCallback
,
resultsCallback
(
done
))
})
})
...
...
@@ -204,19 +208,19 @@ describe('testRunner', () => {
{
type
:
'accountList'
,
value
:
accounts
},
{
type
:
'contract'
,
value
:
'StorageResolveTest'
,
filename
:
'tests/examples_5/test/simple_storage_test.sol'
},
{
type
:
'testPass'
,
value
:
'Initial value should be100'
,
context
:
'StorageResolveTest'
},
{
type
:
'testPass'
,
value
:
'Check if
odd
'
,
context
:
'StorageResolveTest'
},
{
type
:
'testPass'
,
value
:
'Check if
even
'
,
context
:
'StorageResolveTest'
}
{
type
:
'testPass'
,
value
:
'Check if
even
'
,
context
:
'StorageResolveTest'
},
{
type
:
'testPass'
,
value
:
'Check if
odd
'
,
context
:
'StorageResolveTest'
}
],
[
'time'
])
})
})
//Test signed/unsigned integer weight
describe
(
'test number weight'
,
function
()
{
let
filename
=
'tests/number/number_test.sol'
const
filename
:
string
=
'tests/number/number_test.sol'
before
(
function
(
done
)
{
compileAndDeploy
(
filename
,
(
_err
,
compilationData
,
contracts
,
accounts
)
=>
{
runTest
(
'IntegerTest'
,
contracts
.
IntegerTest
,
compilationData
[
filename
][
'IntegerTest'
],
{
accounts
},
testCallback
,
resultsCallback
(
done
))
compileAndDeploy
(
filename
,
function
(
_err
:
Error
|
null
|
undefined
,
compilationData
:
object
,
contracts
:
any
,
asts
:
any
,
accounts
:
string
[])
{
runTest
(
'IntegerTest'
,
contracts
.
IntegerTest
,
compilationData
[
filename
][
'IntegerTest'
],
asts
[
filename
],
{
accounts
},
testCallback
,
resultsCallback
(
done
))
})
})
...
...
@@ -232,11 +236,11 @@ describe('testRunner', () => {
// Test Transaction with different sender
describe
(
'various sender'
,
function
()
{
let
filename
=
'tests/various_sender/sender_test.sol'
const
filename
:
string
=
'tests/various_sender/sender_test.sol'
before
(
function
(
done
)
{
compileAndDeploy
(
filename
,
(
_err
,
compilationData
,
contracts
,
accounts
)
=>
{
runTest
(
'SenderTest'
,
contracts
.
SenderTest
,
compilationData
[
filename
][
'SenderTest'
],
{
accounts
},
testCallback
,
resultsCallback
(
done
))
compileAndDeploy
(
filename
,
function
(
_err
:
Error
|
null
|
undefined
,
compilationData
:
object
,
contracts
:
any
,
asts
:
any
,
accounts
:
string
[])
{
runTest
(
'SenderTest'
,
contracts
.
SenderTest
,
compilationData
[
filename
][
'SenderTest'
],
asts
[
filename
],
{
accounts
},
testCallback
,
resultsCallback
(
done
))
})
})
...
...
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