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
742b91bd
Commit
742b91bd
authored
May 04, 2020
by
aniket-engg
Committed by
Aniket
May 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
custom transaction context support for special functions
parent
29c4f59c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
10 deletions
+58
-10
testRunner.ts
remix-tests/src/testRunner.ts
+28
-7
testRunner.ts
remix-tests/tests/testRunner.ts
+2
-2
sender_and_value_test.sol
remix-tests/tests/various_sender/sender_and_value_test.sol
+28
-1
No files found.
remix-tests/src/testRunner.ts
View file @
742b91bd
...
...
@@ -102,6 +102,23 @@ function getTestFunctionsInterface (jsonInterface: FunctionDescription[], funcLi
}
/**
* @dev returns ABI of special functions from passed interface
* @param jsonInterface Json Interface
*/
function
getSpecialFunctionsInterface
(
jsonInterface
:
FunctionDescription
[]):
Record
<
string
,
FunctionDescription
>
{
const
specialFunctionsInterface
:
Record
<
string
,
FunctionDescription
>
=
{}
const
funcList
:
string
[]
=
[
'beforeAll'
,
'beforeEach'
,
'afterAll'
,
'afterEach'
]
for
(
const
func
of
funcList
){
const
funcInterface
:
FunctionDescription
|
undefined
=
jsonInterface
.
find
(
node
=>
node
.
type
===
'function'
&&
node
.
name
===
func
)
if
(
funcInterface
)
{
specialFunctionsInterface
[
func
]
=
funcInterface
}
}
return
specialFunctionsInterface
}
/**
* @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
...
...
@@ -111,25 +128,29 @@ function getTestFunctionsInterface (jsonInterface: FunctionDescription[], funcLi
function
createRunList
(
jsonInterface
:
FunctionDescription
[],
fileAST
:
AstNode
,
testContractName
:
string
):
RunListInterface
[]
{
const
availableFunctions
:
string
[]
=
getAvailableFunctions
(
fileAST
,
testContractName
)
const
testFunctionsInterface
:
FunctionDescription
[]
=
getTestFunctionsInterface
(
jsonInterface
,
availableFunctions
)
const
specialFunctionsInterface
:
Record
<
string
,
FunctionDescription
>
=
getSpecialFunctionsInterface
(
jsonInterface
)
let
runList
:
RunListInterface
[]
=
[]
if
(
availableFunctions
.
indexOf
(
'beforeAll'
)
>=
0
)
{
runList
.
push
({
name
:
'beforeAll'
,
type
:
'internal'
,
constant
:
false
,
payable
:
false
})
if
(
availableFunctions
.
includes
(
'beforeAll'
))
{
let
func
=
specialFunctionsInterface
[
'beforeAll'
]
runList
.
push
({
name
:
'beforeAll'
,
inputs
:
func
.
inputs
,
signature
:
func
.
signature
,
type
:
'internal'
,
constant
:
isConstant
(
func
),
payable
:
isPayable
(
func
)
})
}
for
(
const
func
of
testFunctionsInterface
)
{
if
(
availableFunctions
.
indexOf
(
'beforeEach'
)
>=
0
)
{
runList
.
push
({
name
:
'beforeEach'
,
type
:
'internal'
,
constant
:
false
,
payable
:
false
})
if
(
availableFunctions
.
includes
(
'beforeEach'
))
{
let
func
=
specialFunctionsInterface
[
'beforeEach'
]
runList
.
push
({
name
:
'beforeEach'
,
inputs
:
func
.
inputs
,
signature
:
func
.
signature
,
type
:
'internal'
,
constant
:
isConstant
(
func
),
payable
:
isPayable
(
func
)
})
}
if
(
func
.
name
&&
func
.
inputs
)
runList
.
push
({
name
:
func
.
name
,
inputs
:
func
.
inputs
,
signature
:
func
.
signature
,
type
:
'test'
,
constant
:
isConstant
(
func
),
payable
:
isPayable
(
func
)
})
if
(
availableFunctions
.
indexOf
(
'afterEach'
)
>=
0
)
{
runList
.
push
({
name
:
'afterEach'
,
type
:
'internal'
,
constant
:
false
,
payable
:
false
})
let
func
=
specialFunctionsInterface
[
'afterEach'
]
runList
.
push
({
name
:
'afterEach'
,
inputs
:
func
.
inputs
,
signature
:
func
.
signature
,
type
:
'internal'
,
constant
:
isConstant
(
func
),
payable
:
isPayable
(
func
)
})
}
}
if
(
availableFunctions
.
indexOf
(
'afterAll'
)
>=
0
)
{
runList
.
push
({
name
:
'afterAll'
,
type
:
'internal'
,
constant
:
false
,
payable
:
false
})
let
func
=
specialFunctionsInterface
[
'afterAll'
]
runList
.
push
({
name
:
'afterAll'
,
inputs
:
func
.
inputs
,
signature
:
func
.
signature
,
type
:
'internal'
,
constant
:
isConstant
(
func
),
payable
:
isPayable
(
func
)
})
}
return
runList
...
...
remix-tests/tests/testRunner.ts
View file @
742b91bd
...
...
@@ -246,8 +246,8 @@ describe('testRunner', () => {
after
(()
=>
{
tests
=
[]
})
it
(
'should have
5
passing tests'
,
function
()
{
assert
.
equal
(
results
.
passingNum
,
5
)
it
(
'should have
17
passing tests'
,
function
()
{
assert
.
equal
(
results
.
passingNum
,
17
)
})
it
(
'should have 0 failing tests'
,
function
()
{
assert
.
equal
(
results
.
failureNum
,
0
)
...
...
remix-tests/tests/various_sender/sender_and_value_test.sol
View file @
742b91bd
...
...
@@ -2,7 +2,20 @@ import "remix_tests.sol"; // this import is automatically injected by Remix.
import "remix_accounts.sol";
contract SenderAndValueTest {
function beforeAll () public {}
/// #sender: account-2
/// #value: 200
function beforeAll () public payable {
Assert.equal(msg.sender, TestsAccounts.getAccount(2), "wrong sender in beforeAll");
Assert.equal(msg.value, 200, "wrong value in beforeAll");
}
/// #sender: account-3
/// #value: 300
function beforeEach () public payable {
Assert.equal(msg.sender, TestsAccounts.getAccount(3), "wrong sender in beforeEach");
Assert.equal(msg.value, 300, "wrong value in beforeEach");
}
/// #sender: account-1
function checkSenderIs1 () public {
...
...
@@ -28,4 +41,18 @@ contract SenderAndValueTest {
function checkValueIsnt10 () public payable{
Assert.notEqual(msg.value, 10, "wrong value in checkValueIsnt10");
}
/// #sender: account-4
/// #value: 400
function afterEach () public payable {
Assert.equal(msg.sender, TestsAccounts.getAccount(4), "wrong sender in afterEach");
Assert.equal(msg.value, 400, "wrong value in afterEach");
}
/// #sender: account-5
/// #value: 500
function afterAll () public payable {
Assert.equal(msg.sender, TestsAccounts.getAccount(5), "wrong sender in afterAll");
Assert.equal(msg.value, 500, "wrong value in afterAll");
}
}
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