Merge pull request #984 from ethereum/remix_tests_grt_lsrt

Remix tests greaterThan() & lesserThan() implementation
pull/7/head
yann300 6 years ago committed by GitHub
commit 3df28ddeec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      docs/unittesting_tab.md
  2. 19
      remix-tests/README.md
  3. 59
      remix-tests/sol/tests.sol.js
  4. 38
      remix-tests/tests/number/number_test.sol
  5. 30
      remix-tests/tests/testRunner.js

@ -16,9 +16,16 @@ Run Tests
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
----------------------
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)

@ -44,21 +44,22 @@ contract MyTest {
```
Available special functions:
* `beforeEach` - runs before each test
* `beforeAll` - runs before all tests
* `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`
| 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` |
### 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:

@ -97,5 +97,64 @@ library Assert {
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);
}
}
`

@ -0,0 +1,38 @@
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");
}
}

@ -95,8 +95,8 @@ describe('testRunner', function () {
})
})
// Test string comparision
describe('test with beforeAll', function () {
// Test string equality
describe('test string equality', function () {
let filename = 'tests/examples_3/simple_string_test.sol'
let tests = [], results = {}
@ -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)
})
})
})
})

Loading…
Cancel
Save