Skip to content

Testing

Timothy Wang edited this page May 21, 2018 · 2 revisions

Solidity

Truffle Test

see http://truffleframework.com/docs/getting_started/javascript-tests

To use OpenZeppelin test helpers, such as

EVMRevert.js
increaseTime.js
etc

First install OpenZeppelin

npm install -E openzeppelin-solidity

You need to configure babel to use helpers, see https://github.com/ventureum/VetXToken for configurations

Solidity Coverage

At Ventureum, solidity-coverage is used to report coverage of tests.

Install

$ npm install --save-dev solidity-coverage

Add coverage network configuration in truffle.js

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*"
    },
    coverage: {
      host: "localhost",
      network_id: "*",
      port: 8555,         // <-- If you change this, also set the port option in .solcover.js.
      gas: 0xfffffffffff, // <-- Use this high gas value
      gasPrice: 0x01      // <-- Use this low gas price
    },
    ...etc...
  }
};

Setup .solcover.js at your project root dir

module.exports = {
  port: 8555,
  testrpcOptions: '-p 8555 -e 10000000',
  copyPackages: ['openzeppelin-solidity', 'vetx-token']
}

Here we add testrpc options "-p 8555 -e 10000000" to use port 8555 and default balance 10000000. Also, to include solidity source files from node_modules, we use the copyPackages parameter.

Run

$ ./node_modules/.bin/solidity-coverage

To generate a report

First install istanbul

npm i istanbul --save-dev

Then generate a report using ./coverage.json file

istanbul report

Clone this wiki locally