From 38cf621327443dab988721881b27ed10f6efe331 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 5 Jun 2017 13:13:04 +0200 Subject: Add regression test for transferFrom bug --- test/token_wrapper_test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/token_wrapper_test.ts b/test/token_wrapper_test.ts index 698ad5b6a..3cfc6d197 100644 --- a/test/token_wrapper_test.ts +++ b/test/token_wrapper_test.ts @@ -89,6 +89,16 @@ describe('TokenWrapper', () => { token.address, fromAddress, toAddress, senderAddress, transferAmount, )).to.be.rejectedWith(ZeroExError.INSUFFICIENT_ALLOWANCE_FOR_TRANSFER); }); + it('should fail to transfer tokens if set allowance for toAddress instead of senderAddress', async () => { + const fromAddress = coinbase; + const transferAmount = new BigNumber(42); + + await zeroEx.token.setAllowanceAsync(token.address, fromAddress, toAddress, transferAmount); + + return expect(zeroEx.token.transferFromAsync( + token.address, fromAddress, toAddress, senderAddress, transferAmount, + )).to.be.rejectedWith(ZeroExError.INSUFFICIENT_ALLOWANCE_FOR_TRANSFER); + }); it('should fail to transfer tokens if fromAddress has insufficient balance', async () => { const fromAddress = addressWithoutFunds; const transferAmount = new BigNumber(42); -- cgit From 592cab8d3f487450943d5f6e31815939f581bb96 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 5 Jun 2017 14:12:20 +0200 Subject: Add a couple of awaits and returns for async tests --- test/exchange_wrapper_test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 4f3a48b26..c4e6e308b 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -361,7 +361,7 @@ describe('ExchangeWrapper', () => { describe('#getUnavailableTakerAmountAsync', () => { it ('should throw if passed an invalid orderHash', async () => { const invalidOrderHashHex = '0x123'; - expect(zeroEx.exchange.getUnavailableTakerAmountAsync(invalidOrderHashHex)).to.be.rejected(); + return expect(zeroEx.exchange.getUnavailableTakerAmountAsync(invalidOrderHashHex)).to.be.rejected(); }); it ('should return zero if passed a valid but non-existent orderHash', async () => { const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync(NON_EXISTENT_ORDER_HASH); @@ -376,7 +376,7 @@ describe('ExchangeWrapper', () => { describe('#getFilledTakerAmountAsync', () => { it ('should throw if passed an invalid orderHash', async () => { const invalidOrderHashHex = '0x123'; - expect(zeroEx.exchange.getFilledTakerAmountAsync(invalidOrderHashHex)).to.be.rejected(); + return expect(zeroEx.exchange.getFilledTakerAmountAsync(invalidOrderHashHex)).to.be.rejected(); }); it ('should return zero if passed a valid but non-existent orderHash', async () => { const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync(NON_EXISTENT_ORDER_HASH); @@ -391,7 +391,7 @@ describe('ExchangeWrapper', () => { describe('#getCanceledTakerAmountAsync', () => { it ('should throw if passed an invalid orderHash', async () => { const invalidOrderHashHex = '0x123'; - expect(zeroEx.exchange.getCanceledTakerAmountAsync(invalidOrderHashHex)).to.be.rejected(); + return expect(zeroEx.exchange.getCanceledTakerAmountAsync(invalidOrderHashHex)).to.be.rejected(); }); it ('should return zero if passed a valid but non-existent orderHash', async () => { const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(NON_EXISTENT_ORDER_HASH); @@ -427,7 +427,7 @@ describe('ExchangeWrapper', () => { ); }); afterEach(async () => { - (zeroEx.exchange as any).stopWatchingExchangeLogEventsAsync(); + await (zeroEx.exchange as any).stopWatchingExchangeLogEventsAsync(); }); // 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 `subscribeAsync` callback, -- cgit From 713ad291c4d4c537ef142e332566555076708b6d Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 5 Jun 2017 15:31:39 +0200 Subject: Add chai-as-promised --- test/exchange_wrapper_test.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index c4e6e308b..b680c015b 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -5,6 +5,7 @@ import * as Web3 from 'web3'; import * as BigNumber from 'bignumber.js'; import * as dirtyChai from 'dirty-chai'; import ChaiBigNumber = require('chai-bignumber'); +import * as chaiAsPromised from 'chai-as-promised'; import promisify = require('es6-promisify'); import {web3Factory} from './utils/web3_factory'; import {ZeroEx} from '../src/0x.js'; @@ -24,6 +25,7 @@ import {TokenUtils} from './utils/token_utils'; chai.config.includeStack = true; chai.use(dirtyChai); chai.use(ChaiBigNumber()); +chai.use(chaiAsPromised); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(); -- cgit From 39958be0b81a4de8e09ea1e783231cc0a9417e36 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 6 Jun 2017 11:38:29 +0200 Subject: Address feedback --- test/token_wrapper_test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/token_wrapper_test.ts b/test/token_wrapper_test.ts index 3cfc6d197..ffe3db983 100644 --- a/test/token_wrapper_test.ts +++ b/test/token_wrapper_test.ts @@ -89,7 +89,8 @@ describe('TokenWrapper', () => { token.address, fromAddress, toAddress, senderAddress, transferAmount, )).to.be.rejectedWith(ZeroExError.INSUFFICIENT_ALLOWANCE_FOR_TRANSFER); }); - it('should fail to transfer tokens if set allowance for toAddress instead of senderAddress', async () => { + it('[regression] should fail to transfer tokens if set allowance for toAddress instead of senderAddress', + async () => { const fromAddress = coinbase; const transferAmount = new BigNumber(42); -- cgit