aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract-wrappers
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-12-22 08:40:07 +0800
committerGreg Hysen <greg.hysen@gmail.com>2019-01-08 07:50:48 +0800
commit0432212a346aa761c54b5a9159a7e61e0c2f9b9a (patch)
treed713c31d0a4820cc462846030754f6fd96ec4cdc /packages/contract-wrappers
parent7203ca90cf9bff2f7accf5fe2ee7da5764d0dac3 (diff)
downloaddexon-sol-tools-0432212a346aa761c54b5a9159a7e61e0c2f9b9a.tar
dexon-sol-tools-0432212a346aa761c54b5a9159a7e61e0c2f9b9a.tar.gz
dexon-sol-tools-0432212a346aa761c54b5a9159a7e61e0c2f9b9a.tar.bz2
dexon-sol-tools-0432212a346aa761c54b5a9159a7e61e0c2f9b9a.tar.lz
dexon-sol-tools-0432212a346aa761c54b5a9159a7e61e0c2f9b9a.tar.xz
dexon-sol-tools-0432212a346aa761c54b5a9159a7e61e0c2f9b9a.tar.zst
dexon-sol-tools-0432212a346aa761c54b5a9159a7e61e0c2f9b9a.zip
dutch wrapper tests working
Diffstat (limited to 'packages/contract-wrappers')
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts24
-rw-r--r--packages/contract-wrappers/src/types.ts12
-rw-r--r--packages/contract-wrappers/test/dutch_auction_wrapper_test.ts43
3 files changed, 27 insertions, 52 deletions
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;
+}
diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts
index f548e3ff8..697554dd1 100644
--- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts
+++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts
@@ -1,12 +1,11 @@
import { BlockchainLifecycle } from '@0x/dev-utils';
-import { FillScenarios } from '@0x/fill-scenarios';
import { assetDataUtils } from '@0x/order-utils';
import { RevertReason, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import * as chai from 'chai';
import 'mocha';
-import { ContractWrappers, OrderStatus } from '../src';
+import { ContractWrappers } from '../src';
import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
@@ -14,10 +13,6 @@ import { migrateOnceAsync } from './utils/migrate';
import { tokenUtils } from './utils/token_utils';
import { provider, web3Wrapper } from './utils/web3_wrapper';
import { getLatestBlockTimestampAsync } from '@0x/contracts-test-utils';
-import { DutchAuction } from '@0x/contract-artifacts';
-import { DutchAuctionWrapper } from '../src/contract_wrappers/dutch_auction_wrapper';
-import { Web3Wrapper } from '@0x/web3-wrapper';
-
import { DutchAuctionUtils } from './utils/dutch_auction_utils';
import {
@@ -33,9 +28,7 @@ describe.only('DutchAuctionWrapper', () => {
const fillableAmount = new BigNumber(2);//Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18);
const tenMinutesInSeconds = 10 * 60;
let contractWrappers: ContractWrappers;
- let fillScenarios: FillScenarios;
let exchangeContractAddress: string;
- let zrxTokenAddress: string;
let userAddresses: string[];
let makerAddress: string;
let takerAddress: string;
@@ -50,7 +43,7 @@ describe.only('DutchAuctionWrapper', () => {
let auctionEndTimeSeconds: BigNumber;
let auctionEndAmount: BigNumber;
before(async () => {
- console.log(`BEOGIN DEPLOYINH`);
+ // setup contract wrappers & addresses
const contractAddresses = await migrateOnceAsync();
await blockchainLifecycle.startAsync();
const config = {
@@ -58,47 +51,23 @@ describe.only('DutchAuctionWrapper', () => {
contractAddresses,
blockPollingIntervalMs: 10,
};
-
contractWrappers = new ContractWrappers(provider, config);
- console.log(`DEPLOYINH`);
exchangeContractAddress = contractWrappers.exchange.address;
userAddresses = await web3Wrapper.getAvailableAddressesAsync();
- zrxTokenAddress = contractWrappers.exchange.zrxTokenAddress;
- fillScenarios = new FillScenarios(
- provider,
- userAddresses,
- zrxTokenAddress,
- exchangeContractAddress,
- contractWrappers.erc20Proxy.address,
- contractWrappers.erc721Proxy.address,
- );
[, makerAddress, takerAddress] = userAddresses;
[makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
- console.log(`B`);
// construct asset data for tokens being swapped
[makerTokenAssetData, takerTokenAssetData] = [
assetDataUtils.encodeERC20AssetData(makerTokenAddress),
assetDataUtils.encodeERC20AssetData(takerTokenAddress),
];
- console.log(`C`);
- // encode auction details in maker asset data
+ // setup auction details in maker asset data
auctionEndAmount = fillableAmount;
auctionBeginAmount = auctionEndAmount.times(2);
const currentBlockTimestamp = await getLatestBlockTimestampAsync();
auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds);
auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds);
- /* makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData(
- makerTokenAssetData,
- auctionBeginTimeSeconds,
- auctionBeginAmount
- );*/
- console.log(`C2`);
- // Create template orders from
-
-
- // create sell / buy orders for auction
- // note that the maker/taker asset datas are swapped in the `buyOrder`
-
+ // create auction orders
const coinbase = userAddresses[0];
const dutchAuctionUtils = new DutchAuctionUtils(web3Wrapper, coinbase, exchangeContractAddress, contractWrappers.erc20Proxy.address);
sellOrder = await dutchAuctionUtils.createSignedSellOrderAsync(
@@ -112,12 +81,10 @@ describe.only('DutchAuctionWrapper', () => {
constants.NULL_ADDRESS,
auctionEndAmount,
);
- console.log(`ASDS`);
buyOrder = await dutchAuctionUtils.createSignedBuyOrderAsync(
sellOrder,
takerAddress,
);
- console.log(`CD`);
});
after(async () => {
await blockchainLifecycle.revertAsync();
@@ -152,7 +119,7 @@ describe.only('DutchAuctionWrapper', () => {
});
describe('#getAuctionDetailsAsync', () => {
- it('should be worth the begin price at the begining of the auction', async () => {
+ it('should get auction details', async () => {
// get auction details
const auctionDetails = await contractWrappers.dutchAuction.getAuctionDetailsAsync(sellOrder);
// run some basic sanity checks on the return value