Skip to content

Commit

Permalink
test: refactor tests + updated config (libp2p#1573)
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Jul 5, 2023
1 parent df1ba0e commit f86432a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/libp2p/src/connection-manager/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const validateConnectionManagerConfig = (opts: ConnectionManagerInit): Ob
inboundUpgradeTimeout: number().integer().default(INBOUND_UPGRADE_TIMEOUT),
allow: array().of(string()).test('is multiaddr', validateMultiaddr).optional(),
deny: array().of(string()).test('is multiaddr', validateMultiaddr).optional(),
inboundConnectionThreshold: number().max(opts?.maxConnections ?? MAX_CONNECTIONS, `inboundConnectionThreshold must be less than the max connections limit: ${opts?.maxConnections}`).integer().default(INBOUND_CONNECTION_THRESHOLD),
maxIncomingPendingConnections: number().integer().max(opts?.maxConnections ?? MAX_CONNECTIONS, `maxIncomingPendingConnections must be less than the max connections limit: ${opts?.maxConnections}`).default(MAX_INCOMING_PENDING_CONNECTIONS)
inboundConnectionThreshold: number().max(opts?.maxConnections ?? MAX_CONNECTIONS, `inboundConnectionThreshold must be less than the max connections limit: ${opts?.inboundConnectionThreshold}`).integer().default(INBOUND_CONNECTION_THRESHOLD),
maxIncomingPendingConnections: number().integer().max(opts?.maxConnections ?? MAX_CONNECTIONS, `maxIncomingPendingConnections must be less than the max connections limit: ${opts?.maxIncomingPendingConnections}`).default(MAX_INCOMING_PENDING_CONNECTIONS)
})
}
4 changes: 2 additions & 2 deletions packages/libp2p/src/fetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class DefaultFetchService implements Startable, FetchService {
constructor (components: FetchServiceComponents, init: FetchServiceInit) {
this.started = false
this.components = components
this.protocol = `/${init.protocolPrefix ?? 'libp2p'}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`
this.protocol = `/${init.protocolPrefix}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`
this.lookupFunctions = new Map() // Maps key prefix to value lookup function
this.handleMessage = this.handleMessage.bind(this)
this.init = init
Expand Down Expand Up @@ -311,7 +311,7 @@ class DefaultFetchService implements Startable, FetchService {

export function fetchService (init: FetchServiceInit = {}): (components: FetchServiceComponents) => FetchService {
const validatedConfig = object({
protocolPrefix: string().default('ipfs'),
protocolPrefix: string().default('libp2p'),
timeout: number().integer().default(TIMEOUT),
maxInboundStreams: number().integer().min(0).default(MAX_INBOUND_STREAMS),
maxOutboundStreams: number().integer().min(0).default(MAX_OUTBOUND_STREAMS)
Expand Down
3 changes: 2 additions & 1 deletion packages/libp2p/test/configuration/protocol-prefix.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ describe('Protocol prefix is configurable', () => {
'/ipfs/id/1.0.0',
'/ipfs/id/push/1.0.0',
'/ipfs/ping/1.0.0',
'/libp2p/fetch/0.0.1'
'/libp2p/fetch/0.0.1',
'/libp2p/circuit/relay/0.2.0/stop'
])
})
})
4 changes: 3 additions & 1 deletion packages/libp2p/test/connection-manager/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ describe('libp2p.connections', () => {
},
connectionManager: {
minConnections,
maxConnections: 1
maxConnections: 1,
inboundConnectionThreshold: 1,
maxIncomingPendingConnections: 1
}
}
})
Expand Down
5 changes: 5 additions & 0 deletions packages/libp2p/test/ping/ping.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { pingService, type PingService } from '../../src/ping/index.js'
import { createBaseOptions } from '../fixtures/base-options.js'
import { createNode, populateAddressBooks } from '../fixtures/creators/peer.js'
import type { Libp2p } from '@libp2p/interface'
import { identifyService } from '../../src/identify/index.js'

describe('ping', () => {
let nodes: Array<Libp2p<{ ping: PingService }>>
Expand All @@ -18,20 +19,23 @@ describe('ping', () => {
createNode({
config: createBaseOptions({
services: {
identify: identifyService(),
ping: pingService()
}
})
}),
createNode({
config: createBaseOptions({
services: {
identify: identifyService(),
ping: pingService()
}
})
}),
createNode({
config: createBaseOptions({
services: {
identify: identifyService(),
ping: pingService()
}
})
Expand Down Expand Up @@ -104,6 +108,7 @@ describe('ping', () => {
const client = await createNode({
config: createBaseOptions({
services: {
identify: identifyService(),
ping: pingService({
// Allow two outbound ping streams.
// It is not allowed by the spec, but this test needs to open two concurrent streams.
Expand Down
3 changes: 1 addition & 2 deletions packages/transport-webrtc/.aegir.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/** @type {import('aegir').PartialOptions} */
export default {
build: {
Expand Down Expand Up @@ -35,7 +34,7 @@ export default {
services: {
relay: circuitRelayServer({
reservations: {
maxReservations: Infinity
maxReservations: 10000
}
}),
identify: identifyService()
Expand Down

0 comments on commit f86432a

Please sign in to comment.