Update affiliate fee tests
This commit is contained in:
@@ -20,7 +20,7 @@ import { TestEth2DaiContract, TestUniswapExchangeContract } from '../wrappers';
|
||||
import { deployForwarderAsync } from './deploy_forwarder';
|
||||
import { ForwarderTestFactory } from './forwarder_test_factory';
|
||||
|
||||
blockchainTests.resets('Forwarder <> ERC20Bridge integration tests', env => {
|
||||
blockchainTests.resets.only('Forwarder <> ERC20Bridge integration tests', env => {
|
||||
let deployment: DeploymentManager;
|
||||
let balanceStore: BlockchainBalanceStore;
|
||||
let testFactory: ForwarderTestFactory;
|
||||
@@ -193,7 +193,7 @@ blockchainTests.resets('Forwarder <> ERC20Bridge integration tests', env => {
|
||||
eth2DaiBridgeOrder,
|
||||
await maker.signOrderAsync({ makerAssetData: makerTokenAssetData }), // Non-bridge order of the same ERC20
|
||||
];
|
||||
await testFactory.marketSellTestAsync(orders, 2.56, { forwarderFeePercentage: 1 });
|
||||
await testFactory.marketSellTestAsync(orders, 2.56, { forwarderFeeAmount: toBaseUnitAmount(0.1) });
|
||||
});
|
||||
it('should fully fill a single UniswapBridge order without a taker fee', async () => {
|
||||
await testFactory.marketSellTestAsync([uniswapBridgeOrder], 1);
|
||||
@@ -234,7 +234,7 @@ blockchainTests.resets('Forwarder <> ERC20Bridge integration tests', env => {
|
||||
uniswapBridgeOrder,
|
||||
await maker.signOrderAsync({ makerAssetData: makerTokenAssetData }), // Non-bridge order of the same ERC20
|
||||
];
|
||||
await testFactory.marketSellTestAsync(orders, 2.56, { forwarderFeePercentage: 1 });
|
||||
await testFactory.marketSellTestAsync(orders, 2.56, { forwarderFeeAmount: toBaseUnitAmount(0.1) });
|
||||
});
|
||||
it('should fill multiple bridge orders', async () => {
|
||||
await testFactory.marketSellTestAsync([eth2DaiBridgeOrder, uniswapBridgeOrder], 1.23);
|
||||
@@ -292,7 +292,7 @@ blockchainTests.resets('Forwarder <> ERC20Bridge integration tests', env => {
|
||||
eth2DaiBridgeOrder,
|
||||
await maker.signOrderAsync({ makerAssetData: makerTokenAssetData }), // Non-bridge order of the same ERC20
|
||||
];
|
||||
await testFactory.marketBuyTestAsync(orders, 2.56, { forwarderFeePercentage: 1 });
|
||||
await testFactory.marketBuyTestAsync(orders, 2.56, { forwarderFeeAmount: toBaseUnitAmount(0.1) });
|
||||
});
|
||||
it('should revert if the amount of ETH sent is too low to fill the makerAssetAmount (Eth2Dai)', async () => {
|
||||
const expectedError = new ExchangeForwarderRevertErrors.CompleteBuyFailedError(
|
||||
@@ -343,7 +343,7 @@ blockchainTests.resets('Forwarder <> ERC20Bridge integration tests', env => {
|
||||
uniswapBridgeOrder,
|
||||
await maker.signOrderAsync({ makerAssetData: makerTokenAssetData }), // Non-bridge order of the same ERC20
|
||||
];
|
||||
await testFactory.marketBuyTestAsync(orders, 2.56, { forwarderFeePercentage: 1 });
|
||||
await testFactory.marketBuyTestAsync(orders, 2.56, { forwarderFeeAmount: toBaseUnitAmount(0.1) });
|
||||
});
|
||||
it('should revert if the amount of ETH sent is too low to fill the makerAssetAmount (Uniswap)', async () => {
|
||||
const expectedError = new ExchangeForwarderRevertErrors.CompleteBuyFailedError(
|
||||
|
@@ -7,7 +7,6 @@ import {
|
||||
constants,
|
||||
expect,
|
||||
getLatestBlockTimestampAsync,
|
||||
getPercentageOfValue,
|
||||
toBaseUnitAmount,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
@@ -24,7 +23,7 @@ import { DeploymentManager } from '../framework/deployment_manager';
|
||||
import { deployForwarderAsync } from './deploy_forwarder';
|
||||
import { ForwarderTestFactory } from './forwarder_test_factory';
|
||||
|
||||
blockchainTests('Forwarder integration tests', env => {
|
||||
blockchainTests.only('Forwarder integration tests', env => {
|
||||
let deployment: DeploymentManager;
|
||||
let forwarder: ForwarderContract;
|
||||
let balanceStore: BlockchainBalanceStore;
|
||||
@@ -312,18 +311,7 @@ blockchainTests('Forwarder integration tests', env => {
|
||||
takerAssetAmount: toBaseUnitAmount(36),
|
||||
});
|
||||
await testFactory.marketSellTestAsync([order], 0.67, {
|
||||
forwarderFeePercentage: new BigNumber(2),
|
||||
});
|
||||
});
|
||||
it('should fail if the fee is set too high', async () => {
|
||||
const order = await maker.signOrderAsync();
|
||||
const forwarderFeePercentage = new BigNumber(6);
|
||||
const revertError = new ExchangeForwarderRevertErrors.FeePercentageTooLargeError(
|
||||
getPercentageOfValue(constants.PERCENTAGE_DENOMINATOR, forwarderFeePercentage),
|
||||
);
|
||||
await testFactory.marketSellTestAsync([order], 0.5, {
|
||||
forwarderFeePercentage,
|
||||
revertError,
|
||||
forwarderFeeAmount: toBaseUnitAmount(0.2),
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -585,30 +573,19 @@ blockchainTests('Forwarder integration tests', env => {
|
||||
takerAssetAmount: toBaseUnitAmount(11),
|
||||
});
|
||||
await testFactory.marketBuyTestAsync([order], 0.33, {
|
||||
forwarderFeePercentage: new BigNumber(2),
|
||||
});
|
||||
});
|
||||
it('should fail if the fee is set too high', async () => {
|
||||
const order = await maker.signOrderAsync();
|
||||
const revertError = new ExchangeForwarderRevertErrors.FeePercentageTooLargeError(
|
||||
getPercentageOfValue(constants.PERCENTAGE_DENOMINATOR, new BigNumber(6)),
|
||||
);
|
||||
await testFactory.marketBuyTestAsync([order], 0.5, {
|
||||
forwarderFeePercentage: new BigNumber(6),
|
||||
revertError,
|
||||
forwarderFeeAmount: toBaseUnitAmount(0.2),
|
||||
});
|
||||
});
|
||||
it('should fail if there is not enough ETH remaining to pay the fee', async () => {
|
||||
const order = await maker.signOrderAsync();
|
||||
const forwarderFeePercentage = new BigNumber(2);
|
||||
const ethFee = getPercentageOfValue(
|
||||
order.takerAssetAmount.times(0.5).plus(DeploymentManager.protocolFee),
|
||||
forwarderFeePercentage,
|
||||
const forwarderFeeAmount = toBaseUnitAmount(1);
|
||||
const revertError = new ExchangeForwarderRevertErrors.InsufficientEthForFeeError(
|
||||
forwarderFeeAmount,
|
||||
forwarderFeeAmount.minus(1),
|
||||
);
|
||||
const revertError = new ExchangeForwarderRevertErrors.InsufficientEthForFeeError(ethFee, ethFee.minus(1));
|
||||
await testFactory.marketBuyTestAsync([order], 0.5, {
|
||||
ethValueAdjustment: -1,
|
||||
forwarderFeePercentage,
|
||||
forwarderFeeAmount,
|
||||
revertError,
|
||||
});
|
||||
});
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { IAssetDataContract } from '@0x/contracts-asset-proxy';
|
||||
import { ForwarderContract } from '@0x/contracts-exchange-forwarder';
|
||||
import { constants, expect, getPercentageOfValue, Numberish, OrderStatus, provider } from '@0x/contracts-test-utils';
|
||||
import { constants, expect, getPercentageOfValue, hexSlice, OrderStatus, provider } from '@0x/contracts-test-utils';
|
||||
import { AssetProxyId, OrderInfo, SignedOrder } from '@0x/types';
|
||||
import { BigNumber, hexUtils, RevertError } from '@0x/utils';
|
||||
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
@@ -19,7 +19,7 @@ interface ForwarderFillState {
|
||||
}
|
||||
|
||||
interface MarketSellOptions {
|
||||
forwarderFeePercentage: Numberish;
|
||||
forwarderFeeAmount: BigNumber;
|
||||
revertError: RevertError;
|
||||
bridgeExcessBuyAmount: BigNumber;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ export class ForwarderTestFactory {
|
||||
options: Partial<MarketBuyOptions> = {},
|
||||
): Promise<void> {
|
||||
const ethValueAdjustment = options.ethValueAdjustment || 0;
|
||||
const forwarderFeePercentage = options.forwarderFeePercentage || 0;
|
||||
const forwarderFeeAmount = options.forwarderFeeAmount || constants.ZERO_AMOUNT;
|
||||
|
||||
const orderInfoBefore = await Promise.all(
|
||||
orders.map(order => this._deployment.exchange.getOrderInfo(order).callAsync()),
|
||||
@@ -82,19 +82,16 @@ export class ForwarderTestFactory {
|
||||
makerAssetAcquiredAmount,
|
||||
} = await this._simulateForwarderFillAsync(orders, orderInfoBefore, fractionalNumberOfOrdersToFill, options);
|
||||
|
||||
const ethSpentOnForwarderFee = getPercentageOfValue(wethSpentAmount, forwarderFeePercentage);
|
||||
const feePercentage = getPercentageOfValue(constants.PERCENTAGE_DENOMINATOR, forwarderFeePercentage);
|
||||
|
||||
const tx = this._forwarder
|
||||
.marketBuyOrdersWithEth(
|
||||
orders,
|
||||
makerAssetAcquiredAmount.minus(options.bridgeExcessBuyAmount || 0),
|
||||
orders.map(signedOrder => signedOrder.signature),
|
||||
feePercentage,
|
||||
forwarderFeeAmount,
|
||||
this._forwarderFeeRecipient.address,
|
||||
)
|
||||
.awaitTransactionSuccessAsync({
|
||||
value: wethSpentAmount.plus(ethSpentOnForwarderFee).plus(ethValueAdjustment),
|
||||
value: wethSpentAmount.plus(forwarderFeeAmount).plus(ethValueAdjustment),
|
||||
from: this._taker.address,
|
||||
});
|
||||
|
||||
@@ -127,19 +124,17 @@ export class ForwarderTestFactory {
|
||||
options,
|
||||
);
|
||||
|
||||
const forwarderFeePercentage = options.forwarderFeePercentage || 0;
|
||||
const ethSpentOnForwarderFee = getPercentageOfValue(wethSpentAmount, forwarderFeePercentage);
|
||||
const feePercentage = getPercentageOfValue(constants.PERCENTAGE_DENOMINATOR, forwarderFeePercentage);
|
||||
const forwarderFeeAmount = options.forwarderFeeAmount || constants.ZERO_AMOUNT;
|
||||
|
||||
const tx = this._forwarder
|
||||
.marketSellOrdersWithEth(
|
||||
orders,
|
||||
orders.map(signedOrder => signedOrder.signature),
|
||||
feePercentage,
|
||||
forwarderFeeAmount,
|
||||
this._forwarderFeeRecipient.address,
|
||||
)
|
||||
.awaitTransactionSuccessAsync({
|
||||
value: wethSpentAmount.plus(ethSpentOnForwarderFee),
|
||||
value: wethSpentAmount.plus(forwarderFeeAmount),
|
||||
from: this._taker.address,
|
||||
});
|
||||
|
||||
@@ -214,10 +209,8 @@ export class ForwarderTestFactory {
|
||||
);
|
||||
}
|
||||
|
||||
const ethSpentOnForwarderFee = getPercentageOfValue(
|
||||
currentTotal.wethSpentAmount,
|
||||
options.forwarderFeePercentage || 0,
|
||||
);
|
||||
const ethSpentOnForwarderFee = options.forwarderFeeAmount || constants.ZERO_AMOUNT;
|
||||
|
||||
// In reality the Forwarder is a middleman in this transaction and the ETH gets wrapped and unwrapped.
|
||||
balances.sendEth(this._taker.address, this._forwarderFeeRecipient.address, ethSpentOnForwarderFee);
|
||||
|
||||
|
Reference in New Issue
Block a user