From 62a758334ca77b9c0eab7ef8b31a8ea416d58dc4 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 12 Sep 2024 13:26:15 +0100 Subject: [PATCH] chore: fix tests --- src/pubsub/subscribe.ts | 3 ++- test/interface-tests.spec.ts | 2 +- test/interface-tests/src/name/publish.ts | 10 ++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/pubsub/subscribe.ts b/src/pubsub/subscribe.ts index 3baf71ea3..5487cdbde 100644 --- a/src/pubsub/subscribe.ts +++ b/src/pubsub/subscribe.ts @@ -105,7 +105,8 @@ async function readMessages (response: ExtendedResponse, { onMessage, onEnd, onE data: rpcToBytes(msg.data), sequenceNumber: rpcToBigInt(msg.seqno), topic: rpcToText(msg.topicIDs[0]), - key: publicKeyFromProtobuf(rpcToBytes(msg.key ?? 'u')), + // @ts-expect-error kubo does not supply the key + key: msg.key != null ? publicKeyFromProtobuf(rpcToBytes(msg.key ?? 'u')) : undefined, signature: rpcToBytes(msg.signature ?? 'u') }) } else { diff --git a/test/interface-tests.spec.ts b/test/interface-tests.spec.ts index 1d6cb57da..8ae211c78 100644 --- a/test/interface-tests.spec.ts +++ b/test/interface-tests.spec.ts @@ -267,7 +267,7 @@ describe('kubo-rpc-client tests against kubo', function () { */ const commonFactory = factory({ type: 'kubo', - bin: path(), + bin: typeof path === 'function' ? path() : undefined, test: true }) describe('kubo RPC client interface tests', function () { diff --git a/test/interface-tests/src/name/publish.ts b/test/interface-tests/src/name/publish.ts index 1aed28859..d9df7947a 100644 --- a/test/interface-tests/src/name/publish.ts +++ b/test/interface-tests/src/name/publish.ts @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { peerIdFromString } from '@libp2p/peer-id' +import { peerIdFromCID, peerIdFromString } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import last from 'it-last' import { nanoid } from 'nanoid' @@ -10,6 +10,8 @@ import { fixture } from './utils.js' import type { KuboRPCClient } from '../../../../src/index.js' import type { PeerId } from '@libp2p/interface' import type { Factory, KuboNode } from 'ipfsd-ctl' +import { CID } from 'multiformats/cid' +import { base36 } from 'multiformats/bases/base36' export function testPublish (factory: Factory, options: MochaConfig): void { const describe = getDescribe(options) @@ -53,7 +55,7 @@ export function testPublish (factory: Factory, options: MochaConfig): const res = await ipfs.name.publish(value, { allowOffline: true }) expect(res).to.exist() - expect(peerIdFromString(res.name).toString()).to.equal(peerIdFromString(self.id).toString()) + expect(peerIdFromCID(CID.parse(res.name, base36)).toString()).to.equal(peerIdFromCID(CID.parse(self.id, base36)).toString()) expect(res.value).to.equal(`/ipfs/${value}`) }) @@ -84,7 +86,7 @@ export function testPublish (factory: Factory, options: MochaConfig): const res = await ipfs.name.publish(value, options) expect(res).to.exist() - expect(peerIdFromString(res.name).toString()).to.equal(peerIdFromString(self.id).toString()) + expect(peerIdFromCID(CID.parse(res.name, base36)).toString()).to.equal(peerIdFromCID(CID.parse(self.id, base36)).toString()) expect(res.value).to.equal(`/ipfs/${value}`) }) @@ -104,7 +106,7 @@ export function testPublish (factory: Factory, options: MochaConfig): const res = await ipfs.name.publish(value, options) expect(res).to.exist() - expect(peerIdFromString(res.name).toString()).to.equal(peerIdFromString(key.id).toString()) + expect(peerIdFromCID(CID.parse(res.name, base36)).toString()).to.equal(peerIdFromCID(CID.parse(key.id, base36)).toString()) expect(res.value).to.equal(`/ipfs/${value}`) }) })