@libp2p/interop 7.0.1 → 7.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/interop",
3
- "version": "7.0.1",
3
+ "version": "7.0.3",
4
4
  "description": "Interoperability Tests for libp2p",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/interop#readme",
@@ -128,7 +128,7 @@
128
128
  "clean": "aegir clean",
129
129
  "lint": "aegir lint",
130
130
  "dep-check": "aegir dep-check -i protons",
131
- "build": "aegir build",
131
+ "build": "aegir build --bundle false",
132
132
  "postbuild": "cp src/resources/keys/*.key dist/src/resources/keys",
133
133
  "release": "aegir release"
134
134
  },
package/src/connect.ts CHANGED
@@ -22,52 +22,51 @@ export function connectTests (factory: DaemonFactory): void {
22
22
 
23
23
  function runConnectTests (name: string, factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
24
24
  describe(`connect using ${name}`, () => {
25
- let daemons: Daemon[]
25
+ let daemonA: Daemon
26
+ let daemonB: Daemon
26
27
 
27
28
  // Start Daemons
28
29
  before(async function () {
29
30
  this.timeout(20 * 1000)
30
31
 
31
- daemons = await Promise.all([
32
- factory.spawn(optionsA),
33
- factory.spawn(optionsB)
34
- ])
32
+ daemonA = await factory.spawn(optionsA)
33
+ daemonB = await factory.spawn(optionsB)
35
34
  })
36
35
 
37
36
  // Stop daemons
38
37
  after(async function () {
39
- if (daemons != null) {
40
- await Promise.all(
41
- daemons.map(async (daemon) => { await daemon.stop() })
42
- )
43
- }
38
+ await Promise.all(
39
+ [daemonA, daemonB]
40
+ .filter(Boolean)
41
+ .map(async d => { await d.stop() })
42
+ )
44
43
  })
45
44
 
46
45
  it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
47
46
  this.timeout(10 * 1000)
48
47
 
49
- const identify1 = await daemons[0].client.identify()
50
- const identify2 = await daemons[1].client.identify()
48
+ const identify1 = await daemonA.client.identify()
49
+ const identify2 = await daemonB.client.identify()
51
50
 
52
51
  // verify connected peers
53
- const knownPeersBeforeConnect1 = await daemons[0].client.listPeers()
52
+ const knownPeersBeforeConnect1 = await daemonA.client.listPeers()
54
53
  expect(knownPeersBeforeConnect1).to.have.lengthOf(0)
55
54
 
56
- const knownPeersBeforeConnect2 = await daemons[1].client.listPeers()
55
+ const knownPeersBeforeConnect2 = await daemonB.client.listPeers()
57
56
  expect(knownPeersBeforeConnect2).to.have.lengthOf(0)
58
57
 
59
58
  // connect peers
60
- await daemons[0].client.connect(identify2.peerId, identify2.addrs)
59
+ await daemonA.client.connect(identify2.peerId, identify2.addrs)
61
60
 
62
- // daemons[0] will take some time to get the peers
61
+ // daemonA will take some time to get the peers
63
62
  await new Promise(resolve => setTimeout(resolve, 1000))
64
63
 
65
64
  // verify connected peers
66
- const knownPeersAfterConnect1 = await daemons[0].client.listPeers()
65
+ const knownPeersAfterConnect1 = await daemonA.client.listPeers()
67
66
  expect(knownPeersAfterConnect1).to.have.length.greaterThanOrEqual(1)
68
67
  expect(knownPeersAfterConnect1[0].toString()).to.equal(identify2.peerId.toString())
69
68
 
70
- const knownPeersAfterConnect2 = await daemons[1].client.listPeers()
69
+ const knownPeersAfterConnect2 = await daemonB.client.listPeers()
71
70
  expect(knownPeersAfterConnect2).to.have.length.greaterThanOrEqual(1)
72
71
  expect(knownPeersAfterConnect2[0].toString()).to.equal(identify1.peerId.toString())
73
72
  })
@@ -29,21 +29,20 @@ export function contentFetchingTests (factory: DaemonFactory): void {
29
29
 
30
30
  function runContentFetchingTests (factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
31
31
  describe('dht.contentFetching', () => {
32
- let daemons: Daemon[]
32
+ let daemonA: Daemon
33
+ let daemonB: Daemon
33
34
 
34
35
  // Start Daemons
35
36
  before(async function () {
36
37
  this.timeout(20 * 1000)
37
38
 
38
- daemons = await Promise.all([
39
- factory.spawn(optionsA),
40
- factory.spawn(optionsB)
41
- ])
39
+ daemonA = await factory.spawn(optionsA)
40
+ daemonB = await factory.spawn(optionsB)
42
41
 
43
42
  // connect them
44
- const identify0 = await daemons[0].client.identify()
43
+ const identify0 = await daemonA.client.identify()
45
44
 
46
- await daemons[1].client.connect(identify0.peerId, identify0.addrs)
45
+ await daemonB.client.connect(identify0.peerId, identify0.addrs)
47
46
 
48
47
  // jsDaemon1 will take some time to get the peers
49
48
  await new Promise(resolve => setTimeout(resolve, 1000))
@@ -51,19 +50,19 @@ function runContentFetchingTests (factory: DaemonFactory, optionsA: SpawnOptions
51
50
 
52
51
  // Stop daemons
53
52
  after(async function () {
54
- if (daemons != null) {
55
- await Promise.all(
56
- daemons.map(async (daemon) => { await daemon.stop() })
57
- )
58
- }
53
+ await Promise.all(
54
+ [daemonA, daemonB]
55
+ .filter(Boolean)
56
+ .map(async d => { await d.stop() })
57
+ )
59
58
  })
60
59
 
61
60
  it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
62
61
  this.timeout(10 * 1000)
63
62
 
64
- await daemons[0].client.dht.put(record.key, record.value)
63
+ await daemonA.client.dht.put(record.key, record.value)
65
64
 
66
- const data = await daemons[1].client.dht.get(record.key)
65
+ const data = await daemonB.client.dht.get(record.key)
67
66
  expect(data).to.equalBytes(record.value)
68
67
  })
69
68
  })
@@ -27,25 +27,27 @@ export function contentRoutingTests (factory: DaemonFactory): void {
27
27
 
28
28
  function runContentRoutingTests (factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
29
29
  describe('dht.contentRouting', () => {
30
- let daemons: Daemon[]
30
+ let daemonA: Daemon
31
+ let daemonB: Daemon
32
+ let daemonC: Daemon
31
33
  let identify: IdentifyResult[]
32
34
 
33
35
  // Start Daemons
34
36
  before(async function () {
35
37
  this.timeout(20 * 1000)
36
38
 
37
- daemons = await Promise.all([
38
- factory.spawn(optionsA),
39
- factory.spawn(optionsB),
40
- factory.spawn(optionsB)
41
- ])
39
+ daemonA = await factory.spawn(optionsA)
40
+ daemonB = await factory.spawn(optionsB)
41
+ daemonC = await factory.spawn(optionsB)
42
42
 
43
- identify = await Promise.all(
44
- daemons.map(async d => await d.client.identify())
45
- )
43
+ identify = await Promise.all([
44
+ daemonA.client.identify(),
45
+ daemonB.client.identify(),
46
+ daemonC.client.identify()
47
+ ])
46
48
 
47
- await daemons[0].client.connect(identify[1].peerId, identify[1].addrs)
48
- await daemons[0].client.connect(identify[2].peerId, identify[2].addrs)
49
+ await daemonA.client.connect(identify[1].peerId, identify[1].addrs)
50
+ await daemonA.client.connect(identify[2].peerId, identify[2].addrs)
49
51
 
50
52
  // get the peers in the table
51
53
  await new Promise(resolve => setTimeout(resolve, 1000))
@@ -53,19 +55,19 @@ function runContentRoutingTests (factory: DaemonFactory, optionsA: SpawnOptions,
53
55
 
54
56
  // Stop daemons
55
57
  after(async function () {
56
- if (daemons != null) {
57
- await Promise.all(
58
- daemons.map(async (daemon) => { await daemon.stop() })
59
- )
60
- }
58
+ await Promise.all(
59
+ [daemonA, daemonB, daemonC]
60
+ .filter(Boolean)
61
+ .map(async d => { await d.stop() })
62
+ )
61
63
  })
62
64
 
63
65
  it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
64
66
  const cid = CID.parse('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp39')
65
67
 
66
- await daemons[0].client.dht.provide(cid)
68
+ await daemonA.client.dht.provide(cid)
67
69
 
68
- const providers = await all(daemons[1].client.dht.findProviders(cid, 1))
70
+ const providers = await all(daemonB.client.dht.findProviders(cid, 1))
69
71
 
70
72
  expect(providers).to.exist()
71
73
  expect(providers.length).to.be.greaterThan(0)
@@ -21,41 +21,41 @@ export function peerRoutingTests (factory: DaemonFactory): void {
21
21
 
22
22
  function runPeerRoutingTests (factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
23
23
  describe('dht.peerRouting', () => {
24
- let daemons: Daemon[]
24
+ let daemonA: Daemon
25
+ let daemonB: Daemon
26
+ let daemonC: Daemon
25
27
 
26
28
  // Start Daemons
27
29
  before(async function () {
28
30
  this.timeout(20 * 1000)
29
31
 
30
- daemons = await Promise.all([
31
- factory.spawn(optionsA),
32
- factory.spawn(optionsB),
33
- factory.spawn(optionsB)
34
- ])
32
+ daemonA = await factory.spawn(optionsA)
33
+ daemonB = await factory.spawn(optionsB)
34
+ daemonC = await factory.spawn(optionsB)
35
35
  })
36
36
 
37
37
  // Stop daemons
38
38
  after(async function () {
39
- if (daemons != null) {
40
- await Promise.all(
41
- daemons.map(async (daemon) => { await daemon.stop() })
42
- )
43
- }
39
+ await Promise.all(
40
+ [daemonA, daemonB, daemonC]
41
+ .filter(Boolean)
42
+ .map(async d => { await d.stop() })
43
+ )
44
44
  })
45
45
 
46
46
  it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
47
- const identify1 = await daemons[1].client.identify()
48
- const identify2 = await daemons[2].client.identify()
47
+ const identify1 = await daemonB.client.identify()
48
+ const identify2 = await daemonC.client.identify()
49
49
 
50
50
  // peers need at least one peer in their routing table or they fail with:
51
51
  // connect 0 => 1
52
- await daemons[0].client.connect(identify1.peerId, identify1.addrs)
52
+ await daemonA.client.connect(identify1.peerId, identify1.addrs)
53
53
 
54
54
  // connect 0 => 2
55
- await daemons[0].client.connect(identify2.peerId, identify2.addrs)
55
+ await daemonA.client.connect(identify2.peerId, identify2.addrs)
56
56
 
57
57
  // peer 1 find peer 2, retry up to 10 times to allow the routing table to refresh
58
- const peerData: PeerInfo = await pRetry(async () => await daemons[1].client.dht.findPeer(identify2.peerId), { retries: 10 })
58
+ const peerData: PeerInfo = await pRetry(async () => await daemonB.client.dht.findPeer(identify2.peerId), { retries: 10 })
59
59
 
60
60
  expect(identify2.addrs.map(ma => ma.toString())).to.include.deep.members(peerData.multiaddrs.map(ma => ma.toString()))
61
61
  })
@@ -22,37 +22,34 @@ export function floodsubTests (factory: DaemonFactory): void {
22
22
 
23
23
  function runFloodsubTests (factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
24
24
  describe('pubsub.floodSub', () => {
25
- let daemons: Daemon[]
25
+ let daemonA: Daemon
26
+ let daemonB: Daemon
26
27
 
27
28
  // Start Daemons
28
29
  before(async function () {
29
30
  this.timeout(20 * 1000)
30
31
 
31
- daemons = await Promise.all([
32
- factory.spawn(optionsA),
33
- factory.spawn(optionsB)
34
- ])
32
+ daemonA = await factory.spawn(optionsA)
33
+ daemonB = await factory.spawn(optionsB)
35
34
 
36
- const [peerA, peerB] = daemons
37
- const identifyB = await peerB.client.identify()
38
- await peerA.client.connect(identifyB.peerId, identifyB.addrs)
35
+ const identifyB = await daemonB.client.identify()
36
+ await daemonA.client.connect(identifyB.peerId, identifyB.addrs)
39
37
  })
40
38
 
41
39
  // Stop daemons
42
40
  after(async function () {
43
- if (daemons != null) {
44
- await Promise.all(
45
- daemons.map(async (daemon) => { await daemon.stop() })
46
- )
47
- }
41
+ await Promise.all(
42
+ [daemonA, daemonB]
43
+ .filter(Boolean)
44
+ .map(async d => { await d.stop() })
45
+ )
48
46
  })
49
47
 
50
48
  it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
51
49
  const topic = 'test-topic'
52
50
  const data = uint8ArrayFromString('test-data')
53
- const [peerA, peerB] = daemons
54
51
 
55
- const subscription = await peerB.client.pubsub.subscribe(topic)
52
+ const subscription = await daemonB.client.pubsub.subscribe(topic)
56
53
  const subscriber = async (): Promise<void> => {
57
54
  const message = await first(subscription.messages())
58
55
 
@@ -61,8 +58,8 @@ function runFloodsubTests (factory: DaemonFactory, optionsA: SpawnOptions, optio
61
58
  }
62
59
 
63
60
  const publisher = async (): Promise<void> => {
64
- await waitForSubscribed(topic, peerA, peerB)
65
- await peerA.client.pubsub.publish(topic, data)
61
+ await waitForSubscribed(topic, daemonA, daemonB)
62
+ await daemonA.client.pubsub.publish(topic, data)
66
63
  }
67
64
 
68
65
  return await Promise.all([
@@ -22,37 +22,34 @@ export function gossipsubTests (factory: DaemonFactory): void {
22
22
 
23
23
  function runGossipsubTests (factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
24
24
  describe('pubsub.gossipsub', () => {
25
- let daemons: Daemon[]
25
+ let daemonA: Daemon
26
+ let daemonB: Daemon
26
27
 
27
28
  // Start Daemons
28
29
  before(async function () {
29
30
  this.timeout(20 * 1000)
30
31
 
31
- daemons = await Promise.all([
32
- factory.spawn(optionsA),
33
- factory.spawn(optionsB)
34
- ])
32
+ daemonA = await factory.spawn(optionsA)
33
+ daemonB = await factory.spawn(optionsB)
35
34
 
36
- const [peerA, peerB] = daemons
37
- const identifyB = await peerB.client.identify()
38
- await peerA.client.connect(identifyB.peerId, identifyB.addrs)
35
+ const identifyB = await daemonB.client.identify()
36
+ await daemonA.client.connect(identifyB.peerId, identifyB.addrs)
39
37
  })
40
38
 
41
39
  // Stop daemons
42
40
  after(async function () {
43
- if (daemons != null) {
44
- await Promise.all(
45
- daemons.map(async daemon => { await daemon.stop() })
46
- )
47
- }
41
+ await Promise.all(
42
+ [daemonA, daemonB]
43
+ .filter(Boolean)
44
+ .map(async d => { await d.stop() })
45
+ )
48
46
  })
49
47
 
50
48
  it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
51
49
  const topic = 'test-topic'
52
50
  const data = uint8ArrayFromString('test-data')
53
- const [peerA, peerB] = daemons
54
51
 
55
- const subscription = await peerB.client.pubsub.subscribe(topic)
52
+ const subscription = await daemonB.client.pubsub.subscribe(topic)
56
53
  const subscriber = async (): Promise<void> => {
57
54
  const message = await first(subscription.messages())
58
55
 
@@ -61,8 +58,8 @@ function runGossipsubTests (factory: DaemonFactory, optionsA: SpawnOptions, opti
61
58
  }
62
59
 
63
60
  const publisher = async (): Promise<void> => {
64
- await waitForSubscribed(topic, peerA, peerB)
65
- await peerA.client.pubsub.publish(topic, data)
61
+ await waitForSubscribed(topic, daemonA, daemonB)
62
+ await daemonA.client.pubsub.publish(topic, data)
66
63
  }
67
64
 
68
65
  return await Promise.all([
@@ -22,37 +22,34 @@ export function hybridTests (factory: DaemonFactory): void {
22
22
 
23
23
  function runHybridTests (factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
24
24
  describe('pubsub.hybrid', () => {
25
- let daemons: Daemon[]
25
+ let daemonA: Daemon
26
+ let daemonB: Daemon
26
27
 
27
28
  // Start Daemons
28
29
  before(async function () {
29
30
  this.timeout(20 * 1000)
30
31
 
31
- daemons = await Promise.all([
32
- factory.spawn(optionsA),
33
- factory.spawn(optionsB)
34
- ])
32
+ daemonA = await factory.spawn(optionsA)
33
+ daemonB = await factory.spawn(optionsB)
35
34
 
36
- const [peerA, peerB] = daemons
37
- const identifyB = await peerB.client.identify()
38
- await peerA.client.connect(identifyB.peerId, identifyB.addrs)
35
+ const identifyB = await daemonB.client.identify()
36
+ await daemonA.client.connect(identifyB.peerId, identifyB.addrs)
39
37
  })
40
38
 
41
39
  // Stop daemons
42
40
  after(async function () {
43
- if (daemons != null) {
44
- await Promise.all(
45
- daemons.map(async (daemon) => { await daemon.stop() })
46
- )
47
- }
41
+ await Promise.all(
42
+ [daemonA, daemonB]
43
+ .filter(Boolean)
44
+ .map(async d => { await d.stop() })
45
+ )
48
46
  })
49
47
 
50
48
  it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
51
49
  const topic = 'test-topic'
52
50
  const data = uint8ArrayFromString('test-data')
53
- const [peerA, peerB] = daemons
54
51
 
55
- const subscription = await peerB.client.pubsub.subscribe(topic)
52
+ const subscription = await daemonB.client.pubsub.subscribe(topic)
56
53
  const subscriber = async (): Promise<void> => {
57
54
  const message = await first(subscription.messages())
58
55
 
@@ -61,8 +58,8 @@ function runHybridTests (factory: DaemonFactory, optionsA: SpawnOptions, options
61
58
  }
62
59
 
63
60
  const publisher = async (): Promise<void> => {
64
- await waitForSubscribed(topic, peerA, peerB)
65
- await peerA.client.pubsub.publish(topic, data)
61
+ await waitForSubscribed(topic, daemonA, daemonB)
62
+ await daemonA.client.pubsub.publish(topic, data)
66
63
  }
67
64
 
68
65
  return await Promise.all([
@@ -17,6 +17,7 @@ export async function waitForSubscribed (topic: string, a: Daemon, b: Daemon): P
17
17
  interval: 500
18
18
  })
19
19
 
20
- // wait for the gossipsub heartbeat to rebalance the mesh
20
+ // just having a peer in the subscriber list is not a guarentee they will recieve the
21
+ // message - we have to also wait for the gossipsub heartbeat to rebalance the mesh
21
22
  await delay(2000)
22
23
  }
@@ -29,7 +29,10 @@ function relayTest (factory: DaemonFactory, aType: NodeType, bType: NodeType, re
29
29
 
30
30
  beforeEach(async function () {
31
31
  this.timeout(20 * 1000)
32
- ;[aNode, bNode, relay] = await Promise.all(opts.map(async o => await factory.spawn(o)))
32
+ aNode = await factory.spawn(opts[0])
33
+ bNode = await factory.spawn(opts[1])
34
+ relay = await factory.spawn(opts[2])
35
+
33
36
  ;[bId, relayId] = await Promise.all([bNode, relay].map(async d => await d.client.identify()))
34
37
 
35
38
  // construct a relay address
@@ -40,7 +43,11 @@ function relayTest (factory: DaemonFactory, aType: NodeType, bType: NodeType, re
40
43
  })
41
44
 
42
45
  afterEach(async function () {
43
- await Promise.all([aNode, bNode, relay].map(async d => { await d.stop() }))
46
+ await Promise.all(
47
+ [aNode, bNode, relay]
48
+ .filter(Boolean)
49
+ .map(async d => { await d.stop() })
50
+ )
44
51
  })
45
52
 
46
53
  it('connects', async () => {
@@ -24,21 +24,20 @@ export function echoStreamTests (factory: DaemonFactory, muxer: Muxer): void {
24
24
 
25
25
  function runEchoStreamTests (factory: DaemonFactory, muxer: Muxer, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
26
26
  describe(`echo streams - ${muxer}`, () => {
27
- let daemons: Daemon[]
27
+ let daemonA: Daemon
28
+ let daemonB: Daemon
28
29
 
29
30
  // Start Daemons
30
31
  before(async function () {
31
32
  this.timeout(20 * 1000)
32
33
 
33
- daemons = await Promise.all([
34
- factory.spawn(optionsA),
35
- factory.spawn(optionsB)
36
- ])
34
+ daemonA = await factory.spawn(optionsA)
35
+ daemonB = await factory.spawn(optionsB)
37
36
 
38
37
  // connect them
39
- const identify0 = await daemons[0].client.identify()
38
+ const identify0 = await daemonA.client.identify()
40
39
 
41
- await daemons[1].client.connect(identify0.peerId, identify0.addrs)
40
+ await daemonB.client.connect(identify0.peerId, identify0.addrs)
42
41
 
43
42
  // jsDaemon1 will take some time to get the peers
44
43
  await new Promise(resolve => setTimeout(resolve, 1000))
@@ -46,21 +45,21 @@ function runEchoStreamTests (factory: DaemonFactory, muxer: Muxer, optionsA: Spa
46
45
 
47
46
  // Stop daemons
48
47
  after(async function () {
49
- if (daemons != null) {
50
- await Promise.all(
51
- daemons.map(async (daemon) => { await daemon.stop() })
52
- )
53
- }
48
+ await Promise.all(
49
+ [daemonA, daemonB]
50
+ .filter(Boolean)
51
+ .map(async d => { await d.stop() })
52
+ )
54
53
  })
55
54
 
56
55
  it(`${optionsA.type} sender to ${optionsB.type} listener`, async function () {
57
56
  this.timeout(10 * 1000)
58
57
 
59
- const receivingIdentity = await daemons[1].client.identify()
58
+ const receivingIdentity = await daemonB.client.identify()
60
59
  const protocol = '/echo/1.0.0'
61
60
  const input = [uint8ArrayFromString('hello world')]
62
61
 
63
- await daemons[1].client.registerStreamHandler(protocol, async (stream) => {
62
+ await daemonB.client.registerStreamHandler(protocol, async (stream) => {
64
63
  await pipe(
65
64
  stream,
66
65
  async function * (source) {
@@ -72,7 +71,7 @@ function runEchoStreamTests (factory: DaemonFactory, muxer: Muxer, optionsA: Spa
72
71
  )
73
72
  })
74
73
 
75
- const stream = await daemons[0].client.openStream(receivingIdentity.peerId, protocol)
74
+ const stream = await daemonA.client.openStream(receivingIdentity.peerId, protocol)
76
75
 
77
76
  // without this the socket can close before we receive a response
78
77
  const responseReceived = defer()