From 2759af03e493ce8f5df45bc4abf1b1c2b1abf1d2 Mon Sep 17 00:00:00 2001 From: acolytec3 <17355484+acolytec3@users.noreply.github.com> Date: Wed, 7 Aug 2024 17:56:06 -0400 Subject: [PATCH] add test --- packages/client/src/rpc/modules/admin.ts | 3 +- packages/client/test/rpc/admin/peers.spec.ts | 38 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 packages/client/test/rpc/admin/peers.spec.ts diff --git a/packages/client/src/rpc/modules/admin.ts b/packages/client/src/rpc/modules/admin.ts index f967676dd3..5b94d3b658 100644 --- a/packages/client/src/rpc/modules/admin.ts +++ b/packages/client/src/rpc/modules/admin.ts @@ -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 { diff --git a/packages/client/test/rpc/admin/peers.spec.ts b/packages/client/test/rpc/admin/peers.spec.ts new file mode 100644 index 0000000000..c7bf6f40f8 --- /dev/null +++ b/packages/client/test/rpc/admin/peers.spec.ts @@ -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') + }) +})