remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Iuri Matias cc8358c91b update to clarify test files must end with _test.sol 6 years ago
bin move index and run files 7 years ago
examples update example tests 7 years ago
sol fix linting 7 years ago
src Update compiler.js 6 years ago
tests add test case 6 years ago
.gitignore add download json script (for now) 7 years ago
.travis.yml add travis file 7 years ago
README.md update to clarify test files must end with _test.sol 6 years ago
package-lock.json update to 0.0.6 7 years ago
package.json update to 0.0.6 7 years ago

README.md

Build Status

Remix-Tests

Installation

npm -g install remix-tests

Test structure

Example test file:

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:

const RemixTests = require('remix-tests');

Running a single test object:

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:

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)