diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-01-19 22:34:28 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-01-30 23:01:36 +0800 |
commit | 709026bf1a49d468850b4ebed845c8598fa4fd75 (patch) | |
tree | 496c9889b0494112239cd720315b213a0b89befa /packages/contracts | |
parent | f2b2b867866faa92256bc175e651e038001cef4d (diff) | |
download | dexon-sol-tools-709026bf1a49d468850b4ebed845c8598fa4fd75.tar dexon-sol-tools-709026bf1a49d468850b4ebed845c8598fa4fd75.tar.gz dexon-sol-tools-709026bf1a49d468850b4ebed845c8598fa4fd75.tar.bz2 dexon-sol-tools-709026bf1a49d468850b4ebed845c8598fa4fd75.tar.lz dexon-sol-tools-709026bf1a49d468850b4ebed845c8598fa4fd75.tar.xz dexon-sol-tools-709026bf1a49d468850b4ebed845c8598fa4fd75.tar.zst dexon-sol-tools-709026bf1a49d468850b4ebed845c8598fa4fd75.zip |
Refactor contracts tests to not use injected web3 instance
Diffstat (limited to 'packages/contracts')
-rw-r--r-- | packages/contracts/test/ether_token.ts | 9 | ||||
-rw-r--r-- | packages/contracts/test/exchange/core.ts | 10 | ||||
-rw-r--r-- | packages/contracts/test/exchange/helpers.ts | 10 | ||||
-rw-r--r-- | packages/contracts/test/exchange/wrapper.ts | 9 | ||||
-rw-r--r-- | packages/contracts/test/multi_sig_with_time_lock.ts | 16 | ||||
-rw-r--r-- | packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts | 9 | ||||
-rw-r--r-- | packages/contracts/test/token_registry.ts | 9 | ||||
-rw-r--r-- | packages/contracts/test/token_transfer_proxy/auth.ts | 9 | ||||
-rw-r--r-- | packages/contracts/test/token_transfer_proxy/transfer_from.ts | 9 | ||||
-rw-r--r-- | packages/contracts/test/unlimited_allowance_token.ts | 9 | ||||
-rw-r--r-- | packages/contracts/test/unlimited_allowance_token_v2.ts | 7 | ||||
-rw-r--r-- | packages/contracts/test/zrx_token.ts | 21 | ||||
-rw-r--r-- | packages/contracts/util/constants.ts | 1 |
13 files changed, 46 insertions, 82 deletions
diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index 31c6c4ed6..eadeeaa57 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -1,9 +1,8 @@ import { ZeroEx, ZeroExError } from '0x.js'; -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber, promisify } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; -import * as Web3 from 'web3'; import { Artifacts } from '../util/artifacts'; import { constants } from '../util/constants'; @@ -15,10 +14,8 @@ const { EtherToken } = new Artifacts(artifacts); chaiSetup.configure(); const expect = chai.expect; -// 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); +const web3 = web3Factory.create(); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('EtherToken', () => { const web3Wrapper = new Web3Wrapper(web3.currentProvider); diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index 9a6b4dc83..4f55bc398 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -1,10 +1,9 @@ import { ZeroEx } from '0x.js'; -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; import ethUtil = require('ethereumjs-util'); -import * as Web3 from 'web3'; import { Artifacts } from '../../util/artifacts'; import { Balances } from '../../util/balances'; @@ -19,11 +18,8 @@ import { chaiSetup } from '../utils/chai_setup'; chaiSetup.configure(); const expect = chai.expect; const { Exchange, TokenTransferProxy, DummyToken, TokenRegistry, MaliciousToken } = new Artifacts(artifacts); - -// 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); +const web3 = web3Factory.create(); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('Exchange', () => { const web3Wrapper = new Web3Wrapper(web3.currentProvider); diff --git a/packages/contracts/test/exchange/helpers.ts b/packages/contracts/test/exchange/helpers.ts index f6e11f087..7af9866d5 100644 --- a/packages/contracts/test/exchange/helpers.ts +++ b/packages/contracts/test/exchange/helpers.ts @@ -1,13 +1,11 @@ import { ZeroEx } from '0x.js'; -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; import ethUtil = require('ethereumjs-util'); -import * as Web3 from 'web3'; import { Artifacts } from '../../util/artifacts'; -import { constants } from '../../util/constants'; import { ExchangeWrapper } from '../../util/exchange_wrapper'; import { Order } from '../../util/order'; import { OrderFactory } from '../../util/order_factory'; @@ -17,10 +15,8 @@ chaiSetup.configure(); const expect = chai.expect; const { Exchange, TokenRegistry } = new Artifacts(artifacts); -// 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); +const web3 = web3Factory.create(); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('Exchange', () => { const web3Wrapper = new Web3Wrapper(web3.currentProvider); diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 22deec01c..93f9bf876 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -1,10 +1,9 @@ import { ZeroEx } from '0x.js'; -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; import * as _ from 'lodash'; -import * as Web3 from 'web3'; import { Artifacts } from '../../util/artifacts'; import { Balances } from '../../util/balances'; @@ -18,10 +17,8 @@ import { chaiSetup } from '../utils/chai_setup'; chaiSetup.configure(); const expect = chai.expect; const { Exchange, TokenTransferProxy, DummyToken, TokenRegistry } = new Artifacts(artifacts); -// 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); +const web3 = web3Factory.create(); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('Exchange', () => { const web3Wrapper = new Web3Wrapper(web3.currentProvider); diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts index 03914786c..6590dccaa 100644 --- a/packages/contracts/test/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/multi_sig_with_time_lock.ts @@ -1,8 +1,7 @@ -import { BlockchainLifecycle, RPC } from '@0xproject/dev-utils'; -import { BigNumber, promisify } from '@0xproject/utils'; +import { BlockchainLifecycle, devConstants, RPC, web3Factory } from '@0xproject/dev-utils'; +import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; -import * as Web3 from 'web3'; import * as multiSigWalletJSON from '../../build/contracts/MultiSigWalletWithTimeLock.json'; import * as truffleConf from '../truffle.js'; @@ -19,10 +18,8 @@ const MULTI_SIG_ABI = (multiSigWalletJSON as any).abi; chaiSetup.configure(); const expect = chai.expect; -// 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); +const web3 = web3Factory.create(); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('MultiSigWalletWithTimeLock', () => { const web3Wrapper = new Web3Wrapper(web3.currentProvider); @@ -79,8 +76,9 @@ describe('MultiSigWalletWithTimeLock', () => { it('should set confirmation time with enough confirmations', async () => { const res = await multiSig.confirmTransaction(txId, { from: owners[1] }); expect(res.logs).to.have.length(2); - const blockNum = await promisify<number>(web3.eth.getBlockNumber)(); - const blockInfo = await promisify<Web3.BlockWithoutTransactionData>(web3.eth.getBlock)(blockNum); + + const blockNum = await web3Wrapper.getBlockNumberAsync(); + const blockInfo = await web3Wrapper.getBlockAsync(blockNum); const timestamp = new BigNumber(blockInfo.timestamp); const confirmationTimeBigNum = new BigNumber(await multiSig.confirmationTimes.call(txId)); diff --git a/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts b/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts index f8e8c1f8d..b10e260a2 100644 --- a/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts +++ b/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts @@ -1,7 +1,6 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; -import * as Web3 from 'web3'; import * as tokenTransferProxyJSON from '../../build/contracts/TokenTransferProxy.json'; import { Artifacts } from '../util/artifacts'; @@ -16,10 +15,8 @@ const PROXY_ABI = (tokenTransferProxyJSON as any).abi; chaiSetup.configure(); const expect = chai.expect; -// 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); +const web3 = web3Factory.create(); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => { const web3Wrapper = new Web3Wrapper(web3.currentProvider); diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts index bcb620e03..cc78feba3 100644 --- a/packages/contracts/test/token_registry.ts +++ b/packages/contracts/test/token_registry.ts @@ -1,10 +1,9 @@ import { ZeroEx } from '0x.js'; -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } 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'; @@ -16,10 +15,8 @@ import { chaiSetup } from './utils/chai_setup'; const { TokenRegistry } = new Artifacts(artifacts); chaiSetup.configure(); const expect = chai.expect; -// 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); +const web3 = web3Factory.create(); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('TokenRegistry', () => { const web3Wrapper = new Web3Wrapper(web3.currentProvider); diff --git a/packages/contracts/test/token_transfer_proxy/auth.ts b/packages/contracts/test/token_transfer_proxy/auth.ts index 399ad2080..65455ed9e 100644 --- a/packages/contracts/test/token_transfer_proxy/auth.ts +++ b/packages/contracts/test/token_transfer_proxy/auth.ts @@ -1,7 +1,6 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; -import * as Web3 from 'web3'; import { constants } from '../../util/constants'; import { ContractInstance } from '../../util/types'; @@ -10,10 +9,8 @@ import { chaiSetup } from '../utils/chai_setup'; chaiSetup.configure(); const expect = chai.expect; const TokenTransferProxy = artifacts.require('./db/TokenTransferProxy.sol'); -// 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); +const web3 = web3Factory.create(); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('TokenTransferProxy', () => { const web3Wrapper = new Web3Wrapper(web3.currentProvider); diff --git a/packages/contracts/test/token_transfer_proxy/transfer_from.ts b/packages/contracts/test/token_transfer_proxy/transfer_from.ts index 1a5151309..d1245d3b2 100644 --- a/packages/contracts/test/token_transfer_proxy/transfer_from.ts +++ b/packages/contracts/test/token_transfer_proxy/transfer_from.ts @@ -1,7 +1,6 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; -import * as Web3 from 'web3'; import { Artifacts } from '../../util/artifacts'; import { Balances } from '../../util/balances'; @@ -12,10 +11,8 @@ import { chaiSetup } from '../utils/chai_setup'; chaiSetup.configure(); const expect = chai.expect; const { TokenTransferProxy, DummyToken, TokenRegistry } = new Artifacts(artifacts); -// 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); +const web3 = web3Factory.create(); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('TokenTransferProxy', () => { const web3Wrapper = new Web3Wrapper(web3.currentProvider); diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index ca8ce4c50..36f88c3d2 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -1,9 +1,8 @@ import { ZeroEx } from '0x.js'; -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; -import * as Web3 from 'web3'; import { Artifacts } from '../util/artifacts'; import { constants } from '../util/constants'; @@ -12,12 +11,10 @@ import { ContractInstance } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; const { DummyToken } = new Artifacts(artifacts); -// 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 web3 = web3Factory.create(); chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('UnlimitedAllowanceToken', () => { const web3Wrapper = new Web3Wrapper(web3.currentProvider); diff --git a/packages/contracts/test/unlimited_allowance_token_v2.ts b/packages/contracts/test/unlimited_allowance_token_v2.ts index ebdc3ba11..3c4a8e941 100644 --- a/packages/contracts/test/unlimited_allowance_token_v2.ts +++ b/packages/contracts/test/unlimited_allowance_token_v2.ts @@ -1,9 +1,8 @@ import { ZeroEx } from '0x.js'; -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; -import * as Web3 from 'web3'; import { Artifacts } from '../util/artifacts'; import { constants } from '../util/constants'; @@ -14,8 +13,8 @@ import { chaiSetup } from './utils/chai_setup'; const { DummyTokenV2 } = new Artifacts(artifacts); chaiSetup.configure(); const expect = chai.expect; -const web3: Web3 = (global as any).web3; -const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL); +const web3 = web3Factory.create(); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('UnlimitedAllowanceTokenV2', () => { const web3Wrapper = new Web3Wrapper(web3.currentProvider); diff --git a/packages/contracts/test/zrx_token.ts b/packages/contracts/test/zrx_token.ts index fe251f53d..573fb8d5a 100644 --- a/packages/contracts/test/zrx_token.ts +++ b/packages/contracts/test/zrx_token.ts @@ -1,9 +1,8 @@ import { ZeroEx } from '0x.js'; -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; -import Web3 = require('web3'); import { Artifacts } from '../util/artifacts'; import { constants } from '../util/constants'; @@ -14,10 +13,8 @@ import { chaiSetup } from './utils/chai_setup'; chaiSetup.configure(); const expect = chai.expect; const { Exchange, ZRXToken } = new Artifacts(artifacts); -// 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); +const web3 = web3Factory.create(); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('ZRXToken', () => { const web3Wrapper = new Web3Wrapper(web3.currentProvider); @@ -140,10 +137,10 @@ describe('ZRXToken', () => { const initOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = MAX_UINT; - let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance, { + await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance, { gasLimit: constants.MAX_TOKEN_APPROVE_GAS, }); - txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { + await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); @@ -156,8 +153,8 @@ describe('ZRXToken', () => { const initSpenderBalance = await zeroEx.token.getBalanceAsync(zrxAddress, spender); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = initOwnerBalance; - let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance); - txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { + await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance); + await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); @@ -171,8 +168,8 @@ describe('ZRXToken', () => { it('should modify allowance if spender has sufficient allowance less than 2^256 - 1', async () => { const initOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); const amountToTransfer = initOwnerBalance; - let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer); - txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { + await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer); + await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); diff --git a/packages/contracts/util/constants.ts b/packages/contracts/util/constants.ts index d2a6352ed..e61b2f802 100644 --- a/packages/contracts/util/constants.ts +++ b/packages/contracts/util/constants.ts @@ -3,7 +3,6 @@ export const constants = { INVALID_OPCODE: 'invalid opcode', REVERT: 'revert', TESTRPC_NETWORK_ID: 50, - RPC_URL: 'http://localhost:8545', MAX_ETHERTOKEN_WITHDRAW_GAS: 43000, MAX_TOKEN_TRANSFERFROM_GAS: 80000, MAX_TOKEN_APPROVE_GAS: 60000, |