diff options
author | Fabio Berger <me@fabioberger.com> | 2018-04-12 07:53:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-12 07:53:32 +0800 |
commit | c47fb8f9a83d409c092dd7449054fa16cf0fa1c9 (patch) | |
tree | 3e5e1b9f8e4588f811b203806ffde6864f0e09de /packages/0x.js/test/token_wrapper_test.ts | |
parent | e8d4f6d5322930cf8618abcb9fea7c773a87ecd7 (diff) | |
parent | 27b915789efcacbeb0bfbe943f917c590cfaff4a (diff) | |
download | dexon-0x-contracts-c47fb8f9a83d409c092dd7449054fa16cf0fa1c9.tar.gz dexon-0x-contracts-c47fb8f9a83d409c092dd7449054fa16cf0fa1c9.tar.zst dexon-0x-contracts-c47fb8f9a83d409c092dd7449054fa16cf0fa1c9.zip |
Merge pull request #500 from 0xProject/removeMigrateStep
Run all tests against in-process Ganache
Diffstat (limited to 'packages/0x.js/test/token_wrapper_test.ts')
-rw-r--r-- | packages/0x.js/test/token_wrapper_test.ts | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts index 0c6335d5e..04fd943aa 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -1,9 +1,10 @@ -import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants } from '@0xproject/dev-utils'; +import { EmptyWalletSubprovider } from '@0xproject/subproviders'; +import { Provider } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; import 'mocha'; -import * as Web3 from 'web3'; +import Web3ProviderEngine = require('web3-provider-engine'); import { ApprovalContractEventArgs, @@ -22,7 +23,7 @@ import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; import { reportNodeCallbackErrors } from './utils/report_callback_errors'; import { TokenUtils } from './utils/token_utils'; -import { web3, web3Wrapper } from './utils/web3_wrapper'; +import { provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -39,7 +40,7 @@ describe('TokenWrapper', () => { networkId: constants.TESTRPC_NETWORK_ID, }; before(async () => { - zeroEx = new ZeroEx(web3.currentProvider, config); + zeroEx = new ZeroEx(provider, config); userAddresses = await zeroEx.getAvailableAddressesAsync(); tokens = await zeroEx.tokenRegistry.getTokensAsync(); tokenUtils = new TokenUtils(tokens); @@ -164,7 +165,7 @@ describe('TokenWrapper', () => { }); }); describe('#getBalanceAsync', () => { - describe('With web3 provider with accounts', () => { + describe('With provider with accounts', () => { it('should return the balance for an existing ERC20 token', async () => { const token = tokens[0]; const ownerAddress = coinbase; @@ -187,14 +188,14 @@ describe('TokenWrapper', () => { return expect(balance).to.be.bignumber.equal(expectedBalance); }); }); - describe('With web3 provider without accounts', () => { + describe('With provider without accounts', () => { let zeroExWithoutAccounts: ZeroEx; before(async () => { const hasAddresses = false; - const web3WithoutAccounts = web3Factory.create({ hasAddresses }); - zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider, config); + const emptyWalletProvider = addEmptyWalletSubprovider(provider); + zeroExWithoutAccounts = new ZeroEx(emptyWalletProvider, config); }); - it('should return balance even when called with Web3 provider instance without addresses', async () => { + it('should return balance even when called with provider instance without addresses', async () => { const token = tokens[0]; const ownerAddress = coinbase; const balance = await zeroExWithoutAccounts.token.getBalanceAsync(token.address, ownerAddress); @@ -277,7 +278,7 @@ describe('TokenWrapper', () => { }); }); describe('#getAllowanceAsync', () => { - describe('With web3 provider with accounts', () => { + describe('With provider with accounts', () => { it('should get the proxy allowance', async () => { const token = tokens[0]; const ownerAddress = coinbase; @@ -299,12 +300,12 @@ describe('TokenWrapper', () => { return expect(allowance).to.be.bignumber.equal(expectedAllowance); }); }); - describe('With web3 provider without accounts', () => { + describe('With provider without accounts', () => { let zeroExWithoutAccounts: ZeroEx; before(async () => { const hasAddresses = false; - const web3WithoutAccounts = web3Factory.create({ hasAddresses }); - zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider, config); + const emptyWalletProvider = addEmptyWalletSubprovider(provider); + zeroExWithoutAccounts = new ZeroEx(emptyWalletProvider, config); }); it('should get the proxy allowance', async () => { const token = tokens[0]; @@ -424,8 +425,7 @@ describe('TokenWrapper', () => { ); zeroEx.token.subscribe(tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackNeverToBeCalled); const callbackToBeCalled = reportNodeCallbackErrors(done)(); - const newProvider = web3Factory.getRpcProvider(); - zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID); + zeroEx.setProvider(provider, constants.TESTRPC_NETWORK_ID); zeroEx.token.subscribe(tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackToBeCalled); await zeroEx.token.transferAsync(tokenAddress, coinbase, addressWithoutFunds, transferAmount); })().catch(done); @@ -515,3 +515,14 @@ describe('TokenWrapper', () => { }); }); // tslint:disable:max-file-line-count + +function addEmptyWalletSubprovider(p: Provider): Provider { + const providerEngine = new Web3ProviderEngine(); + providerEngine.addProvider(new EmptyWalletSubprovider()); + const currentSubproviders = (p as any)._providers; + for (const subprovider of currentSubproviders) { + providerEngine.addProvider(subprovider); + } + providerEngine.start(); + return providerEngine; +} |