Commit e8018b4b authored by rajivpoc's avatar rajivpoc

removed unused functions from core utils

parent e6151443
......@@ -15,10 +15,6 @@ export interface AppendSequencerBatchParams {
transactions: string[] // total_size_bytes[],total_size_bytes[]
}
/**********************
* Internal Functions *
*********************/
const APPEND_SEQUENCER_BATCH_METHOD_ID = 'appendSequencerBatch()'
export const encodeAppendSequencerBatch = (
......
/* Imports: External */
import { ethers } from 'ethers'
/* Imports: Internal */
import { getRandomHexString } from './hex-strings'
/* @returns a random Ethereum address as a string of 40 hex characters, normalized as a checksum address. */
export const getRandomAddress = (): string => {
return ethers.utils.getAddress(getRandomHexString(20))
}
export const assert = (condition: () => boolean, reason?: string) => {
try {
if (condition() === false) {
throw new Error(`Assertion failed: ${reason}`)
}
} catch (err) {
throw new Error(`Assertion failed: ${reason}\n${err}`)
}
}
......@@ -27,16 +27,6 @@ export const add0x = (str: string): string => {
return str.startsWith('0x') ? str : '0x' + str
}
/**
* Returns whether or not the provided string is a hex string.
*
* @param str The string to test.
* @returns True if the provided string is a hex string, false otherwise.
*/
export const isHexString = (inp: any): boolean => {
return typeof inp === 'string' && inp.startsWith('0x')
}
/**
* Casts a hex string to a buffer.
*
......@@ -88,30 +78,5 @@ export const padHexString = (str: string, length: number): string => {
}
}
export const getLen = (pos: { start; end }) => (pos.end - pos.start) * 2
export const encodeHex = (val: any, len: number) =>
remove0x(BigNumber.from(val).toHexString()).padStart(len, '0')
export const toVerifiedBytes = (val: string, len: number) => {
val = remove0x(val)
if (val.length !== len) {
throw new Error('Invalid length!')
}
return val
}
/**
* @param byteLength The length of the hex string in bytes
* @returns a random hex string of the specified byteLength (string length will be byteLength*2)
*/
export const getRandomHexString = (byteLength: number): string => {
return (
'0x' +
[...Array(byteLength * 2)]
.map(() => {
return Math.floor(Math.random() * 16).toString(16)
})
.join('')
)
}
export * from './addresses'
export * from './hex-strings'
export * from './misc'
export * from './common'
......@@ -5,14 +5,12 @@
import { BigNumber } from 'ethers'
import { remove0x } from './common'
const hundredMillion = BigNumber.from(100_000_000)
const feeScalar = 10_000_000
export const TxGasPrice = BigNumber.from(feeScalar + feeScalar / 2)
const txDataZeroGas = 4
const txDataNonZeroGasEIP2028 = 16
const overhead = 4200 + 200 * txDataNonZeroGasEIP2028
const tenThousand = BigNumber.from(10_000)
export const TxGasPrice = BigNumber.from(feeScalar + feeScalar / 2)
export interface EncodableL2GasLimit {
data: Buffer | string
l1GasPrice: BigNumber | number
......
import { expect } from '../setup'
/* Imports: Internal */
import { getRandomAddress } from '../../src'
describe('getRandomAddress', () => {
const random = global.Math.random
before(async () => {
global.Math.random = () => 0.5
})
after(async () => {
global.Math.random = random
})
it('returns a random address string', () => {
expect(getRandomAddress()).to.equal('0x' + '88'.repeat(20))
})
})
......@@ -2,23 +2,7 @@ import { expect } from '../setup'
import { BigNumber } from 'ethers'
/* Imports: Internal */
import { getRandomHexString, toRpcHexString } from '../../src'
describe('getRandomHexString', () => {
const random = global.Math.random
before(async () => {
global.Math.random = () => 0.5
})
after(async () => {
global.Math.random = random
})
it('returns a random address string of the specified length', () => {
expect(getRandomHexString(8)).to.equal('0x' + '88'.repeat(8))
})
})
import { toRpcHexString } from '../../src'
describe('toRpcHexString', () => {
it('should parse 0', () => {
......
import { expect } from '../setup'
import * as fees from '../../src/fees'
import { BigNumber, utils } from 'ethers'
import { utils } from 'ethers'
const hundredBillion = 10 ** 11
const million = 10 ** 6
describe('Fees', () => {
it('should count zeros and ones', () => {
......
/* Imports: External */
import { fromHexString, EventArgsAddressSet } from '@eth-optimism/core-utils'
import { fromHexString } from '@eth-optimism/core-utils'
import { BaseService, Metrics } from '@eth-optimism/common-ts'
import { JsonRpcProvider } from '@ethersproject/providers'
import { LevelUp } from 'levelup'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment