Utility for creating a sandbox with contracts for testing purposes
npm i --save ganache-sandbox@https://github.com/pandoraboxchain/ganache-sandbox.git#v0.1.1
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.
Docker is required to running tests
npm test
npm run test-with-coverage