Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 32 additions & 29 deletions test/compliance.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import transportCompliance from '@libp2p/interface-compliance-tests/transport'
import { QUICV1 } from '@multiformats/multiaddr-matcher'
import { quic } from '../src/index.js'
import { hostSupportsIpv6 } from './util.ts'

describe('Interface compliance tests (IPv4)', () => {
transportCompliance({
Expand Down Expand Up @@ -33,36 +34,38 @@ describe('Interface compliance tests (IPv4)', () => {
})
})

// IPv6 isn't always available in CI
if (!process.env.CI) {
describe('Interface compliance tests (IPv6)', function () {
transportCompliance({
async setup () {
const dialer = {
transports: [
quic()
],
connectionMonitor: {
enabled: false
}
describe('Interface compliance tests (IPv6)', function () {
if (!hostSupportsIpv6()) {
it.skip('Host does not support IPv6', () => {})
return
}

transportCompliance({
async setup () {
const dialer = {
transports: [
quic()
],
connectionMonitor: {
enabled: false
}
}

return {
dialer,
listener: {
addresses: {
listen: [
'/ip6/::/udp/0/quic-v1',
'/ip6/::/udp/0/quic-v1'
]
},
...dialer
return {
dialer,
listener: {
addresses: {
listen: [
'/ip6/::/udp/0/quic-v1',
'/ip6/::/udp/0/quic-v1'
]
},
dialMultiaddrMatcher: QUICV1,
listenMultiaddrMatcher: QUICV1
}
},
async teardown () {}
})
...dialer
},
dialMultiaddrMatcher: QUICV1,
listenMultiaddrMatcher: QUICV1
}
},
async teardown () {}
})
}
})
18 changes: 18 additions & 0 deletions test/util.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import { generateKeyPair } from '@libp2p/crypto/keys'
import { defaultLogger } from '@libp2p/logger'
import type { QuicComponents } from '../src/index.js'
import { isIPv6 } from '@chainsafe/is-ip'
import os from 'node:os'

export async function createComponents (): Promise<QuicComponents> {
return {
privateKey: await generateKeyPair('Ed25519'),
logger: defaultLogger()
}
}

export function hostSupportsIpv6 (): boolean {
for (const interfaces of Object.values(os.networkInterfaces())) {
if (interfaces == null) {
continue
}

for (const info of interfaces) {
if (isIPv6(info.address)) {
return true
}
}
}

return false
}
Loading