From 661029f7ccf8e28e87faf85bb451298b3b066bfa Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 19 Jan 2018 14:15:44 +0100 Subject: Remove truffle from TokenRegistry tests --- packages/contracts/test/token_registry.ts | 40 +++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts index 9ca18202f..1e01dcb6d 100644 --- a/packages/contracts/test/token_registry.ts +++ b/packages/contracts/test/token_registry.ts @@ -1,7 +1,10 @@ import { ZeroEx } from '0x.js'; +import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; import ethUtil = require('ethereumjs-util'); import * as _ from 'lodash'; +import * as Web3 from 'web3'; import { Artifacts } from '../util/artifacts'; import { constants } from '../util/constants'; @@ -13,10 +16,31 @@ import { chaiSetup } from './utils/chai_setup'; const { TokenRegistry } = new Artifacts(artifacts); chaiSetup.configure(); const expect = chai.expect; - -contract('TokenRegistry', (accounts: string[]) => { - const owner = accounts[0]; - const notOwner = accounts[1]; +// In order to benefit from type-safety, we re-assign the global web3 instance injected by Truffle +// with type `any` to a variable of type `Web3`. +const web3: Web3 = (global as any).web3; +const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL); + +describe('TokenRegistry', () => { + const web3Wrapper = new Web3Wrapper(web3.currentProvider); + let accounts: string[]; + let owner: string; + let notOwner: string; + let tokenReg: ContractInstance; + let tokenRegWrapper: TokenRegWrapper; + before(async () => { + accounts = await web3Wrapper.getAvailableAddressesAsync(); + owner = accounts[0]; + notOwner = accounts[1]; + tokenReg = await TokenRegistry.new(); + tokenRegWrapper = new TokenRegWrapper(tokenReg); + }); + beforeEach(async () => { + await blockchainLifecycle.startAsync(); + }); + afterEach(async () => { + await blockchainLifecycle.revertAsync(); + }); const tokenAddress1 = `0x${ethUtil.setLength(ethUtil.toBuffer('0x1'), 20, false).toString('hex')}`; const tokenAddress2 = `0x${ethUtil.setLength(ethUtil.toBuffer('0x2'), 20, false).toString('hex')}`; @@ -48,14 +72,6 @@ contract('TokenRegistry', (accounts: string[]) => { swarmHash: constants.NULL_BYTES, }; - let tokenReg: ContractInstance; - let tokenRegWrapper: TokenRegWrapper; - - beforeEach(async () => { - tokenReg = await TokenRegistry.new(); - tokenRegWrapper = new TokenRegWrapper(tokenReg); - }); - describe('addToken', () => { it('should throw when not called by owner', async () => { return expect(tokenRegWrapper.addTokenAsync(token1, notOwner)).to.be.rejectedWith(constants.REVERT); -- cgit