diff --git a/packages/interface-compliance-tests/src/transport/dial-test.ts b/packages/interface-compliance-tests/src/transport/dial-test.ts index 34286e98a6..942c74771b 100644 --- a/packages/interface-compliance-tests/src/transport/dial-test.ts +++ b/packages/interface-compliance-tests/src/transport/dial-test.ts @@ -1,4 +1,4 @@ -import { AbortError, TypedEventEmitter } from '@libp2p/interface' +import { TypedEventEmitter } from '@libp2p/interface' import { expect } from 'aegir/chai' import all from 'it-all' import drain from 'it-drain' @@ -19,9 +19,10 @@ export default (common: TestSetup): void => { let registrar: Registrar let listenAddrs: Multiaddr[] let dialAddrs: Multiaddr[] - let transport: Transport + let dialer: Transport + let listener: Transport let connector: Connector - let listener: Listener + let listen: Listener before(async () => { registrar = mockRegistrar() @@ -30,7 +31,7 @@ export default (common: TestSetup): void => { events: new TypedEventEmitter() }); - ({ listenAddrs, dialAddrs, transport, connector } = await common.setup()) + ({ listenAddrs, dialAddrs, dialer, listener, connector } = await common.setup()) }) after(async () => { @@ -38,16 +39,16 @@ export default (common: TestSetup): void => { }) beforeEach(async () => { - listener = transport.createListener({ + listen = listener.createListener({ upgrader }) - await listener.listen(listenAddrs[0]) + await listen.listen(listenAddrs[0]) }) afterEach(async () => { sinon.restore() connector.restore() - await listener.close() + await listen.close() }) it('simple', async () => { @@ -62,7 +63,7 @@ export default (common: TestSetup): void => { }) const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound') - const conn = await transport.dial(dialAddrs[0], { + const conn = await dialer.dial(dialAddrs[0], { upgrader }) @@ -78,7 +79,7 @@ export default (common: TestSetup): void => { it('can close connections', async () => { const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound') - const conn = await transport.dial(dialAddrs[0], { + const conn = await dialer.dial(dialAddrs[0], { upgrader }) @@ -91,7 +92,7 @@ export default (common: TestSetup): void => { it('to non existent listener', async () => { const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound') - await expect(transport.dial(dialAddrs[1], { + await expect(dialer.dial(dialAddrs[1], { upgrader })).to.eventually.be.rejected() expect(upgradeSpy.callCount).to.equal(0) @@ -101,9 +102,9 @@ export default (common: TestSetup): void => { const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound') const controller = new AbortController() controller.abort() - const conn = transport.dial(dialAddrs[0], { signal: controller.signal, upgrader }) + const conn = dialer.dial(dialAddrs[0], { signal: controller.signal, upgrader }) - await expect(conn).to.eventually.be.rejected().with.property('code', AbortError.code) + await expect(conn).to.eventually.be.rejected().with.property('name', 'AbortError') expect(upgradeSpy.callCount).to.equal(0) }) @@ -114,10 +115,10 @@ export default (common: TestSetup): void => { connector.delay(100) const controller = new AbortController() - const conn = transport.dial(dialAddrs[0], { signal: controller.signal, upgrader }) + const conn = dialer.dial(dialAddrs[0], { signal: controller.signal, upgrader }) setTimeout(() => { controller.abort() }, 50) - await expect(conn).to.eventually.be.rejected().with.property('code', AbortError.code) + await expect(conn).to.eventually.be.rejected().with.property('name', 'AbortError') expect(upgradeSpy.callCount).to.equal(0) }) }) diff --git a/packages/interface-compliance-tests/src/transport/filter-test.ts b/packages/interface-compliance-tests/src/transport/filter-test.ts index 925766e571..79c940abde 100644 --- a/packages/interface-compliance-tests/src/transport/filter-test.ts +++ b/packages/interface-compliance-tests/src/transport/filter-test.ts @@ -8,10 +8,11 @@ export default (common: TestSetup): void => { describe('filter', () => { let listenAddrs: Multiaddr[] let dialAddrs: Multiaddr[] - let transport: Transport + let dialer: Transport + let listener: Transport before(async () => { - ({ listenAddrs, dialAddrs, transport } = await common.setup()) + ({ listenAddrs, dialAddrs, dialer, listener } = await common.setup()) }) after(async () => { @@ -19,12 +20,12 @@ export default (common: TestSetup): void => { }) it('filters listen addresses', () => { - const filteredAddrs = transport.listenFilter(listenAddrs) + const filteredAddrs = listener.listenFilter(listenAddrs) expect(filteredAddrs).to.eql(listenAddrs) }) it('filters dial addresses', () => { - const filteredAddrs = transport.dialFilter(dialAddrs) + const filteredAddrs = dialer.dialFilter(dialAddrs) expect(filteredAddrs).to.eql(dialAddrs) }) }) diff --git a/packages/interface-compliance-tests/src/transport/index.ts b/packages/interface-compliance-tests/src/transport/index.ts index 89126a0570..9210ddbb06 100644 --- a/packages/interface-compliance-tests/src/transport/index.ts +++ b/packages/interface-compliance-tests/src/transport/index.ts @@ -13,7 +13,8 @@ export interface Connector { export interface TransportTestFixtures { listenAddrs: Multiaddr[] dialAddrs: Multiaddr[] - transport: Transport + dialer: Transport + listener: Transport connector: Connector } diff --git a/packages/interface-compliance-tests/src/transport/listen-test.ts b/packages/interface-compliance-tests/src/transport/listen-test.ts index 5dc48ae096..4f18a2ecde 100644 --- a/packages/interface-compliance-tests/src/transport/listen-test.ts +++ b/packages/interface-compliance-tests/src/transport/listen-test.ts @@ -20,7 +20,8 @@ export default (common: TestSetup): void => { let upgrader: Upgrader let listenAddrs: Multiaddr[] let dialAddrs: Multiaddr[] - let transport: Transport + let dialer: Transport + let listener: Transport let registrar: Registrar before(async () => { @@ -30,7 +31,7 @@ export default (common: TestSetup): void => { events: new TypedEventEmitter() }); - ({ transport, listenAddrs, dialAddrs } = await common.setup()) + ({ dialer, listener, listenAddrs, dialAddrs } = await common.setup()) }) after(async () => { @@ -42,11 +43,11 @@ export default (common: TestSetup): void => { }) it('simple', async () => { - const listener = transport.createListener({ + const listen = listener.createListener({ upgrader }) - await listener.listen(listenAddrs[0]) - await listener.close() + await listen.listen(listenAddrs[0]) + await listen.close() }) it('close listener with connections, through timeout', async () => { @@ -58,7 +59,7 @@ export default (common: TestSetup): void => { void drain(data.stream.source) }) - const listener = transport.createListener({ + const listen = listener.createListener({ upgrader, handler: (conn) => { listenerConns.push(conn) @@ -66,14 +67,14 @@ export default (common: TestSetup): void => { }) // Listen - await listener.listen(listenAddrs[0]) + await listen.listen(listenAddrs[0]) // Create two connections to the listener const [conn1] = await Promise.all([ - transport.dial(dialAddrs[0], { + dialer.dial(dialAddrs[0], { upgrader }), - transport.dial(dialAddrs[0], { + dialer.dial(dialAddrs[0], { upgrader }) ]) @@ -90,7 +91,7 @@ export default (common: TestSetup): void => { stream1 ), // Closer the listener (will take a couple of seconds to time out) - listener.close() + listen.close() ]) await stream1.close() @@ -108,39 +109,39 @@ export default (common: TestSetup): void => { it('should not handle connection if upgradeInbound throws', async () => { sinon.stub(upgrader, 'upgradeInbound').throws() - const listener = transport.createListener({ + const listen = listener.createListener({ upgrader }) // Listen - await listener.listen(listenAddrs[0]) + await listen.listen(listenAddrs[0]) // Create a connection to the listener - const conn = await transport.dial(dialAddrs[0], { + const conn = await dialer.dial(dialAddrs[0], { upgrader }) await pWaitFor(() => typeof conn.timeline.close === 'number') - await listener.close() + await listen.close() }) describe('events', () => { it('connection', async () => { const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound') - const listener = transport.createListener({ + const listen = listener.createListener({ upgrader }) const deferred = defer() let conn - listener.addEventListener('connection', (evt) => { + listen.addEventListener('connection', (evt) => { conn = evt.detail deferred.resolve() }) void (async () => { - await listener.listen(listenAddrs[0]) - await transport.dial(dialAddrs[0], { + await listen.listen(listenAddrs[0]) + await dialer.dial(dialAddrs[0], { upgrader }) })() @@ -149,41 +150,41 @@ export default (common: TestSetup): void => { await expect(upgradeSpy.getCall(0).returnValue).to.eventually.equal(conn) expect(upgradeSpy.callCount).to.equal(1) - await listener.close() + await listen.close() }) it('listening', (done) => { - const listener = transport.createListener({ + const listen = listener.createListener({ upgrader }) - listener.addEventListener('listening', () => { - listener.close().then(done, done) + listen.addEventListener('listening', () => { + listen.close().then(done, done) }) - void listener.listen(listenAddrs[0]) + void listen.listen(listenAddrs[0]) }) it('error', (done) => { - const listener = transport.createListener({ + const listen = listener.createListener({ upgrader }) - listener.addEventListener('error', (evt) => { + listen.addEventListener('error', (evt) => { expect(evt.detail).to.be.an.instanceOf(Error) - listener.close().then(done, done) + listen.close().then(done, done) }) - listener.dispatchEvent(new CustomEvent('error', { + listen.dispatchEvent(new CustomEvent('error', { detail: new Error('my err') })) }) it('close', (done) => { - const listener = transport.createListener({ + const listen = listener.createListener({ upgrader }) - listener.addEventListener('close', () => { done() }) + listen.addEventListener('close', () => { done() }) void (async () => { - await listener.listen(listenAddrs[0]) - await listener.close() + await listen.listen(listenAddrs[0]) + await listen.close() })() }) }) diff --git a/packages/transport-tcp/test/compliance.spec.ts b/packages/transport-tcp/test/compliance.spec.ts index b7b3011598..33a945a4d4 100644 --- a/packages/transport-tcp/test/compliance.spec.ts +++ b/packages/transport-tcp/test/compliance.spec.ts @@ -38,7 +38,7 @@ describe('interface-transport compliance', () => { } } - return { transport, listenAddrs: addrs, dialAddrs: addrs, connector } + return { dialer: transport, listener: transport, listenAddrs: addrs, dialAddrs: addrs, connector } }, async teardown () {} }) diff --git a/packages/transport-websockets/test/compliance.node.ts b/packages/transport-websockets/test/compliance.node.ts index e3aac58013..c204accde3 100644 --- a/packages/transport-websockets/test/compliance.node.ts +++ b/packages/transport-websockets/test/compliance.node.ts @@ -56,7 +56,7 @@ describe('interface-transport compliance', () => { restore () { delayMs = 0 } } - return { transport: wsProxy, listenAddrs: addrs, dialAddrs: addrs, connector } + return { dialer: wsProxy, listener: wsProxy, listenAddrs: addrs, dialAddrs: addrs, connector } }, async teardown () {} })