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
3df28dde
Unverified
Commit
3df28dde
authored
Sep 24, 2018
by
yann300
Committed by
GitHub
Sep 24, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #984 from ethereum/remix_tests_grt_lsrt
Remix tests greaterThan() & lesserThan() implementation
parents
46f71015
a16fe805
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
143 additions
and
12 deletions
+143
-12
unittesting_tab.md
docs/unittesting_tab.md
+8
-1
README.md
remix-tests/README.md
+10
-9
tests.sol.js
remix-tests/sol/tests.sol.js
+59
-0
number_test.sol
remix-tests/tests/number/number_test.sol
+38
-0
testRunner.js
remix-tests/tests/testRunner.js
+28
-2
No files found.
docs/unittesting_tab.md
View file @
3df28dde
...
@@ -16,9 +16,16 @@ Run Tests
...
@@ -16,9 +16,16 @@ Run Tests
This execute tests. The execution is run in a separate environment and the result is displayed below.
This execute tests. The execution is run in a separate environment and the result is displayed below.
| Available functions | Supported types |
| ------------- | ------------- |
|
`Assert.ok()`
|
`bool`
|
|
`Assert.equal()`
|
`uint`
,
`int`
,
`bool`
,
`address`
,
`bytes32`
,
`string`
|
|
`Assert.notEqual()`
|
`uint`
,
`int`
,
`bool`
,
`address`
,
`bytes32`
,
`string`
|
|
`Assert.greaterThan()`
|
`uint`
,
`int`
|
|
`Assert.lesserThan()`
|
`uint`
,
`int`
|
Continuous integration
Continuous integration
----------------------
----------------------
remix-tests is also a CLI, it can be used in a continuous integration environement which support node.js.
remix-tests is also a CLI, it can be used in a continuous integration environement which support node.js.
Please find more information in the
[
remix-test repository
](
https://github.com/ethereum/remix/tree/master/remix-tests
)
Please find more information in the
[
remix-test repository
](
https://github.com/ethereum/remix/tree/master/remix-tests
)
remix-tests/README.md
View file @
3df28dde
...
@@ -44,21 +44,22 @@ contract MyTest {
...
@@ -44,21 +44,22 @@ contract MyTest {
```
```
Available special functions:
Available special functions:
*
`beforeEach`
- runs before each test
*
`beforeEach
()
`
- runs before each test
*
`beforeAll`
- runs before all tests
*
`beforeAll
()
`
- runs before all tests
#### Assert library
#### Assert library
Available functions:
| Available functions | Supported types |
`Assert.ok(value, message)`
| ------------- | ------------- |
`Assert.equal(value1, value2, message)`
|
`Assert.ok()`
|
`bool`
|
`Assert.notEqual(value1, value2, message)`
|
`Assert.equal()`
|
`uint`
,
`int`
,
`bool`
,
`address`
,
`bytes32`
,
`string`
|
|
`Assert.notEqual()`
|
`uint`
,
`int`
,
`bool`
,
`address`
,
`bytes32`
,
`string`
|
supported values currently are:
`bool`
`uint`
`int`
`address`
`bytes32`
|
`Assert.greaterThan()`
|
`uint`
,
`int`
|
|
`Assert.lesserThan()`
|
`uint`
,
`int`
|
### Command Line
### Command Line
Remix-Tests will assume the tests will files whose name end with
"_test.sol"
. e.g
`simple_storage_test.sol`
Remix-Tests will assume the tests will files whose name end with
`"_test.sol"`
. e.g
`simple_storage_test.sol`
Usage:
Usage:
...
...
remix-tests/sol/tests.sol.js
View file @
3df28dde
...
@@ -97,5 +97,64 @@ library Assert {
...
@@ -97,5 +97,64 @@ library Assert {
AssertionEvent(result, message);
AssertionEvent(result, message);
}
}
/*----------------- Greater than --------------------*/
function greaterThan(uint a, uint b, string message) public constant returns (bool result) {
result = (a > b);
emit AssertionEvent(result, message);
}
function greaterThan(int a, int b, string message) public constant returns (bool result) {
result = (a > b);
emit AssertionEvent(result, message);
}
// TODO: safely compare between uint and int
function greaterThan(uint a, int b, string message) public constant returns (bool result) {
if(b < int(0)) {
// int is negative uint "a" always greater
result = true;
} else {
result = (a > uint(b));
}
emit AssertionEvent(result, message);
}
function greaterThan(int a, uint b, string message) public constant returns (bool result) {
if(a < int(0)) {
// int is negative uint "b" always greater
result = false;
} else {
result = (uint(a) > b);
}
emit AssertionEvent(result, message);
}
/*----------------- Lesser than --------------------*/
function lesserThan(uint a, uint b, string message) public constant returns (bool result) {
result = (a < b);
emit AssertionEvent(result, message);
}
function lesserThan(int a, int b, string message) public constant returns (bool result) {
result = (a < b);
emit AssertionEvent(result, message);
}
// TODO: safely compare between uint and int
function lesserThan(uint a, int b, string message) public constant returns (bool result) {
if(b < int(0)) {
// int is negative int "b" always lesser
result = false;
} else {
result = (a < uint(b));
}
emit AssertionEvent(result, message);
}
function lesserThan(int a, uint b, string message) public constant returns (bool result) {
if(a < int(0)) {
// int is negative int "a" always lesser
result = true;
} else {
result = (uint(a) < b);
}
emit AssertionEvent(result, message);
}
}
}
`
`
remix-tests/tests/number/number_test.sol
0 → 100644
View file @
3df28dde
pragma solidity ^0.4.24;
contract IntegerTest {
// GREATER THAN [>] tests
function _2_shouldBeGreaterThan_1() public constant returns (bool) {
return Assert.greaterThan(uint(2), uint(1), "2 is greater than 1");
}
function _0_shouldBeGreaterThan_neg_1() public constant returns (bool) {
return Assert.greaterThan(uint(0), int(-1), "0 is greater than -1");
}
function _neg_1_shouldNotBeGreaterThan_1() public constant returns (bool) {
return Assert.greaterThan(int(-1), uint(1), "-1 is not greater than 1");
}
function _1_shouldBeGreaterThan_neg_1() public constant returns (bool) {
return Assert.greaterThan(uint(1), int(-1), "1 is greater than -1");
}
// LESSER THAN [<] tests
function _1_shouldBeLesserThan_2() public constant returns (bool) {
return Assert.lesserThan(uint(1), uint(2), "1 is lesser than 2");
}
function _neg_1_shouldBeLesserThan_0() public constant returns (bool) {
return Assert.lesserThan(int(-1), uint(0), "-1 is lesser than 0");
}
function _neg_2_shouldBeLesserThan_neg_1() public constant returns (bool) {
return Assert.lesserThan(int(-2), int(-1), "-2 is lesser than -1");
}
function _0_shouldNotBeLesserThan_neg_1() public constant returns (bool) {
return Assert.lesserThan(uint(0), int(-1), "0 is not lesser than -1");
}
}
remix-tests/tests/testRunner.js
View file @
3df28dde
...
@@ -95,8 +95,8 @@ describe('testRunner', function () {
...
@@ -95,8 +95,8 @@ describe('testRunner', function () {
})
})
})
})
// Test string
comparision
// Test string
equality
describe
(
'test
with beforeAll
'
,
function
()
{
describe
(
'test
string equality
'
,
function
()
{
let
filename
=
'tests/examples_3/simple_string_test.sol'
let
filename
=
'tests/examples_3/simple_string_test.sol'
let
tests
=
[],
results
=
{}
let
tests
=
[],
results
=
{}
...
@@ -131,5 +131,31 @@ describe('testRunner', function () {
...
@@ -131,5 +131,31 @@ describe('testRunner', function () {
])
])
})
})
})
})
// Test signed/unsigned integer weight
describe
(
'test number weight'
,
function
()
{
let
filename
=
'tests/number/number_test.sol'
let
tests
=
[],
results
=
{}
before
(
function
(
done
)
{
compileAndDeploy
(
filename
,
function
(
_err
,
contracts
)
{
var
testCallback
=
function
(
test
)
{
tests
.
push
(
test
)
}
var
resultsCallback
=
function
(
_err
,
_results
)
{
results
=
_results
done
()
}
TestRunner
.
runTest
(
'IntegerTest'
,
contracts
.
IntegerTest
,
testCallback
,
resultsCallback
)
})
})
it
(
'should have 6 passing tests'
,
function
()
{
assert
.
equal
(
results
.
passingNum
,
6
)
})
it
(
'should have 2 failing tests'
,
function
()
{
assert
.
equal
(
results
.
failureNum
,
2
)
})
})
})
})
})
})
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