Refactor balance & allowance tests

This commit is contained in:
Leonid Logvinov
2017-06-02 16:25:05 +02:00
parent c650d1ba20
commit 07c61b1f9b

View File

@@ -160,54 +160,49 @@ describe('ExchangeWrapper', () => {
signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer, signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer,
)).to.be.rejectedWith(FillOrderValidationErrs.EXPIRED); )).to.be.rejectedWith(FillOrderValidationErrs.EXPIRED);
}); });
it('should throw when taker balance is less than fill amount', async () => { describe('should throw when not enough balance or allowance to fulfill the order', () => {
const fillableAmount = new BigNumber(5); const fillableAmount = new BigNumber(5);
const signedOrder = await fillScenarios.createFillableSignedOrderAsync( const lackingBalance = new BigNumber(3);
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, const lackingAllowance = new BigNumber(3);
); let signedOrder: SignedOrder;
zeroEx.setTransactionSenderAccount(takerAddress); beforeEach('create fillable signed order', async () => {
const moreThanTheBalance = new BigNumber(6); signedOrder = await fillScenarios.createFillableSignedOrderAsync(
return expect(zeroEx.exchange.fillOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
signedOrder, moreThanTheBalance, shouldCheckTransfer, );
)).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_BALANCE); });
}); it('should throw when taker balance is less than fill amount', async () => {
it('should throw when taker allowance is less than fill amount', async () => {
const fillableAmount = new BigNumber(5); await zeroEx.token.transferAsync(takerTokenAddress, takerAddress, coinBase, lackingBalance);
const signedOrder = await fillScenarios.createFillableSignedOrderAsync( zeroEx.setTransactionSenderAccount(takerAddress);
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, return expect(zeroEx.exchange.fillOrderAsync(
); signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer,
const newAllowanceWhichIsLessThanFillAmount = fillTakerAmountInBaseUnits.minus(1); )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_BALANCE);
await zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, });
newAllowanceWhichIsLessThanFillAmount); it('should throw when taker allowance is less than fill amount', async () => {
zeroEx.setTransactionSenderAccount(takerAddress); const newAllowanceWhichIsLessThanFillAmount = fillTakerAmountInBaseUnits.minus(lackingAllowance);
return expect(zeroEx.exchange.fillOrderAsync( await zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress,
signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer, newAllowanceWhichIsLessThanFillAmount);
)).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_ALLOWANCE); zeroEx.setTransactionSenderAccount(takerAddress);
}); return expect(zeroEx.exchange.fillOrderAsync(
it('should throw when maker balance is less than maker fill amount', async () => { signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer,
const fillableAmount = new BigNumber(5); )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_ALLOWANCE);
const signedOrder = await fillScenarios.createFillableSignedOrderAsync( });
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, it('should throw when maker balance is less than maker fill amount', async () => {
); await zeroEx.token.transferAsync(makerTokenAddress, makerAddress, coinBase, lackingBalance);
const lackingMakerBalance = new BigNumber(3); zeroEx.setTransactionSenderAccount(takerAddress);
await zeroEx.token.transferAsync(makerTokenAddress, makerAddress, coinBase, lackingMakerBalance); return expect(zeroEx.exchange.fillOrderAsync(
zeroEx.setTransactionSenderAccount(takerAddress); signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer,
return expect(zeroEx.exchange.fillOrderAsync( )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_MAKER_BALANCE);
signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer, });
)).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_MAKER_BALANCE); it('should throw when maker allowance is less than maker fill amount', async () => {
}); const newAllowanceWhichIsLessThanFillAmount = fillTakerAmountInBaseUnits.minus(lackingAllowance);
it('should throw when maker allowance is less than maker fill amount', async () => { await zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress,
const fillableAmount = new BigNumber(5); newAllowanceWhichIsLessThanFillAmount);
const signedOrder = await fillScenarios.createFillableSignedOrderAsync( zeroEx.setTransactionSenderAccount(takerAddress);
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, return expect(zeroEx.exchange.fillOrderAsync(
); signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer,
const newAllowanceWhichIsLessThanFillAmount = fillTakerAmountInBaseUnits.minus(1); )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_MAKER_ALLOWANCE);
await zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, });
newAllowanceWhichIsLessThanFillAmount);
zeroEx.setTransactionSenderAccount(takerAddress);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer,
)).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_MAKER_ALLOWANCE);
}); });
it('should throw when there would be a rounding error', async () => { it('should throw when there would be a rounding error', async () => {
const makerFillableAmount = new BigNumber(3); const makerFillableAmount = new BigNumber(3);