Skip to content

Instantly share code, notes, and snippets.

@twxia
Last active January 11, 2019 09:00
Show Gist options
  • Save twxia/7ad4f15d7b5e285cd8f14255b5c097c3 to your computer and use it in GitHub Desktop.
Save twxia/7ad4f15d7b5e285cd8f14255b5c097c3 to your computer and use it in GitHub Desktop.
Wrap contract with web3.js v1.0.0 instead truffle-contract in truffle solidity unit testing
const Web3 = require('web3'); // v1.0.0
const Election = artifacts.require('ElectionMock');
contract ('Election', (accounts) => {
const web3 = new Web3(new Web3.providers.WebsocketProvider('ws://127.0.0.1:8545'));
let election;
before('setup web3 contract', async () => {
await Election.new();
});
beforeEach('setup contract for each test', async () => {
const deployedContract = await Election.deployed();
election = new web3.eth.Contract(
deployedContract.abi,
deployedContract.address,
)
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment