aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract-wrappers/test
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-12-22 08:11:59 +0800
committerGreg Hysen <greg.hysen@gmail.com>2019-01-08 07:50:48 +0800
commit7203ca90cf9bff2f7accf5fe2ee7da5764d0dac3 (patch)
treed496355d06c83fb70144b5147f12050c9b7cb7a8 /packages/contract-wrappers/test
parent5da748a062043b46133a2dbce248a756bbefce12 (diff)
downloaddexon-sol-tools-7203ca90cf9bff2f7accf5fe2ee7da5764d0dac3.tar
dexon-sol-tools-7203ca90cf9bff2f7accf5fe2ee7da5764d0dac3.tar.gz
dexon-sol-tools-7203ca90cf9bff2f7accf5fe2ee7da5764d0dac3.tar.bz2
dexon-sol-tools-7203ca90cf9bff2f7accf5fe2ee7da5764d0dac3.tar.lz
dexon-sol-tools-7203ca90cf9bff2f7accf5fe2ee7da5764d0dac3.tar.xz
dexon-sol-tools-7203ca90cf9bff2f7accf5fe2ee7da5764d0dac3.tar.zst
dexon-sol-tools-7203ca90cf9bff2f7accf5fe2ee7da5764d0dac3.zip
all dutchie wrapper tests passing
Diffstat (limited to 'packages/contract-wrappers/test')
-rw-r--r--packages/contract-wrappers/test/dutch_auction_wrapper_test.ts90
1 files changed, 46 insertions, 44 deletions
diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts
index bfc4e0a58..f548e3ff8 100644
--- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts
+++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts
@@ -1,7 +1,7 @@
import { BlockchainLifecycle } from '@0x/dev-utils';
import { FillScenarios } from '@0x/fill-scenarios';
import { assetDataUtils } from '@0x/order-utils';
-import { SignedOrder } from '@0x/types';
+import { RevertReason, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import * as chai from 'chai';
import 'mocha';
@@ -18,13 +18,19 @@ 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 {
+ expectTransactionFailedAsync,
+} from '@0x/contracts-test-utils';
+
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
// tslint:disable:custom-no-magic-numbers
describe.only('DutchAuctionWrapper', () => {
- const fillableAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18);
+ const fillableAmount = new BigNumber(2);//Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18);
const tenMinutesInSeconds = 10 * 60;
let contractWrappers: ContractWrappers;
let fillScenarios: FillScenarios;
@@ -33,13 +39,16 @@ describe.only('DutchAuctionWrapper', () => {
let userAddresses: string[];
let makerAddress: string;
let takerAddress: string;
- let buyerAddress: string;
let makerTokenAddress: string;
let takerTokenAddress: string;
let buyOrder: SignedOrder;
let sellOrder: SignedOrder;
let makerTokenAssetData: string;
let takerTokenAssetData: string;
+ let auctionBeginTimeSeconds: BigNumber;
+ let auctionBeginAmount: BigNumber;
+ let auctionEndTimeSeconds: BigNumber;
+ let auctionEndAmount: BigNumber;
before(async () => {
console.log(`BEOGIN DEPLOYINH`);
const contractAddresses = await migrateOnceAsync();
@@ -63,9 +72,8 @@ describe.only('DutchAuctionWrapper', () => {
contractWrappers.erc20Proxy.address,
contractWrappers.erc721Proxy.address,
);
- [, makerAddress, takerAddress, buyerAddress] = userAddresses;
- [makerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
- takerTokenAddress = contractWrappers.forwarder.etherTokenAddress;
+ [, makerAddress, takerAddress] = userAddresses;
+ [makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
console.log(`B`);
// construct asset data for tokens being swapped
[makerTokenAssetData, takerTokenAssetData] = [
@@ -74,31 +82,40 @@ describe.only('DutchAuctionWrapper', () => {
];
console.log(`C`);
// encode auction details in maker asset data
- const auctionBeginAmount = fillableAmount;
+ auctionEndAmount = fillableAmount;
+ auctionBeginAmount = auctionEndAmount.times(2);
const currentBlockTimestamp = await getLatestBlockTimestampAsync();
- const auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds);
+ 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`
- sellOrder = await contractWrappers.dutchAuction.createSignedSellOrderAsync(
+
+ const coinbase = userAddresses[0];
+ const dutchAuctionUtils = new DutchAuctionUtils(web3Wrapper, coinbase, exchangeContractAddress, contractWrappers.erc20Proxy.address);
+ sellOrder = await dutchAuctionUtils.createSignedSellOrderAsync(
auctionBeginTimeSeconds,
- fillableAmount.times(2),
- fillableAmount,
- new BigNumber(currentBlockTimestamp + tenMinutesInSeconds),
+ auctionBeginAmount,
+ auctionEndAmount,
+ auctionEndTimeSeconds,
makerTokenAssetData,
takerTokenAssetData,
makerAddress,
constants.NULL_ADDRESS,
- fillableAmount,
+ auctionEndAmount,
);
- buyOrder = await contractWrappers.dutchAuction.createSignedBuyOrderAsync(
+ console.log(`ASDS`);
+ buyOrder = await dutchAuctionUtils.createSignedBuyOrderAsync(
sellOrder,
- buyerAddress,
+ takerAddress,
);
console.log(`CD`);
});
@@ -113,17 +130,15 @@ describe.only('DutchAuctionWrapper', () => {
});
describe('#matchOrdersAsync', () => {
it('should match two orders', async () => {
- console.log(await contractWrappers.dutchAuction.getAuctionDetailsAsync(sellOrder));
-
- // const txHash = await contractWrappers.dutchAuction.matchOrdersAsync(buyOrder, sellOrder, takerAddress, {gasLimit: 1000000});
- //await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
+ const txHash = await contractWrappers.dutchAuction.matchOrdersAsync(buyOrder, sellOrder, takerAddress);
+ await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
});
it('should throw when invalid transaction and shouldValidate is true', async () => {
// request match with bad buy/sell orders
const badSellOrder = buyOrder;
const badBuyOrder = sellOrder;
- return expect(
- await contractWrappers.dutchAuction.matchOrdersAsync(
+ return expectTransactionFailedAsync(
+ contractWrappers.dutchAuction.matchOrdersAsync(
badBuyOrder,
badSellOrder,
takerAddress,
@@ -131,32 +146,19 @@ describe.only('DutchAuctionWrapper', () => {
shouldValidate: true,
},
),
- ).to.be.rejectedWith('COMPLETE_FILL_FAILED');
+ RevertReason.InvalidAssetData
+ );
});
});
describe('#getAuctionDetailsAsync', () => {
- /*it('should be worth the begin price at the begining of the auction', async () => {
- // setup auction details
- const auctionBeginAmount = fillableAmount;
- const currentBlockTimestamp = await getLatestBlockTimestampAsync();
- const auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds);
- const makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData(
- makerTokenAssetData,
- auctionBeginTimeSeconds,
- auctionBeginAmount
- );
- const order = await fillScenarios.createFillableSignedOrderAsync(
- makerAssetData,
- takerAssetData,
- makerAddress,
- constants.NULL_ADDRESS,
- fillableAmount,
- );
- const auctionDetails = await contractWrappers.dutchAuction.getAuctionDetailsAsync(order);
- expect(auctionDetails.currentTimeSeconds).to.be.bignumber.lte(auctionBeginTimeSeconds);
- expect(auctionDetails.currentAmount).to.be.bignumber.equal(auctionBeginAmount);
- expect(auctionDetails.beginAmount).to.be.bignumber.equal(auctionBeginAmount);
- });*/
+ it('should be worth the begin price at the begining of the auction', async () => {
+ // get auction details
+ const auctionDetails = await contractWrappers.dutchAuction.getAuctionDetailsAsync(sellOrder);
+ // run some basic sanity checks on the return value
+ expect(auctionDetails.beginTimeSeconds, 'auctionDetails.beginTimeSeconds').to.be.bignumber.equal(auctionBeginTimeSeconds);
+ expect(auctionDetails.beginAmount, 'auctionDetails.beginAmount').to.be.bignumber.equal(auctionBeginAmount);
+ expect(auctionDetails.endTimeSeconds, 'auctionDetails.endTimeSeconds').to.be.bignumber.equal(auctionEndTimeSeconds);
+ });
});
});