aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-12-08 07:59:15 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-12-19 05:36:05 +0800
commit51355209a2a43a1a7b5a72c78aabefcdac5ede33 (patch)
treea34a11204691c910bc59a28bcdd0f23759776203 /packages
parent4b0d01ad72b93e8ccb01ca2eabe521cdf78eeea2 (diff)
downloaddexon-sol-tools-51355209a2a43a1a7b5a72c78aabefcdac5ede33.tar.gz
dexon-sol-tools-51355209a2a43a1a7b5a72c78aabefcdac5ede33.tar.zst
dexon-sol-tools-51355209a2a43a1a7b5a72c78aabefcdac5ede33.zip
Tests for batchFill variants
Diffstat (limited to 'packages')
-rw-r--r--packages/contracts/test/extensions/balance_threshold_filter.ts214
1 files changed, 203 insertions, 11 deletions
diff --git a/packages/contracts/test/extensions/balance_threshold_filter.ts b/packages/contracts/test/extensions/balance_threshold_filter.ts
index c91d4880e..003bc2cdc 100644
--- a/packages/contracts/test/extensions/balance_threshold_filter.ts
+++ b/packages/contracts/test/extensions/balance_threshold_filter.ts
@@ -317,16 +317,7 @@ describe.only(ContractName.BalanceThresholdFilter, () => {
// @TODO - greater than 1 balance
});
- describe('batchFillOrdersNoThrow', () => {
- });
-
- describe('batchFillOrKillOrders', () => {
- });
-
- describe('batchFillOrKillOrders', () => {
- });
-
- describe.only('batchFillOrders', () => {
+ describe('batchFillOrders', () => {
beforeEach(async () => {
erc20Balances = await erc20Wrapper.getBalancesAsync();
compliantSignedOrder = await orderFactory.newSignedOrderAsync();
@@ -420,6 +411,207 @@ describe.only(ContractName.BalanceThresholdFilter, () => {
});
});
+ describe('batchFillOrdersNoThrow', () => {
+ beforeEach(async () => {
+ erc20Balances = await erc20Wrapper.getBalancesAsync();
+ compliantSignedOrder = await orderFactory.newSignedOrderAsync();
+ compliantSignedOrder2 = await orderFactory2.newSignedOrderAsync();
+ });
+ it('should transfer the correct amounts and validate both makers/taker when both maker and taker meet the balance threshold', async () => {
+ // Execute a valid fill
+ const orders = [compliantSignedOrder, compliantSignedOrder2];
+ const takerAssetFillAmounts = [takerAssetFillAmount, takerAssetFillAmount];
+ const txReceipt = await balanceThresholdWrapper.batchFillOrdersNoThrowAsync(orders, compliantTakerAddress, {takerAssetFillAmounts});
+ // Assert validated addresses
+ const expectedValidatedAddresseses = [compliantSignedOrder.makerAddress, compliantSignedOrder2.makerAddress, compliantSignedFillOrderTx.signerAddress];
+ assertValidatedAddressesLog(txReceipt, expectedValidatedAddresseses);
+ // Check balances
+ const newBalances = await erc20Wrapper.getBalancesAsync();
+ const cumulativeTakerAssetFillAmount = takerAssetFillAmount.times(2);
+ const makerAssetFillAmount = takerAssetFillAmount
+ .times(compliantSignedOrder.makerAssetAmount)
+ .dividedToIntegerBy(compliantSignedOrder.takerAssetAmount);
+ const makerFeePaid = compliantSignedOrder.makerFee
+ .times(makerAssetFillAmount)
+ .dividedToIntegerBy(compliantSignedOrder.makerAssetAmount);
+ const takerFeePaid = compliantSignedOrder.takerFee
+ .times(makerAssetFillAmount)
+ .dividedToIntegerBy(compliantSignedOrder.makerAssetAmount)
+ .times(2);
+ // Maker #1
+ expect(newBalances[compliantMakerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
+ erc20Balances[compliantMakerAddress][defaultMakerAssetAddress].minus(makerAssetFillAmount),
+ );
+ expect(newBalances[compliantMakerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
+ erc20Balances[compliantMakerAddress][defaultTakerAssetAddress].add(takerAssetFillAmount),
+ );
+ expect(newBalances[compliantMakerAddress][zrxToken.address]).to.be.bignumber.equal(
+ erc20Balances[compliantMakerAddress][zrxToken.address].minus(makerFeePaid),
+ );
+ // Maker #2
+ expect(newBalances[compliantMakerAddress2][defaultMakerAssetAddress]).to.be.bignumber.equal(
+ erc20Balances[compliantMakerAddress2][defaultMakerAssetAddress].minus(makerAssetFillAmount),
+ );
+ expect(newBalances[compliantMakerAddress2][defaultTakerAssetAddress]).to.be.bignumber.equal(
+ erc20Balances[compliantMakerAddress2][defaultTakerAssetAddress].add(takerAssetFillAmount),
+ );
+ expect(newBalances[compliantMakerAddress2][zrxToken.address]).to.be.bignumber.equal(
+ erc20Balances[compliantMakerAddress2][zrxToken.address].minus(makerFeePaid),
+ );
+ // Taker
+ expect(newBalances[compliantTakerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
+ erc20Balances[compliantTakerAddress][defaultTakerAssetAddress].minus(cumulativeTakerAssetFillAmount),
+ );
+
+ expect(newBalances[compliantTakerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
+ erc20Balances[compliantTakerAddress][defaultMakerAssetAddress].add(makerAssetFillAmount.times(2)),
+ );
+ expect(newBalances[compliantTakerAddress][zrxToken.address]).to.be.bignumber.equal(
+ erc20Balances[compliantTakerAddress][zrxToken.address].minus(takerFeePaid),
+ );
+ // Fee recipient
+ expect(newBalances[feeRecipientAddress][zrxToken.address]).to.be.bignumber.equal(
+ erc20Balances[feeRecipientAddress][zrxToken.address].add(makerFeePaid.times(2).add(takerFeePaid)),
+ );
+ });
+ it('should revert if one maker does not meet the balance threshold', async () => {
+ // Create order set with one non-compliant maker address
+ const takerAssetFillAmounts = [takerAssetFillAmount, takerAssetFillAmount];
+ const signedOrderWithBadMakerAddress = await orderFactory.newSignedOrderAsync({
+ makerAddress: nonCompliantAddress
+ });
+ const orders = [compliantSignedOrder, signedOrderWithBadMakerAddress];
+ // Execute transaction
+ return expectTransactionFailedAsync(
+ balanceThresholdWrapper.batchFillOrdersNoThrowAsync(
+ orders,
+ compliantTakerAddress,
+ {takerAssetFillAmounts}
+ ),
+ RevertReason.AtLeastOneAddressDoesNotMeetBalanceThreshold
+ );
+ });
+ it('should revert if taker does not meet the balance threshold', async () => {
+ const orders = [compliantSignedOrder, compliantSignedOrder2];
+ const takerAssetFillAmounts = [takerAssetFillAmount, takerAssetFillAmount];
+ return expectTransactionFailedAsync(
+ nonCompliantBalanceThresholdWrapper.batchFillOrdersNoThrowAsync(
+ orders,
+ nonCompliantAddress,
+ {takerAssetFillAmounts}
+ ),
+ RevertReason.AtLeastOneAddressDoesNotMeetBalanceThreshold
+ );
+ });
+ });
+
+ describe.only('batchFillOrKillOrders', () => {
+ beforeEach(async () => {
+ erc20Balances = await erc20Wrapper.getBalancesAsync();
+ compliantSignedOrder = await orderFactory.newSignedOrderAsync();
+ compliantSignedOrder2 = await orderFactory2.newSignedOrderAsync();
+ });
+ it('should transfer the correct amounts and validate both makers/taker when both makers and taker meet the balance threshold', async () => {
+ // Execute a valid fill
+ const orders = [compliantSignedOrder, compliantSignedOrder2];
+ const takerAssetFillAmounts = [takerAssetFillAmount, takerAssetFillAmount];
+ const txReceipt = await balanceThresholdWrapper.batchFillOrKillOrdersAsync(orders, compliantTakerAddress, {takerAssetFillAmounts});
+ // Assert validated addresses
+ const expectedValidatedAddresseses = [compliantSignedOrder.makerAddress, compliantSignedOrder2.makerAddress, compliantSignedFillOrderTx.signerAddress];
+ assertValidatedAddressesLog(txReceipt, expectedValidatedAddresseses);
+ // Check balances
+ const newBalances = await erc20Wrapper.getBalancesAsync();
+ const cumulativeTakerAssetFillAmount = takerAssetFillAmount.times(2);
+ const makerAssetFillAmount = takerAssetFillAmount
+ .times(compliantSignedOrder.makerAssetAmount)
+ .dividedToIntegerBy(compliantSignedOrder.takerAssetAmount);
+ const makerFeePaid = compliantSignedOrder.makerFee
+ .times(makerAssetFillAmount)
+ .dividedToIntegerBy(compliantSignedOrder.makerAssetAmount);
+ const takerFeePaid = compliantSignedOrder.takerFee
+ .times(makerAssetFillAmount)
+ .dividedToIntegerBy(compliantSignedOrder.makerAssetAmount)
+ .times(2);
+ // Maker #1
+ expect(newBalances[compliantMakerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
+ erc20Balances[compliantMakerAddress][defaultMakerAssetAddress].minus(makerAssetFillAmount),
+ );
+ expect(newBalances[compliantMakerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
+ erc20Balances[compliantMakerAddress][defaultTakerAssetAddress].add(takerAssetFillAmount),
+ );
+ expect(newBalances[compliantMakerAddress][zrxToken.address]).to.be.bignumber.equal(
+ erc20Balances[compliantMakerAddress][zrxToken.address].minus(makerFeePaid),
+ );
+ // Maker #2
+ expect(newBalances[compliantMakerAddress2][defaultMakerAssetAddress]).to.be.bignumber.equal(
+ erc20Balances[compliantMakerAddress2][defaultMakerAssetAddress].minus(makerAssetFillAmount),
+ );
+ expect(newBalances[compliantMakerAddress2][defaultTakerAssetAddress]).to.be.bignumber.equal(
+ erc20Balances[compliantMakerAddress2][defaultTakerAssetAddress].add(takerAssetFillAmount),
+ );
+ expect(newBalances[compliantMakerAddress2][zrxToken.address]).to.be.bignumber.equal(
+ erc20Balances[compliantMakerAddress2][zrxToken.address].minus(makerFeePaid),
+ );
+ // Taker
+ expect(newBalances[compliantTakerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
+ erc20Balances[compliantTakerAddress][defaultTakerAssetAddress].minus(cumulativeTakerAssetFillAmount),
+ );
+
+ expect(newBalances[compliantTakerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
+ erc20Balances[compliantTakerAddress][defaultMakerAssetAddress].add(makerAssetFillAmount.times(2)),
+ );
+ expect(newBalances[compliantTakerAddress][zrxToken.address]).to.be.bignumber.equal(
+ erc20Balances[compliantTakerAddress][zrxToken.address].minus(takerFeePaid),
+ );
+ // Fee recipient
+ expect(newBalances[feeRecipientAddress][zrxToken.address]).to.be.bignumber.equal(
+ erc20Balances[feeRecipientAddress][zrxToken.address].add(makerFeePaid.times(2).add(takerFeePaid)),
+ );
+ });
+ it('should revert if one maker does not meet the balance threshold', async () => {
+ // Create order set with one non-compliant maker address
+ const takerAssetFillAmounts = [takerAssetFillAmount, takerAssetFillAmount];
+ const signedOrderWithBadMakerAddress = await orderFactory.newSignedOrderAsync({
+ makerAddress: nonCompliantAddress
+ });
+ const orders = [compliantSignedOrder, signedOrderWithBadMakerAddress];
+ // Execute transaction
+ return expectTransactionFailedAsync(
+ balanceThresholdWrapper.batchFillOrKillOrdersAsync(
+ orders,
+ compliantTakerAddress,
+ {takerAssetFillAmounts}
+ ),
+ RevertReason.AtLeastOneAddressDoesNotMeetBalanceThreshold
+ );
+ });
+ it('should revert if taker does not meet the balance threshold', async () => {
+ const orders = [compliantSignedOrder, compliantSignedOrder2];
+ const takerAssetFillAmounts = [takerAssetFillAmount, takerAssetFillAmount];
+ return expectTransactionFailedAsync(
+ nonCompliantBalanceThresholdWrapper.batchFillOrKillOrdersAsync(
+ orders,
+ nonCompliantAddress,
+ {takerAssetFillAmounts}
+ ),
+ RevertReason.AtLeastOneAddressDoesNotMeetBalanceThreshold
+ );
+ });
+ it('should revert if one takerAssetFillAmount is not fully filled', async () => {
+ const tooBigTakerAssetFillAmount = compliantSignedOrder.takerAssetAmount.times(2);
+ const orders = [compliantSignedOrder, compliantSignedOrder2];
+ const takerAssetFillAmounts = [takerAssetFillAmount, tooBigTakerAssetFillAmount];
+ return expectTransactionFailedAsync(
+ balanceThresholdWrapper.batchFillOrKillOrdersAsync(
+ orders,
+ compliantTakerAddress,
+ {takerAssetFillAmounts}
+ ),
+ RevertReason.FailedExecution
+ );
+ });
+ });
+
/*
describe.only('fillOrderNoThrow', () => {
beforeEach(async () => {
@@ -564,7 +756,7 @@ describe.only(ContractName.BalanceThresholdFilter, () => {
RevertReason.AtLeastOneAddressDoesNotMeetBalanceThreshold
);
});
- it('should revert if order is not fully filled', async () => {
+ it('should revert if takerAssetFillAmount is not fully filled', async () => {
const tooBigTakerAssetFillAmount = compliantSignedOrder.takerAssetAmount.times(2);
return expectTransactionFailedAsync(
balanceThresholdWrapper.fillOrKillOrderAsync(