Implement zeroEx.exchange.getOrderStateAsync
				
					
				
			This commit is contained in:
		@@ -4,6 +4,8 @@ Edit the package's CHANGELOG.json file only.
 | 
				
			|||||||
-->
 | 
					-->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CHANGELOG
 | 
					CHANGELOG
 | 
				
			||||||
 | 
					## v0.36.0 - TBD
 | 
				
			||||||
 | 
					    * Add `zeroEx.exchange.getOrderStateAsync` to allow obtaining current OrderState for a signedOrder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## v0.35.0 - _April 2, 2018_
 | 
					## v0.35.0 - _April 2, 2018_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,35 +13,38 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
 | 
				
			|||||||
import * as _ from 'lodash';
 | 
					import * as _ from 'lodash';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { artifacts } from '../artifacts';
 | 
					import { artifacts } from '../artifacts';
 | 
				
			||||||
 | 
					import { BalanceAndProxyAllowanceLazyStore } from '../stores/balance_proxy_allowance_lazy_store';
 | 
				
			||||||
 | 
					import { OrderFilledCancelledLazyStore } from '../stores/order_filled_cancelled_lazy_store';
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
    BlockRange,
 | 
					BlockRange,
 | 
				
			||||||
    EventCallback,
 | 
					EventCallback,
 | 
				
			||||||
    ExchangeContractErrCodes,
 | 
					ExchangeContractErrCodes,
 | 
				
			||||||
    ExchangeContractErrs,
 | 
					ExchangeContractErrs,
 | 
				
			||||||
    IndexedFilterValues,
 | 
					IndexedFilterValues,
 | 
				
			||||||
    MethodOpts,
 | 
					MethodOpts,
 | 
				
			||||||
    OrderAddresses,
 | 
					OrderAddresses,
 | 
				
			||||||
    OrderCancellationRequest,
 | 
					OrderCancellationRequest,
 | 
				
			||||||
    OrderFillRequest,
 | 
					OrderFillRequest,
 | 
				
			||||||
    OrderTransactionOpts,
 | 
					OrderState,
 | 
				
			||||||
    OrderValues,
 | 
					OrderTransactionOpts,
 | 
				
			||||||
    ValidateOrderFillableOpts,
 | 
					OrderValues,
 | 
				
			||||||
 | 
					ValidateOrderFillableOpts,
 | 
				
			||||||
} from '../types';
 | 
					} from '../types';
 | 
				
			||||||
import { assert } from '../utils/assert';
 | 
					import { assert } from '../utils/assert';
 | 
				
			||||||
import { decorators } from '../utils/decorators';
 | 
					import { decorators } from '../utils/decorators';
 | 
				
			||||||
import { ExchangeTransferSimulator } from '../utils/exchange_transfer_simulator';
 | 
					import { ExchangeTransferSimulator } from '../utils/exchange_transfer_simulator';
 | 
				
			||||||
 | 
					import { OrderStateUtils } from '../utils/order_state_utils';
 | 
				
			||||||
import { OrderValidationUtils } from '../utils/order_validation_utils';
 | 
					import { OrderValidationUtils } from '../utils/order_validation_utils';
 | 
				
			||||||
import { utils } from '../utils/utils';
 | 
					import { utils } from '../utils/utils';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { ContractWrapper } from './contract_wrapper';
 | 
					import { ContractWrapper } from './contract_wrapper';
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
    ExchangeContract,
 | 
					ExchangeContract,
 | 
				
			||||||
    ExchangeContractEventArgs,
 | 
					ExchangeContractEventArgs,
 | 
				
			||||||
    ExchangeEvents,
 | 
					ExchangeEvents,
 | 
				
			||||||
    LogErrorContractEventArgs,
 | 
					LogErrorContractEventArgs,
 | 
				
			||||||
} from './generated/exchange';
 | 
					} from './generated/exchange';
 | 
				
			||||||
import { TokenWrapper } from './token_wrapper';
 | 
					import { TokenWrapper } from './token_wrapper';
 | 
				
			||||||
 | 
					 | 
				
			||||||
