Skip to content

Commit

Permalink
Disable jsdoc for test files
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmire committed Sep 29, 2021
1 parent 5fcbb2c commit 118fda6
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 27 deletions.
38 changes: 38 additions & 0 deletions .eslintrc.js
Expand Up @@ -14,6 +14,44 @@ module.exports = {
{
files: ['*.test.ts', '*.test.js'],
extends: ['@metamask/eslint-config-jest'],
rules: {
'jsdoc/check-access': 'off',
'jsdoc/check-alignment': 'off',
'jsdoc/check-line-alignment': 'off',
'jsdoc/check-param-names': 'off',
'jsdoc/check-property-names': 'off',
'jsdoc/check-tag-names': 'off',
'jsdoc/check-types': 'off',
'jsdoc/check-values': 'off',
'jsdoc/empty-tags': 'off',
'jsdoc/implements-on-classes': 'off',
'jsdoc/match-description': 'off',
'jsdoc/multiline-blocks': 'off',
'jsdoc/newline-after-description': 'off',
'jsdoc/no-bad-blocks': 'off',
'jsdoc/no-defaults': 'off',
'jsdoc/no-multi-asterisks': 'off',
'jsdoc/require-asterisk-prefix': 'off',
'jsdoc/require-description': 'off',
'jsdoc/require-hyphen-before-param-description': 'off',
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param-name': 'off',
'jsdoc/require-param': 'off',
'jsdoc/require-param-description': 'off',
'jsdoc/require-param-type': 'off',
'jsdoc/require-property': 'off',
'jsdoc/require-property-description': 'off',
'jsdoc/require-property-name': 'off',
'jsdoc/require-property-type': 'off',
'jsdoc/require-returns': 'off',
'jsdoc/require-returns-check': 'off',
'jsdoc/require-returns-description': 'off',
'jsdoc/require-returns-type': 'off',
'jsdoc/require-yields': 'off',
'jsdoc/require-yields-check': 'off',
'jsdoc/tag-lines': 'off',
'jsdoc/valid-types': 'off',
},
},
{
files: ['*.js'],
Expand Down
52 changes: 25 additions & 27 deletions src/gas/fetchFeeHistory.ts
Expand Up @@ -9,7 +9,6 @@ type HexString = `0x${string}`;
*
* Historical data for gas and priority fees for a range of blocks within a
* particular network. This can be used to gauge how congested the network is.
*
* @property {string} startBlockId - The id of the oldest block in the block
* range requested (as hex).
* @property {Array<BlockFeeHistory>} blocks - Data for the blocks in the block
Expand All @@ -25,7 +24,6 @@ type FeeHistory = {
* @type BlockFeeHistory
*
* Historical data for gas and priority fees for a block.
*
* @property {Array<number>} baseFeePerGas - The base fee per gas for the block.
* @property {Array<number>} gasUsedRatio - A number between 0 and 1 that
* represents the ratio between the effective gas used and the gas limit for
Expand Down Expand Up @@ -53,36 +51,36 @@ type EthFeeHistoryResponse = {
};
};

function hexToDec(hex: string): any {
/**
* Converts a hexadecimal string to a decimal number (as a BN instance).
*
* @param hex - A string encoding a hexadecimal number (with a "0x") prefix.
* @returns The BN instance.
*/
function hexToDec(hex: string): BN {
return new BN(new BN(stripHexPrefix(hex), 16).toString(10), 10);
}

/**
* Uses eth_feeHistory (an EIP-1559 feature) to obtain information about gas and
* priority fees from a range of blocks that appeared on a network, starting
* from a particular block and working backward in time. This can be used to
* gauge how congested the network is.
* Uses eth_feeHistory (an EIP-1559 feature) to obtain information about gas and priority fees from
* a range of blocks that appeared on a network, starting from a particular block and working
* backward in time. This can be used to gauge how congested the network is.
*
* @param args - The arguments.
* @param args.ethQuery - An EthQuery instance that wraps a provider for the
* network in question.
* @param args.endBlock - Which block to start with when forming the block
* range. Can be a block tag ("latest" for the latest successful block or
* "pending" for the latest pending block) or a block id.
* @param args.numberOfBlocks - How many blocks to jump back from the endBlock when
* forming the block range. Each array in the return value will be of this
* length.
* @param args.percentiles - A tuple of numbers between 1 and 100 which will
* advise how priorityFeesByPercentile in the return value will be formed. When
* Ethereum runs the eth_feeHistory method, for each block it is considering, it
* will calculate the ratio of gas used for each transaction compared to the
* total gas used for the block, then sort all transactions in the block by this
* ratio. For each percentile given, it will then find the transaction whose gas
* used ratio matches the percentile and capture that transaction's priority fee.
* Hence, priorityFeesByPercentile represents the priority fees of transactions
* at key gas used ratios.
*
* @return Promise<FeeHistory>
* @param args.ethQuery - An EthQuery instance that wraps a provider for the network in question.
* @param args.endBlock - Which block to start with when forming the block range. Can be a block tag
* ("latest" for the latest successful block or "pending" for the latest pending block) or a block
* id.
* @param args.numberOfBlocks - How many blocks to jump back from the endBlock when forming the
* block range. Each array in the return value will be of this length.
* @param args.percentiles - A tuple of numbers between 1 and 100 which will advise how
* priorityFeesByPercentile in the return value will be formed. When Ethereum runs the
* eth_feeHistory method, for each block it is considering, it will calculate the ratio of gas used
* for each transaction compared to the total gas used for the block, then sort all transactions in
* the block by this ratio. For each percentile given, it will then find the transaction whose gas
* used ratio matches the percentile and capture that transaction's priority fee. Hence,
* priorityFeesByPercentile represents the priority fees of transactions at key gas used ratios.
* @returns The fee history data.
*/
export async function fetchFeeHistory({
ethQuery,
Expand Down Expand Up @@ -124,7 +122,7 @@ export async function fetchFeeHistory({
],
numberOfColumnsPerTuple: numberOfBlocks,
}).map(([baseFeePerGasAsHex, gasUsedRatio, priorityFeesAsHex]) => {
const baseFeePerGas = hexToDec(baseFeePerGasAsHex);
const baseFeePerGas = hexToDec(baseFeePerGasAsHex).toString(10);

const priorityFeesByPercentile: Map<number, string> = zipEqualSizedTuples(
{
Expand Down
11 changes: 11 additions & 0 deletions src/util.ts
Expand Up @@ -768,6 +768,17 @@ export function validateMinimumIncrease(proposed: string, min: string) {
throw new Error(errorMsg);
}

/**
* Rotates a matrix. That is, takes an array of tuples (arrays) representing rows and columns and
* reorients that array such that rows becomes columns and vice versa. Each row is expected to have
* the same number of columns, although if that is not the case, then the final result will have the
* same number of columns per row, where values may be filled in with undefined.
*
* @param args - The arguments.
* @param args.tuples - The tuples on which we want to operate.
* @param args.numberOfColumnsPerTuple - The number of columns you expected each row to have.
* @returns The rotated array of arrays.
*/
export function zipEqualSizedTuples({
tuples,
numberOfColumnsPerTuple,
Expand Down

0 comments on commit 118fda6

Please sign in to comment.