aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-06-02 18:57:21 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-06-02 18:57:21 +0800
commite1ee6b84945e729d894f6535be02f3541e43dbf0 (patch)
treeab58800b09c204ab05fb9c2a1161ded792d7e244 /test
parent2a0c6abbe7f9abeacc4fea05bc468413ec1f4732 (diff)
downloaddexon-0x-contracts-e1ee6b84945e729d894f6535be02f3541e43dbf0.tar.gz
dexon-0x-contracts-e1ee6b84945e729d894f6535be02f3541e43dbf0.tar.zst
dexon-0x-contracts-e1ee6b84945e729d894f6535be02f3541e43dbf0.zip
Add check for ROUNDING_ERROR and test for it
Diffstat (limited to 'test')
-rw-r--r--test/exchange_wrapper_test.ts31
-rw-r--r--test/utils/fill_scenarios.ts27
2 files changed, 40 insertions, 18 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index 66ba167cc..7f8bad377 100644
--- a/test/exchange_wrapper_test.ts
+++ b/test/exchange_wrapper_test.ts
@@ -127,7 +127,7 @@ describe('ExchangeWrapper', () => {
describe('failed fills', () => {
it('should throw when the fill amount is zero', async () => {
const fillableAmount = new BigNumber(5);
- const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
+ const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
const zeroFillAmount = new BigNumber(0);
@@ -138,7 +138,7 @@ describe('ExchangeWrapper', () => {
});
it('should throw when sender is not a taker', async () => {
const fillableAmount = new BigNumber(5);
- const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
+ const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
return expect(zeroEx.exchange.fillOrderAsync(
@@ -148,7 +148,7 @@ describe('ExchangeWrapper', () => {
it('should throw when order is expired', async () => {
const expirationInPast = new BigNumber(42);
const fillableAmount = new BigNumber(5);
- const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
+ const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, expirationInPast,
);
zeroEx.setTransactionSenderAccount(takerAddress);
@@ -158,7 +158,7 @@ describe('ExchangeWrapper', () => {
});
it('should throw when taker balance is less than fill amount', async () => {
const fillableAmount = new BigNumber(5);
- const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
+ const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
zeroEx.setTransactionSenderAccount(takerAddress);
@@ -169,7 +169,7 @@ describe('ExchangeWrapper', () => {
});
it('should throw when taker allowance is less than fill amount', async () => {
const fillableAmount = new BigNumber(5);
- const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
+ const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
const newAllowanceWhichIsLessThanFillAmount = fillTakerAmountInBaseUnits.minus(1);
@@ -182,7 +182,7 @@ describe('ExchangeWrapper', () => {
});
it('should throw when maker balance is less than maker fill amount', async () => {
const fillableAmount = new BigNumber(5);
- const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
+ const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
const lackingMakerBalance = new BigNumber(3);
@@ -194,7 +194,7 @@ describe('ExchangeWrapper', () => {
});
it('should throw when maker allowance is less than maker fill amount', async () => {
const fillableAmount = new BigNumber(5);
- const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
+ const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
const newAllowanceWhichIsLessThanFillAmount = fillTakerAmountInBaseUnits.minus(1);
@@ -205,11 +205,24 @@ describe('ExchangeWrapper', () => {
signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer,
)).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_MAKER_ALLOWANCE);
});
+ it('should throw when there would be a rounding error', async () => {
+ const makerFillableAmount = new BigNumber(3);
+ const takerFillableAmount = new BigNumber(5);
+ const signedOrder = await fillScenarios.createAsymetricFillableSignedOrderAsync(
+ makerTokenAddress, takerTokenAddress, makerAddress, takerAddress,
+ makerFillableAmount, takerFillableAmount,
+ );
+ const fillTakerAmountInBaseUnitsThatCausesRoundingError = new BigNumber(3);
+ zeroEx.setTransactionSenderAccount(takerAddress);
+ return expect(zeroEx.exchange.fillOrderAsync(
+ signedOrder, fillTakerAmountInBaseUnitsThatCausesRoundingError, shouldCheckTransfer,
+ )).to.be.rejectedWith(FillOrderValidationErrs.ROUNDING_ERROR);
+ });
});
describe('successful fills', () => {
it('should fill the valid order', async () => {
const fillableAmount = new BigNumber(5);
- const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
+ const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
@@ -234,7 +247,7 @@ describe('ExchangeWrapper', () => {
});
it('should partially fill the valid order', async () => {
const fillableAmount = new BigNumber(5);
- const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
+ const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
const partialFillAmount = new BigNumber(3);
diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts
index 3b66937e6..568b11ef8 100644
--- a/test/utils/fill_scenarios.ts
+++ b/test/utils/fill_scenarios.ts
@@ -14,20 +14,29 @@ export class FillScenarios {
this.tokens = tokens;
this.coinBase = userAddresses[0];
}
- public async createAFillableSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string,
- makerAddress: string, takerAddress: string,
- fillableAmount: BigNumber.BigNumber,
- expirationUnixTimestampSec?: BigNumber.BigNumber):
+ public async createFillableSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string,
+ makerAddress: string, takerAddress: string,
+ fillableAmount: BigNumber.BigNumber,
+ expirationUnixTimestampSec?: BigNumber.BigNumber):
Promise<SignedOrder> {
- await this.zeroEx.token.transferAsync(makerTokenAddress, this.coinBase, makerAddress, fillableAmount);
- await this.zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, fillableAmount);
- await this.zeroEx.token.transferAsync(takerTokenAddress, this.coinBase, takerAddress, fillableAmount);
- await this.zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, fillableAmount);
+ return this.createAsymetricFillableSignedOrderAsync(
+ makerTokenAddress, takerTokenAddress, makerAddress, takerAddress,
+ fillableAmount, fillableAmount, expirationUnixTimestampSec,
+ );
+ }
+ public async createAsymetricFillableSignedOrderAsync(
+ makerTokenAddress: string, takerTokenAddress: string, makerAddress: string, takerAddress: string,
+ makerFillableAmount: BigNumber.BigNumber, takerFillableAmount: BigNumber.BigNumber,
+ expirationUnixTimestampSec?: BigNumber.BigNumber): Promise<SignedOrder> {
+ await this.zeroEx.token.transferAsync(makerTokenAddress, this.coinBase, makerAddress, makerFillableAmount);
+ await this.zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, makerFillableAmount);
+ await this.zeroEx.token.transferAsync(takerTokenAddress, this.coinBase, takerAddress, takerFillableAmount);
+ await this.zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, takerFillableAmount);
const transactionSenderAccount = await this.zeroEx.getTransactionSenderAccountIfExistsAsync();
this.zeroEx.setTransactionSenderAccount(makerAddress);
const signedOrder = await orderFactory.createSignedOrderAsync(this.zeroEx, makerAddress,
- takerAddress, fillableAmount, makerTokenAddress, fillableAmount, takerTokenAddress,
+ takerAddress, makerFillableAmount, makerTokenAddress, takerFillableAmount, takerTokenAddress,
expirationUnixTimestampSec);
this.zeroEx.setTransactionSenderAccount(transactionSenderAccount as string);
return signedOrder;