aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/0x.js_test.ts6
-rw-r--r--test/exchange_wrapper_test.ts32
-rw-r--r--test/utils/fill_scenarios.ts60
3 files changed, 49 insertions, 49 deletions
diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts
index 0d8d63985..f25f104bd 100644
--- a/test/0x.js_test.ts
+++ b/test/0x.js_test.ts
@@ -163,7 +163,7 @@ describe('ZeroEx library', () => {
_.each(stubs, s => s.restore());
stubs = [];
});
- it ('Should return the correct ECSignature on TestPRC nodeVersion', async () => {
+ it('Should return the correct ECSignature on TestPRC nodeVersion', async () => {
const orderHash = '0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b0';
const expectedECSignature = {
v: 27,
@@ -173,7 +173,7 @@ describe('ZeroEx library', () => {
const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAddress);
expect(ecSignature).to.deep.equal(expectedECSignature);
});
- it ('should return the correct ECSignature on Parity > V1.6.6', async () => {
+ it('should return the correct ECSignature on Parity > V1.6.6', async () => {
const newParityNodeVersion = 'Parity//v1.6.7-beta-e128418-20170518/x86_64-macos/rustc1.17.0';
const orderHash = '0x34decbedc118904df65f379a175bb39ca18209d6ce41d5ed549d54e6e0a95004';
// tslint:disable-next-line: max-line-length
@@ -194,7 +194,7 @@ describe('ZeroEx library', () => {
const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAddress);
expect(ecSignature).to.deep.equal(expectedECSignature);
});
- it ('should return the correct ECSignature on Parity < V1.6.6', async () => {
+ it('should return the correct ECSignature on Parity < V1.6.6', async () => {
const newParityNodeVersion = 'Parity//v1.6.6-beta-8c6e3f3-20170411/x86_64-macos/rustc1.16.0';
const orderHash = '0xc793e33ffded933b76f2f48d9aa3339fc090399d5e7f5dec8d3660f5480793f7';
// tslint:disable-next-line: max-line-length
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index 45da44f54..53032efd6 100644
--- a/test/exchange_wrapper_test.ts
+++ b/test/exchange_wrapper_test.ts
@@ -386,7 +386,7 @@ describe('ExchangeWrapper', () => {
});
});
});
- describe('#batchFillOrderAsync', () => {
+ describe('#batchFillOrdersAsync', () => {
let signedOrder: SignedOrder;
let signedOrderHashHex: string;
let anotherSignedOrder: SignedOrder;
@@ -414,10 +414,10 @@ describe('ExchangeWrapper', () => {
});
describe('successful batch fills', () => {
it('should no-op for an empty batch', async () => {
- await zeroEx.exchange.batchFillOrderAsync([], shouldCheckTransfer, takerAddress);
+ await zeroEx.exchange.batchFillOrdersAsync([], shouldCheckTransfer, takerAddress);
});
it('should successfully fill multiple orders', async () => {
- await zeroEx.exchange.batchFillOrderAsync(orderFillBatch, shouldCheckTransfer, takerAddress);
+ await zeroEx.exchange.batchFillOrdersAsync(orderFillBatch, shouldCheckTransfer, takerAddress);
const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(
signedOrderHashHex, exchangeContractAddress,
);
@@ -531,7 +531,7 @@ describe('ExchangeWrapper', () => {
});
});
});
- describe('#batchCancelOrderAsync', () => {
+ describe('#batchCancelOrdersAsync', () => {
let anotherSignedOrder: SignedOrder;
let anotherOrderHashHex: string;
let cancelBatch: OrderCancellationRequest[];
@@ -556,7 +556,7 @@ describe('ExchangeWrapper', () => {
const signedOrderWithDifferentMaker = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, takerAddress, takerAddress, fillableAmount,
);
- return expect(zeroEx.exchange.batchCancelOrderAsync([
+ return expect(zeroEx.exchange.batchCancelOrdersAsync([
cancelBatch[0],
{
order: signedOrderWithDifferentMaker,
@@ -567,7 +567,7 @@ describe('ExchangeWrapper', () => {
});
describe('successful batch cancels', () => {
it('should cancel a batch of orders', async () => {
- await zeroEx.exchange.batchCancelOrderAsync(cancelBatch);
+ await zeroEx.exchange.batchCancelOrdersAsync(cancelBatch);
const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(
orderHashHex, exchangeContractAddress,
);
@@ -603,19 +603,19 @@ describe('ExchangeWrapper', () => {
orderHash = zeroEx.getOrderHashHex(signedOrder);
});
describe('#getUnavailableTakerAmountAsync', () => {
- it ('should throw if passed an invalid orderHash', async () => {
+ it('should throw if passed an invalid orderHash', async () => {
const invalidOrderHashHex = '0x123';
return expect(zeroEx.exchange.getUnavailableTakerAmountAsync(
invalidOrderHashHex, exchangeContractAddress,
)).to.be.rejected();
});
- it ('should return zero if passed a valid but non-existent orderHash', async () => {
+ it('should return zero if passed a valid but non-existent orderHash', async () => {
const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync(
NON_EXISTENT_ORDER_HASH, exchangeContractAddress,
);
expect(unavailableValueT).to.be.bignumber.equal(0);
});
- it ('should return the unavailableValueT for a valid and partially filled orderHash', async () => {
+ it('should return the unavailableValueT for a valid and partially filled orderHash', async () => {
const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync(
orderHash, exchangeContractAddress,
);
@@ -623,19 +623,19 @@ describe('ExchangeWrapper', () => {
});
});
describe('#getFilledTakerAmountAsync', () => {
- it ('should throw if passed an invalid orderHash', async () => {
+ it('should throw if passed an invalid orderHash', async () => {
const invalidOrderHashHex = '0x123';
return expect(zeroEx.exchange.getFilledTakerAmountAsync(
invalidOrderHashHex, exchangeContractAddress,
)).to.be.rejected();
});
- it ('should return zero if passed a valid but non-existent orderHash', async () => {
+ it('should return zero if passed a valid but non-existent orderHash', async () => {
const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync(
NON_EXISTENT_ORDER_HASH, exchangeContractAddress,
);
expect(filledValueT).to.be.bignumber.equal(0);
});
- it ('should return the filledValueT for a valid and partially filled orderHash', async () => {
+ it('should return the filledValueT for a valid and partially filled orderHash', async () => {
const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync(
orderHash, exchangeContractAddress,
);
@@ -643,25 +643,25 @@ describe('ExchangeWrapper', () => {
});
});
describe('#getCanceledTakerAmountAsync', () => {
- it ('should throw if passed an invalid orderHash', async () => {
+ it('should throw if passed an invalid orderHash', async () => {
const invalidOrderHashHex = '0x123';
return expect(zeroEx.exchange.getCanceledTakerAmountAsync(
invalidOrderHashHex, exchangeContractAddress,
)).to.be.rejected();
});
- it ('should return zero if passed a valid but non-existent orderHash', async () => {
+ it('should return zero if passed a valid but non-existent orderHash', async () => {
const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(
NON_EXISTENT_ORDER_HASH, exchangeContractAddress,
);
expect(cancelledValueT).to.be.bignumber.equal(0);
});
- it ('should return the cancelledValueT for a valid and partially filled orderHash', async () => {
+ it('should return the cancelledValueT for a valid and partially filled orderHash', async () => {
const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(
orderHash, exchangeContractAddress,
);
expect(cancelledValueT).to.be.bignumber.equal(0);
});
- it ('should return the cancelledValueT for a valid and cancelled orderHash', async () => {
+ it('should return the cancelledValueT for a valid and cancelled orderHash', async () => {
const cancelAmount = fillableAmount.minus(partialFillAmount);
await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount);
const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(
diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts
index 65a912955..bebf82fd8 100644
--- a/test/utils/fill_scenarios.ts
+++ b/test/utils/fill_scenarios.ts
@@ -71,37 +71,15 @@ export class FillScenarios {
makerAddress: string, takerAddress: string,
makerFillableAmount: BigNumber.BigNumber, takerFillableAmount: BigNumber.BigNumber,
feeRecepient: string, expirationUnixTimestampSec?: BigNumber.BigNumber): Promise<SignedOrder> {
- await this.zeroEx.token.transferAsync(makerTokenAddress, this.coinbase, makerAddress, makerFillableAmount);
- const oldMakerAllowance = await this.zeroEx.token.getProxyAllowanceAsync(makerTokenAddress, makerAddress);
- const newMakerAllowance = oldMakerAllowance.plus(makerFillableAmount);
- await this.zeroEx.token.setProxyAllowanceAsync(
- makerTokenAddress, makerAddress, newMakerAllowance,
- );
- await this.zeroEx.token.transferAsync(takerTokenAddress, this.coinbase, takerAddress, takerFillableAmount);
- const oldTakerAllowance = await this.zeroEx.token.getProxyAllowanceAsync(takerTokenAddress, takerAddress);
- const newTakerAllowance = oldTakerAllowance.plus(takerFillableAmount);
- await this.zeroEx.token.setProxyAllowanceAsync(
- takerTokenAddress, takerAddress, newTakerAllowance,
- );
- if (!makerFee.isZero()) {
- await this.zeroEx.token.transferAsync(this.zrxTokenAddress, this.coinbase, makerAddress, makerFee);
- const oldMakerFeeAllowance =
- await this.zeroEx.token.getProxyAllowanceAsync(this.zrxTokenAddress, makerAddress);
- const newMakerFeeAllowance = oldMakerFeeAllowance.plus(makerFee);
- await this.zeroEx.token.setProxyAllowanceAsync(
- this.zrxTokenAddress, makerAddress, newMakerFeeAllowance,
- );
- }
- if (!takerFee.isZero()) {
- await this.zeroEx.token.transferAsync(this.zrxTokenAddress, this.coinbase, takerAddress, takerFee);
- const oldTakerFeeAllowance =
- await this.zeroEx.token.getProxyAllowanceAsync(this.zrxTokenAddress, takerAddress);
- const newTakerFeeAllowance = oldTakerFeeAllowance.plus(takerFee);
- await this.zeroEx.token.setProxyAllowanceAsync(
- this.zrxTokenAddress, takerAddress, newTakerFeeAllowance,
- );
- }
+ await Promise.all([
+ this.increaseBalanceAndAllowanceAsync(makerTokenAddress, makerAddress, makerFillableAmount),
+ this.increaseBalanceAndAllowanceAsync(takerTokenAddress, takerAddress, takerFillableAmount),
+ ]);
+ await Promise.all([
+ this.increaseBalanceAndAllowanceAsync(this.zrxTokenAddress, makerAddress, makerFee),
+ this.increaseBalanceAndAllowanceAsync(this.zrxTokenAddress, takerAddress, takerFee),
+ ]);
const signedOrder = await orderFactory.createSignedOrderAsync(this.zeroEx,
makerAddress, takerAddress, makerFee, takerFee,
@@ -109,4 +87,26 @@ export class FillScenarios {
this.exchangeContractAddress, feeRecepient, expirationUnixTimestampSec);
return signedOrder;
}
+ private async increaseBalanceAndAllowanceAsync(
+ tokenAddress: string, address: string, amount: BigNumber.BigNumber): Promise<void> {
+ if (amount.isZero()) {
+ return; // noop
+ }
+ await Promise.all([
+ this.increaseBalanceAsync(tokenAddress, address, amount),
+ this.increaseAllowanceAsync(tokenAddress, address, amount),
+ ]);
+ }
+ private async increaseBalanceAsync(
+ tokenAddress: string, address: string, amount: BigNumber.BigNumber): Promise<void> {
+ await this.zeroEx.token.transferAsync(tokenAddress, this.coinbase, address, amount);
+ }
+ private async increaseAllowanceAsync(
+ tokenAddress: string, address: string, amount: BigNumber.BigNumber): Promise<void> {
+ const oldMakerAllowance = await this.zeroEx.token.getProxyAllowanceAsync(tokenAddress, address);
+ const newMakerAllowance = oldMakerAllowance.plus(amount);
+ await this.zeroEx.token.setProxyAllowanceAsync(
+ tokenAddress, address, newMakerAllowance,
+ );
+ }
}