aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-07-18 08:40:19 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-07-26 04:25:56 +0800
commitdefd09459dd774791b5bb88e2ec3a5216e8b6b4a (patch)
tree28b26c6f89f8e5b0d284b93423ad9c032697d9d8 /src/utils
parent58d2b799d6adb8d8af7565af4b63e3a3c5748c10 (diff)
downloaddexon-sol-tools-defd09459dd774791b5bb88e2ec3a5216e8b6b4a.tar
dexon-sol-tools-defd09459dd774791b5bb88e2ec3a5216e8b6b4a.tar.gz
dexon-sol-tools-defd09459dd774791b5bb88e2ec3a5216e8b6b4a.tar.bz2
dexon-sol-tools-defd09459dd774791b5bb88e2ec3a5216e8b6b4a.tar.lz
dexon-sol-tools-defd09459dd774791b5bb88e2ec3a5216e8b6b4a.tar.xz
dexon-sol-tools-defd09459dd774791b5bb88e2ec3a5216e8b6b4a.tar.zst
dexon-sol-tools-defd09459dd774791b5bb88e2ec3a5216e8b6b4a.zip
Cover all possible branches of order validation errors with tests
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/order_validation_utils.ts19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/utils/order_validation_utils.ts b/src/utils/order_validation_utils.ts
index 2d7acd905..4452a7aef 100644
--- a/src/utils/order_validation_utils.ts
+++ b/src/utils/order_validation_utils.ts
@@ -16,14 +16,9 @@ export class OrderValidationUtils {
tokenWrapper: TokenWrapper, signedOrder: SignedOrder, fillTakerAmount: BigNumber.BigNumber,
zrxTokenAddress: string,
): Promise<void> {
- const makerBalance = await tokenWrapper.getBalanceAsync(
- signedOrder.makerTokenAddress, signedOrder.maker);
+ const makerBalance = await tokenWrapper.getBalanceAsync(signedOrder.makerTokenAddress, signedOrder.maker);
const makerAllowance = await tokenWrapper.getProxyAllowanceAsync(
signedOrder.makerTokenAddress, signedOrder.maker);
- const makerZRXBalance = await tokenWrapper.getBalanceAsync(
- zrxTokenAddress, signedOrder.maker);
- const makerZRXAllowance = await tokenWrapper.getProxyAllowanceAsync(
- zrxTokenAddress, signedOrder.maker);
const isMakerTokenZRX = signedOrder.makerTokenAddress === zrxTokenAddress;
// exchangeRate is the price of one maker token denominated in taker tokens
@@ -39,6 +34,9 @@ export class OrderValidationUtils {
throw new Error(ExchangeContractErrs.InsufficientMakerAllowance);
}
} else {
+ const makerZRXBalance = await tokenWrapper.getBalanceAsync(zrxTokenAddress, signedOrder.maker);
+ const makerZRXAllowance = await tokenWrapper.getProxyAllowanceAsync(zrxTokenAddress, signedOrder.maker);
+
if (fillMakerAmount.greaterThan(makerBalance)) {
throw new Error(ExchangeContractErrs.InsufficientMakerBalance);
}
@@ -58,11 +56,7 @@ export class OrderValidationUtils {
senderAddress: string, zrxTokenAddress: string,
): Promise<void> {
const takerBalance = await tokenWrapper.getBalanceAsync(signedOrder.takerTokenAddress, senderAddress);
- const takerAllowance = await tokenWrapper.getProxyAllowanceAsync(
- signedOrder.takerTokenAddress, senderAddress);
- const takerZRXBalance = await tokenWrapper.getBalanceAsync(zrxTokenAddress, senderAddress);
- const takerZRXAllowance = await tokenWrapper.getProxyAllowanceAsync(
- zrxTokenAddress, senderAddress);
+ const takerAllowance = await tokenWrapper.getProxyAllowanceAsync(signedOrder.takerTokenAddress, senderAddress);
const isTakerTokenZRX = signedOrder.takerTokenAddress === zrxTokenAddress;
@@ -75,6 +69,9 @@ export class OrderValidationUtils {
throw new Error(ExchangeContractErrs.InsufficientTakerAllowance);
}
} else {
+ const takerZRXBalance = await tokenWrapper.getBalanceAsync(zrxTokenAddress, senderAddress);
+ const takerZRXAllowance = await tokenWrapper.getProxyAllowanceAsync(zrxTokenAddress, senderAddress);
+
if (fillTakerAmount.greaterThan(takerBalance)) {
throw new Error(ExchangeContractErrs.InsufficientTakerBalance);
}