Skip to content

Commit 9f36bb2

Browse files
deps!: bump @libp2p/interface-peer-store from 1.2.9 to 2.0.0 (libp2p#171)
Bumps [@libp2p/interface-peer-store](https://github.com/libp2p/js-libp2p-interfaces) from 1.2.9 to 2.0.0. - [Release notes](https://github.com/libp2p/js-libp2p-interfaces/releases) - [Commits](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/interface-peer-store-v1.2.9...@libp2p/interface-peer-store-v2.0.0) --- updated-dependencies: - dependency-name: "@libp2p/interface-peer-store" dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: achingbrain <[email protected]>
1 parent 6d1b65a commit 9f36bb2

File tree

4 files changed

+32
-36
lines changed

4 files changed

+32
-36
lines changed

package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
"dependencies": {
142142
"@libp2p/interface-peer-discovery": "^1.0.1",
143143
"@libp2p/interface-peer-info": "^1.0.7",
144-
"@libp2p/interface-peer-store": "^1.2.2",
144+
"@libp2p/interface-peer-store": "^2.0.0",
145145
"@libp2p/interfaces": "^3.0.3",
146146
"@libp2p/logger": "^2.0.1",
147147
"@libp2p/peer-id": "^2.0.0",
@@ -151,10 +151,7 @@
151151
"devDependencies": {
152152
"@libp2p/interface-peer-discovery-compliance-tests": "^2.0.0",
153153
"@libp2p/interface-peer-id": "^2.0.0",
154-
"@libp2p/peer-id-factory": "^2.0.0",
155-
"@libp2p/peer-store": "^7.0.0",
156154
"aegir": "^38.1.7",
157-
"datastore-core": "^9.0.3",
158-
"delay": "^5.0.0"
155+
"sinon-ts": "^1.0.0"
159156
}
160157
}

src/index.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { multiaddr } from '@multiformats/multiaddr'
22
import { P2P } from '@multiformats/mafmt'
3-
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
3+
import { EventEmitter } from '@libp2p/interfaces/events'
44
import { logger } from '@libp2p/logger'
55
import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery'
66
import type { PeerInfo } from '@libp2p/interface-peer-info'
@@ -133,17 +133,21 @@ class Bootstrap extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscove
133133
}
134134

135135
for (const peerData of this.list) {
136-
await this.components.peerStore.tagPeer(peerData.id, this._init.tagName ?? DEFAULT_BOOTSTRAP_TAG_NAME, {
137-
value: this._init.tagValue ?? DEFAULT_BOOTSTRAP_TAG_VALUE,
138-
ttl: this._init.tagTTL ?? DEFAULT_BOOTSTRAP_TAG_TTL
136+
await this.components.peerStore.merge(peerData.id, {
137+
tags: {
138+
[this._init.tagName ?? DEFAULT_BOOTSTRAP_TAG_NAME]: {
139+
value: this._init.tagValue ?? DEFAULT_BOOTSTRAP_TAG_VALUE,
140+
ttl: this._init.tagTTL ?? DEFAULT_BOOTSTRAP_TAG_TTL
141+
}
142+
}
139143
})
140144

141145
// check we are still running
142146
if (this.timer == null) {
143147
return
144148
}
145149

146-
this.dispatchEvent(new CustomEvent<PeerInfo>('peer', { detail: peerData }))
150+
this.safeDispatchEvent('peer', { detail: peerData })
147151
}
148152
}
149153

test/bootstrap.spec.ts

+18-19
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@ import { bootstrap, BootstrapComponents } from '../src/index.js'
66
import peerList from './fixtures/default-peers.js'
77
import partialValidPeerList from './fixtures/some-invalid-peers.js'
88
import { isPeerId } from '@libp2p/interface-peer-id'
9-
import { PersistentPeerStore } from '@libp2p/peer-store'
10-
import { MemoryDatastore } from 'datastore-core'
119
import { multiaddr } from '@multiformats/multiaddr'
1210
import { peerIdFromString } from '@libp2p/peer-id'
13-
import delay from 'delay'
1411
import { start, stop } from '@libp2p/interfaces/startable'
15-
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
12+
import { StubbedInstance, stubInterface } from 'sinon-ts'
13+
import type { PeerStore } from '@libp2p/interface-peer-store'
1614

1715
describe('bootstrap', () => {
1816
let components: BootstrapComponents
17+
let peerStore: StubbedInstance<PeerStore>
1918

2019
beforeEach(async () => {
20+
peerStore = stubInterface<PeerStore>()
21+
2122
components = {
22-
peerStore: new PersistentPeerStore({
23-
peerId: await createEd25519PeerId(),
24-
datastore: new MemoryDatastore()
25-
})
23+
peerStore
2624
}
2725
})
2826

@@ -83,17 +81,18 @@ describe('bootstrap', () => {
8381

8482
const bootstrapper0PeerId = peerIdFromString(bootstrapper0PeerIdStr)
8583

86-
const tags = await components.peerStore.getTags(bootstrapper0PeerId)
87-
88-
expect(tags).to.have.lengthOf(1, 'bootstrap tag was not set')
89-
expect(tags).to.have.nested.property('[0].name', tagName, 'bootstrap tag had incorrect name')
90-
expect(tags).to.have.nested.property('[0].value', tagValue, 'bootstrap tag had incorrect value')
91-
92-
await delay(tagTTL * 2)
93-
94-
const tags2 = await components.peerStore.getTags(bootstrapper0PeerId)
95-
96-
expect(tags2).to.have.lengthOf(0, 'bootstrap tag did not expire')
84+
expect(peerStore.merge).to.have.property('called', true)
85+
86+
const call = peerStore.merge.getCall(0)
87+
expect(call).to.have.deep.nested.property('args[0]', bootstrapper0PeerId)
88+
expect(call).to.have.deep.nested.property('args[1]', {
89+
tags: {
90+
[tagName]: {
91+
value: tagValue,
92+
ttl: tagTTL
93+
}
94+
}
95+
})
9796

9897
await stop(r)
9998
})

test/compliance.spec.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@
33
import tests from '@libp2p/interface-peer-discovery-compliance-tests'
44
import { bootstrap } from '../src/index.js'
55
import peerList from './fixtures/default-peers.js'
6-
import { PersistentPeerStore } from '@libp2p/peer-store'
7-
import { MemoryDatastore } from 'datastore-core'
8-
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
6+
import type { PeerStore } from '@libp2p/interface-peer-store'
7+
import { stubInterface } from 'sinon-ts'
98

109
describe('compliance tests', () => {
1110
tests({
1211
async setup () {
1312
const components = {
14-
peerStore: new PersistentPeerStore({
15-
peerId: await createEd25519PeerId(),
16-
datastore: new MemoryDatastore()
17-
})
13+
peerStore: stubInterface<PeerStore>()
1814
}
1915

2016
return bootstrap({

0 commit comments

Comments
 (0)