@libp2p/interface-compliance-tests 1.1.6 → 1.1.10
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.d.ts +13 -2
- package/dist/src/mocks/connection.d.ts.map +1 -1
- package/dist/src/mocks/connection.js +56 -24
- package/dist/src/mocks/connection.js.map +1 -1
- package/dist/src/mocks/multiaddr-connection.d.ts +2 -1
- package/dist/src/mocks/multiaddr-connection.d.ts.map +1 -1
- package/dist/src/mocks/multiaddr-connection.js +2 -2
- package/dist/src/mocks/multiaddr-connection.js.map +1 -1
- package/dist/src/mocks/muxer.d.ts +2 -2
- package/dist/src/mocks/muxer.d.ts.map +1 -1
- package/dist/src/mocks/muxer.js +175 -26
- package/dist/src/mocks/muxer.js.map +1 -1
- package/dist/src/mocks/registrar.d.ts +11 -2
- package/dist/src/mocks/registrar.d.ts.map +1 -1
- package/dist/src/mocks/registrar.js +47 -5
- package/dist/src/mocks/registrar.js.map +1 -1
- package/dist/src/mocks/upgrader.d.ts.map +1 -1
- package/dist/src/mocks/upgrader.js +8 -4
- package/dist/src/mocks/upgrader.js.map +1 -1
- package/dist/src/pubsub/api.d.ts +3 -2
- package/dist/src/pubsub/api.d.ts.map +1 -1
- package/dist/src/pubsub/api.js +23 -13
- package/dist/src/pubsub/api.js.map +1 -1
- package/dist/src/pubsub/connection-handlers.d.ts +3 -2
- package/dist/src/pubsub/connection-handlers.d.ts.map +1 -1
- package/dist/src/pubsub/connection-handlers.js +165 -69
- package/dist/src/pubsub/connection-handlers.js.map +1 -1
- package/dist/src/pubsub/emit-self.d.ts +3 -2
- package/dist/src/pubsub/emit-self.d.ts.map +1 -1
- package/dist/src/pubsub/emit-self.js +15 -4
- package/dist/src/pubsub/emit-self.js.map +1 -1
- package/dist/src/pubsub/index.d.ts +6 -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 +3 -2
- package/dist/src/pubsub/messages.d.ts.map +1 -1
- package/dist/src/pubsub/messages.js +42 -39
- package/dist/src/pubsub/messages.js.map +1 -1
- package/dist/src/pubsub/multiple-nodes.d.ts +3 -2
- package/dist/src/pubsub/multiple-nodes.d.ts.map +1 -1
- package/dist/src/pubsub/multiple-nodes.js +163 -65
- package/dist/src/pubsub/multiple-nodes.js.map +1 -1
- package/dist/src/pubsub/two-nodes.d.ts +3 -2
- package/dist/src/pubsub/two-nodes.d.ts.map +1 -1
- package/dist/src/pubsub/two-nodes.js +80 -38
- package/dist/src/pubsub/two-nodes.js.map +1 -1
- package/dist/src/stream-muxer/base-test.js +1 -1
- package/dist/src/stream-muxer/base-test.js.map +1 -1
- package/dist/src/stream-muxer/close-test.d.ts.map +1 -1
- package/dist/src/stream-muxer/close-test.js +12 -10
- package/dist/src/stream-muxer/close-test.js.map +1 -1
- package/dist/src/transport/dial-test.d.ts.map +1 -1
- package/dist/src/transport/dial-test.js +2 -1
- package/dist/src/transport/dial-test.js.map +1 -1
- package/dist/src/transport/filter-test.js +1 -1
- package/dist/src/transport/filter-test.js.map +1 -1
- package/dist/src/transport/listen-test.d.ts.map +1 -1
- package/dist/src/transport/listen-test.js +2 -1
- package/dist/src/transport/listen-test.js.map +1 -1
- package/dist/src/utils/is-valid-tick.d.ts +6 -0
- package/dist/src/utils/is-valid-tick.d.ts.map +1 -0
- package/dist/src/utils/is-valid-tick.js +15 -0
- package/dist/src/utils/is-valid-tick.js.map +1 -0
- package/package.json +7 -5
- package/src/mocks/connection.ts +80 -24
- package/src/mocks/multiaddr-connection.ts +3 -2
- package/src/mocks/muxer.ts +230 -28
- package/src/mocks/registrar.ts +65 -7
- package/src/mocks/upgrader.ts +8 -5
- package/src/pubsub/api.ts +29 -15
- package/src/pubsub/connection-handlers.ts +186 -75
- package/src/pubsub/emit-self.ts +19 -7
- package/src/pubsub/index.ts +6 -3
- package/src/pubsub/messages.ts +59 -44
- package/src/pubsub/multiple-nodes.ts +189 -76
- package/src/pubsub/two-nodes.ts +94 -46
- package/src/stream-muxer/base-test.ts +1 -1
- package/src/stream-muxer/close-test.ts +13 -12
- package/src/transport/dial-test.ts +2 -1
- package/src/transport/filter-test.ts +1 -1
- package/src/transport/listen-test.ts +2 -1
- package/src/utils/is-valid-tick.ts +18 -0
- package/dist/src/pubsub/utils.d.ts +0 -3
- package/dist/src/pubsub/utils.d.ts.map +0 -1
- package/dist/src/pubsub/utils.js +0 -11
- package/dist/src/pubsub/utils.js.map +0 -1
- package/dist/src/transport/utils/index.d.ts +0 -15
- package/dist/src/transport/utils/index.d.ts.map +0 -1
- package/dist/src/transport/utils/index.js +0 -137
- package/dist/src/transport/utils/index.js.map +0 -1
- package/src/pubsub/utils.ts +0 -13
- package/src/transport/utils/index.ts +0 -172
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit-self.js","sourceRoot":"","sources":["../../../src/pubsub/emit-self.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"emit-self.js","sourceRoot":"","sources":["../../../src/pubsub/emit-self.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAMhD,MAAM,KAAK,GAAG,KAAK,CAAA;AACnB,MAAM,IAAI,GAAG,oBAAoB,CAAC,KAAK,CAAC,C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p/interfaces/pubsub';
|
|
3
|
+
import type { PubsubBaseProtocol } from '@libp2p/pubsub';
|
|
4
|
+
export interface EventMap extends PubSubEvents {
|
|
4
5
|
'topic': CustomEvent<Message>;
|
|
5
6
|
'foo': CustomEvent<Message>;
|
|
6
7
|
'test-topic': CustomEvent<Message>;
|
|
7
8
|
'reconnect-channel': CustomEvent<Message>;
|
|
8
9
|
'Z': CustomEvent<Message>;
|
|
10
|
+
'Za': CustomEvent<Message>;
|
|
11
|
+
'Zb': CustomEvent<Message>;
|
|
9
12
|
}
|
|
10
|
-
declare const _default: (common: TestSetup<
|
|
13
|
+
declare const _default: (common: TestSetup<PubsubBaseProtocol<EventMap>, PubSubOptions>) => void;
|
|
11
14
|
export default _default;
|
|
12
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pubsub/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pubsub/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACrF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAExD,MAAM,WAAW,QAAS,SAAQ,YAAY;IAC5C,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IAC7B,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IAC3B,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IAClC,mBAAmB,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IACzC,GAAG,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IACzB,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IAC1B,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;CAC3B;iCAEuB,UAAU,mBAAmB,QAAQ,CAAC,EAAE,aAAa,CAAC;AAA9E,wBASC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pubsub/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,YAAY,MAAM,eAAe,CAAA;AACxC,OAAO,sBAAsB,MAAM,0BAA0B,CAAA;AAC7D,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,iBAAiB,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pubsub/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,YAAY,MAAM,eAAe,CAAA;AACxC,OAAO,sBAAsB,MAAM,0BAA0B,CAAA;AAC7D,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,iBAAiB,MAAM,qBAAqB,CAAA;AAenD,eAAe,CAAC,MAA8D,EAAE,EAAE;IAChF,QAAQ,CAAC,mCAAmC,EAAE,GAAG,EAAE;QACjD,OAAO,CAAC,MAAM,CAAC,CAAA;QACf,YAAY,CAAC,MAAM,CAAC,CAAA;QACpB,YAAY,CAAC,MAAM,CAAC,CAAA;QACpB,sBAAsB,CAAC,MAAM,CAAC,CAAA;QAC9B,YAAY,CAAC,MAAM,CAAC,CAAA;QACpB,iBAAiB,CAAC,MAAM,CAAC,CAAA;IAC3B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TestSetup } from '../index.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PubSubOptions } from '@libp2p/interfaces/pubsub';
|
|
3
3
|
import type { EventMap } from './index.js';
|
|
4
|
-
|
|
4
|
+
import type { PubsubBaseProtocol } from '@libp2p/pubsub';
|
|
5
|
+
declare const _default: (common: TestSetup<PubsubBaseProtocol<EventMap>, PubSubOptions>) => void;
|
|
5
6
|
export default _default;
|
|
6
7
|
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/pubsub/messages.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/pubsub/messages.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAO,MAAM,2BAA2B,CAAA;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;iCAKhC,UAAU,mBAAmB,QAAQ,CAAC,EAAE,aAAa,CAAC;AAA9E,wBA0GC"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { expect } from 'aegir/utils/chai.js';
|
|
2
2
|
import sinon from 'sinon';
|
|
3
|
-
import
|
|
3
|
+
import { createEd25519PeerId } from '@libp2p/peer-id-factory';
|
|
4
4
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
5
|
-
import
|
|
5
|
+
import { noSignMsgId } from '@libp2p/pubsub/utils';
|
|
6
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 { CustomEvent } from '@libp2p/interfaces';
|
|
7
12
|
const topic = 'foo';
|
|
8
13
|
const data = uint8ArrayFromString('bar');
|
|
9
14
|
export default (common) => {
|
|
@@ -11,7 +16,11 @@ export default (common) => {
|
|
|
11
16
|
let pubsub;
|
|
12
17
|
// Create pubsub router
|
|
13
18
|
beforeEach(async () => {
|
|
14
|
-
pubsub = await common.setup(
|
|
19
|
+
pubsub = await common.setup({
|
|
20
|
+
peerId: await createEd25519PeerId(),
|
|
21
|
+
registrar: mockRegistrar(),
|
|
22
|
+
emitSelf: true
|
|
23
|
+
});
|
|
15
24
|
await pubsub.start();
|
|
16
25
|
});
|
|
17
26
|
afterEach(async () => {
|
|
@@ -21,72 +30,66 @@ export default (common) => {
|
|
|
21
30
|
});
|
|
22
31
|
it('should emit normalized signed messages on publish', async () => {
|
|
23
32
|
pubsub.globalSignaturePolicy = 'StrictSign';
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
await
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const [messageToEmit] =
|
|
33
|
+
const spy = sinon.spy(pubsub, 'publishMessage');
|
|
34
|
+
await pubsub.dispatchEvent(new CustomEvent(topic, { detail: data }));
|
|
35
|
+
await pWaitFor(async () => {
|
|
36
|
+
return spy.callCount === 1;
|
|
37
|
+
});
|
|
38
|
+
expect(spy).to.have.property('callCount', 1);
|
|
39
|
+
const [from, messageToEmit] = spy.getCall(0).args;
|
|
40
|
+
expect(from.toString()).to.equal(pubsub.peerId.toString());
|
|
31
41
|
expect(messageToEmit.seqno).to.not.eql(undefined);
|
|
32
42
|
expect(messageToEmit.key).to.not.eql(undefined);
|
|
33
43
|
expect(messageToEmit.signature).to.not.eql(undefined);
|
|
34
44
|
});
|
|
35
45
|
it('should drop unsigned messages', async () => {
|
|
36
|
-
|
|
37
|
-
sinon.spy(pubsub, '_emitMessage');
|
|
38
|
-
// @ts-expect-error protected field
|
|
39
|
-
sinon.spy(pubsub, '_publish');
|
|
46
|
+
const publishSpy = sinon.spy(pubsub, 'publishMessage');
|
|
40
47
|
sinon.spy(pubsub, 'validate');
|
|
41
48
|
const peerStream = new PeerStreams({
|
|
42
|
-
id: await
|
|
49
|
+
id: await createEd25519PeerId(),
|
|
43
50
|
protocol: 'test'
|
|
44
51
|
});
|
|
45
52
|
const rpc = {
|
|
46
53
|
subscriptions: [],
|
|
47
|
-
|
|
48
|
-
receivedFrom: peerStream.id.toString(),
|
|
54
|
+
messages: [{
|
|
49
55
|
from: peerStream.id.toBytes(),
|
|
50
56
|
data,
|
|
51
|
-
seqno:
|
|
52
|
-
|
|
57
|
+
seqno: await noSignMsgId(data),
|
|
58
|
+
topic: topic
|
|
53
59
|
}]
|
|
54
60
|
};
|
|
55
61
|
pubsub.subscribe(topic);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
expect(pubsub._emitMessage).to.have.property('called', false);
|
|
61
|
-
// @ts-expect-error protected field
|
|
62
|
-
expect(pubsub._publish).to.have.property('called', false);
|
|
62
|
+
await pubsub.processRpc(peerStream.id, peerStream, rpc);
|
|
63
|
+
// message should not be delivered
|
|
64
|
+
await delay(1000);
|
|
65
|
+
expect(publishSpy).to.have.property('called', false);
|
|
63
66
|
});
|
|
64
67
|
it('should not drop unsigned messages if strict signing is disabled', async () => {
|
|
65
68
|
pubsub.globalSignaturePolicy = 'StrictNoSign';
|
|
66
|
-
|
|
67
|
-
sinon.spy(pubsub, '_emitMessage');
|
|
68
|
-
// @ts-expect-error protected field
|
|
69
|
-
sinon.spy(pubsub, '_publish');
|
|
69
|
+
const publishSpy = sinon.spy(pubsub, 'publishMessage');
|
|
70
70
|
sinon.spy(pubsub, 'validate');
|
|
71
71
|
const peerStream = new PeerStreams({
|
|
72
|
-
id: await
|
|
72
|
+
id: await createEd25519PeerId(),
|
|
73
73
|
protocol: 'test'
|
|
74
74
|
});
|
|
75
75
|
const rpc = {
|
|
76
76
|
subscriptions: [],
|
|
77
|
-
|
|
77
|
+
messages: [{
|
|
78
|
+
from: peerStream.id.toBytes(),
|
|
78
79
|
data,
|
|
79
|
-
|
|
80
|
+
topic
|
|
80
81
|
}]
|
|
81
82
|
};
|
|
82
83
|
pubsub.subscribe(topic);
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
const deferred = pDefer();
|
|
85
|
+
pubsub.addEventListener(topic, () => {
|
|
86
|
+
deferred.resolve();
|
|
87
|
+
});
|
|
88
|
+
await pubsub.processRpc(peerStream.id, peerStream, rpc);
|
|
89
|
+
// await message delivery
|
|
90
|
+
await deferred.promise;
|
|
85
91
|
expect(pubsub.validate).to.have.property('callCount', 1);
|
|
86
|
-
|
|
87
|
-
expect(pubsub._emitMessage).to.have.property('called', 1);
|
|
88
|
-
// @ts-expect-error protected field
|
|
89
|
-
expect(pubsub._publish).to.have.property('called', 1);
|
|
92
|
+
expect(publishSpy).to.have.property('callCount', 1);
|
|
90
93
|
});
|
|
91
94
|
});
|
|
92
95
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../src/pubsub/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../src/pubsub/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,O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AAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;YACxD,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;QACrD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TestSetup } from '../index.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PubSubOptions } from '@libp2p/interfaces/pubsub';
|
|
3
3
|
import type { EventMap } from './index.js';
|
|
4
|
-
|
|
4
|
+
import type { PubsubBaseProtocol } from '@libp2p/pubsub';
|
|
5
|
+
declare const _default: (common: TestSetup<PubsubBaseProtocol<EventMap>, PubSubOptions>) => void;
|
|
5
6
|
export default _default;
|
|
6
7
|
//# 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":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAW,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAG1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;iCAEhC,UAAU,mBAAmB,QAAQ,CAAC,EAAE,aAAa,CAAC;AAA9E,wBAsdC"}
|
|
@@ -6,7 +6,9 @@ import pDefer from 'p-defer';
|
|
|
6
6
|
import pWaitFor from 'p-wait-for';
|
|
7
7
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
8
8
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
9
|
-
import {
|
|
9
|
+
import { createEd25519PeerId } from '@libp2p/peer-id-factory';
|
|
10
|
+
import { connectPeers, mockRegistrar } from '../mocks/registrar.js';
|
|
11
|
+
import { CustomEvent } from '@libp2p/interfaces';
|
|
10
12
|
export default (common) => {
|
|
11
13
|
describe('pubsub with multiple nodes', function () {
|
|
12
14
|
describe('every peer subscribes to the topic', () => {
|
|
@@ -17,46 +19,80 @@ export default (common) => {
|
|
|
17
19
|
let psA;
|
|
18
20
|
let psB;
|
|
19
21
|
let psC;
|
|
22
|
+
let peerIdA;
|
|
23
|
+
let peerIdB;
|
|
24
|
+
let peerIdC;
|
|
25
|
+
let registrarA;
|
|
26
|
+
let registrarB;
|
|
27
|
+
let registrarC;
|
|
20
28
|
// Create and start pubsub nodes
|
|
21
29
|
beforeEach(async () => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
peerIdA = await createEd25519PeerId();
|
|
31
|
+
peerIdB = await createEd25519PeerId();
|
|
32
|
+
peerIdC = await createEd25519PeerId();
|
|
33
|
+
registrarA = mockRegistrar();
|
|
34
|
+
registrarB = mockRegistrar();
|
|
35
|
+
registrarC = mockRegistrar();
|
|
36
|
+
psA = await common.setup({
|
|
37
|
+
peerId: peerIdA,
|
|
38
|
+
registrar: registrarA,
|
|
39
|
+
emitSelf: true
|
|
40
|
+
});
|
|
41
|
+
psB = await common.setup({
|
|
42
|
+
peerId: peerIdB,
|
|
43
|
+
registrar: registrarB,
|
|
44
|
+
emitSelf: true
|
|
45
|
+
});
|
|
46
|
+
psC = await common.setup({
|
|
47
|
+
peerId: peerIdC,
|
|
48
|
+
registrar: registrarC,
|
|
49
|
+
emitSelf: true
|
|
50
|
+
});
|
|
51
|
+
// Start pubsub modes
|
|
52
|
+
await Promise.all([psA, psB, psC].map(async (p) => await p.start()));
|
|
26
53
|
});
|
|
27
54
|
// Connect nodes
|
|
28
55
|
beforeEach(async () => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
56
|
+
await connectPeers(psA.multicodecs[0], {
|
|
57
|
+
peerId: peerIdA,
|
|
58
|
+
registrar: registrarA
|
|
59
|
+
}, {
|
|
60
|
+
peerId: peerIdB,
|
|
61
|
+
registrar: registrarB
|
|
62
|
+
});
|
|
63
|
+
await connectPeers(psA.multicodecs[0], {
|
|
64
|
+
peerId: peerIdB,
|
|
65
|
+
registrar: registrarB
|
|
66
|
+
}, {
|
|
67
|
+
peerId: peerIdC,
|
|
68
|
+
registrar: registrarC
|
|
69
|
+
});
|
|
33
70
|
// Wait for peers to be ready in pubsub
|
|
34
|
-
await pWaitFor(() => psA.
|
|
35
|
-
psC.
|
|
36
|
-
psA.
|
|
71
|
+
await pWaitFor(() => psA.getPeers().length === 1 &&
|
|
72
|
+
psC.getPeers().length === 1 &&
|
|
73
|
+
psA.getPeers().length === 1);
|
|
37
74
|
});
|
|
38
75
|
afterEach(async () => {
|
|
39
76
|
sinon.restore();
|
|
40
|
-
[psA, psB, psC].map((p) => p.stop());
|
|
77
|
+
await Promise.all([psA, psB, psC].map(async (p) => await p.stop()));
|
|
41
78
|
await common.teardown();
|
|
42
79
|
});
|
|
43
80
|
it('subscribe to the topic on node a', async () => {
|
|
44
81
|
const topic = 'Z';
|
|
45
82
|
psA.subscribe(topic);
|
|
46
|
-
|
|
83
|
+
expect(psA.getTopics()).to.deep.equal([topic]);
|
|
47
84
|
await new Promise((resolve) => psB.addEventListener('pubsub:subscription-change', resolve, {
|
|
48
85
|
once: true
|
|
49
86
|
}));
|
|
50
|
-
expect(psB.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
expect(psC.
|
|
54
|
-
expect(psC.topics.get(topic)).to.eql(undefined);
|
|
87
|
+
expect(psB.getPeers().length).to.equal(2);
|
|
88
|
+
expect(psB.getSubscribers(topic).map(p => p.toString())).to.deep.equal([peerIdA.toString()]);
|
|
89
|
+
expect(psC.getPeers().length).to.equal(1);
|
|
90
|
+
expect(psC.getSubscribers(topic)).to.be.empty();
|
|
55
91
|
});
|
|
56
92
|
it('subscribe to the topic on node b', async () => {
|
|
57
93
|
const topic = 'Z';
|
|
58
94
|
psB.subscribe(topic);
|
|
59
|
-
|
|
95
|
+
expect(psB.getTopics()).to.deep.equal([topic]);
|
|
60
96
|
await Promise.all([
|
|
61
97
|
new Promise((resolve) => psA.addEventListener('pubsub:subscription-change', resolve, {
|
|
62
98
|
once: true
|
|
@@ -65,20 +101,20 @@ export default (common) => {
|
|
|
65
101
|
once: true
|
|
66
102
|
}))
|
|
67
103
|
]);
|
|
68
|
-
expect(psA.
|
|
69
|
-
|
|
70
|
-
expect(psC.
|
|
71
|
-
|
|
104
|
+
expect(psA.getPeers().length).to.equal(1);
|
|
105
|
+
expect(psA.getSubscribers(topic).map(p => p.toString())).to.deep.equal([peerIdB.toString()]);
|
|
106
|
+
expect(psC.getPeers().length).to.equal(1);
|
|
107
|
+
expect(psC.getSubscribers(topic).map(p => p.toString())).to.deep.equal([peerIdB.toString()]);
|
|
72
108
|
});
|
|
73
109
|
it('subscribe to the topic on node c', async () => {
|
|
74
110
|
const topic = 'Z';
|
|
75
111
|
const defer = pDefer();
|
|
76
112
|
psC.subscribe(topic);
|
|
77
|
-
|
|
113
|
+
expect(psC.getTopics()).to.deep.equal([topic]);
|
|
78
114
|
psB.addEventListener('pubsub:subscription-change', () => {
|
|
79
|
-
expect(psA.
|
|
80
|
-
expect(psB.
|
|
81
|
-
|
|
115
|
+
expect(psA.getPeers().length).to.equal(1);
|
|
116
|
+
expect(psB.getPeers().length).to.equal(2);
|
|
117
|
+
expect(psB.getSubscribers(topic).map(p => p.toString())).to.deep.equal([peerIdC.toString()]);
|
|
82
118
|
defer.resolve();
|
|
83
119
|
}, {
|
|
84
120
|
once: true
|
|
@@ -88,28 +124,29 @@ export default (common) => {
|
|
|
88
124
|
it('publish on node a', async () => {
|
|
89
125
|
const topic = 'Z';
|
|
90
126
|
const defer = pDefer();
|
|
91
|
-
psA.subscribe(topic);
|
|
92
|
-
psB.subscribe(topic);
|
|
93
|
-
psC.subscribe(topic);
|
|
94
127
|
// await subscription change
|
|
95
|
-
|
|
96
|
-
new Promise(resolve => psA.addEventListener('pubsub:subscription-change', () => resolve(
|
|
128
|
+
const p = Promise.all([
|
|
129
|
+
new Promise(resolve => psA.addEventListener('pubsub:subscription-change', () => resolve(), {
|
|
97
130
|
once: true
|
|
98
131
|
})),
|
|
99
|
-
new Promise(resolve => psB.addEventListener('pubsub:subscription-change', () => resolve(
|
|
132
|
+
new Promise(resolve => psB.addEventListener('pubsub:subscription-change', () => resolve(), {
|
|
100
133
|
once: true
|
|
101
134
|
})),
|
|
102
|
-
new Promise(resolve => psC.addEventListener('pubsub:subscription-change', () => resolve(
|
|
135
|
+
new Promise(resolve => psC.addEventListener('pubsub:subscription-change', () => resolve(), {
|
|
103
136
|
once: true
|
|
104
137
|
}))
|
|
105
138
|
]);
|
|
106
|
-
|
|
107
|
-
|
|
139
|
+
psA.subscribe(topic);
|
|
140
|
+
psB.subscribe(topic);
|
|
141
|
+
psC.subscribe(topic);
|
|
142
|
+
await p;
|
|
108
143
|
let counter = 0;
|
|
109
144
|
psA.addEventListener(topic, incMsg);
|
|
110
145
|
psB.addEventListener(topic, incMsg);
|
|
111
146
|
psC.addEventListener(topic, incMsg);
|
|
112
|
-
|
|
147
|
+
// await a cycle
|
|
148
|
+
await delay(1000);
|
|
149
|
+
void psA.dispatchEvent(new CustomEvent(topic, { detail: uint8ArrayFromString('hey') }));
|
|
113
150
|
function incMsg(evt) {
|
|
114
151
|
const msg = evt.detail;
|
|
115
152
|
expect(uint8ArrayToString(msg.data)).to.equal('hey');
|
|
@@ -157,7 +194,7 @@ export default (common) => {
|
|
|
157
194
|
psC.addEventListener(topic, incMsg);
|
|
158
195
|
// await a cycle
|
|
159
196
|
await delay(1000);
|
|
160
|
-
void psB.
|
|
197
|
+
void psB.dispatchEvent(new CustomEvent(topic, { detail: uint8ArrayFromString('hey') }));
|
|
161
198
|
function incMsg(evt) {
|
|
162
199
|
const msg = evt.detail;
|
|
163
200
|
expect(uint8ArrayToString(msg.data)).to.equal('hey');
|
|
@@ -188,47 +225,108 @@ export default (common) => {
|
|
|
188
225
|
let psC;
|
|
189
226
|
let psD;
|
|
190
227
|
let psE;
|
|
228
|
+
let peerIdA;
|
|
229
|
+
let peerIdB;
|
|
230
|
+
let peerIdC;
|
|
231
|
+
let peerIdD;
|
|
232
|
+
let peerIdE;
|
|
233
|
+
let registrarA;
|
|
234
|
+
let registrarB;
|
|
235
|
+
let registrarC;
|
|
236
|
+
let registrarD;
|
|
237
|
+
let registrarE;
|
|
191
238
|
// Create and start pubsub nodes
|
|
192
239
|
beforeEach(async () => {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
240
|
+
peerIdA = await createEd25519PeerId();
|
|
241
|
+
peerIdB = await createEd25519PeerId();
|
|
242
|
+
peerIdC = await createEd25519PeerId();
|
|
243
|
+
peerIdD = await createEd25519PeerId();
|
|
244
|
+
peerIdE = await createEd25519PeerId();
|
|
245
|
+
registrarA = mockRegistrar();
|
|
246
|
+
registrarB = mockRegistrar();
|
|
247
|
+
registrarC = mockRegistrar();
|
|
248
|
+
registrarD = mockRegistrar();
|
|
249
|
+
registrarE = mockRegistrar();
|
|
250
|
+
psA = await common.setup({
|
|
251
|
+
peerId: peerIdA,
|
|
252
|
+
registrar: registrarA,
|
|
253
|
+
emitSelf: true
|
|
254
|
+
});
|
|
255
|
+
psB = await common.setup({
|
|
256
|
+
peerId: peerIdB,
|
|
257
|
+
registrar: registrarB,
|
|
258
|
+
emitSelf: true
|
|
259
|
+
});
|
|
260
|
+
psC = await common.setup({
|
|
261
|
+
peerId: peerIdC,
|
|
262
|
+
registrar: registrarC,
|
|
263
|
+
emitSelf: true
|
|
264
|
+
});
|
|
265
|
+
psD = await common.setup({
|
|
266
|
+
peerId: peerIdD,
|
|
267
|
+
registrar: registrarD,
|
|
268
|
+
emitSelf: true
|
|
269
|
+
});
|
|
270
|
+
psE = await common.setup({
|
|
271
|
+
peerId: peerIdE,
|
|
272
|
+
registrar: registrarE,
|
|
273
|
+
emitSelf: true
|
|
274
|
+
});
|
|
275
|
+
// Start pubsub nodes
|
|
276
|
+
await Promise.all([psA, psB, psC, psD, psE].map(async (p) => await p.start()));
|
|
199
277
|
});
|
|
200
278
|
// connect nodes
|
|
201
279
|
beforeEach(async () => {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
await
|
|
280
|
+
await connectPeers(psA.multicodecs[0], {
|
|
281
|
+
peerId: peerIdA,
|
|
282
|
+
registrar: registrarA
|
|
283
|
+
}, {
|
|
284
|
+
peerId: peerIdB,
|
|
285
|
+
registrar: registrarB
|
|
286
|
+
});
|
|
287
|
+
await connectPeers(psA.multicodecs[0], {
|
|
288
|
+
peerId: peerIdB,
|
|
289
|
+
registrar: registrarB
|
|
290
|
+
}, {
|
|
291
|
+
peerId: peerIdC,
|
|
292
|
+
registrar: registrarC
|
|
293
|
+
});
|
|
294
|
+
await connectPeers(psA.multicodecs[0], {
|
|
295
|
+
peerId: peerIdC,
|
|
296
|
+
registrar: registrarC
|
|
297
|
+
}, {
|
|
298
|
+
peerId: peerIdD,
|
|
299
|
+
registrar: registrarD
|
|
300
|
+
});
|
|
301
|
+
await connectPeers(psA.multicodecs[0], {
|
|
302
|
+
peerId: peerIdD,
|
|
303
|
+
registrar: registrarD
|
|
304
|
+
}, {
|
|
305
|
+
peerId: peerIdE,
|
|
306
|
+
registrar: registrarE
|
|
307
|
+
});
|
|
210
308
|
// Wait for peers to be ready in pubsub
|
|
211
|
-
await pWaitFor(() => psA.
|
|
212
|
-
psB.
|
|
213
|
-
psC.
|
|
214
|
-
psD.
|
|
215
|
-
psE.
|
|
309
|
+
await pWaitFor(() => psA.getPeers().length === 1 &&
|
|
310
|
+
psB.getPeers().length === 2 &&
|
|
311
|
+
psC.getPeers().length === 2 &&
|
|
312
|
+
psD.getPeers().length === 2 &&
|
|
313
|
+
psE.getPeers().length === 1);
|
|
216
314
|
});
|
|
217
315
|
afterEach(async () => {
|
|
218
|
-
[psA, psB, psC, psD, psE].map((p) => p.stop());
|
|
316
|
+
await Promise.all([psA, psB, psC, psD, psE].map(async (p) => await p.stop()));
|
|
219
317
|
await common.teardown();
|
|
220
318
|
});
|
|
221
319
|
it('subscribes', () => {
|
|
222
320
|
psA.subscribe('Z');
|
|
223
|
-
|
|
321
|
+
expect(psA.getTopics()).to.deep.equal(['Z']);
|
|
224
322
|
psB.subscribe('Z');
|
|
225
|
-
|
|
323
|
+
expect(psB.getTopics()).to.deep.equal(['Z']);
|
|
226
324
|
psC.subscribe('Z');
|
|
227
|
-
|
|
325
|
+
expect(psC.getTopics()).to.deep.equal(['Z']);
|
|
228
326
|
psD.subscribe('Z');
|
|
229
|
-
|
|
327
|
+
expect(psD.getTopics()).to.deep.equal(['Z']);
|
|
230
328
|
psE.subscribe('Z');
|
|
231
|
-
|
|
329
|
+
expect(psE.getTopics()).to.deep.equal(['Z']);
|
|
232
330
|
});
|
|
233
331
|
it('publishes from c', async function () {
|
|
234
332
|
const defer = pDefer();
|
|
@@ -252,7 +350,7 @@ export default (common) => {
|
|
|
252
350
|
]);
|
|
253
351
|
// await a cycle
|
|
254
352
|
await delay(1000);
|
|
255
|
-
void psC.
|
|
353
|
+
void psC.dispatchEvent(new CustomEvent('Z', { detail: uint8ArrayFromString('hey from c') }));
|
|
256
354
|
function incMsg(evt) {
|
|
257
355
|
const msg = evt.detail;
|
|
258
356
|
expect(uint8ArrayToString(msg.data)).to.equal('hey from c');
|