From cb596c1413938ce23901135f8235bb813cc6e784 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 8 Dec 2017 18:01:40 +0300 Subject: Move more shared utils into utils package and reuse them --- packages/0x.js/test/ether_token_wrapper_test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/0x.js/test/ether_token_wrapper_test.ts') diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index d3e4439ee..e0d738f84 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -1,3 +1,4 @@ +import {BlockchainLifecycle} from '@0xproject/dev-utils'; import BigNumber from 'bignumber.js'; import * as chai from 'chai'; import 'mocha'; @@ -5,14 +6,13 @@ import * as Web3 from 'web3'; import {ZeroEx, ZeroExError} from '../src'; -import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; import {chaiSetup} from './utils/chai_setup'; import {constants} from './utils/constants'; import {web3Factory} from './utils/web3_factory'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(); +const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL); // Since the address depositing/withdrawing ETH/WETH also needs to pay gas costs for the transaction, // a small amount of ETH will be used to pay this gas cost. We therefore check that the difference between -- cgit From 1f748afed96ed40d1ee61b970e8c6fe2a75fa382 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Sun, 17 Dec 2017 00:32:53 -0600 Subject: Modify the etherToken wrapper methods to accept an etherTokenAddress as the first arg. Since it is becoming apparent we will be updating the canonical WETH contract, we want users of 0x.js to be able to interact with n number of etherTokens without re-instantiating for each one. --- packages/0x.js/test/ether_token_wrapper_test.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'packages/0x.js/test/ether_token_wrapper_test.ts') diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index e0d738f84..b5ed19308 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -5,6 +5,7 @@ import 'mocha'; import * as Web3 from 'web3'; import {ZeroEx, ZeroExError} from '../src'; +import {artifacts} from '../src/artifacts'; import {chaiSetup} from './utils/chai_setup'; import {constants} from './utils/constants'; @@ -38,7 +39,7 @@ describe('EtherTokenWrapper', () => { zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig); userAddresses = await zeroEx.getAvailableAddressesAsync(); addressWithETH = userAddresses[0]; - wethContractAddress = zeroEx.etherToken.getContractAddress(); + wethContractAddress = (zeroEx.etherToken as any)._getContractAddress(artifacts.EtherTokenArtifact); depositWeiAmount = (zeroEx as any)._web3Wrapper.toWei(new BigNumber(5)); decimalPlaces = 7; }); @@ -55,7 +56,7 @@ describe('EtherTokenWrapper', () => { expect(preETHBalance).to.be.bignumber.gt(0); expect(preWETHBalance).to.be.bignumber.equal(0); - const txHash = await zeroEx.etherToken.depositAsync(depositWeiAmount, addressWithETH); + const txHash = await zeroEx.etherToken.depositAsync(wethContractAddress, depositWeiAmount, addressWithETH); await zeroEx.awaitTransactionMinedAsync(txHash); const postETHBalanceInWei = await (zeroEx as any)._web3Wrapper.getBalanceInWeiAsync(addressWithETH); @@ -73,7 +74,7 @@ describe('EtherTokenWrapper', () => { const overETHBalanceinWei = preETHBalance.add(extraETHBalance); return expect( - zeroEx.etherToken.depositAsync(overETHBalanceinWei, addressWithETH), + zeroEx.etherToken.depositAsync(wethContractAddress, overETHBalanceinWei, addressWithETH), ).to.be.rejectedWith(ZeroExError.InsufficientEthBalanceForDeposit); }); }); @@ -81,7 +82,7 @@ describe('EtherTokenWrapper', () => { it('should successfully withdraw ETH in return for Wrapped ETH tokens', async () => { const ETHBalanceInWei = await (zeroEx as any)._web3Wrapper.getBalanceInWeiAsync(addressWithETH); - await zeroEx.etherToken.depositAsync(depositWeiAmount, addressWithETH); + await zeroEx.etherToken.depositAsync(wethContractAddress, depositWeiAmount, addressWithETH); const expectedPreETHBalance = ETHBalanceInWei.minus(depositWeiAmount); const preETHBalance = await (zeroEx as any)._web3Wrapper.getBalanceInWeiAsync(addressWithETH); @@ -90,7 +91,7 @@ describe('EtherTokenWrapper', () => { expect(gasCost).to.be.bignumber.lte(MAX_REASONABLE_GAS_COST_IN_WEI); expect(preWETHBalance).to.be.bignumber.equal(depositWeiAmount); - const txHash = await zeroEx.etherToken.withdrawAsync(depositWeiAmount, addressWithETH); + const txHash = await zeroEx.etherToken.withdrawAsync(wethContractAddress, depositWeiAmount, addressWithETH); await zeroEx.awaitTransactionMinedAsync(txHash); const postETHBalance = await (zeroEx as any)._web3Wrapper.getBalanceInWeiAsync(addressWithETH); @@ -108,7 +109,7 @@ describe('EtherTokenWrapper', () => { const overWETHBalance = preWETHBalance.add(999999999); return expect( - zeroEx.etherToken.withdrawAsync(overWETHBalance, addressWithETH), + zeroEx.etherToken.withdrawAsync(wethContractAddress, overWETHBalance, addressWithETH), ).to.be.rejectedWith(ZeroExError.InsufficientWEthBalanceForWithdrawal); }); }); -- cgit From 613fada49f9d168fb949a370b884367f99deb401 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 19 Dec 2017 14:15:14 +0100 Subject: Add etherToken.getLogsAsync and etherToken.subscribe with tests --- packages/0x.js/test/ether_token_wrapper_test.ts | 171 +++++++++++++++++++++++- 1 file changed, 170 insertions(+), 1 deletion(-) (limited to 'packages/0x.js/test/ether_token_wrapper_test.ts') diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index b5ed19308..cdb6ef3b6 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -4,11 +4,23 @@ import * as chai from 'chai'; import 'mocha'; import * as Web3 from 'web3'; -import {ZeroEx, ZeroExError} from '../src'; +import { + ApprovalContractEventArgs, + BlockParamLiteral, + BlockRange, + DecodedLogEvent, + EtherTokenEvents, + Token, + TransferContractEventArgs, + ZeroEx, + ZeroExError, +} from '../src'; import {artifacts} from '../src/artifacts'; +import {DoneCallback} from '../src/types'; import {chaiSetup} from './utils/chai_setup'; import {constants} from './utils/constants'; +import {TokenUtils} from './utils/token_utils'; import {web3Factory} from './utils/web3_factory'; chaiSetup.configure(); @@ -24,11 +36,13 @@ const MAX_REASONABLE_GAS_COST_IN_WEI = 62517; describe('EtherTokenWrapper', () => { let web3: Web3; let zeroEx: ZeroEx; + let tokens: Token[]; let userAddresses: string[]; let addressWithETH: string; let wethContractAddress: string; let depositWeiAmount: BigNumber; let decimalPlaces: number; + let addressWithoutFunds: string; const gasPrice = new BigNumber(1); const zeroExConfig = { gasPrice, @@ -37,11 +51,13 @@ describe('EtherTokenWrapper', () => { before(async () => { web3 = web3Factory.create(); zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig); + tokens = await zeroEx.tokenRegistry.getTokensAsync(); userAddresses = await zeroEx.getAvailableAddressesAsync(); addressWithETH = userAddresses[0]; wethContractAddress = (zeroEx.etherToken as any)._getContractAddress(artifacts.EtherTokenArtifact); depositWeiAmount = (zeroEx as any)._web3Wrapper.toWei(new BigNumber(5)); decimalPlaces = 7; + addressWithoutFunds = userAddresses[1]; }); beforeEach(async () => { await blockchainLifecycle.startAsync(); @@ -113,4 +129,157 @@ describe('EtherTokenWrapper', () => { ).to.be.rejectedWith(ZeroExError.InsufficientWEthBalanceForWithdrawal); }); }); + describe('#subscribe', () => { + const indexFilterValues = {}; + let etherTokenAddress: string; + const transferAmount = new BigNumber(42); + const allowanceAmount = new BigNumber(42); + before(() => { + const tokenUtils = new TokenUtils(tokens); + const etherToken = tokenUtils.getWethTokenOrThrow(); + etherTokenAddress = etherToken.address; + }); + afterEach(() => { + zeroEx.etherToken.unsubscribeAll(); + }); + // Hack: Mocha does not allow a test to be both async and have a `done` callback + // Since we need to await the receipt of the event in the `subscribe` callback, + // we do need both. A hack is to make the top-level a sync fn w/ a done callback and then + // wrap the rest of the test in an async block + // Source: https://github.com/mochajs/mocha/issues/2407 + it('Should receive the Transfer event when tokens are transfered', (done: DoneCallback) => { + (async () => { + const callback = (err: Error, logEvent: DecodedLogEvent) => { + expect(logEvent).to.not.be.undefined(); + expect(logEvent.isRemoved).to.be.false(); + expect(logEvent.log.logIndex).to.be.equal(0); + expect(logEvent.log.transactionIndex).to.be.equal(0); + expect(logEvent.log.blockNumber).to.be.a('number'); + const args = logEvent.log.args; + expect(args._from).to.be.equal(addressWithETH); + expect(args._to).to.be.equal(addressWithoutFunds); + expect(args._value).to.be.bignumber.equal(transferAmount); + done(); + }; + await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH); + zeroEx.etherToken.subscribe( + etherTokenAddress, EtherTokenEvents.Transfer, indexFilterValues, callback); + await zeroEx.token.transferAsync( + etherTokenAddress, addressWithETH, addressWithoutFunds, transferAmount, + ); + })().catch(done); + }); + it('Should receive the Approval event when allowance is being set', (done: DoneCallback) => { + (async () => { + const callback = (err: Error, logEvent: DecodedLogEvent) => { + expect(logEvent).to.not.be.undefined(); + expect(logEvent.isRemoved).to.be.false(); + const args = logEvent.log.args; + expect(args._owner).to.be.equal(addressWithETH); + expect(args._spender).to.be.equal(addressWithoutFunds); + expect(args._value).to.be.bignumber.equal(allowanceAmount); + done(); + }; + zeroEx.etherToken.subscribe( + etherTokenAddress, EtherTokenEvents.Approval, indexFilterValues, callback); + await zeroEx.token.setAllowanceAsync( + etherTokenAddress, addressWithETH, addressWithoutFunds, allowanceAmount, + ); + })().catch(done); + }); + it('Outstanding subscriptions are cancelled when zeroEx.setProvider called', (done: DoneCallback) => { + (async () => { + const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent) => { + done(new Error('Expected this subscription to have been cancelled')); + }; + zeroEx.etherToken.subscribe( + etherTokenAddress, EtherTokenEvents.Transfer, indexFilterValues, callbackNeverToBeCalled, + ); + const callbackToBeCalled = (err: Error, logEvent: DecodedLogEvent) => { + done(); + }; + const newProvider = web3Factory.getRpcProvider(); + zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID); + await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH); + zeroEx.etherToken.subscribe( + etherTokenAddress, EtherTokenEvents.Transfer, indexFilterValues, callbackToBeCalled, + ); + await zeroEx.token.transferAsync( + etherTokenAddress, addressWithETH, addressWithoutFunds, transferAmount, + ); + })().catch(done); + }); + it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => { + (async () => { + const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent) => { + done(new Error('Expected this subscription to have been cancelled')); + }; + await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH); + const subscriptionToken = zeroEx.etherToken.subscribe( + etherTokenAddress, EtherTokenEvents.Transfer, indexFilterValues, callbackNeverToBeCalled); + zeroEx.etherToken.unsubscribe(subscriptionToken); + await zeroEx.token.transferAsync( + etherTokenAddress, addressWithETH, addressWithoutFunds, transferAmount, + ); + done(); + })().catch(done); + }); + }); + describe('#getLogsAsync', () => { + let etherTokenAddress: string; + let tokenTransferProxyAddress: string; + const blockRange: BlockRange = { + fromBlock: 0, + toBlock: BlockParamLiteral.Latest, + }; + let txHash: string; + before(() => { + addressWithETH = userAddresses[0]; + const tokenUtils = new TokenUtils(tokens); + const etherToken = tokenUtils.getWethTokenOrThrow(); + etherTokenAddress = etherToken.address; + tokenTransferProxyAddress = zeroEx.proxy.getContractAddress(); + }); + it('should get logs with decoded args emitted by Approval', async () => { + txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(etherTokenAddress, addressWithETH); + await zeroEx.awaitTransactionMinedAsync(txHash); + const eventName = EtherTokenEvents.Approval; + const indexFilterValues = {}; + const logs = await zeroEx.etherToken.getLogsAsync( + etherTokenAddress, eventName, blockRange, indexFilterValues, + ); + expect(logs).to.have.length(1); + const args = logs[0].args; + expect(logs[0].event).to.be.equal(eventName); + expect(args._owner).to.be.equal(addressWithETH); + expect(args._spender).to.be.equal(tokenTransferProxyAddress); + expect(args._value).to.be.bignumber.equal(zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS); + }); + it('should only get the logs with the correct event name', async () => { + txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(etherTokenAddress, addressWithETH); + await zeroEx.awaitTransactionMinedAsync(txHash); + const differentEventName = EtherTokenEvents.Transfer; + const indexFilterValues = {}; + const logs = await zeroEx.etherToken.getLogsAsync( + etherTokenAddress, differentEventName, blockRange, indexFilterValues, + ); + expect(logs).to.have.length(0); + }); + it('should only get the logs with the correct indexed fields', async () => { + txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(etherTokenAddress, addressWithETH); + await zeroEx.awaitTransactionMinedAsync(txHash); + txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(etherTokenAddress, addressWithoutFunds); + await zeroEx.awaitTransactionMinedAsync(txHash); + const eventName = EtherTokenEvents.Approval; + const indexFilterValues = { + _owner: addressWithETH, + }; + const logs = await zeroEx.etherToken.getLogsAsync( + etherTokenAddress, eventName, blockRange, indexFilterValues, + ); + expect(logs).to.have.length(1); + const args = logs[0].args; + expect(args._owner).to.be.equal(addressWithETH); + }); + }); }); -- cgit From 78eb79396efcdf803d5be054b28816967fd340e0 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 19 Dec 2017 20:12:46 +0100 Subject: Fix a typo --- packages/0x.js/test/ether_token_wrapper_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/0x.js/test/ether_token_wrapper_test.ts') diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index cdb6ef3b6..f3feb39c6 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -144,7 +144,7 @@ describe('EtherTokenWrapper', () => { }); // Hack: Mocha does not allow a test to be both async and have a `done` callback // Since we need to await the receipt of the event in the `subscribe` callback, - // we do need both. A hack is to make the top-level a sync fn w/ a done callback and then + // we do need both. A hack is to make the top-level async fn w/ a done callback and then // wrap the rest of the test in an async block // Source: https://github.com/mochajs/mocha/issues/2407 it('Should receive the Transfer event when tokens are transfered', (done: DoneCallback) => { -- cgit From d639a22cffebed137d703ad76b30f5bcb42de9a4 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 20 Dec 2017 14:01:35 +0100 Subject: Add WETH9 tests --- packages/0x.js/test/ether_token_wrapper_test.ts | 58 ++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'packages/0x.js/test/ether_token_wrapper_test.ts') diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index f3feb39c6..03f5216ee 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -9,9 +9,11 @@ import { BlockParamLiteral, BlockRange, DecodedLogEvent, + DepositContractEventArgs, EtherTokenEvents, Token, TransferContractEventArgs, + WithdrawalContractEventArgs, ZeroEx, ZeroExError, } from '../src'; @@ -48,6 +50,10 @@ describe('EtherTokenWrapper', () => { gasPrice, networkId: constants.TESTRPC_NETWORK_ID, }; + const transferAmount = new BigNumber(42); + const allowanceAmount = new BigNumber(42); + const depositAmount = new BigNumber(42); + const withdrawalAmount = new BigNumber(42); before(async () => { web3 = web3Factory.create(); zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig); @@ -132,8 +138,6 @@ describe('EtherTokenWrapper', () => { describe('#subscribe', () => { const indexFilterValues = {}; let etherTokenAddress: string; - const transferAmount = new BigNumber(42); - const allowanceAmount = new BigNumber(42); before(() => { const tokenUtils = new TokenUtils(tokens); const etherToken = tokenUtils.getWethTokenOrThrow(); @@ -187,6 +191,43 @@ describe('EtherTokenWrapper', () => { ); })().catch(done); }); + it('Should receive the Deposit event when ether is being deposited', (done: DoneCallback) => { + (async () => { + const callback = (err: Error, logEvent: DecodedLogEvent) => { + expect(logEvent).to.not.be.undefined(); + expect(logEvent.isRemoved).to.be.false(); + const args = logEvent.log.args; + expect(args._owner).to.be.equal(addressWithETH); + expect(args._value).to.be.bignumber.equal(depositAmount); + done(); + }; + zeroEx.etherToken.subscribe( + etherTokenAddress, EtherTokenEvents.Deposit, indexFilterValues, callback); + await zeroEx.etherToken.depositAsync( + etherTokenAddress, depositAmount, addressWithETH, + ); + })().catch(done); + }); + it('Should receive the Withdrawal event when ether is being withdrewn', (done: DoneCallback) => { + (async () => { + const callback = (err: Error, logEvent: DecodedLogEvent) => { + expect(logEvent).to.not.be.undefined(); + expect(logEvent.isRemoved).to.be.false(); + const args = logEvent.log.args; + expect(args._owner).to.be.equal(addressWithETH); + expect(args._value).to.be.bignumber.equal(depositAmount); + done(); + }; + await zeroEx.etherToken.depositAsync( + etherTokenAddress, depositAmount, addressWithETH, + ); + zeroEx.etherToken.subscribe( + etherTokenAddress, EtherTokenEvents.Withdrawal, indexFilterValues, callback); + await zeroEx.etherToken.withdrawAsync( + etherTokenAddress, withdrawalAmount, addressWithETH, + ); + })().catch(done); + }); it('Outstanding subscriptions are cancelled when zeroEx.setProvider called', (done: DoneCallback) => { (async () => { const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent) => { @@ -255,6 +296,19 @@ describe('EtherTokenWrapper', () => { expect(args._spender).to.be.equal(tokenTransferProxyAddress); expect(args._value).to.be.bignumber.equal(zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS); }); + it('should get logs with decoded args emitted by Deposit', async () => { + await zeroEx.etherToken.depositAsync(etherTokenAddress, depositAmount, addressWithETH); + const eventName = EtherTokenEvents.Deposit; + const indexFilterValues = {}; + const logs = await zeroEx.etherToken.getLogsAsync( + etherTokenAddress, eventName, blockRange, indexFilterValues, + ); + expect(logs).to.have.length(1); + const args = logs[0].args; + expect(logs[0].event).to.be.equal(eventName); + expect(args._owner).to.be.equal(addressWithETH); + expect(args._value).to.be.bignumber.equal(depositAmount); + }); it('should only get the logs with the correct event name', async () => { txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(etherTokenAddress, addressWithETH); await zeroEx.awaitTransactionMinedAsync(txHash); -- cgit From 2a7cafbf20e4ceb42ab79303213a324261dadc0c Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 20 Dec 2017 14:44:54 +0100 Subject: Add err==null assertions --- packages/0x.js/test/ether_token_wrapper_test.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'packages/0x.js/test/ether_token_wrapper_test.ts') diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index 03f5216ee..b64c53283 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -154,6 +154,7 @@ describe('EtherTokenWrapper', () => { it('Should receive the Transfer event when tokens are transfered', (done: DoneCallback) => { (async () => { const callback = (err: Error, logEvent: DecodedLogEvent) => { + expect(err).to.be.null(); expect(logEvent).to.not.be.undefined(); expect(logEvent.isRemoved).to.be.false(); expect(logEvent.log.logIndex).to.be.equal(0); @@ -176,6 +177,7 @@ describe('EtherTokenWrapper', () => { it('Should receive the Approval event when allowance is being set', (done: DoneCallback) => { (async () => { const callback = (err: Error, logEvent: DecodedLogEvent) => { + expect(err).to.be.null(); expect(logEvent).to.not.be.undefined(); expect(logEvent.isRemoved).to.be.false(); const args = logEvent.log.args; @@ -194,6 +196,7 @@ describe('EtherTokenWrapper', () => { it('Should receive the Deposit event when ether is being deposited', (done: DoneCallback) => { (async () => { const callback = (err: Error, logEvent: DecodedLogEvent) => { + expect(err).to.be.null(); expect(logEvent).to.not.be.undefined(); expect(logEvent.isRemoved).to.be.false(); const args = logEvent.log.args; @@ -211,6 +214,7 @@ describe('EtherTokenWrapper', () => { it('Should receive the Withdrawal event when ether is being withdrewn', (done: DoneCallback) => { (async () => { const callback = (err: Error, logEvent: DecodedLogEvent) => { + expect(err).to.be.null(); expect(logEvent).to.not.be.undefined(); expect(logEvent.isRemoved).to.be.false(); const args = logEvent.log.args; -- cgit From 01bc254cd0cc96d2657aec61a21bddae44bb5d0e Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 20 Dec 2017 14:45:13 +0100 Subject: Fix a typo --- packages/0x.js/test/ether_token_wrapper_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/0x.js/test/ether_token_wrapper_test.ts') diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index b64c53283..4d12f9f88 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -211,7 +211,7 @@ describe('EtherTokenWrapper', () => { ); })().catch(done); }); - it('Should receive the Withdrawal event when ether is being withdrewn', (done: DoneCallback) => { + it('Should receive the Withdrawal event when ether is being withdrawn', (done: DoneCallback) => { (async () => { const callback = (err: Error, logEvent: DecodedLogEvent) => { expect(err).to.be.null(); -- cgit From 455f74d449738d43abb5caee3aa02ea86286866c Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 20 Dec 2017 14:45:35 +0100 Subject: Fix test description --- packages/0x.js/test/ether_token_wrapper_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/0x.js/test/ether_token_wrapper_test.ts') diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index 4d12f9f88..4fcb37409 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -232,7 +232,7 @@ describe('EtherTokenWrapper', () => { ); })().catch(done); }); - it('Outstanding subscriptions are cancelled when zeroEx.setProvider called', (done: DoneCallback) => { + it('should cancel outstanding subscriptions when ZeroEx.setProvider is called', (done: DoneCallback) => { (async () => { const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent) => { done(new Error('Expected this subscription to have been cancelled')); -- cgit From e744e4cd989bd3ae1070c59f7baa8097f18b8b06 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 22 Dec 2017 15:05:32 +0100 Subject: Apply prettier config --- packages/0x.js/test/ether_token_wrapper_test.ts | 95 ++++++++++++++++--------- 1 file changed, 62 insertions(+), 33 deletions(-) (limited to 'packages/0x.js/test/ether_token_wrapper_test.ts') diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index 4fcb37409..b39481b55 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -1,4 +1,4 @@ -import {BlockchainLifecycle} from '@0xproject/dev-utils'; +import { BlockchainLifecycle } from '@0xproject/dev-utils'; import BigNumber from 'bignumber.js'; import * as chai from 'chai'; import 'mocha'; @@ -17,13 +17,13 @@ import { ZeroEx, ZeroExError, } from '../src'; -import {artifacts} from '../src/artifacts'; -import {DoneCallback} from '../src/types'; +import { artifacts } from '../src/artifacts'; +import { DoneCallback } from '../src/types'; -import {chaiSetup} from './utils/chai_setup'; -import {constants} from './utils/constants'; -import {TokenUtils} from './utils/token_utils'; -import {web3Factory} from './utils/web3_factory'; +import { chaiSetup } from './utils/chai_setup'; +import { constants } from './utils/constants'; +import { TokenUtils } from './utils/token_utils'; +import { web3Factory } from './utils/web3_factory'; chaiSetup.configure(); const expect = chai.expect; @@ -167,10 +167,12 @@ describe('EtherTokenWrapper', () => { done(); }; await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH); - zeroEx.etherToken.subscribe( - etherTokenAddress, EtherTokenEvents.Transfer, indexFilterValues, callback); + zeroEx.etherToken.subscribe(etherTokenAddress, EtherTokenEvents.Transfer, indexFilterValues, callback); await zeroEx.token.transferAsync( - etherTokenAddress, addressWithETH, addressWithoutFunds, transferAmount, + etherTokenAddress, + addressWithETH, + addressWithoutFunds, + transferAmount, ); })().catch(done); }); @@ -186,10 +188,12 @@ describe('EtherTokenWrapper', () => { expect(args._value).to.be.bignumber.equal(allowanceAmount); done(); }; - zeroEx.etherToken.subscribe( - etherTokenAddress, EtherTokenEvents.Approval, indexFilterValues, callback); + zeroEx.etherToken.subscribe(etherTokenAddress, EtherTokenEvents.Approval, indexFilterValues, callback); await zeroEx.token.setAllowanceAsync( - etherTokenAddress, addressWithETH, addressWithoutFunds, allowanceAmount, + etherTokenAddress, + addressWithETH, + addressWithoutFunds, + allowanceAmount, ); })().catch(done); }); @@ -204,11 +208,8 @@ describe('EtherTokenWrapper', () => { expect(args._value).to.be.bignumber.equal(depositAmount); done(); }; - zeroEx.etherToken.subscribe( - etherTokenAddress, EtherTokenEvents.Deposit, indexFilterValues, callback); - await zeroEx.etherToken.depositAsync( - etherTokenAddress, depositAmount, addressWithETH, - ); + zeroEx.etherToken.subscribe(etherTokenAddress, EtherTokenEvents.Deposit, indexFilterValues, callback); + await zeroEx.etherToken.depositAsync(etherTokenAddress, depositAmount, addressWithETH); })().catch(done); }); it('Should receive the Withdrawal event when ether is being withdrawn', (done: DoneCallback) => { @@ -222,14 +223,14 @@ describe('EtherTokenWrapper', () => { expect(args._value).to.be.bignumber.equal(depositAmount); done(); }; - await zeroEx.etherToken.depositAsync( - etherTokenAddress, depositAmount, addressWithETH, - ); + await zeroEx.etherToken.depositAsync(etherTokenAddress, depositAmount, addressWithETH); zeroEx.etherToken.subscribe( - etherTokenAddress, EtherTokenEvents.Withdrawal, indexFilterValues, callback); - await zeroEx.etherToken.withdrawAsync( - etherTokenAddress, withdrawalAmount, addressWithETH, + etherTokenAddress, + EtherTokenEvents.Withdrawal, + indexFilterValues, + callback, ); + await zeroEx.etherToken.withdrawAsync(etherTokenAddress, withdrawalAmount, addressWithETH); })().catch(done); }); it('should cancel outstanding subscriptions when ZeroEx.setProvider is called', (done: DoneCallback) => { @@ -238,7 +239,10 @@ describe('EtherTokenWrapper', () => { done(new Error('Expected this subscription to have been cancelled')); }; zeroEx.etherToken.subscribe( - etherTokenAddress, EtherTokenEvents.Transfer, indexFilterValues, callbackNeverToBeCalled, + etherTokenAddress, + EtherTokenEvents.Transfer, + indexFilterValues, + callbackNeverToBeCalled, ); const callbackToBeCalled = (err: Error, logEvent: DecodedLogEvent) => { done(); @@ -247,10 +251,16 @@ describe('EtherTokenWrapper', () => { zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID); await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH); zeroEx.etherToken.subscribe( - etherTokenAddress, EtherTokenEvents.Transfer, indexFilterValues, callbackToBeCalled, + etherTokenAddress, + EtherTokenEvents.Transfer, + indexFilterValues, + callbackToBeCalled, ); await zeroEx.token.transferAsync( - etherTokenAddress, addressWithETH, addressWithoutFunds, transferAmount, + etherTokenAddress, + addressWithETH, + addressWithoutFunds, + transferAmount, ); })().catch(done); }); @@ -261,10 +271,17 @@ describe('EtherTokenWrapper', () => { }; await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH); const subscriptionToken = zeroEx.etherToken.subscribe( - etherTokenAddress, EtherTokenEvents.Transfer, indexFilterValues, callbackNeverToBeCalled); + etherTokenAddress, + EtherTokenEvents.Transfer, + indexFilterValues, + callbackNeverToBeCalled, + ); zeroEx.etherToken.unsubscribe(subscriptionToken); await zeroEx.token.transferAsync( - etherTokenAddress, addressWithETH, addressWithoutFunds, transferAmount, + etherTokenAddress, + addressWithETH, + addressWithoutFunds, + transferAmount, ); done(); })().catch(done); @@ -291,7 +308,10 @@ describe('EtherTokenWrapper', () => { const eventName = EtherTokenEvents.Approval; const indexFilterValues = {}; const logs = await zeroEx.etherToken.getLogsAsync( - etherTokenAddress, eventName, blockRange, indexFilterValues, + etherTokenAddress, + eventName, + blockRange, + indexFilterValues, ); expect(logs).to.have.length(1); const args = logs[0].args; @@ -305,7 +325,10 @@ describe('EtherTokenWrapper', () => { const eventName = EtherTokenEvents.Deposit; const indexFilterValues = {}; const logs = await zeroEx.etherToken.getLogsAsync( - etherTokenAddress, eventName, blockRange, indexFilterValues, + etherTokenAddress, + eventName, + blockRange, + indexFilterValues, ); expect(logs).to.have.length(1); const args = logs[0].args; @@ -319,7 +342,10 @@ describe('EtherTokenWrapper', () => { const differentEventName = EtherTokenEvents.Transfer; const indexFilterValues = {}; const logs = await zeroEx.etherToken.getLogsAsync( - etherTokenAddress, differentEventName, blockRange, indexFilterValues, + etherTokenAddress, + differentEventName, + blockRange, + indexFilterValues, ); expect(logs).to.have.length(0); }); @@ -333,7 +359,10 @@ describe('EtherTokenWrapper', () => { _owner: addressWithETH, }; const logs = await zeroEx.etherToken.getLogsAsync( - etherTokenAddress, eventName, blockRange, indexFilterValues, + etherTokenAddress, + eventName, + blockRange, + indexFilterValues, ); expect(logs).to.have.length(1); const args = logs[0].args; -- cgit From 4dfa720f2dec2be0b0758633c087579a02e482bb Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 4 Jan 2018 12:38:19 +0100 Subject: Use configured version of bignumber in all packages --- packages/0x.js/test/ether_token_wrapper_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/0x.js/test/ether_token_wrapper_test.ts') diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index b39481b55..db7acc8e5 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -1,5 +1,5 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils'; -import BigNumber from 'bignumber.js'; +import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import 'mocha'; import * as Web3 from 'web3'; -- cgit From c8c86c44f8b978d74e03c11d4bb1813e76574af3 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 5 Jan 2018 15:33:00 +0100 Subject: Fix callback types --- packages/0x.js/test/ether_token_wrapper_test.ts | 103 ++++++++++++------------ 1 file changed, 53 insertions(+), 50 deletions(-) (limited to 'packages/0x.js/test/ether_token_wrapper_test.ts') diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index db7acc8e5..b810fc9f1 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -22,6 +22,7 @@ import { DoneCallback } from '../src/types'; 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 { web3Factory } from './utils/web3_factory'; @@ -153,19 +154,19 @@ describe('EtherTokenWrapper', () => { // Source: https://github.com/mochajs/mocha/issues/2407 it('Should receive the Transfer event when tokens are transfered', (done: DoneCallback) => { (async () => { - const callback = (err: Error, logEvent: DecodedLogEvent) => { - expect(err).to.be.null(); - expect(logEvent).to.not.be.undefined(); - expect(logEvent.isRemoved).to.be.false(); - expect(logEvent.log.logIndex).to.be.equal(0); - expect(logEvent.log.transactionIndex).to.be.equal(0); - expect(logEvent.log.blockNumber).to.be.a('number'); - const args = logEvent.log.args; - expect(args._from).to.be.equal(addressWithETH); - expect(args._to).to.be.equal(addressWithoutFunds); - expect(args._value).to.be.bignumber.equal(transferAmount); - done(); - }; + const callback = reportNodeCallbackErrors(done)( + (logEvent: DecodedLogEvent) => { + expect(logEvent).to.not.be.undefined(); + expect(logEvent.isRemoved).to.be.false(); + expect(logEvent.log.logIndex).to.be.equal(0); + expect(logEvent.log.transactionIndex).to.be.equal(0); + expect(logEvent.log.blockNumber).to.be.a('number'); + const args = logEvent.log.args; + expect(args._from).to.be.equal(addressWithETH); + expect(args._to).to.be.equal(addressWithoutFunds); + expect(args._value).to.be.bignumber.equal(transferAmount); + }, + ); await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH); zeroEx.etherToken.subscribe(etherTokenAddress, EtherTokenEvents.Transfer, indexFilterValues, callback); await zeroEx.token.transferAsync( @@ -178,16 +179,16 @@ describe('EtherTokenWrapper', () => { }); it('Should receive the Approval event when allowance is being set', (done: DoneCallback) => { (async () => { - const callback = (err: Error, logEvent: DecodedLogEvent) => { - expect(err).to.be.null(); - expect(logEvent).to.not.be.undefined(); - expect(logEvent.isRemoved).to.be.false(); - const args = logEvent.log.args; - expect(args._owner).to.be.equal(addressWithETH); - expect(args._spender).to.be.equal(addressWithoutFunds); - expect(args._value).to.be.bignumber.equal(allowanceAmount); - done(); - }; + const callback = reportNodeCallbackErrors(done)( + (logEvent: DecodedLogEvent) => { + expect(logEvent).to.not.be.undefined(); + expect(logEvent.isRemoved).to.be.false(); + const args = logEvent.log.args; + expect(args._owner).to.be.equal(addressWithETH); + expect(args._spender).to.be.equal(addressWithoutFunds); + expect(args._value).to.be.bignumber.equal(allowanceAmount); + }, + ); zeroEx.etherToken.subscribe(etherTokenAddress, EtherTokenEvents.Approval, indexFilterValues, callback); await zeroEx.token.setAllowanceAsync( etherTokenAddress, @@ -199,30 +200,30 @@ describe('EtherTokenWrapper', () => { }); it('Should receive the Deposit event when ether is being deposited', (done: DoneCallback) => { (async () => { - const callback = (err: Error, logEvent: DecodedLogEvent) => { - expect(err).to.be.null(); - expect(logEvent).to.not.be.undefined(); - expect(logEvent.isRemoved).to.be.false(); - const args = logEvent.log.args; - expect(args._owner).to.be.equal(addressWithETH); - expect(args._value).to.be.bignumber.equal(depositAmount); - done(); - }; + const callback = reportNodeCallbackErrors(done)( + (logEvent: DecodedLogEvent) => { + expect(logEvent).to.not.be.undefined(); + expect(logEvent.isRemoved).to.be.false(); + const args = logEvent.log.args; + expect(args._owner).to.be.equal(addressWithETH); + expect(args._value).to.be.bignumber.equal(depositAmount); + }, + ); zeroEx.etherToken.subscribe(etherTokenAddress, EtherTokenEvents.Deposit, indexFilterValues, callback); await zeroEx.etherToken.depositAsync(etherTokenAddress, depositAmount, addressWithETH); })().catch(done); }); it('Should receive the Withdrawal event when ether is being withdrawn', (done: DoneCallback) => { (async () => { - const callback = (err: Error, logEvent: DecodedLogEvent) => { - expect(err).to.be.null(); - expect(logEvent).to.not.be.undefined(); - expect(logEvent.isRemoved).to.be.false(); - const args = logEvent.log.args; - expect(args._owner).to.be.equal(addressWithETH); - expect(args._value).to.be.bignumber.equal(depositAmount); - done(); - }; + const callback = reportNodeCallbackErrors(done)( + (logEvent: DecodedLogEvent) => { + expect(logEvent).to.not.be.undefined(); + expect(logEvent.isRemoved).to.be.false(); + const args = logEvent.log.args; + expect(args._owner).to.be.equal(addressWithETH); + expect(args._value).to.be.bignumber.equal(depositAmount); + }, + ); await zeroEx.etherToken.depositAsync(etherTokenAddress, depositAmount, addressWithETH); zeroEx.etherToken.subscribe( etherTokenAddress, @@ -235,18 +236,18 @@ describe('EtherTokenWrapper', () => { }); it('should cancel outstanding subscriptions when ZeroEx.setProvider is called', (done: DoneCallback) => { (async () => { - const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent) => { - done(new Error('Expected this subscription to have been cancelled')); - }; + const callbackNeverToBeCalled = reportNodeCallbackErrors(done)( + (logEvent: DecodedLogEvent) => { + done(new Error('Expected this subscription to have been cancelled')); + }, + ); zeroEx.etherToken.subscribe( etherTokenAddress, EtherTokenEvents.Transfer, indexFilterValues, callbackNeverToBeCalled, ); - const callbackToBeCalled = (err: Error, logEvent: DecodedLogEvent) => { - done(); - }; + const callbackToBeCalled = reportNodeCallbackErrors(done)(); const newProvider = web3Factory.getRpcProvider(); zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID); await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH); @@ -266,9 +267,11 @@ describe('EtherTokenWrapper', () => { }); it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => { (async () => { - const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent) => { - done(new Error('Expected this subscription to have been cancelled')); - }; + const callbackNeverToBeCalled = reportNodeCallbackErrors(done)( + (logEvent: DecodedLogEvent) => { + done(new Error('Expected this subscription to have been cancelled')); + }, + ); await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH); const subscriptionToken = zeroEx.etherToken.subscribe( etherTokenAddress, -- cgit