Skip to content

Commit 4580b64

Browse files
ruedistedozyio
andauthored
chore(utils): Add Test for getNetConfig() (libp2p#3399)
* Add tests for getNetConfig() --------- Co-authored-by: dozyio <37986489+dozyio@users.noreply.github.com> Co-authored-by: dozyio <github@dozy.io>
1 parent 709b3fa commit 4580b64

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { multiaddr } from '@multiformats/multiaddr'
2+
import { expect } from 'aegir/chai'
3+
import { getNetConfig } from '../../src/index.ts'
4+
5+
describe('multiaddr getNetConfig', () => {
6+
it('throws on empty multiaddr', () => {
7+
expect(() => getNetConfig(multiaddr())).to.throw()
8+
})
9+
10+
it('identifies ip4 multiaddrs', () => {
11+
expect(getNetConfig(multiaddr('/ip4/169.254.35.4'))).to.deep.equal({
12+
type: 'ip4',
13+
host: '169.254.35.4'
14+
})
15+
expect(getNetConfig(multiaddr('/ip4/169.254.35.4/tcp/1000'))).to.deep.equal({
16+
type: 'ip4',
17+
host: '169.254.35.4',
18+
protocol: 'tcp',
19+
port: 1000
20+
})
21+
})
22+
23+
it('identifies ip6 multiaddrs', () => {
24+
expect(getNetConfig(multiaddr('/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095'))).to.deep.equal({
25+
type: 'ip6',
26+
host: '2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095'
27+
})
28+
expect(getNetConfig(multiaddr('/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000'))).to.deep.equal({
29+
type: 'ip6',
30+
host: '2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095',
31+
protocol: 'tcp',
32+
port: 1000
33+
})
34+
})
35+
})

0 commit comments

Comments
 (0)