diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-03 00:00:37 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-03 00:00:37 +0800 |
commit | abf2cf4c5e2ea6d09d862871adfa16ca108907e2 (patch) | |
tree | 576899e4e72b89e62300443e613735f3f5e70ba7 | |
parent | 54e8bf773091eb2c8587c72e50892afec42abb9d (diff) | |
download | dexon-sol-tools-abf2cf4c5e2ea6d09d862871adfa16ca108907e2.tar dexon-sol-tools-abf2cf4c5e2ea6d09d862871adfa16ca108907e2.tar.gz dexon-sol-tools-abf2cf4c5e2ea6d09d862871adfa16ca108907e2.tar.bz2 dexon-sol-tools-abf2cf4c5e2ea6d09d862871adfa16ca108907e2.tar.lz dexon-sol-tools-abf2cf4c5e2ea6d09d862871adfa16ca108907e2.tar.xz dexon-sol-tools-abf2cf4c5e2ea6d09d862871adfa16ca108907e2.tar.zst dexon-sol-tools-abf2cf4c5e2ea6d09d862871adfa16ca108907e2.zip |
Move FillOrderValidatinErrs to ExchangeContractErrs
-rw-r--r-- | src/contract_wrappers/exchange_wrapper.ts | 25 | ||||
-rw-r--r-- | src/types.ts | 12 | ||||
-rw-r--r-- | test/exchange_wrapper_test.ts | 26 |
3 files changed, 28 insertions, 35 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 828994829..716f9c77a 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -5,7 +5,6 @@ import { ExchangeContract, ExchangeContractErrCodes, ExchangeContractErrs, - FillOrderValidationErrs, OrderValues, OrderAddresses, SignedOrder, @@ -126,14 +125,14 @@ export class ExchangeWrapper extends ContractWrapper { fillTakerAmount: BigNumber.BigNumber, senderAddress: string): Promise<void> { if (fillTakerAmount.eq(0)) { - throw new Error(FillOrderValidationErrs.FILL_AMOUNT_IS_ZERO); + throw new Error(ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO); } if (signedOrder.taker !== constants.NULL_ADDRESS && signedOrder.taker !== senderAddress) { - throw new Error(FillOrderValidationErrs.TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER); + throw new Error(ExchangeContractErrs.TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER); } const currentUnixTimestampSec = Date.now() / 1000; if (signedOrder.expirationUnixTimestampSec.lessThan(currentUnixTimestampSec)) { - throw new Error(FillOrderValidationErrs.FILL_ORDER_EXPIRED); + throw new Error(ExchangeContractErrs.ORDER_FILL_EXPIRED); } const zrxTokenAddress = await this.getZRXTokenAddressAsync(); await this.validateFillOrderBalancesAndAllowancesAndThrowIfInvalidAsync(signedOrder, fillTakerAmount, @@ -143,7 +142,7 @@ export class ExchangeWrapper extends ContractWrapper { signedOrder.takerTokenAmount, fillTakerAmount, signedOrder.makerTokenAmount, ); if (wouldRoundingErrorOccur) { - throw new Error(FillOrderValidationErrs.ROUNDING_ERROR); + throw new Error(ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR); } } private async validateFillOrderBalancesAndAllowancesAndThrowIfInvalidAsync(signedOrder: SignedOrder, @@ -168,16 +167,16 @@ export class ExchangeWrapper extends ContractWrapper { const fillMakerAmountInBaseUnits = fillTakerAmount.div(exchangeRate); if (fillTakerAmount.greaterThan(takerBalance)) { - throw new Error(FillOrderValidationErrs.NOT_ENOUGH_TAKER_BALANCE); + throw new Error(ExchangeContractErrs.NOT_ENOUGH_TAKER_BALANCE); } if (fillTakerAmount.greaterThan(takerAllowance)) { - throw new Error(FillOrderValidationErrs.NOT_ENOUGH_TAKER_ALLOWANCE); + throw new Error(ExchangeContractErrs.NOT_ENOUGH_TAKER_ALLOWANCE); } if (fillMakerAmountInBaseUnits.greaterThan(makerBalance)) { - throw new Error(FillOrderValidationErrs.NOT_ENOUGH_MAKER_BALANCE); + throw new Error(ExchangeContractErrs.NOT_ENOUGH_MAKER_BALANCE); } if (fillMakerAmountInBaseUnits.greaterThan(makerAllowance)) { - throw new Error(FillOrderValidationErrs.NOT_ENOUGH_MAKER_ALLOWANCE); + throw new Error(ExchangeContractErrs.NOT_ENOUGH_MAKER_ALLOWANCE); } const makerFeeBalance = await this.tokenWrapper.getBalanceAsync(zrxTokenAddress, @@ -189,16 +188,16 @@ export class ExchangeWrapper extends ContractWrapper { senderAddress); if (signedOrder.takerFee.greaterThan(takerFeeBalance)) { - throw new Error(FillOrderValidationErrs.NOT_ENOUGH_TAKER_FEE_BALANCE); + throw new Error(ExchangeContractErrs.NOT_ENOUGH_TAKER_FEE_BALANCE); } if (signedOrder.takerFee.greaterThan(takerFeeAllowance)) { - throw new Error(FillOrderValidationErrs.NOT_ENOUGH_TAKER_FEE_ALLOWANCE); + throw new Error(ExchangeContractErrs.NOT_ENOUGH_TAKER_FEE_ALLOWANCE); } if (signedOrder.makerFee.greaterThan(makerFeeBalance)) { - throw new Error(FillOrderValidationErrs.NOT_ENOUGH_MAKER_FEE_BALANCE); + throw new Error(ExchangeContractErrs.NOT_ENOUGH_MAKER_FEE_BALANCE); } if (signedOrder.makerFee.greaterThan(makerFeeAllowance)) { - throw new Error(FillOrderValidationErrs.NOT_ENOUGH_MAKER_FEE_ALLOWANCE); + throw new Error(ExchangeContractErrs.NOT_ENOUGH_MAKER_FEE_ALLOWANCE); } } private throwErrorLogsAsErrors(logs: ContractEvent[]): void { diff --git a/src/types.ts b/src/types.ts index e4a7da5d7..6cd5a93fe 100644 --- a/src/types.ts +++ b/src/types.ts @@ -89,13 +89,6 @@ export const ExchangeContractErrs = strEnum([ 'ORDER_REMAINING_FILL_AMOUNT_ZERO', 'ORDER_FILL_ROUNDING_ERROR', 'FILL_BALANCE_ALLOWANCE_ERROR', -]); -export type ExchangeContractErrs = keyof typeof ExchangeContractErrs; - -export const FillOrderValidationErrs = strEnum([ - 'FILL_AMOUNT_IS_ZERO', - 'TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER', - 'FILL_ORDER_EXPIRED', 'NOT_ENOUGH_TAKER_BALANCE', 'NOT_ENOUGH_TAKER_ALLOWANCE', 'NOT_ENOUGH_MAKER_BALANCE', @@ -104,9 +97,10 @@ export const FillOrderValidationErrs = strEnum([ 'NOT_ENOUGH_TAKER_FEE_ALLOWANCE', 'NOT_ENOUGH_MAKER_FEE_BALANCE', 'NOT_ENOUGH_MAKER_FEE_ALLOWANCE', - 'ROUNDING_ERROR', + 'TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER', + ]); -export type FillOrderValidationErrs = keyof typeof FillOrderValidationErrs; +export type ExchangeContractErrs = keyof typeof ExchangeContractErrs; export interface ContractResponse { logs: ContractEvent[]; diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index e83134909..c05c5c26f 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -9,7 +9,7 @@ import promisify = require('es6-promisify'); import {web3Factory} from './utils/web3_factory'; import {ZeroEx} from '../src/0x.js'; import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; -import {FillOrderValidationErrs, SignedOrder, Token} from '../src/types'; +import {ExchangeContractErrs, SignedOrder, Token} from '../src/types'; import {FillScenarios} from './utils/fill_scenarios'; import {TokenUtils} from './utils/token_utils'; @@ -138,7 +138,7 @@ describe('ExchangeWrapper', () => { zeroEx.setTransactionSenderAccount(takerAddress); return expect(zeroEx.exchange.fillOrderAsync( signedOrder, zeroFillAmount, shouldCheckTransfer, - )).to.be.rejectedWith(FillOrderValidationErrs.FILL_AMOUNT_IS_ZERO); + )).to.be.rejectedWith(ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO); }); it('should throw when sender is not a taker', async () => { const fillableAmount = new BigNumber(5); @@ -147,7 +147,7 @@ describe('ExchangeWrapper', () => { ); return expect(zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmount, shouldCheckTransfer, - )).to.be.rejectedWith(FillOrderValidationErrs.TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER); + )).to.be.rejectedWith(ExchangeContractErrs.TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER); }); it('should throw when order is expired', async () => { const expirationInPast = new BigNumber(42); @@ -158,7 +158,7 @@ describe('ExchangeWrapper', () => { zeroEx.setTransactionSenderAccount(takerAddress); return expect(zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmount, shouldCheckTransfer, - )).to.be.rejectedWith(FillOrderValidationErrs.FILL_ORDER_EXPIRED); + )).to.be.rejectedWith(ExchangeContractErrs.ORDER_FILL_EXPIRED); }); describe('should throw when not enough balance or allowance to fulfill the order', () => { const fillableAmount = new BigNumber(5); @@ -176,7 +176,7 @@ describe('ExchangeWrapper', () => { zeroEx.setTransactionSenderAccount(takerAddress); return expect(zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmount, shouldCheckTransfer, - )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_BALANCE); + )).to.be.rejectedWith(ExchangeContractErrs.NOT_ENOUGH_TAKER_BALANCE); }); it('should throw when taker allowance is less than fill amount', async () => { const newAllowanceWhichIsLessThanFillAmount = fillTakerAmount.minus(lackingAllowance); @@ -185,14 +185,14 @@ describe('ExchangeWrapper', () => { zeroEx.setTransactionSenderAccount(takerAddress); return expect(zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmount, shouldCheckTransfer, - )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_ALLOWANCE); + )).to.be.rejectedWith(ExchangeContractErrs.NOT_ENOUGH_TAKER_ALLOWANCE); }); it('should throw when maker balance is less than maker fill amount', async () => { await zeroEx.token.transferAsync(makerTokenAddress, makerAddress, coinbase, lackingBalance); zeroEx.setTransactionSenderAccount(takerAddress); return expect(zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmount, shouldCheckTransfer, - )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_MAKER_BALANCE); + )).to.be.rejectedWith(ExchangeContractErrs.NOT_ENOUGH_MAKER_BALANCE); }); it('should throw when maker allowance is less than maker fill amount', async () => { const newAllowanceWhichIsLessThanFillAmount = fillTakerAmount.minus(lackingAllowance); @@ -201,7 +201,7 @@ describe('ExchangeWrapper', () => { zeroEx.setTransactionSenderAccount(takerAddress); return expect(zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmount, shouldCheckTransfer, - )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_MAKER_ALLOWANCE); + )).to.be.rejectedWith(ExchangeContractErrs.NOT_ENOUGH_MAKER_ALLOWANCE); }); }); it('should throw when there would be a rounding error', async () => { @@ -215,7 +215,7 @@ describe('ExchangeWrapper', () => { zeroEx.setTransactionSenderAccount(takerAddress); return expect(zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmountThatCausesRoundingError, shouldCheckTransfer, - )).to.be.rejectedWith(FillOrderValidationErrs.ROUNDING_ERROR); + )).to.be.rejectedWith(ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR); }); describe('should raise when not enough balance or allowance to pay fees', () => { const fillableAmount = new BigNumber(5); @@ -234,7 +234,7 @@ describe('ExchangeWrapper', () => { await zeroEx.token.transferAsync(zrxTokenAddress, makerAddress, coinbase, lackingBalance); return expect(zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmount, shouldCheckTransfer, - )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_MAKER_FEE_BALANCE); + )).to.be.rejectedWith(ExchangeContractErrs.NOT_ENOUGH_MAKER_FEE_BALANCE); }); it('should throw when maker doesn\'t have enough allowance to pay fees', async () => { const newAllowanceWhichIsLessThanFees = makerFee.minus(1); @@ -242,14 +242,14 @@ describe('ExchangeWrapper', () => { newAllowanceWhichIsLessThanFees); return expect(zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmount, shouldCheckTransfer, - )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_MAKER_FEE_ALLOWANCE); + )).to.be.rejectedWith(ExchangeContractErrs.NOT_ENOUGH_MAKER_FEE_ALLOWANCE); }); it('should throw when taker doesn\'t have enough balance to pay fees', async () => { const lackingBalance = new BigNumber(1); await zeroEx.token.transferAsync(zrxTokenAddress, takerAddress, coinbase, lackingBalance); return expect(zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmount, shouldCheckTransfer, - )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_FEE_BALANCE); + )).to.be.rejectedWith(ExchangeContractErrs.NOT_ENOUGH_TAKER_FEE_BALANCE); }); it('should throw when taker doesn\'t have enough allowance to pay fees', async () => { const newAllowanceWhichIsLessThanFees = makerFee.minus(1); @@ -257,7 +257,7 @@ describe('ExchangeWrapper', () => { newAllowanceWhichIsLessThanFees); return expect(zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmount, shouldCheckTransfer, - )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_FEE_ALLOWANCE); + )).to.be.rejectedWith(ExchangeContractErrs.NOT_ENOUGH_TAKER_FEE_ALLOWANCE); }); }); }); |