@libp2p/interface-compliance-tests 1.1.23 → 1.1.26
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 +2 -2
- 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 +2 -2
- package/dist/src/pubsub/connection-handlers.d.ts.map +1 -1
- package/dist/src/pubsub/connection-handlers.js +58 -148
- package/dist/src/pubsub/connection-handlers.js.map +1 -1
- package/dist/src/pubsub/emit-self.d.ts +2 -2
- 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/index.d.ts +2 -3
- package/dist/src/pubsub/index.d.ts.map +1 -1
- package/dist/src/pubsub/index.js.map +1 -1
- package/dist/src/pubsub/messages.d.ts +2 -2
- package/dist/src/pubsub/messages.d.ts.map +1 -1
- package/dist/src/pubsub/messages.js +13 -75
- package/dist/src/pubsub/messages.js.map +1 -1
- package/dist/src/pubsub/multiple-nodes.d.ts +2 -2
- 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 +2 -2
- 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 +5 -2
- package/dist/src/pubsub/utils.d.ts.map +1 -1
- package/dist/src/pubsub/utils.js +11 -1
- 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 +12 -18
- package/src/pubsub/connection-handlers.ts +69 -170
- package/src/pubsub/emit-self.ts +13 -10
- package/src/pubsub/index.ts +2 -3
- package/src/pubsub/messages.ts +18 -100
- package/src/pubsub/multiple-nodes.ts +98 -231
- package/src/pubsub/two-nodes.ts +27 -46
- package/src/pubsub/utils.ts +15 -4
|
@@ -1,29 +1,20 @@
|
|
|
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 { noSignMsgId } from '@libp2p/pubsub/utils';
|
|
6
|
-
import { PeerStreams } from '@libp2p/pubsub/peer-streams';
|
|
7
|
-
import { mockRegistrar } from '../mocks/registrar.js';
|
|
8
|
-
import pDefer from 'p-defer';
|
|
9
|
-
import delay from 'delay';
|
|
10
|
-
import pWaitFor from 'p-wait-for';
|
|
11
|
-
import { Components } from '@libp2p/interfaces/components';
|
|
12
4
|
import { start, stop } from '../index.js';
|
|
5
|
+
import { pEvent } from 'p-event';
|
|
6
|
+
import { createComponents } from './utils.js';
|
|
13
7
|
const topic = 'foo';
|
|
14
8
|
const data = uint8ArrayFromString('bar');
|
|
15
9
|
export default (common) => {
|
|
16
10
|
describe('messages', () => {
|
|
17
|
-
let peerId;
|
|
18
11
|
let pubsub;
|
|
12
|
+
let components;
|
|
19
13
|
// Create pubsub router
|
|
20
14
|
beforeEach(async () => {
|
|
21
|
-
|
|
15
|
+
components = await createComponents();
|
|
22
16
|
pubsub = await common.setup({
|
|
23
|
-
components
|
|
24
|
-
peerId,
|
|
25
|
-
registrar: mockRegistrar()
|
|
26
|
-
}),
|
|
17
|
+
components,
|
|
27
18
|
init: {
|
|
28
19
|
emitSelf: true
|
|
29
20
|
}
|
|
@@ -36,69 +27,16 @@ export default (common) => {
|
|
|
36
27
|
await common.teardown();
|
|
37
28
|
});
|
|
38
29
|
it('should emit normalized signed messages on publish', async () => {
|
|
30
|
+
const eventPromise = pEvent(pubsub, 'message');
|
|
39
31
|
pubsub.globalSignaturePolicy = 'StrictSign';
|
|
40
|
-
const spy = sinon.spy(pubsub, 'publishMessage');
|
|
41
|
-
await pubsub.publish(topic, data);
|
|
42
|
-
await pWaitFor(async () => {
|
|
43
|
-
return spy.callCount === 1;
|
|
44
|
-
});
|
|
45
|
-
expect(spy).to.have.property('callCount', 1);
|
|
46
|
-
const [from, messageToEmit] = spy.getCall(0).args;
|
|
47
|
-
expect(from.toString()).to.equal(peerId.toString());
|
|
48
|
-
expect(messageToEmit.sequenceNumber).to.not.eql(undefined);
|
|
49
|
-
expect(messageToEmit.key).to.not.eql(undefined);
|
|
50
|
-
expect(messageToEmit.signature).to.not.eql(undefined);
|
|
51
|
-
});
|
|
52
|
-
it('should drop unsigned messages', async () => {
|
|
53
|
-
const publishSpy = sinon.spy(pubsub, 'publishMessage');
|
|
54
|
-
sinon.spy(pubsub, 'validate');
|
|
55
|
-
const peerStream = new PeerStreams({
|
|
56
|
-
id: await createEd25519PeerId(),
|
|
57
|
-
protocol: 'test'
|
|
58
|
-
});
|
|
59
|
-
const rpc = {
|
|
60
|
-
subscriptions: [],
|
|
61
|
-
messages: [{
|
|
62
|
-
from: peerStream.id.toBytes(),
|
|
63
|
-
data,
|
|
64
|
-
sequenceNumber: await noSignMsgId(data),
|
|
65
|
-
topic: topic
|
|
66
|
-
}]
|
|
67
|
-
};
|
|
68
|
-
pubsub.subscribe(topic);
|
|
69
|
-
await pubsub.processRpc(peerStream.id, peerStream, rpc);
|
|
70
|
-
// message should not be delivered
|
|
71
|
-
await delay(1000);
|
|
72
|
-
expect(publishSpy).to.have.property('called', false);
|
|
73
|
-
});
|
|
74
|
-
it('should not drop unsigned messages if strict signing is disabled', async () => {
|
|
75
|
-
pubsub.globalSignaturePolicy = 'StrictNoSign';
|
|
76
|
-
const publishSpy = sinon.spy(pubsub, 'publishMessage');
|
|
77
|
-
sinon.spy(pubsub, 'validate');
|
|
78
|
-
const peerStream = new PeerStreams({
|
|
79
|
-
id: await createEd25519PeerId(),
|
|
80
|
-
protocol: 'test'
|
|
81
|
-
});
|
|
82
|
-
const rpc = {
|
|
83
|
-
subscriptions: [],
|
|
84
|
-
messages: [{
|
|
85
|
-
from: peerStream.id.toBytes(),
|
|
86
|
-
data,
|
|
87
|
-
topic
|
|
88
|
-
}]
|
|
89
|
-
};
|
|
90
32
|
pubsub.subscribe(topic);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// await message delivery
|
|
99
|
-
await deferred.promise;
|
|
100
|
-
expect(pubsub.validate).to.have.property('callCount', 1);
|
|
101
|
-
expect(publishSpy).to.have.property('callCount', 1);
|
|
33
|
+
await pubsub.publish(topic, data);
|
|
34
|
+
const event = await eventPromise;
|
|
35
|
+
const message = event.detail;
|
|
36
|
+
expect(message.from.toString()).to.equal(components.getPeerId().toString());
|
|
37
|
+
expect(message.sequenceNumber).to.not.eql(undefined);
|
|
38
|
+
expect(message.key).to.not.eql(undefined);
|
|
39
|
+
expect(message.signature).to.not.eql(undefined);
|
|
102
40
|
});
|
|
103
41
|
});
|
|
104
42
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../src/pubsub/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../src/pubsub/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAK5E,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,KAAK,GAAG,KAAK,CAAA;AACnB,MAAM,IAAI,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAA;AAExC,eAAe,CAAC,MAAqC,EAAE,EAAE;IACvD,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;QACxB,IAAI,MAAc,CAAA;QAClB,IAAI,UAAsB,CAAA;QAE1B,uBAAuB;QACvB,UAAU,CAAC,KAAK,IAAI,EAAE;YACpB,UAAU,GAAG,MAAM,gBAAgB,EAAE,CAAA;YAErC,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC;gBAC1B,UAAU;gBACV,IAAI,EAAE;oBACJ,QAAQ,EAAE,IAAI;iBACf;aACF,CAAC,CAAA;YACF,MAAM,KAAK,CAAC,MAAM,CAAC,CAAA;QACrB,CAAC,CAAC,CAAA;QAEF,SAAS,CAAC,KAAK,IAAI,EAAE;YACnB,KAAK,CAAC,OAAO,EAAE,CAAA;YACf,MAAM,IAAI,CAAC,MAAM,CAAC,CAAA;YAClB,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAA;QACzB,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,mDAAmD,EAAE,KAAK,IAAI,EAAE;YACjE,MAAM,YAAY,GAAG,MAAM,CAAkC,MAAM,EAAE,SAAS,CAAC,CAAA;YAE/E,MAAM,CAAC,qBAAqB,GAAG,YAAY,CAAA;YAC3C,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;YACvB,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YAEjC,MAAM,KAAK,GAAG,MAAM,YAAY,CAAA;YAChC,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAA;YAE5B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAA;YAC3E,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YACpD,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YACzC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QACjD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TestSetup } from '../index.js';
|
|
2
|
+
import type { PubSub } from '@libp2p/interfaces/pubsub';
|
|
2
3
|
import type { PubSubArgs } from './index.js';
|
|
3
|
-
|
|
4
|
-
declare const _default: (common: TestSetup<PubSubBaseProtocol, PubSubArgs>) => void;
|
|
4
|
+
declare const _default: (common: TestSetup<PubSub, PubSubArgs>) => void;
|
|
5
5
|
export default _default;
|
|
6
6
|
//# sourceMappingURL=multiple-nodes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multiple-nodes.d.ts","sourceRoot":"","sources":["../../../src/pubsub/multiple-nodes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"multiple-nodes.d.ts","sourceRoot":"","sources":["../../../src/pubsub/multiple-nodes.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAW,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;iCAIpB,UAAU,MAAM,EAAE,UAAU,CAAC;AAArD,wBAmZC"}
|
|
@@ -5,10 +5,8 @@ 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 {
|
|
9
|
-
import {
|
|
10
|
-
import { waitForSubscriptionUpdate } from './utils.js';
|
|
11
|
-
import { Components } from '@libp2p/interfaces/components';
|
|
8
|
+
import { connectPeers } from '../mocks/registrar.js';
|
|
9
|
+
import { createComponents, waitForSubscriptionUpdate } from './utils.js';
|
|
12
10
|
import { start, stop } from '../index.js';
|
|
13
11
|
export default (common) => {
|
|
14
12
|
describe('pubsub with multiple nodes', function () {
|
|
@@ -20,43 +18,28 @@ export default (common) => {
|
|
|
20
18
|
let psA;
|
|
21
19
|
let psB;
|
|
22
20
|
let psC;
|
|
23
|
-
let
|
|
24
|
-
let
|
|
25
|
-
let
|
|
26
|
-
let registrarA;
|
|
27
|
-
let registrarB;
|
|
28
|
-
let registrarC;
|
|
21
|
+
let componentsA;
|
|
22
|
+
let componentsB;
|
|
23
|
+
let componentsC;
|
|
29
24
|
// Create and start pubsub nodes
|
|
30
25
|
beforeEach(async () => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
registrarA = mockRegistrar();
|
|
35
|
-
registrarB = mockRegistrar();
|
|
36
|
-
registrarC = mockRegistrar();
|
|
26
|
+
componentsA = await createComponents();
|
|
27
|
+
componentsB = await createComponents();
|
|
28
|
+
componentsC = await createComponents();
|
|
37
29
|
psA = await common.setup({
|
|
38
|
-
components:
|
|
39
|
-
peerId: peerIdA,
|
|
40
|
-
registrar: registrarA
|
|
41
|
-
}),
|
|
30
|
+
components: componentsA,
|
|
42
31
|
init: {
|
|
43
32
|
emitSelf: true
|
|
44
33
|
}
|
|
45
34
|
});
|
|
46
35
|
psB = await common.setup({
|
|
47
|
-
components:
|
|
48
|
-
peerId: peerIdB,
|
|
49
|
-
registrar: registrarB
|
|
50
|
-
}),
|
|
36
|
+
components: componentsB,
|
|
51
37
|
init: {
|
|
52
38
|
emitSelf: true
|
|
53
39
|
}
|
|
54
40
|
});
|
|
55
41
|
psC = await common.setup({
|
|
56
|
-
components:
|
|
57
|
-
peerId: peerIdC,
|
|
58
|
-
registrar: registrarC
|
|
59
|
-
}),
|
|
42
|
+
components: componentsC,
|
|
60
43
|
init: {
|
|
61
44
|
emitSelf: true
|
|
62
45
|
}
|
|
@@ -66,20 +49,8 @@ export default (common) => {
|
|
|
66
49
|
});
|
|
67
50
|
// Connect nodes
|
|
68
51
|
beforeEach(async () => {
|
|
69
|
-
await connectPeers(psA.multicodecs[0],
|
|
70
|
-
|
|
71
|
-
registrar: registrarA
|
|
72
|
-
}, {
|
|
73
|
-
peerId: peerIdB,
|
|
74
|
-
registrar: registrarB
|
|
75
|
-
});
|
|
76
|
-
await connectPeers(psA.multicodecs[0], {
|
|
77
|
-
peerId: peerIdB,
|
|
78
|
-
registrar: registrarB
|
|
79
|
-
}, {
|
|
80
|
-
peerId: peerIdC,
|
|
81
|
-
registrar: registrarC
|
|
82
|
-
});
|
|
52
|
+
await connectPeers(psA.multicodecs[0], componentsA, componentsB);
|
|
53
|
+
await connectPeers(psB.multicodecs[0], componentsB, componentsC);
|
|
83
54
|
// Wait for peers to be ready in pubsub
|
|
84
55
|
await pWaitFor(() => psA.getPeers().length === 1 &&
|
|
85
56
|
psC.getPeers().length === 1 &&
|
|
@@ -94,9 +65,9 @@ export default (common) => {
|
|
|
94
65
|
const topic = 'Z';
|
|
95
66
|
psA.subscribe(topic);
|
|
96
67
|
expect(psA.getTopics()).to.deep.equal([topic]);
|
|
97
|
-
await waitForSubscriptionUpdate(psB,
|
|
68
|
+
await waitForSubscriptionUpdate(psB, componentsA.getPeerId());
|
|
98
69
|
expect(psB.getPeers().length).to.equal(2);
|
|
99
|
-
expect(psB.getSubscribers(topic).map(p => p.toString())).to.deep.equal([
|
|
70
|
+
expect(psB.getSubscribers(topic).map(p => p.toString())).to.deep.equal([componentsA.getPeerId().toString()]);
|
|
100
71
|
expect(psC.getPeers().length).to.equal(1);
|
|
101
72
|
expect(psC.getSubscribers(topic)).to.be.empty();
|
|
102
73
|
});
|
|
@@ -105,13 +76,13 @@ export default (common) => {
|
|
|
105
76
|
psB.subscribe(topic);
|
|
106
77
|
expect(psB.getTopics()).to.deep.equal([topic]);
|
|
107
78
|
await Promise.all([
|
|
108
|
-
waitForSubscriptionUpdate(psA,
|
|
109
|
-
waitForSubscriptionUpdate(psC,
|
|
79
|
+
waitForSubscriptionUpdate(psA, componentsB.getPeerId()),
|
|
80
|
+
waitForSubscriptionUpdate(psC, componentsB.getPeerId())
|
|
110
81
|
]);
|
|
111
82
|
expect(psA.getPeers().length).to.equal(1);
|
|
112
|
-
expect(psA.getSubscribers(topic).map(p => p.toString())).to.deep.equal([
|
|
83
|
+
expect(psA.getSubscribers(topic).map(p => p.toString())).to.deep.equal([componentsB.getPeerId().toString()]);
|
|
113
84
|
expect(psC.getPeers().length).to.equal(1);
|
|
114
|
-
expect(psC.getSubscribers(topic).map(p => p.toString())).to.deep.equal([
|
|
85
|
+
expect(psC.getSubscribers(topic).map(p => p.toString())).to.deep.equal([componentsB.getPeerId().toString()]);
|
|
115
86
|
});
|
|
116
87
|
it('subscribe to the topic on node c', async () => {
|
|
117
88
|
const topic = 'Z';
|
|
@@ -121,7 +92,7 @@ export default (common) => {
|
|
|
121
92
|
psB.addEventListener('subscription-change', () => {
|
|
122
93
|
expect(psA.getPeers().length).to.equal(1);
|
|
123
94
|
expect(psB.getPeers().length).to.equal(2);
|
|
124
|
-
expect(psB.getSubscribers(topic).map(p => p.toString())).to.deep.equal([
|
|
95
|
+
expect(psB.getSubscribers(topic).map(p => p.toString())).to.deep.equal([componentsC.getPeerId().toString()]);
|
|
125
96
|
defer.resolve();
|
|
126
97
|
}, {
|
|
127
98
|
once: true
|
|
@@ -135,49 +106,29 @@ export default (common) => {
|
|
|
135
106
|
psB.subscribe(topic);
|
|
136
107
|
psC.subscribe(topic);
|
|
137
108
|
let counter = 0;
|
|
138
|
-
psA.addEventListener('message',
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
psB.addEventListener('message', (evt) => {
|
|
144
|
-
if (evt.detail.topic === topic) {
|
|
145
|
-
incMsg(evt);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
psC.addEventListener('message', (evt) => {
|
|
149
|
-
if (evt.detail.topic === topic) {
|
|
150
|
-
incMsg(evt);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
109
|
+
psA.addEventListener('message', incMsg);
|
|
110
|
+
psB.addEventListener('message', incMsg);
|
|
111
|
+
psC.addEventListener('message', incMsg);
|
|
153
112
|
await Promise.all([
|
|
154
|
-
waitForSubscriptionUpdate(psA,
|
|
155
|
-
waitForSubscriptionUpdate(psB,
|
|
156
|
-
waitForSubscriptionUpdate(psC,
|
|
113
|
+
waitForSubscriptionUpdate(psA, componentsB.getPeerId()),
|
|
114
|
+
waitForSubscriptionUpdate(psB, componentsA.getPeerId()),
|
|
115
|
+
waitForSubscriptionUpdate(psC, componentsB.getPeerId())
|
|
157
116
|
]);
|
|
158
|
-
psA.publish(topic, uint8ArrayFromString('hey'));
|
|
117
|
+
const result = await psA.publish(topic, uint8ArrayFromString('hey'));
|
|
118
|
+
expect(result).to.have.property('recipients').with.property('length').greaterThanOrEqual(1);
|
|
159
119
|
function incMsg(evt) {
|
|
160
120
|
const msg = evt.detail;
|
|
121
|
+
if (msg.topic !== topic) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
161
124
|
expect(uint8ArrayToString(msg.data)).to.equal('hey');
|
|
162
125
|
check();
|
|
163
126
|
}
|
|
164
127
|
function check() {
|
|
165
128
|
if (++counter === 3) {
|
|
166
|
-
psA.removeEventListener('message',
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
psB.removeEventListener('message', (evt) => {
|
|
172
|
-
if (evt.detail.topic === topic) {
|
|
173
|
-
incMsg(evt);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
psC.removeEventListener('message', (evt) => {
|
|
177
|
-
if (evt.detail.topic === topic) {
|
|
178
|
-
incMsg(evt);
|
|
179
|
-
}
|
|
180
|
-
});
|
|
129
|
+
psA.removeEventListener('message', incMsg);
|
|
130
|
+
psB.removeEventListener('message', incMsg);
|
|
131
|
+
psC.removeEventListener('message', incMsg);
|
|
181
132
|
defer.resolve();
|
|
182
133
|
}
|
|
183
134
|
}
|
|
@@ -195,52 +146,31 @@ export default (common) => {
|
|
|
195
146
|
const topic = 'Z';
|
|
196
147
|
const defer = pDefer();
|
|
197
148
|
let counter = 0;
|
|
198
|
-
psA.addEventListener('message',
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
psB.addEventListener('message', (evt) => {
|
|
204
|
-
if (evt.detail.topic === topic) {
|
|
205
|
-
incMsg(evt);
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
psC.addEventListener('message', (evt) => {
|
|
209
|
-
if (evt.detail.topic === topic) {
|
|
210
|
-
incMsg(evt);
|
|
211
|
-
}
|
|
212
|
-
});
|
|
149
|
+
psA.addEventListener('message', incMsg);
|
|
150
|
+
psB.addEventListener('message', incMsg);
|
|
151
|
+
psC.addEventListener('message', incMsg);
|
|
213
152
|
psA.subscribe(topic);
|
|
214
153
|
psB.subscribe(topic);
|
|
215
154
|
psC.subscribe(topic);
|
|
216
155
|
await Promise.all([
|
|
217
|
-
waitForSubscriptionUpdate(psA,
|
|
218
|
-
waitForSubscriptionUpdate(psB,
|
|
219
|
-
waitForSubscriptionUpdate(psC,
|
|
156
|
+
waitForSubscriptionUpdate(psA, componentsB.getPeerId()),
|
|
157
|
+
waitForSubscriptionUpdate(psB, componentsA.getPeerId()),
|
|
158
|
+
waitForSubscriptionUpdate(psC, componentsB.getPeerId())
|
|
220
159
|
]);
|
|
221
|
-
psB.publish(topic, uint8ArrayFromString('hey'));
|
|
160
|
+
await psB.publish(topic, uint8ArrayFromString('hey'));
|
|
222
161
|
function incMsg(evt) {
|
|
223
162
|
const msg = evt.detail;
|
|
163
|
+
if (msg.topic !== topic) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
224
166
|
expect(uint8ArrayToString(msg.data)).to.equal('hey');
|
|
225
167
|
check();
|
|
226
168
|
}
|
|
227
169
|
function check() {
|
|
228
170
|
if (++counter === 3) {
|
|
229
|
-
psA.removeEventListener('message',
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
psB.removeEventListener('message', (evt) => {
|
|
235
|
-
if (evt.detail.topic === topic) {
|
|
236
|
-
incMsg(evt);
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
psC.removeEventListener('message', (evt) => {
|
|
240
|
-
if (evt.detail.topic === topic) {
|
|
241
|
-
incMsg(evt);
|
|
242
|
-
}
|
|
243
|
-
});
|
|
171
|
+
psA.removeEventListener('message', incMsg);
|
|
172
|
+
psB.removeEventListener('message', incMsg);
|
|
173
|
+
psC.removeEventListener('message', incMsg);
|
|
244
174
|
defer.resolve();
|
|
245
175
|
}
|
|
246
176
|
}
|
|
@@ -261,69 +191,44 @@ export default (common) => {
|
|
|
261
191
|
let psC;
|
|
262
192
|
let psD;
|
|
263
193
|
let psE;
|
|
264
|
-
let
|
|
265
|
-
let
|
|
266
|
-
let
|
|
267
|
-
let
|
|
268
|
-
let
|
|
269
|
-
let registrarA;
|
|
270
|
-
let registrarB;
|
|
271
|
-
let registrarC;
|
|
272
|
-
let registrarD;
|
|
273
|
-
let registrarE;
|
|
194
|
+
let componentsA;
|
|
195
|
+
let componentsB;
|
|
196
|
+
let componentsC;
|
|
197
|
+
let componentsD;
|
|
198
|
+
let componentsE;
|
|
274
199
|
// Create and start pubsub nodes
|
|
275
200
|
beforeEach(async () => {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
registrarA = mockRegistrar();
|
|
282
|
-
registrarB = mockRegistrar();
|
|
283
|
-
registrarC = mockRegistrar();
|
|
284
|
-
registrarD = mockRegistrar();
|
|
285
|
-
registrarE = mockRegistrar();
|
|
201
|
+
componentsA = await createComponents();
|
|
202
|
+
componentsB = await createComponents();
|
|
203
|
+
componentsC = await createComponents();
|
|
204
|
+
componentsD = await createComponents();
|
|
205
|
+
componentsE = await createComponents();
|
|
286
206
|
psA = await common.setup({
|
|
287
|
-
components:
|
|
288
|
-
peerId: peerIdA,
|
|
289
|
-
registrar: registrarA
|
|
290
|
-
}),
|
|
207
|
+
components: componentsA,
|
|
291
208
|
init: {
|
|
292
209
|
emitSelf: true
|
|
293
210
|
}
|
|
294
211
|
});
|
|
295
212
|
psB = await common.setup({
|
|
296
|
-
components:
|
|
297
|
-
peerId: peerIdB,
|
|
298
|
-
registrar: registrarB
|
|
299
|
-
}),
|
|
213
|
+
components: componentsB,
|
|
300
214
|
init: {
|
|
301
215
|
emitSelf: true
|
|
302
216
|
}
|
|
303
217
|
});
|
|
304
218
|
psC = await common.setup({
|
|
305
|
-
components:
|
|
306
|
-
peerId: peerIdC,
|
|
307
|
-
registrar: registrarC
|
|
308
|
-
}),
|
|
219
|
+
components: componentsC,
|
|
309
220
|
init: {
|
|
310
221
|
emitSelf: true
|
|
311
222
|
}
|
|
312
223
|
});
|
|
313
224
|
psD = await common.setup({
|
|
314
|
-
components:
|
|
315
|
-
peerId: peerIdD,
|
|
316
|
-
registrar: registrarD
|
|
317
|
-
}),
|
|
225
|
+
components: componentsD,
|
|
318
226
|
init: {
|
|
319
227
|
emitSelf: true
|
|
320
228
|
}
|
|
321
229
|
});
|
|
322
230
|
psE = await common.setup({
|
|
323
|
-
components:
|
|
324
|
-
peerId: peerIdE,
|
|
325
|
-
registrar: registrarE
|
|
326
|
-
}),
|
|
231
|
+
components: componentsE,
|
|
327
232
|
init: {
|
|
328
233
|
emitSelf: true
|
|
329
234
|
}
|
|
@@ -333,34 +238,10 @@ export default (common) => {
|
|
|
333
238
|
});
|
|
334
239
|
// connect nodes
|
|
335
240
|
beforeEach(async () => {
|
|
336
|
-
await connectPeers(psA.multicodecs[0],
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
peerId: peerIdB,
|
|
341
|
-
registrar: registrarB
|
|
342
|
-
});
|
|
343
|
-
await connectPeers(psA.multicodecs[0], {
|
|
344
|
-
peerId: peerIdB,
|
|
345
|
-
registrar: registrarB
|
|
346
|
-
}, {
|
|
347
|
-
peerId: peerIdC,
|
|
348
|
-
registrar: registrarC
|
|
349
|
-
});
|
|
350
|
-
await connectPeers(psA.multicodecs[0], {
|
|
351
|
-
peerId: peerIdC,
|
|
352
|
-
registrar: registrarC
|
|
353
|
-
}, {
|
|
354
|
-
peerId: peerIdD,
|
|
355
|
-
registrar: registrarD
|
|
356
|
-
});
|
|
357
|
-
await connectPeers(psA.multicodecs[0], {
|
|
358
|
-
peerId: peerIdD,
|
|
359
|
-
registrar: registrarD
|
|
360
|
-
}, {
|
|
361
|
-
peerId: peerIdE,
|
|
362
|
-
registrar: registrarE
|
|
363
|
-
});
|
|
241
|
+
await connectPeers(psA.multicodecs[0], componentsA, componentsB);
|
|
242
|
+
await connectPeers(psA.multicodecs[0], componentsB, componentsC);
|
|
243
|
+
await connectPeers(psA.multicodecs[0], componentsC, componentsD);
|
|
244
|
+
await connectPeers(psA.multicodecs[0], componentsD, componentsE);
|
|
364
245
|
// Wait for peers to be ready in pubsub
|
|
365
246
|
await pWaitFor(() => psA.getPeers().length === 1 &&
|
|
366
247
|
psB.getPeers().length === 2 &&
|
|
@@ -389,45 +270,28 @@ export default (common) => {
|
|
|
389
270
|
let counter = 0;
|
|
390
271
|
const topic = 'Z';
|
|
391
272
|
psA.subscribe(topic);
|
|
392
|
-
psA.addEventListener('message',
|
|
393
|
-
if (evt.detail.topic === topic) {
|
|
394
|
-
incMsg(evt);
|
|
395
|
-
}
|
|
396
|
-
});
|
|
273
|
+
psA.addEventListener('message', incMsg);
|
|
397
274
|
psB.subscribe(topic);
|
|
398
|
-
psB.addEventListener('message',
|
|
399
|
-
if (evt.detail.topic === topic) {
|
|
400
|
-
incMsg(evt);
|
|
401
|
-
}
|
|
402
|
-
});
|
|
275
|
+
psB.addEventListener('message', incMsg);
|
|
403
276
|
psC.subscribe(topic);
|
|
404
|
-
psC.addEventListener('message',
|
|
405
|
-
if (evt.detail.topic === topic) {
|
|
406
|
-
incMsg(evt);
|
|
407
|
-
}
|
|
408
|
-
});
|
|
277
|
+
psC.addEventListener('message', incMsg);
|
|
409
278
|
psD.subscribe(topic);
|
|
410
|
-
psD.addEventListener('message',
|
|
411
|
-
if (evt.detail.topic === topic) {
|
|
412
|
-
incMsg(evt);
|
|
413
|
-
}
|
|
414
|
-
});
|
|
279
|
+
psD.addEventListener('message', incMsg);
|
|
415
280
|
psE.subscribe(topic);
|
|
416
|
-
psE.addEventListener('message',
|
|
417
|
-
if (evt.detail.topic === topic) {
|
|
418
|
-
incMsg(evt);
|
|
419
|
-
}
|
|
420
|
-
});
|
|
281
|
+
psE.addEventListener('message', incMsg);
|
|
421
282
|
await Promise.all([
|
|
422
|
-
waitForSubscriptionUpdate(psA,
|
|
423
|
-
waitForSubscriptionUpdate(psB,
|
|
424
|
-
waitForSubscriptionUpdate(psC,
|
|
425
|
-
waitForSubscriptionUpdate(psD,
|
|
426
|
-
waitForSubscriptionUpdate(psE,
|
|
283
|
+
waitForSubscriptionUpdate(psA, componentsB.getPeerId()),
|
|
284
|
+
waitForSubscriptionUpdate(psB, componentsA.getPeerId()),
|
|
285
|
+
waitForSubscriptionUpdate(psC, componentsB.getPeerId()),
|
|
286
|
+
waitForSubscriptionUpdate(psD, componentsC.getPeerId()),
|
|
287
|
+
waitForSubscriptionUpdate(psE, componentsD.getPeerId())
|
|
427
288
|
]);
|
|
428
|
-
psC.publish('Z', uint8ArrayFromString('hey from c'));
|
|
289
|
+
await psC.publish('Z', uint8ArrayFromString('hey from c'));
|
|
429
290
|
function incMsg(evt) {
|
|
430
291
|
const msg = evt.detail;
|
|
292
|
+
if (msg.topic !== topic) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
431
295
|
expect(uint8ArrayToString(msg.data)).to.equal('hey from c');
|
|
432
296
|
check();
|
|
433
297
|
}
|