@libp2p/interface-compliance-tests 1.1.24 → 1.1.25

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 (45) hide show
  1. package/dist/src/mocks/connection-manager.d.ts +0 -8
  2. package/dist/src/mocks/connection-manager.d.ts.map +1 -1
  3. package/dist/src/mocks/connection-manager.js +4 -16
  4. package/dist/src/mocks/connection-manager.js.map +1 -1
  5. package/dist/src/mocks/connection.d.ts +2 -1
  6. package/dist/src/mocks/connection.d.ts.map +1 -1
  7. package/dist/src/mocks/connection.js +4 -4
  8. package/dist/src/mocks/connection.js.map +1 -1
  9. package/dist/src/mocks/registrar.d.ts +2 -5
  10. package/dist/src/mocks/registrar.d.ts.map +1 -1
  11. package/dist/src/mocks/registrar.js +4 -4
  12. package/dist/src/mocks/registrar.js.map +1 -1
  13. package/dist/src/pubsub/api.d.ts.map +1 -1
  14. package/dist/src/pubsub/api.js +10 -15
  15. package/dist/src/pubsub/api.js.map +1 -1
  16. package/dist/src/pubsub/connection-handlers.d.ts.map +1 -1
  17. package/dist/src/pubsub/connection-handlers.js +53 -145
  18. package/dist/src/pubsub/connection-handlers.js.map +1 -1
  19. package/dist/src/pubsub/emit-self.d.ts.map +1 -1
  20. package/dist/src/pubsub/emit-self.js +8 -7
  21. package/dist/src/pubsub/emit-self.js.map +1 -1
  22. package/dist/src/pubsub/messages.d.ts.map +1 -1
  23. package/dist/src/pubsub/messages.js +9 -12
  24. package/dist/src/pubsub/messages.js.map +1 -1
  25. package/dist/src/pubsub/multiple-nodes.d.ts.map +1 -1
  26. package/dist/src/pubsub/multiple-nodes.js +80 -216
  27. package/dist/src/pubsub/multiple-nodes.js.map +1 -1
  28. package/dist/src/pubsub/two-nodes.d.ts.map +1 -1
  29. package/dist/src/pubsub/two-nodes.js +20 -38
  30. package/dist/src/pubsub/two-nodes.js.map +1 -1
  31. package/dist/src/pubsub/utils.d.ts +2 -0
  32. package/dist/src/pubsub/utils.d.ts.map +1 -1
  33. package/dist/src/pubsub/utils.js +10 -0
  34. package/dist/src/pubsub/utils.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/mocks/connection-manager.ts +4 -20
  37. package/src/mocks/connection.ts +5 -5
  38. package/src/mocks/registrar.ts +6 -10
  39. package/src/pubsub/api.ts +11 -16
  40. package/src/pubsub/connection-handlers.ts +54 -151
  41. package/src/pubsub/emit-self.ts +10 -7
  42. package/src/pubsub/messages.ts +11 -13
  43. package/src/pubsub/multiple-nodes.ts +88 -220
  44. package/src/pubsub/two-nodes.ts +23 -41
  45. package/src/pubsub/utils.ts +11 -0
@@ -8,6 +8,7 @@ import type { PubSubArgs } from './index.js'
8
8
  import { Components } from '@libp2p/interfaces/components'
9
9
  import { start, stop } from '../index.js'
10
10
  import type { PubSub } from '@libp2p/interfaces/pubsub'
11
+ import { createComponents } from './utils.js'
11
12
 
12
13
  const topic = 'foo'
13
14
  const data = uint8ArrayFromString('bar')
