tests for invalid fee assets

This commit is contained in:
Michael Zhu 2019-08-19 10:24:54 -07:00
parent 7796c88be3
commit 090b83a237

View File

@ -297,19 +297,17 @@ describe(ContractName.Forwarder, () => {
expect(takerEthBalanceAfter).to.be.bignumber.equal(takerEthBalanceBefore.minus(totalEthSpent)); expect(takerEthBalanceAfter).to.be.bignumber.equal(takerEthBalanceBefore.minus(totalEthSpent));
}); });
it('should not fill orders with different makerAssetData than the first order', async () => { it('should not fill orders with different makerAssetData than the first order', async () => {
const firstOrderMakerAssetData = assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress); const firstOrderMakerAssetData = assetDataUtils.encodeERC20AssetData(erc20Token.address);
const erc20SignedOrder = await orderFactory.newSignedOrderAsync({ const firstOrder = await orderFactory.newSignedOrderAsync({
makerAssetData: firstOrderMakerAssetData, makerAssetData: firstOrderMakerAssetData,
}); });
const makerAssetId = erc721MakerAssetIds[0]; const secondOrderMakerAssetData = assetDataUtils.encodeERC20AssetData(secondErc20Token.address);
const secondOrderMakerAssetData = assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId); const secondOrder = await orderFactory.newSignedOrderAsync({
const erc721SignedOrder = await orderFactory.newSignedOrderAsync({
makerAssetAmount: new BigNumber(1),
makerAssetData: secondOrderMakerAssetData, makerAssetData: secondOrderMakerAssetData,
}); });
const orders = [erc20SignedOrder, erc721SignedOrder]; const orders = [firstOrder, secondOrder];
const revertError = new ForwarderRevertErrors.MakerAssetMismatchError( const revertError = new ForwarderRevertErrors.MakerAssetMismatchError(
firstOrderMakerAssetData, firstOrderMakerAssetData,
@ -319,6 +317,21 @@ describe(ContractName.Forwarder, () => {
revertError, revertError,
}); });
}); });
it('should fail to fill an order with a fee denominated in an asset other than makerAsset or WETH', async () => {
const makerAssetData = assetDataUtils.encodeERC20AssetData(erc20Token.address);
const takerFeeAssetData = assetDataUtils.encodeERC20AssetData(secondErc20Token.address);
const order = await orderFactory.newSignedOrderAsync({
makerAssetData,
takerFeeAssetData,
takerFee: Web3Wrapper.toBaseUnitAmount(1, DECIMALS_DEFAULT),
});
const revertError = new ForwarderRevertErrors.UnsupportedFeeError(takerFeeAssetData);
await forwarderTestFactory.marketSellTestAsync([order], new BigNumber(0.5), erc20Token, {
revertError,
});
});
}); });
describe('marketSellOrdersWithEth with extra fees', () => { describe('marketSellOrdersWithEth with extra fees', () => {
it('should fill the order and send fee to feeRecipient', async () => { it('should fill the order and send fee to feeRecipient', async () => {
@ -406,7 +419,7 @@ describe(ContractName.Forwarder, () => {
makerAssetId, makerAssetId,
}); });
}); });
it('should buy an ERC721 asset and pay WETH fees from a single fee order', async () => { it('should buy an ERC721 asset and pay a WETH fee', async () => {
const makerAssetId = erc721MakerAssetIds[0]; const makerAssetId = erc721MakerAssetIds[0];
const erc721orderWithWethFee = await orderFactory.newSignedOrderAsync({ const erc721orderWithWethFee = await orderFactory.newSignedOrderAsync({
makerAssetAmount: new BigNumber(1), makerAssetAmount: new BigNumber(1),
@ -418,6 +431,21 @@ describe(ContractName.Forwarder, () => {
makerAssetId, makerAssetId,
}); });
}); });
it('should fail to fill an order with a fee denominated in an asset other than makerAsset or WETH', async () => {
const makerAssetData = assetDataUtils.encodeERC20AssetData(erc20Token.address);
const takerFeeAssetData = assetDataUtils.encodeERC20AssetData(secondErc20Token.address);
const order = await orderFactory.newSignedOrderAsync({
makerAssetData,
takerFeeAssetData,
takerFee: Web3Wrapper.toBaseUnitAmount(1, DECIMALS_DEFAULT),
});
const revertError = new ForwarderRevertErrors.UnsupportedFeeError(takerFeeAssetData);
await forwarderTestFactory.marketBuyTestAsync([order], new BigNumber(0.5), erc20Token, {
revertError,
});
});
it('Should buy slightly greater MakerAsset when exchange rate is rounded', async () => { it('Should buy slightly greater MakerAsset when exchange rate is rounded', async () => {
// The 0x Protocol contracts round the exchange rate in favor of the Maker. // The 0x Protocol contracts round the exchange rate in favor of the Maker.
// In this case, the taker must round up how much they're going to spend, which // In this case, the taker must round up how much they're going to spend, which