How to use the @0x/assert.assert.doesConformToSchema function in @0x/assert

To help you get started, we’ve selected a few @0x/assert examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / packages / connect / src / utils / orders_channel_message_parser.ts View on Github external
parse(utf8Data: string): OrdersChannelMessage {
        // parse the message
        const messageObj = JSON.parse(utf8Data);
        // ensure we have a type parameter to switch on
        const type: string = _.get(messageObj, 'type');
        assert.assert(type !== undefined, `Message is missing a type parameter: ${utf8Data}`);
        assert.isString('type', type);
        // ensure we have a request id for the resulting message
        const requestId: string = _.get(messageObj, 'requestId');
        assert.assert(requestId !== undefined, `Message is missing a requestId parameter: ${utf8Data}`);
        assert.isString('requestId', requestId);
        switch (type) {
            case OrdersChannelMessageTypes.Update: {
                assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrdersChannelUpdateSchema);
                const ordersJson = messageObj.payload;
                const orders = relayerResponseJsonParsers.parseAPIOrdersJson(ordersJson);
                return _.assign(messageObj, { payload: orders });
            }
            default: {
                return {
                    type: OrdersChannelMessageTypes.Unknown,
                    requestId,
                    payload: undefined,
                };
            }
        }
    },
};
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / generated-wrappers / forwarder.ts View on Github external
public async getLogsAsync(
        eventName: ForwarderEvents,
        blockRange: BlockRange,
        indexFilterValues: IndexedFilterValues,
    ): Promise>> {
        assert.doesBelongToStringEnum('eventName', eventName, ForwarderEvents);
        assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
        assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
        const logs = await this._subscriptionManager.getLogsAsync(
            this.address,
            eventName,
            blockRange,
            indexFilterValues,
            ForwarderContract.ABI(),
        );
        return logs;
    }
    constructor(
github 0xProject / 0x-monorepo / packages / abi-gen-wrappers / src / generated-wrappers / zrx_token.ts View on Github external
public subscribe(
        eventName: ZRXTokenEvents,
        indexFilterValues: IndexedFilterValues,
        callback: EventCallback,
        isVerbose: boolean = false,
        blockPollingIntervalMs?: number,
    ): string {
        assert.doesBelongToStringEnum('eventName', eventName, ZRXTokenEvents);
        assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
        assert.isFunction('callback', callback);
        const subscriptionToken = this._subscriptionManager.subscribe(
            this.address,
            eventName,
            indexFilterValues,
            ZRXTokenContract.ABI(),
            callback,
            isVerbose,
            blockPollingIntervalMs,
        );
        return subscriptionToken;
    }
    /**
github 0xProject / 0x-monorepo / packages / order-utils / src / eip712_utils.ts View on Github external
assert.isString('primaryType', primaryType);
        const typedData = {
            types: {
                EIP712Domain: constants.DEFAULT_DOMAIN_SCHEMA.parameters,
                ...types,
            },
            domain: {
                name: domain.name === undefined ? constants.EXCHANGE_DOMAIN_NAME : domain.name,
                version: domain.version === undefined ? constants.EXCHANGE_DOMAIN_VERSION : domain.version,
                chainId: domain.chainId,
                verifyingContract: domain.verifyingContract,
            },
            message,
            primaryType,
        };
        assert.doesConformToSchema('typedData', typedData, schemas.eip712TypedDataSchema);
        return typedData;
    },
    /**
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / generated-wrappers / erc20_token.ts View on Github external
public async getLogsAsync(
        eventName: ERC20TokenEvents,
        blockRange: BlockRange,
        indexFilterValues: IndexedFilterValues,
    ): Promise>> {
        assert.doesBelongToStringEnum('eventName', eventName, ERC20TokenEvents);
        assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
        assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
        const logs = await this._subscriptionManager.getLogsAsync(
            this.address,
            eventName,
            blockRange,
            indexFilterValues,
            ERC20TokenContract.ABI(),
        );
        return logs;
    }
    constructor(
github 0xProject / 0x-monorepo / packages / asset-buyer / src / utils / assert.ts View on Github external
isValidSwapQuote(variableName: string, swapQuote: SwapQuote): void {
        sharedAssert.isHexString(`${variableName}.takerAssetData`, swapQuote.takerAssetData);
        sharedAssert.isHexString(`${variableName}.makerAssetData`, swapQuote.makerAssetData);
        sharedAssert.doesConformToSchema(`${variableName}.orders`, swapQuote.orders, schemas.signedOrdersSchema);
        sharedAssert.doesConformToSchema(`${variableName}.feeOrders`, swapQuote.feeOrders, schemas.signedOrdersSchema);
        assert.isValidSwapQuoteInfo(`${variableName}.bestCaseQuoteInfo`, swapQuote.bestCaseQuoteInfo);
        assert.isValidSwapQuoteInfo(`${variableName}.worstCaseQuoteInfo`, swapQuote.worstCaseQuoteInfo);
        if (utils.isSwapQuoteMarketBuy(swapQuote)) {
            sharedAssert.isBigNumber(`${variableName}.makerAssetFillAmount`, swapQuote.makerAssetFillAmount);
        } else if (utils.isSwapQuoteMarketSell(swapQuote)) {
            sharedAssert.isBigNumber(`${variableName}.takerAssetFillAmount`, swapQuote.takerAssetFillAmount);
        } else {
            throw new Error(SwapQuoteConsumerError.InvalidMarketSellOrMarketBuySwapQuote);
        }
    },
    isValidForwarderSwapQuote(variableName: string, swapQuote: SwapQuote, wethAssetData: string): void {
github 0xProject / 0x-monorepo / packages / abi-gen-wrappers / src / generated-wrappers / erc1155_mintable.ts View on Github external
public async getLogsAsync(
        eventName: ERC1155MintableEvents,
        blockRange: BlockRange,
        indexFilterValues: IndexedFilterValues,
    ): Promise>> {
        assert.doesBelongToStringEnum('eventName', eventName, ERC1155MintableEvents);
        assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
        assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
        const logs = await this._subscriptionManager.getLogsAsync(
            this.address,
            eventName,
            blockRange,
            indexFilterValues,
            ERC1155MintableContract.ABI(),
        );
        return logs;
    }
    constructor(
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / generated-wrappers / staking_proxy.ts View on Github external
public subscribe(
        eventName: StakingProxyEvents,
        indexFilterValues: IndexedFilterValues,
        callback: EventCallback,
        isVerbose: boolean = false,
        blockPollingIntervalMs?: number,
    ): string {
        assert.doesBelongToStringEnum('eventName', eventName, StakingProxyEvents);
        assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
        assert.isFunction('callback', callback);
        const subscriptionToken = this._subscriptionManager.subscribe(
            this.address,
            eventName,
            indexFilterValues,
            StakingProxyContract.ABI(),
            callback,
            isVerbose,
            blockPollingIntervalMs,
        );
        return subscriptionToken;
    }
    /**
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / contract_wrappers.ts View on Github external
constructor(supportedProvider: SupportedProvider, config: ContractWrappersConfig) {
        assert.doesConformToSchema('config', config, ContractWrappersConfigSchema);
        const txDefaults = {
            gasPrice: config.gasPrice,
        };
        this._web3Wrapper = new Web3Wrapper(supportedProvider, txDefaults);
        const contractsArray = [
            CoordinatorContract,
            DevUtilsContract,
            ERC20TokenContract,
            ERC721TokenContract,
            ExchangeContract,
            ForwarderContract,
            StakingContract,
            WETH9Contract,
        ];
        contractsArray.forEach(contract => {
            this._web3Wrapper.abiDecoder.addABI(contract.ABI(), contract.contractName);
github 0xProject / 0x-monorepo / packages / abi-gen-wrappers / src / generated-wrappers / erc20_proxy.ts View on Github external
public subscribe(
        eventName: ERC20ProxyEvents,
        indexFilterValues: IndexedFilterValues,
        callback: EventCallback,
        isVerbose: boolean = false,
        blockPollingIntervalMs?: number,
    ): string {
        assert.doesBelongToStringEnum('eventName', eventName, ERC20ProxyEvents);
        assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
        assert.isFunction('callback', callback);
        const subscriptionToken = this._subscriptionManager.subscribe(
            this.address,
            eventName,
            indexFilterValues,
            ERC20ProxyContract.ABI(),
            callback,
            isVerbose,
            blockPollingIntervalMs,
        );
        return subscriptionToken;
    }
    /**