From dcab272be029dc45729313ef718cc122f629b05c Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Tue, 14 May 2019 19:06:22 +0200 Subject: [PATCH 1/3] Add a test for encoding/decoding dutch auction asset data --- .../test/dutch_auction_wrapper_test.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index d7a6ca015c..aed73feac4 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -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'; @@ -91,6 +91,20 @@ describe('DutchAuctionWrapper', () => { afterEach(async () => { await blockchainLifecycle.revertAsync(); }); + describe.only('.decodeDutchAuctionAssetData', () => { + it('encode and decode to the same values', async () => { + const encodedAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( + makerTokenAssetData, + auctionBeginTimeSeconds, + makerAssetAmount, + ); + const decodedAssetData = DutchAuctionWrapper.decodeDutchAuctionData(encodedAssetData); + 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); From eec016380d4f5e76a6b502fc1548d0d5131ccd3e Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Tue, 14 May 2019 19:32:19 +0200 Subject: [PATCH 2/3] Commit fix to decode --- .../src/contract_wrappers/dutch_auction_wrapper.ts | 4 ++-- .../contract-wrappers/test/dutch_auction_wrapper_test.ts | 5 +++-- 2 files changed, 5 insertions(+), 4 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 a3e1d0ca7d..4af7254bbc 100644 --- a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts @@ -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, diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index aed73feac4..15936a2eed 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -91,14 +91,15 @@ describe('DutchAuctionWrapper', () => { afterEach(async () => { await blockchainLifecycle.revertAsync(); }); - describe.only('.decodeDutchAuctionAssetData', () => { - it('encode and decode to the same values', async () => { + 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); From b4b34e489077ad0a96ad800cb88aa4df971d6253 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Tue, 14 May 2019 22:25:30 +0200 Subject: [PATCH 3/3] Update CHANGELOG --- packages/contract-wrappers/CHANGELOG.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json index c6f26613f2..e4e997812b 100644 --- a/packages/contract-wrappers/CHANGELOG.json +++ b/packages/contract-wrappers/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "9.1.3", + "changes": [ + { + "note": "Fix decoding bug in `DutchAuctionWrapper.decodeDutchAuctionData`", + "pr": 1815 + } + ] + }, { "version": "9.1.2", "changes": [