aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-06-03 00:34:24 +0800
committerFabio Berger <me@fabioberger.com>2017-06-03 00:34:24 +0800
commit0c98f4c754a6a3aceeaf93f40ee431850a28c7e9 (patch)
tree53f569617f061273b70460c1a57279716d412b73 /test
parent3551f0791408a5c91f357130740cb81f72b59f9f (diff)
parentcc6b27cbb179de3e5ac124bfddac63f66e16737a (diff)
downloaddexon-sol-tools-0c98f4c754a6a3aceeaf93f40ee431850a28c7e9.tar
dexon-sol-tools-0c98f4c754a6a3aceeaf93f40ee431850a28c7e9.tar.gz
dexon-sol-tools-0c98f4c754a6a3aceeaf93f40ee431850a28c7e9.tar.bz2
dexon-sol-tools-0c98f4c754a6a3aceeaf93f40ee431850a28c7e9.tar.lz
dexon-sol-tools-0c98f4c754a6a3aceeaf93f40ee431850a28c7e9.tar.xz
dexon-sol-tools-0c98f4c754a6a3aceeaf93f40ee431850a28c7e9.tar.zst
dexon-sol-tools-0c98f4c754a6a3aceeaf93f40ee431850a28c7e9.zip
Merge branch 'fillOrderAsync' of github.com:0xProject/0x.js into fillOrderAsync
Diffstat (limited to 'test')
-rw-r--r--test/exchange_wrapper_test.ts58
-rw-r--r--test/utils/fill_scenarios.ts10
-rw-r--r--test/utils/token_utils.ts2
3 files changed, 34 insertions, 36 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index 92b6e5c35..7b4730f3a 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';
@@ -115,7 +115,7 @@ describe('ExchangeWrapper', () => {
let zrxTokenAddress: string;
const fillTakerAmount = new BigNumber(5);
const shouldCheckTransfer = false;
- before('fetch tokens', async () => {
+ before(async () => {
[coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses;
tokens = await zeroEx.tokenRegistry.getTokensAsync();
const tokenUtils = new TokenUtils(tokens);
@@ -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.NOT_A_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,11 +158,11 @@ describe('ExchangeWrapper', () => {
zeroEx.setTransactionSenderAccount(takerAddress);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer,
- )).to.be.rejectedWith(FillOrderValidationErrs.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);
- const lackingBalance = new BigNumber(3);
+ const balanceToSubtractFromMaker = new BigNumber(3);
const lackingAllowance = new BigNumber(3);
let signedOrder: SignedOrder;
beforeEach('create fillable signed order', async () => {
@@ -171,12 +171,11 @@ describe('ExchangeWrapper', () => {
);
});
it('should throw when taker balance is less than fill amount', async () => {
-
- await zeroEx.token.transferAsync(takerTokenAddress, takerAddress, coinbase, lackingBalance);
+ await zeroEx.token.transferAsync(takerTokenAddress, takerAddress, coinbase, balanceToSubtractFromMaker);
zeroEx.setTransactionSenderAccount(takerAddress);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer,
- )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_BALANCE);
+ )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_BALANCE);
});
it('should throw when taker allowance is less than fill amount', async () => {
const newAllowanceWhichIsLessThanFillAmount = fillTakerAmount.minus(lackingAllowance);
@@ -185,14 +184,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.INSUFFICIENT_TAKER_ALLOWANCE);
});
it('should throw when maker balance is less than maker fill amount', async () => {
- await zeroEx.token.transferAsync(makerTokenAddress, makerAddress, coinbase, lackingBalance);
+ await zeroEx.token.transferAsync(makerTokenAddress, makerAddress, coinbase, balanceToSubtractFromMaker);
zeroEx.setTransactionSenderAccount(takerAddress);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer,
- )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_MAKER_BALANCE);
+ )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_BALANCE);
});
it('should throw when maker allowance is less than maker fill amount', async () => {
const newAllowanceWhichIsLessThanFillAmount = fillTakerAmount.minus(lackingAllowance);
@@ -201,23 +200,23 @@ 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.INSUFFICIENT_MAKER_ALLOWANCE);
});
});
- it('should throw when there would be a rounding error', async () => {
- const makerFillableAmount = new BigNumber(3);
- const takerFillableAmount = new BigNumber(5);
- const signedOrder = await fillScenarios.createAsymetricFillableSignedOrderAsync(
+ it('should throw when there a rounding error would have occurred', async () => {
+ const makerAmount = new BigNumber(3);
+ const takerAmount = new BigNumber(5);
+ const signedOrder = await fillScenarios.createAsymmetricFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress,
- makerFillableAmount, takerFillableAmount,
+ makerAmount, takerAmount,
);
const fillTakerAmountThatCausesRoundingError = new BigNumber(3);
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', () => {
+ describe('should throw when not enough balance or allowance to pay fees', () => {
const fillableAmount = new BigNumber(5);
const makerFee = new BigNumber(2);
const takerFee = new BigNumber(2);
@@ -230,11 +229,11 @@ describe('ExchangeWrapper', () => {
zeroEx.setTransactionSenderAccount(takerAddress);
});
it('should throw when maker doesn\'t have enough balance to pay fees', async () => {
- const lackingBalance = new BigNumber(1);
- await zeroEx.token.transferAsync(zrxTokenAddress, makerAddress, coinbase, lackingBalance);
+ const balanceToSubtractFromMaker = new BigNumber(1);
+ await zeroEx.token.transferAsync(zrxTokenAddress, makerAddress, coinbase, balanceToSubtractFromMaker);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer,
- )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_MAKER_FEE_BALANCE);
+ )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_FEE_BALANCE);
});
it('should throw when maker doesn\'t have enough allowance to pay fees', async () => {
const newAllowanceWhichIsLessThanFees = makerFee.minus(1);
@@ -242,14 +241,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.INSUFFICIENT_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);
+ const balanceToSubtractFromTaker = new BigNumber(1);
+ await zeroEx.token.transferAsync(zrxTokenAddress, takerAddress, coinbase, balanceToSubtractFromTaker);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer,
- )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_FEE_BALANCE);
+ )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_FEE_BALANCE);
});
it('should throw when taker doesn\'t have enough allowance to pay fees', async () => {
const newAllowanceWhichIsLessThanFees = makerFee.minus(1);
@@ -257,17 +256,16 @@ describe('ExchangeWrapper', () => {
newAllowanceWhichIsLessThanFees);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer,
- )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_FEE_ALLOWANCE);
+ )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_FEE_ALLOWANCE);
});
});
});
describe('successful fills', () => {
- it('should fill the valid order', async () => {
+ it('should fill a valid order', async () => {
const fillableAmount = new BigNumber(5);
const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
-
expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress))
.to.be.bignumber.equal(fillableAmount);
expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress))
diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts
index 8260b76ab..f95b06663 100644
--- a/test/utils/fill_scenarios.ts
+++ b/test/utils/fill_scenarios.ts
@@ -22,7 +22,7 @@ export class FillScenarios {
fillableAmount: BigNumber.BigNumber,
expirationUnixTimestampSec?: BigNumber.BigNumber):
Promise<SignedOrder> {
- return this.createAsymetricFillableSignedOrderAsync(
+ return this.createAsymmetricFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress,
fillableAmount, fillableAmount, expirationUnixTimestampSec,
);
@@ -34,24 +34,24 @@ export class FillScenarios {
fillableAmount: BigNumber.BigNumber,
feeRecepient: string, expirationUnixTimestampSec?: BigNumber.BigNumber,
): Promise<SignedOrder> {
- return this.createAsymetricFillableSignedOrderWithFeesAsync(
+ return this.createAsymmetricFillableSignedOrderWithFeesAsync(
makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress,
fillableAmount, fillableAmount, feeRecepient, expirationUnixTimestampSec,
);
}
- public async createAsymetricFillableSignedOrderAsync(
+ public async createAsymmetricFillableSignedOrderAsync(
makerTokenAddress: string, takerTokenAddress: string, makerAddress: string, takerAddress: string,
makerFillableAmount: BigNumber.BigNumber, takerFillableAmount: BigNumber.BigNumber,
expirationUnixTimestampSec?: BigNumber.BigNumber): Promise<SignedOrder> {
const makerFee = new BigNumber(0);
const takerFee = new BigNumber(0);
const feeRecepient = constants.NULL_ADDRESS;
- return this.createAsymetricFillableSignedOrderWithFeesAsync(
+ return this.createAsymmetricFillableSignedOrderWithFeesAsync(
makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress,
makerFillableAmount, takerFillableAmount, feeRecepient, expirationUnixTimestampSec,
);
}
- private async createAsymetricFillableSignedOrderWithFeesAsync(
+ private async createAsymmetricFillableSignedOrderWithFeesAsync(
makerTokenAddress: string, takerTokenAddress: string,
makerFee: BigNumber.BigNumber, takerFee: BigNumber.BigNumber,
makerAddress: string, takerAddress: string,
diff --git a/test/utils/token_utils.ts b/test/utils/token_utils.ts
index 11d334619..3d2faa959 100644
--- a/test/utils/token_utils.ts
+++ b/test/utils/token_utils.ts
@@ -11,7 +11,7 @@ export class TokenUtils {
public getProtocolTokenOrThrow(): Token {
const zrxToken = _.find(this.tokens, {symbol: PROTOCOL_TOKEN_SYMBOL});
if (_.isUndefined(zrxToken)) {
- throw new Error(ZeroExError.CONTRACT_NOT_DEPLOYED_ON_NETWORK);
+ throw new Error(ZeroExError.ZRX_NOT_IN_TOKEN_REGISTRY);
}
return zrxToken;
}