Skip to content

peerRouting.findPeer() does not accept strings, only PeerId instances #819

@a1300

Description

@a1300
  • Version: v0.29.3
  • Platform: Linux
  • Subsystem:

Type: Bug

Severity: Low

Description: peerRouting.findPeer() does not accept string representations for PeerId, it only accepts PeerId instances

The API.md#peerroutingfindpeer says findPeer() only accepts PeerId instances

On the other hand the JSDoc type documentation findPeer() only accepts string

return {
/**
* Iterates over all peer routers in series to find the given peer.
*
* @param {string} id - The id of the peer to find
* @param {object} [options]
* @param {number} [options.timeout] - How long the query should run
* @returns {Promise<{ id: PeerId, multiaddrs: Multiaddr[] }>}
*/
findPeer: async (id, options) => { // eslint-disable-line require-await

If I understand the following test correctly, it uses findPeer() also with a string

it('should be able to find a peer', async () => {
const peerKey = 'QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSySnL'
const mockApi = nock('http://0.0.0.0:60197')
.post('/api/v0/dht/findpeer')
.query(true)
.reply(200, `{"Extra":"","ID":"some other id","Responses":null,"Type":0}\n{"Extra":"","ID":"","Responses":[{"Addrs":["/ip4/127.0.0.1/tcp/4001"],"ID":"${peerKey}"}],"Type":2}\n`, [
'Content-Type', 'application/json',
'X-Chunked-Output', '1'
])
const peer = await node.peerRouting.findPeer(peerKey)
expect(peer.id).to.equal(peerKey)
expect(mockApi.isDone()).to.equal(true)
})

Steps to reproduce the error:

git clone https://gist.github.com/a1300/79357f742a6e459a9a801e60bd2840ef libp2p-peerRouting-no-string
cd libp2p-peerRouting-no-string
npm install
node index

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions