Skip to content

Commit

Permalink
test: fix peerId parsing for ipns records
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Nov 14, 2024
1 parent d08dacf commit a79dcb8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/gateway-conformance/src/fixtures/kubo-mgmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -97,7 +98,18 @@ export async function loadFixtures (kuboRepoDir: string): Promise<string> {
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)

Expand Down

0 comments on commit a79dcb8

Please sign in to comment.