@@ -16,14 +17,14 @@ const shouldNotHappen = () => expect.fail()
16
17
  export default (common: TestSetup<PubSub, PubSubArgs>) => {
17
18
  describe('emit self', () => {
18
19
  let pubsub: PubSub
20
+ let components: Components
19
21
 
20
22
  describe('enabled', () => {
21
23
  before(async () => {
24
+ components = await createComponents()
25
+
22
26
  pubsub = await common.setup({
23
- components: new Components({
24
- peerId: await createEd25519PeerId(),
25
- registrar: mockRegistrar()
26
- }),
27
+ components,
27
28
  init: {
28
29
  emitSelf: true
29
30
  }
@@ -52,9 +53,11 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
52
53
  })
53
54
  })
54
55
 
55
- pubsub.publish(topic, data)
56
+ const result = await pubsub.publish(topic, data)
57
+
58
+ await promise
56
59
 
57
- return await promise
60
+ expect(result).to.have.property('recipients').with.lengthOf(1)
58
61
  })
59
62
  })
60
63
 
@@ -87,7 +90,7 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
87
90
  once: true
88
91
  })
89
92
 
90
- pubsub.publish(topic, data)
93
+ await pubsub.publish(topic, data)
91
94
 
92
95
  // Wait 1 second to guarantee that self is not noticed
93
96
  return await new Promise((resolve) => setTimeout(resolve, 1000))
@@ -1,33 +1,28 @@
1
1
  import { expect } from 'aegir/chai'
2
2
  import sinon from 'sinon'
3
- import { createEd25519PeerId } from '@libp2p/peer-id-factory'
4
3
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
5
- import { mockRegistrar } from '../mocks/registrar.js'
6
4
  import type { TestSetup } from '../index.js'
7
5
  import type { Message, PubSub } from '@libp2p/interfaces/pubsub'
8
6
  import type { PubSubArgs } from './index.js'
9
- import { Components } from '@libp2p/interfaces/components'
10
- import type { PeerId } from '@libp2p/interfaces/peer-id'
7
+ import type { Components } from '@libp2p/interfaces/components'
11
8
  import { start, stop } from '../index.js'
12
9
  import { pEvent } from 'p-event'
10
+ import { createComponents } from './utils.js'
13
11
 
14
12
  const topic = 'foo'
15
13
  const data = uint8ArrayFromString('bar')
16
14
 
