Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Aug 7, 2024
1 parent 2484722 commit 2759af0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/client/src/rpc/modules/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export class Admin {
* @returns an array of objects containing information about peers (including id, eth protocol versions supported, client name, etc.)
*/
async peers() {
const peers = this._client.service('eth')?.pool.peers as RlpxPeer[]
const peers = this._client.services.filter((serv) => serv.name === 'eth')[0]?.pool
.peers as RlpxPeer[]

return peers?.map((peer) => {
return {
Expand Down
38 changes: 38 additions & 0 deletions packages/client/test/rpc/admin/peers.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { randomBytes } from 'crypto'
import { assert, describe, it } from 'vitest'

import { createClient, createManager, getRpcClient, startRPC } from '../helpers.js'

const method = 'admin_peers'

describe(method, () => {
it('works', async () => {
const manager = createManager(await createClient({ opened: true, noPeers: true }))
const rpc = getRpcClient(startRPC(manager.getMethods()))

console.log(manager['_client'].services[0].pool)
//@ts-ignore
manager['_client'].services[0].pool.peers = [
{
id: 'abcd',
eth: {
versions: ['68'],
status: {
td: 1n,
bestHash: randomBytes(32),
},
},
rlpxPeer: {
_hello: {
clientId: 'fakeClient',
},
},
address: '127.0.0.1:8545',
},
]
const res = await rpc.request(method, [])
const { result } = res
console.log(res)
assert.notEqual(result, undefined, 'admin_peers returns a value')
})
})

0 comments on commit 2759af0

Please sign in to comment.