From a79dcb8e4cd11482bba7fe13de294a785ae59692 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:14:36 -0600 Subject: [PATCH] test: fix peerId parsing for ipns records --- .../src/fixtures/kubo-mgmt.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/gateway-conformance/src/fixtures/kubo-mgmt.ts b/packages/gateway-conformance/src/fixtures/kubo-mgmt.ts index 7f0ac9f..f3294dd 100644 --- a/packages/gateway-conformance/src/fixtures/kubo-mgmt.ts +++ b/packages/gateway-conformance/src/fixtures/kubo-mgmt.ts @@ -12,12 +12,13 @@ import { dirname, relative, posix, basename } from 'node:path' import { fileURLToPath } from 'node:url' import { Record as DhtRecord } from '@libp2p/kad-dht' import { logger } from '@libp2p/logger' -import { peerIdFromString } from '@libp2p/peer-id' +import { peerIdFromCID, peerIdFromString } from '@libp2p/peer-id' import { $ } from 'execa' import fg from 'fast-glob' import { Key } from 'interface-datastore' import { multihashToIPNSRoutingKey } from 'ipns' import { path } from 'kubo' +import { CID } from 'multiformats/cid' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { GWC_IMAGE } from '../constants.js' import { getIpnsRecordDatastore } from './ipns-record-datastore.js' @@ -97,7 +98,18 @@ export async function loadFixtures (kuboRepoDir: string): Promise { const peerIdString = basename(fsIpnsRecord, '.ipns-record').split('_')[0] const relativePath = relative(GWC_FIXTURES_PATH, fsIpnsRecord) log('Loading *.ipns-record fixture %s', relativePath) - const key = peerIdFromString(peerIdString) + let key + if (peerIdString.startsWith('k51')) { + /** + * libp2p CID peerID + * + * @see https://github.com/libp2p/js-libp2p/blob/2feaeddb40712a5d58aee158021a10b9b9bbf660/doc/migrations/v1.0.0-v2.0.0.md?plain=1#L255 + */ + const cid = CID.parse(peerIdString) + key = peerIdFromCID(cid) + } else { + key = peerIdFromString(peerIdString) + } const customRoutingKey = multihashToIPNSRoutingKey(key.toMultihash()) const dhtKey = new Key('/dht/record/' + uint8ArrayToString(customRoutingKey, 'base32'), false)