diff options
author | Jacob Evans <jacob@dekz.net> | 2018-11-30 10:25:36 +0800 |
---|---|---|
committer | Jacob Evans <jacob@dekz.net> | 2018-12-04 06:14:00 +0800 |
commit | 0bffc3d10e5b7c55fabfd4f0e5dcceefe468aa5f (patch) | |
tree | 2f7a9cb190a538d94e1e71e050f9c4a6c7f4f152 | |
parent | a882a399378f75261e9fe68e6f20b1d4bb8d59c0 (diff) | |
download | dexon-sol-tools-0bffc3d10e5b7c55fabfd4f0e5dcceefe468aa5f.tar dexon-sol-tools-0bffc3d10e5b7c55fabfd4f0e5dcceefe468aa5f.tar.gz dexon-sol-tools-0bffc3d10e5b7c55fabfd4f0e5dcceefe468aa5f.tar.bz2 dexon-sol-tools-0bffc3d10e5b7c55fabfd4f0e5dcceefe468aa5f.tar.lz dexon-sol-tools-0bffc3d10e5b7c55fabfd4f0e5dcceefe468aa5f.tar.xz dexon-sol-tools-0bffc3d10e5b7c55fabfd4f0e5dcceefe468aa5f.tar.zst dexon-sol-tools-0bffc3d10e5b7c55fabfd4f0e5dcceefe468aa5f.zip |
chore: Add RevertReasons for DutchAuction. Test revert reasons
-rw-r--r-- | packages/contracts/contracts/extensions/DutchAuction/DutchAuction.sol | 4 | ||||
-rw-r--r-- | packages/contracts/test/extensions/dutch_auction.ts | 51 | ||||
-rw-r--r-- | packages/types/CHANGELOG.json | 4 | ||||
-rw-r--r-- | packages/types/src/index.ts | 6 |
4 files changed, 51 insertions, 14 deletions
diff --git a/packages/contracts/contracts/extensions/DutchAuction/DutchAuction.sol b/packages/contracts/contracts/extensions/DutchAuction/DutchAuction.sol index 60077746d..9b8fec54a 100644 --- a/packages/contracts/contracts/extensions/DutchAuction/DutchAuction.sol +++ b/packages/contracts/contracts/extensions/DutchAuction/DutchAuction.sol @@ -154,9 +154,9 @@ contract DutchAuction is // | Params | | 2 * 32 | parameters: | // | | -64 | 32 | 1. auction begin unix timestamp | // | | -32 | 32 | 2. auction begin begin amount | - // ERC20 asset data length is 4+32, 64 for auction details results in min length if 100 + // ERC20 asset data length is 4+32, 64 for auction details results in min length 100 require( - makerAssetDataLength > 10, + makerAssetDataLength >= 100, "INVALID_ASSET_DATA" ); uint256 auctionBeginTimeSeconds = order.makerAssetData.readUint256(makerAssetDataLength - 64); diff --git a/packages/contracts/test/extensions/dutch_auction.ts b/packages/contracts/test/extensions/dutch_auction.ts index b3408e27d..c133d8c60 100644 --- a/packages/contracts/test/extensions/dutch_auction.ts +++ b/packages/contracts/test/extensions/dutch_auction.ts @@ -1,6 +1,6 @@ import { BlockchainLifecycle } from '@0x/dev-utils'; import { assetDataUtils, generatePseudoRandomSalt } from '@0x/order-utils'; -import { SignedOrder } from '@0x/types'; +import { RevertReason, SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import * as chai from 'chai'; @@ -268,7 +268,7 @@ describe(ContractName.DutchAuction, () => { erc20Balances[makerAddress][wethContract.address].plus(afterAuctionDetails.currentAmount), ); expect(newBalances[takerAddress][wethContract.address]).to.be.bignumber.gte( - erc20Balances[takerAddress][wethContract.address].minus(afterAuctionDetails.currentAmount), + erc20Balances[takerAddress][wethContract.address].minus(beforeAuctionDetails.currentAmount), ); }); it('should have valid getAuctionDetails at some block in the future', async () => { @@ -346,9 +346,15 @@ describe(ContractName.DutchAuction, () => { ); }); it('should revert when auction expires', async () => { - auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp - 100); + auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds * 2); + auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); sellOrder = await sellerOrderFactory.newSignedOrderAsync({ expirationTimeSeconds: auctionEndTimeSeconds, + makerAssetData: extendMakerAssetData( + assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress), + auctionBeginTimeSeconds, + auctionBeginAmount, + ), }); return expectTransactionFailedAsync( dutchAuctionContract.matchOrders.sendTransactionAsync( @@ -360,7 +366,7 @@ describe(ContractName.DutchAuction, () => { from: takerAddress, }, ), - 'AUCTION_EXPIRED' as any, + RevertReason.AuctionExpired, ); }); it('cannot be filled for less than the current price', async () => { @@ -378,14 +384,35 @@ describe(ContractName.DutchAuction, () => { from: takerAddress, }, ), - 'INVALID_AMOUNT' as any, + RevertReason.AuctionInvalidAmount, + ); + }); + it('auction begin amount must be higher than final amount ', async () => { + sellOrder = await sellerOrderFactory.newSignedOrderAsync({ + takerAssetAmount: auctionBeginAmount.plus(1), + }); + return expectTransactionFailedAsync( + dutchAuctionContract.matchOrders.sendTransactionAsync( + buyOrder, + sellOrder, + buyOrder.signature, + sellOrder.signature, + { + from: takerAddress, + }, + ), + RevertReason.AuctionInvalidAmount, ); }); - it('cannot match an expired auction', async () => { - auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - 1000); - auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp - 100); + it('begin time is less than end time', async () => { + auctionBeginTimeSeconds = new BigNumber(auctionEndTimeSeconds).plus(tenMinutesInSeconds); sellOrder = await sellerOrderFactory.newSignedOrderAsync({ expirationTimeSeconds: auctionEndTimeSeconds, + makerAssetData: extendMakerAssetData( + assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress), + auctionBeginTimeSeconds, + auctionBeginAmount, + ), }); return expectTransactionFailedAsync( dutchAuctionContract.matchOrders.sendTransactionAsync( @@ -397,12 +424,12 @@ describe(ContractName.DutchAuction, () => { from: takerAddress, }, ), - 'AUCTION_EXPIRED' as any, + RevertReason.AuctionInvalidBeginTime, ); }); - it('auction begin amount must be higher than final amount ', async () => { + it('asset data contains auction parameters', async () => { sellOrder = await sellerOrderFactory.newSignedOrderAsync({ - takerAssetAmount: auctionBeginAmount.plus(1), + makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress), }); return expectTransactionFailedAsync( dutchAuctionContract.matchOrders.sendTransactionAsync( @@ -414,7 +441,7 @@ describe(ContractName.DutchAuction, () => { from: takerAddress, }, ), - 'INVALID_AMOUNT' as any, + RevertReason.InvalidAssetData, ); }); describe('ERC721', () => { diff --git a/packages/types/CHANGELOG.json b/packages/types/CHANGELOG.json index 53b24aff0..b09859101 100644 --- a/packages/types/CHANGELOG.json +++ b/packages/types/CHANGELOG.json @@ -5,6 +5,10 @@ { "note": "Add `LengthMismatch` and `LengthGreaterThan3Required` revert reasons", "pr": 1224 + }, + { + "note": "Add RevertReasons for DutchAuction contract", + "pr": 1225 } ] }, diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 26d8f8e22..6b728af71 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -237,6 +237,12 @@ export enum RevertReason { TxFullyConfirmed = 'TX_FULLY_CONFIRMED', TxNotFullyConfirmed = 'TX_NOT_FULLY_CONFIRMED', TimeLockIncomplete = 'TIME_LOCK_INCOMPLETE', + // DutchAuction + AuctionInvalidAmount = 'INVALID_AMOUNT', + AuctionExpired = 'AUCTION_EXPIRED', + AuctionNotStarted = 'AUCTION_NOT_STARTED', + AuctionInvalidBeginTime = 'INVALID_BEGIN_TIME', + InvalidAssetData = 'INVALID_ASSET_DATA', } export enum StatusCodes { |