From 246eca91aa9a816215483cb1a28b6a3d0c73206e Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Fri, 9 Feb 2018 13:20:15 -0800 Subject: Add logDecoder, remove outdated tests --- packages/contracts/test/exchange/core.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index c7724c511..ae136816e 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -19,6 +19,7 @@ import { Balances } from '../../src/utils/balances'; import { constants } from '../../src/utils/constants'; import { crypto } from '../../src/utils/crypto'; import { ExchangeWrapper } from '../../src/utils/exchange_wrapper'; +import { LogDecoder } from '../../src/utils/log_decoder'; import { OrderFactory } from '../../src/utils/order_factory'; import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../src/utils/types'; import { chaiSetup } from '../utils/chai_setup'; @@ -393,7 +394,7 @@ describe('Exchange', () => { const res = await exWrapper.fillOrderAsync(signedOrder, taker, { takerTokenFillAmount: signedOrder.takerTokenAmount, }); - const log = res.logs[0] as LogWithDecodedArgs; + const log = logDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs; expect(log.args.takerTokenFilledAmount).to.be.bignumber.equal( signedOrder.takerTokenAmount.minus(takerTokenFillAmount), ); @@ -429,7 +430,7 @@ describe('Exchange', () => { }); expect(res.logs).to.have.length(1); - const log = res.logs[0] as LogWithDecodedArgs; + const log = logDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs; const logArgs = log.args; const expectedFilledMakerTokenAmount = signedOrder.makerTokenAmount.div(divisor); const expectedFilledTakerTokenAmount = signedOrder.takerTokenAmount.div(divisor); @@ -460,7 +461,7 @@ describe('Exchange', () => { }); expect(res.logs).to.have.length(1); - const log = res.logs[0] as LogWithDecodedArgs; + const log = logDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs; const logArgs = log.args; const expectedFilledMakerTokenAmount = signedOrder.makerTokenAmount.div(divisor); const expectedFilledTakerTokenAmount = signedOrder.takerTokenAmount.div(divisor); @@ -688,8 +689,8 @@ describe('Exchange', () => { const res = await exWrapper.fillOrderAsync(signedOrder, taker); expect(res.logs).to.have.length(1); - const log = res.logs[0] as LogWithDecodedArgs; - const errCode = log.args.errorId; + const log = logDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs; + const errCode = log.args.errorId.toNumber(); expect(errCode).to.be.equal(ExchangeContractErrs.ERROR_ORDER_EXPIRED); }); @@ -699,8 +700,8 @@ describe('Exchange', () => { const res = await exWrapper.fillOrderAsync(signedOrder, taker); expect(res.logs).to.have.length(1); - const log = res.logs[0] as LogWithDecodedArgs; - const errCode = log.args.errorId; + const log = logDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs; + const errCode = log.args.errorId.toNumber(); expect(errCode).to.be.equal(ExchangeContractErrs.ERROR_ORDER_FULLY_FILLED_OR_CANCELLED); }); }); @@ -760,7 +761,7 @@ describe('Exchange', () => { const res = await exWrapper.fillOrderAsync(signedOrder, taker, { takerTokenFillAmount: signedOrder.takerTokenAmount, }); - const log = res.logs[0] as LogWithDecodedArgs; + const log = logDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs; expect(log.args.takerTokenFilledAmount).to.be.bignumber.equal( signedOrder.takerTokenAmount.minus(takerTokenCancelAmount), ); @@ -805,7 +806,7 @@ describe('Exchange', () => { }); expect(res.logs).to.have.length(1); - const log = res.logs[0] as LogWithDecodedArgs; + const log = logDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs; const logArgs = log.args; const expectedCancelledMakerTokenAmount = signedOrder.makerTokenAmount.div(divisor); const expectedCancelledTakerTokenAmount = signedOrder.takerTokenAmount.div(divisor); @@ -826,8 +827,8 @@ describe('Exchange', () => { const res = await exWrapper.cancelOrderAsync(signedOrder, maker); expect(res.logs).to.have.length(1); - const log = res.logs[0] as LogWithDecodedArgs; - const errCode = log.args.errorId; + const log = logDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs; + const errCode = log.args.errorId.toNumber(); expect(errCode).to.be.equal(ExchangeContractErrs.ERROR_ORDER_FULLY_FILLED_OR_CANCELLED); }); @@ -838,8 +839,8 @@ describe('Exchange', () => { const res = await exWrapper.cancelOrderAsync(signedOrder, maker); expect(res.logs).to.have.length(1); - const log = res.logs[0] as LogWithDecodedArgs; - const errCode = log.args.errorId; + const log = logDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs; + const errCode = log.args.errorId.toNumber(); expect(errCode).to.be.equal(ExchangeContractErrs.ERROR_ORDER_EXPIRED); }); }); -- cgit v1.2.3