Skip to content

Commit

Permalink
monorepo: fix misc type issues and remove ts-ignore clauses (#3621)
Browse files Browse the repository at this point in the history
* monorepo: fix misc type issues and remove ts-ignore clauses

* monorepo: fix linting
  • Loading branch information
gabrocheleau authored Aug 27, 2024
1 parent 75eebc3 commit 8816159
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 31 deletions.
6 changes: 2 additions & 4 deletions packages/block/test/block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import * as testDataPreLondon2 from './testdata/testdata_pre-london-2.json'
import * as testDataPreLondon from './testdata/testdata_pre-london.json'
import * as testnetMerge from './testdata/testnetMerge.json'

import type { ChainConfig } from '@ethereumjs/common'
import type { NestedUint8Array, PrefixedHexString } from '@ethereumjs/util'

describe('[Block]: block functions', () => {
Expand Down Expand Up @@ -99,10 +100,7 @@ describe('[Block]: block functions', () => {
})

it('initialization -> setHardfork option', () => {
// @ts-ignore type is too strict in this case
const common = createCustomCommon(testnetMerge.default, Mainnet, {
name: 'testnetMerge',
})
const common = createCustomCommon(testnetMerge.default as ChainConfig, Mainnet)

let block = createBlock(
{
Expand Down
2 changes: 0 additions & 2 deletions packages/client/src/util/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ export function createRPCServer(
server.on('response', onBatchResponse)
const namespaces = [...new Set(Object.keys(methods).map((m) => m.split('_')[0]))].join(',')

//@ts-ignore
return { server, methods, namespaces }
}

Expand Down Expand Up @@ -207,7 +206,6 @@ export function createRPCServerListener(opts: CreateRPCServerListenerOpts): Http
}
})
}
//@ts-ignore
app.use(server.middleware())
const httpServer = createServer(app)
return httpServer
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/execution/vmexecution.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import shanghaiJSON from '../testdata/geth-genesis/withdrawals.json'

import type { BlockData, ExecutionPayload } from '@ethereumjs/block'
import type { Blockchain } from '@ethereumjs/blockchain'
import type { ChainConfig } from '@ethereumjs/common'

const shanghaiPayload = {
blockNumber: '0x1',
Expand Down Expand Up @@ -123,8 +124,7 @@ describe('[VMExecution]', () => {
newHead = await exec.vm.blockchain.getIteratorHead!()
assert.equal(newHead.header.number, BigInt(5), 'should run all blocks')

// @ts-ignore PrefixedHexString type is too strict
const common = createCustomCommon(testnet, Mainnet)
const common = createCustomCommon(testnet as ChainConfig, Mainnet)
exec = await testSetup(blockchain, common)
await exec.run()
assert.equal(exec.hardfork, 'byzantium', 'should update HF on block run')
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/sync/skeleton.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import mergeGenesisParams from '../testdata/common/mergeTestnet.json'
import genesisJSON from '../testdata/geth-genesis/post-merge.json'

import type { Block } from '@ethereumjs/block'
import type { ChainConfig } from '@ethereumjs/common'
type Subchain = {
head: bigint
tail: bigint
Expand Down Expand Up @@ -810,8 +811,7 @@ describe('[Skeleton] / setHead', async () => {
})

it('should abort filling the canonical chain if the terminal block is invalid', async () => {
// @ts-ignore PrefixedHexString type is too strict
const common = createCustomCommon(mergeGenesisParams, Mainnet, { name: 'post-merge' })
const common = createCustomCommon(mergeGenesisParams as ChainConfig, Mainnet)
common.setHardforkBy({ blockNumber: BigInt(0) })
const config = new Config({
common,
Expand Down
8 changes: 4 additions & 4 deletions packages/evm/test/eips/eip-4200.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { createEVM } from '../../src/index.js'

import { getCommon } from './eof-utils.js'

import type { PrefixedHexString } from '@ethereumjs/util'

async function getEVM() {
const common = getCommon()
const evm = createEVM({
Expand All @@ -19,12 +21,10 @@ describe('EIP 4200 tests', async () => {
const evm = await getEVM()
for (const key in testData.validInvalid.vectors) {
it(`Container validation tests ${key}`, () => {
//@ts-ignore
const input = testData.validInvalid.vectors[key]
const code = hexToBytes(input.code)
const input = testData.validInvalid.vectors[key as keyof typeof testData.validInvalid.vectors]
const code = hexToBytes(input.code as PrefixedHexString)

const expected = input.results.Prague.result
const _exception = input.results.Prague.exception

if (expected === true) {
validateEOF(code, evm)
Expand Down
2 changes: 1 addition & 1 deletion packages/trie/src/trie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ export class Trie {
if (branchNode instanceof BranchNode) {
// create an extension node
// branch->extension->branch
// @ts-ignore
// @ts-ignore Why does this work, and why are we doing this? See issue https://github.com/ethereumjs/ethereumjs-monorepo/issues/3620
const extensionNode = new ExtensionNode([branchKey], null)
stack.push(extensionNode)
key.push(branchKey)
Expand Down
3 changes: 1 addition & 2 deletions packages/tx/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ export class AuthorizationLists {
for (let i = 0; i < authorizationList.length; i++) {
const item: AuthorizationListItem = authorizationList[i]
for (const key of jsonItems) {
// @ts-ignore TODO why does TsScript fail here?
if (item[key] === undefined) {
if (item[key as keyof typeof item] === undefined) {
throw new Error(`EIP-7702 authorization list invalid: ${key} is not defined`)
}
}
Expand Down
9 changes: 3 additions & 6 deletions packages/vm/test/api/customChain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { VM } from '../../src/vm.js'
import * as testChain from './testdata/testnet.json'
import * as testnetMerge from './testdata/testnetMerge.json'

import type { ChainConfig } from '@ethereumjs/common'
import type { AccountState, GenesisState, PrefixedHexString } from '@ethereumjs/util'

const storage: Array<[PrefixedHexString, PrefixedHexString]> = [
Expand Down Expand Up @@ -49,9 +50,7 @@ const genesisState: GenesisState = {
[contractAddress]: accountState,
}

// @ts-ignore PrefixedHesString type is too strict
const common = createCustomCommon(testChain.default, Mainnet, {
name: 'testnet',
const common = createCustomCommon(testChain.default as ChainConfig, Mainnet, {
hardfork: Hardfork.Chainstart,
})
const block = createBlock(
Expand Down Expand Up @@ -117,9 +116,7 @@ describe('VM initialized with custom state', () => {
})

it('setHardfork', async () => {
// @ts-ignore PrefixedHexString type is too strict
const common = createCustomCommon(testnetMerge.default, Mainnet, {
name: 'testnetMerge',
const common = createCustomCommon(testnetMerge.default as ChainConfig, Mainnet, {
hardfork: Hardfork.Istanbul,
})

Expand Down
5 changes: 2 additions & 3 deletions packages/vm/test/api/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { VM } from '../../src/vm.js'
import * as testnetMerge from './testdata/testnetMerge.json'
import { setupVM } from './utils.js'

import type { ChainConfig } from '@ethereumjs/common'
import type { DefaultStateManager } from '@ethereumjs/statemanager'

/**
Expand Down Expand Up @@ -217,9 +218,7 @@ describe('VM -> common (chain, HFs, EIPs)', () => {

describe('VM -> setHardfork, state (deprecated), blockchain', () => {
it('setHardfork', async () => {
// @ts-ignore PrefixedHexString type is too strict
const common = createCustomCommon(testnetMerge.default, Mainnet, {
name: 'testnetMerge',
const common = createCustomCommon(testnetMerge.default as ChainConfig, Mainnet, {
hardfork: Hardfork.Istanbul,
})

Expand Down
8 changes: 3 additions & 5 deletions packages/vm/test/api/runBlock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ import type {
RunBlockOpts,
} from '../../src/types.js'
import type { Block, BlockBytes } from '@ethereumjs/block'
import type { AuthorizationListBytesItem } from '@ethereumjs/common'
import type { ChainConfig } from '@ethereumjs/common'
import type { DefaultStateManager } from '@ethereumjs/statemanager'
import type { TypedTransaction } from '@ethereumjs/tx'
import type { AuthorizationListBytesItem, TypedTransaction } from '@ethereumjs/tx'
import type { NestedUint8Array, PrefixedHexString } from '@ethereumjs/util'

const common = new Common({ chain: Mainnet, hardfork: Hardfork.Berlin })
Expand Down Expand Up @@ -154,9 +154,7 @@ describe('runBlock() -> successful API parameter usage', async () => {
})

it('PoW block, Common custom chain (Common customChains constructor option)', async () => {
// @ts-ignore because PrefixedHexString type is too strict
const common = createCustomCommon(testnet.default, Mainnet, {
name: 'testnet',
const common = createCustomCommon(testnet.default as ChainConfig, Mainnet, {
hardfork: Hardfork.Berlin,
})
const vm = await setupVM({ common })
Expand Down

0 comments on commit 8816159

Please sign in to comment.