Appendix C. SimpleCoin Mocha unit testing suite

Listing C.1. SimpleCoinTests.js
const fs = require('fs'); const solc = require('solc'); const Web3 = require('web3'); const web3 = new Web3( new Web3.providers.HttpProvider("http://localhost:8545")); var assert = require('assert'); const source = fs.readFileSync('c:/Ethereum/mocha/SimpleCoin/SimpleCoin.sol', 'utf8'); const compiledContract = solc.compile(source, 1); const abi = compiledContract.contracts[':SimpleCoin'].interface; const bytecode = '0x' + compiledContract.contracts[':SimpleCoin'].bytecode; const gasEstimate = web3.eth.estimateGas({ data: bytecode }) + 100000; const SimpleCoinContractFactory = web3.eth.contract(JSON.parse(abi)); describe('SimpleCoin', function() { this.timeout(5000); ...

Get Building Ethereum Dapps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.