chore: Add RevertReasons for DutchAuction. Test revert reasons
This commit is contained in:
parent
a882a39937
commit
0bffc3d10e
@ -154,9 +154,9 @@ contract DutchAuction is
|
|||||||
// | Params | | 2 * 32 | parameters: |
|
// | Params | | 2 * 32 | parameters: |
|
||||||
// | | -64 | 32 | 1. auction begin unix timestamp |
|
// | | -64 | 32 | 1. auction begin unix timestamp |
|
||||||
// | | -32 | 32 | 2. auction begin begin amount |
|
// | | -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(
|
require(
|
||||||
makerAssetDataLength > 10,
|
makerAssetDataLength >= 100,
|
||||||
"INVALID_ASSET_DATA"
|
"INVALID_ASSET_DATA"
|
||||||
);
|
);
|
||||||
uint256 auctionBeginTimeSeconds = order.makerAssetData.readUint256(makerAssetDataLength - 64);
|
uint256 auctionBeginTimeSeconds = order.makerAssetData.readUint256(makerAssetDataLength - 64);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||||
import { assetDataUtils, generatePseudoRandomSalt } from '@0x/order-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 { BigNumber } from '@0x/utils';
|
||||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
@ -268,7 +268,7 @@ describe(ContractName.DutchAuction, () => {
|
|||||||
erc20Balances[makerAddress][wethContract.address].plus(afterAuctionDetails.currentAmount),
|
erc20Balances[makerAddress][wethContract.address].plus(afterAuctionDetails.currentAmount),
|
||||||
);
|
);
|
||||||
expect(newBalances[takerAddress][wethContract.address]).to.be.bignumber.gte(
|
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 () => {
|
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 () => {
|
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({
|
sellOrder = await sellerOrderFactory.newSignedOrderAsync({
|
||||||
expirationTimeSeconds: auctionEndTimeSeconds,
|
expirationTimeSeconds: auctionEndTimeSeconds,
|
||||||
|
makerAssetData: extendMakerAssetData(
|
||||||
|
assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
|
||||||
|
auctionBeginTimeSeconds,
|
||||||
|
auctionBeginAmount,
|
||||||
|
),
|
||||||
});
|
});
|
||||||
return expectTransactionFailedAsync(
|
return expectTransactionFailedAsync(
|
||||||
dutchAuctionContract.matchOrders.sendTransactionAsync(
|
dutchAuctionContract.matchOrders.sendTransactionAsync(
|
||||||
@ -360,7 +366,7 @@ describe(ContractName.DutchAuction, () => {
|
|||||||
from: takerAddress,
|
from: takerAddress,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
'AUCTION_EXPIRED' as any,
|
RevertReason.AuctionExpired,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('cannot be filled for less than the current price', async () => {
|
it('cannot be filled for less than the current price', async () => {
|
||||||
@ -378,26 +384,7 @@ describe(ContractName.DutchAuction, () => {
|
|||||||
from: takerAddress,
|
from: takerAddress,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
'INVALID_AMOUNT' as any,
|
RevertReason.AuctionInvalidAmount,
|
||||||
);
|
|
||||||
});
|
|
||||||
it('cannot match an expired auction', async () => {
|
|
||||||
auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - 1000);
|
|
||||||
auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp - 100);
|
|
||||||
sellOrder = await sellerOrderFactory.newSignedOrderAsync({
|
|
||||||
expirationTimeSeconds: auctionEndTimeSeconds,
|
|
||||||
});
|
|
||||||
return expectTransactionFailedAsync(
|
|
||||||
dutchAuctionContract.matchOrders.sendTransactionAsync(
|
|
||||||
buyOrder,
|
|
||||||
sellOrder,
|
|
||||||
buyOrder.signature,
|
|
||||||
sellOrder.signature,
|
|
||||||
{
|
|
||||||
from: takerAddress,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
'AUCTION_EXPIRED' as any,
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('auction begin amount must be higher than final amount ', async () => {
|
it('auction begin amount must be higher than final amount ', async () => {
|
||||||
@ -414,7 +401,47 @@ describe(ContractName.DutchAuction, () => {
|
|||||||
from: takerAddress,
|
from: takerAddress,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
'INVALID_AMOUNT' as any,
|
RevertReason.AuctionInvalidAmount,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
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(
|
||||||
|
buyOrder,
|
||||||
|
sellOrder,
|
||||||
|
buyOrder.signature,
|
||||||
|
sellOrder.signature,
|
||||||
|
{
|
||||||
|
from: takerAddress,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
RevertReason.AuctionInvalidBeginTime,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('asset data contains auction parameters', async () => {
|
||||||
|
sellOrder = await sellerOrderFactory.newSignedOrderAsync({
|
||||||
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
|
||||||
|
});
|
||||||
|
return expectTransactionFailedAsync(
|
||||||
|
dutchAuctionContract.matchOrders.sendTransactionAsync(
|
||||||
|
buyOrder,
|
||||||
|
sellOrder,
|
||||||
|
buyOrder.signature,
|
||||||
|
sellOrder.signature,
|
||||||
|
{
|
||||||
|
from: takerAddress,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
RevertReason.InvalidAssetData,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
describe('ERC721', () => {
|
describe('ERC721', () => {
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
{
|
{
|
||||||
"note": "Add `LengthMismatch` and `LengthGreaterThan3Required` revert reasons",
|
"note": "Add `LengthMismatch` and `LengthGreaterThan3Required` revert reasons",
|
||||||
"pr": 1224
|
"pr": 1224
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"note": "Add RevertReasons for DutchAuction contract",
|
||||||
|
"pr": 1225
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -237,6 +237,12 @@ export enum RevertReason {
|
|||||||
TxFullyConfirmed = 'TX_FULLY_CONFIRMED',
|
TxFullyConfirmed = 'TX_FULLY_CONFIRMED',
|
||||||
TxNotFullyConfirmed = 'TX_NOT_FULLY_CONFIRMED',
|
TxNotFullyConfirmed = 'TX_NOT_FULLY_CONFIRMED',
|
||||||
TimeLockIncomplete = 'TIME_LOCK_INCOMPLETE',
|
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 {
|
export enum StatusCodes {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user