@libp2p/interface-compliance-tests 1.1.21 → 1.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/src/pubsub/api.d.ts +2 -2
  2. package/dist/src/pubsub/api.d.ts.map +1 -1
  3. package/dist/src/pubsub/api.js +10 -8
  4. package/dist/src/pubsub/api.js.map +1 -1
  5. package/dist/src/pubsub/connection-handlers.d.ts +2 -2
  6. package/dist/src/pubsub/connection-handlers.d.ts.map +1 -1
  7. package/dist/src/pubsub/connection-handlers.js +41 -27
  8. package/dist/src/pubsub/connection-handlers.js.map +1 -1
  9. package/dist/src/pubsub/emit-self.d.ts +2 -2
  10. package/dist/src/pubsub/emit-self.d.ts.map +1 -1
  11. package/dist/src/pubsub/emit-self.js +12 -7
  12. package/dist/src/pubsub/emit-self.js.map +1 -1
  13. package/dist/src/pubsub/index.d.ts +2 -3
  14. package/dist/src/pubsub/index.d.ts.map +1 -1
  15. package/dist/src/pubsub/index.js.map +1 -1
  16. package/dist/src/pubsub/messages.d.ts +2 -2
  17. package/dist/src/pubsub/messages.d.ts.map +1 -1
  18. package/dist/src/pubsub/messages.js +8 -66
  19. package/dist/src/pubsub/messages.js.map +1 -1
  20. package/dist/src/pubsub/multiple-nodes.d.ts +2 -2
  21. package/dist/src/pubsub/multiple-nodes.d.ts.map +1 -1
  22. package/dist/src/pubsub/multiple-nodes.js +109 -53
  23. package/dist/src/pubsub/multiple-nodes.js.map +1 -1
  24. package/dist/src/pubsub/two-nodes.d.ts +2 -2
  25. package/dist/src/pubsub/two-nodes.d.ts.map +1 -1
  26. package/dist/src/pubsub/two-nodes.js +40 -55
  27. package/dist/src/pubsub/two-nodes.js.map +1 -1
  28. package/dist/src/pubsub/utils.d.ts +3 -2
  29. package/dist/src/pubsub/utils.d.ts.map +1 -1
  30. package/dist/src/pubsub/utils.js +2 -2
  31. package/dist/src/pubsub/utils.js.map +1 -1
  32. package/package.json +2 -4
  33. package/src/pubsub/api.ts +11 -10
  34. package/src/pubsub/connection-handlers.ts +53 -39
  35. package/src/pubsub/emit-self.ts +15 -10
  36. package/src/pubsub/index.ts +2 -3
  37. package/src/pubsub/messages.ts +11 -90
  38. package/src/pubsub/multiple-nodes.ts +120 -66
  39. package/src/pubsub/two-nodes.ts +47 -66
  40. package/src/pubsub/utils.ts +5 -5
@@ -7,27 +7,25 @@ import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
7
7
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
8
8
  import { createEd25519PeerId } from '@libp2p/peer-id-factory'
9
9
  import { connectPeers, mockRegistrar } from '../mocks/registrar.js'
10
- import { CustomEvent } from '@libp2p/interfaces'
11
10
  import { waitForSubscriptionUpdate } from './utils.js'
12
11
  import type { TestSetup } from '../index.js'
13
- import type { Message } from '@libp2p/interfaces/pubsub'
12
+ import type { Message, PubSub } from '@libp2p/interfaces/pubsub'
14
13
  import type { PubSubArgs } from './index.js'
15
14
  import type { PeerId } from '@libp2p/interfaces/peer-id'
16
15
  import type { Registrar } from '@libp2p/interfaces/registrar'
17
- import type { PubSubBaseProtocol } from '@libp2p/pubsub'
18
16
  import { Components } from '@libp2p/interfaces/components'
19
17
  import { start, stop } from '../index.js'
20
18
 
