How to use the @0x/assert.assert.isNumber 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 / web3-wrapper / src / web3_wrapper.ts View on Github external
public async increaseTimeAsync(timeDelta: number): Promise {
        assert.isNumber('timeDelta', timeDelta);
        // Detect Geth vs. Ganache and use appropriate endpoint.
        const version = await this.getNodeVersionAsync();
        if (_.includes(version, uniqueVersionIds.geth)) {
            return this.sendRawPayloadAsync({ method: 'debug_increaseTime', params: [timeDelta] });
        } else if (_.includes(version, uniqueVersionIds.ganache)) {
            return this.sendRawPayloadAsync({ method: 'evm_increaseTime', params: [timeDelta] });
        } else {
            throw new Error(`Unknown client version: ${version}`);
        }
    }
    /**
github 0xProject / 0x-monorepo / packages / web3-wrapper / src / web3_wrapper.ts View on Github external
public async awaitTransactionMinedAsync(
        txHash: string,
        pollingIntervalMs: number = 1000,
        timeoutMs?: number,
    ): Promise {
        assert.isHexString('txHash', txHash);
        assert.isNumber('pollingIntervalMs', pollingIntervalMs);
        if (timeoutMs !== undefined) {
            assert.isNumber('timeoutMs', timeoutMs);
        }
        // Immediately check if the transaction has already been mined.
        let transactionReceipt = await this.getTransactionReceiptIfExistsAsync(txHash);
        if (transactionReceipt !== undefined) {
            const logsWithDecodedArgs = _.map(
                transactionReceipt.logs,
                this.abiDecoder.tryToDecodeLogOrNoop.bind(this.abiDecoder),
            );
            const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = {
                ...transactionReceipt,
                logs: logsWithDecodedArgs,
            };
            return transactionReceiptWithDecodedLogArgs;
        }

        // Otherwise, check again every pollingIntervalMs.
github 0xProject / 0x-monorepo / packages / web3-wrapper / src / web3_wrapper.ts View on Github external
public async awaitTransactionMinedAsync(
        txHash: string,
        pollingIntervalMs: number = 1000,
        timeoutMs?: number,
    ): Promise {
        assert.isHexString('txHash', txHash);
        assert.isNumber('pollingIntervalMs', pollingIntervalMs);
        if (timeoutMs !== undefined) {
            assert.isNumber('timeoutMs', timeoutMs);
        }
        // Immediately check if the transaction has already been mined.
        let transactionReceipt = await this.getTransactionReceiptIfExistsAsync(txHash);
        if (transactionReceipt !== undefined) {
            const logsWithDecodedArgs = _.map(
                transactionReceipt.logs,
                this.abiDecoder.tryToDecodeLogOrNoop.bind(this.abiDecoder),
            );
            const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = {
                ...transactionReceipt,
                logs: logsWithDecodedArgs,
            };
            return transactionReceiptWithDecodedLogArgs;
        }
github 0xProject / 0x-monorepo / packages / orderbook / src / order_provider / sra_polling_order_provider.ts View on Github external
constructor(opts: SRAPollingOrderProviderOpts, orderStore: OrderStore) {
        super(orderStore, opts.httpEndpoint, opts.perPage);
        assert.isNumber('pollingIntervalMs', opts.pollingIntervalMs);
        this._pollingIntervalMs = opts.pollingIntervalMs;
    }
github 0xProject / 0x-monorepo / packages / web3-wrapper / src / web3_wrapper.ts View on Github external
public static toUnitAmount(amount: BigNumber, decimals: number): BigNumber {
        assert.isValidBaseUnitAmount('amount', amount);
        assert.isNumber('decimals', decimals);
        const aUnit = new BigNumber(BASE_TEN).pow(decimals);
        const unit = amount.div(aUnit);
        return unit;
    }
    /**
github 0xProject / 0x-monorepo / packages / subproviders / src / subproviders / mnemonic_wallet.ts View on Github external
constructor(config: MnemonicWalletSubproviderConfigs) {
        assert.isString('mnemonic', config.mnemonic);
        const baseDerivationPath = config.baseDerivationPath || DEFAULT_BASE_DERIVATION_PATH;
        assert.isString('baseDerivationPath', baseDerivationPath);
        const addressSearchLimit = config.addressSearchLimit || DEFAULT_ADDRESS_SEARCH_LIMIT;
        assert.isNumber('addressSearchLimit', addressSearchLimit);
        super();

        this._mnemonic = config.mnemonic;
        this._baseDerivationPath = baseDerivationPath;
        this._addressSearchLimit = addressSearchLimit;
        this._derivedKeyInfo = this._initialDerivedKeyInfo(this._baseDerivationPath);
    }
    /**
github 0xProject / 0x-monorepo / packages / web3-wrapper / src / web3_wrapper.ts View on Github external
public async revertSnapshotAsync(snapshotId: number): Promise {
        assert.isNumber('snapshotId', snapshotId);
        const didRevert = await this.sendRawPayloadAsync({ method: 'evm_revert', params: [snapshotId] });
        return didRevert;
    }
    /**
github 0xProject / 0x-monorepo / packages / web3-wrapper / src / web3_wrapper.ts View on Github external
public static toBaseUnitAmount(amount: BigNumber | number, decimals: number): BigNumber {
        assert.isNumber('decimals', decimals);
        const unit = new BigNumber(BASE_TEN).pow(decimals);
        const baseUnitAmount = unit.times(amount);
        const hasDecimals = baseUnitAmount.decimalPlaces() !== 0;
        if (hasDecimals) {
            throw new Error(`Invalid unit amount: ${amount.toString(BASE_TEN)} - Too many decimal places`);
        }
        return baseUnitAmount;
    }
    /**
github 0xProject / 0x-monorepo / packages / web3-wrapper / src / web3_wrapper.ts View on Github external
public async setHeadAsync(blockNumber: number): Promise {
        assert.isNumber('blockNumber', blockNumber);
        await this.sendRawPayloadAsync({ method: 'debug_setHead', params: [utils.numberToHex(blockNumber)] });
    }
    /**