Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove peer id fixtures #1795

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { webSockets } from '@libp2p/websockets'
import { mplex } from '@libp2p/mplex'
import { noise } from '@chainsafe/libp2p-noise'
import { pipe } from 'it-pipe'
import { createFromJSON } from '@libp2p/peer-id-factory'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { yamux } from '@chainsafe/libp2p-yamux'
import { WebSockets } from '@multiformats/mafmt'

/** @type {import('aegir').PartialOptions} */
export default {
Expand All @@ -14,22 +15,21 @@ export default {
before: async () => {
// use dynamic import because we only want to reference these files during the test run, e.g. after building
const { createLibp2p } = await import('./dist/src/index.js')
const { MULTIADDRS_WEBSOCKETS } = await import('./dist/test/fixtures/browser.js')
const { plaintext } = await import('./dist/src/insecure/index.js')
const { default: Peers } = await import('./dist/test/fixtures/peers.js')
const { circuitRelayServer, circuitRelayTransport } = await import('./dist/src/circuit-relay/index.js')
const { identifyService } = await import('./dist/src/identify/index.js')
const { pingService } = await import('./dist/src/ping/index.js')
const { fetchService } = await import('./dist/src/fetch/index.js')

// Use the last peer
const peerId = await createFromJSON(Peers[Peers.length - 1])
const peerId = await createEd25519PeerId()
const libp2p = await createLibp2p({
connectionManager: {
inboundConnectionThreshold: Infinity
},
addresses: {
listen: [MULTIADDRS_WEBSOCKETS[0]]
listen: [
'/ip4/127.0.0.1/tcp/0/ws'
]
},
peerId,
transports: [
Expand Down Expand Up @@ -64,7 +64,7 @@ export default {
return {
libp2p,
env: {
RELAY_MULTIADDR: MULTIADDRS_WEBSOCKETS[0]
RELAY_MULTIADDR: libp2p.getMultiaddrs().filter(ma => WebSockets.matches(ma)).pop()
}
}
},
Expand Down
5 changes: 2 additions & 3 deletions test/addresses/address-manager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* eslint-env mocha */

import { EventEmitter } from '@libp2p/interfaces/events'
import { createFromJSON } from '@libp2p/peer-id-factory'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { multiaddr } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
import delay from 'delay'
import { type StubbedInstance, stubInterface } from 'sinon-ts'
import { type AddressFilter, DefaultAddressManager } from '../../src/address-manager/index.js'
import Peers from '../fixtures/peers.js'
import type { Libp2pEvents } from '@libp2p/interface-libp2p'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerStore } from '@libp2p/interface-peer-store'
Expand All @@ -22,7 +21,7 @@ describe('Address Manager', () => {
let events: EventEmitter<Libp2pEvents>

beforeEach(async () => {
peerId = await createFromJSON(Peers[0])
peerId = await createEd25519PeerId()
peerStore = stubInterface<PeerStore>({
// @ts-expect-error incorrect return type
patch: Promise.resolve({})
Expand Down
4 changes: 2 additions & 2 deletions test/configuration/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { mockConnectionGater } from '@libp2p/interface-mocks'
import { PubSubBaseProtocol, type PubSubComponents } from '@libp2p/pubsub'
import { webSockets } from '@libp2p/websockets'
import * as filters from '@libp2p/websockets/filters'
import { multiaddr } from '@multiformats/multiaddr'
import * as cborg from 'cborg'
import mergeOptions from 'merge-options'
import { circuitRelayTransport } from '../../src/circuit-relay/index.js'
import { plaintext } from '../../src/insecure/index.js'
import { MULTIADDRS_WEBSOCKETS } from '../fixtures/browser.js'
import type { Libp2pInit, Libp2pOptions } from '../../src/index.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { Message, PublishResult, PubSub, PubSubInit, PubSubRPC, PubSubRPCMessage } from '@libp2p/interface-pubsub'

const relayAddr = MULTIADDRS_WEBSOCKETS[0]
const relayAddr = multiaddr(process.env.RELAY_MULTIADDR)

export const baseOptions: Partial<Libp2pInit<{ pubsub: PubSub }>> = {
addresses: {
Expand Down
15 changes: 7 additions & 8 deletions test/connection-manager/direct.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AbortError } from '@libp2p/interfaces/errors'
import { EventEmitter } from '@libp2p/interfaces/events'
import { mplex } from '@libp2p/mplex'
import { peerIdFromString } from '@libp2p/peer-id'
import { createEd25519PeerId, createFromJSON } from '@libp2p/peer-id-factory'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { PersistentPeerStore } from '@libp2p/peer-store'
import { tcp } from '@libp2p/tcp'
import { multiaddr } from '@multiformats/multiaddr'
Expand All @@ -33,7 +33,6 @@ import { plaintext } from '../../src/insecure/index.js'
import { createLibp2pNode, type Libp2pNode } from '../../src/libp2p.js'
import { preSharedKey } from '../../src/pnet/index.js'
import { DefaultTransportManager } from '../../src/transport-manager.js'
import Peers from '../fixtures/peers.js'
import swarmKey from '../fixtures/swarm.key.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { TransportManager } from '@libp2p/interface-transport'
Expand All @@ -54,8 +53,8 @@ describe('dialing (direct, TCP)', () => {
beforeEach(async () => {
resolver = sinon.stub<[Multiaddr], Promise<string[]>>()
const [localPeerId, remotePeerId] = await Promise.all([
createFromJSON(Peers[0]),
createFromJSON(Peers[1])
createEd25519PeerId(),
createEd25519PeerId()
])

const remoteEvents = new EventEmitter()
Expand Down Expand Up @@ -151,7 +150,7 @@ describe('dialing (direct, TCP)', () => {

it('should fail to connect if peer has no known addresses', async () => {
const dialer = new DialQueue(localComponents)
const peerId = await createFromJSON(Peers[1])
const peerId = await createEd25519PeerId()

await expect(dialer.dial(peerId))
.to.eventually.be.rejectedWith(Error)
Expand Down Expand Up @@ -185,7 +184,7 @@ describe('dialing (direct, TCP)', () => {
it('should only try to connect to addresses supported by the transports configured', async () => {
const remoteAddrs = remoteTM.getAddrs()

const peerId = await createFromJSON(Peers[1])
const peerId = await createEd25519PeerId()
await localComponents.peerStore.patch(peerId, {
multiaddrs: [...remoteAddrs, unsupportedAddr]
})
Expand Down Expand Up @@ -306,8 +305,8 @@ describe('libp2p.dialer (direct, TCP)', () => {

beforeEach(async () => {
[peerId, remotePeerId] = await Promise.all([
createFromJSON(Peers[0]),
createFromJSON(Peers[1])
createEd25519PeerId(),
createEd25519PeerId()
])

remoteLibp2p = await createLibp2pNode({
Expand Down
15 changes: 7 additions & 8 deletions test/connection-manager/direct.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AbortError } from '@libp2p/interfaces/errors'
import { EventEmitter } from '@libp2p/interfaces/events'
import { mplex } from '@libp2p/mplex'
import { peerIdFromString } from '@libp2p/peer-id'
import { createFromJSON } from '@libp2p/peer-id-factory'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { PersistentPeerStore } from '@libp2p/peer-store'
import { publicAddressesFirst } from '@libp2p/utils/address-sort'
import { webSockets } from '@libp2p/websockets'
Expand All @@ -26,8 +26,6 @@ import { identifyService } from '../../src/identify/index.js'
import { createLibp2p } from '../../src/index.js'
import { plaintext } from '../../src/insecure/index.js'
import { DefaultTransportManager } from '../../src/transport-manager.js'
import { MULTIADDRS_WEBSOCKETS } from '../fixtures/browser.js'
import Peers from '../fixtures/peers.js'
import { createPeerId } from '../utils/creators/peer.js'
import type { DefaultIdentifyService } from '../../src/identify/identify.js'
import type { Connection } from '@libp2p/interface-connection'
Expand All @@ -37,6 +35,7 @@ import type { TransportManager } from '@libp2p/interface-transport'
import type { Multiaddr } from '@multiformats/multiaddr'

const unsupportedAddr = multiaddr('/ip4/127.0.0.1/tcp/9999')
const relayMultiaddr = multiaddr(process.env.RELAY_MULTIADDR)

describe('dialing (direct, WebSockets)', () => {
let localTM: TransportManager
Expand All @@ -48,7 +47,7 @@ describe('dialing (direct, WebSockets)', () => {
beforeEach(async () => {
const localEvents = new EventEmitter()
localComponents = defaultComponents({
peerId: await createFromJSON(Peers[0]),
peerId: await createEd25519PeerId(),
datastore: new MemoryDatastore(),
upgrader: mockUpgrader({ events: localEvents }),
connectionGater: mockConnectionGater(),
Expand All @@ -69,7 +68,7 @@ describe('dialing (direct, WebSockets)', () => {
localComponents.transportManager = localTM

// this peer is spun up in .aegir.cjs
remoteAddr = MULTIADDRS_WEBSOCKETS[0]
remoteAddr = relayMultiaddr
remoteComponents = defaultComponents({
peerId: peerIdFromString(remoteAddr.getPeerId() ?? '')
})
Expand Down Expand Up @@ -389,7 +388,7 @@ describe('libp2p.dialer (direct, WebSockets)', () => {

await libp2p.start()

const connection = await libp2p.dial(MULTIADDRS_WEBSOCKETS[0])
const connection = await libp2p.dial(relayMultiaddr)
expect(connection).to.exist()

// Wait for connection event to be emitted
Expand Down Expand Up @@ -423,7 +422,7 @@ describe('libp2p.dialer (direct, WebSockets)', () => {

await libp2p.start()

const connection = await libp2p.dial(MULTIADDRS_WEBSOCKETS[0])
const connection = await libp2p.dial(relayMultiaddr)
expect(connection).to.exist()
expect(connection.stat.timeline.close).to.not.exist()

Expand Down Expand Up @@ -451,7 +450,7 @@ describe('libp2p.dialer (direct, WebSockets)', () => {
connectionGater: mockConnectionGater()
})

await libp2p.hangUp(MULTIADDRS_WEBSOCKETS[0])
await libp2p.hangUp(relayMultiaddr)
})

it('should fail to dial self', async () => {
Expand Down
20 changes: 5 additions & 15 deletions test/connection-manager/resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { yamux } from '@chainsafe/libp2p-yamux'
import { mockConnection, mockConnectionGater, mockDuplex, mockMultiaddrConnection } from '@libp2p/interface-mocks'
import { mplex } from '@libp2p/mplex'
import { peerIdFromString } from '@libp2p/peer-id'
import { createFromJSON } from '@libp2p/peer-id-factory'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { webSockets } from '@libp2p/websockets'
import * as filters from '@libp2p/websockets/filters'
import { multiaddr } from '@multiformats/multiaddr'
Expand All @@ -16,12 +16,11 @@ import { circuitRelayServer, type CircuitRelayService, circuitRelayTransport } f
import { codes as ErrorCodes } from '../../src/errors.js'
import { plaintext } from '../../src/insecure/index.js'
import { createLibp2pNode, type Libp2pNode } from '../../src/libp2p.js'
import { MULTIADDRS_WEBSOCKETS } from '../fixtures/browser.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { Transport } from '@libp2p/interface-transport'
import type { Multiaddr } from '@multiformats/multiaddr'

const relayAddr = MULTIADDRS_WEBSOCKETS[0]
const relayAddr = multiaddr(process.env.RELAY_MULTIADDR)

const getDnsaddrStub = (peerId: PeerId): string[] => [
`/dnsaddr/ams-1.bootstrap.libp2p.io/p2p/${peerId.toString()}`,
Expand Down Expand Up @@ -117,10 +116,7 @@ describe('dialing (resolvable addresses)', () => {
})

it('resolves dnsaddr to ws local address', async () => {
const { default: Peers } = await import('../fixtures/peers.js')

// Use the last peer
const peerId = await createFromJSON(Peers[Peers.length - 1])
const peerId = await createEd25519PeerId()
// ensure remote libp2p creates reservation on relay
await remoteLibp2p.peerStore.merge(peerId, {
protocols: [RELAY_V2_HOP_CODEC]
Expand Down Expand Up @@ -150,10 +146,7 @@ describe('dialing (resolvable addresses)', () => {
const dialAddr = multiaddr(`/dnsaddr/remote.libp2p.io/p2p/${remoteId.toString()}`)
const relayedAddrFetched = multiaddr(relayedAddr(remoteId))

const { default: Peers } = await import('../fixtures/peers.js')

// Use the last peer
const relayId = await createFromJSON(Peers[Peers.length - 1])
const relayId = await createEd25519PeerId()
// ensure remote libp2p creates reservation on relay
await remoteLibp2p.peerStore.merge(relayId, {
protocols: [RELAY_V2_HOP_CODEC]
Expand Down Expand Up @@ -218,10 +211,7 @@ describe('dialing (resolvable addresses)', () => {
const dialAddr = multiaddr(`/dnsaddr/remote.libp2p.io/p2p/${remoteId.toString()}`)
const relayedAddrFetched = multiaddr(relayedAddr(remoteId))

const { default: Peers } = await import('../fixtures/peers.js')

// Use the last peer
const relayId = await createFromJSON(Peers[Peers.length - 1])
const relayId = await createEd25519PeerId()
// ensure remote libp2p creates reservation on relay
await remoteLibp2p.peerStore.merge(relayId, {
protocols: [RELAY_V2_HOP_CODEC]
Expand Down
5 changes: 2 additions & 3 deletions test/fetch/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { mockRegistrar, mockUpgrader, connectionPair } from '@libp2p/interface-mocks'
import { EventEmitter } from '@libp2p/interfaces/events'
import { start, stop } from '@libp2p/interfaces/startable'
import { createFromJSON } from '@libp2p/peer-id-factory'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { PersistentPeerStore } from '@libp2p/peer-store'
import { expect } from 'aegir/chai'
import { MemoryDatastore } from 'datastore-core'
Expand All @@ -14,7 +14,6 @@ import { stubInterface } from 'sinon-ts'
import { defaultComponents, type Components } from '../../src/components.js'
import { DefaultConnectionManager } from '../../src/connection-manager/index.js'
import { fetchService, type FetchServiceInit } from '../../src/fetch/index.js'
import Peers from '../fixtures/peers.js'
import type { ConnectionGater } from '@libp2p/interface-connection-gater'
import type { TransportManager } from '@libp2p/interface-transport'

Expand All @@ -26,7 +25,7 @@ const defaultInit: FetchServiceInit = {
}

async function createComponents (index: number): Promise<Components> {
const peerId = await createFromJSON(Peers[index])
const peerId = await createEd25519PeerId()

const events = new EventEmitter()
const components = defaultComponents({
Expand Down
6 changes: 0 additions & 6 deletions test/fixtures/browser.ts

This file was deleted.

25 changes: 0 additions & 25 deletions test/fixtures/peers.ts

This file was deleted.

5 changes: 2 additions & 3 deletions test/identify/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { mockConnectionGater, mockRegistrar, mockUpgrader, connectionPair } from '@libp2p/interface-mocks'
import { EventEmitter } from '@libp2p/interfaces/events'
import { start, stop } from '@libp2p/interfaces/startable'
import { createFromJSON } from '@libp2p/peer-id-factory'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record'
import { PersistentPeerStore } from '@libp2p/peer-store'
import { multiaddr } from '@multiformats/multiaddr'
Expand All @@ -31,7 +31,6 @@ import { DefaultIdentifyService } from '../../src/identify/identify.js'
import { identifyService, type IdentifyServiceInit, Message } from '../../src/identify/index.js'
import { Identify } from '../../src/identify/pb/message.js'
import { DefaultTransportManager } from '../../src/transport-manager.js'
import Peers from '../fixtures/peers.js'
import type { IncomingStreamData } from '@libp2p/interface-registrar'
import type { TransportManager } from '@libp2p/interface-transport'

Expand All @@ -50,7 +49,7 @@ const defaultInit: IdentifyServiceInit = {
const protocols = [MULTICODEC_IDENTIFY, MULTICODEC_IDENTIFY_PUSH]

async function createComponents (index: number): Promise<Components> {
const peerId = await createFromJSON(Peers[index])
const peerId = await createEd25519PeerId()

const events = new EventEmitter()
const components = defaultComponents({
Expand Down
5 changes: 2 additions & 3 deletions test/identify/push.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { mockConnectionGater, mockRegistrar, mockUpgrader, connectionPair } from '@libp2p/interface-mocks'
import { EventEmitter } from '@libp2p/interfaces/events'
import { start, stop } from '@libp2p/interfaces/startable'
import { createFromJSON } from '@libp2p/peer-id-factory'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { PersistentPeerStore } from '@libp2p/peer-store'
import { multiaddr } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
Expand All @@ -23,7 +23,6 @@ import {
} from '../../src/identify/consts.js'
import { DefaultIdentifyService } from '../../src/identify/identify.js'
import { DefaultTransportManager } from '../../src/transport-manager.js'
import Peers from '../fixtures/peers.js'
import type { IdentifyServiceInit } from '../../src/identify/index.js'
import type { TransportManager } from '@libp2p/interface-transport'

Expand All @@ -42,7 +41,7 @@ const defaultInit: IdentifyServiceInit = {
const protocols = [MULTICODEC_IDENTIFY, MULTICODEC_IDENTIFY_PUSH]

async function createComponents (index: number): Promise<Components> {
const peerId = await createFromJSON(Peers[index])
const peerId = await createEd25519PeerId()

const events = new EventEmitter()
const components = defaultComponents({
Expand Down
Loading