Unit tests

All Javascript mocha unit tests must be inside the tests directory in order to run. The tests are automatically run on parasol and are rerun on file changes in the tests, Solidity contracts or the parasol.js config file. Alternatively, you may run tests manually using parasol test. Unit tests in Parasol have no restrictions on file names or location inside the tests folder; they are disconnected from smart contract names and file names.


The following Javascript global variables are available for each mocha test:

web3 Object

web3 1.0 already attached to the Ganache provider and 10 generated accounts funded with 100 ETH each. Read the web3 1.0 docs for full API

contracts Object

Object of contract instances deployed on ganache. Key is relative location from contracts/ folder + ":" + contract name. Example: contracts['Folder/File.sol:Token'] would return the deployed instance of a Token contract located at /contracts/Folder/File.sol. Read the web3 1.0 docs for full API

address0 String

Short for 0x00000000000000000000000000000000000 also known as address(0) in solidity. Useful to reduce code redundancy.


Array of public Ethereum addresses of accounts attached to the above web3 instance.

assert Object|Function

The native Node.js assertion module required for basic unit tests. Read Node.js Docs for full API.

assertRevert(e) Function

Special assertion function used to assert failure of a web3 send transaction. Takes a Promise error as an argument. Useful for many unit test cases specific to smart contracts.


In order to demonstrate the utility of available JS global variables in Mocha tests, a sample unit test was embedded in the default project structure at /tests/Token.js:

describe('Token.sol', function() {
describe('Transfer()', function() {
it('should revert when transferred amount is smaller than 0', function() {
contracts['Token.sol:Token'].methods.transfer(address0, -1).send().on('error', (e) => assertRevert(e))

Notice the above test does not require() any of the modules it is using, because they are global variables. Of course, you can require() any additional npm modules you need.