aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-11-09 23:21:54 +0800
committerFabio Berger <me@fabioberger.com>2017-11-09 23:21:54 +0800
commit453f3405a7069bce2cefabdc26c5b1d5ca834981 (patch)
tree5394d61e483bb029fb111c87ab8dfd625a486678 /test
parenta8585df81bed4a1d4da8b0bb1f50e7f6e39c73ad (diff)
downloaddexon-sol-tools-453f3405a7069bce2cefabdc26c5b1d5ca834981.tar
dexon-sol-tools-453f3405a7069bce2cefabdc26c5b1d5ca834981.tar.gz
dexon-sol-tools-453f3405a7069bce2cefabdc26c5b1d5ca834981.tar.bz2
dexon-sol-tools-453f3405a7069bce2cefabdc26c5b1d5ca834981.tar.lz
dexon-sol-tools-453f3405a7069bce2cefabdc26c5b1d5ca834981.tar.xz
dexon-sol-tools-453f3405a7069bce2cefabdc26c5b1d5ca834981.tar.zst
dexon-sol-tools-453f3405a7069bce2cefabdc26c5b1d5ca834981.zip
Rename test file and add test for a partial fill
Diffstat (limited to 'test')
-rw-r--r--test/order_state_watcher_test.ts (renamed from test/order_watcher_test.ts)48
1 files changed, 46 insertions, 2 deletions
diff --git a/test/order_watcher_test.ts b/test/order_state_watcher_test.ts
index 11138567c..f1b027c40 100644
--- a/test/order_watcher_test.ts
+++ b/test/order_state_watcher_test.ts
@@ -25,7 +25,7 @@ import { DoneCallback } from '../src/types';
chaiSetup.configure();
const expect = chai.expect;
-describe.only('EventWatcher', () => {
+describe('OrderStateWatcher', () => {
let web3: Web3;
let zeroEx: ZeroEx;
let tokens: Token[];
@@ -56,6 +56,7 @@ describe.only('EventWatcher', () => {
});
afterEach(async () => {
zeroEx.orderStateWatcher.unsubscribe();
+ const orderHash = ZeroEx.getOrderHashHex(signedOrder);
zeroEx.orderStateWatcher.removeOrder(signedOrder);
});
it('should emit orderStateInvalid when maker allowance set to 0 for watched order', (done: DoneCallback) => {
@@ -103,12 +104,17 @@ describe.only('EventWatcher', () => {
);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
zeroEx.orderStateWatcher.addOrder(signedOrder);
+
+ let eventCount = 0;
const callback = (orderState: OrderState) => {
+ eventCount++;
expect(orderState.isValid).to.be.false();
const invalidOrderState = orderState as OrderStateInvalid;
expect(invalidOrderState.orderHash).to.be.equal(orderHash);
expect(invalidOrderState.error).to.be.equal(ExchangeContractErrs.OrderRemainingFillAmountZero);
- done();
+ if (eventCount === 2) {
+ done();
+ }
};
zeroEx.orderStateWatcher.subscribe(callback);
@@ -118,4 +124,42 @@ describe.only('EventWatcher', () => {
);
})().catch(done);
});
+ it('should emit orderStateValid when watched order partially filled', (done: DoneCallback) => {
+ (async () => {
+ signedOrder = await fillScenarios.createFillableSignedOrderAsync(
+ makerToken.address, takerToken.address, maker, taker, fillableAmount,
+ );
+
+ const makerBalance = await zeroEx.token.getBalanceAsync(makerToken.address, maker);
+ const takerBalance = await zeroEx.token.getBalanceAsync(makerToken.address, taker);
+
+ const fillAmountInBaseUnits = new BigNumber(2);
+ const orderHash = ZeroEx.getOrderHashHex(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
+
+ let eventCount = 0;
+ const callback = (orderState: OrderState) => {
+ eventCount++;
+ expect(orderState.isValid).to.be.true();
+ const validOrderState = orderState as OrderStateValid;
+ expect(validOrderState.orderHash).to.be.equal(orderHash);
+ const orderRelevantState = validOrderState.orderRelevantState;
+ const remainingMakerBalance = makerBalance.sub(fillAmountInBaseUnits);
+ expect(orderRelevantState.makerBalance).to.be.bignumber.equal(remainingMakerBalance);
+ if (eventCount === 2) {
+ done();
+ }
+ };
+ zeroEx.orderStateWatcher.subscribe(callback);
+ const shouldThrowOnInsufficientBalanceOrAllowance = true;
+ await zeroEx.exchange.fillOrderAsync(
+ signedOrder, fillAmountInBaseUnits, shouldThrowOnInsufficientBalanceOrAllowance, taker,
+ );
+ })().catch(done);
+ });
});
+
+/*
+ * - it should emit orderState when watched order partially filled
+ * - it should emit orderState when watched order is cancelled
+ */