Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Utility for creating a sandbox with contracts for testing purposes

License

Notifications You must be signed in to change notification settings

pandoraboxchain/ganache-sandbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codacy Badge Codacy Badge Build Status

ganache-sandbox

Utility for creating a sandbox with contracts for testing purposes

Installing

npm i --save ganache-sandbox@https://github.com/pandoraboxchain/ganache-sandbox.git#v0.1.1

Usage

const GanacheNode = require('ganache-sandbox');
const contractsPath = '<full-path-to-contracts-dir>';

// Names of contracts which addresses you want to extract 
// during deployment process from migrations logs
const extract = ['MetaCoin', 'ConvertLib'];

const runner = async () => {

    const node = new GanacheNode({ path: contractsPath, extract });
    const server = await node.server;
    const provider = await node.provider;
    const contracts = await node.contracts;
    const addresses = await node.addresses;
    const publisher = await node.publisher;

    return {
        node,
        server,// Ganache server
        provider,// Web3 WebsocketProvider instance
        contracts,// Built contracts
        addresses,
        publisher
    };
};

runner()
    .then(sandbox => {
        console.log('Contracts:', Object.keys(sandbox));
        console.log('Extracted addresses:', addresses);
        console.log('Publisher address (from):', publisher);

        // ... doing tests

        // We need close all servers to finish tests gracefully
        sandbox.server.close(() => {
            console.log('All done!');
        });
    })
    .catch(console.error);

You can instantiate as much sandboxes as you need.

Testing

Docker is required to running tests

npm test
npm run test-with-coverage