Skip to content

Commit

Permalink
chore: do not reset sinon
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Nov 12, 2024
1 parent 4fc77af commit 594ecd6
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { peerIdFromString } from '@libp2p/peer-id'
import { debounce } from '@libp2p/utils/debounce'
import { multiaddr, protocols } from '@multiformats/multiaddr'
import { debounce } from './utils.js'
import type { ComponentLogger, Libp2pEvents, Logger, TypedEventTarget, PeerId, PeerStore } from '@libp2p/interface'
import type { AddressManager as AddressManagerInterface, TransportManager } from '@libp2p/interface-internal'
import type { Multiaddr } from '@multiformats/multiaddr'
Expand Down Expand Up @@ -84,6 +84,8 @@ export class AddressManager implements AddressManagerInterface {
private readonly announceFilter: AddressFilter
private readonly ipDomainMappings: Map<string, string>

private readonly where: Error

/**
* Responsible for managing the peer addresses.
* Peers can specify their listen and announce addresses.
Expand Down Expand Up @@ -113,6 +115,8 @@ export class AddressManager implements AddressManagerInterface {
components.events.addEventListener('transport:close', () => {
this._updatePeerStoreAddresses()
})

this.where = new Error('where')
}

readonly [Symbol.toStringTag] = '@libp2p/address-manager'
Expand Down
43 changes: 0 additions & 43 deletions packages/libp2p/src/address-manager/README.md

This file was deleted.

13 changes: 0 additions & 13 deletions packages/libp2p/src/address-manager/utils.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/libp2p/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { generateKeyPair } from '@libp2p/crypto/keys'
import { peerIdFromPrivateKey } from '@libp2p/peer-id'
import { validateConfig } from './config.js'
import { Libp2p as Libp2pClass } from './libp2p.js'
import type { AddressManagerInit, AddressFilter } from './address-manager/index.js'
import type { AddressManagerInit, AddressFilter } from './address-manager.js'
import type { Components } from './components.js'
import type { ConnectionManagerInit } from './connection-manager/index.js'
import type { ConnectionMonitorInit } from './connection-monitor.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p/src/libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isMultiaddr, type Multiaddr } from '@multiformats/multiaddr'
import { MemoryDatastore } from 'datastore-core/memory'
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { AddressManager } from './address-manager/index.js'
import { AddressManager } from './address-manager.js'
import { checkServiceDependencies, defaultComponents } from './components.js'
import { connectionGater } from './config/connection-gater.js'
import { DefaultConnectionManager } from './connection-manager/index.js'
Expand Down
6 changes: 3 additions & 3 deletions packages/libp2p/test/addresses/address-manager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-env mocha */

import { generateKeyPair } from '@libp2p/crypto/keys'
import { TypedEventEmitter, type TypedEventTarget, type Libp2pEvents, type PeerId, type PeerStore } from '@libp2p/interface'
import { TypedEventEmitter, type TypedEventTarget, type Libp2pEvents, type PeerId, type PeerStore, type Peer } from '@libp2p/interface'
import { defaultLogger } from '@libp2p/logger'
import { peerIdFromPrivateKey } from '@libp2p/peer-id'
import { multiaddr } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
import delay from 'delay'
import Sinon from 'sinon'
import { type StubbedInstance, stubInterface } from 'sinon-ts'
import { type AddressFilter, AddressManager } from '../../src/address-manager/index.js'
import { type AddressFilter, AddressManager } from '../../src/address-manager.js'
import type { TransportManager } from '@libp2p/interface-internal'

const listenAddresses = ['/ip4/127.0.0.1/tcp/15006/ws', '/ip4/127.0.0.1/tcp/15008/ws']
Expand All @@ -23,7 +23,7 @@ describe('Address Manager', () => {
beforeEach(async () => {
peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519'))
peerStore = stubInterface<PeerStore>({
patch: Sinon.stub().resolves({})
patch: Sinon.stub().resolves(stubInterface<Peer>())
})
events = new TypedEventEmitter()
})
Expand Down
2 changes: 0 additions & 2 deletions packages/libp2p/test/connection-manager/dial-queue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ describe('dial queue', () => {
if (dialer != null) {
dialer.stop()
}

sinon.reset()
})

it('should end when a single multiaddr dials succeeds', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { peerIdFromPrivateKey } from '@libp2p/peer-id'
import { expect } from 'aegir/chai'
import delay from 'delay'
import pRetry from 'p-retry'
import sinon from 'sinon'
import Sinon from 'sinon'
import { type StubbedInstance, stubInterface } from 'sinon-ts'
import { ReconnectQueue } from '../../src/connection-manager/reconnect-queue.js'
import type { ComponentLogger, Libp2pEvents, PeerStore, TypedEventTarget, Peer } from '@libp2p/interface'
Expand All @@ -28,15 +28,15 @@ describe('reconnect queue', () => {
components = {
connectionManager: stubInterface(),
events: new TypedEventEmitter<Libp2pEvents>(),
peerStore: stubInterface<PeerStore>(),
peerStore: stubInterface<PeerStore>({
all: Sinon.stub().resolves([])
}),
logger: peerLogger(peerId)
}
})

afterEach(async () => {
await stop(queue)

sinon.reset()
})

it('should reconnect to KEEP_ALIVE peers on startup', async () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/libp2p/test/peer-discovery/peer-discovery.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ describe('peer discovery', () => {
if (libp2p != null) {
await libp2p.stop()
}

sinon.reset()
})

it('should start/stop startable discovery on libp2p start/stop', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p/test/transports/transport-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { pEvent } from 'p-event'
import pWaitFor from 'p-wait-for'
import Sinon from 'sinon'
import { stubInterface } from 'sinon-ts'
import { AddressManager } from '../../src/address-manager/index.js'
import { AddressManager } from '../../src/address-manager.js'
import { DefaultTransportManager } from '../../src/transport-manager.js'
import type { Components } from '../../src/components.js'
import type { Connection, Transport, Upgrader, Listener } from '@libp2p/interface'
Expand Down

0 comments on commit 594ecd6

Please sign in to comment.