@libp2p/interface-compliance-tests 1.1.29 → 1.1.30

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 (44) hide show
  1. package/dist/src/mocks/connection-manager.d.ts +21 -7
  2. package/dist/src/mocks/connection-manager.d.ts.map +1 -1
  3. package/dist/src/mocks/connection-manager.js +97 -9
  4. package/dist/src/mocks/connection-manager.js.map +1 -1
  5. package/dist/src/mocks/index.d.ts +1 -1
  6. package/dist/src/mocks/index.d.ts.map +1 -1
  7. package/dist/src/mocks/index.js +1 -1
  8. package/dist/src/mocks/index.js.map +1 -1
  9. package/dist/src/mocks/registrar.d.ts +0 -2
  10. package/dist/src/mocks/registrar.d.ts.map +1 -1
  11. package/dist/src/mocks/registrar.js +1 -12
  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 +13 -10
  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 +43 -37
  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 +22 -18
  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 +7 -4
  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 +33 -33
  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 +10 -8
  30. package/dist/src/pubsub/two-nodes.js.map +1 -1
  31. package/dist/src/pubsub/utils.d.ts.map +1 -1
  32. package/dist/src/pubsub/utils.js +4 -1
  33. package/dist/src/pubsub/utils.js.map +1 -1
  34. package/package.json +1 -1
  35. package/src/mocks/connection-manager.ts +125 -11
  36. package/src/mocks/index.ts +1 -1
  37. package/src/mocks/registrar.ts +1 -16
  38. package/src/pubsub/api.ts +13 -10
  39. package/src/pubsub/connection-handlers.ts +45 -37
  40. package/src/pubsub/emit-self.ts +24 -19
  41. package/src/pubsub/messages.ts +7 -4
  42. package/src/pubsub/multiple-nodes.ts +35 -35
  43. package/src/pubsub/two-nodes.ts +11 -10
  44. package/src/pubsub/utils.ts +6 -1
@@ -5,7 +5,6 @@ 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 { connectPeers } from '../mocks/registrar.js'
9
8
  import { createComponents, waitForSubscriptionUpdate } from './utils.js'
10
9
  import type { TestSetup } from '../index.js'
11
10
  import type { Message, PubSub } from '@libp2p/interfaces/pubsub'
@@ -13,6 +12,7 @@ import type { PubSubArgs } from './index.js'
13
12
  import type { Components } from '@libp2p/interfaces/components'
14
13
  import { start, stop } from '../index.js'
15
14
  import delay from 'delay'
15
+ import { mockNetwork } from '../mocks/connection-manager.js'
16
16
 
