Skip to content

Commit

Permalink
client: revert changes to test files
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Jan 20, 2024
1 parent 4fa316b commit 6cca82c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
16 changes: 9 additions & 7 deletions packages/client/test/net/peerpool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { EventEmitter } from 'events'
import { assert, describe, it, vi } from 'vitest'

import { Config } from '../../src/config'
import { PeerPool } from '../../src/net/peerpool.js'
import { Event } from '../../src/types'
import { MockPeer } from '../integration/mocks/mockpeer'

Expand All @@ -11,12 +10,13 @@ describe('[PeerPool]', async () => {
id: string
idle: boolean

constructor(id: string) {
this.id = id
constructor(id: string | number) {
this.id = id.toString()
this.idle = false
}
}
vi.doMock('../../src/net/peer/peer', () => Peer)
const { PeerPool } = await import('../../src/net/peerpool')

it('should initialize', () => {
const config = new Config({ accountCache: 10000, storageCache: 1000 })
Expand Down Expand Up @@ -71,24 +71,26 @@ describe('[PeerPool]', async () => {
})

it('should check contains', () => {
const peer: any = new Peer('abc')
const peer = new Peer('abc')
const config = new Config({ accountCache: 10000, storageCache: 1000 })
const pool = new PeerPool({ config })
// @ts-ignore
pool.add(peer)
assert.ok(pool.contains(peer.id), 'found peer')
})

it('should get idle peers', () => {
const peers = [new Peer('1'), new Peer('2'), new Peer('3')]
const peers = [new Peer(1), new Peer(2), new Peer(3)]
const config = new Config({ accountCache: 10000, storageCache: 1000 })
const pool = new PeerPool({ config })
peers[1].idle = true
for (const p of peers) {
pool.add(p as any)
// @ts-ignore
pool.add(p)
}
assert.equal(pool.idle(), peers[1], 'correct idle peer')
assert.equal(
pool.idle((p: any) => p.id > '1'),
pool.idle((p: any) => p.id > 1),
peers[1],
'correct idle peer with filter'
)
Expand Down
3 changes: 2 additions & 1 deletion packages/client/test/service/fullethereumservice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { assert, describe, expect, it, vi } from 'vitest'
import { Chain } from '../../src/blockchain'
import { Config, SyncMode } from '../../src/config'
import { RlpxServer } from '../../src/net/server'
import { FullEthereumService } from '../../src/service/fullethereumservice'
import { Event } from '../../src/types'
import genesisJSON from '../testdata/geth-genesis/post-merge.json'

Expand Down Expand Up @@ -62,6 +61,7 @@ describe('[FullEthereumService]', async () => {
vi.mock('@ethereumjs/block')
vi.mock('../../src/net/server')
vi.mock('../../src/execution')
const { FullEthereumService } = await import('../../src/service/fullethereumservice')

it('should initialize correctly', async () => {
const config = new Config({ accountCache: 10000, storageCache: 1000 })
Expand Down Expand Up @@ -127,6 +127,7 @@ describe('[FullEthereumService]', async () => {
it('should correctly handle GetBlockHeaders', async () => {
const config = new Config({ accountCache: 10000, storageCache: 1000 })
vi.unmock('../../src/blockchain')
await import('../../src/blockchain')
const chain = await Chain.create({ config })
chain.getHeaders = () => [{ number: 1n }] as any
const service = new FullEthereumService({ config, chain })
Expand Down

0 comments on commit 6cca82c

Please sign in to comment.