From a4162ac48cab7475e629a32dbc821a5e2f94b723 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 30 Aug 2024 14:17:19 +0100 Subject: [PATCH] chore: fix tests --- .../test/index.spec.ts | 2 +- .../test/index.spec.ts | 2 +- .../test/connection-manager/index.node.ts | 8 ++++---- packages/libp2p/test/core/random-walk.spec.ts | 4 ++-- .../libp2p/test/upgrading/upgrader.spec.ts | 18 +++++++++--------- packages/protocol-ping/test/index.spec.ts | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/connection-encrypter-plaintext/test/index.spec.ts b/packages/connection-encrypter-plaintext/test/index.spec.ts index ea6f36fa4a..3ae8de7beb 100644 --- a/packages/connection-encrypter-plaintext/test/index.spec.ts +++ b/packages/connection-encrypter-plaintext/test/index.spec.ts @@ -84,6 +84,6 @@ describe('plaintext', () => { remotePeer: localPeer }) ])) - .to.eventually.be.rejected.with.property('name', 'InvalidCryptoExchangeError') + .to.eventually.be.rejected.with.property('name', 'UnexpectedPeerError') }) }) diff --git a/packages/connection-encrypter-tls/test/index.spec.ts b/packages/connection-encrypter-tls/test/index.spec.ts index 7d6f4a0623..0a529d8c45 100644 --- a/packages/connection-encrypter-tls/test/index.spec.ts +++ b/packages/connection-encrypter-tls/test/index.spec.ts @@ -83,6 +83,6 @@ describe('tls', () => { remotePeer: localPeer }) ])) - .to.eventually.be.rejected.with.property('name', 'InvalidParametersError') + .to.eventually.be.rejected.with.property('name', 'UnexpectedPeerError') }) }) diff --git a/packages/libp2p/test/connection-manager/index.node.ts b/packages/libp2p/test/connection-manager/index.node.ts index 251ee96c71..aebb600c36 100644 --- a/packages/libp2p/test/connection-manager/index.node.ts +++ b/packages/libp2p/test/connection-manager/index.node.ts @@ -422,7 +422,7 @@ describe('libp2p.connections', () => { await remoteLibp2p.dial(libp2p.peerId) expect(denyInboundEncryptedConnection.called).to.be.true() - expect(denyInboundEncryptedConnection.getCall(0)).to.have.nested.property('args[0].toMultihash().digest').that.equalBytes(remoteLibp2p.peerId.toMultihash().digest) + expect(denyInboundEncryptedConnection.getCall(0).args[0].toMultihash().bytes).to.equalBytes(remoteLibp2p.peerId.toMultihash().bytes) }) it('intercept outbound encrypted', async () => { @@ -444,7 +444,7 @@ describe('libp2p.connections', () => { await libp2p.dial(remoteLibp2p.peerId) expect(denyOutboundEncryptedConnection.called).to.be.true() - expect(denyOutboundEncryptedConnection.getCall(0)).to.have.nested.property('args[0].toMultihash().digest').that.equalBytes(remoteLibp2p.peerId.toMultihash().digest) + expect(denyOutboundEncryptedConnection.getCall(0).args[0].toMultihash().bytes).to.equalBytes(remoteLibp2p.peerId.toMultihash().bytes) }) it('intercept inbound upgraded', async () => { @@ -472,7 +472,7 @@ describe('libp2p.connections', () => { const output = await pipe(input, stream, async (source) => all(source)) expect(denyInboundUpgradedConnection.called).to.be.true() - expect(denyInboundUpgradedConnection.getCall(0)).to.have.nested.property('args[0].toMultihash().digest').that.equalBytes(remoteLibp2p.peerId.toMultihash().digest) + expect(denyInboundUpgradedConnection.getCall(0).args[0].toMultihash().bytes).to.equalBytes(remoteLibp2p.peerId.toMultihash().bytes) expect(output.map(b => b.subarray())).to.deep.equal(input) }) @@ -498,7 +498,7 @@ describe('libp2p.connections', () => { const output = await pipe(input, stream, async (source) => all(source)) expect(denyOutboundUpgradedConnection.called).to.be.true() - expect(denyOutboundUpgradedConnection.getCall(0)).to.have.nested.property('args[0].toMultihash().digest').that.equalBytes(remoteLibp2p.peerId.toMultihash().digest) + expect(denyOutboundUpgradedConnection.getCall(0).args[0].toMultihash().bytes).to.equalBytes(remoteLibp2p.peerId.toMultihash().bytes) expect(output.map(b => b.subarray())).to.deep.equal(input) }) }) diff --git a/packages/libp2p/test/core/random-walk.spec.ts b/packages/libp2p/test/core/random-walk.spec.ts index f2e0277d32..70a8b704fa 100644 --- a/packages/libp2p/test/core/random-walk.spec.ts +++ b/packages/libp2p/test/core/random-walk.spec.ts @@ -156,7 +156,7 @@ describe('random-walk', () => { drain(take(randomwalk.walk(), 2)) ]) - expect(yielded).to.equal(2) + expect(yielded).to.equal(3) }) it('should not block walk on slow consumers', async () => { @@ -180,7 +180,7 @@ describe('random-walk', () => { })) ]) - expect(yielded).to.equal(7) + expect(yielded).to.equal(10) }) it('should unpause query if second consumer requires peers', async () => { diff --git a/packages/libp2p/test/upgrading/upgrader.spec.ts b/packages/libp2p/test/upgrading/upgrader.spec.ts index 32c0a14cb6..432336a47d 100644 --- a/packages/libp2p/test/upgrading/upgrader.spec.ts +++ b/packages/libp2p/test/upgrading/upgrader.spec.ts @@ -53,19 +53,18 @@ describe('Upgrader', () => { let remoteComponents: Components beforeEach(async () => { - ([ - localPeer, - remotePeer - ] = await Promise.all([ - peerIdFromPrivateKey(await generateKeyPair('Ed25519')), - peerIdFromPrivateKey(await generateKeyPair('Ed25519')) - ])) + const localKey = await generateKeyPair('Ed25519') + localPeer = peerIdFromPrivateKey(localKey) + + const remoteKey = await generateKeyPair('Ed25519') + remotePeer = peerIdFromPrivateKey(remoteKey) localConnectionProtector = stubInterface() localConnectionProtector.protect.resolvesArg(0) localComponents = defaultComponents({ peerId: localPeer, + privateKey: localKey, connectionGater: mockConnectionGater(), registrar: mockRegistrar(), datastore: new MemoryDatastore(), @@ -93,6 +92,7 @@ describe('Upgrader', () => { remoteComponents = defaultComponents({ peerId: remotePeer, + privateKey: remoteKey, connectionGater: mockConnectionGater(), registrar: mockRegistrar(), datastore: new MemoryDatastore(), @@ -779,7 +779,7 @@ describe('libp2p.upgrader', () => { throw new Error(`Incorrect event type, expected: 'connection:open' actual: ${connectEvent.type}`) } - expect(remotePeer.equals(connectEvent.detail.remotePeer)).to.equal(true) + expect(remotePeer.publicKey.equals(connectEvent.detail.remotePeer.publicKey)).to.equal(true) const disconnectionPromise = pEvent<'peer:disconnect', CustomEvent>(libp2p, 'peer:disconnect') @@ -792,7 +792,7 @@ describe('libp2p.upgrader', () => { throw new Error(`Incorrect event type, expected: 'peer:disconnect' actual: ${disconnectEvent.type}`) } - expect(remotePeer.equals(disconnectEvent.detail)).to.equal(true) + expect(remotePeer.publicKey.equals(disconnectEvent.detail.publicKey)).to.equal(true) }) it('should limit the number of incoming streams that can be opened using a protocol', async () => { diff --git a/packages/protocol-ping/test/index.spec.ts b/packages/protocol-ping/test/index.spec.ts index b72c32caab..6ab997bf29 100644 --- a/packages/protocol-ping/test/index.spec.ts +++ b/packages/protocol-ping/test/index.spec.ts @@ -143,6 +143,6 @@ describe('ping', () => { const err = await deferred.promise - expect(err).to.have.property('code', 'ERR_INVALID_MESSAGE') + expect(err).to.have.property('name', 'InvalidMessageError') }) })