aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-06-02 18:03:52 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-06-02 18:03:52 +0800
commit5155f4980440f1c91006b124406c8b4a7a90e300 (patch)
tree1b6c6c75ce4a7b24d97a1c6da8cb69a4bb951265
parenta740498c8061bc7a3dafae82929b358e61bac2d4 (diff)
downloaddexon-sol-tools-5155f4980440f1c91006b124406c8b4a7a90e300.tar
dexon-sol-tools-5155f4980440f1c91006b124406c8b4a7a90e300.tar.gz
dexon-sol-tools-5155f4980440f1c91006b124406c8b4a7a90e300.tar.bz2
dexon-sol-tools-5155f4980440f1c91006b124406c8b4a7a90e300.tar.lz
dexon-sol-tools-5155f4980440f1c91006b124406c8b4a7a90e300.tar.xz
dexon-sol-tools-5155f4980440f1c91006b124406c8b4a7a90e300.tar.zst
dexon-sol-tools-5155f4980440f1c91006b124406c8b4a7a90e300.zip
Add test for insufficient balance and make all async tests async
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts3
-rw-r--r--test/exchange_wrapper_test.ts47
2 files changed, 35 insertions, 15 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index eace55f4d..e2ac07b55 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -141,6 +141,9 @@ export class ExchangeWrapper extends ContractWrapper {
if (fillAmount.greaterThan(takerBalance)) {
throw new Error(FillOrderValidationErrs.NOT_ENOUGH_TAKER_BALANCE);
}
+ if (fillAmount.greaterThan(takerAllowance)) {
+ throw new Error(FillOrderValidationErrs.NOT_ENOUGH_TAKER_ALLOWANCE);
+ }
}
private throwErrorLogsAsErrors(logs: ContractEvent[]): void {
const errEvent = _.find(logs, {event: 'LogError'});
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index 716adb63a..8d39c9e57 100644
--- a/test/exchange_wrapper_test.ts
+++ b/test/exchange_wrapper_test.ts
@@ -50,37 +50,37 @@ describe('ExchangeWrapper', () => {
r: signature.r,
s: signature.s,
};
- expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address))
+ return expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address))
.to.be.rejected();
});
- it('r lacks 0x prefix', () => {
+ it('r lacks 0x prefix', async () => {
const malformedR = signature.r.replace('0x', '');
const malformedSignature = {
v: signature.v,
r: malformedR,
s: signature.s,
};
- expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address))
+ return expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address))
.to.be.rejected();
});
- it('r is too short', () => {
+ it('r is too short', async () => {
const malformedR = signature.r.substr(10);
const malformedSignature = {
v: signature.v,
r: malformedR,
s: signature.s.replace('0', 'z'),
};
- expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address))
+ return expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address))
.to.be.rejected();
});
- it('s is not hex', () => {
+ it('s is not hex', async () => {
const malformedS = signature.s.replace('0', 'z');
const malformedSignature = {
v: signature.v,
r: signature.r,
s: malformedS,
};
- expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address))
+ return expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address))
.to.be.rejected();
});
});
@@ -132,16 +132,18 @@ describe('ExchangeWrapper', () => {
);
const zeroFillAmount = new BigNumber(0);
zeroEx.setTransactionSenderAccount(takerAddress);
- expect(zeroEx.exchange.fillOrderAsync(signedOrder, zeroFillAmount, shouldCheckTransfer))
- .to.be.rejectedWith(FillOrderValidationErrs.FILL_AMOUNT_IS_ZERO);
+ return expect(zeroEx.exchange.fillOrderAsync(
+ signedOrder, zeroFillAmount, shouldCheckTransfer,
+ )).to.be.rejectedWith(FillOrderValidationErrs.FILL_AMOUNT_IS_ZERO);
});
it('should throw when sender is not a taker', async () => {
const fillableAmount = new BigNumber(5);
const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
- expect(zeroEx.exchange.fillOrderAsync(signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer))
- .to.be.rejectedWith(FillOrderValidationErrs.NOT_A_TAKER);
+ return expect(zeroEx.exchange.fillOrderAsync(
+ signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer,
+ )).to.be.rejectedWith(FillOrderValidationErrs.NOT_A_TAKER);
});
it('should throw when order is expired', async () => {
const expirationInPast = new BigNumber(42);
@@ -150,8 +152,9 @@ describe('ExchangeWrapper', () => {
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, expirationInPast,
);
zeroEx.setTransactionSenderAccount(takerAddress);
- expect(zeroEx.exchange.fillOrderAsync(signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer))
- .to.be.rejectedWith(FillOrderValidationErrs.EXPIRED);
+ return expect(zeroEx.exchange.fillOrderAsync(
+ signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer,
+ )).to.be.rejectedWith(FillOrderValidationErrs.EXPIRED);
});
it('should throw when taker balance is less than fill amount', async () => {
const fillableAmount = new BigNumber(5);
@@ -160,8 +163,22 @@ describe('ExchangeWrapper', () => {
);
zeroEx.setTransactionSenderAccount(takerAddress);
const moreThanTheBalance = new BigNumber(6);
- expect(zeroEx.exchange.fillOrderAsync(signedOrder, moreThanTheBalance, shouldCheckTransfer))
- .to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_BALANCE);
+ return expect(zeroEx.exchange.fillOrderAsync(
+ signedOrder, moreThanTheBalance, shouldCheckTransfer,
+ )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_BALANCE);
+ });
+ it('should throw when taker allowance is less than fill amount', async () => {
+ const fillableAmount = new BigNumber(5);
+ const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
+ makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
+ );
+ const newAllowanceWhichIsLessThanFillAmount = fillTakerAmountInBaseUnits.minus(1);
+ await zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress,
+ newAllowanceWhichIsLessThanFillAmount);
+ zeroEx.setTransactionSenderAccount(takerAddress);
+ return expect(zeroEx.exchange.fillOrderAsync(
+ signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer,
+ )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_ALLOWANCE);
});
});
describe('successful fills', () => {