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,23 +160,26 @@ 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);
const lackingAllowance = new BigNumber(3);
let signedOrder: SignedOrder;
beforeEach('create fillable signed order', async () => {
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
); );
});
it('should throw when taker balance is less than fill amount', async () => {
await zeroEx.token.transferAsync(takerTokenAddress, takerAddress, coinBase, lackingBalance);
zeroEx.setTransactionSenderAccount(takerAddress); zeroEx.setTransactionSenderAccount(takerAddress);
const moreThanTheBalance = new BigNumber(6);
return expect(zeroEx.exchange.fillOrderAsync( return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, moreThanTheBalance, shouldCheckTransfer, signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer,
)).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_BALANCE); )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_BALANCE);
}); });
it('should throw when taker allowance is less than fill amount', async () => { it('should throw when taker allowance is less than fill amount', async () => {
const fillableAmount = new BigNumber(5); const newAllowanceWhichIsLessThanFillAmount = fillTakerAmountInBaseUnits.minus(lackingAllowance);
const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
const newAllowanceWhichIsLessThanFillAmount = fillTakerAmountInBaseUnits.minus(1);
await zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, await zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress,
newAllowanceWhichIsLessThanFillAmount); newAllowanceWhichIsLessThanFillAmount);
zeroEx.setTransactionSenderAccount(takerAddress); zeroEx.setTransactionSenderAccount(takerAddress);
@@ -185,23 +188,14 @@ describe('ExchangeWrapper', () => {
)).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_ALLOWANCE); )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_ALLOWANCE);
}); });
it('should throw when maker balance is less than maker fill amount', async () => { it('should throw when maker balance is less than maker fill amount', async () => {
const fillableAmount = new BigNumber(5); await zeroEx.token.transferAsync(makerTokenAddress, makerAddress, coinBase, lackingBalance);
const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
const lackingMakerBalance = new BigNumber(3);
await zeroEx.token.transferAsync(makerTokenAddress, makerAddress, coinBase, lackingMakerBalance);
zeroEx.setTransactionSenderAccount(takerAddress); zeroEx.setTransactionSenderAccount(takerAddress);
return expect(zeroEx.exchange.fillOrderAsync( return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer, signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer,
)).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_MAKER_BALANCE); )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_MAKER_BALANCE);
}); });
it('should throw when maker allowance is less than maker fill amount', async () => { it('should throw when maker allowance is less than maker fill amount', async () => {
const fillableAmount = new BigNumber(5); const newAllowanceWhichIsLessThanFillAmount = fillTakerAmountInBaseUnits.minus(lackingAllowance);
const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
const newAllowanceWhichIsLessThanFillAmount = fillTakerAmountInBaseUnits.minus(1);
await zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, await zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress,
newAllowanceWhichIsLessThanFillAmount); newAllowanceWhichIsLessThanFillAmount);
zeroEx.setTransactionSenderAccount(takerAddress); zeroEx.setTransactionSenderAccount(takerAddress);
@@ -209,6 +203,7 @@ describe('ExchangeWrapper', () => {
signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer, signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer,
)).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_MAKER_ALLOWANCE); )).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);
const takerFillableAmount = new BigNumber(5); const takerFillableAmount = new BigNumber(5);