const SHOULD_VALIDATE_BY_DEFAULT = true;
 | 
					const SHOULD_VALIDATE_BY_DEFAULT = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface ExchangeContractErrCodesToMsgs {
 | 
					interface ExchangeContractErrCodesToMsgs {
 | 
				
			||||||
@@ -873,6 +876,22 @@ export class ExchangeWrapper extends ContractWrapper {
 | 
				
			|||||||
            throw new Error(errMessage);
 | 
					            throw new Error(errMessage);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Gets the latest OrderState of a signedOrder
 | 
				
			||||||
 | 
					     * @param   signedOrder   The signedOrder
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public async getOrderStateAsync(signedOrder: SignedOrder): Promise<OrderState> {
 | 
				
			||||||
 | 
					        const balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
 | 
				
			||||||
 | 
					            this._tokenWrapper,
 | 
				
			||||||
 | 
					            BlockParamLiteral.Latest,
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        const orderFilledCancelledLazyStore = new OrderFilledCancelledLazyStore(this);
 | 
				
			||||||
 | 
					        const orderStateUtils = new OrderStateUtils(
 | 
				
			||||||
 | 
					            balanceAndProxyAllowanceLazyStore,
 | 
				
			||||||
 | 
					            orderFilledCancelledLazyStore,
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        return orderStateUtils.getOrderStateAsync(signedOrder);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Returns the ZRX token address used by the exchange contract.
 | 
					     * Returns the ZRX token address used by the exchange contract.
 | 
				
			||||||
     * @return Address of ZRX token
 | 
					     * @return Address of ZRX token
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,7 +14,7 @@ import {
 | 
				
			|||||||
    LogCancelContractEventArgs,
 | 
					    LogCancelContractEventArgs,
 | 
				
			||||||
    LogFillContractEventArgs,
 | 
					    LogFillContractEventArgs,
 | 
				
			||||||
    OrderCancellationRequest,
 | 
					    OrderCancellationRequest,
 | 
				
			||||||
    OrderFillRequest,
 | 
					    OrderFillRequest, OrderState, OrderStateInvalid,
 | 
				
			||||||
    SignedOrder,
 | 
					    SignedOrder,
 | 
				
			||||||
    Token,
 | 
					    Token,
 | 
				
			||||||
    ZeroEx,
 | 
					    ZeroEx,
 | 
				
			||||||
@@ -1156,4 +1156,41 @@ describe('ExchangeWrapper', () => {
 | 
				
			|||||||
            expect(args.maker).to.be.equal(differentMakerAddress);
 | 
					            expect(args.maker).to.be.equal(differentMakerAddress);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					    describe('#getOrderState', () => {
 | 
				
			||||||
 | 
					        let maker: string;
 | 
				
			||||||
 | 
					        let taker: string;
 | 
				
			||||||
 | 
					        let makerToken: Token;
 | 
				
			||||||
 | 
					        let takerToken: Token;
 | 
				
			||||||
 | 
					        let signedOrder: SignedOrder;
 | 
				
			||||||
 | 
					        let orderState: OrderState;
 | 
				
			||||||
 | 
					        const fillableAmount = ZeroEx.toBaseUnitAmount(new BigNumber(5), constants.ZRX_DECIMALS);
 | 
				
			||||||
 | 
					        before(async () => {
 | 
				
			||||||
 | 
					            [, maker, taker] = userAddresses;
 | 
				
			||||||
 | 
					            tokens = await zeroEx.tokenRegistry.getTokensAsync();
 | 
				
			||||||
 | 
					            [makerToken, takerToken] = tokenUtils.getDummyTokens();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        it('should report orderStateValid when order is fillable', async () => {
 | 
				
			||||||
 | 
					            signedOrder = await fillScenarios.createFillableSignedOrderAsync(
 | 
				
			||||||
 | 
					                makerToken.address,
 | 
				
			||||||
 | 
					                takerToken.address,
 | 
				
			||||||
 | 
					                maker,
 | 
				
			||||||
 | 
					                taker,
 | 
				
			||||||
 | 
					                fillableAmount,
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					            orderState = await zeroEx.exchange.getOrderStateAsync(signedOrder);
 | 
				
			||||||
 | 
					            expect(orderState.isValid).to.be.true();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        it('should report orderStateInvalid when maker allowance set to 0', async () => {
 | 
				
			||||||
 | 
					            signedOrder = await fillScenarios.createFillableSignedOrderAsync(
 | 
				
			||||||
 | 
					                makerToken.address,
 | 
				
			||||||
 | 
					                takerToken.address,
 | 
				
			||||||
 | 
					                maker,
 | 
				
			||||||
 | 
					                taker,
 | 
				
			||||||
 | 
					                fillableAmount,
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					            await zeroEx.token.setProxyAllowanceAsync(makerToken.address, maker, new BigNumber(0));
 | 
				
			||||||
 | 
					            orderState = await zeroEx.exchange.getOrderStateAsync(signedOrder);
 | 
				
			||||||
 | 
					            expect(orderState.isValid).to.be.false();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
}); // tslint:disable:max-file-line-count
 | 
					}); // tslint:disable:max-file-line-count
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user