aboutsummaryrefslogtreecommitdiffstats
path: root/test/exchange_wrapper_test.ts
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 /test/exchange_wrapper_test.ts
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
Diffstat (limited to 'test/exchange_wrapper_test.ts')
-rw-r--r--test/exchange_wrapper_test.ts47
1 files changed, 32 insertions, 15 deletions
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', () => {