From f8684d6a776724d0172c30126a7277885ed4e966 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Tue, 18 Dec 2018 22:37:36 -0800 Subject: All contract tests working with new abi encoder --- contracts/protocol/test/exchange/fill_order.ts | 2 +- contracts/protocol/test/exchange/internal.ts | 2 +- contracts/protocol/test/utils/exchange_wrapper.ts | 16 ++++++++++++++-- .../test/utils/fill_order_combinatorial_utils.ts | 7 ++++--- 4 files changed, 20 insertions(+), 7 deletions(-) (limited to 'contracts/protocol') diff --git a/contracts/protocol/test/exchange/fill_order.ts b/contracts/protocol/test/exchange/fill_order.ts index 82f1dd9bf..2bdbe4855 100644 --- a/contracts/protocol/test/exchange/fill_order.ts +++ b/contracts/protocol/test/exchange/fill_order.ts @@ -51,7 +51,7 @@ const defaultFillScenario = { }, }; -describe.skip('FillOrder Tests', () => { +describe('FillOrder Tests', () => { let fillOrderCombinatorialUtils: FillOrderCombinatorialUtils; before(async () => { diff --git a/contracts/protocol/test/exchange/internal.ts b/contracts/protocol/test/exchange/internal.ts index ffe1f8a55..c65c477b2 100644 --- a/contracts/protocol/test/exchange/internal.ts +++ b/contracts/protocol/test/exchange/internal.ts @@ -50,7 +50,7 @@ const emptySignedOrder: SignedOrder = { const overflowErrorForCall = new Error(RevertReason.Uint256Overflow); -describe.skip('Exchange core internal functions', () => { +describe('Exchange core internal functions', () => { let testExchange: TestExchangeInternalsContract; let overflowErrorForSendTransaction: Error | undefined; let divisionByZeroErrorForCall: Error | undefined; diff --git a/contracts/protocol/test/utils/exchange_wrapper.ts b/contracts/protocol/test/utils/exchange_wrapper.ts index cb6dce901..28532f44b 100644 --- a/contracts/protocol/test/utils/exchange_wrapper.ts +++ b/contracts/protocol/test/utils/exchange_wrapper.ts @@ -7,10 +7,12 @@ import { SignedTransaction, } from '@0x/contracts-test-utils'; import { artifacts as tokensArtifacts } from '@0x/contracts-tokens'; -import { SignedOrder } from '@0x/types'; +import { OrderWithoutExchangeAddress, SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; -import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; +import { AbiDefinition, MethodAbi ,Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; +import * as _ from 'lodash'; +import { AbiEncoder } from '@0x/utils'; import { ExchangeContract } from '../../generated-wrappers/exchange'; import { artifacts } from '../../src/artifacts'; @@ -275,6 +277,16 @@ export class ExchangeWrapper { ); return data; } + // @hysz -- TEMPORARY HACK @TODO remove + public abiDecodeFillOrder(data: string): {order: OrderWithoutExchangeAddress, takerAssetFillAmount: BigNumber, signature: string} { + let fillOrderAbi = _.find(this._exchange.abi, (value: AbiDefinition) => { + if ((value.type === 'function') && (value as MethodAbi).name === 'fillOrder') { + return true; + } + return false; + }) as MethodAbi; + return (new AbiEncoder.Method(fillOrderAbi)).decode(data) as {order: OrderWithoutExchangeAddress, takerAssetFillAmount: BigNumber, signature: string}; + } public getExchangeAddress(): string { return this._exchange.address; } diff --git a/contracts/protocol/test/utils/fill_order_combinatorial_utils.ts b/contracts/protocol/test/utils/fill_order_combinatorial_utils.ts index 5d0ea07a8..df38bd59c 100644 --- a/contracts/protocol/test/utils/fill_order_combinatorial_utils.ts +++ b/contracts/protocol/test/utils/fill_order_combinatorial_utils.ts @@ -42,6 +42,7 @@ import { ExchangeWrapper } from './exchange_wrapper'; import { OrderFactoryFromScenario } from './order_factory_from_scenario'; import { SimpleAssetBalanceAndProxyAllowanceFetcher } from './simple_asset_balance_and_proxy_allowance_fetcher'; import { SimpleOrderFilledCancelledFetcher } from './simple_order_filled_cancelled_fetcher'; +import { Method } from '@0x/utils/lib/src/abi_encoder'; chaiSetup.configure(); const expect = chai.expect; @@ -613,13 +614,13 @@ export class FillOrderCombinatorialUtils { takerAssetFillAmount: BigNumber, ): Promise { const params = orderUtils.createFill(signedOrder, takerAssetFillAmount); - const expectedAbiEncodedData = this.exchangeWrapper.abiEncodeFillOrder(signedOrder, { takerAssetFillAmount }); - const libsAbiEncodedData = await this.testLibsContract.publicAbiEncodeFillOrder.callAsync( + const abiDataEncodedByContract = await this.testLibsContract.publicAbiEncodeFillOrder.callAsync( params.order, params.takerAssetFillAmount, params.signature, ); - expect(libsAbiEncodedData).to.be.equal(expectedAbiEncodedData, 'ABIEncodedFillOrderData'); + const paramsDecodeddByClient = this.exchangeWrapper.abiDecodeFillOrder(abiDataEncodedByContract); + expect(paramsDecodeddByClient).to.be.deep.equal(params, 'ABIEncodedFillOrderData'); } private async _getTakerAssetFillAmountAsync( signedOrder: SignedOrder, -- cgit v1.2.3