aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers/exchange_wrapper.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-06-02 00:21:12 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-06-02 00:21:12 +0800
commit0554f947b12f36a1cd5f7be469123e794b467f0b (patch)
treec3d1a55af98063dadfb37cf588adc6e00dfdf3b1 /src/contract_wrappers/exchange_wrapper.ts
parent6ced554d9f6cf00d0d9e8f9ff8170af4f1cfbee3 (diff)
downloaddexon-sol-tools-0554f947b12f36a1cd5f7be469123e794b467f0b.tar
dexon-sol-tools-0554f947b12f36a1cd5f7be469123e794b467f0b.tar.gz
dexon-sol-tools-0554f947b12f36a1cd5f7be469123e794b467f0b.tar.bz2
dexon-sol-tools-0554f947b12f36a1cd5f7be469123e794b467f0b.tar.lz
dexon-sol-tools-0554f947b12f36a1cd5f7be469123e794b467f0b.tar.xz
dexon-sol-tools-0554f947b12f36a1cd5f7be469123e794b467f0b.tar.zst
dexon-sol-tools-0554f947b12f36a1cd5f7be469123e794b467f0b.zip
Add not enough taker balance tests
Diffstat (limited to 'src/contract_wrappers/exchange_wrapper.ts')
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index b2d201516..dd3c3c933 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -19,6 +19,7 @@ import {signedOrderSchema} from '../schemas/order_schemas';
import {SchemaValidator} from '../utils/schema_validator';
import {ContractResponse} from '../types';
import {constants} from '../utils/constants';
+import {TokenWrapper} from './token_wrapper';
export class ExchangeWrapper extends ContractWrapper {
private exchangeContractErrCodesToMsg = {
@@ -30,8 +31,10 @@ export class ExchangeWrapper extends ContractWrapper {
[ExchangeContractErrCodes.ERROR_FILL_BALANCE_ALLOWANCE]: ExchangeContractErrs.ORDER_BALANCE_ALLOWANCE_ERROR,
};
private exchangeContractIfExists?: ExchangeContract;
- constructor(web3Wrapper: Web3Wrapper) {
+ private tokenWrapper: TokenWrapper;
+ constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper) {
super(web3Wrapper);
+ this.tokenWrapper = tokenWrapper;
}
public invalidateContractInstance(): void {
delete this.exchangeContractIfExists;
@@ -117,7 +120,7 @@ export class ExchangeWrapper extends ContractWrapper {
);
this.throwErrorLogsAsErrors(response.logs);
}
- private validateFillOrder(signedOrder: SignedOrder, fillAmount: BigNumber.BigNumber, senderAddress: string) {
+ private async validateFillOrder(signedOrder: SignedOrder, fillAmount: BigNumber.BigNumber, senderAddress: string) {
if (fillAmount.eq(0)) {
throw new Error(FillOrderValidationErrs.FILL_AMOUNT_IS_ZERO);
}
@@ -127,6 +130,15 @@ export class ExchangeWrapper extends ContractWrapper {
if (signedOrder.expirationUnixTimestampSec.lessThan(Date.now() / 1000)) {
throw new Error(FillOrderValidationErrs.EXPIRED);
}
+ const makerBalance = await this.tokenWrapper.getBalanceAsync(signedOrder.makerTokenAddress, signedOrder.maker);
+ const takerBalance = await this.tokenWrapper.getBalanceAsync(signedOrder.takerTokenAddress, senderAddress);
+ const makerAllowance = await this.tokenWrapper.getProxyAllowanceAsync(signedOrder.makerTokenAddress,
+ signedOrder.maker);
+ const takerAllowance = await this.tokenWrapper.getProxyAllowanceAsync(signedOrder.takerTokenAddress,
+ senderAddress);
+ if (fillAmount.greaterThan(takerBalance)) {
+ throw new Error(FillOrderValidationErrs.NOT_ENOUGH_TAKER_BALANCE);
+ }
}
private throwErrorLogsAsErrors(logs: ContractEvent[]): void {
const errEvent = _.find(logs, {event: 'LogError'});