From 7d73f8121da109df2715c9d94115a64791616d63 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 15 Mar 2023 16:50:42 -0700 Subject: [PATCH 01/14] Add webkit test script --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index b5df58e0b2..423bab396e 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,7 @@ "test:chrome-webworker": "aegir test -t webworker -f \"./dist/test/**/*.spec.js\"", "test:firefox": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -f \"./dist/test/**/*.spec.js\" -- --browser firefox", + "test:webkit": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser webkit", "test:examples": "cd examples && npm run test:all", "test:interop": "aegir test -t node -f dist/test/interop.js" }, From cfd5c4b7d9ce2cf75d3a27bb65267154ba4a5b8c Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 15 Mar 2023 21:48:25 -0700 Subject: [PATCH 02/14] Add webkit test to CI --- .github/workflows/main.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bf4e8f23cd..a6cc7a5f09 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -100,6 +100,21 @@ jobs: directory: ./.nyc_output flags: firefox-webworker + test-webkit: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:webkit + - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + with: + directory: ./.nyc_output + flags: webkit + test-electron-main: needs: check runs-on: ubuntu-latest From c3cde5e557234ca43e1ab94cff0bd81ffb3753f1 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Mon, 20 Mar 2023 14:16:26 -0700 Subject: [PATCH 03/14] Install playwright deps --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a6cc7a5f09..16b2e0cd3c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -109,6 +109,7 @@ jobs: with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npx playwright install-deps - run: npm run --if-present test:webkit - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 with: From 6cc9030d0db8ae1e57e0f89e814fdb322d9ecc10 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Mon, 1 May 2023 21:22:09 -0700 Subject: [PATCH 04/14] Fix stream stubbing. We can't set the property value like this on safari --- src/autonat/index.ts | 4 ++-- test/autonat/index.spec.ts | 29 ++++++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/autonat/index.ts b/src/autonat/index.ts index 935a4524a0..5d7cfc70a2 100644 --- a/src/autonat/index.ts +++ b/src/autonat/index.ts @@ -505,7 +505,7 @@ export class AutonatService implements Startable { // they either told us which address worked/didn't work, or we only sent them one address const addr = dialResponse.addr == null ? multiaddrs[0] : multiaddr(dialResponse.addr) - log('Autonat response for %s is %s', addr, dialResponse.status) + log('Autonat response for %s is %s', addr.toString(), dialResponse.status) if (dialResponse.status === Message.ResponseStatus.E_BAD_REQUEST) { // the remote could not parse our request @@ -548,7 +548,7 @@ export class AutonatService implements Startable { if (results[addrStr].failure === REQUIRED_SUCCESSFUL_DIALS) { // we are now unconvinced - log('%s is not externally dialable', addr) + log('%s is not externally dialable', addr.toString()) addressManager.removeObservedAddr(addr) return } diff --git a/test/autonat/index.spec.ts b/test/autonat/index.spec.ts index 3a3cd7b242..0313ea1e6e 100644 --- a/test/autonat/index.spec.ts +++ b/test/autonat/index.spec.ts @@ -6,7 +6,7 @@ import sinon from 'sinon' import { createEd25519PeerId } from '@libp2p/peer-id-factory' import { start, stop } from '@libp2p/interfaces/startable' import { AutonatService, AutonatServiceInit } from '../../src/autonat/index.js' -import { StubbedInstance, stubInterface } from 'sinon-ts' +import { StubbedInstance, stubInterface, stubObject } from 'sinon-ts' import type { PeerRouting } from '@libp2p/interface-peer-routing' import { Multiaddr, multiaddr } from '@multiformats/multiaddr' import type { Registrar } from '@libp2p/interface-registrar' @@ -92,19 +92,27 @@ describe('autonat', () => { connection.remoteAddr = multiaddr(`/ip4/${host}/tcp/28319/p2p/${peer.id.toString()}`) connectionManager.openConnection.withArgs(peer.id).resolves(connection) - // stub autonat protocol stream - const stream = stubInterface() - connection.newStream.withArgs(PROTOCOL).resolves(stream) - - // stub autonat response const response = Message.encode({ type: Message.MessageType.DIAL_RESPONSE, dialResponse }) - stream.source = (async function * () { - yield lp.encode.single(response) - }()) - stream.sink.returns(Promise.resolve()) + + // stub autonat protocol stream + const stream = stubObject({ + close: sinon.stub(), + closeRead: sinon.stub(), + closeWrite: sinon.stub(), + abort: sinon.stub(), + reset: sinon.stub(), + id: '', + stat: { direction: 'outbound', timeline: { open: Date.now() } }, + metadata: {}, + source: (async function * () { + yield lp.encode.single(response) + }()), + sink: sinon.stub().returns(Promise.resolve()) + }) + connection.newStream.withArgs(PROTOCOL).resolves(stream) return peer } @@ -289,7 +297,6 @@ describe('autonat', () => { status: Message.ResponseStatus.E_DIAL_ERROR }) ] - peerRouting.getClosestPeers.returns(async function * () { yield * peers }()) From 5ed21461025c2ee466cd284b5f9b0a000d346db3 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Mon, 1 May 2023 21:35:10 -0700 Subject: [PATCH 05/14] Bump @libp2p/crypto --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dcdd6499df..7a3aeb664d 100644 --- a/package.json +++ b/package.json @@ -121,7 +121,7 @@ }, "dependencies": { "@achingbrain/nat-port-mapper": "^1.0.3", - "@libp2p/crypto": "^1.0.4", + "@libp2p/crypto": "^1.0.15", "@libp2p/interface-address-manager": "^3.0.0", "@libp2p/interface-connection": "^5.0.0", "@libp2p/interface-connection-encrypter": "^4.0.0", From 111ba6b5215107cf1f5064998369dc13e85bf439 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Fri, 5 May 2023 08:49:55 -0700 Subject: [PATCH 06/14] Update @libp2p/crypto --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7a3aeb664d..49c6a33231 100644 --- a/package.json +++ b/package.json @@ -121,7 +121,7 @@ }, "dependencies": { "@achingbrain/nat-port-mapper": "^1.0.3", - "@libp2p/crypto": "^1.0.15", + "@libp2p/crypto": "^1.0.17", "@libp2p/interface-address-manager": "^3.0.0", "@libp2p/interface-connection": "^5.0.0", "@libp2p/interface-connection-encrypter": "^4.0.0", From 2f0dde94546c0d439b86d3f283282153f230b489 Mon Sep 17 00:00:00 2001 From: chad Date: Mon, 22 May 2023 21:15:52 -0500 Subject: [PATCH 07/14] refactor: updated formatters --- src/autonat/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/autonat/index.ts b/src/autonat/index.ts index c8e7aec788..5c89dfae9d 100644 --- a/src/autonat/index.ts +++ b/src/autonat/index.ts @@ -508,7 +508,7 @@ class DefaultAutoNATService implements Startable { // they either told us which address worked/didn't work, or we only sent them one address const addr = dialResponse.addr == null ? multiaddrs[0] : multiaddr(dialResponse.addr) - log('Autonat response for %s is %s', addr.toString(), dialResponse.status) + log('autonat response for %ma is %s', addr, dialResponse.status) if (dialResponse.status === Message.ResponseStatus.E_BAD_REQUEST) { // the remote could not parse our request @@ -526,7 +526,7 @@ class DefaultAutoNATService implements Startable { } if (!multiaddrs.some(ma => ma.equals(addr))) { - log('peer reported %s as %s but it was not in our observed address list', addr, dialResponse.status) + log('Peer reported %ma as %s but it was not in our observed address list', addr, dialResponse.status) continue } @@ -544,14 +544,14 @@ class DefaultAutoNATService implements Startable { if (results[addrStr].success === REQUIRED_SUCCESSFUL_DIALS) { // we are now convinced - log('%s is externally dialable', addr) + log('%s is externally dialable: %ma', addr) addressManager.confirmObservedAddr(addr) return } if (results[addrStr].failure === REQUIRED_SUCCESSFUL_DIALS) { // we are now unconvinced - log('%s is not externally dialable', addr.toString()) + log('%s is not externally dialable: %ma', addr) addressManager.removeObservedAddr(addr) return } From 3d6a67ed8fd7949e585bc52384515e6a64110bed Mon Sep 17 00:00:00 2001 From: chad Date: Wed, 31 May 2023 11:53:37 -0500 Subject: [PATCH 08/14] test: skip flaky connect and disconnect event tests --- test/upgrading/upgrader.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/upgrading/upgrader.spec.ts b/test/upgrading/upgrader.spec.ts index c289b9871a..88a3ed633d 100644 --- a/test/upgrading/upgrader.spec.ts +++ b/test/upgrading/upgrader.spec.ts @@ -668,7 +668,8 @@ describe('libp2p.upgrader', () => { expect(arg0.stream).to.include.keys(['id', 'recvWindowCapacity', 'sendWindowCapacity', 'sourceInput']) }) - it('should emit connect and disconnect events', async () => { + // #TODO Investigate why this is failing https://github.com/libp2p/js-libp2p/issues/1781, skipping for now based https://github.com/libp2p/js-libp2p/pull/1627#issuecomment-1570561645 + it.skip('should emit connect and disconnect events', async () => { const remotePeer = peers[1] libp2p = await createLibp2p({ peerId: peers[0], From 8e43bb5795dc81aad5f21373303ccc983f398b3e Mon Sep 17 00:00:00 2001 From: chad Date: Wed, 31 May 2023 12:15:11 -0500 Subject: [PATCH 09/14] deps: update logger to enable multiaddr formatting --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ef4a326b39..68dd87a242 100644 --- a/package.json +++ b/package.json @@ -143,7 +143,7 @@ "@libp2p/interface-transport": "^4.0.0", "@libp2p/interfaces": "^3.2.0", "@libp2p/keychain": "^2.0.0", - "@libp2p/logger": "^2.0.1", + "@libp2p/logger": "^2.1.0", "@libp2p/multistream-select": "^3.1.8", "@libp2p/peer-collections": "^3.0.0", "@libp2p/peer-id": "^2.0.0", From a78db93c14ede84379596a2fc687a7ee4620ccf7 Mon Sep 17 00:00:00 2001 From: Chad Nehemiah Date: Thu, 1 Jun 2023 03:35:37 +0000 Subject: [PATCH 10/14] test: ensure that libp2p nodes are shutdown in identify service spec --- test/identify/service.spec.ts | 12 ++++++++++-- test/upgrading/upgrader.spec.ts | 3 +-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/test/identify/service.spec.ts b/test/identify/service.spec.ts index bc31da4213..790856dc3a 100644 --- a/test/identify/service.spec.ts +++ b/test/identify/service.spec.ts @@ -67,7 +67,10 @@ describe('identify', () => { // The connection should have no open streams await pWaitFor(() => connection.streams.length === 0) + await connection.close() + + await libp2p.stop() }) it('should emit peer:identify event after connecting', async () => { @@ -79,11 +82,11 @@ describe('identify', () => { })) await libp2p.start() - + if (libp2p.services.identify == null) { throw new Error('Identity service was not configured') } - + const eventPromise = pEvent<'peer:identify', CustomEvent>(libp2p, 'peer:identify') const connection = await libp2p.dial(remoteAddr) @@ -95,7 +98,10 @@ describe('identify', () => { const remotePeer = peerIdFromString(remoteAddr.getPeerId() ?? '') expect(event.detail.peerId.equals(remotePeer)).to.be.true() + await connection.close() + + await libp2p.stop() }) it('should store remote agent and protocol versions in metadataBook after connecting', async () => { @@ -129,6 +135,8 @@ describe('identify', () => { const remotePeer = await libp2p.peerStore.get(remotePeerId) expect(remotePeer.metadata.get('AgentVersion')).to.exist() expect(remotePeer.metadata.get('ProtocolVersion')).to.exist() + + await libp2p.stop() }) it('should push protocol updates to an already connected peer', async () => { diff --git a/test/upgrading/upgrader.spec.ts b/test/upgrading/upgrader.spec.ts index 88a3ed633d..c289b9871a 100644 --- a/test/upgrading/upgrader.spec.ts +++ b/test/upgrading/upgrader.spec.ts @@ -668,8 +668,7 @@ describe('libp2p.upgrader', () => { expect(arg0.stream).to.include.keys(['id', 'recvWindowCapacity', 'sendWindowCapacity', 'sourceInput']) }) - // #TODO Investigate why this is failing https://github.com/libp2p/js-libp2p/issues/1781, skipping for now based https://github.com/libp2p/js-libp2p/pull/1627#issuecomment-1570561645 - it.skip('should emit connect and disconnect events', async () => { + it('should emit connect and disconnect events', async () => { const remotePeer = peers[1] libp2p = await createLibp2p({ peerId: peers[0], From 5a24425cb15db90b59ca7712aa20d2eb4a07d65e Mon Sep 17 00:00:00 2001 From: chad Date: Wed, 31 May 2023 22:40:40 -0500 Subject: [PATCH 11/14] chore: linting fixes --- test/identify/service.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/identify/service.spec.ts b/test/identify/service.spec.ts index 790856dc3a..04c1fcf17a 100644 --- a/test/identify/service.spec.ts +++ b/test/identify/service.spec.ts @@ -69,7 +69,7 @@ describe('identify', () => { await pWaitFor(() => connection.streams.length === 0) await connection.close() - + await libp2p.stop() }) @@ -82,11 +82,11 @@ describe('identify', () => { })) await libp2p.start() - + if (libp2p.services.identify == null) { throw new Error('Identity service was not configured') } - + const eventPromise = pEvent<'peer:identify', CustomEvent>(libp2p, 'peer:identify') const connection = await libp2p.dial(remoteAddr) @@ -100,7 +100,7 @@ describe('identify', () => { expect(event.detail.peerId.equals(remotePeer)).to.be.true() await connection.close() - + await libp2p.stop() }) From c21177edff499833b45c35fd48313c239cde6cb3 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 2 Jun 2023 21:01:08 +0100 Subject: [PATCH 12/14] chore: remove webkit fixes --- test/autonat/index.spec.ts | 34 ++++++++++++++-------------------- test/identify/service.spec.ts | 8 -------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/test/autonat/index.spec.ts b/test/autonat/index.spec.ts index 584d474608..d2ef3e8ee4 100644 --- a/test/autonat/index.spec.ts +++ b/test/autonat/index.spec.ts @@ -10,7 +10,7 @@ import * as lp from 'it-length-prefixed' import { pipe } from 'it-pipe' import { pushable } from 'it-pushable' import sinon from 'sinon' -import { stubInterface, stubObject } from 'sinon-ts' +import { stubInterface } from 'sinon-ts' import { Uint8ArrayList } from 'uint8arraylist' import { PROTOCOL_NAME, PROTOCOL_PREFIX, PROTOCOL_VERSION } from '../../src/autonat/constants.js' import { autoNATService } from '../../src/autonat/index.js' @@ -96,28 +96,22 @@ describe('autonat', () => { connection.remoteAddr = multiaddr(`/ip4/${host}/tcp/28319/p2p/${peer.id.toString()}`) connectionManager.openConnection.withArgs(peer.id).resolves(connection) - const response = Message.encode({ - type: Message.MessageType.DIAL_RESPONSE, - dialResponse - }) + connection.newStream.withArgs(`/${PROTOCOL_PREFIX}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`).callsFake(async () => { + // stub autonat protocol stream + const stream = stubInterface() - // stub autonat protocol stream - const stream = stubObject({ - close: sinon.stub(), - closeRead: sinon.stub(), - closeWrite: sinon.stub(), - abort: sinon.stub(), - reset: sinon.stub(), - id: '', - stat: { direction: 'outbound', timeline: { open: Date.now() } }, - metadata: {}, - source: (async function * () { - // stub autonat response + // stub autonat response + const response = Message.encode({ + type: Message.MessageType.DIAL_RESPONSE, + dialResponse + }) + stream.source = (async function * () { yield lp.encode.single(response) - }()), - sink: sinon.stub().returns(Promise.resolve()) + }()) + stream.sink.returns(Promise.resolve()) + + return stream }) - connection.newStream.withArgs(`/${PROTOCOL_PREFIX}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`).resolves(stream) return peer } diff --git a/test/identify/service.spec.ts b/test/identify/service.spec.ts index 04c1fcf17a..bc31da4213 100644 --- a/test/identify/service.spec.ts +++ b/test/identify/service.spec.ts @@ -67,10 +67,7 @@ describe('identify', () => { // The connection should have no open streams await pWaitFor(() => connection.streams.length === 0) - await connection.close() - - await libp2p.stop() }) it('should emit peer:identify event after connecting', async () => { @@ -98,10 +95,7 @@ describe('identify', () => { const remotePeer = peerIdFromString(remoteAddr.getPeerId() ?? '') expect(event.detail.peerId.equals(remotePeer)).to.be.true() - await connection.close() - - await libp2p.stop() }) it('should store remote agent and protocol versions in metadataBook after connecting', async () => { @@ -135,8 +129,6 @@ describe('identify', () => { const remotePeer = await libp2p.peerStore.get(remotePeerId) expect(remotePeer.metadata.get('AgentVersion')).to.exist() expect(remotePeer.metadata.get('ProtocolVersion')).to.exist() - - await libp2p.stop() }) it('should push protocol updates to an already connected peer', async () => { From d29de4a3586e6697b460dfce354e495aa401f904 Mon Sep 17 00:00:00 2001 From: chad Date: Sat, 3 Jun 2023 14:21:48 -0500 Subject: [PATCH 13/14] refactor: updated multiaddr formatting in logs --- package.json | 2 +- src/autonat/index.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 68dd87a242..377828dc78 100644 --- a/package.json +++ b/package.json @@ -143,7 +143,7 @@ "@libp2p/interface-transport": "^4.0.0", "@libp2p/interfaces": "^3.2.0", "@libp2p/keychain": "^2.0.0", - "@libp2p/logger": "^2.1.0", + "@libp2p/logger": "^2.1.1", "@libp2p/multistream-select": "^3.1.8", "@libp2p/peer-collections": "^3.0.0", "@libp2p/peer-id": "^2.0.0", diff --git a/src/autonat/index.ts b/src/autonat/index.ts index 5c89dfae9d..9b7c068805 100644 --- a/src/autonat/index.ts +++ b/src/autonat/index.ts @@ -508,7 +508,7 @@ class DefaultAutoNATService implements Startable { // they either told us which address worked/didn't work, or we only sent them one address const addr = dialResponse.addr == null ? multiaddrs[0] : multiaddr(dialResponse.addr) - log('autonat response for %ma is %s', addr, dialResponse.status) + log('autonat response for %a is %s', addr, dialResponse.status) if (dialResponse.status === Message.ResponseStatus.E_BAD_REQUEST) { // the remote could not parse our request @@ -526,7 +526,7 @@ class DefaultAutoNATService implements Startable { } if (!multiaddrs.some(ma => ma.equals(addr))) { - log('Peer reported %ma as %s but it was not in our observed address list', addr, dialResponse.status) + log('Peer reported %a as %s but it was not in our observed address list', addr, dialResponse.status) continue } @@ -544,14 +544,14 @@ class DefaultAutoNATService implements Startable { if (results[addrStr].success === REQUIRED_SUCCESSFUL_DIALS) { // we are now convinced - log('%s is externally dialable: %ma', addr) + log('%a is externally dialable', addr) addressManager.confirmObservedAddr(addr) return } if (results[addrStr].failure === REQUIRED_SUCCESSFUL_DIALS) { // we are now unconvinced - log('%s is not externally dialable: %ma', addr) + log('%a is not externally dialable', addr) addressManager.removeObservedAddr(addr) return } From 37044faebd2bb661966f24f09467853b792c435d Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 6 Jun 2023 10:35:43 +0100 Subject: [PATCH 14/14] chore: edits for consistency --- src/autonat/index.ts | 2 +- test/autonat/index.spec.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/autonat/index.ts b/src/autonat/index.ts index 9b7c068805..312f557807 100644 --- a/src/autonat/index.ts +++ b/src/autonat/index.ts @@ -526,7 +526,7 @@ class DefaultAutoNATService implements Startable { } if (!multiaddrs.some(ma => ma.equals(addr))) { - log('Peer reported %a as %s but it was not in our observed address list', addr, dialResponse.status) + log('peer reported %a as %s but it was not in our observed address list', addr, dialResponse.status) continue } diff --git a/test/autonat/index.spec.ts b/test/autonat/index.spec.ts index d2ef3e8ee4..a21ac4a521 100644 --- a/test/autonat/index.spec.ts +++ b/test/autonat/index.spec.ts @@ -296,6 +296,7 @@ describe('autonat', () => { status: Message.ResponseStatus.E_DIAL_ERROR }) ] + peerRouting.getClosestPeers.returns(async function * () { yield * peers }())