21
- export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
19
+ export default (common: TestSetup<PubSub, PubSubArgs>) => {
22
20
  describe('pubsub with multiple nodes', function () {
23
21
  describe('every peer subscribes to the topic', () => {
24
22
  describe('line', () => {
25
23
  // line
26
24
  // ◉────◉────◉
27
25
  // a b c
28
- let psA: PubSubBaseProtocol
29
- let psB: PubSubBaseProtocol
30
- let psC: PubSubBaseProtocol
26
+ let psA: PubSub
27
+ let psB: PubSub
28
+ let psC: PubSub
31
29
  let peerIdA: PeerId
32
30
  let peerIdB: PeerId
33
31
  let peerIdC: PeerId
@@ -116,7 +114,7 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
116
114
  psA.subscribe(topic)
117
115
  expect(psA.getTopics()).to.deep.equal([topic])
118
116
 
119
- await waitForSubscriptionUpdate(psB, psA)
117
+ await waitForSubscriptionUpdate(psB, peerIdA)
120
118
 
121
119
  expect(psB.getPeers().length).to.equal(2)
122
120
  expect(psB.getSubscribers(topic).map(p => p.toString())).to.deep.equal([peerIdA.toString()])
@@ -131,8 +129,8 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
131
129
  expect(psB.getTopics()).to.deep.equal([topic])
132
130
 
133
131
  await Promise.all([
134
- waitForSubscriptionUpdate(psA, psB),
135
- waitForSubscriptionUpdate(psC, psB)
132
+ waitForSubscriptionUpdate(psA, peerIdB),
133
+ waitForSubscriptionUpdate(psC, peerIdB)
136
134
  ])
137
135
 
138
136
  expect(psA.getPeers().length).to.equal(1)
@@ -149,7 +147,7 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
149
147
  psC.subscribe(topic)
150
148
  expect(psC.getTopics()).to.deep.equal([topic])
151
149
 
152
- psB.addEventListener('pubsub:subscription-change', () => {
150
+ psB.addEventListener('subscription-change', () => {
153
151
  expect(psA.getPeers().length).to.equal(1)
154
152
  expect(psB.getPeers().length).to.equal(2)
155
153
  expect(psB.getSubscribers(topic).map(p => p.toString())).to.deep.equal([peerIdC.toString()])
@@ -172,17 +170,29 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
172
170
 
173
171
  let counter = 0
174
172
 
175
- psA.addEventListener(topic, incMsg)
176
- psB.addEventListener(topic, incMsg)
177
- psC.addEventListener(topic, incMsg)
173
+ psA.addEventListener('message', (evt) => {
174
+ if (evt.detail.topic === topic) {
175
+ incMsg(evt)
176
+ }
177
+ })
178
+ psB.addEventListener('message', (evt) => {
179
+ if (evt.detail.topic === topic) {
180
+ incMsg(evt)
181
+ }
182
+ })
183
+ psC.addEventListener('message', (evt) => {
184
+ if (evt.detail.topic === topic) {
185
+ incMsg(evt)
186
+ }
187
+ })
178
188
 
179
189
  await Promise.all([
180
- waitForSubscriptionUpdate(psA, psB),
181
- waitForSubscriptionUpdate(psB, psA),
182
- waitForSubscriptionUpdate(psC, psB)
190
+ waitForSubscriptionUpdate(psA, peerIdB),
191
+ waitForSubscriptionUpdate(psB, peerIdA),
192
+ waitForSubscriptionUpdate(psC, peerIdB)
183
193
  ])
184
194
 
185
- void psA.dispatchEvent(new CustomEvent<Uint8Array>(topic, { detail: uint8ArrayFromString('hey') }))
195
+ psA.publish(topic, uint8ArrayFromString('hey'))
186
196
 
187
197
  function incMsg (evt: CustomEvent<Message>) {
188
198
  const msg = evt.detail
@@ -192,9 +202,21 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
192
202
 
193
203
  function check () {
194
204
  if (++counter === 3) {
195
- psA.removeEventListener(topic, incMsg)
196
- psB.removeEventListener(topic, incMsg)
197
- psC.removeEventListener(topic, incMsg)
205
+ psA.removeEventListener('message', (evt) => {
206
+ if (evt.detail.topic === topic) {
207
+ incMsg(evt)
208
+ }
209
+ })
210
+ psB.removeEventListener('message', (evt) => {
211
+ if (evt.detail.topic === topic) {
212
+ incMsg(evt)
213
+ }
214
+ })
215
+ psC.removeEventListener('message', (evt) => {
216
+ if (evt.detail.topic === topic) {
217
+ incMsg(evt)
218
+ }
219
+ })
198
220
  defer.resolve()
199
221
  }
200
222
  }
@@ -216,34 +238,33 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
216
238
  const defer = pDefer()
217
239
  let counter = 0
218
240
 
241
+ psA.addEventListener('message', (evt) => {
242
+ if (evt.detail.topic === topic) {
243
+ incMsg(evt)
244
+ }
245
+ })
246
+ psB.addEventListener('message', (evt) => {
247
+ if (evt.detail.topic === topic) {
248
+ incMsg(evt)
249
+ }
250
+ })
251
+ psC.addEventListener('message', (evt) => {
252
+ if (evt.detail.topic === topic) {
253
+ incMsg(evt)
254
+ }
255
+ })
256
+
219
257
  psA.subscribe(topic)
220
258
  psB.subscribe(topic)
221
259
  psC.subscribe(topic)
222
260
 
223
- // await subscription change
224
- await Promise.all([
225
- new Promise(resolve => psA.addEventListener('pubsub:subscription-change', () => resolve(null), {
226
- once: true
227
- })),
228
- new Promise(resolve => psB.addEventListener('pubsub:subscription-change', () => resolve(null), {
229
- once: true
230
- })),
231
- new Promise(resolve => psC.addEventListener('pubsub:subscription-change', () => resolve(null), {
232
- once: true
233
- }))
234
- ])
235
-
236
- psA.addEventListener(topic, incMsg)
237
- psB.addEventListener(topic, incMsg)
238
- psC.addEventListener(topic, incMsg)
239
-
240
261
  await Promise.all([
241
- waitForSubscriptionUpdate(psA, psB),
242
- waitForSubscriptionUpdate(psB, psA),
243
- waitForSubscriptionUpdate(psC, psB)
262
+ waitForSubscriptionUpdate(psA, peerIdB),
263
+ waitForSubscriptionUpdate(psB, peerIdA),
264
+ waitForSubscriptionUpdate(psC, peerIdB)
244
265
  ])
245
266
 
246
- void psB.dispatchEvent(new CustomEvent<Uint8Array>(topic, { detail: uint8ArrayFromString('hey') }))
267
+ psB.publish(topic, uint8ArrayFromString('hey'))
247
268
 
248
269
  function incMsg (evt: CustomEvent<Message>) {
249
270
  const msg = evt.detail
@@ -253,9 +274,21 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
253
274
 
254
275
  function check () {
255
276
  if (++counter === 3) {
256
- psA.removeEventListener(topic, incMsg)
257
- psB.removeEventListener(topic, incMsg)
258
- psC.removeEventListener(topic, incMsg)
277
+ psA.removeEventListener('message', (evt) => {
278
+ if (evt.detail.topic === topic) {
279
+ incMsg(evt)
280
+ }
281
+ })
282
+ psB.removeEventListener('message', (evt) => {
283
+ if (evt.detail.topic === topic) {
284
+ incMsg(evt)
285
+ }
286
+ })
287
+ psC.removeEventListener('message', (evt) => {
288
+ if (evt.detail.topic === topic) {
289
+ incMsg(evt)
290
+ }
291
+ })
259
292
  defer.resolve()
260
293
  }
261
294
  }
@@ -273,11 +306,11 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
273
306
  // │b d│
274
307
  // ◉─┘ └─◉
275
308
  // a
276
- let psA: PubSubBaseProtocol
277
- let psB: PubSubBaseProtocol
278
- let psC: PubSubBaseProtocol
279
- let psD: PubSubBaseProtocol
280
- let psE: PubSubBaseProtocol
309
+ let psA: PubSub
310
+ let psB: PubSub
311
+ let psC: PubSub
312
+ let psD: PubSub
313
+ let psE: PubSub
281
314
  let peerIdA: PeerId
282
315
  let peerIdB: PeerId
283
316
  let peerIdC: PeerId
@@ -415,27 +448,48 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
415
448
  it('publishes from c', async function () {
416
449
  const defer = pDefer()
417
450
  let counter = 0
451
+ const topic = 'Z'
418
452
 
419
- psA.subscribe('Z')
420
- psA.addEventListener('Z', incMsg)
421
- psB.subscribe('Z')
422
- psB.addEventListener('Z', incMsg)
423
- psC.subscribe('Z')
424
- psC.addEventListener('Z', incMsg)
425
- psD.subscribe('Z')
426
- psD.addEventListener('Z', incMsg)
427
- psE.subscribe('Z')
428
- psE.addEventListener('Z', incMsg)
453
+ psA.subscribe(topic)
454
+ psA.addEventListener('message', (evt) => {
455
+ if (evt.detail.topic === topic) {
456
+ incMsg(evt)
457
+ }
458
+ })
459
+ psB.subscribe(topic)
460
+ psB.addEventListener('message', (evt) => {
461
+ if (evt.detail.topic === topic) {
462
+ incMsg(evt)
463
+ }
464
+ })
465
+ psC.subscribe(topic)
466
+ psC.addEventListener('message', (evt) => {
467
+ if (evt.detail.topic === topic) {
468
+ incMsg(evt)
469
+ }
470
+ })
471
+ psD.subscribe(topic)
472
+ psD.addEventListener('message', (evt) => {
473
+ if (evt.detail.topic === topic) {
474
+ incMsg(evt)
475
+ }
476
+ })
477
+ psE.subscribe(topic)
478
+ psE.addEventListener('message', (evt) => {
479
+ if (evt.detail.topic === topic) {
480
+ incMsg(evt)
481
+ }
482
+ })
429
483
 
430
484
  await Promise.all([
431
- waitForSubscriptionUpdate(psA, psB),
432
- waitForSubscriptionUpdate(psB, psA),
433
- waitForSubscriptionUpdate(psC, psB),
434
- waitForSubscriptionUpdate(psD, psC),
435
- waitForSubscriptionUpdate(psE, psD)
485
+ waitForSubscriptionUpdate(psA, peerIdB),
486
+ waitForSubscriptionUpdate(psB, peerIdA),
487
+ waitForSubscriptionUpdate(psC, peerIdB),
488
+ waitForSubscriptionUpdate(psD, peerIdC),
489
+ waitForSubscriptionUpdate(psE, peerIdD)
436
490
  ])
437
491
 
438
- void psC.dispatchEvent(new CustomEvent<Uint8Array>('Z', { detail: uint8ArrayFromString('hey from c') }))
492
+ psC.publish('Z', uint8ArrayFromString('hey from c'))
439
493
 
440
494
  function incMsg (evt: CustomEvent<Message>) {
441
495
  const msg = evt.detail
@@ -7,14 +7,12 @@ import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
7
7
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
8
8
  import { connectPeers, mockRegistrar } from '../mocks/registrar.js'
9
9
  import { createEd25519PeerId } from '@libp2p/peer-id-factory'
10
- import { CustomEvent } from '@libp2p/interfaces'
11
10
  import { waitForSubscriptionUpdate } from './utils.js'
12
11
  import type { TestSetup } from '../index.js'
13
- import type { Message } from '@libp2p/interfaces/pubsub'
12
+ import type { Message, PubSub } from '@libp2p/interfaces/pubsub'
14
13
  import type { PubSubArgs } from './index.js'
15
14
  import type { PeerId } from '@libp2p/interfaces/peer-id'
16
15
  import type { Registrar } from '@libp2p/interfaces/registrar'
17
- import type { PubSubBaseProtocol } from '@libp2p/pubsub'
18
16
  import { Components } from '@libp2p/interfaces/components'
19
17
  import { start, stop } from '../index.js'
20
18
 
@@ -24,10 +22,10 @@ function shouldNotHappen () {
24
22
  expect.fail()
25
23
  }
26
24
 
27
- export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
25
+ export default (common: TestSetup<PubSub, PubSubArgs>) => {
28
26
  describe('pubsub with two nodes', () => {
29
- let psA: PubSubBaseProtocol
30
- let psB: PubSubBaseProtocol
27
+ let psA: PubSub
28
+ let psB: PubSub
31
29
  let peerIdA: PeerId
32
30
  let peerIdB: PeerId
33
31
  let registrarA: Registrar
@@ -89,7 +87,7 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
89
87
  it('Subscribe to a topic in nodeA', async () => {
90
88
  const defer = pDefer()
91
89
 
92
- psB.addEventListener('pubsub:subscription-change', (evt) => {
90
+ psB.addEventListener('subscription-change', (evt) => {
93
91
  const { peerId: changedPeerId, subscriptions: changedSubs } = evt.detail
94
92
  expect(psA.getTopics()).to.deep.equal([topic])
95
93
  expect(psB.getPeers()).to.have.lengthOf(1)
@@ -110,25 +108,26 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
110
108
  it('Publish to a topic in nodeA', async () => {
111
109
  const defer = pDefer()
112
110
 
113
- psA.addEventListener(topic, (evt) => {
114
- const msg = evt.detail
115
- expect(uint8ArrayToString(msg.data)).to.equal('hey')
116
- psB.removeEventListener(topic, shouldNotHappen)
117
- defer.resolve()
111
+ psA.addEventListener('message', (evt) => {
112
+ if (evt.detail.topic === topic) {
113
+ const msg = evt.detail
114
+ expect(uint8ArrayToString(msg.data)).to.equal('hey')
115
+ psB.removeEventListener('message', shouldNotHappen)
116
+ defer.resolve()
117
+ }
118
118
  }, {
119
119
  once: true
120
120
  })
121
121
 
122
- psB.addEventListener(topic, shouldNotHappen, {
123
- once: true
124
- })
122
+ psA.subscribe(topic)
123
+ psB.subscribe(topic)
125
124
 
126
125
  await Promise.all([
127
- waitForSubscriptionUpdate(psA, psB),
128
- waitForSubscriptionUpdate(psB, psA)
126
+ waitForSubscriptionUpdate(psA, peerIdB),
127
+ waitForSubscriptionUpdate(psB, peerIdA)
129
128
  ])
130
129
 
131
- void psA.dispatchEvent(new CustomEvent<Uint8Array>(topic, { detail: uint8ArrayFromString('hey') }))
130
+ psA.publish(topic, uint8ArrayFromString('hey'))
132
131
 
133
132
  return await defer.promise
134
133
  })
@@ -136,16 +135,24 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
136
135
  it('Publish to a topic in nodeB', async () => {
137
136
  const defer = pDefer()
138
137
 
139
- psA.addEventListener(topic, (evt) => {
138
+ psA.addEventListener('message', (evt) => {
139
+ if (evt.detail.topic !== topic) {
140
+ return
141
+ }
142
+
140
143
  const msg = evt.detail
141
- psA.addEventListener(topic, shouldNotHappen, {
144
+ psA.addEventListener('message', (evt) => {
145
+ if (evt.detail.topic === topic) {
146
+ shouldNotHappen()
147
+ }
148
+ }, {
142
149
  once: true
143
150
  })
144
151
  expect(uint8ArrayToString(msg.data)).to.equal('banana')
145
152
 
146
153
  setTimeout(() => {
147
- psA.removeEventListener(topic, shouldNotHappen)
148
- psB.removeEventListener(topic, shouldNotHappen)
154
+ psA.removeEventListener('message')
155
+ psB.removeEventListener('message')
149
156
 
150
157
  defer.resolve()
151
158
  }, 100)
@@ -153,16 +160,17 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
153
160
  once: true
154
161
  })
155
162
 
156
- psB.addEventListener(topic, shouldNotHappen, {
157
- once: true
158
- })
163
+ psB.addEventListener('message', shouldNotHappen)
164
+
165
+ psA.subscribe(topic)
166
+ psB.subscribe(topic)
159
167
 
160
168
  await Promise.all([
161
- waitForSubscriptionUpdate(psA, psB),
162
- waitForSubscriptionUpdate(psB, psA)
169
+ waitForSubscriptionUpdate(psA, peerIdB),
170
+ waitForSubscriptionUpdate(psB, peerIdA)
163
171
  ])
164
172
 
165
- void psB.dispatchEvent(new CustomEvent<Uint8Array>(topic, { detail: uint8ArrayFromString('banana') }))
173
+ psB.publish(topic, uint8ArrayFromString('banana'))
166
174
 
167
175
  return await defer.promise
168
176
  })
@@ -171,10 +179,8 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
171
179
  const defer = pDefer()
172
180
  let counter = 0
173
181
 
174
- psB.addEventListener(topic, shouldNotHappen, {
175
- once: true
176
- })
177
- psA.addEventListener(topic, receivedMsg)
182
+ psB.addEventListener('message', shouldNotHappen)
183
+ psA.addEventListener('message', receivedMsg)
178
184
 
179
185
  function receivedMsg (evt: CustomEvent<Message>) {
180
186
  const msg = evt.detail
@@ -184,19 +190,22 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
184
190
  expect(msg.topic).to.be.equal(topic)
185
191
 
186
192
  if (++counter === 10) {
187
- psA.removeEventListener(topic, receivedMsg)
188
- psB.removeEventListener(topic, shouldNotHappen)
193
+ psA.removeEventListener('message', receivedMsg)
194
+ psB.removeEventListener('message', shouldNotHappen)
189
195
 
190
196
  defer.resolve()
191
197
  }
192
198
  }
193
199
 
200
+ psA.subscribe(topic)
201
+ psB.subscribe(topic)
202
+
194
203
  await Promise.all([
195
- waitForSubscriptionUpdate(psA, psB),
196
- waitForSubscriptionUpdate(psB, psA)
204
+ waitForSubscriptionUpdate(psA, peerIdB),
205
+ waitForSubscriptionUpdate(psB, peerIdA)
197
206
  ])
198
207
 
199
- Array.from({ length: 10 }, (_, i) => psB.dispatchEvent(new CustomEvent<Uint8Array>(topic, { detail: uint8ArrayFromString('banana') })))
208
+ Array.from({ length: 10 }, (_, i) => psB.publish(topic, uint8ArrayFromString('banana')))
200
209
 
201
210
  return await defer.promise
202
211
  })
@@ -205,7 +214,7 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
205
214
  const defer = pDefer()
206
215
  let callCount = 0
207
216
 
208
- psB.addEventListener('pubsub:subscription-change', (evt) => {
217
+ psB.addEventListener('subscription-change', (evt) => {
209
218
  callCount++
210
219
 
211
220
  if (callCount === 1) {
@@ -239,33 +248,5 @@ export default (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => {
239
248
 
240
249
  return await defer.promise
241
250
  })
242
-
243
- it.skip('Publish to a topic:Z in nodeA nodeB', async () => {
244
- const defer = pDefer()
245
- const topic = 'Z'
246
-
247
- psA.addEventListener(topic, shouldNotHappen, {
248
- once: true
249
- })
250
- psB.addEventListener(topic, shouldNotHappen, {
251
- once: true
252
- })
253
-
254
- await Promise.all([
255
- waitForSubscriptionUpdate(psA, psB),
256
- waitForSubscriptionUpdate(psB, psA)
257
- ])
258
-
259
- setTimeout(() => {
260
- psA.removeEventListener(topic, shouldNotHappen)
261
- psB.removeEventListener(topic, shouldNotHappen)
262
- defer.resolve()
263
- }, 100)
264
-
265
- void psB.dispatchEvent(new CustomEvent<Uint8Array>(topic, { detail: uint8ArrayFromString('banana') }))
266
- void psA.dispatchEvent(new CustomEvent<Uint8Array>(topic, { detail: uint8ArrayFromString('banana') }))
267
-
268
- return await defer.promise
269
- })
270
251
  })
271
252
  }
@@ -1,12 +1,12 @@
1
1
  import { pEvent } from 'p-event'
2
2
  import pWaitFor from 'p-wait-for'
3
- import type { SubscriptionChangeData } from '@libp2p/interfaces/pubsub'
4
- import type { PubSubBaseProtocol } from '@libp2p/pubsub'
3
+ import type { PubSub, SubscriptionChangeData } from '@libp2p/interfaces/pubsub'
4
+ import type { PeerId } from '@libp2p/interfaces/peer-id'
5
5
 
6
- export async function waitForSubscriptionUpdate (a: PubSubBaseProtocol, b: PubSubBaseProtocol) {
6
+ export async function waitForSubscriptionUpdate (a: PubSub, b: PeerId) {
7
7
  await pWaitFor(async () => {
8
- const event = await pEvent<'pubsub:subscription-change', CustomEvent<SubscriptionChangeData>>(a, 'pubsub:subscription-change')
8
+ const event = await pEvent<'subscription-change', CustomEvent<SubscriptionChangeData>>(a, 'subscription-change')
9
9
 
10
- return event.detail.peerId.equals(b.components.getPeerId())
10
+ return event.detail.peerId.equals(b)
11
11
  })
12
12
  }