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
1cab5245
Commit
1cab5245
authored
Aug 23, 2018
by
0mkar
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/master'
parents
2aa3a86f
fe48ebbc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
132 additions
and
19 deletions
+132
-19
README.md
README.md
+107
-1
tests.sol.js
sol/tests.sol.js
+17
-17
testRunner.js
src/testRunner.js
+8
-1
No files found.
README.md
View file @
1cab5245
[

](https://travis-ci.org/ethereum/remix-tests)
[

](https://travis-ci.org/ethereum/remix-tests)
# remix-tests
Remix-Tests
---
### Installation
`npm -g install remix-tests`
### Test structure
Example test file:
```
Javascript
pragma solidity ^0.4.7;
import "remix_tests.sol"; // injected by remix-tests
import "./simple_storage.sol";
contract MyTest {
SimpleStorage foo;
uint i = 0;
function beforeAll() {
foo = new SimpleStorage();
}
function beforeEach() {
if (i == 1) {
foo.set(200);
}
i += 1;
}
function initialValueShouldBe100() public {
Assert.equal(foo.get(), 100, "initial value is not correct");
}
function initialValueShouldBe200() public constant returns {
return Assert.equal(foo.get(), 200, "initial value is not correct");
}
}
```
Available special functions:
*
`beforeEach`
- runs before each test
*
`beforeAll`
- runs before all tests
#### Assert library
Available functions:
`Assert.ok(value, message)`
`Assert.equal(value1, value2, message)`
`Assert.notEqual(value1, value2, message)`
supported values currently are:
`bool`
`uint`
`int`
`address`
`bytes32`
### Command Line
Remix-Tests will assume the tests will files whose name end with "_test.sol". e.g
`simple_storage_test.sol`
Usage:
*
A directory with tests files
`remix-tests examples/`
*
A test file
`remix-tests examples/simple_storage_test.sol`
### Library
Importing the library:
```
Javascript
const RemixTests = require('remix-tests');
```
Running a single test object:
```
Javascript
remixTests.runTest(contractName, contractObj, testCallback, resultsCallback)
```
params:
`testName`
-
`string`
name of the test
`testObj`
- web3.js 1.0 contract instance of the test
`testCallback(object)`
- called each time there is a test event. 3 possible type of objects:
*
`{ type: 'contract', value: '<TestName>', filename: '<test_filename.sol>' }`
*
`{ type: 'testPass', value: '<name of testing function>', time: <time taken>, context: '<TestName>'}`
*
`{ type: 'testFailure', value: '<name of testing function>', time: <time taken>, context: '<TestName>', errMsg: '<message in the Assert>' }`
`resultsCallback(object)`
*
`passingNum`
- number of passing tests
*
`failureNum`
- number of failing tests
*
`timePassed`
- time it took for all the tests to run (in seconds)
Running a set of tests given the sourcecode:
```
Javascript
remixTests.runTestSources(contractSources, testCallback, resultCallback, finalCallback, importFileCb);
```
params:
`contractSources`
-
`object`
->
`filename => { content: source }`
`testCallback(object)`
- called each time there is a test event. 3 possible type of objects:
*
`{ type: 'contract', value: '<TestName>', filename: '<test_filename.sol>' }`
*
`{ type: 'testPass', value: '<name of testing function>', time: <time taken>, context: '<TestName>'}`
*
`{ type: 'testFailure', value: '<name of testing function>', time: <time taken>, context: '<TestName>', errMsg: '<message in the Assert>' }`
`resultCallback(object)`
*
`passingNum`
- number of passing tests
*
`failureNum`
- number of failing tests
*
`timePassed`
- time it took for all the tests to run (in seconds)
`finalCallback(err)`
- called when all tests finish running.
`importCb(url, cb)`
sol/tests.sol.js
View file @
1cab5245
...
@@ -10,93 +10,93 @@ library Assert {
...
@@ -10,93 +10,93 @@ library Assert {
function ok(bool a, string message) public returns (bool result) {
function ok(bool a, string message) public returns (bool result) {
result = a;
result = a;
AssertionEvent(result, message);
emit
AssertionEvent(result, message);
}
}
function equal(uint a, uint b, string message) public returns (bool result) {
function equal(uint a, uint b, string message) public returns (bool result) {
result = (a == b);
result = (a == b);
AssertionEvent(result, message);
emit
AssertionEvent(result, message);
}
}
function equal(int a, int b, string message) public returns (bool result) {
function equal(int a, int b, string message) public returns (bool result) {
result = (a == b);
result = (a == b);
AssertionEvent(result, message);
emit
AssertionEvent(result, message);
}
}
function equal(bool a, bool b, string message) public returns (bool result) {
function equal(bool a, bool b, string message) public returns (bool result) {
result = (a == b);
result = (a == b);
AssertionEvent(result, message);
emit
AssertionEvent(result, message);
}
}
// TODO: only for certain versions of solc
// TODO: only for certain versions of solc
//function equal(fixed a, fixed b, string message) public returns (bool result) {
//function equal(fixed a, fixed b, string message) public returns (bool result) {
// result = (a == b);
// result = (a == b);
// AssertionEvent(result, message);
//
emit
AssertionEvent(result, message);
//}
//}
// TODO: only for certain versions of solc
// TODO: only for certain versions of solc
//function equal(ufixed a, ufixed b, string message) public returns (bool result) {
//function equal(ufixed a, ufixed b, string message) public returns (bool result) {
// result = (a == b);
// result = (a == b);
// AssertionEvent(result, message);
//
emit
AssertionEvent(result, message);
//}
//}
function equal(address a, address b, string message) public returns (bool result) {
function equal(address a, address b, string message) public returns (bool result) {
result = (a == b);
result = (a == b);
AssertionEvent(result, message);
emit
AssertionEvent(result, message);
}
}
function equal(bytes32 a, bytes32 b, string message) public returns (bool result) {
function equal(bytes32 a, bytes32 b, string message) public returns (bool result) {
result = (a == b);
result = (a == b);
AssertionEvent(result, message);
emit
AssertionEvent(result, message);
}
}
// TODO: needs to be convert to bytes first to be comparable
// TODO: needs to be convert to bytes first to be comparable
//function equal(string a, string b, string message) public returns (bool result) {
//function equal(string a, string b, string message) public returns (bool result) {
// result = (a == b);
// result = (a == b);
// AssertionEvent(result, message);
//
emit
AssertionEvent(result, message);
//}
//}
function notEqual(uint a, uint b, string message) public returns (bool result) {
function notEqual(uint a, uint b, string message) public returns (bool result) {
result = (a != b);
result = (a != b);
AssertionEvent(result, message);
emit
AssertionEvent(result, message);
}
}
function notEqual(int a, int b, string message) public returns (bool result) {
function notEqual(int a, int b, string message) public returns (bool result) {
result = (a != b);
result = (a != b);
AssertionEvent(result, message);
emit
AssertionEvent(result, message);
}
}
function notEqual(bool a, bool b, string message) public returns (bool result) {
function notEqual(bool a, bool b, string message) public returns (bool result) {
result = (a != b);
result = (a != b);
AssertionEvent(result, message);
emit
AssertionEvent(result, message);
}
}
// TODO: only for certain versions of solc
// TODO: only for certain versions of solc
//function notEqual(fixed a, fixed b, string message) public returns (bool result) {
//function notEqual(fixed a, fixed b, string message) public returns (bool result) {
// result = (a != b);
// result = (a != b);
// AssertionEvent(result, message);
//
emit
AssertionEvent(result, message);
//}
//}
// TODO: only for certain versions of solc
// TODO: only for certain versions of solc
//function notEqual(ufixed a, ufixed b, string message) public returns (bool result) {
//function notEqual(ufixed a, ufixed b, string message) public returns (bool result) {
// result = (a != b);
// result = (a != b);
// AssertionEvent(result, message);
//
emit
AssertionEvent(result, message);
//}
//}
function notEqual(address a, address b, string message) public returns (bool result) {
function notEqual(address a, address b, string message) public returns (bool result) {
result = (a != b);
result = (a != b);
AssertionEvent(result, message);
emit
AssertionEvent(result, message);
}
}
function notEqual(bytes32 a, bytes32 b, string message) public returns (bool result) {
function notEqual(bytes32 a, bytes32 b, string message) public returns (bool result) {
result = (a != b);
result = (a != b);
AssertionEvent(result, message);
emit
AssertionEvent(result, message);
}
}
// TODO: needs to be convert to bytes first to be comparable
// TODO: needs to be convert to bytes first to be comparable
//function notEqual(string a, string b, string message) public returns (bool result) {
//function notEqual(string a, string b, string message) public returns (bool result) {
// result = (a != b);
// result = (a != b);
// AssertionEvent(result, message);
//
emit
AssertionEvent(result, message);
//}
//}
}
}
...
...
src/testRunner.js
View file @
1cab5245
...
@@ -7,7 +7,7 @@ function getAvailableFunctions (jsonInterface) {
...
@@ -7,7 +7,7 @@ function getAvailableFunctions (jsonInterface) {
}
}
function
getTestFunctions
(
jsonInterface
)
{
function
getTestFunctions
(
jsonInterface
)
{
let
specialFunctions
=
[
'beforeAll'
,
'beforeEach'
]
let
specialFunctions
=
[
'beforeAll'
,
'beforeEach'
,
'afterAll'
,
'afterEach'
]
return
jsonInterface
.
filter
((
x
)
=>
specialFunctions
.
indexOf
(
x
.
name
)
<
0
&&
x
.
type
===
'function'
)
return
jsonInterface
.
filter
((
x
)
=>
specialFunctions
.
indexOf
(
x
.
name
)
<
0
&&
x
.
type
===
'function'
)
}
}
...
@@ -25,6 +25,13 @@ function createRunList (jsonInterface) {
...
@@ -25,6 +25,13 @@ function createRunList (jsonInterface) {
runList
.
push
({
name
:
'beforeEach'
,
type
:
'internal'
,
constant
:
false
})
runList
.
push
({
name
:
'beforeEach'
,
type
:
'internal'
,
constant
:
false
})
}
}
runList
.
push
({
name
:
func
.
name
,
type
:
'test'
,
constant
:
func
.
constant
})
runList
.
push
({
name
:
func
.
name
,
type
:
'test'
,
constant
:
func
.
constant
})
if
(
availableFunctions
.
indexOf
(
'afterEach'
)
>=
0
)
{
runList
.
push
({
name
:
'afterEach'
,
type
:
'internal'
,
constant
:
false
})
}
}
if
(
availableFunctions
.
indexOf
(
'afterAll'
)
>=
0
)
{
runList
.
push
({
name
:
'afterAll'
,
type
:
'internal'
,
constant
:
false
})
}
}
return
runList
return
runList
...
...
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