Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Incorrect decode in DutchAuctionWrapper #1815

Merged
merged 3 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/contract-wrappers/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[
{
"version": "9.1.3",
"changes": [
{
"note": "Fix decoding bug in `DutchAuctionWrapper.decodeDutchAuctionData`",
"pr": 1815
}
]
},
{
"version": "9.1.2",
"changes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export class DutchAuctionWrapper extends ContractWrapper {
['uint256', 'uint256'],
dutchAuctionDetailsBuffer,
);
const beginTimeSeconds = new BigNumber(`0x${beginTimeSecondsAsBN.toString()}`);
const beginAmount = new BigNumber(`0x${beginAmountAsBN.toString()}`);
const beginTimeSeconds = new BigNumber(beginTimeSecondsAsBN.toString());
const beginAmount = new BigNumber(beginAmountAsBN.toString());
return {
assetData,
beginTimeSeconds,
Expand Down
19 changes: 17 additions & 2 deletions packages/contract-wrappers/test/dutch_auction_wrapper_test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { expectTransactionFailedAsync, getLatestBlockTimestampAsync } from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { assetDataUtils } from '@0x/order-utils';
import { RevertReason, SignedOrder } from '@0x/types';
import { ERC20AssetData, RevertReason, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import * as chai from 'chai';
import 'mocha';

import { ContractWrappers } from '../src';
import { ContractWrappers, DutchAuctionWrapper } from '../src';

import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
Expand Down Expand Up @@ -91,6 +91,21 @@ describe('DutchAuctionWrapper', () => {
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('.decodeDutchAuctionAssetData', () => {
it('decodes to the encoded values', async () => {
const encodedAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData(
makerTokenAssetData,
auctionBeginTimeSeconds,
makerAssetAmount,
);
const decodedAssetData = DutchAuctionWrapper.decodeDutchAuctionData(encodedAssetData);
// tslint:disable-next-line:no-unnecessary-type-assertion
const erc20AssetData = decodedAssetData.assetData as ERC20AssetData;
expect(erc20AssetData.tokenAddress).to.eq(makerTokenAddress);
expect(decodedAssetData.beginAmount).to.be.bignumber.eq(makerAssetAmount);
expect(decodedAssetData.beginTimeSeconds).to.be.bignumber.eq(auctionBeginTimeSeconds);
});
});
describe('#matchOrdersAsync', () => {
it('should match two orders', async () => {
const txHash = await contractWrappers.dutchAuction.matchOrdersAsync(buyOrder, sellOrder, takerAddress);
Expand Down