Skip to content

Commit

Permalink
chore: use PeerId/Multiaddr matchers from interface tests (#2375)
Browse files Browse the repository at this point in the history
Removes duplicated code.
  • Loading branch information
achingbrain authored Jan 24, 2024
1 parent 2e464c0 commit f4dda4a
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@libp2p/floodsub": "^9.0.0",
"@libp2p/identify": "^1.0.9",
"@libp2p/interface": "^1.0.0",
"@libp2p/interface-compliance-tests": "^5.1.1",
"@libp2p/interface-compliance-tests": "^5.1.3",
"@libp2p/interface-internal": "^1.0.0",
"@libp2p/interop": "^10.0.0",
"@libp2p/kad-dht": "^12.0.0",
Expand Down
6 changes: 0 additions & 6 deletions packages/kad-dht/test/fixtures/match-peer-id.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/kad-dht/test/libp2p-routing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { contentRoutingSymbol, TypedEventEmitter, start, stop, peerRoutingSymbol } from '@libp2p/interface'
import { matchPeerId } from '@libp2p/interface-compliance-tests/matchers'
import { defaultLogger } from '@libp2p/logger'
import { multiaddr } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
Expand All @@ -13,7 +14,6 @@ import { stubInterface, type StubbedInstance } from 'sinon-ts'
import { kadDHT, passthroughMapper, type KadDHT } from '../src/index.js'
import { Message, MessageType } from '../src/message/dht.js'
import { convertBuffer } from '../src/utils.js'
import { matchPeerId } from './fixtures/match-peer-id.js'
import { createPeerIds } from './utils/create-peer-id.js'
import { sortClosestPeers } from './utils/sort-closest-peers.js'
import type { ContentRouting, PeerStore, PeerId, TypedEventTarget, ComponentLogger, Connection, Peer, Stream, PeerRouting } from '@libp2p/interface'
Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p/test/connection-manager/auto-dial.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env mocha */

import { TypedEventEmitter, type TypedEventTarget, type Libp2pEvents, type Connection, type PeerId, type PeerStore, type Peer } from '@libp2p/interface'
import { matchPeerId } from '@libp2p/interface-compliance-tests/matchers'
import { defaultLogger } from '@libp2p/logger'
import { PeerMap } from '@libp2p/peer-collections'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
Expand All @@ -16,7 +17,6 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { defaultComponents } from '../../src/components.js'
import { AutoDial } from '../../src/connection-manager/auto-dial.js'
import { LAST_DIAL_FAILURE_KEY } from '../../src/connection-manager/constants.js'
import { matchPeerId } from '../fixtures/matchers.js'
import type { ConnectionManager } from '@libp2p/interface-internal'

describe('auto-dial', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p/test/connection-manager/dial-queue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env mocha */

import { CodeError } from '@libp2p/interface'
import { matchMultiaddr } from '@libp2p/interface-compliance-tests/matchers'
import { mockConnection, mockDuplex, mockMultiaddrConnection } from '@libp2p/interface-compliance-tests/mocks'
import { peerLogger } from '@libp2p/logger'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
Expand All @@ -12,7 +13,6 @@ import pDefer from 'p-defer'
import sinon from 'sinon'
import { type StubbedInstance, stubInterface } from 'sinon-ts'
import { DialQueue } from '../../src/connection-manager/dial-queue.js'
import { matchMultiaddr } from '../fixtures/matchers.js'
import type { ComponentLogger, Connection, ConnectionGater, PeerId, PeerRouting, PeerStore, Transport } from '@libp2p/interface'
import type { TransportManager } from '@libp2p/interface-internal'

Expand Down
11 changes: 0 additions & 11 deletions packages/libp2p/test/fixtures/matchers.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/libp2p/test/registrar/registrar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { yamux } from '@chainsafe/libp2p-yamux'
import { TypedEventEmitter, type TypedEventTarget, type Libp2pEvents, type ConnectionGater, type PeerId, type PeerStore, type Topology } from '@libp2p/interface'
import { matchPeerId } from '@libp2p/interface-compliance-tests/matchers'
import { mockDuplex, mockMultiaddrConnection, mockUpgrader, mockConnection } from '@libp2p/interface-compliance-tests/mocks'
import { defaultLogger } from '@libp2p/logger'
import { mplex } from '@libp2p/mplex'
Expand All @@ -17,7 +18,6 @@ import { type Components, defaultComponents } from '../../src/components.js'
import { DefaultConnectionManager } from '../../src/connection-manager/index.js'
import { createLibp2pNode, type Libp2pNode } from '../../src/libp2p.js'
import { DefaultRegistrar } from '../../src/registrar.js'
import { matchPeerId } from '../fixtures/matchers.js'
import type { ConnectionManager, Registrar, TransportManager } from '@libp2p/interface-internal'

const protocol = '/test/1.0.0'
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-identify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"wherearewe": "^2.0.1"
},
"devDependencies": {
"@libp2p/interface-compliance-tests": "^5.1.3",
"@libp2p/logger": "^4.0.5",
"@libp2p/peer-id-factory": "^4.0.5",
"aegir": "^42.0.0",
Expand All @@ -73,7 +74,6 @@
"it-pair": "^2.0.6",
"it-pushable": "^3.2.1",
"protons": "^7.3.0",
"sinon": "^17.0.1",
"sinon-ts": "^2.0.0"
},
"sideEffects": false
Expand Down
5 changes: 0 additions & 5 deletions packages/protocol-identify/test/fixtures/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import drain from 'it-drain'
import * as lp from 'it-length-prefixed'
import { pushable } from 'it-pushable'
import Sinon from 'sinon'
import { stubInterface, type StubbedInstance } from 'sinon-ts'
import { Uint8ArrayList } from 'uint8arraylist'
import { Identify as IdentifyMessage } from '../../src/pb/message.js'
import type { ComponentLogger, Libp2pEvents, NodeInfo, TypedEventTarget, PeerId, PeerStore, Connection, Stream } from '@libp2p/interface'
import type { AddressManager, ConnectionManager, Registrar } from '@libp2p/interface-internal'

export function matchPeerId (peerId: PeerId): Sinon.SinonMatcher {
return Sinon.match(p => p.toString() === peerId.toString())
}

export interface StubbedIdentifyComponents {
peerId: PeerId
peerStore: StubbedInstance<PeerStore>
Expand Down
3 changes: 2 additions & 1 deletion packages/protocol-identify/test/push.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TypedEventEmitter, start, stop } from '@libp2p/interface'
import { matchPeerId } from '@libp2p/interface-compliance-tests/matchers'
import { defaultLogger } from '@libp2p/logger'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { multiaddr } from '@multiformats/multiaddr'
Expand All @@ -8,7 +9,7 @@ import { pbStream } from 'it-protobuf-stream'
import { stubInterface } from 'sinon-ts'
import { Identify } from '../src/identify.js'
import { Identify as IdentifyMessage } from '../src/pb/message.js'
import { identifyPushStream, matchPeerId, type StubbedIdentifyComponents } from './fixtures/index.js'
import { identifyPushStream, type StubbedIdentifyComponents } from './fixtures/index.js'
import type { Libp2pEvents, PeerStore } from '@libp2p/interface'
import type { AddressManager, ConnectionManager, Registrar } from '@libp2p/interface-internal'

Expand Down
5 changes: 1 addition & 4 deletions packages/transport-circuit-relay-v2/test/hop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { TypedEventEmitter, type TypedEventTarget, type ComponentLogger, type Libp2pEvents, type Connection, type Stream, type ConnectionGater, type ContentRouting, type PeerId, type PeerStore, type Transport, type Upgrader } from '@libp2p/interface'
import { isStartable } from '@libp2p/interface'
import { matchPeerId } from '@libp2p/interface-compliance-tests/matchers'
import { mockRegistrar, mockUpgrader, mockNetwork, mockConnectionManager, mockConnectionGater } from '@libp2p/interface-compliance-tests/mocks'
import { defaultLogger } from '@libp2p/logger'
import { PeerMap } from '@libp2p/peer-collections'
Expand All @@ -17,10 +18,6 @@ import { HopMessage, Status } from '../src/pb/index.js'
import type { CircuitRelayServerInit } from '../src/server/index.js'
import type { AddressManager, ConnectionManager, Registrar, TransportManager } from '@libp2p/interface-internal'

export function matchPeerId (peerId: PeerId): Sinon.SinonMatcher {
return Sinon.match(p => p.toString() === peerId.toString())
}

interface Node {
peerId: PeerId
multiaddr: Multiaddr
Expand Down

0 comments on commit f4dda4a

Please sign in to comment.