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
9d55d34a
Commit
9d55d34a
authored
Jan 21, 2020
by
aniket-engg
Committed by
Aniket
Jan 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pass value in test methods
parent
f024d0ea
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
18 deletions
+34
-18
package.json
remix-tests/package.json
+2
-1
testRunner.ts
remix-tests/src/testRunner.ts
+24
-9
types.ts
remix-tests/src/types.ts
+1
-0
sender_test.sol
remix-tests/tests/various_sender/sender_test.sol
+7
-8
No files found.
remix-tests/package.json
View file @
9d55d34a
...
@@ -33,7 +33,8 @@
...
@@ -33,7 +33,8 @@
},
},
"standard"
:
{
"standard"
:
{
"ignore"
:
[
"ignore"
:
[
"tests/"
"tests/"
,
"dist/"
]
]
},
},
"homepage"
:
"https://github.com/ethereum/remix/tree/master/remix-tests#readme"
,
"homepage"
:
"https://github.com/ethereum/remix/tree/master/remix-tests#readme"
,
...
...
remix-tests/src/testRunner.ts
View file @
9d55d34a
...
@@ -14,16 +14,27 @@ function getFunctionFullName (signature: string, methodIdentifiers: Record <stri
...
@@ -14,16 +14,27 @@ function getFunctionFullName (signature: string, methodIdentifiers: Record <stri
}
}
function
isConstant
(
funcABI
:
FunctionDescription
):
boolean
{
function
isConstant
(
funcABI
:
FunctionDescription
):
boolean
{
return
(
funcABI
.
stateMutability
===
'view'
||
funcABI
.
stateMutability
===
'pure'
)
return
(
funcABI
.
constant
||
funcABI
.
stateMutability
===
'view'
||
funcABI
.
stateMutability
===
'pure'
)
}
function
isPayable
(
funcABI
:
FunctionDescription
):
boolean
{
return
(
funcABI
.
payable
||
funcABI
.
stateMutability
===
'payable'
)
}
}
function
getOverridedSender
(
userdoc
:
UserDocumentation
,
signature
:
string
,
methodIdentifiers
:
Record
<
string
,
string
>
)
{
function
getOverridedSender
(
userdoc
:
UserDocumentation
,
signature
:
string
,
methodIdentifiers
:
Record
<
string
,
string
>
)
{
let
fullName
:
any
=
getFunctionFullName
(
signature
,
methodIdentifiers
)
let
fullName
:
any
=
getFunctionFullName
(
signature
,
methodIdentifiers
)
let
match
:
RegExp
=
/
sender: account-+
(\d)
/g
let
senderRegex
:
RegExp
=
/#
sender: account-+
(\d)
/g
let
accountIndex
:
any
=
userdoc
.
methods
[
fullName
]
?
match
.
exec
(
userdoc
.
methods
[
fullName
].
notice
)
:
null
let
accountIndex
:
RegExpExecArray
|
null
=
userdoc
.
methods
[
fullName
]
?
senderRegex
.
exec
(
userdoc
.
methods
[
fullName
].
notice
)
:
null
return
fullName
&&
accountIndex
?
accountIndex
[
1
]
:
null
return
fullName
&&
accountIndex
?
accountIndex
[
1
]
:
null
}
}
function
getProvidedValue
(
userdoc
:
UserDocumentation
,
signature
:
string
,
methodIdentifiers
:
Record
<
string
,
string
>
)
{
let
fullName
:
any
=
getFunctionFullName
(
signature
,
methodIdentifiers
)
let
valueRegex
:
RegExp
=
/#value:
(\d
+
)
/g
let
value
:
RegExpExecArray
|
null
=
userdoc
.
methods
[
fullName
]
?
valueRegex
.
exec
(
userdoc
.
methods
[
fullName
].
notice
)
:
null
return
fullName
&&
value
?
value
[
1
]
:
null
}
/**
/**
* @dev returns functions of a test contract file in same sequence they appear in file (using passed AST)
* @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 fileAST AST of test contract file source
...
@@ -74,21 +85,21 @@ function createRunList (jsonInterface: FunctionDescription[], fileAST: AstNode,
...
@@ -74,21 +85,21 @@ function createRunList (jsonInterface: FunctionDescription[], fileAST: AstNode,
let
runList
:
RunListInterface
[]
=
[]
let
runList
:
RunListInterface
[]
=
[]
if
(
availableFunctions
.
indexOf
(
'beforeAll'
)
>=
0
)
{
if
(
availableFunctions
.
indexOf
(
'beforeAll'
)
>=
0
)
{
runList
.
push
({
name
:
'beforeAll'
,
type
:
'internal'
,
constant
:
false
})
runList
.
push
({
name
:
'beforeAll'
,
type
:
'internal'
,
constant
:
false
,
payable
:
false
})
}
}
for
(
const
func
of
testFunctionsInterface
)
{
for
(
const
func
of
testFunctionsInterface
)
{
if
(
availableFunctions
.
indexOf
(
'beforeEach'
)
>=
0
)
{
if
(
availableFunctions
.
indexOf
(
'beforeEach'
)
>=
0
)
{
runList
.
push
({
name
:
'beforeEach'
,
type
:
'internal'
,
constant
:
false
})
runList
.
push
({
name
:
'beforeEach'
,
type
:
'internal'
,
constant
:
false
,
payable
:
false
})
}
}
runList
.
push
({
name
:
func
.
name
,
signature
:
func
.
signature
,
type
:
'test'
,
constant
:
isConstant
(
func
)
})
runList
.
push
({
name
:
func
.
name
,
signature
:
func
.
signature
,
type
:
'test'
,
constant
:
isConstant
(
func
)
,
payable
:
isPayable
(
func
)
})
if
(
availableFunctions
.
indexOf
(
'afterEach'
)
>=
0
)
{
if
(
availableFunctions
.
indexOf
(
'afterEach'
)
>=
0
)
{
runList
.
push
({
name
:
'afterEach'
,
type
:
'internal'
,
constant
:
false
})
runList
.
push
({
name
:
'afterEach'
,
type
:
'internal'
,
constant
:
false
,
payable
:
false
})
}
}
}
}
if
(
availableFunctions
.
indexOf
(
'afterAll'
)
>=
0
)
{
if
(
availableFunctions
.
indexOf
(
'afterAll'
)
>=
0
)
{
runList
.
push
({
name
:
'afterAll'
,
type
:
'internal'
,
constant
:
false
})
runList
.
push
({
name
:
'afterAll'
,
type
:
'internal'
,
constant
:
false
,
payable
:
false
})
}
}
return
runList
return
runList
...
@@ -125,7 +136,6 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
...
@@ -125,7 +136,6 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
}
}
let
sendParams
let
sendParams
if
(
sender
)
sendParams
=
{
from
:
sender
}
if
(
sender
)
sendParams
=
{
from
:
sender
}
const
method
=
testObject
.
methods
[
func
.
name
].
apply
(
testObject
.
methods
[
func
.
name
],
[])
const
method
=
testObject
.
methods
[
func
.
name
].
apply
(
testObject
.
methods
[
func
.
name
],
[])
const
startTime
=
Date
.
now
()
const
startTime
=
Date
.
now
()
if
(
func
.
constant
)
{
if
(
func
.
constant
)
{
...
@@ -155,6 +165,11 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
...
@@ -155,6 +165,11 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
next
()
next
()
})
})
}
else
{
}
else
{
if
(
func
.
payable
)
{
const
value
=
getProvidedValue
(
contractDetails
.
userdoc
,
func
.
signature
,
contractDetails
.
evm
.
methodIdentifiers
)
if
(
sendParams
)
sendParams
.
value
=
value
else
sendParams
=
{
value
}
}
method
.
send
(
sendParams
).
on
(
'receipt'
,
(
receipt
)
=>
{
method
.
send
(
sendParams
).
on
(
'receipt'
,
(
receipt
)
=>
{
try
{
try
{
const
time
:
number
=
(
Date
.
now
()
-
startTime
)
/
1000.0
const
time
:
number
=
(
Date
.
now
()
-
startTime
)
/
1000.0
...
...
remix-tests/src/types.ts
View file @
9d55d34a
...
@@ -16,6 +16,7 @@ export interface RunListInterface {
...
@@ -16,6 +16,7 @@ export interface RunListInterface {
name
:
string
,
name
:
string
,
type
:
string
,
type
:
string
,
constant
:
boolean
,
constant
:
boolean
,
payable
:
boolean
,
signature
?:
any
signature
?:
any
}
}
export
interface
ResultsInterface
{
export
interface
ResultsInterface
{
...
...
remix-tests/tests/various_sender/sender_test.sol
View file @
9d55d34a
...
@@ -2,25 +2,24 @@ import "remix_tests.sol"; // this import is automatically injected by Remix.
...
@@ -2,25 +2,24 @@ import "remix_tests.sol"; // this import is automatically injected by Remix.
import "remix_accounts.sol";
import "remix_accounts.sol";
contract SenderTest {
contract SenderTest {
function beforeAll () public {}
function beforeAll () public {}
/// sender: account-1
///
#
sender: account-1
function checkSenderIs1 () public {
function checkSenderIs1 () public {
Assert.equal(msg.sender, TestsAccounts.getAccount(1), "wrong sender in checkSenderIs1");
Assert.equal(msg.sender, TestsAccounts.getAccount(1), "wrong sender in checkSenderIs1");
}
}
/// sender: account-0
/// #sender: account-0
function checkSenderIs0 () public {
/// #value: 10
function checkSenderIs0 () public payable{
Assert.equal(msg.sender, TestsAccounts.getAccount(0), "wrong sender in checkSenderIs0");
Assert.equal(msg.sender, TestsAccounts.getAccount(0), "wrong sender in checkSenderIs0");
}
}
///
sender: account-1
///
#value: 100
function checkSenderIsNt0 () public {
function checkSenderIsNt0 () public
payable
{
Assert.
notE
qual(msg.sender, TestsAccounts.getAccount(0), "wrong sender in checkSenderIsNot0");
Assert.
e
qual(msg.sender, TestsAccounts.getAccount(0), "wrong sender in checkSenderIsNot0");
}
}
/// sender: account-2
function checkSenderIsnt2 () public {
function checkSenderIsnt2 () public {
Assert.notEqual(msg.sender, TestsAccounts.getAccount(1), "wrong sender in checkSenderIsnt2");
Assert.notEqual(msg.sender, TestsAccounts.getAccount(1), "wrong sender in checkSenderIsnt2");
}
}
...
...
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