@@ -2,53 +2,156 @@ import { MetadataCodec } from "@waku/core";
2
2
import type { LightNode , ShardInfo } from "@waku/interfaces" ;
3
3
import { createLightNode } from "@waku/sdk" ;
4
4
import { shardInfoToPubsubTopics } from "@waku/utils" ;
5
- import { expect } from "chai" ;
5
+ import chai , { expect } from "chai" ;
6
+ import chaiAsPromised from "chai-as-promised" ;
6
7
7
8
import { tearDownNodes } from "../src/index.js" ;
8
9
import { makeLogFileName } from "../src/log_file.js" ;
9
10
import { NimGoNode } from "../src/node/node.js" ;
10
11
11
- describe . only ( "Metadata Protocol" , ( ) => {
12
- describe ( "Locally Run Nodes" , ( ) => {
13
- let waku : LightNode ;
14
- let nwaku1 : NimGoNode ;
12
+ chai . use ( chaiAsPromised ) ;
13
+
14
+ describe ( "Metadata Protocol" , ( ) => {
15
+ let waku : LightNode ;
16
+ let nwaku1 : NimGoNode ;
17
+
18
+ beforeEach ( function ( ) {
19
+ nwaku1 = new NimGoNode ( makeLogFileName ( this ) + "1" ) ;
20
+ } ) ;
21
+
22
+ afterEach ( async function ( ) {
23
+ this . timeout ( 15000 ) ;
24
+ await tearDownNodes ( [ nwaku1 ] , waku ) ;
25
+ } ) ;
26
+
27
+ it ( "same cluster, same shard: nodes connect" , async function ( ) {
28
+ this . timeout ( 55_000 ) ;
29
+
15
30
const shardInfo : ShardInfo = {
16
31
clusterId : 1 ,
17
32
shards : [ 1 ]
18
33
} ;
19
34
20
- beforeEach ( function ( ) {
21
- nwaku1 = new NimGoNode ( makeLogFileName ( this ) + "1" ) ;
35
+ await nwaku1 . start ( {
36
+ relay : true ,
37
+ discv5Discovery : true ,
38
+ peerExchange : true ,
39
+ clusterId : shardInfo . clusterId ,
40
+ pubsubTopic : shardInfoToPubsubTopics ( shardInfo )
22
41
} ) ;
23
42
24
- afterEach ( async function ( ) {
25
- this . timeout ( 15000 ) ;
26
- await tearDownNodes ( [ nwaku1 ] , waku ) ;
43
+ const nwaku1Ma = await nwaku1 . getMultiaddrWithId ( ) ;
44
+ const nwaku1PeerId = await nwaku1 . getPeerId ( ) ;
45
+
46
+ waku = await createLightNode ( { shardInfo } ) ;
47
+ await waku . start ( ) ;
48
+ await waku . libp2p . dialProtocol ( nwaku1Ma , MetadataCodec ) ;
49
+
50
+ const shardInfoRes =
51
+ await waku . libp2p . services . metadata ?. query ( nwaku1PeerId ) ;
52
+ expect ( shardInfoRes ) . to . not . be . undefined ;
53
+ expect ( shardInfoRes ?. clusterId ) . to . equal ( shardInfo . clusterId ) ;
54
+ expect ( shardInfoRes ?. shards ) . to . deep . equal ( shardInfo . shards ) ;
55
+ } ) ;
56
+
57
+ it ( "same cluster, different shard: nodes connect" , async function ( ) {
58
+ this . timeout ( 55_000 ) ;
59
+
60
+ const shardInfo1 : ShardInfo = {
61
+ clusterId : 1 ,
62
+ shards : [ 1 ]
63
+ } ;
64
+
65
+ const shardInfo2 : ShardInfo = {
66
+ clusterId : 1 ,
67
+ shards : [ 2 ]
68
+ } ;
69
+
70
+ await nwaku1 . start ( {
71
+ relay : true ,
72
+ discv5Discovery : true ,
73
+ peerExchange : true ,
74
+ clusterId : shardInfo1 . clusterId ,
75
+ pubsubTopic : shardInfoToPubsubTopics ( shardInfo1 )
27
76
} ) ;
28
77
29
- it ( "interop" , async function ( ) {
30
- this . timeout ( 55_000 ) ;
31
-
32
- await nwaku1 . start ( {
33
- relay : true ,
34
- discv5Discovery : true ,
35
- peerExchange : true ,
36
- clusterId : shardInfo . clusterId ,
37
- pubsubTopic : shardInfoToPubsubTopics ( shardInfo )
38
- } ) ;
39
-
40
- const nwaku1Ma = await nwaku1 . getMultiaddrWithId ( ) ;
41
- const nwaku1PeerId = await nwaku1 . getPeerId ( ) ;
42
-
43
- waku = await createLightNode ( { shardInfo } ) ;
44
- await waku . start ( ) ;
45
- await waku . libp2p . dialProtocol ( nwaku1Ma , MetadataCodec ) ;
46
-
47
- const shardInfoRes =
48
- await waku . libp2p . services . metadata ?. query ( nwaku1PeerId ) ;
49
- expect ( shardInfoRes ) . to . not . be . undefined ;
50
- expect ( shardInfoRes ?. clusterId ) . to . equal ( shardInfo . clusterId ) ;
51
- expect ( shardInfoRes ?. shards ) . to . deep . equal ( shardInfo . shards ) ;
78
+ const nwaku1Ma = await nwaku1 . getMultiaddrWithId ( ) ;
79
+ const nwaku1PeerId = await nwaku1 . getPeerId ( ) ;
80
+
81
+ waku = await createLightNode ( { shardInfo : shardInfo2 } ) ;
82
+ await waku . start ( ) ;
83
+ await waku . libp2p . dialProtocol ( nwaku1Ma , MetadataCodec ) ;
84
+
85
+ const shardInfoRes =
86
+ await waku . libp2p . services . metadata ?. query ( nwaku1PeerId ) ;
87
+ expect ( shardInfoRes ) . to . not . be . undefined ;
88
+ expect ( shardInfoRes ?. clusterId ) . to . equal ( shardInfo1 . clusterId ) ;
89
+ expect ( shardInfoRes ?. shards ) . to . deep . equal ( shardInfo1 . shards ) ;
90
+ } ) ;
91
+
92
+ it ( "different cluster, same shard: nodes don't connect" , async function ( ) {
93
+ this . timeout ( 55_000 ) ;
94
+
95
+ const shardInfo1 : ShardInfo = {
96
+ clusterId : 1 ,
97
+ shards : [ 1 ]
98
+ } ;
99
+
100
+ const shardInfo2 : ShardInfo = {
101
+ clusterId : 2 ,
102
+ shards : [ 1 ]
103
+ } ;
104
+
105
+ await nwaku1 . start ( {
106
+ relay : true ,
107
+ discv5Discovery : true ,
108
+ peerExchange : true ,
109
+ clusterId : shardInfo1 . clusterId ,
110
+ pubsubTopic : shardInfoToPubsubTopics ( shardInfo1 )
52
111
} ) ;
112
+
113
+ const nwaku1Ma = await nwaku1 . getMultiaddrWithId ( ) ;
114
+ const nwaku1PeerId = await nwaku1 . getPeerId ( ) ;
115
+
116
+ waku = await createLightNode ( { shardInfo : shardInfo2 } ) ;
117
+ await waku . start ( ) ;
118
+ await waku . libp2p . dialProtocol ( nwaku1Ma , MetadataCodec ) ;
119
+
120
+ await expect (
121
+ waku . libp2p . services . metadata ?. query ( nwaku1PeerId )
122
+ ) . to . be . rejectedWith ( "the connection is being closed" ) ;
123
+ } ) ;
124
+
125
+ it ( "different cluster, different shard: nodes don't connect" , async function ( ) {
126
+ this . timeout ( 55_000 ) ;
127
+
128
+ const shardInfo1 : ShardInfo = {
129
+ clusterId : 1 ,
130
+ shards : [ 1 ]
131
+ } ;
132
+
133
+ const shardInfo2 : ShardInfo = {
134
+ clusterId : 2 ,
135
+ shards : [ 2 ]
136
+ } ;
137
+
138
+ await nwaku1 . start ( {
139
+ relay : true ,
140
+ discv5Discovery : true ,
141
+ peerExchange : true ,
142
+ clusterId : shardInfo1 . clusterId ,
143
+ pubsubTopic : shardInfoToPubsubTopics ( shardInfo1 )
144
+ } ) ;
145
+
146
+ const nwaku1Ma = await nwaku1 . getMultiaddrWithId ( ) ;
147
+ const nwaku1PeerId = await nwaku1 . getPeerId ( ) ;
148
+
149
+ waku = await createLightNode ( { shardInfo : shardInfo2 } ) ;
150
+ await waku . start ( ) ;
151
+ await waku . libp2p . dialProtocol ( nwaku1Ma , MetadataCodec ) ;
152
+
153
+ await expect (
154
+ waku . libp2p . services . metadata ?. query ( nwaku1PeerId )
155
+ ) . to . be . rejectedWith ( "the connection is being closed" ) ;
53
156
} ) ;
54
157
} ) ;
0 commit comments