17
15
  export default (common: TestSetup<PubSub, PubSubArgs>) => {
18
16
  describe('messages', () => {
19
- let peerId: PeerId
20
17
  let pubsub: PubSub
18
+ let components: Components
21
19
 
22
20
  // Create pubsub router
23
21
  beforeEach(async () => {
24
- peerId = await createEd25519PeerId()
22
+ components = await createComponents()
25
23
 
26
24
  pubsub = await common.setup({
27
- components: new Components({
28
- peerId,
29
- registrar: mockRegistrar()
30
- }),
25
+ components,
31
26
  init: {
32
27
  emitSelf: true
33
28
  }
@@ -42,13 +37,16 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
42
37
  })
43
38
 
44
39
  it('should emit normalized signed messages on publish', async () => {
40
+ const eventPromise = pEvent<'message', CustomEvent<Message>>(pubsub, 'message')
41
+
45
42
  pubsub.globalSignaturePolicy = 'StrictSign'
46
- pubsub.publish(topic, data)
43
+ pubsub.subscribe(topic)
44
+ await pubsub.publish(topic, data)
47
45
 
48
- const event = await pEvent<'message', CustomEvent<Message>>(pubsub, 'message')
46
+ const event = await eventPromise
49
47
  const message = event.detail
50
48
 
51
- expect(message.from.toString()).to.equal(peerId.toString())
49
+ expect(message.from.toString()).to.equal(components.getPeerId().toString())
52
50
  expect(message.sequenceNumber).to.not.eql(undefined)
53
51
  expect(message.key).to.not.eql(undefined)
54
52
  expect(message.signature).to.not.eql(undefined)
@@ -5,15 +5,12 @@ import pDefer from 'p-defer'
5
5
  import pWaitFor from 'p-wait-for'
6
6
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
7
7
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
8
- import { createEd25519PeerId } from '@libp2p/peer-id-factory'
9
- import { connectPeers, mockRegistrar } from '../mocks/registrar.js'
10
- import { waitForSubscriptionUpdate } from './utils.js'
8
+ import { connectPeers } from '../mocks/registrar.js'
9
+ import { createComponents, waitForSubscriptionUpdate } from './utils.js'
11
10
  import type { TestSetup } from '../index.js'
12
11
  import type { Message, PubSub } from '@libp2p/interfaces/pubsub'
13
12
  import type { PubSubArgs } from './index.js'
14
- import type { PeerId } from '@libp2p/interfaces/peer-id'
15
- import type { Registrar } from '@libp2p/interfaces/registrar'
16
- import { Components } from '@libp2p/interfaces/components'
13
+ import type { Components } from '@libp2p/interfaces/components'
17
14
  import { start, stop } from '../index.js'
18
15
 
19
16
  export default (common: TestSetup<PubSub, PubSubArgs>) => {
@@ -26,46 +23,30 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
26
23
  let psA: PubSub
27
24
  let psB: PubSub
28
25
  let psC: PubSub
29
- let peerIdA: PeerId
30
- let peerIdB: PeerId
31
- let peerIdC: PeerId
32
- let registrarA: Registrar
33
- let registrarB: Registrar
34
- let registrarC: Registrar
26
+ let componentsA: Components
27
+ let componentsB: Components
28
+ let componentsC: Components
35
29
 
36
30
  // Create and start pubsub nodes
37
31
  beforeEach(async () => {
38
- peerIdA = await createEd25519PeerId()
39
- peerIdB = await createEd25519PeerId()
40
- peerIdC = await createEd25519PeerId()
41
-
42
- registrarA = mockRegistrar()
43
- registrarB = mockRegistrar()
44
- registrarC = mockRegistrar()
32
+ componentsA = await createComponents()
33
+ componentsB = await createComponents()
34
+ componentsC = await createComponents()
45
35
 
46
36
  psA = await common.setup({
47
- components: new Components({
48
- peerId: peerIdA,
49
- registrar: registrarA
50
- }),
37
+ components: componentsA,
51
38
  init: {
52
39
  emitSelf: true
53
40
  }
54
41
  })
55
42
  psB = await common.setup({
56
- components: new Components({
57
- peerId: peerIdB,
58
- registrar: registrarB
59
- }),
43
+ components: componentsB,
60
44
  init: {
61
45
  emitSelf: true
62
46
  }
63
47
  })
64
48
  psC = await common.setup({
65
- components: new Components({
66
- peerId: peerIdC,
67
- registrar: registrarC
68
- }),
49
+ components: componentsC,
69
50
  init: {
70
51
  emitSelf: true
71
52
  }
@@ -77,20 +58,8 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
77
58
 
78
59
  // Connect nodes
79
60
  beforeEach(async () => {
80
- await connectPeers(psA.multicodecs[0], {
81
- peerId: peerIdA,
82
- registrar: registrarA
83
- }, {
84
- peerId: peerIdB,
85
- registrar: registrarB
86
- })
87
- await connectPeers(psA.multicodecs[0], {
88
- peerId: peerIdB,
89
- registrar: registrarB
90
- }, {
91
- peerId: peerIdC,
92
- registrar: registrarC
93
- })
61
+ await connectPeers(psA.multicodecs[0], componentsA, componentsB)
62
+ await connectPeers(psB.multicodecs[0], componentsB, componentsC)
94
63
 
95
64
  // Wait for peers to be ready in pubsub
96
65
  await pWaitFor(() =>
@@ -114,10 +83,10 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
114
83
  psA.subscribe(topic)
115
84
  expect(psA.getTopics()).to.deep.equal([topic])
116
85
 
117
- await waitForSubscriptionUpdate(psB, peerIdA)
86
+ await waitForSubscriptionUpdate(psB, componentsA.getPeerId())
118
87
 
119
88
  expect(psB.getPeers().length).to.equal(2)
120
- expect(psB.getSubscribers(topic).map(p => p.toString())).to.deep.equal([peerIdA.toString()])
89
+ expect(psB.getSubscribers(topic).map(p => p.toString())).to.deep.equal([componentsA.getPeerId().toString()])
121
90
 
122
91
  expect(psC.getPeers().length).to.equal(1)
123
92
  expect(psC.getSubscribers(topic)).to.be.empty()
@@ -129,15 +98,15 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
129
98
  expect(psB.getTopics()).to.deep.equal([topic])
130
99
 
131
100
  await Promise.all([
132
- waitForSubscriptionUpdate(psA, peerIdB),
133
- waitForSubscriptionUpdate(psC, peerIdB)
101
+ waitForSubscriptionUpdate(psA, componentsB.getPeerId()),
102
+ waitForSubscriptionUpdate(psC, componentsB.getPeerId())
134
103
  ])
135
104
 
136
105
  expect(psA.getPeers().length).to.equal(1)
137
- expect(psA.getSubscribers(topic).map(p => p.toString())).to.deep.equal([peerIdB.toString()])
106
+ expect(psA.getSubscribers(topic).map(p => p.toString())).to.deep.equal([componentsB.getPeerId().toString()])
138
107
 
139
108
  expect(psC.getPeers().length).to.equal(1)
140
- expect(psC.getSubscribers(topic).map(p => p.toString())).to.deep.equal([peerIdB.toString()])
109
+ expect(psC.getSubscribers(topic).map(p => p.toString())).to.deep.equal([componentsB.getPeerId().toString()])
141
110
  })
142
111
 
143
112
  it('subscribe to the topic on node c', async () => {
@@ -150,7 +119,7 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
150
119
  psB.addEventListener('subscription-change', () => {
151
120
  expect(psA.getPeers().length).to.equal(1)
152
121
  expect(psB.getPeers().length).to.equal(2)
153
- expect(psB.getSubscribers(topic).map(p => p.toString())).to.deep.equal([peerIdC.toString()])
122
+ expect(psB.getSubscribers(topic).map(p => p.toString())).to.deep.equal([componentsC.getPeerId().toString()])
154
123
 
155
124
  defer.resolve()
156
125
  }, {
@@ -170,53 +139,36 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
170
139
 
171
140
  let counter = 0
172
141
 
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
- })
142
+ psA.addEventListener('message', incMsg)
143
+ psB.addEventListener('message', incMsg)
144
+ psC.addEventListener('message', incMsg)
188
145
 
189
146
  await Promise.all([
190
- waitForSubscriptionUpdate(psA, peerIdB),
191
- waitForSubscriptionUpdate(psB, peerIdA),
192
- waitForSubscriptionUpdate(psC, peerIdB)
147
+ waitForSubscriptionUpdate(psA, componentsB.getPeerId()),
148
+ waitForSubscriptionUpdate(psB, componentsA.getPeerId()),
149
+ waitForSubscriptionUpdate(psC, componentsB.getPeerId())
193
150
  ])
194
151
 
195
- psA.publish(topic, uint8ArrayFromString('hey'))
152
+ const result = await psA.publish(topic, uint8ArrayFromString('hey'))
153
+
154
+ expect(result).to.have.property('recipients').with.property('length').greaterThanOrEqual(1)
196
155
 
197
156
  function incMsg (evt: CustomEvent<Message>) {
198
157
  const msg = evt.detail
158
+
159
+ if (msg.topic !== topic) {
160
+ return
161
+ }
162
+
199
163
  expect(uint8ArrayToString(msg.data)).to.equal('hey')
200
164
  check()
201
165
  }
202
166
 
203
167
  function check () {
204
168
  if (++counter === 3) {
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
- })
169
+ psA.removeEventListener('message', incMsg)
170
+ psB.removeEventListener('message', incMsg)
171
+ psC.removeEventListener('message', incMsg)
220
172
  defer.resolve()
221
173
  }
222
174
  }
@@ -238,57 +190,38 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
238
190
  const defer = pDefer()
239
191
  let counter = 0
240
192
 
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
- })
193
+ psA.addEventListener('message', incMsg)
194
+ psB.addEventListener('message', incMsg)
195
+ psC.addEventListener('message', incMsg)
256
196
 
257
197
  psA.subscribe(topic)
258
198
  psB.subscribe(topic)
259
199
  psC.subscribe(topic)
260
200
 
261
201
  await Promise.all([
262
- waitForSubscriptionUpdate(psA, peerIdB),
263
- waitForSubscriptionUpdate(psB, peerIdA),
264
- waitForSubscriptionUpdate(psC, peerIdB)
202
+ waitForSubscriptionUpdate(psA, componentsB.getPeerId()),
203
+ waitForSubscriptionUpdate(psB, componentsA.getPeerId()),
204
+ waitForSubscriptionUpdate(psC, componentsB.getPeerId())
265
205
  ])
266
206
 
267
- psB.publish(topic, uint8ArrayFromString('hey'))
207
+ await psB.publish(topic, uint8ArrayFromString('hey'))
268
208
 
269
209
  function incMsg (evt: CustomEvent<Message>) {
270
210
  const msg = evt.detail
211
+
212
+ if (msg.topic !== topic) {
213
+ return
214
+ }
215
+
271
216
  expect(uint8ArrayToString(msg.data)).to.equal('hey')
272
217
  check()
273
218
  }
274
219
 
275
220
  function check () {
276
221
  if (++counter === 3) {
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
- })
222
+ psA.removeEventListener('message', incMsg)
223
+ psB.removeEventListener('message', incMsg)
224
+ psC.removeEventListener('message', incMsg)
292
225
  defer.resolve()
293
226
  }
294
227
  }
@@ -311,72 +244,46 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
311
244
  let psC: PubSub
312
245
  let psD: PubSub
313
246
  let psE: PubSub
314
- let peerIdA: PeerId
315
- let peerIdB: PeerId
316
- let peerIdC: PeerId
317
- let peerIdD: PeerId
318
- let peerIdE: PeerId
319
- let registrarA: Registrar
320
- let registrarB: Registrar
321
- let registrarC: Registrar
322
- let registrarD: Registrar
323
- let registrarE: Registrar
247
+ let componentsA: Components
248
+ let componentsB: Components
249
+ let componentsC: Components
250
+ let componentsD: Components
251
+ let componentsE: Components
324
252
 
325
253
  // Create and start pubsub nodes
326
254
  beforeEach(async () => {
327
- peerIdA = await createEd25519PeerId()
328
- peerIdB = await createEd25519PeerId()
329
- peerIdC = await createEd25519PeerId()
330
- peerIdD = await createEd25519PeerId()
331
- peerIdE = await createEd25519PeerId()
332
-
333
- registrarA = mockRegistrar()
334
- registrarB = mockRegistrar()
335
- registrarC = mockRegistrar()
336
- registrarD = mockRegistrar()
337
- registrarE = mockRegistrar()
255
+ componentsA = await createComponents()
256
+ componentsB = await createComponents()
257
+ componentsC = await createComponents()
258
+ componentsD = await createComponents()
259
+ componentsE = await createComponents()
338
260
 
339
261
  psA = await common.setup({
340
- components: new Components({
341
- peerId: peerIdA,
342
- registrar: registrarA
343
- }),
262
+ components: componentsA,
344
263
  init: {
345
264
  emitSelf: true
346
265
  }
347
266
  })
348
267
  psB = await common.setup({
349
- components: new Components({
350
- peerId: peerIdB,
351
- registrar: registrarB
352
- }),
268
+ components: componentsB,
353
269
  init: {
354
270
  emitSelf: true
355
271
  }
356
272
  })
357
273
  psC = await common.setup({
358
- components: new Components({
359
- peerId: peerIdC,
360
- registrar: registrarC
361
- }),
274
+ components: componentsC,
362
275
  init: {
363
276
  emitSelf: true
364
277
  }
365
278
  })
366
279
  psD = await common.setup({
367
- components: new Components({
368
- peerId: peerIdD,
369
- registrar: registrarD
370
- }),
280
+ components: componentsD,
371
281
  init: {
372
282
  emitSelf: true
373
283
  }
374
284
  })
375
285
  psE = await common.setup({
376
- components: new Components({
377
- peerId: peerIdE,
378
- registrar: registrarE
379
- }),
286
+ components: componentsE,
380
287
  init: {
381
288
  emitSelf: true
382
289
  }
@@ -388,34 +295,10 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
388
295
 
389
296
  // connect nodes
390
297
  beforeEach(async () => {
391
- await connectPeers(psA.multicodecs[0], {
392
- peerId: peerIdA,
393
- registrar: registrarA
394
- }, {
395
- peerId: peerIdB,
396
- registrar: registrarB
397
- })
398
- await connectPeers(psA.multicodecs[0], {
399
- peerId: peerIdB,
400
- registrar: registrarB
401
- }, {
402
- peerId: peerIdC,
403
- registrar: registrarC
404
- })
405
- await connectPeers(psA.multicodecs[0], {
406
- peerId: peerIdC,
407
- registrar: registrarC
408
- }, {
409
- peerId: peerIdD,
410
- registrar: registrarD
411
- })
412
- await connectPeers(psA.multicodecs[0], {
413
- peerId: peerIdD,
414
- registrar: registrarD
415
- }, {
416
- peerId: peerIdE,
417
- registrar: registrarE
418
- })
298
+ await connectPeers(psA.multicodecs[0], componentsA, componentsB)
299
+ await connectPeers(psA.multicodecs[0], componentsB, componentsC)
300
+ await connectPeers(psA.multicodecs[0], componentsC, componentsD)
301
+ await connectPeers(psA.multicodecs[0], componentsD, componentsE)
419
302
 
420
303
  // Wait for peers to be ready in pubsub
421
304
  await pWaitFor(() =>
@@ -451,48 +334,33 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
451
334
  const topic = 'Z'
452
335
 
453
336
  psA.subscribe(topic)
454
- psA.addEventListener('message', (evt) => {
455
- if (evt.detail.topic === topic) {
456
- incMsg(evt)
457
- }
458
- })
337
+ psA.addEventListener('message', incMsg)
459
338
  psB.subscribe(topic)
460
- psB.addEventListener('message', (evt) => {
461
- if (evt.detail.topic === topic) {
462
- incMsg(evt)
463
- }
464
- })
339
+ psB.addEventListener('message', incMsg)
465
340
  psC.subscribe(topic)
466
- psC.addEventListener('message', (evt) => {
467
- if (evt.detail.topic === topic) {
468
- incMsg(evt)
469
- }
470
- })
341
+ psC.addEventListener('message', incMsg)
471
342
  psD.subscribe(topic)
472
- psD.addEventListener('message', (evt) => {
473
- if (evt.detail.topic === topic) {
474
- incMsg(evt)
475
- }
476
- })
343
+ psD.addEventListener('message', incMsg)
477
344
  psE.subscribe(topic)
478
- psE.addEventListener('message', (evt) => {
479
- if (evt.detail.topic === topic) {
480
- incMsg(evt)
481
- }
482
- })
345
+ psE.addEventListener('message', incMsg)
483
346
 
484
347
  await Promise.all([
485
- waitForSubscriptionUpdate(psA, peerIdB),
486
- waitForSubscriptionUpdate(psB, peerIdA),
487
- waitForSubscriptionUpdate(psC, peerIdB),
488
- waitForSubscriptionUpdate(psD, peerIdC),
489
- waitForSubscriptionUpdate(psE, peerIdD)
348
+ waitForSubscriptionUpdate(psA, componentsB.getPeerId()),
349
+ waitForSubscriptionUpdate(psB, componentsA.getPeerId()),
350
+ waitForSubscriptionUpdate(psC, componentsB.getPeerId()),
351
+ waitForSubscriptionUpdate(psD, componentsC.getPeerId()),
352
+ waitForSubscriptionUpdate(psE, componentsD.getPeerId())
490
353
  ])
491
354
 
492
- psC.publish('Z', uint8ArrayFromString('hey from c'))
355
+ await psC.publish('Z', uint8ArrayFromString('hey from c'))
493
356
 
494
357
  function incMsg (evt: CustomEvent<Message>) {
495
358
  const msg = evt.detail
359
+
360
+ if (msg.topic !== topic) {
361
+ return
362
+ }
363
+
496
364
  expect(uint8ArrayToString(msg.data)).to.equal('hey from c')
497
365
  check()
498
366
  }