From 3a7bb97ad1182eb9c718797bda8dca5eb5d7f9cd Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Wed, 3 Oct 2018 16:21:17 -0700 Subject: Remove artifacts from migrations package and update contract-wrappers accordingly --- .../contract-wrappers/test/erc20_wrapper_test.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'packages/contract-wrappers/test/erc20_wrapper_test.ts') diff --git a/packages/contract-wrappers/test/erc20_wrapper_test.ts b/packages/contract-wrappers/test/erc20_wrapper_test.ts index fde587dec..9389ad626 100644 --- a/packages/contract-wrappers/test/erc20_wrapper_test.ts +++ b/packages/contract-wrappers/test/erc20_wrapper_test.ts @@ -1,4 +1,5 @@ import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils'; +import { getContractAddresses } from '@0xproject/migrations'; import { EmptyWalletSubprovider, Web3ProviderEngine } from '@0xproject/subproviders'; import { DoneCallback } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; @@ -10,14 +11,14 @@ import { BlockParamLiteral, BlockRange, ContractWrappers, + ContractWrappersConfig, ContractWrappersError, + DecodedLogEvent, ERC20TokenApprovalEventArgs, ERC20TokenEvents, ERC20TokenTransferEventArgs, } from '../src'; -import { DecodedLogEvent } from '../src/types'; - import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; import { tokenUtils } from './utils/token_utils'; @@ -33,10 +34,14 @@ describe('ERC20Wrapper', () => { let tokens: string[]; let coinbase: string; let addressWithoutFunds: string; - const config = { - networkId: constants.TESTRPC_NETWORK_ID, - }; + let config: ContractWrappersConfig; + before(async () => { + config = { + networkId: constants.TESTRPC_NETWORK_ID, + contractAddresses: getContractAddresses(), + blockPollingIntervalMs: 10, + }; contractWrappers = new ContractWrappers(provider, config); userAddresses = await web3Wrapper.getAvailableAddressesAsync(); tokens = tokenUtils.getDummyERC20TokenAddresses(); @@ -294,7 +299,7 @@ describe('ERC20Wrapper', () => { }); it('should reduce the gas cost for transfers including tokens with unlimited allowance support', async () => { const transferAmount = new BigNumber(5); - const zrxAddress = tokenUtils.getProtocolTokenAddress(); + const zrxAddress = getContractAddresses().zrxToken; const [, userWithNormalAllowance, userWithUnlimitedAllowance] = userAddresses; await contractWrappers.erc20Token.setAllowanceAsync( zrxAddress, @@ -539,7 +544,7 @@ describe('ERC20Wrapper', () => { callbackNeverToBeCalled, ); const callbackToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(); - contractWrappers.setProvider(provider, constants.TESTRPC_NETWORK_ID); + contractWrappers.setProvider(provider); contractWrappers.erc20Token.subscribe( tokenAddress, ERC20TokenEvents.Transfer, @@ -588,7 +593,7 @@ describe('ERC20Wrapper', () => { let txHash: string; before(() => { tokenAddress = tokens[0]; - tokenTransferProxyAddress = contractWrappers.erc20Proxy.getContractAddress(); + tokenTransferProxyAddress = contractWrappers.erc20Proxy.address; }); it('should get logs with decoded args emitted by Approval', async () => { txHash = await contractWrappers.erc20Token.setUnlimitedProxyAllowanceAsync(tokenAddress, coinbase); -- cgit From a48e0a08bf4ea8a8fb0f08cfe5187a6291378afb Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 9 Oct 2018 13:52:40 -0700 Subject: Add new runMigrationsOnce method to migrations. Update contract-wrappers to use it. --- packages/contract-wrappers/test/erc20_wrapper_test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'packages/contract-wrappers/test/erc20_wrapper_test.ts') diff --git a/packages/contract-wrappers/test/erc20_wrapper_test.ts b/packages/contract-wrappers/test/erc20_wrapper_test.ts index 9389ad626..a42650a63 100644 --- a/packages/contract-wrappers/test/erc20_wrapper_test.ts +++ b/packages/contract-wrappers/test/erc20_wrapper_test.ts @@ -1,7 +1,6 @@ import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils'; -import { getContractAddresses } from '@0xproject/migrations'; import { EmptyWalletSubprovider, Web3ProviderEngine } from '@0xproject/subproviders'; -import { DoneCallback } from '@0xproject/types'; +import { ContractAddresses, DoneCallback } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import { Provider } from 'ethereum-types'; @@ -21,6 +20,7 @@ import { import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; +import { migrateOnceAsync } from './utils/migrate'; import { tokenUtils } from './utils/token_utils'; import { provider, web3Wrapper } from './utils/web3_wrapper'; @@ -30,6 +30,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); describe('ERC20Wrapper', () => { let contractWrappers: ContractWrappers; + let contractAddresses: ContractAddresses; let userAddresses: string[]; let tokens: string[]; let coinbase: string; @@ -37,9 +38,10 @@ describe('ERC20Wrapper', () => { let config: ContractWrappersConfig; before(async () => { + contractAddresses = await migrateOnceAsync(); config = { networkId: constants.TESTRPC_NETWORK_ID, - contractAddresses: getContractAddresses(), + contractAddresses, blockPollingIntervalMs: 10, }; contractWrappers = new ContractWrappers(provider, config); @@ -299,7 +301,7 @@ describe('ERC20Wrapper', () => { }); it('should reduce the gas cost for transfers including tokens with unlimited allowance support', async () => { const transferAmount = new BigNumber(5); - const zrxAddress = getContractAddresses().zrxToken; + const zrxAddress = contractAddresses.zrxToken; const [, userWithNormalAllowance, userWithUnlimitedAllowance] = userAddresses; await contractWrappers.erc20Token.setAllowanceAsync( zrxAddress, -- cgit From 1e9ea09f087c7b3120e758d931a88812b655da08 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 9 Oct 2018 23:10:33 -0700 Subject: Introduce new contract-addresses package and use it everywhere --- packages/contract-wrappers/test/erc20_wrapper_test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages/contract-wrappers/test/erc20_wrapper_test.ts') diff --git a/packages/contract-wrappers/test/erc20_wrapper_test.ts b/packages/contract-wrappers/test/erc20_wrapper_test.ts index a42650a63..37a824120 100644 --- a/packages/contract-wrappers/test/erc20_wrapper_test.ts +++ b/packages/contract-wrappers/test/erc20_wrapper_test.ts @@ -1,6 +1,7 @@ +import { ContractAddresses } from '@0xproject/contract-addresses'; import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils'; import { EmptyWalletSubprovider, Web3ProviderEngine } from '@0xproject/subproviders'; -import { ContractAddresses, DoneCallback } from '@0xproject/types'; +import { DoneCallback } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import { Provider } from 'ethereum-types'; -- cgit From 6f8e98e53727a1efc08800017cf2bde38884c982 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 15 Oct 2018 17:35:25 -0700 Subject: In contract-wrappers, remove setProvider and add unsubscribeAll method. --- packages/contract-wrappers/test/erc20_wrapper_test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/contract-wrappers/test/erc20_wrapper_test.ts') diff --git a/packages/contract-wrappers/test/erc20_wrapper_test.ts b/packages/contract-wrappers/test/erc20_wrapper_test.ts index 37a824120..2cfa9f0b2 100644 --- a/packages/contract-wrappers/test/erc20_wrapper_test.ts +++ b/packages/contract-wrappers/test/erc20_wrapper_test.ts @@ -533,7 +533,7 @@ describe('ERC20Wrapper', () => { ); })().catch(done); }); - it('Outstanding subscriptions are cancelled when contractWrappers.setProvider called', (done: DoneCallback) => { + it('Outstanding subscriptions are cancelled when contractWrappers.unsubscribeAll called', (done: DoneCallback) => { (async () => { const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)( (_logEvent: DecodedLogEvent) => { @@ -547,7 +547,7 @@ describe('ERC20Wrapper', () => { callbackNeverToBeCalled, ); const callbackToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(); - contractWrappers.setProvider(provider); + contractWrappers.unsubscribeAll(); contractWrappers.erc20Token.subscribe( tokenAddress, ERC20TokenEvents.Transfer, -- cgit From 5bdfad9b415fc183102d5f5a7f3a08782921f003 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 16 Oct 2018 00:11:58 -0700 Subject: Remove ContractNotFound errors in contract-wrappers --- .../contract-wrappers/test/erc20_wrapper_test.ts | 33 ---------------------- 1 file changed, 33 deletions(-) (limited to 'packages/contract-wrappers/test/erc20_wrapper_test.ts') diff --git a/packages/contract-wrappers/test/erc20_wrapper_test.ts b/packages/contract-wrappers/test/erc20_wrapper_test.ts index 2cfa9f0b2..c065f4d63 100644 --- a/packages/contract-wrappers/test/erc20_wrapper_test.ts +++ b/packages/contract-wrappers/test/erc20_wrapper_test.ts @@ -80,19 +80,6 @@ describe('ERC20Wrapper', () => { contractWrappers.erc20Token.transferAsync(tokenAddress, fromAddress, toAddress, transferAmount), ).to.be.rejectedWith(ContractWrappersError.InsufficientBalanceForTransfer); }); - it('should throw a CONTRACT_DOES_NOT_EXIST error for a non-existent token contract', async () => { - const nonExistentTokenAddress = '0x9dd402f14d67e001d8efbe6583e51bf9706aa065'; - const fromAddress = coinbase; - const toAddress = coinbase; - return expect( - contractWrappers.erc20Token.transferAsync( - nonExistentTokenAddress, - fromAddress, - toAddress, - transferAmount, - ), - ).to.be.rejectedWith(ContractWrappersError.ERC20TokenContractDoesNotExist); - }); }); describe('#transferFromAsync', () => { let tokenAddress: string; @@ -197,19 +184,6 @@ describe('ERC20Wrapper', () => { const postBalance = await contractWrappers.erc20Token.getBalanceAsync(tokenAddress, toAddress); return expect(postBalance).to.be.bignumber.equal(transferAmount); }); - it('should throw a CONTRACT_DOES_NOT_EXIST error for a non-existent token contract', async () => { - const fromAddress = coinbase; - const nonExistentTokenAddress = '0x9dd402f14d67e001d8efbe6583e51bf9706aa065'; - return expect( - contractWrappers.erc20Token.transferFromAsync( - nonExistentTokenAddress, - fromAddress, - toAddress, - senderAddress, - new BigNumber(42), - ), - ).to.be.rejectedWith(ContractWrappersError.ERC20TokenContractDoesNotExist); - }); }); describe('#getBalanceAsync', () => { describe('With provider with accounts', () => { @@ -220,13 +194,6 @@ describe('ERC20Wrapper', () => { const expectedBalance = new BigNumber('1000000000000000000000000000'); return expect(balance).to.be.bignumber.equal(expectedBalance); }); - it('should throw a CONTRACT_DOES_NOT_EXIST error for a non-existent token contract', async () => { - const nonExistentTokenAddress = '0x9dd402f14d67e001d8efbe6583e51bf9706aa065'; - const ownerAddress = coinbase; - return expect( - contractWrappers.erc20Token.getBalanceAsync(nonExistentTokenAddress, ownerAddress), - ).to.be.rejectedWith(ContractWrappersError.ERC20TokenContractDoesNotExist); - }); it('should return a balance of 0 for a non-existent owner address', async () => { const tokenAddress = tokens[0]; const nonExistentOwner = '0x198c6ad858f213fb31b6fe809e25040e6b964593'; -- cgit