Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: fix misc tsc issues #3349

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/client/test/net/peer/peer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { assert, describe, it } from 'vitest'

import { Config } from '../../../src/config'
import { Peer } from '../../../src/net/peer'
import { Peer as AbstractPeer } from '../../../src/net/peer'

// Mock peer class (can't directly use the imported Peer class as it's abstract)
class Peer extends AbstractPeer {
async connect() {}
}

describe('[Peer]', () => {
const config = new Config({ accountCache: 10000, storageCache: 1000 })
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/sim/4844-devnet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('sharding/eip4844 hardfork tests', async () => {
done = false
let block2
while (!done) {
const nextBlockNumber = `0x${(Number(block1.result.number) + 1).toString('16')}`
const nextBlockNumber = `0x${(Number(block1.result.number) + 1).toString(16)}`
block2 = await client.request('eth_getBlockByNumber', [nextBlockNumber, false], 2.0)
if (block2.result !== null && block2.result !== undefined) {
done = true
Expand Down
27 changes: 15 additions & 12 deletions packages/client/test/sim/snapsync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
} from './simutils'

import type { EthereumClient } from '../../src/client'
import type { RlpxServer } from '../../src/net/server'
import type { DefaultStateManager } from '@ethereumjs/statemanager'

const client = Client.http({ port: 8545 })
Expand Down Expand Up @@ -130,12 +129,16 @@ describe('simple mainnet test run', async () => {
beaconSyncRelayer: relayer,
} =
// eslint-disable-next-line @typescript-eslint/no-use-before-define
(await createSnapClient(common, customGenesisState, [nodeInfo.enode], peerBeaconUrl).catch(
(e) => {
console.log(e)
return null
}
)) ?? {
(await createSnapClient(
common,
customGenesisState,
[nodeInfo.enode],
peerBeaconUrl,
''
).catch((e) => {
console.log(e)
return null
})) ?? {
ejsInlineClient: null,
peerConnectedPromise: Promise.reject('Client creation error'),
beaconSyncRelayer: null,
Expand All @@ -146,7 +149,7 @@ describe('simple mainnet test run', async () => {
snapCompleted = snapSyncCompletedPromise
assert.ok(ejsClient !== null, 'ethereumjs client started')

const enode = (ejsClient!.server('rlpx') as RlpxServer)!.getRlpxInfo().enode
const enode = ejsClient!.server()!.getRlpxInfo().enode
const res = await client.request('admin_addPeer', [enode])
assert.equal(res.result, true, 'successfully requested Geth add EthereumJS as peer')

Expand Down Expand Up @@ -176,7 +179,7 @@ describe('simple mainnet test run', async () => {
// call sync if not has been called yet
void ejsClient.services[0].synchronizer?.sync()
await Promise.race([
snapCompleted.then(([root, syncedStateManager]) => {
(snapCompleted as any).then(([root, syncedStateManager]: [any, any]) => {
syncedSnapRoot = root
stateManager = syncedStateManager
}),
Expand Down Expand Up @@ -208,13 +211,13 @@ describe('simple mainnet test run', async () => {
undefined,
undefined,
BigInt(0),
]
customGenesisState[sender][0] = `0x${senderBalance.toString(16)}`
] as any
;(customGenesisState[sender][0] as any) = `0x${senderBalance.toString(16)}`
}

for (const addressString of Object.keys(customGenesisState)) {
const address = Address.fromString(addressString)
const account = await stateManager.getAccount(address)
const account = await stateManager?.getAccount(address)
assert.equal(
account?.balance,
BigInt(customGenesisState[addressString][0]),
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/sync/beaconsync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('[BeaconSynchronizer]', async () => {
number: BigInt(2),
hash: () => new Uint8Array(0),
})
td.when(ReverseBlockFetcher.prototype.fetch(), { delay: 100, times: 3 }).thenResolve(undefined)
td.when(ReverseBlockFetcher.prototype.fetch(), { delay: 100, times: 3 }).thenResolve(false)
;(skeleton as any).status.progress.subchains = [
{ head: BigInt(10), tail: BigInt(6) },
{ head: BigInt(4), tail: BigInt(2) },
Expand Down Expand Up @@ -168,7 +168,7 @@ describe('[BeaconSynchronizer]', async () => {
number: BigInt(2),
hash: () => new Uint8Array(0),
})
td.when(ReverseBlockFetcher.prototype.fetch(), { delay: 100, times: 1 }).thenResolve(undefined)
td.when(ReverseBlockFetcher.prototype.fetch(), { delay: 100, times: 1 }).thenResolve(false)
;(skeleton as any).status.progress.subchains = [{ head: BigInt(10), tail: BigInt(6) }]
;(sync as any).chain = {
// Make height > tail so that skeletonSubchainMergeMinimum is triggered
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/sync/fetcher/accountfetcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ describe('[AccountFetcher]', async () => {
})

it('should verify zero-element proof correctly', async () => {
const config = new Config({ transports: [], accountCache: 10000, storageCache: 1000 })
const config = new Config({ accountCache: 10000, storageCache: 1000 })
const pool = new PeerPool() as any
const fetcher = new AccountFetcher({
config,
Expand Down Expand Up @@ -280,7 +280,7 @@ describe('[AccountFetcher]', async () => {
})

it('should reject zero-element proof if elements still remain to right of requested range', async () => {
const config = new Config({ transports: [], accountCache: 10000, storageCache: 1000 })
const config = new Config({ accountCache: 10000, storageCache: 1000 })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be off with this, but I think setting the transports here to empty was done to not have e.g. the RLPx layer started on tests here (and other occurrences as well). So this change might have the side-effect to reintroduce this for the test runs which is not what we want. We should double check here.

(I generally find this a bit problematic to do an eventual functional change just for typing reasons. What was the complaint here? Is there maybe a solution possible to adjust the type or something? 🤔 )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual TS issue in this case is the following:

Object literal may only specify known properties, and 'transports' does not exist in type 'ConfigOptions'.ts(2353)
(property) transports: never[]

It seems like the transports property was removed in this PR: #3069

Not sure why this should be kept?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second what @gabrocheleau said. transports no longer exists as a config option since we only support RPLx and not libp2p.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

const pool = new PeerPool() as any

// calculate new root with a key all the way to the right of the trie
Expand Down
7 changes: 0 additions & 7 deletions packages/client/test/sync/fetcher/bytecodefetcher.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { RLP } from '@ethereumjs/rlp'
import { Trie } from '@ethereumjs/trie'
import { hexToBytes } from '@ethereumjs/util'
import { utf8ToBytes } from 'ethereum-cryptography/utils'
import { assert, describe, it, vi } from 'vitest'
Expand All @@ -13,7 +12,6 @@ import { _accountRangeRLP } from './accountfetcher.spec'

const _byteCodesRLP =
'0xf89e1af89b9e60806040526004361061003f5760003560e01c806301ffc9a714610044579e60806040526004361061003f5760003560e01c806301ffc9a714610044589e60806040526004361061003f5760003560e01c806301ffc9a714610044599e60806040526004361061003f5760003560e01c806301ffc9a714610044609e60806040526004361061003f5760003560e01c806301ffc9a71461004461'
const useKeyHashing = true

describe('[ByteCodeFetcher]', async () => {
class PeerPool {
Expand All @@ -31,7 +29,6 @@ describe('[ByteCodeFetcher]', async () => {
const fetcher = new ByteCodeFetcher({
config,
pool,
trie: new Trie({ useKeyHashing }),
hashes: [hexToBytes('0x2034f79e0e33b0ae6bef948532021baceb116adf2616478703bec6b17329f1cc')],
})
fetcher.next = () => false
Expand Down Expand Up @@ -60,7 +57,6 @@ describe('[ByteCodeFetcher]', async () => {
const fetcher = new ByteCodeFetcher({
config,
pool,
trie: new Trie({ useKeyHashing }),
hashes: [],
})

Expand Down Expand Up @@ -88,7 +84,6 @@ describe('[ByteCodeFetcher]', async () => {
const fetcher = new ByteCodeFetcher({
config,
pool,
trie: new Trie({ useKeyHashing }),
hashes: [],
})
const ByteCodeResponse: any = [utf8ToBytes(''), utf8ToBytes('')]
Expand Down Expand Up @@ -117,7 +112,6 @@ describe('[ByteCodeFetcher]', async () => {
const fetcher = new ByteCodeFetcher({
config,
pool,
trie: new Trie({ useKeyHashing }),
hashes: [],
})

Expand Down Expand Up @@ -169,7 +163,6 @@ describe('[ByteCodeFetcher]', async () => {
const fetcher = new ByteCodeFetcher({
config,
pool,
trie: new Trie({ useKeyHashing }),
hashes: [utf8ToBytes('')],
})
assert.equal(fetcher.peer(), 'peer0' as any, 'found peer')
Expand Down
28 changes: 15 additions & 13 deletions packages/client/test/sync/fetcher/storagefetcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
_zeroElementProofRoot,
} from './accountfetcher.spec'

import type { StorageFetcherOptions } from '../../../src/sync/fetcher/storagefetcher'

const _storageRangesRLP =
'0xf83e0bf83af838f7a0290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5639594053cd080a26cb03d5e6d2956cebb31c56e7660cac0'

Expand Down Expand Up @@ -52,7 +54,7 @@ describe('[StorageFetcher]', async () => {
count: BigInt(2) ** BigInt(256) - BigInt(1),
},
],
})
} as StorageFetcherOptions)
fetcher.next = () => false
assert.notOk((fetcher as any).running, 'not started')
assert.equal((fetcher as any).in.length, 0, 'No jobs have yet been added')
Expand Down Expand Up @@ -91,7 +93,7 @@ describe('[StorageFetcher]', async () => {
root: utf8ToBytes(''),
first: BigInt(1),
count: BigInt(10),
})
} as StorageFetcherOptions)
const fullResult: any = [
[
[{ hash: utf8ToBytes(''), body: utf8ToBytes('') }],
Expand Down Expand Up @@ -120,7 +122,7 @@ describe('[StorageFetcher]', async () => {
],
}
;(fetcher as any).running = true
fetcher.enqueueTask(task)
fetcher.enqueueTask(task as any)
const job = (fetcher as any).in.peek()
assert.deepEqual(
(fetcher.process(job, StorageDataResponse) as any)[0],
Expand All @@ -139,7 +141,7 @@ describe('[StorageFetcher]', async () => {
root: utf8ToBytes(''),
first: BigInt(1),
count: BigInt(10),
})
} as StorageFetcherOptions)

const accountHashString = '0xe9a5016cb1a53dbc750d06e725514ac164231d71853cafdcbff42f5adb6ca6f1'
const highestReceivedhash = '10'
Expand Down Expand Up @@ -203,7 +205,7 @@ describe('[StorageFetcher]', async () => {
config,
pool,
root: utf8ToBytes(''),
})
} as StorageFetcherOptions)
const StorageDataResponse: any = [
[
[{ hash: utf8ToBytes(''), body: utf8ToBytes('') }],
Expand All @@ -226,7 +228,7 @@ describe('[StorageFetcher]', async () => {
],
}
;(fetcher as any).running = true
fetcher.enqueueTask(task)
fetcher.enqueueTask(task as any)
const job = (fetcher as any).in.peek()
let results = fetcher.process(job as any, StorageDataResponse)
assert.equal((fetcher as any).in.length, 1, 'Fetcher should still have same job')
Expand All @@ -253,7 +255,7 @@ describe('[StorageFetcher]', async () => {
config,
pool,
root: utf8ToBytes(''),
})
} as StorageFetcherOptions)
const partialResult: any = [
[
[{ hash: utf8ToBytes(''), body: utf8ToBytes('') }],
Expand Down Expand Up @@ -319,13 +321,13 @@ describe('[StorageFetcher]', async () => {
})

it('should verify zero-element proof correctly', async () => {
const config = new Config({ transports: [], accountCache: 10000, storageCache: 1000 })
const config = new Config({ accountCache: 10000, storageCache: 1000 })
const pool = new PeerPool() as any
const fetcher = new StorageFetcher({
config,
pool,
root: _zeroElementProofRoot,
})
} as StorageFetcherOptions)
const task = {
storageRequests: [
{
Expand Down Expand Up @@ -356,7 +358,7 @@ describe('[StorageFetcher]', async () => {
})

it('should reject zero-element proof if elements still remain to right of requested range', async () => {
const config = new Config({ transports: [], accountCache: 10000, storageCache: 1000 })
const config = new Config({ accountCache: 10000, storageCache: 1000 })
const pool = new PeerPool() as any

// calculate new root with a key all the way to the right of the trie
Expand All @@ -368,7 +370,7 @@ describe('[StorageFetcher]', async () => {
config,
pool,
root: _zeroElementProofRoot,
})
} as StorageFetcherOptions)
const task = {
storageRequests: [
{
Expand Down Expand Up @@ -407,7 +409,7 @@ describe('[StorageFetcher]', async () => {
config,
pool,
root: utf8ToBytes(''),
})
} as StorageFetcherOptions)
const partialResult: any = [
[
[{ hash: utf8ToBytes(''), body: utf8ToBytes('') }],
Expand Down Expand Up @@ -508,7 +510,7 @@ describe('[StorageFetcher]', async () => {
root: utf8ToBytes(''),
first: BigInt(1),
count: BigInt(10),
})
} as StorageFetcherOptions)
;(fetcher as any).pool.idle = vi.fn(() => 'peer0')
assert.equal(fetcher.peer(), 'peer0' as any, 'found peer')
})
Expand Down
Loading
Loading