@@ -4,7 +4,7 @@ import type { MultiaddrFromUriOpts } from '../src/index.js'
4
4
5
5
describe ( 'uri-to-multiaddr' , ( ) => {
6
6
it ( 'should convert URIs to multiaddrs' , ( ) => {
7
- const data = [
7
+ const data : Array < [ string , string , MultiaddrFromUriOpts ? ] > = [
8
8
[ '/ip4/127.0.0.1/tcp/80/http' , 'http://127.0.0.1' ] ,
9
9
[ '/ip6/fc00::/tcp/80/http' , 'http://[fc00::]' ] ,
10
10
[ '/ip4/0.0.7.6/tcp/1234' , 'tcp://0.0.7.6:1234' ] ,
@@ -13,28 +13,128 @@ describe('uri-to-multiaddr', () => {
13
13
[ '/ip6/::/tcp/0' , 'tcp://[::]:0' ] ,
14
14
[ '/ip4/0.0.7.6/udp/1234' , 'udp://0.0.7.6:1234' ] ,
15
15
[ '/ip6/::/udp/0' , 'udp://[::]:0' ] ,
16
- [ '/dns4/protocol.ai/tcp/80' , 'tcp://protocol.ai:80' ] ,
17
- [ '/dns4/protocol.ai/tcp/80/http' , 'http://protocol.ai:80' ] ,
18
- [ '/dns4/protocol.ai/tcp/80/https' , 'https://protocol.ai:80' ] ,
19
- [ '/dns4/ipfs.io/tcp/80/ws' , 'ws://ipfs.io' ] ,
20
- [ '/dns4/ipfs.io/tcp/443/wss' , 'wss://ipfs.io' ] ,
21
- [ '/dns4/ipfs.io/tcp/80/http' , 'http://ipfs.io' ] ,
22
- [ '/dns4/ipfs.io/tcp/443/https' , 'https://ipfs.io' ] ,
23
- [ '/dns4/ipfs.io/tcp/443/https' , 'https://ipfs.io:443' ] ,
24
- [ '/dns4/ipfs.io/tcp/443' , 'tcp://ipfs.io:443' ] ,
25
- [ '/dns4/ipfs.io/tcp/80' , 'tcp://ipfs.io:80' ] ,
16
+ [ '/dns/protocol.ai/tcp/80' , 'tcp://protocol.ai:80' ] ,
17
+ [ '/dns4/protocol.ai/tcp/80' , 'tcp://protocol.ai:80' , {
18
+ defaultDnsType : 'dns4'
19
+ } ] ,
20
+ [ '/dns6/protocol.ai/tcp/80' , 'tcp://protocol.ai:80' , {
21
+ defaultDnsType : 'dns6'
22
+ } ] ,
23
+ [ '/dnsaddr/protocol.ai/tcp/80' , 'tcp://protocol.ai:80' , {
24
+ defaultDnsType : 'dnsaddr'
25
+ } ] ,
26
+ [ '/dns/protocol.ai/tcp/80/http' , 'http://protocol.ai:80' ] ,
27
+ [ '/dns4/protocol.ai/tcp/80/http' , 'http://protocol.ai:80' , {
28
+ defaultDnsType : 'dns4'
29
+ } ] ,
30
+ [ '/dns6/protocol.ai/tcp/80/http' , 'http://protocol.ai:80' , {
31
+ defaultDnsType : 'dns6'
32
+ } ] ,
33
+ [ '/dnsaddr/protocol.ai/tcp/80/http' , 'http://protocol.ai:80' , {
34
+ defaultDnsType : 'dnsaddr'
35
+ } ] ,
36
+ [ '/dns/protocol.ai/tcp/80/https' , 'https://protocol.ai:80' ] ,
37
+ [ '/dns4/protocol.ai/tcp/80/https' , 'https://protocol.ai:80' , {
38
+ defaultDnsType : 'dns4'
39
+ } ] ,
40
+ [ '/dns6/protocol.ai/tcp/80/https' , 'https://protocol.ai:80' , {
41
+ defaultDnsType : 'dns6'
42
+ } ] ,
43
+ [ '/dnsaddr/protocol.ai/tcp/80/https' , 'https://protocol.ai:80' , {
44
+ defaultDnsType : 'dnsaddr'
45
+ } ] ,
46
+ [ '/dns/ipfs.io/tcp/80/ws' , 'ws://ipfs.io' ] ,
47
+ [ '/dns4/ipfs.io/tcp/80/ws' , 'ws://ipfs.io' , {
48
+ defaultDnsType : 'dns4'
49
+ } ] ,
50
+ [ '/dns6/ipfs.io/tcp/80/ws' , 'ws://ipfs.io' , {
51
+ defaultDnsType : 'dns6'
52
+ } ] ,
53
+ [ '/dnsaddr/ipfs.io/tcp/80/ws' , 'ws://ipfs.io' , {
54
+ defaultDnsType : 'dnsaddr'
55
+ } ] ,
56
+ [ '/dns/ipfs.io/tcp/443/wss' , 'wss://ipfs.io' ] ,
57
+ [ '/dns4/ipfs.io/tcp/443/wss' , 'wss://ipfs.io' , {
58
+ defaultDnsType : 'dns4'
59
+ } ] ,
60
+ [ '/dns6/ipfs.io/tcp/443/wss' , 'wss://ipfs.io' , {
61
+ defaultDnsType : 'dns6'
62
+ } ] ,
63
+ [ '/dnsaddr/ipfs.io/tcp/443/wss' , 'wss://ipfs.io' , {
64
+ defaultDnsType : 'dnsaddr'
65
+ } ] ,
66
+ [ '/dns/ipfs.io/tcp/80/http' , 'http://ipfs.io' ] ,
67
+ [ '/dns4/ipfs.io/tcp/80/http' , 'http://ipfs.io' , {
68
+ defaultDnsType : 'dns4'
69
+ } ] ,
70
+ [ '/dns6/ipfs.io/tcp/80/http' , 'http://ipfs.io' , {
71
+ defaultDnsType : 'dns6'
72
+ } ] ,
73
+ [ '/dnsaddr/ipfs.io/tcp/80/http' , 'http://ipfs.io' , {
74
+ defaultDnsType : 'dnsaddr'
75
+ } ] ,
76
+ [ '/dns/ipfs.io/tcp/443/https' , 'https://ipfs.io' ] ,
77
+ [ '/dns4/ipfs.io/tcp/443/https' , 'https://ipfs.io' , {
78
+ defaultDnsType : 'dns4'
79
+ } ] ,
80
+ [ '/dns6/ipfs.io/tcp/443/https' , 'https://ipfs.io' , {
81
+ defaultDnsType : 'dns6'
82
+ } ] ,
83
+ [ '/dnsaddr/ipfs.io/tcp/443/https' , 'https://ipfs.io' , {
84
+ defaultDnsType : 'dnsaddr'
85
+ } ] ,
86
+ [ '/dns/ipfs.io/tcp/443/https' , 'https://ipfs.io:443' ] ,
87
+ [ '/dns4/ipfs.io/tcp/443/https' , 'https://ipfs.io:443' , {
88
+ defaultDnsType : 'dns4'
89
+ } ] ,
90
+ [ '/dns6/ipfs.io/tcp/443/https' , 'https://ipfs.io:443' , {
91
+ defaultDnsType : 'dns6'
92
+ } ] ,
93
+ [ '/dnsaddr/ipfs.io/tcp/443/https' , 'https://ipfs.io:443' , {
94
+ defaultDnsType : 'dnsaddr'
95
+ } ] ,
96
+ [ '/dns/ipfs.io/tcp/443' , 'tcp://ipfs.io:443' ] ,
97
+ [ '/dns4/ipfs.io/tcp/443' , 'tcp://ipfs.io:443' , {
98
+ defaultDnsType : 'dns4'
99
+ } ] ,
100
+ [ '/dns6/ipfs.io/tcp/443' , 'tcp://ipfs.io:443' , {
101
+ defaultDnsType : 'dns6'
102
+ } ] ,
103
+ [ '/dnsaddr/ipfs.io/tcp/443' , 'tcp://ipfs.io:443' , {
104
+ defaultDnsType : 'dnsaddr'
105
+ } ] ,
106
+ [ '/dns/ipfs.io/tcp/80' , 'tcp://ipfs.io:80' ] ,
107
+ [ '/dns4/ipfs.io/tcp/80' , 'tcp://ipfs.io:80' , {
108
+ defaultDnsType : 'dns4'
109
+ } ] ,
110
+ [ '/dns6/ipfs.io/tcp/80' , 'tcp://ipfs.io:80' , {
111
+ defaultDnsType : 'dns6'
112
+ } ] ,
113
+ [ '/dnsaddr/ipfs.io/tcp/80' , 'tcp://ipfs.io:80' , {
114
+ defaultDnsType : 'dnsaddr'
115
+ } ] ,
26
116
[ '/ip4/1.2.3.4/tcp/3456/ws' , 'ws://1.2.3.4:3456' ] ,
27
117
[ '/ip4/1.2.3.4/tcp/3456/wss' , 'wss://1.2.3.4:3456' ] ,
28
118
[ '/ip6/::/tcp/0/ws' , 'ws://[::]:0' ] ,
29
119
[ '/ip4/1.2.3.4/tcp/3456/wss' , 'wss://1.2.3.4:3456' ] ,
30
120
[ '/ip6/::/tcp/0/wss' , 'wss://[::]:0' ] ,
31
- [ '/dns4/example.com/tcp/443/wss/http-path/foo' , 'wss://example.com:443/foo' ]
121
+ [ '/dns/example.com/tcp/443/wss/http-path/foo' , 'wss://example.com:443/foo' ] ,
122
+ [ '/dns4/example.com/tcp/443/wss/http-path/foo' , 'wss://example.com:443/foo' , {
123
+ defaultDnsType : 'dns4'
124
+ } ] ,
125
+ [ '/dns6/example.com/tcp/443/wss/http-path/foo' , 'wss://example.com:443/foo' , {
126
+ defaultDnsType : 'dns6'
127
+ } ] ,
128
+ [ '/dnsaddr/example.com/tcp/443/wss/http-path/foo' , 'wss://example.com:443/foo' , {
129
+ defaultDnsType : 'dnsaddr'
130
+ } ]
32
131
]
33
132
34
133
data . forEach ( d => {
35
134
const input = d [ 1 ]
36
135
const expected = d [ 0 ]
37
- const output = uriToMultiaddr ( input ) . toString ( )
136
+ const opts = d [ 2 ]
137
+ const output = uriToMultiaddr ( input , opts ) . toString ( )
38
138
expect ( output ) . to . equal ( expected , `Converts ${ input } to ${ expected } ` )
39
139
} )
40
140
} )
0 commit comments