From 03bc3f08cd0d1c51dc9eb4441a3415e131b72c95 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 2 Jun 2017 10:02:19 +0200 Subject: Simplify tests --- test/exchange_wrapper_test.ts | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 519442d9f..d50a5f031 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -10,7 +10,7 @@ import {web3Factory} from './utils/web3_factory'; import {ZeroEx} from '../src/0x.js'; import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; import {orderFactory} from './utils/order_factory'; -import {FillOrderValidationErrs, Token} from '../src/types'; +import {FillOrderValidationErrs, Token, SignedOrder} from '../src/types'; import {FillScenarios} from './utils/fill_scenarios'; chai.use(dirtyChai); @@ -187,12 +187,22 @@ describe('ExchangeWrapper', () => { let makerTokenAddress: string; let takerTokenAddress: string; let takerAddress: string; + let fillableAmount: BigNumber.BigNumber; + let partialFillAmount: BigNumber.BigNumber; + let signedOrder: SignedOrder; before(() => { takerAddress = userAddresses[1]; const [makerToken, takerToken] = tokens; makerTokenAddress = makerToken.address; takerTokenAddress = takerToken.address; }); + beforeEach(async () => { + fillableAmount = new BigNumber(5); + partialFillAmount = new BigNumber(2); + signedOrder = await fillScenarios.createPartiallyFilledSignedOrderAsync( + makerTokenAddress, takerTokenAddress, takerAddress, fillableAmount, partialFillAmount, + ); + }); describe('#getUnavailableTakerAmountAsync', () => { it ('should throw if passed an invalid orderHash', async () => { const invalidOrderHashHex = '0x123'; @@ -203,11 +213,6 @@ describe('ExchangeWrapper', () => { expect(unavailableValueT).to.be.bignumber.equal(0); }); it ('should return the unavailableValueT for a valid and partially filled orderHash', async () => { - const fillableAmount = new BigNumber(5); - const partialFillAmount = new BigNumber(2); - const signedOrder = await fillScenarios.createPartiallyFilledSignedOrderAsync( - makerTokenAddress, takerTokenAddress, takerAddress, fillableAmount, partialFillAmount, - ); const orderHash = await zeroEx.getOrderHashHexAsync(signedOrder); const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync(orderHash); expect(unavailableValueT).to.be.bignumber.equal(partialFillAmount); @@ -223,11 +228,6 @@ describe('ExchangeWrapper', () => { expect(filledValueT).to.be.bignumber.equal(0); }); it ('should return the filledValueT for a valid and partially filled orderHash', async () => { - const fillableAmount = new BigNumber(5); - const partialFillAmount = new BigNumber(2); - const signedOrder = await fillScenarios.createPartiallyFilledSignedOrderAsync( - makerTokenAddress, takerTokenAddress, takerAddress, fillableAmount, partialFillAmount, - ); const orderHash = await zeroEx.getOrderHashHexAsync(signedOrder); const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync(orderHash); expect(filledValueT).to.be.bignumber.equal(partialFillAmount); @@ -243,11 +243,6 @@ describe('ExchangeWrapper', () => { expect(cancelledValueT).to.be.bignumber.equal(0); }); it ('should return the cancelledValueT for a valid and partially filled orderHash', async () => { - const fillableAmount = new BigNumber(5); - const partialFillAmount = new BigNumber(2); - const signedOrder = await fillScenarios.createPartiallyFilledSignedOrderAsync( - makerTokenAddress, takerTokenAddress, takerAddress, fillableAmount, partialFillAmount, - ); const orderHash = await zeroEx.getOrderHashHexAsync(signedOrder); const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHash); expect(cancelledValueT).to.be.bignumber.equal(0); -- cgit v1.2.3