From 0432212a346aa761c54b5a9159a7e61e0c2f9b9a Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 21 Dec 2018 16:40:07 -0800 Subject: dutch wrapper tests working --- .../src/contract_wrappers/dutch_auction_wrapper.ts | 24 +++++++++------------- packages/contract-wrappers/src/types.ts | 12 +++++++++++ 2 files changed, 22 insertions(+), 14 deletions(-) (limited to 'packages/contract-wrappers/src') diff --git a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts index 5896617fc..dea759962 100644 --- a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts @@ -19,9 +19,9 @@ import { orderTxOptsSchema } from '../schemas/order_tx_opts_schema'; import { txOptsSchema } from '../schemas/tx_opts_schema'; import { OrderTransactionOpts } from '../types'; import { ContractWrapper } from './contract_wrapper'; -import { ExchangeWrapperError } from '../types'; +import { DutchAuctionWrapperError, DutchAuctionData } from '../types'; -import { assetDataUtils, AssetData } from '@0x/order-utils'; +import { assetDataUtils } from '@0x/order-utils'; export class DutchAuctionWrapper extends ContractWrapper { public abi: ContractAbi = DutchAuction.compilerOutput.abi; @@ -72,11 +72,7 @@ export class DutchAuctionWrapper extends ContractWrapper { sellOrder.makerAssetData !== buyOrder.takerAssetData || sellOrder.takerAssetData !== buyOrder.makerAssetData ) { - throw new Error(ExchangeWrapperError.AssetDataMismatch); - } else { - // Smart contracts assigns the asset data from the left order to the right one so we can save gas on reducing the size of call data - //rightSignedOrder.makerAssetData = '0x'; - // rightSignedOrder.takerAssetData = '0x'; + throw new Error(DutchAuctionWrapperError.AssetDataMismatch); } // get contract const dutchAuctionInstance = await this._getDutchAuctionContractAsync(); @@ -119,8 +115,6 @@ export class DutchAuctionWrapper extends ContractWrapper { // type assertions assert.doesConformToSchema('sellOrder', sellOrder, schemas.signedOrderSchema); // get contract - console.log(sellOrder); - console.log(await this._getDutchAuctionContractAsync()); const dutchAuctionInstance = await this._getDutchAuctionContractAsync(); // call contract const afterAuctionDetails = await dutchAuctionInstance.getAuctionDetails.callAsync(sellOrder); @@ -156,7 +150,6 @@ export class DutchAuctionWrapper extends ContractWrapper { ); const abiEncodedAuctionDataBuffer = ethUtil.toBuffer(abiEncodedAuctionData); const dutchAuctionDataBuffer = Buffer.concat([assetDataBuffer, abiEncodedAuctionDataBuffer]); - // console.log(`GREFG --- `, abiEncodedAuctionData); const dutchAuctionData = ethUtil.bufferToHex(dutchAuctionDataBuffer); return dutchAuctionData; }; @@ -165,9 +158,9 @@ export class DutchAuctionWrapper extends ContractWrapper { * encoded assetData string, containing information both about the asset being traded and the * dutch auction; which is usable in the makerAssetData or takerAssetData fields in a 0x order. * @param dutchAuctionData Hex encoded assetData string for the asset being auctioned. - * @return + * @return An object containing the auction asset, auction begin time and auction begin amount. */ - public static decodeDutchAuctionData(dutchAuctionData: string): [AssetData, BigNumber, BigNumber] { + public static decodeDutchAuctionData(dutchAuctionData: string): DutchAuctionData { const dutchAuctionDataBuffer = ethUtil.toBuffer(dutchAuctionData); // Decode asset data const assetDataBuffer = dutchAuctionDataBuffer.slice(0, dutchAuctionDataBuffer.byteLength - 64); @@ -181,7 +174,10 @@ export class DutchAuctionWrapper extends ContractWrapper { ); const beginTimeSeconds = new BigNumber(`0x${beginTimeSecondsAsBN.toString()}`); const beginAmount = new BigNumber(`0x${beginAmountAsBN.toString()}`); - console.log(beginAmount); - return [assetData, beginTimeSeconds, beginAmount]; + return { + assetData, + beginTimeSeconds, + beginAmount + }; }; } diff --git a/packages/contract-wrappers/src/types.ts b/packages/contract-wrappers/src/types.ts index 14d4649ae..f23587c20 100644 --- a/packages/contract-wrappers/src/types.ts +++ b/packages/contract-wrappers/src/types.ts @@ -14,6 +14,8 @@ import { BigNumber } from '@0x/utils'; import { BlockParam, ContractEventArg, DecodedLogArgs, LogEntryEvent, LogWithDecodedArgs } from 'ethereum-types'; +import { AssetData } from '@0x/order-utils'; + export enum ExchangeWrapperError { AssetDataMismatch = 'ASSET_DATA_MISMATCH', } @@ -206,3 +208,13 @@ export interface BalanceAndAllowance { balance: BigNumber; allowance: BigNumber; } + +export enum DutchAuctionWrapperError { + AssetDataMismatch = 'ASSET_DATA_MISMATCH', +} + +export interface DutchAuctionData { + assetData: AssetData; + beginTimeSeconds: BigNumber; + beginAmount: BigNumber; +} -- cgit v1.2.3