aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts')
-rw-r--r--packages/contracts/src/utils/exchange_wrapper.ts21
-rw-r--r--packages/contracts/test/exchange/wrapper.ts54
2 files changed, 69 insertions, 6 deletions
diff --git a/packages/contracts/src/utils/exchange_wrapper.ts b/packages/contracts/src/utils/exchange_wrapper.ts
index 04e6c2feb..9dd414be2 100644
--- a/packages/contracts/src/utils/exchange_wrapper.ts
+++ b/packages/contracts/src/utils/exchange_wrapper.ts
@@ -81,6 +81,27 @@ export class ExchangeWrapper {
});
return tx;
}
+ public async fillOrderNoThrowAsync(
+ signedOrder: SignedOrder,
+ from: string,
+ opts: { takerTokenFillAmount?: BigNumber } = {},
+ ): Promise<TransactionReceiptWithDecodedLogs> {
+ const params = orderUtils.createFill(signedOrder, opts.takerTokenFillAmount);
+ const txHash = await this._exchange.fillOrderNoThrow.sendTransactionAsync(
+ params.order,
+ params.takerTokenFillAmount,
+ params.signature,
+ { from },
+ );
+ const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
+ tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
+ tx.logs = _.map(tx.logs, log => {
+ const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log);
+ wrapLogBigNumbers(logWithDecodedArgs);
+ return logWithDecodedArgs;
+ });
+ return tx;
+ }
public async batchFillOrdersAsync(
orders: SignedOrder[],
from: string,
diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts
index 182578f42..e5933a7e7 100644
--- a/packages/contracts/test/exchange/wrapper.ts
+++ b/packages/contracts/test/exchange/wrapper.ts
@@ -111,15 +111,12 @@ describe('Exchange', () => {
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
+ balances = await dmyBalances.getAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('fillOrKillOrder', () => {
- beforeEach(async () => {
- balances = await dmyBalances.getAsync();
- });
-
it('should transfer the correct amounts', async () => {
const signedOrder = orderFactory.newSignedOrder({
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
@@ -187,6 +184,52 @@ describe('Exchange', () => {
});
});
+ describe('fillOrderNoThrow', () => {
+ it('should transfer the correct amounts', async () => {
+ const signedOrder = orderFactory.newSignedOrder({
+ makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
+ takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
+ });
+ const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2);
+ await exWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress, {
+ takerTokenFillAmount,
+ });
+
+ const newBalances = await dmyBalances.getAsync();
+
+ const makerTokenFillAmount = takerTokenFillAmount
+ .times(signedOrder.makerTokenAmount)
+ .dividedToIntegerBy(signedOrder.takerTokenAmount);
+ const makerFeeAmount = signedOrder.makerFeeAmount
+ .times(makerTokenFillAmount)
+ .dividedToIntegerBy(signedOrder.makerTokenAmount);
+ const takerFeeAmount = signedOrder.takerFeeAmount
+ .times(makerTokenFillAmount)
+ .dividedToIntegerBy(signedOrder.makerTokenAmount);
+ expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
+ );
+ expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
+ );
+ expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[makerAddress][zrx.address].minus(makerFeeAmount),
+ );
+ expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
+ );
+ expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
+ );
+ expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[takerAddress][zrx.address].minus(takerFeeAmount),
+ );
+ expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipientAddress][zrx.address].add(makerFeeAmount.add(takerFeeAmount)),
+ );
+ });
+ });
+
describe('batch functions', () => {
let signedOrders: SignedOrder[];
beforeEach(async () => {
@@ -195,7 +238,6 @@ describe('Exchange', () => {
orderFactory.newSignedOrder(),
orderFactory.newSignedOrder(),
];
- balances = await dmyBalances.getAsync();
});
describe('batchFillOrders', () => {
@@ -304,7 +346,7 @@ describe('Exchange', () => {
});
});
- describe('fillOrdersUpTo', () => {
+ describe('marketFillOrders', () => {
it('should stop when the entire takerTokenFillAmount is filled', async () => {
const takerTokenFillAmount = signedOrders[0].takerTokenAmount.plus(
signedOrders[1].takerTokenAmount.div(2),