Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Aug 30, 2024
1 parent 7e89e7b commit a4162ac
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/connection-encrypter-plaintext/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ describe('plaintext', () => {
remotePeer: localPeer
})
]))
.to.eventually.be.rejected.with.property('name', 'InvalidCryptoExchangeError')
.to.eventually.be.rejected.with.property('name', 'UnexpectedPeerError')
})
})
2 changes: 1 addition & 1 deletion packages/connection-encrypter-tls/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ describe('tls', () => {
remotePeer: localPeer
})
]))
.to.eventually.be.rejected.with.property('name', 'InvalidParametersError')
.to.eventually.be.rejected.with.property('name', 'UnexpectedPeerError')
})
})
8 changes: 4 additions & 4 deletions packages/libp2p/test/connection-manager/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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)
})

Expand All @@ -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)
})
})
Expand Down
4 changes: 2 additions & 2 deletions packages/libp2p/test/core/random-walk.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down
18 changes: 9 additions & 9 deletions packages/libp2p/test/upgrading/upgrader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConnectionProtector>()
localConnectionProtector.protect.resolvesArg(0)

localComponents = defaultComponents({
peerId: localPeer,
privateKey: localKey,
connectionGater: mockConnectionGater(),
registrar: mockRegistrar(),
datastore: new MemoryDatastore(),
Expand Down Expand Up @@ -93,6 +92,7 @@ describe('Upgrader', () => {

remoteComponents = defaultComponents({
peerId: remotePeer,
privateKey: remoteKey,
connectionGater: mockConnectionGater(),
registrar: mockRegistrar(),
datastore: new MemoryDatastore(),
Expand Down Expand Up @@ -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<PeerId>>(libp2p, 'peer:disconnect')

Expand All @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-ping/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

0 comments on commit a4162ac

Please sign in to comment.