17
17
  export default (common: TestSetup<PubSub, PubSubArgs>) => {
18
18
  describe('pubsub with multiple nodes', function () {
@@ -30,37 +30,37 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
30
30
 
31
31
  // Create and start pubsub nodes
32
32
  beforeEach(async () => {
33
+ mockNetwork.reset()
34
+
33
35
  componentsA = await createComponents()
34
36
  componentsB = await createComponents()
35
37
  componentsC = await createComponents()
36
38
 
37
- psA = await common.setup({
39
+ psA = componentsA.setPubSub(await common.setup({
38
40
  components: componentsA,
39
41
  init: {
40
42
  emitSelf: true
41
43
  }
42
- })
43
- psB = await common.setup({
44
+ }))
45
+ psB = componentsB.setPubSub(await common.setup({
44
46
  components: componentsB,
45
47
  init: {
46
48
  emitSelf: true
47
49
  }
48
- })
49
- psC = await common.setup({
50
+ }))
51
+ psC = componentsC.setPubSub(await common.setup({
50
52
  components: componentsC,
51
53
  init: {
52
54
  emitSelf: true
53
55
  }
54
- })
56
+ }))
55
57
 
56
58
  // Start pubsub modes
57
- await start(psA, psB, psC)
58
- })
59
+ await start(componentsA, componentsB, componentsC)
59
60
 
60
- // Connect nodes
61
- beforeEach(async () => {
62
- await connectPeers(psA.multicodecs[0], componentsA, componentsB)
63
- await connectPeers(psB.multicodecs[0], componentsB, componentsC)
61
+ // Connect nodes
62
+ await componentsA.getConnectionManager().openConnection(componentsB.getPeerId())
63
+ await componentsB.getConnectionManager().openConnection(componentsC.getPeerId())
64
64
 
65
65
  // Wait for peers to be ready in pubsub
66
66
  await pWaitFor(() =>
@@ -72,10 +72,9 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
72
72
 
73
73
  afterEach(async () => {
74
74
  sinon.restore()
75
-
76
- await stop(psA, psB, psC)
77
-
75
+ await stop(componentsA, componentsB, componentsC)
78
76
  await common.teardown()
77
+ mockNetwork.reset()
79
78
  })
80
79
 
81
80
  it('subscribe to the topic on node a', async () => {
@@ -259,53 +258,53 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
259
258
 
260
259
  // Create and start pubsub nodes
261
260
  beforeEach(async () => {
261
+ mockNetwork.reset()
262
+
262
263
  componentsA = await createComponents()
263
264
  componentsB = await createComponents()
264
265
  componentsC = await createComponents()
265
266
  componentsD = await createComponents()
266
267
  componentsE = await createComponents()
267
268
 
268
- psA = await common.setup({
269
+ psA = componentsA.setPubSub(await common.setup({
269
270
  components: componentsA,
270
271
  init: {
271
272
  emitSelf: true
272
273
  }
273
- })
274
- psB = await common.setup({
274
+ }))
275
+ psB = componentsB.setPubSub(await common.setup({
275
276
  components: componentsB,
276
277
  init: {
277
278
  emitSelf: true
278
279
  }
279
- })
280
- psC = await common.setup({
280
+ }))
281
+ psC = componentsC.setPubSub(await common.setup({
281
282
  components: componentsC,
282
283
  init: {
283
284
  emitSelf: true
284
285
  }
285
- })
286
- psD = await common.setup({
286
+ }))
287
+ psD = componentsD.setPubSub(await common.setup({
287
288
  components: componentsD,
288
289
  init: {
289
290
  emitSelf: true
290
291
  }
291
- })
292
- psE = await common.setup({
292
+ }))
293
+ psE = componentsE.setPubSub(await common.setup({
293
294
  components: componentsE,
294
295
  init: {
295
296
  emitSelf: true
296
297
  }
297
- })
298
+ }))
298
299
 
299
300
  // Start pubsub nodes
300
- await start(psA, psB, psC, psD, psE)
301
- })
301
+ await start(componentsA, componentsB, componentsC, componentsD, componentsE)
302
302
 
303
- // connect nodes
304
- beforeEach(async () => {
305
- await connectPeers(psA.multicodecs[0], componentsA, componentsB)
306
- await connectPeers(psA.multicodecs[0], componentsB, componentsC)
307
- await connectPeers(psA.multicodecs[0], componentsC, componentsD)
308
- await connectPeers(psA.multicodecs[0], componentsD, componentsE)
303
+ // connect nodes
304
+ await componentsA.getConnectionManager().openConnection(componentsB.getPeerId())
305
+ await componentsB.getConnectionManager().openConnection(componentsC.getPeerId())
306
+ await componentsC.getConnectionManager().openConnection(componentsD.getPeerId())
307
+ await componentsD.getConnectionManager().openConnection(componentsE.getPeerId())
309
308
 
310
309
  // Wait for peers to be ready in pubsub
311
310
  await pWaitFor(() =>
@@ -318,8 +317,9 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
318
317
  })
319
318
 
320
319
  afterEach(async () => {
321
- await stop(psA, psB, psC, psD, psE)
320
+ await stop(componentsA, componentsB, componentsC, componentsD, componentsE)
322
321
  await common.teardown()
322
+ mockNetwork.reset()
323
323
  })
324
324
 
325
325
  it('subscribes', () => {
@@ -5,13 +5,13 @@ 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 { connectPeers } from '../mocks/registrar.js'
9
8
  import { createComponents, waitForSubscriptionUpdate } from './utils.js'
10
9
  import type { TestSetup } from '../index.js'
11
10
  import type { Message, PubSub } from '@libp2p/interfaces/pubsub'
12
11
  import type { PubSubArgs } from './index.js'
13
12
  import type { Components } from '@libp2p/interfaces/components'
14
13
  import { start, stop } from '../index.js'
14
+ import { mockNetwork } from '../mocks/connection-manager.js'
15
15
 
16
16
  const topic = 'foo'
17
17
 
@@ -28,29 +28,31 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
28
28
 
29
29
  // Create pubsub nodes and connect them
30
30
  beforeEach(async () => {
31
+ mockNetwork.reset()
32
+
31
33
  componentsA = await createComponents()
32
34
  componentsB = await createComponents()
33
35
 
34
- psA = await common.setup({
36
+ psA = componentsA.setPubSub(await common.setup({
35
37
  components: componentsA,
36
38
  init: {
37
39
  emitSelf: true
38
40
  }
39
- })
40
- psB = await common.setup({
41
+ }))
42
+ psB = componentsB.setPubSub(await common.setup({
41
43
  components: componentsB,
42
44
  init: {
43
45
  emitSelf: false
44
46
  }
45
- })
47
+ }))
46
48
 
47
49
  // Start pubsub and connect nodes
48
- await start(psA, psB)
50
+ await start(componentsA, componentsB)
49
51
 
50
52
  expect(psA.getPeers()).to.be.empty()
51
53
  expect(psB.getPeers()).to.be.empty()
52
54
 
53
- await connectPeers(psA.multicodecs[0], componentsA, componentsB)
55
+ await componentsA.getConnectionManager().openConnection(componentsB.getPeerId())
54
56
 
55
57
  // Wait for peers to be ready in pubsub
56
58
  await pWaitFor(() => psA.getPeers().length === 1 && psB.getPeers().length === 1)
@@ -58,10 +60,9 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
58
60
 
59
61
  afterEach(async () => {
60
62
  sinon.restore()
61
-
62
- await stop(psA, psB)
63
-
63
+ await stop(componentsA, componentsB)
64
64
  await common.teardown()
65
+ mockNetwork.reset()
65
66
  })
66
67
 
67
68
  it('Subscribe to a topic in nodeA', async () => {
@@ -5,6 +5,7 @@ import type { PubSub, SubscriptionChangeData } from '@libp2p/interfaces/pubsub'
5
5
  import type { PeerId } from '@libp2p/interfaces/peer-id'
6
6
  import { createEd25519PeerId } from '@libp2p/peer-id-factory'
7
7
  import { mockConnectionManager, mockRegistrar } from '../mocks/index.js'
8
+ import { mockNetwork } from '../mocks/connection-manager.js'
8
9
 
9
10
  export async function waitForSubscriptionUpdate (a: PubSub, b: PeerId) {
10
11
  await pWaitFor(async () => {
@@ -15,9 +16,13 @@ export async function waitForSubscriptionUpdate (a: PubSub, b: PeerId) {
15
16
  }
16
17
 
17
18
  export async function createComponents (): Promise<Components> {
18
- return new Components({
19
+ const components = new Components({
19
20
  peerId: await createEd25519PeerId(),
20
21
  registrar: mockRegistrar(),
21
22
  connectionManager: mockConnectionManager()
22
23
  })
24
+
25
+ mockNetwork.addNode(components)
26
+
27
+ return components
23
28
  }