Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
2color committed Jan 22, 2025
1 parent 6f9076c commit d7d4635
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/ipns/test/resolve-dnslink.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { peerIdFromPrivateKey } from '@libp2p/peer-id'
import { RecordType } from '@multiformats/dns'
import { expect } from 'aegir/chai'
import { MemoryDatastore } from 'datastore-core'
import { base36 } from 'multiformats/bases/base36'
import { CID } from 'multiformats/cid'
import { stubInterface } from 'sinon-ts'
import { ipns } from '../src/index.js'
Expand Down Expand Up @@ -172,6 +173,30 @@ describe('resolveDNSLink', () => {
expect(result.path).to.equal('foobar/path/123')
})

it('should resolve recursive dnslink -> <IPNS_base36_CID>/<path>', async () => {
const cid = CID.parse('QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn')
const key = await generateKeyPair('Ed25519')
const peerId = peerIdFromPrivateKey(key)
const peerIdBase36CID = peerId.toCID().toString(base36)
dns.query.withArgs('_dnslink.foobar.baz').resolves(dnsResponse([{
name: 'foobar.baz.',
TTL: 60,
type: RecordType.TXT,
data: `dnslink=/ipns/${peerIdBase36CID}/foobar/path/123`
}]))

await name.publish(key, cid)

const result = await name.resolveDNSLink('foobar.baz')

if (result == null) {
throw new Error('Did not resolve entry')
}

Check warning on line 194 in packages/ipns/test/resolve-dnslink.spec.ts

View check run for this annotation

Codecov / codecov/patch

packages/ipns/test/resolve-dnslink.spec.ts#L193-L194

Added lines #L193 - L194 were not covered by tests

expect(result.cid.toString()).to.equal(cid.toV1().toString())
expect(result.path).to.equal('foobar/path/123')
})

it('should follow CNAMES to delegated DNSLink domains', async () => {
const cid = CID.parse('bafybeifcaqowoyito3qvsmbwbiugsu4umlxn4ehu223hvtubbfvwyuxjoe')
const key = await generateKeyPair('Ed25519')
Expand Down

0 comments on commit d7d4635

Please sign in to comment.