Skip to content

Commit

Permalink
fix(tests): sharding (#1893)
Browse files Browse the repository at this point in the history
  • Loading branch information
danisharora099 authored Mar 10, 2024
1 parent 36dfcc9 commit 49c3968
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions packages/tests/tests/getPeers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,43 +72,55 @@ describe("getConnectedPeersForProtocolAndShard", function () {
expect(peers.length).to.be.greaterThan(0);
});

// Had to use cluster 0 because of https://github.com/waku-org/js-waku/issues/1848
it("same cluster, different shard: nodes connect", async function () {
it("same cluster, different shard: nodes don't connect", async function () {
this.timeout(15000);

const shardInfo: ShardInfo = {
clusterId: 0,
const shardInfo1: ShardInfo = {
clusterId: 2,
shards: [1]
};

const shardInfoServiceNode: ShardInfo = {
clusterId: 0,
shards: [1]
const shardInfo2: ShardInfo = {
clusterId: 2,
shards: [2]
};

// Separate shard
await serviceNode1.start({
discv5Discovery: true,
peerExchange: true,
clusterId: shardInfoServiceNode.clusterId,
pubsubTopic: shardInfoToPubsubTopics(shardInfoServiceNode),
clusterId: shardInfo1.clusterId,
pubsubTopic: shardInfoToPubsubTopics(shardInfo1),
lightpush: true,
relay: true
});

const serviceNodeMa = await serviceNode1.getMultiaddrWithId();
// Same shard
await serviceNode2.start({
discv5Discovery: true,
peerExchange: true,
clusterId: shardInfo2.clusterId,
pubsubTopic: shardInfoToPubsubTopics(shardInfo2),
lightpush: true,
relay: true
});

waku = await createLightNode({ shardInfo });
await waku.libp2p.dialProtocol(serviceNodeMa, LightPushCodec);
const serviceNode1Ma = await serviceNode1.getMultiaddrWithId();
const serviceNode2Ma = await serviceNode2.getMultiaddrWithId();

waku = await createLightNode({ shardInfo: shardInfo2 });
await waku.libp2p.dialProtocol(serviceNode1Ma, LightPushCodec);
await waku.libp2p.dialProtocol(serviceNode2Ma, LightPushCodec);
await waku.start();
await waitForRemotePeer(waku, [Protocols.LightPush]);

const peers = await getConnectedPeersForProtocolAndShard(
waku.libp2p.getConnections(),
waku.libp2p.peerStore,
waku.libp2p.getProtocols(),
shardInfo
ensureShardingConfigured(shardInfo2).shardInfo
);
expect(peers.length).to.be.greaterThan(0);
expect(peers.length).to.be.equal(1);
});

it("different cluster, same shard: nodes don't connect", async function () {
Expand Down

0 comments on commit 49c3968

Please sign in to comment.