Skip to content
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

feat!: test different transports #149

Merged
merged 1 commit into from
Apr 29, 2024
Merged
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
23 changes: 18 additions & 5 deletions src/connect.ts → src/connect/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import { expect } from 'aegir/chai'
import { runTests } from './utils/test-matrix.js'
import type { Daemon, SpawnOptions, DaemonFactory } from './index.js'
import type { Daemon, DaemonFactory, NodeType, SpawnOptions, TransportType } from '../index.js'

export function connectTests (factory: DaemonFactory): void {
runTests('connect', runConnectTests, factory)
const nodeTypes: NodeType[] = ['js', 'go']
const transportTypes: TransportType[] = ['tcp', 'webtransport']

for (const typeA of nodeTypes) {
for (const typeB of nodeTypes) {
transportTypes.forEach(transport => {
runConnectTests(
transport,
factory,
{ type: typeA, transport },
{ type: typeB, transport }
)
})
}
}
}

function runConnectTests (name: string, factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
describe(name, () => {
describe(`connection.${name}`, () => {
let daemonA: Daemon
let daemonB: Daemon

Expand All @@ -28,7 +41,7 @@ function runConnectTests (name: string, factory: DaemonFactory, optionsA: SpawnO
)
})

it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
it(`${optionsA.type} peer to ${optionsB.type} peer over ${name}`, async function () {
this.timeout(10 * 1000)

const identify1 = await daemonA.client.identify()
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* For an example, see the js-libp2p interop test runner.
*/

import { connectTests } from './connect.js'
import { connectTests } from './connect/index.js'
import { dhtTests } from './dht/index.js'
import { pubsubTests } from './pubsub/index.js'
import { relayTests } from './relay/index.js'
Expand All @@ -59,6 +59,7 @@ export type PeerIdType = 'rsa' | 'ed25519' | 'secp256k1'
export type PubSubRouter = 'gossipsub' | 'floodsub'
export type Muxer = 'mplex' | 'yamux'
export type Encryption = 'noise' | 'tls'
export type TransportType = 'tcp' | 'webtransport'

export interface SpawnOptions {
type: NodeType
Expand All @@ -72,6 +73,7 @@ export interface SpawnOptions {
// the node will not listen on any
// addresses if true
noListen?: boolean
transport?: TransportType
}

export interface DaemonFactory {
Expand Down
Loading