diff --git a/packages/libp2p/src/index.ts b/packages/libp2p/src/index.ts index adb9fe8b35..72fa49b1f8 100644 --- a/packages/libp2p/src/index.ts +++ b/packages/libp2p/src/index.ts @@ -76,7 +76,7 @@ export interface Libp2pInit /** * An array that must include at least 1 compliant transport */ - transports: Array<(components: Components) => Transport> + transports?: Array<(components: Components) => Transport> streamMuxers?: Array<(components: Components) => StreamMuxerFactory> connectionEncryption?: Array<(components: Components) => ConnectionEncrypter> peerDiscovery?: Array<(components: Components) => PeerDiscovery> @@ -150,7 +150,7 @@ export type Libp2pOptions> = Recu * const libp2p = await createLibp2p(options) * ``` */ -export async function createLibp2p }> (options: Libp2pOptions): Promise> { +export async function createLibp2p }> (options: Libp2pOptions = {}): Promise> { const node = await createLibp2pNode(options) if (options.start !== false) { diff --git a/packages/libp2p/src/libp2p.ts b/packages/libp2p/src/libp2p.ts index b1f0e385a0..c38109909c 100644 --- a/packages/libp2p/src/libp2p.ts +++ b/packages/libp2p/src/libp2p.ts @@ -145,7 +145,7 @@ export class Libp2pNode> extends }) // Transport modules - init.transports.forEach((fn, index) => { + init.transports?.forEach((fn, index) => { this.components.transportManager.add(this.configureComponent(`transport-${index}`, fn(this.components))) }) @@ -385,7 +385,7 @@ export class Libp2pNode> extends * Returns a new Libp2pNode instance - this exposes more of the internals than the * libp2p interface and is useful for testing and debugging. */ -export async function createLibp2pNode > (options: Libp2pOptions): Promise> { +export async function createLibp2pNode > (options: Libp2pOptions = {}): Promise> { options.peerId ??= await createEd25519PeerId() return new Libp2pNode(validateConfig(options)) diff --git a/packages/libp2p/test/core/core.spec.ts b/packages/libp2p/test/core/core.spec.ts new file mode 100644 index 0000000000..1bb02fcfc8 --- /dev/null +++ b/packages/libp2p/test/core/core.spec.ts @@ -0,0 +1,19 @@ +/* eslint-env mocha */ + +import { expect } from 'aegir/chai' +import { createLibp2p } from '../../src/index.js' +import type { Libp2p } from '@libp2p/interface' + +describe('core', () => { + let libp2p: Libp2p + + after(async () => { + await libp2p.stop() + }) + + it('should start a minimal node', async () => { + libp2p = await createLibp2p({}) + + expect(libp2p).to.have.property('status', 'started') + }) +})