From 21843a6f4ab943f802f2ad777f5cc8ba5f37c571 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 15 Mar 2022 19:38:28 +0700 Subject: [PATCH 01/11] Add checkReceivedSubscriptions --- test/go-gossipsub.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/go-gossipsub.ts b/test/go-gossipsub.ts index be0b6f0b..5aa20cc8 100644 --- a/test/go-gossipsub.ts +++ b/test/go-gossipsub.ts @@ -25,6 +25,7 @@ import { tearDownGossipsubs, createPeers } from './utils' +import PeerId from 'peer-id' /** * These tests were translated from: @@ -36,6 +37,28 @@ chai.use(require('dirty-chai')) EventEmitter.defaultMaxListeners = 100 +const checkReceivedSubscription = (psub: Gossipsub, peerIdStr: string, topic: string, peerIdx: number) => new Promise ((resolve, reject) => { + const event = 'pubsub:subscription-change' + let cb: (peerId: PeerId) => void + const t = setTimeout(() => reject(`Not received subscriptions of psub ${peerIdx}`), 1000) + cb = (peerId) => { + if (peerId.toB58String() === peerIdStr) { + clearTimeout(t) + psub.off(event, cb) + expect(Array.from(psub.topics.get(topic) || []).includes(peerIdStr), "topics should include the peerId").to.be.true + resolve() + } + } + psub.on(event, cb); +}); + +const checkReceivedSubscriptions = async (psub: Gossipsub, peerIdStrs: string[], topic: string) => { + const recvPeerIdStrs = peerIdStrs.filter((peerIdStr) => peerIdStr !== psub.peerId.toB58String()) + const promises = recvPeerIdStrs.map((peerIdStr, idx) => checkReceivedSubscription(psub, peerIdStr, topic, idx)) + await Promise.all(promises) + expect(Array.from(psub.topics.get(topic) || []).sort()).to.be.deep.equal(recvPeerIdStrs.sort()) +} + /** * Given a topic and data (and debug metadata -- sender index and msg index) * Return a function (takes a gossipsub (and receiver index)) @@ -80,7 +103,7 @@ const awaitEvents = (emitter: EventEmitter, event: string, number: number, timeo }) } -describe.skip('go-libp2p-pubsub gossipsub tests', function () { +describe('go-libp2p-pubsub gossipsub tests', function () { this.timeout(100000) afterEach(() => { sinon.restore() From 246ba516976c7ac0cb5eecbbe501d2237ce4d254 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 15 Mar 2022 19:42:05 +0700 Subject: [PATCH 02/11] Add checkReceivedSubscriptions to 'test gossipsub multihops' --- test/go-gossipsub.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/test/go-gossipsub.ts b/test/go-gossipsub.ts index 5aa20cc8..ac79a8d1 100644 --- a/test/go-gossipsub.ts +++ b/test/go-gossipsub.ts @@ -45,7 +45,7 @@ const checkReceivedSubscription = (psub: Gossipsub, peerIdStr: string, topic: st if (peerId.toB58String() === peerIdStr) { clearTimeout(t) psub.off(event, cb) - expect(Array.from(psub.topics.get(topic) || []).includes(peerIdStr), "topics should include the peerId").to.be.true + expect(Array.from(psub.topics.get(topic) || []).includes(peerIdStr), 'topics should include the peerId').to.be.true resolve() } } @@ -686,26 +686,40 @@ describe('go-libp2p-pubsub gossipsub tests', function () { await Promise.all(sendRecv) await tearDownGossipsubs(psubs) }) + it('test gossipsub multihops', async function () { // Create 6 gossipsub nodes // Connect nodes in a line (eg: 0 -> 1 -> 2 -> 3 ...) // Subscribe to the topic, all nodes // Publish a message from node 0 // Assert that the last node receives the message + const numPeers = 6 const psubs = await createGossipsubs({ - number: 6, + number: numPeers, options: { scoreParams: { IPColocationFactorThreshold: 20 } } }) const topic = 'foobar' - for (let i = 0; i < 5; i++) { + for (let i = 0; i < numPeers - 1; i++) { await psubs[i]._libp2p.dialProtocol(psubs[i + 1]._libp2p.peerId, psubs[i].multicodecs) } + const peerIdStrsByIdx: string[][] = [] + for (let i = 0; i < numPeers; i++) { + if (i === 0) { // first + peerIdStrsByIdx[i] = [psubs[i + 1].peerId.toB58String()] + } else if (i > 0 && i < numPeers - 1) { // middle + peerIdStrsByIdx[i] = [psubs[i + 1].peerId.toB58String(), psubs[i - 1].peerId.toB58String()] + } else if (i === numPeers - 1) { // last + peerIdStrsByIdx[i] = [psubs[i - 1].peerId.toB58String()] + } + } - psubs.forEach((ps) => ps.subscribe(topic)) + const subscriptionPromises = psubs.map((psub, i) => checkReceivedSubscriptions(psub, peerIdStrsByIdx[i], topic)) + psubs.forEach(ps => ps.subscribe(topic)) // wait for heartbeats to build mesh await Promise.all(psubs.map((ps) => awaitEvents(ps, 'gossipsub:heartbeat', 2))) + await Promise.all(subscriptionPromises) const msg = uint8ArrayFromString(`${0} its not a flooooood ${0}`) const owner = 0 From 263bbedb9ff71ea8a66083f2d7e33398c30625ee Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 15 Mar 2022 19:44:40 +0700 Subject: [PATCH 03/11] Add checkReceivedSubscriptions to 'test gossipsub tree topology' --- test/go-gossipsub.ts | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/test/go-gossipsub.ts b/test/go-gossipsub.ts index ac79a8d1..4e22f335 100644 --- a/test/go-gossipsub.ts +++ b/test/go-gossipsub.ts @@ -728,7 +728,8 @@ describe('go-libp2p-pubsub gossipsub tests', function () { await results await tearDownGossipsubs(psubs) }) - it('test gossipsub tree topology', async function () { + + it.only('test gossipsub tree topology', async function () { // Create 10 gossipsub nodes // Connect nodes in a tree, diagram below // Subscribe to the topic, all nodes @@ -751,20 +752,39 @@ describe('go-libp2p-pubsub gossipsub tests', function () { [8] -> [9] */ const multicodecs = psubs[0].multicodecs - await psubs[0]._libp2p.dialProtocol(psubs[1]._libp2p.peerId, multicodecs) - await psubs[1]._libp2p.dialProtocol(psubs[2]._libp2p.peerId, multicodecs) - await psubs[1]._libp2p.dialProtocol(psubs[4]._libp2p.peerId, multicodecs) - await psubs[2]._libp2p.dialProtocol(psubs[3]._libp2p.peerId, multicodecs) - await psubs[0]._libp2p.dialProtocol(psubs[5]._libp2p.peerId, multicodecs) - await psubs[5]._libp2p.dialProtocol(psubs[6]._libp2p.peerId, multicodecs) - await psubs[5]._libp2p.dialProtocol(psubs[8]._libp2p.peerId, multicodecs) - await psubs[6]._libp2p.dialProtocol(psubs[7]._libp2p.peerId, multicodecs) - await psubs[8]._libp2p.dialProtocol(psubs[9]._libp2p.peerId, multicodecs) + const treeTopology = [ + [1, 5], // 0 + [2, 4], // 1 + [3], // 2 + [], // 3 leaf + [], // 4 leaf + [6, 8], // 5 + [7], // 6 + [], // 7 leaf + [9], // 8 + [], // 9 leaf + ] + for (let from = 0; from < treeTopology.length; from++) { + for (let to of treeTopology[from]) { + await psubs[from]._libp2p.dialProtocol(psubs[to]._libp2p.peerId, multicodecs) + } + } + const getPeerIdStrs = (idx: number): string[] => { + const outbounds = treeTopology[idx] + const inbounds = [] + for (let i = 0; i < treeTopology.length; i++) { + if (treeTopology[i].includes(idx)) inbounds.push(i) + } + return Array.from(new Set([...inbounds, ...outbounds])).map((i) => psubs[i].peerId.toB58String()) + } + + const subscriptionPromises = psubs.map((psub, i) => checkReceivedSubscriptions(psub, getPeerIdStrs(i), topic)) psubs.forEach((ps) => ps.subscribe(topic)) // wait for heartbeats to build mesh await Promise.all(psubs.map((ps) => awaitEvents(ps, 'gossipsub:heartbeat', 2))) + await Promise.all(subscriptionPromises) expectSet(new Set(psubs[0].peers.keys()), [psubs[1].peerId.toB58String(), psubs[5].peerId.toB58String()]) expectSet(new Set(psubs[1].peers.keys()), [ From 74d26cc2c76b392b7d4081e35f0dc8e13dff4c3c Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 15 Mar 2022 19:46:58 +0700 Subject: [PATCH 04/11] test gossipsub star topology with signed peer records --- test/go-gossipsub.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/go-gossipsub.ts b/test/go-gossipsub.ts index 4e22f335..27210a77 100644 --- a/test/go-gossipsub.ts +++ b/test/go-gossipsub.ts @@ -729,7 +729,7 @@ describe('go-libp2p-pubsub gossipsub tests', function () { await tearDownGossipsubs(psubs) }) - it.only('test gossipsub tree topology', async function () { + it('test gossipsub tree topology', async function () { // Create 10 gossipsub nodes // Connect nodes in a tree, diagram below // Subscribe to the topic, all nodes @@ -806,6 +806,7 @@ describe('go-libp2p-pubsub gossipsub tests', function () { await Promise.all(sendRecv) await tearDownGossipsubs(psubs) }) + it('test gossipsub star topology with signed peer records', async function () { // Create 20 gossipsub nodes with lower degrees // Connect nodes to a center node, with the center having very low degree @@ -839,10 +840,13 @@ describe('go-libp2p-pubsub gossipsub tests', function () { // build the mesh const topic = 'foobar' + const peerIdStrs = psubs.map((psub) => psub.peerId.toB58String()) + const subscriptionPromise = checkReceivedSubscriptions(psubs[0], peerIdStrs, topic) psubs.forEach((ps) => ps.subscribe(topic)) // wait a bit for the mesh to build await Promise.all(psubs.map((ps) => awaitEvents(ps, 'gossipsub:heartbeat', 15, 25000))) + await subscriptionPromise // check that all peers have > 1 connection psubs.forEach((ps) => { From a580b59a887149ffca9359aa910d499c2234dc28 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 15 Mar 2022 19:50:10 +0700 Subject: [PATCH 05/11] Fix 'test gossipsub direct peers' --- test/go-gossipsub.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/test/go-gossipsub.ts b/test/go-gossipsub.ts index 27210a77..3fb78b56 100644 --- a/test/go-gossipsub.ts +++ b/test/go-gossipsub.ts @@ -867,7 +867,8 @@ describe('go-libp2p-pubsub gossipsub tests', function () { await Promise.all(sendRecv) await tearDownGossipsubs(psubs) }) - it('test gossipsub direct peers', async function () { + + it.only('test gossipsub direct peers', async function () { // Create 3 gossipsub nodes // 2 and 3 with direct peer connections with each other // Connect nodes: 2 <- 1 -> 3 @@ -914,9 +915,11 @@ describe('go-libp2p-pubsub gossipsub tests', function () { expect(libp2ps[1].connectionManager.get(libp2ps[2].peerId)).to.be.ok const topic = 'foobar' - psubs.forEach((ps) => ps.subscribe(topic)) - - await Promise.all(psubs.map((ps) => awaitEvents(ps, 'gossipsub:heartbeat', 1))) + const peerIdStrs = libp2ps.map((libp2p) => libp2p.peerId.toB58String()) + const subscriptionPromises = psubs.map((psub) => checkReceivedSubscriptions(psub, peerIdStrs, topic)) + psubs.forEach(ps => ps.subscribe(topic)) + await Promise.all(psubs.map(ps => awaitEvents(ps, 'gossipsub:heartbeat', 1))) + await subscriptionPromises let sendRecv = [] for (let i = 0; i < 3; i++) { @@ -930,11 +933,18 @@ describe('go-libp2p-pubsub gossipsub tests', function () { } await Promise.all(sendRecv) + const connectPromises = [1,2].map((i) => new Promise((resolve, reject) => { + const t = setTimeout(reject, 3000) + libp2ps[i].connectionManager.once('peer:connect', () => { + clearTimeout(t) + resolve() + }) + })) // disconnect the direct peers to test reconnection - libp2ps[1].connectionManager.getAll(libp2ps[2].peerId).forEach((c) => c.close()) + await libp2ps[1].hangUp(libp2ps[2].peerId); await Promise.all(psubs.map((ps) => awaitEvents(ps, 'gossipsub:heartbeat', 5))) - + await Promise.all(connectPromises) expect(libp2ps[1].connectionManager.get(libp2ps[2].peerId)).to.be.ok sendRecv = [] From dd0ad5373c13d0c6a40b0f9c02b417ab8463a9b8 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 15 Mar 2022 20:01:58 +0700 Subject: [PATCH 06/11] Fix 'test gossipsub flood publish' --- test/go-gossipsub.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/go-gossipsub.ts b/test/go-gossipsub.ts index 3fb78b56..3a3b8baf 100644 --- a/test/go-gossipsub.ts +++ b/test/go-gossipsub.ts @@ -868,7 +868,7 @@ describe('go-libp2p-pubsub gossipsub tests', function () { await tearDownGossipsubs(psubs) }) - it.only('test gossipsub direct peers', async function () { + it('test gossipsub direct peers', async function () { // Create 3 gossipsub nodes // 2 and 3 with direct peer connections with each other // Connect nodes: 2 <- 1 -> 3 @@ -960,14 +960,16 @@ describe('go-libp2p-pubsub gossipsub tests', function () { await Promise.all(sendRecv) await tearDownGossipsubs(psubs) }) + it('test gossipsub flood publish', async function () { // Create 30 gossipsub nodes // Connect in star topology // Subscribe to the topic, all nodes // Publish 20 messages, each from the center node // Assert that the other nodes receive the message + const numPeers = 30; const psubs = await createGossipsubs({ - number: 30, + number: numPeers, options: { scoreParams: { IPColocationFactorThreshold: 30 } } }) @@ -977,17 +979,21 @@ describe('go-libp2p-pubsub gossipsub tests', function () { }) ) + const owner = 0 + const psub0 = psubs[owner] + const peerIdStrs = psubs.filter((_, j) => j !== owner).map(psub => psub.peerId.toB58String()) // build the (partial, unstable) mesh const topic = 'foobar' + const subscriptionPromise = checkReceivedSubscriptions(psub0, peerIdStrs, topic) psubs.forEach((ps) => ps.subscribe(topic)) await Promise.all(psubs.map((ps) => awaitEvents(ps, 'gossipsub:heartbeat', 1))) + await subscriptionPromise // send messages from the star and assert they were received let sendRecv = [] for (let i = 0; i < 20; i++) { const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`) - const owner = 0 const results = Promise.all( psubs.filter((psub, j) => j !== owner).map(checkReceivedMessage(topic, msg, owner, i)) ) @@ -997,6 +1003,7 @@ describe('go-libp2p-pubsub gossipsub tests', function () { await Promise.all(sendRecv) await tearDownGossipsubs(psubs) }) + it('test gossipsub negative score', async function () { // Create 20 gossipsub nodes, with scoring params to quickly lower node 0's score // Connect densely From 53283946c7576838728a937939f4c93ad9fa3e1f Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Wed, 16 Mar 2022 16:22:36 +0700 Subject: [PATCH 07/11] Fix 'test gossipsub star topology with signed peer records' --- test/go-gossipsub.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/go-gossipsub.ts b/test/go-gossipsub.ts index 3a3b8baf..e744612f 100644 --- a/test/go-gossipsub.ts +++ b/test/go-gossipsub.ts @@ -814,6 +814,7 @@ describe('go-libp2p-pubsub gossipsub tests', function () { // Assert that all nodes have > 1 connection // Publish one message per node // Assert that the subscribed nodes receive every message + sinon.replace(constants, 'GossipsubPrunePeers', 5 as 16) const psubs = await createGossipsubs({ number: 20, options: { From 00c82d23dfc706577cb55dd5ca7310d449b9ea7a Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Wed, 16 Mar 2022 18:08:32 +0700 Subject: [PATCH 08/11] 'direct peers' test: wait for subscriptions event again --- test/go-gossipsub.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/go-gossipsub.ts b/test/go-gossipsub.ts index e744612f..6a8713c7 100644 --- a/test/go-gossipsub.ts +++ b/test/go-gossipsub.ts @@ -37,10 +37,10 @@ chai.use(require('dirty-chai')) EventEmitter.defaultMaxListeners = 100 -const checkReceivedSubscription = (psub: Gossipsub, peerIdStr: string, topic: string, peerIdx: number) => new Promise ((resolve, reject) => { +const checkReceivedSubscription = (psub: Gossipsub, peerIdStr: string, topic: string, peerIdx: number, timeout = 1000) => new Promise ((resolve, reject) => { const event = 'pubsub:subscription-change' let cb: (peerId: PeerId) => void - const t = setTimeout(() => reject(`Not received subscriptions of psub ${peerIdx}`), 1000) + const t = setTimeout(() => reject(`Not received subscriptions of psub ${peerIdx}`), timeout) cb = (peerId) => { if (peerId.toB58String() === peerIdStr) { clearTimeout(t) @@ -917,7 +917,7 @@ describe('go-libp2p-pubsub gossipsub tests', function () { const topic = 'foobar' const peerIdStrs = libp2ps.map((libp2p) => libp2p.peerId.toB58String()) - const subscriptionPromises = psubs.map((psub) => checkReceivedSubscriptions(psub, peerIdStrs, topic)) + let subscriptionPromises = psubs.map((psub) => checkReceivedSubscriptions(psub, peerIdStrs, topic)) psubs.forEach(ps => ps.subscribe(topic)) await Promise.all(psubs.map(ps => awaitEvents(ps, 'gossipsub:heartbeat', 1))) await subscriptionPromises @@ -942,10 +942,16 @@ describe('go-libp2p-pubsub gossipsub tests', function () { }) })) // disconnect the direct peers to test reconnection + // need more time to disconnect/connect/send subscriptions again + subscriptionPromises = [ + checkReceivedSubscription(psubs[1], peerIdStrs[2], topic, 2, 10000), + checkReceivedSubscription(psubs[2], peerIdStrs[1], topic, 1, 10000), + ] await libp2ps[1].hangUp(libp2ps[2].peerId); await Promise.all(psubs.map((ps) => awaitEvents(ps, 'gossipsub:heartbeat', 5))) await Promise.all(connectPromises) + await Promise.all(subscriptionPromises) expect(libp2ps[1].connectionManager.get(libp2ps[2].peerId)).to.be.ok sendRecv = [] From 211a09a99567208cd44606187e86c1739a5db525 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Thu, 17 Mar 2022 10:43:30 +0700 Subject: [PATCH 09/11] 'direct peer': await for 2 peer:connect events --- test/go-gossipsub.ts | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/test/go-gossipsub.ts b/test/go-gossipsub.ts index 6a8713c7..696e5fc5 100644 --- a/test/go-gossipsub.ts +++ b/test/go-gossipsub.ts @@ -57,6 +57,10 @@ const checkReceivedSubscriptions = async (psub: Gossipsub, peerIdStrs: string[], const promises = recvPeerIdStrs.map((peerIdStr, idx) => checkReceivedSubscription(psub, peerIdStr, topic, idx)) await Promise.all(promises) expect(Array.from(psub.topics.get(topic) || []).sort()).to.be.deep.equal(recvPeerIdStrs.sort()) + recvPeerIdStrs.forEach((peerIdStr) => { + const peerStream = psub.peers.get(peerIdStr) + expect(peerStream && peerStream.isWritable, "no peerstream or peerstream is not writable").to.be.true + }) } /** @@ -908,12 +912,11 @@ describe('go-libp2p-pubsub gossipsub tests', function () { ] await Promise.all(psubs.map((ps) => ps.start())) const multicodecs = psubs[0].multicodecs + // each peer connects to 2 other peers + let connectPromises = libp2ps.map((libp2p) => awaitEvents(libp2p.connectionManager, 'peer:connect', 2)) await libp2ps[0].dialProtocol(libp2ps[1].peerId, multicodecs) await libp2ps[0].dialProtocol(libp2ps[2].peerId, multicodecs) - - // verify that the direct peers connected - await delay(2000) - expect(libp2ps[1].connectionManager.get(libp2ps[2].peerId)).to.be.ok + await Promise.all(connectPromises) const topic = 'foobar' const peerIdStrs = libp2ps.map((libp2p) => libp2p.peerId.toB58String()) @@ -927,20 +930,14 @@ describe('go-libp2p-pubsub gossipsub tests', function () { const msg = uint8ArrayFromString(`${i} its not a flooooood ${i}`) const owner = i const results = Promise.all( - psubs.filter((psub, j) => j !== owner).map(checkReceivedMessage(topic, msg, owner, i)) + psubs.filter((_, j) => j !== owner).map(checkReceivedMessage(topic, msg, owner, i)) ) sendRecv.push(psubs[owner].publish(topic, msg)) sendRecv.push(results) } await Promise.all(sendRecv) - const connectPromises = [1,2].map((i) => new Promise((resolve, reject) => { - const t = setTimeout(reject, 3000) - libp2ps[i].connectionManager.once('peer:connect', () => { - clearTimeout(t) - resolve() - }) - })) + connectPromises = [1, 2].map((i) => awaitEvents(libp2ps[i].connectionManager, 'peer:connect', 1)) // disconnect the direct peers to test reconnection // need more time to disconnect/connect/send subscriptions again subscriptionPromises = [ From 8553b95ad3cc47322b5855308cdfacea16d1e8f5 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Thu, 17 Mar 2022 14:30:57 +0700 Subject: [PATCH 10/11] 'direct peers': add missing Promise.all --- test/go-gossipsub.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/go-gossipsub.ts b/test/go-gossipsub.ts index 696e5fc5..48d1d809 100644 --- a/test/go-gossipsub.ts +++ b/test/go-gossipsub.ts @@ -39,10 +39,10 @@ EventEmitter.defaultMaxListeners = 100 const checkReceivedSubscription = (psub: Gossipsub, peerIdStr: string, topic: string, peerIdx: number, timeout = 1000) => new Promise ((resolve, reject) => { const event = 'pubsub:subscription-change' - let cb: (peerId: PeerId) => void + let cb: (peerId: PeerId, subs: RPC.ISubOpts[]) => void const t = setTimeout(() => reject(`Not received subscriptions of psub ${peerIdx}`), timeout) - cb = (peerId) => { - if (peerId.toB58String() === peerIdStr) { + cb = (peerId, subs) => { + if (peerId.toB58String() === peerIdStr && subs[0].topicID === topic && subs[0].subscribe === true) { clearTimeout(t) psub.off(event, cb) expect(Array.from(psub.topics.get(topic) || []).includes(peerIdStr), 'topics should include the peerId').to.be.true @@ -923,7 +923,7 @@ describe('go-libp2p-pubsub gossipsub tests', function () { let subscriptionPromises = psubs.map((psub) => checkReceivedSubscriptions(psub, peerIdStrs, topic)) psubs.forEach(ps => ps.subscribe(topic)) await Promise.all(psubs.map(ps => awaitEvents(ps, 'gossipsub:heartbeat', 1))) - await subscriptionPromises + await Promise.all(subscriptionPromises) let sendRecv = [] for (let i = 0; i < 3; i++) { From 723e900d176006d511b00095cb55051891357ae5 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Fri, 18 Mar 2022 09:28:35 +0700 Subject: [PATCH 11/11] Expect topic peers to contain peer id --- test/go-gossipsub.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/go-gossipsub.ts b/test/go-gossipsub.ts index 48d1d809..335be350 100644 --- a/test/go-gossipsub.ts +++ b/test/go-gossipsub.ts @@ -45,8 +45,11 @@ const checkReceivedSubscription = (psub: Gossipsub, peerIdStr: string, topic: st if (peerId.toB58String() === peerIdStr && subs[0].topicID === topic && subs[0].subscribe === true) { clearTimeout(t) psub.off(event, cb) - expect(Array.from(psub.topics.get(topic) || []).includes(peerIdStr), 'topics should include the peerId').to.be.true - resolve() + if (Array.from(psub.topics.get(topic) || []).includes(peerIdStr)) { + resolve() + } else { + reject(Error('topics should include the peerId')) + } } } psub.on(event, cb);