Skip to content

Commit 7fc1cee

Browse files
gabrocheleaujochem-brouweram1r021
authored
monorepo: misc type improvements (#3960)
* monorepo: remove some anys * monorepo: improve types and remove some anys * monorepo: fix more <any> typecastings * monorepo: more fixes * evm: fix opcode type issues with typeguard * chore: fix formatting * monorepo: fix types throughout * monorepo: more type fixes * evm: remove unnecssary update * format: spellcheck * fix: attempt to fix * Update packages/client/bin/utils.ts Co-authored-by: Scorbajio <[email protected]> * refactor: address review and small improvements2 --------- Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Scorbajio <[email protected]>
1 parent 9ef6e49 commit 7fc1cee

37 files changed

+185
-107
lines changed

packages/binarytree/src/binaryTree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class BinaryTree {
6565
this._root = this.EMPTY_TREE_ROOT
6666

6767
if (opts?.root) {
68-
this.root(opts.root as any)
68+
this.root(opts.root)
6969
}
7070

7171
this.DEBUG =

packages/block/test/block.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ describe('[Block]: block functions', () => {
165165
const common = new Common({ chain: Mainnet, hardfork: Hardfork.London })
166166
const block = createBlockFromRLP(blockRlp, { common, freeze: false })
167167
await testTransactionValidation(block)
168-
;(block.header as any).transactionsTrie = new Uint8Array(32)
168+
// @ts-expect-error -- Assigning a read-only property
169+
block.header.transactionsTrie = new Uint8Array(32)
169170
try {
170171
await block.validateData()
171172
assert.fail('should throw')
@@ -205,7 +206,8 @@ describe('[Block]: block functions', () => {
205206
const blockRlp = hexToBytes(testdataPreLondonData.blocks[0].rlp as PrefixedHexString)
206207
const block = createBlockFromRLP(blockRlp, { common, freeze: false })
207208
await testTransactionValidation(block)
208-
;(block.transactions[0] as any).gasPrice = BigInt(0)
209+
// @ts-expect-error -- Assigning to read-only property
210+
block.transactions[0].gasPrice = BigInt(0)
209211
const result = block.getTransactionsValidationErrors()
210212
assert.isTrue(
211213
result[0].includes('tx unable to pay base fee (non EIP-1559 tx)'),
@@ -218,7 +220,8 @@ describe('[Block]: block functions', () => {
218220
const blockRlp = hexToBytes(testdataPreLondon2Data.blocks[2].rlp as PrefixedHexString)
219221
const block = createBlockFromRLP(blockRlp, { common, freeze: false })
220222
assert.equal(block.uncleHashIsValid(), true)
221-
;(block.header as any).uncleHash = new Uint8Array(32)
223+
// @ts-expect-error -- Assigning to read-only property
224+
block.header.uncleHash = new Uint8Array(32)
222225
try {
223226
await block.validateData()
224227
assert.fail('should throw')

packages/block/test/eip1559block.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ describe('EIP1559 tests', () => {
9494
freeze: false,
9595
},
9696
)
97-
;(header as any).baseFeePerGas = undefined
97+
// @ts-expect-error -- Assigning to read-only property
98+
header.baseFeePerGas = undefined
9899
await (header as any)._genericFormatValidation()
99100
} catch (e: any) {
100101
const expectedError = 'EIP1559 block has no base fee field'

packages/blockchain/test/clique.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,11 @@ describe('Clique: Initialization', () => {
218218

219219
it('should throw if signer in epoch checkpoint is not active', async () => {
220220
const { blockchain } = await initWithSigners([A])
221-
;(blockchain as any)._validateBlocks = false
221+
// @ts-expect-error -- Assign to read-only property
222+
blockchain['_validateBlocks'] = false
222223
// _validateConsensus needs to be true to trigger this test condition
223-
;(blockchain as any)._validateConsensus = true
224+
// @ts-expect-error -- Assign to read-only property
225+
blockchain['_validateConsensus'] = true
224226
const number = (COMMON.consensusConfig() as CliqueConfig).epoch
225227
const unauthorizedSigner = createAddressFromString('0x00a839de7922491683f547a67795204763ff8237')
226228
const extraData = concatBytes(

packages/client/bin/utils.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,9 @@ async function inputAccounts(args: ClientOpts) {
551551
})
552552

553553
// Hide key input
554-
;(rl as any).input.on('keypress', function () {
554+
// TODO: Investigate why type doesn't match & if this actually works
555+
// @ts-expect-error -- Absent from type
556+
rl['input'].on('keypress', function () {
555557
// get the number of characters entered so far:
556558
const len = (rl as any).line.length
557559
// move cursor back to the beginning of the input:
@@ -560,7 +562,9 @@ async function inputAccounts(args: ClientOpts) {
560562
readline.clearLine((rl as any).output, 1)
561563
// replace the original input with asterisks:
562564
for (let i = 0; i < len; i++) {
563-
;(rl as any).output.write('*')
565+
// TODO: Investigate why type doesn't match & if this actually works
566+
// @ts-expect-error -- Absent from type
567+
rl['output'].write('*')
564568
}
565569
})
566570

@@ -579,7 +583,9 @@ async function inputAccounts(args: ClientOpts) {
579583
const inputKey = (await question(
580584
`Please enter the 0x-prefixed private key to unlock ${address}:\n`,
581585
)) as PrefixedHexString
582-
;(rl as any).history = (rl as any).history.slice(1)
586+
// TODO: Investigate why type doesn't match & if this actually works
587+
// @ts-expect-error -- -- Property not present on type
588+
rl['history'] = rl['history'].slice(1)
583589
const privKey = hexToBytes(inputKey)
584590
const derivedAddress = createAddressFromPrivateKey(privKey)
585591
if (address.equals(derivedAddress) === true) {
@@ -720,7 +726,8 @@ export async function generateClientConfig(args: ClientOpts) {
720726
common = createCommonFromGethGenesis(genesisFile, {
721727
chain: chainName,
722728
})
723-
;(common.customCrypto as any) = cryptoFunctions
729+
// @ts-expect-error -- Assign to read-only property
730+
common.customCrypto = cryptoFunctions
724731
customGenesisState = parseGethGenesisState(genesisFile)
725732
}
726733

packages/client/src/execution/vmexecution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ export class VMExecution extends Execution {
112112

113113
if (this.config.vm !== undefined) {
114114
this.vm = this.config.vm
115-
;(this.vm as any).blockchain = this.chain.blockchain
115+
// @ts-expect-error -- Assigning to read-only property
116+
this.vm.blockchain = this.chain.blockchain
116117
}
117118

118119
if (this.metaDB) {

packages/client/test/cli/cli.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,9 @@ describe('[CLI]', () => {
277277
assert.include(message, 'engine', 'engine ws started')
278278
await wait(600)
279279
const client = Client.websocket({ url: 'ws://0.0.0.0:' + customPort })
280-
;(client as any).ws.on('open', async function () {
280+
// TODO: Investigate why type doesn't match & if this actually works
281+
// @ts-expect-error -- Property not present on type
282+
client['ws'].on('open', async function () {
281283
const res = await client.request('engine_exchangeCapabilities', [], 2.0)
282284
assert.isTrue(res.result.length > 0, 'read from WS RPC on custom address and port')
283285
child.kill()
@@ -307,7 +309,9 @@ describe('[CLI]', () => {
307309
// if ws endpoint startup message detected, call ws endpoint with RPC method
308310
await wait(600)
309311
const client = Client.websocket({ url: 'ws://0.0.0.0:' + customPort })
310-
;(client as any).ws.on('open', async function () {
312+
// TODO: Investigate why type doesn't match & if this actually works
313+
// @ts-expect-error -- Property not present on type
314+
client['ws'].on('open', async function () {
311315
const res = await client.request('web3_clientVersion', [], 2.0)
312316
assert.isTrue(res.result.includes('EthereumJS'), 'read from WS RPC')
313317
child.kill()

packages/client/test/integration/beaconsync.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { assert, describe, expect, it, vi } from 'vitest'
55
import { Event } from '../../src/types.ts'
66
import { postMergeData } from '../testdata/geth-genesis/post-merge.ts'
77

8+
import type { BeaconSynchronizer } from '../../src/sync/beaconsync.ts'
89
import { destroy, setup, wait } from './util.ts'
910

1011
const common = createCommonFromGethGenesis(postMergeData, { chain: 'post-merge' })
@@ -21,7 +22,7 @@ describe('should sync blocks', async () => {
2122
const [remoteServer, remoteService] = await setup({ location: '127.0.0.2', height: 20, common })
2223
const [localServer, localService] = await setup({ location: '127.0.0.1', height: 0, common })
2324
const next = await remoteService.chain.getCanonicalHeadHeader()
24-
;(localService.synchronizer as any).skeleton.status.progress.subchains = [
25+
;(localService.synchronizer as BeaconSynchronizer).skeleton['status'].progress.subchains = [
2526
{
2627
head: BigInt(21),
2728
tail: BigInt(21),
@@ -73,7 +74,7 @@ describe('should sync with best peer', async () => {
7374
common,
7475
minPeers: 2,
7576
})
76-
;(localService.synchronizer as any).skeleton.status.progress.subchains = [
77+
;(localService.synchronizer as BeaconSynchronizer).skeleton['status'].progress.subchains = [
7778
{
7879
head: BigInt(11),
7980
tail: BigInt(11),

packages/client/test/integration/client.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const config = new Config({
1717
})
1818

1919
// attach server to centralized event bus
20-
;(config.server?.config as any).events = config.events
20+
/// @ts-expect-error -- Overwriting events
21+
config.server.config.events = config.events
2122
const client = await EthereumClient.create({ config })
2223

2324
describe('client should start/stop/error', async () => {

packages/client/test/integration/mocks/mockserver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ export class MockServer extends Server {
3939
transport: this.name,
4040
url: `mock://${this.location}`,
4141
})
42-
;(this.server as any).on('connection', async ({ id, stream }: { id: string; stream: any }) => {
42+
// TODO: Investigate why type doesn't match & if this actually works
43+
/// @ts-expect-error -- on property does not seem to exist?
44+
this.server['on']('connection', async ({ id, stream }: { id: string; stream: any }) => {
4345
await this.connect(id, stream)
4446
})
4547
return true

0 commit comments

Comments
 (0)