11import { NotFoundError } from '@libp2p/interface'
22import { defaultLogger } from '@libp2p/logger'
3- import { peerIdFromString } from '@libp2p/peer-id'
43import { RecordType } from '@multiformats/dns'
54import { expect } from 'aegir/chai'
65import delay from 'delay'
7- import { base36 } from 'multiformats/bases/base36'
86import { base58btc } from 'multiformats/bases/base58'
97import { CID } from 'multiformats/cid'
108import * as Digest from 'multiformats/hashes/digest'
@@ -214,14 +212,14 @@ describe('dnslink', () => {
214212 expect ( result ) . to . have . nested . property ( '[0].path' , '/foobar/path/123' )
215213 } )
216214
217- it ( 'should resolve recursive dnslink -> <peerId >/<path>' , async ( ) => {
218- const peerId = peerIdFromString ( 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' )
215+ it ( 'should resolve recursive dnslink -> <Qm_PeerId >/<path>' , async ( ) => {
216+ const multihash = 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn'
219217
220218 dns . query . withArgs ( '_dnslink.foobar.baz' ) . resolves ( dnsResponse ( [ {
221219 name : 'foobar.baz.' ,
222220 TTL : 60 ,
223221 type : RecordType . TXT ,
224- data : `dnslink=/ipns/${ peerId . toString ( ) } /foobar/path/123`
222+ data : `dnslink=/ipns/${ multihash } /foobar/path/123`
225223 } ] ) )
226224
227225 const result = await name . resolve ( 'foobar.baz' )
@@ -230,18 +228,38 @@ describe('dnslink', () => {
230228 throw new Error ( 'Did not resolve entry' )
231229 }
232230
233- expect ( result ) . to . have . deep . nested . property ( '[0].value' , Digest . decode ( base58btc . decode ( 'zQmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' ) ) )
231+ expect ( result ) . to . have . deep . nested . property ( '[0].value' , Digest . decode ( base58btc . baseDecode ( multihash ) ) )
232+ expect ( result ) . to . have . nested . property ( '[0].path' , '/foobar/path/123' )
233+ } )
234+
235+ it ( 'should resolve recursive dnslink -> <12D3Koo_PeerId>/<path>' , async ( ) => {
236+ const multihash = '12D3KooWDUyFJTGJADckWJdfh2haqj6ckaXFWi1DReJ4RP8KsHg5'
237+
238+ dns . query . withArgs ( '_dnslink.foobar.baz' ) . resolves ( dnsResponse ( [ {
239+ name : 'foobar.baz.' ,
240+ TTL : 60 ,
241+ type : RecordType . TXT ,
242+ data : `dnslink=/ipns/${ multihash } /foobar/path/123`
243+ } ] ) )
244+
245+ const result = await name . resolve ( 'foobar.baz' )
246+
247+ if ( result == null ) {
248+ throw new Error ( 'Did not resolve entry' )
249+ }
250+
251+ expect ( result ) . to . have . deep . nested . property ( '[0].value' , Digest . decode ( base58btc . baseDecode ( multihash ) ) )
234252 expect ( result ) . to . have . nested . property ( '[0].path' , '/foobar/path/123' )
235253 } )
236254
237255 it ( 'should resolve recursive dnslink -> <IPNS_base36_CID>/<path>' , async ( ) => {
238- const peerId = peerIdFromString ( 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' )
239- const peerIdBase36CID = peerId . toCID ( ) . toString ( base36 )
256+ const cid = 'k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2'
257+
240258 dns . query . withArgs ( '_dnslink.foobar.baz' ) . resolves ( dnsResponse ( [ {
241259 name : 'foobar.baz.' ,
242260 TTL : 60 ,
243261 type : RecordType . TXT ,
244- data : `dnslink=/ipns/${ peerIdBase36CID } /foobar/path/123`
262+ data : `dnslink=/ipns/${ cid } /foobar/path/123`
245263 } ] ) )
246264
247265 const result = await name . resolve ( 'foobar.baz' )
@@ -250,7 +268,7 @@ describe('dnslink', () => {
250268 throw new Error ( 'Did not resolve entry' )
251269 }
252270
253- expect ( result ) . to . have . deep . nested . property ( '[0].value' , Digest . decode ( base58btc . decode ( 'zQmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' ) ) )
271+ expect ( result ) . to . have . deep . nested . property ( '[0].value' , CID . parse ( cid ) . multihash )
254272 expect ( result ) . to . have . nested . property ( '[0].path' , '/foobar/path/123' )
255273 } )
256274
0 commit comments