@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.
- package/dist/src/mocks/connection-manager.d.ts +0 -8
- package/dist/src/mocks/connection-manager.d.ts.map +1 -1
- package/dist/src/mocks/connection-manager.js +4 -16
- package/dist/src/mocks/connection-manager.js.map +1 -1
- package/dist/src/mocks/connection.d.ts +2 -1
- package/dist/src/mocks/connection.d.ts.map +1 -1
- package/dist/src/mocks/connection.js +4 -4
- package/dist/src/mocks/connection.js.map +1 -1
- package/dist/src/mocks/registrar.d.ts +2 -5
- package/dist/src/mocks/registrar.d.ts.map +1 -1
- package/dist/src/mocks/registrar.js +4 -4
- package/dist/src/mocks/registrar.js.map +1 -1
- package/dist/src/pubsub/api.d.ts.map +1 -1
- package/dist/src/pubsub/api.js +10 -15
- package/dist/src/pubsub/api.js.map +1 -1
- package/dist/src/pubsub/connection-handlers.d.ts.map +1 -1
- package/dist/src/pubsub/connection-handlers.js +53 -145
- package/dist/src/pubsub/connection-handlers.js.map +1 -1
- package/dist/src/pubsub/emit-self.d.ts.map +1 -1
- package/dist/src/pubsub/emit-self.js +8 -7
- package/dist/src/pubsub/emit-self.js.map +1 -1
- package/dist/src/pubsub/messages.d.ts.map +1 -1
- package/dist/src/pubsub/messages.js +9 -12
- package/dist/src/pubsub/messages.js.map +1 -1
- package/dist/src/pubsub/multiple-nodes.d.ts.map +1 -1
- package/dist/src/pubsub/multiple-nodes.js +80 -216
- package/dist/src/pubsub/multiple-nodes.js.map +1 -1
- package/dist/src/pubsub/two-nodes.d.ts.map +1 -1
- package/dist/src/pubsub/two-nodes.js +20 -38
- package/dist/src/pubsub/two-nodes.js.map +1 -1
- package/dist/src/pubsub/utils.d.ts +2 -0
- package/dist/src/pubsub/utils.d.ts.map +1 -1
- package/dist/src/pubsub/utils.js +10 -0
- package/dist/src/pubsub/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/mocks/connection-manager.ts +4 -20
- package/src/mocks/connection.ts +5 -5
- package/src/mocks/registrar.ts +6 -10
- package/src/pubsub/api.ts +11 -16
- package/src/pubsub/connection-handlers.ts +54 -151
- package/src/pubsub/emit-self.ts +10 -7
- package/src/pubsub/messages.ts +11 -13
- package/src/pubsub/multiple-nodes.ts +88 -220
- package/src/pubsub/two-nodes.ts +23 -41
- package/src/pubsub/utils.ts +11 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"two-nodes.js","sourceRoot":"","sources":["../../../src/pubsub/two-nodes.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"two-nodes.js","sourceRoot":"","sources":["../../../src/pubsub/two-nodes.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAKxE,OAAO,EAA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C,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;oBAEhD,KAAK,CAAC,OAAO,EAAE,CAAA;iBAChB;YACH,CAAC,CAAC,CAAA;YAEF,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;YACpB,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;YAEzC,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;YACtB,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;YAErC,OAAO,MAAM,KAAK,CAAC,OAAO,CAAA;QAC5B,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Components } from '@libp2p/interfaces/components';
|
|
1
2
|
import type { PubSub } from '@libp2p/interfaces/pubsub';
|
|
2
3
|
import type { PeerId } from '@libp2p/interfaces/peer-id';
|
|
3
4
|
export declare function waitForSubscriptionUpdate(a: PubSub, b: PeerId): Promise<void>;
|
|
5
|
+
export declare function createComponents(): Promise<Components>;
|
|
4
6
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/pubsub/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAA0B,MAAM,2BAA2B,CAAA;AAC/E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/pubsub/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC1D,OAAO,KAAK,EAAE,MAAM,EAA0B,MAAM,2BAA2B,CAAA;AAC/E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAIxD,wBAAsB,yBAAyB,CAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,iBAMpE;AAED,wBAAsB,gBAAgB,IAAK,OAAO,CAAC,UAAU,CAAC,CAM7D"}
|
package/dist/src/pubsub/utils.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { pEvent } from 'p-event';
|
|
2
2
|
import pWaitFor from 'p-wait-for';
|
|
3
|
+
import { Components } from '@libp2p/interfaces/components';
|
|
4
|
+
import { createEd25519PeerId } from '@libp2p/peer-id-factory';
|
|
5
|
+
import { mockConnectionManager, mockRegistrar } from '../mocks/index.js';
|
|
3
6
|
export async function waitForSubscriptionUpdate(a, b) {
|
|
4
7
|
await pWaitFor(async () => {
|
|
5
8
|
const event = await pEvent(a, 'subscription-change');
|
|
6
9
|
return event.detail.peerId.equals(b);
|
|
7
10
|
});
|
|
8
11
|
}
|
|
12
|
+
export async function createComponents() {
|
|
13
|
+
return new Components({
|
|
14
|
+
peerId: await createEd25519PeerId(),
|
|
15
|
+
registrar: mockRegistrar(),
|
|
16
|
+
connectionManager: mockConnectionManager()
|
|
17
|
+
});
|
|
18
|
+
}
|
|
9
19
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/pubsub/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,QAAQ,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/pubsub/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAG1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAExE,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAE,CAAS,EAAE,CAAS;IACnE,MAAM,QAAQ,CAAC,KAAK,IAAI,EAAE;QACxB,MAAM,KAAK,GAAG,MAAM,MAAM,CAA6D,CAAC,EAAE,qBAAqB,CAAC,CAAA;QAEhH,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IACtC,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,OAAO,IAAI,UAAU,CAAC;QACpB,MAAM,EAAE,MAAM,mBAAmB,EAAE;QACnC,SAAS,EAAE,aAAa,EAAE;QAC1B,iBAAiB,EAAE,qBAAqB,EAAE;KAC3C,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/interface-compliance-tests",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.25",
|
|
4
4
|
"description": "Compliance tests for JS libp2p interfaces",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-interface-compliance-tests#readme",
|
|
@@ -5,35 +5,19 @@ import type { ConnectionManager, ConnectionManagerEvents } from '@libp2p/interfa
|
|
|
5
5
|
|
|
6
6
|
class MockConnectionManager extends EventEmitter<ConnectionManagerEvents> implements ConnectionManager {
|
|
7
7
|
getConnectionMap (): Map<string, Connection[]> {
|
|
8
|
-
|
|
8
|
+
return new Map<string, Connection[]>()
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
getConnectionList (): Connection[] {
|
|
12
|
-
|
|
12
|
+
return []
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
getConnections (): Connection[] {
|
|
16
|
-
|
|
16
|
+
return []
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
getConnection (peerId: PeerId): Connection | undefined {
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
listenerCount (type: string): number {
|
|
24
|
-
throw new Error('Method not implemented.')
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
addEventListener<U extends keyof ConnectionManagerEvents>(type: U, callback: ((evt: ConnectionManagerEvents[U]) => void) | { handleEvent: (evt: ConnectionManagerEvents[U]) => void } | null, options?: boolean | AddEventListenerOptions): void {
|
|
28
|
-
throw new Error('Method not implemented.')
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
removeEventListener<U extends keyof ConnectionManagerEvents>(type: U, callback: (((evt: ConnectionManagerEvents[U]) => void) | { handleEvent: (evt: ConnectionManagerEvents[U]) => void } | null) | undefined, options?: boolean | EventListenerOptions): void {
|
|
32
|
-
throw new Error('Method not implemented.')
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
dispatchEvent (event: Event): boolean {
|
|
36
|
-
throw new Error('Method not implemented.')
|
|
20
|
+
return undefined
|
|
37
21
|
}
|
|
38
22
|
}
|
|
39
23
|
|
package/src/mocks/connection.ts
CHANGED
|
@@ -184,18 +184,18 @@ export interface Peer {
|
|
|
184
184
|
registrar: Registrar
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
export function connectionPair (a:
|
|
187
|
+
export function connectionPair (a: Components, b: Components): [ Connection, Connection ] {
|
|
188
188
|
const [peerBtoPeerA, peerAtoPeerB] = duplexPair<Uint8Array>()
|
|
189
189
|
|
|
190
190
|
return [
|
|
191
191
|
mockConnection(
|
|
192
|
-
mockMultiaddrConnection(peerAtoPeerB, b.
|
|
193
|
-
registrar: a.
|
|
192
|
+
mockMultiaddrConnection(peerAtoPeerB, b.getPeerId()), {
|
|
193
|
+
registrar: a.getRegistrar()
|
|
194
194
|
}
|
|
195
195
|
),
|
|
196
196
|
mockConnection(
|
|
197
|
-
mockMultiaddrConnection(peerBtoPeerA, a.
|
|
198
|
-
registrar: b.
|
|
197
|
+
mockMultiaddrConnection(peerBtoPeerA, a.getPeerId()), {
|
|
198
|
+
registrar: b.getRegistrar()
|
|
199
199
|
}
|
|
200
200
|
)
|
|
201
201
|
]
|
package/src/mocks/registrar.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Connection } from '@libp2p/interfaces/connection'
|
|
|
3
3
|
import type { PeerId } from '@libp2p/interfaces/peer-id'
|
|
4
4
|
import type { Topology } from '@libp2p/interfaces/topology'
|
|
5
5
|
import { connectionPair } from './connection.js'
|
|
6
|
+
import type { Components } from '@libp2p/interfaces/src/components'
|
|
6
7
|
|
|
7
8
|
export class MockRegistrar implements Registrar {
|
|
8
9
|
private readonly topologies: Map<string, { topology: Topology, protocols: string[] }> = new Map()
|
|
@@ -106,20 +107,15 @@ export async function mockIncomingStreamEvent (protocol: string, conn: Connectio
|
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
export
|
|
110
|
-
peerId: PeerId
|
|
111
|
-
registrar: Registrar
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export async function connectPeers (protocol: string, a: Peer, b: Peer) {
|
|
110
|
+
export async function connectPeers (protocol: string, a: Components, b: Components) {
|
|
115
111
|
// Notify peers of connection
|
|
116
112
|
const [aToB, bToA] = connectionPair(a, b)
|
|
117
113
|
|
|
118
|
-
for (const topology of a.
|
|
119
|
-
await topology.onConnect(b.
|
|
114
|
+
for (const topology of a.getRegistrar().getTopologies(protocol)) {
|
|
115
|
+
await topology.onConnect(b.getPeerId(), aToB)
|
|
120
116
|
}
|
|
121
117
|
|
|
122
|
-
for (const topology of b.
|
|
123
|
-
await topology.onConnect(a.
|
|
118
|
+
for (const topology of b.getRegistrar().getTopologies(protocol)) {
|
|
119
|
+
await topology.onConnect(a.getPeerId(), bToA)
|
|
124
120
|
}
|
|
125
121
|
}
|
package/src/pubsub/api.ts
CHANGED
|
@@ -3,14 +3,12 @@ import sinon from 'sinon'
|
|
|
3
3
|
import pDefer from 'p-defer'
|
|
4
4
|
import pWaitFor from 'p-wait-for'
|
|
5
5
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
6
|
-
import { mockRegistrar } from '../mocks/registrar.js'
|
|
7
|
-
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
|
|
8
6
|
import delay from 'delay'
|
|
9
7
|
import type { TestSetup } from '../index.js'
|
|
10
8
|
import type { PubSub } from '@libp2p/interfaces/pubsub'
|
|
11
9
|
import type { PubSubArgs } from './index.js'
|
|
12
|
-
import type {
|
|
13
|
-
import {
|
|
10
|
+
import type { Components } from '@libp2p/interfaces/components'
|
|
11
|
+
import { createComponents } from './utils.js'
|
|
14
12
|
|
|
15
13
|
const topic = 'foo'
|
|
16
14
|
const data = uint8ArrayFromString('bar')
|
|
@@ -18,17 +16,14 @@ const data = uint8ArrayFromString('bar')
|
|
|
18
16
|
export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
19
17
|
describe('pubsub api', () => {
|
|
20
18
|
let pubsub: PubSub
|
|
21
|
-
let
|
|
19
|
+
let components: Components
|
|
22
20
|
|
|
23
21
|
// Create pubsub router
|
|
24
22
|
beforeEach(async () => {
|
|
25
|
-
|
|
23
|
+
components = await createComponents()
|
|
26
24
|
|
|
27
25
|
pubsub = await common.setup({
|
|
28
|
-
components
|
|
29
|
-
peerId: await createEd25519PeerId(),
|
|
30
|
-
registrar
|
|
31
|
-
}),
|
|
26
|
+
components,
|
|
32
27
|
init: {
|
|
33
28
|
emitSelf: true
|
|
34
29
|
}
|
|
@@ -42,22 +37,22 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
42
37
|
})
|
|
43
38
|
|
|
44
39
|
it('can start correctly', async () => {
|
|
45
|
-
sinon.spy(
|
|
40
|
+
sinon.spy(components.getRegistrar(), 'register')
|
|
46
41
|
|
|
47
42
|
await pubsub.start()
|
|
48
43
|
|
|
49
44
|
expect(pubsub.isStarted()).to.equal(true)
|
|
50
|
-
expect(
|
|
45
|
+
expect(components.getRegistrar().register).to.have.property('callCount', 1)
|
|
51
46
|
})
|
|
52
47
|
|
|
53
48
|
it('can stop correctly', async () => {
|
|
54
|
-
sinon.spy(
|
|
49
|
+
sinon.spy(components.getRegistrar(), 'unregister')
|
|
55
50
|
|
|
56
51
|
await pubsub.start()
|
|
57
52
|
await pubsub.stop()
|
|
58
53
|
|
|
59
54
|
expect(pubsub.isStarted()).to.equal(false)
|
|
60
|
-
expect(
|
|
55
|
+
expect(components.getRegistrar().unregister).to.have.property('callCount', 1)
|
|
61
56
|
})
|
|
62
57
|
|
|
63
58
|
it('can subscribe and unsubscribe correctly', async () => {
|
|
@@ -80,7 +75,7 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
80
75
|
await pWaitFor(() => pubsub.getTopics().length === 0)
|
|
81
76
|
|
|
82
77
|
// Publish to guarantee the handler is not called
|
|
83
|
-
pubsub.publish(topic, data)
|
|
78
|
+
await pubsub.publish(topic, data)
|
|
84
79
|
|
|
85
80
|
// handlers are called async
|
|
86
81
|
await delay(100)
|
|
@@ -99,7 +94,7 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
99
94
|
expect(evt).to.have.deep.nested.property('detail.data', data)
|
|
100
95
|
defer.resolve()
|
|
101
96
|
})
|
|
102
|
-
pubsub.publish(topic, data)
|
|
97
|
+
await pubsub.publish(topic, data)
|
|
103
98
|
await defer.promise
|
|
104
99
|
|
|
105
100
|
await pubsub.stop()
|
|
@@ -4,46 +4,34 @@ import pDefer from 'p-defer'
|
|
|
4
4
|
import pWaitFor from 'p-wait-for'
|
|
5
5
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
6
6
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
7
|
-
import {
|
|
8
|
-
import { connectPeers, mockRegistrar } from '../mocks/registrar.js'
|
|
7
|
+
import { connectPeers } from '../mocks/registrar.js'
|
|
9
8
|
import type { TestSetup } from '../index.js'
|
|
10
9
|
import type { Message, PubSub } from '@libp2p/interfaces/pubsub'
|
|
11
10
|
import type { PubSubArgs } from './index.js'
|
|
12
|
-
import type {
|
|
13
|
-
import type { Registrar } from '@libp2p/interfaces/registrar'
|
|
14
|
-
import { Components } from '@libp2p/interfaces/components'
|
|
11
|
+
import type { Components } from '@libp2p/interfaces/components'
|
|
15
12
|
import { start, stop } from '../index.js'
|
|
13
|
+
import { createComponents } from './utils.js'
|
|
14
|
+
import { pEvent } from 'p-event'
|
|
16
15
|
|
|
17
16
|
export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
18
17
|
describe('pubsub connection handlers', () => {
|
|
19
18
|
let psA: PubSub
|
|
20
19
|
let psB: PubSub
|
|
21
|
-
let
|
|
22
|
-
let
|
|
23
|
-
let registrarA: Registrar
|
|
24
|
-
let registrarB: Registrar
|
|
20
|
+
let componentsA: Components
|
|
21
|
+
let componentsB: Components
|
|
25
22
|
|
|
26
23
|
describe('nodes send state on connection', () => {
|
|
27
24
|
// Create pubsub nodes and connect them
|
|
28
25
|
before(async () => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
registrarA = mockRegistrar()
|
|
33
|
-
registrarB = mockRegistrar()
|
|
26
|
+
componentsA = await createComponents()
|
|
27
|
+
componentsB = await createComponents()
|
|
34
28
|
|
|
35
29
|
psA = await common.setup({
|
|
36
|
-
components:
|
|
37
|
-
peerId: peerA,
|
|
38
|
-
registrar: registrarA
|
|
39
|
-
}),
|
|
30
|
+
components: componentsA,
|
|
40
31
|
init: {}
|
|
41
32
|
})
|
|
42
33
|
psB = await common.setup({
|
|
43
|
-
components:
|
|
44
|
-
peerId: peerB,
|
|
45
|
-
registrar: registrarB
|
|
46
|
-
}),
|
|
34
|
+
components: componentsB,
|
|
47
35
|
init: {}
|
|
48
36
|
})
|
|
49
37
|
|
|
@@ -72,21 +60,11 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
72
60
|
|
|
73
61
|
it('existing subscriptions are sent upon peer connection', async function () {
|
|
74
62
|
const subscriptionsChanged = Promise.all([
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
})),
|
|
78
|
-
new Promise((resolve) => psB.addEventListener('subscription-change', resolve, {
|
|
79
|
-
once: true
|
|
80
|
-
}))
|
|
63
|
+
pEvent(psA, 'subscription-change'),
|
|
64
|
+
pEvent(psB, 'subscription-change')
|
|
81
65
|
])
|
|
82
66
|
|
|
83
|
-
await connectPeers(psA.multicodecs[0],
|
|
84
|
-
peerId: peerA,
|
|
85
|
-
registrar: registrarA
|
|
86
|
-
}, {
|
|
87
|
-
peerId: peerB,
|
|
88
|
-
registrar: registrarB
|
|
89
|
-
})
|
|
67
|
+
await connectPeers(psA.multicodecs[0], componentsA, componentsB)
|
|
90
68
|
|
|
91
69
|
await subscriptionsChanged
|
|
92
70
|
|
|
@@ -96,39 +74,28 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
96
74
|
expect(psA.getTopics()).to.deep.equal(['Za'])
|
|
97
75
|
expect(psB.getTopics()).to.deep.equal(['Zb'])
|
|
98
76
|
|
|
99
|
-
expect(psA.getSubscribers('Zb').map(p => p.toString())).to.deep.equal([
|
|
100
|
-
expect(psB.getSubscribers('Za').map(p => p.toString())).to.deep.equal([
|
|
77
|
+
expect(psA.getSubscribers('Zb').map(p => p.toString())).to.deep.equal([componentsB.getPeerId().toString()])
|
|
78
|
+
expect(psB.getSubscribers('Za').map(p => p.toString())).to.deep.equal([componentsA.getPeerId().toString()])
|
|
101
79
|
})
|
|
102
80
|
})
|
|
103
81
|
|
|
104
82
|
describe('pubsub started before connect', () => {
|
|
105
83
|
let psA: PubSub
|
|
106
84
|
let psB: PubSub
|
|
107
|
-
let
|
|
108
|
-
let
|
|
109
|
-
let registrarA: Registrar
|
|
110
|
-
let registrarB: Registrar
|
|
85
|
+
let componentsA: Components
|
|
86
|
+
let componentsB: Components
|
|
111
87
|
|
|
112
88
|
// Create pubsub nodes and start them
|
|
113
89
|
beforeEach(async () => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
registrarA = mockRegistrar()
|
|
118
|
-
registrarB = mockRegistrar()
|
|
90
|
+
componentsA = await createComponents()
|
|
91
|
+
componentsB = await createComponents()
|
|
119
92
|
|
|
120
93
|
psA = await common.setup({
|
|
121
|
-
components:
|
|
122
|
-
peerId: peerA,
|
|
123
|
-
registrar: registrarA
|
|
124
|
-
}),
|
|
94
|
+
components: componentsA,
|
|
125
95
|
init: {}
|
|
126
96
|
})
|
|
127
97
|
psB = await common.setup({
|
|
128
|
-
components:
|
|
129
|
-
peerId: peerB,
|
|
130
|
-
registrar: registrarB
|
|
131
|
-
}),
|
|
98
|
+
components: componentsB,
|
|
132
99
|
init: {}
|
|
133
100
|
})
|
|
134
101
|
|
|
@@ -142,13 +109,7 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
142
109
|
})
|
|
143
110
|
|
|
144
111
|
it('should get notified of connected peers on dial', async () => {
|
|
145
|
-
await connectPeers(psA.multicodecs[0],
|
|
146
|
-
peerId: peerA,
|
|
147
|
-
registrar: registrarA
|
|
148
|
-
}, {
|
|
149
|
-
peerId: peerB,
|
|
150
|
-
registrar: registrarB
|
|
151
|
-
})
|
|
112
|
+
await connectPeers(psA.multicodecs[0], componentsA, componentsB)
|
|
152
113
|
|
|
153
114
|
return await Promise.all([
|
|
154
115
|
pWaitFor(() => psA.getPeers().length === 1),
|
|
@@ -161,13 +122,7 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
161
122
|
const topic = 'test-topic'
|
|
162
123
|
const data = uint8ArrayFromString('hey!')
|
|
163
124
|
|
|
164
|
-
await connectPeers(psA.multicodecs[0],
|
|
165
|
-
peerId: peerA,
|
|
166
|
-
registrar: registrarA
|
|
167
|
-
}, {
|
|
168
|
-
peerId: peerB,
|
|
169
|
-
registrar: registrarB
|
|
170
|
-
})
|
|
125
|
+
await connectPeers(psA.multicodecs[0], componentsA, componentsB)
|
|
171
126
|
|
|
172
127
|
let subscribedTopics = psA.getTopics()
|
|
173
128
|
expect(subscribedTopics).to.not.include(topic)
|
|
@@ -188,9 +143,9 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
188
143
|
// wait for psB to know about psA subscription
|
|
189
144
|
await pWaitFor(() => {
|
|
190
145
|
const subscribedPeers = psB.getSubscribers(topic)
|
|
191
|
-
return subscribedPeers.map(p => p.toString()).includes(
|
|
146
|
+
return subscribedPeers.map(p => p.toString()).includes(componentsA.getPeerId().toString()) // eslint-disable-line max-nested-callbacks
|
|
192
147
|
})
|
|
193
|
-
psB.publish(topic, data)
|
|
148
|
+
await psB.publish(topic, data)
|
|
194
149
|
|
|
195
150
|
await defer.promise
|
|
196
151
|
})
|
|
@@ -199,31 +154,20 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
199
154
|
describe('pubsub started after connect', () => {
|
|
200
155
|
let psA: PubSub
|
|
201
156
|
let psB: PubSub
|
|
202
|
-
let
|
|
203
|
-
let
|
|
204
|
-
let registrarA: Registrar
|
|
205
|
-
let registrarB: Registrar
|
|
157
|
+
let componentsA: Components
|
|
158
|
+
let componentsB: Components
|
|
206
159
|
|
|
207
160
|
// Create pubsub nodes
|
|
208
161
|
beforeEach(async () => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
registrarA = mockRegistrar()
|
|
213
|
-
registrarB = mockRegistrar()
|
|
162
|
+
componentsA = await createComponents()
|
|
163
|
+
componentsB = await createComponents()
|
|
214
164
|
|
|
215
165
|
psA = await common.setup({
|
|
216
|
-
components:
|
|
217
|
-
peerId: peerA,
|
|
218
|
-
registrar: registrarA
|
|
219
|
-
}),
|
|
166
|
+
components: componentsA,
|
|
220
167
|
init: {}
|
|
221
168
|
})
|
|
222
169
|
psB = await common.setup({
|
|
223
|
-
components:
|
|
224
|
-
peerId: peerB,
|
|
225
|
-
registrar: registrarB
|
|
226
|
-
}),
|
|
170
|
+
components: componentsB,
|
|
227
171
|
init: {}
|
|
228
172
|
})
|
|
229
173
|
})
|
|
@@ -239,13 +183,7 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
239
183
|
it('should get notified of connected peers after starting', async () => {
|
|
240
184
|
await start(psA, psB)
|
|
241
185
|
|
|
242
|
-
await connectPeers(psA.multicodecs[0],
|
|
243
|
-
peerId: peerA,
|
|
244
|
-
registrar: registrarA
|
|
245
|
-
}, {
|
|
246
|
-
peerId: peerB,
|
|
247
|
-
registrar: registrarB
|
|
248
|
-
})
|
|
186
|
+
await connectPeers(psA.multicodecs[0], componentsA, componentsB)
|
|
249
187
|
|
|
250
188
|
return await Promise.all([
|
|
251
189
|
pWaitFor(() => psA.getPeers().length === 1),
|
|
@@ -260,13 +198,7 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
260
198
|
|
|
261
199
|
await start(psA, psB)
|
|
262
200
|
|
|
263
|
-
await connectPeers(psA.multicodecs[0],
|
|
264
|
-
peerId: peerA,
|
|
265
|
-
registrar: registrarA
|
|
266
|
-
}, {
|
|
267
|
-
peerId: peerB,
|
|
268
|
-
registrar: registrarB
|
|
269
|
-
})
|
|
201
|
+
await connectPeers(psA.multicodecs[0], componentsA, componentsB)
|
|
270
202
|
|
|
271
203
|
await Promise.all([
|
|
272
204
|
pWaitFor(() => psA.getPeers().length === 1),
|
|
@@ -292,9 +224,9 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
292
224
|
// wait for psB to know about psA subscription
|
|
293
225
|
await pWaitFor(() => {
|
|
294
226
|
const subscribedPeers = psB.getSubscribers(topic)
|
|
295
|
-
return subscribedPeers.map(p => p.toString()).includes(
|
|
227
|
+
return subscribedPeers.map(p => p.toString()).includes(componentsA.getPeerId().toString()) // eslint-disable-line max-nested-callbacks
|
|
296
228
|
})
|
|
297
|
-
psB.publish(topic, data)
|
|
229
|
+
await psB.publish(topic, data)
|
|
298
230
|
|
|
299
231
|
await defer.promise
|
|
300
232
|
})
|
|
@@ -303,31 +235,20 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
303
235
|
describe('pubsub with intermittent connections', () => {
|
|
304
236
|
let psA: PubSub
|
|
305
237
|
let psB: PubSub
|
|
306
|
-
let
|
|
307
|
-
let
|
|
308
|
-
let registrarA: Registrar
|
|
309
|
-
let registrarB: Registrar
|
|
238
|
+
let componentsA: Components
|
|
239
|
+
let componentsB: Components
|
|
310
240
|
|
|
311
241
|
// Create pubsub nodes and start them
|
|
312
242
|
beforeEach(async () => {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
registrarA = mockRegistrar()
|
|
317
|
-
registrarB = mockRegistrar()
|
|
243
|
+
componentsA = await createComponents()
|
|
244
|
+
componentsB = await createComponents()
|
|
318
245
|
|
|
319
246
|
psA = await common.setup({
|
|
320
|
-
components:
|
|
321
|
-
peerId: peerA,
|
|
322
|
-
registrar: registrarA
|
|
323
|
-
}),
|
|
247
|
+
components: componentsA,
|
|
324
248
|
init: {}
|
|
325
249
|
})
|
|
326
250
|
psB = await common.setup({
|
|
327
|
-
components:
|
|
328
|
-
peerId: peerB,
|
|
329
|
-
registrar: registrarB
|
|
330
|
-
}),
|
|
251
|
+
components: componentsB,
|
|
331
252
|
init: {}
|
|
332
253
|
})
|
|
333
254
|
|
|
@@ -350,13 +271,7 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
350
271
|
const defer1 = pDefer()
|
|
351
272
|
const defer2 = pDefer()
|
|
352
273
|
|
|
353
|
-
await connectPeers(psA.multicodecs[0],
|
|
354
|
-
peerId: peerA,
|
|
355
|
-
registrar: registrarA
|
|
356
|
-
}, {
|
|
357
|
-
peerId: peerB,
|
|
358
|
-
registrar: registrarB
|
|
359
|
-
})
|
|
274
|
+
await connectPeers(psA.multicodecs[0], componentsA, componentsB)
|
|
360
275
|
|
|
361
276
|
let subscribedTopics = psA.getTopics()
|
|
362
277
|
expect(subscribedTopics).to.not.include(topic)
|
|
@@ -378,9 +293,9 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
378
293
|
// wait for psB to know about psA subscription
|
|
379
294
|
await pWaitFor(() => {
|
|
380
295
|
const subscribedPeers = psB.getSubscribers(topic)
|
|
381
|
-
return subscribedPeers.map(p => p.toString()).includes(
|
|
296
|
+
return subscribedPeers.map(p => p.toString()).includes(componentsA.getPeerId().toString()) // eslint-disable-line max-nested-callbacks
|
|
382
297
|
})
|
|
383
|
-
psB.publish(topic, data)
|
|
298
|
+
await psB.publish(topic, data)
|
|
384
299
|
|
|
385
300
|
await defer1.promise
|
|
386
301
|
|
|
@@ -399,21 +314,15 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
399
314
|
await psB._libp2p.start()
|
|
400
315
|
await psB.start()
|
|
401
316
|
|
|
402
|
-
await connectPeers(psA.multicodecs[0],
|
|
403
|
-
peerId: peerA,
|
|
404
|
-
registrar: registrarA
|
|
405
|
-
}, {
|
|
406
|
-
peerId: peerB,
|
|
407
|
-
registrar: registrarB
|
|
408
|
-
})
|
|
317
|
+
await connectPeers(psA.multicodecs[0], componentsA, componentsB)
|
|
409
318
|
|
|
410
319
|
// wait for remoteLibp2p to know about libp2p subscription
|
|
411
320
|
await pWaitFor(() => {
|
|
412
321
|
const subscribedPeers = psB.getSubscribers(topic)
|
|
413
|
-
return subscribedPeers.toString().includes(
|
|
322
|
+
return subscribedPeers.toString().includes(componentsA.getPeerId().toString())
|
|
414
323
|
})
|
|
415
324
|
|
|
416
|
-
psB.publish(topic, data)
|
|
325
|
+
await psB.publish(topic, data)
|
|
417
326
|
|
|
418
327
|
await defer2.promise
|
|
419
328
|
})
|
|
@@ -469,23 +378,17 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
469
378
|
const originalConnection = await psA._libp2p.dialer.connectToPeer(psB.peerId)
|
|
470
379
|
|
|
471
380
|
// second connection
|
|
472
|
-
await connectPeers(psA.multicodecs[0],
|
|
473
|
-
peerId: peerA,
|
|
474
|
-
registrar: registrarA
|
|
475
|
-
}, {
|
|
476
|
-
peerId: peerB,
|
|
477
|
-
registrar: registrarB
|
|
478
|
-
})
|
|
381
|
+
await connectPeers(psA.multicodecs[0], componentsA, componentsB)
|
|
479
382
|
|
|
480
383
|
// Wait for subscriptions to occur
|
|
481
384
|
await pWaitFor(() => {
|
|
482
|
-
return psA.getSubscribers(topic).includes(
|
|
483
|
-
psB.getSubscribers(topic).map(p => p.toString()).includes(
|
|
385
|
+
return psA.getSubscribers(topic).map(p => p.toString()).includes(componentsB.getPeerId().toString()) &&
|
|
386
|
+
psB.getSubscribers(topic).map(p => p.toString()).includes(componentsA.getPeerId().toString())
|
|
484
387
|
})
|
|
485
388
|
|
|
486
389
|
// Verify messages go both ways
|
|
487
|
-
psA.publish(topic, uint8ArrayFromString('message-from-a-1'))
|
|
488
|
-
psB.publish(topic, uint8ArrayFromString('message-from-b-1'))
|
|
390
|
+
await psA.publish(topic, uint8ArrayFromString('message-from-a-1'))
|
|
391
|
+
await psB.publish(topic, uint8ArrayFromString('message-from-b-1'))
|
|
489
392
|
await pWaitFor(() => {
|
|
490
393
|
return aReceivedFirstMessageFromB && bReceivedFirstMessageFromA
|
|
491
394
|
})
|
|
@@ -498,8 +401,8 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
|
|
|
498
401
|
await pWaitFor(() => psAConnUpdateSpy.callCount === 1)
|
|
499
402
|
|
|
500
403
|
// Verify messages go both ways after the disconnect
|
|
501
|
-
psA.publish(topic, uint8ArrayFromString('message-from-a-2'))
|
|
502
|
-
psB.publish(topic, uint8ArrayFromString('message-from-b-2'))
|
|
404
|
+
await psA.publish(topic, uint8ArrayFromString('message-from-a-2'))
|
|
405
|
+
await psB.publish(topic, uint8ArrayFromString('message-from-b-2'))
|
|
503
406
|
await pWaitFor(() => {
|
|
504
407
|
return aReceivedSecondMessageFromB && bReceivedSecondMessageFromA
|
|
505
408
|
})
|