-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add default port for protocol #3
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ const toMultiaddr = require('./') | |
|
||
test('should convert URIs to multiaddrs', (t) => { | ||
const data = [ | ||
['/ip4/127.0.0.1/http', 'http://127.0.0.1'], | ||
['/ip6/fc00::/http', 'http://[fc00::]'], | ||
['/ip4/127.0.0.1/tcp/80/http', 'http://127.0.0.1'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we should keep tests for both versions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean |
||
['/ip6/fc00::/tcp/80/http', 'http://[fc00::]'], | ||
['/ip4/0.0.7.6/tcp/1234', 'tcp://0.0.7.6:1234'], | ||
['/ip4/0.0.7.6/tcp/1234/http', 'http://0.0.7.6:1234'], | ||
['/ip4/0.0.7.6/tcp/1234/https', 'https://0.0.7.6:1234'], | ||
|
@@ -14,17 +14,22 @@ test('should convert URIs to multiaddrs', (t) => { | |
['/dns4/protocol.ai/tcp/80', 'tcp://protocol.ai:80'], | ||
['/dns4/protocol.ai/tcp/80/http', 'http://protocol.ai:80'], | ||
['/dns4/protocol.ai/tcp/80/https', 'https://protocol.ai:80'], | ||
['/dns4/ipfs.io/ws', 'ws://ipfs.io'], | ||
['/dns4/ipfs.io/http', 'http://ipfs.io'], | ||
['/dns4/ipfs.io/https', 'https://ipfs.io'], | ||
['/dns4/ipfs.io/tcp/80/ws', 'ws://ipfs.io'], | ||
['/dns4/ipfs.io/tcp/443/wss', 'wss://ipfs.io'], | ||
['/dns4/ipfs.io/tcp/80/http', 'http://ipfs.io'], | ||
['/dns4/ipfs.io/tcp/443/https', 'https://ipfs.io'], | ||
['/ip4/1.2.3.4/tcp/3456/ws', 'ws://1.2.3.4:3456'], | ||
['/ip4/1.2.3.4/tcp/3456/wss', 'wss://1.2.3.4:3456'], | ||
['/ip6/::/tcp/0/ws', 'ws://[::]:0'], | ||
['/dns4/ipfs.io/wss', 'wss://ipfs.io'], | ||
['/ip4/1.2.3.4/tcp/3456/wss', 'wss://1.2.3.4:3456'], | ||
['/ip6/::/tcp/0/wss', 'wss://[::]:0'] | ||
] | ||
|
||
data.forEach(d => t.is(toMultiaddr(d[1]).toString(), d[0], `Converts ${d[1]} to ${d[0]}`)) | ||
data.forEach(d => { | ||
const input = d[1] | ||
const expected = d[0] | ||
const output = toMultiaddr(input).toString() | ||
t.is(output, expected, `Converts ${input} to ${expected}`) | ||
}) | ||
}) | ||
|
||
test('should use the defaultDnsType where provided', (t) => { | ||
|
@@ -37,6 +42,15 @@ test('should use the defaultDnsType where provided', (t) => { | |
data.forEach(d => t.is(toMultiaddr(d[1], d[2]).toString(), d[0], `Converts ${d[1]} to ${d[0]} with opts ${d[2]}`)) | ||
}) | ||
|
||
test('should throw for unsupported protocol', (t) => { | ||
t.throws(() => toMultiaddr('quic://')) | ||
test('should throw for on invalid url', (t) => { | ||
t.throws(() => { | ||
toMultiaddr('whoosh.fast') | ||
}, /Invalid URL/) | ||
}) | ||
|
||
test('should throw for unknown protocol', (t) => { | ||
t.throws(() => { | ||
// NOTE: `data` is a valid uri protocol but isn't a valid multiaddr protocol yet | ||
toMultiaddr('data:image/svg+xml;base64,test') | ||
}, 'no protocol with name: data') | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why tho 🤔 For
ip4
(1 line above) we default to localhost, shouldn't we do the same here? (::1
)I know this is a nit, but there is a huge difference if a beginner just copies&pastes
0.0.0.0:5001
vs127.0.0.1:5001
without thinking, so I always try to avoid "listen on all interfaces" in examples :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