-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from libp2p/test/dht
test: dht
- Loading branch information
Showing
19 changed files
with
625 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# DHT | ||
|
||
In this set of tests, we intend to guarantee that nodes implemented in a specific language are able to use the dht features correctly, regardless of their implementation language. | ||
|
||
This test suite is divided in three main focus: | ||
|
||
- `content-fetching` aims to test the DHT interop regarding `put` and `get` operations between peers | ||
- `content-routing` aims to test the DHT interop regarding `provide` and `findProviders` operations between peers | ||
- `peer-routing` aims to test the DHT interop regarding `findPeer` operations between peers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
chai.use(require('dirty-chai')) | ||
chai.use(require('chai-bytes')) | ||
const expect = chai.expect | ||
|
||
const spawnDaemons = require('../../utils/spawnDaemons') | ||
|
||
describe.skip('dht.contentFetching', () => { | ||
let daemons | ||
|
||
// Start Daemons | ||
before(async function () { | ||
this.timeout(20 * 1000) | ||
|
||
daemons = await spawnDaemons(2, 'go', { dht: true }) | ||
|
||
// connect them | ||
const identify0 = await daemons[0].client.identify() | ||
|
||
await daemons[1].client.connect(identify0.peerId, identify0.addrs) | ||
|
||
// jsDaemon1 will take some time to get the peers | ||
await new Promise(resolve => setTimeout(resolve, 1000)) | ||
}) | ||
|
||
// Stop daemons | ||
after(async function () { | ||
await Promise.all( | ||
daemons.map((daemon) => daemon.stop()) | ||
) | ||
}) | ||
|
||
it('go peer to go peer', async function () { | ||
this.timeout(10 * 1000) | ||
|
||
const key = 'keyA' | ||
const value = Buffer.from('hello data') | ||
|
||
await daemons[0].client.dht.put(key, value) | ||
|
||
const data = await daemons[1].client.dht.get(key) | ||
|
||
expect(data).to.equalBytes(data) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
chai.use(require('dirty-chai')) | ||
chai.use(require('chai-bytes')) | ||
const expect = chai.expect | ||
|
||
const spawnDaemons = require('../../utils/spawnDaemons') | ||
|
||
describe.skip('dht.contentFetching', () => { | ||
let daemons | ||
|
||
// Start Daemons | ||
before(async function () { | ||
this.timeout(20 * 1000) | ||
|
||
daemons = await spawnDaemons(2, ['go', 'js'], { dht: true }) | ||
|
||
// connect them | ||
const identify0 = await daemons[0].client.identify() | ||
|
||
await daemons[1].client.connect(identify0.peerId, identify0.addrs) | ||
|
||
// jsDaemon1 will take some time to get the peers | ||
await new Promise(resolve => setTimeout(resolve, 1000)) | ||
}) | ||
|
||
// Stop daemons | ||
after(async function () { | ||
await Promise.all( | ||
daemons.map((daemon) => daemon.stop()) | ||
) | ||
}) | ||
|
||
it('go peer to js peer', async function () { | ||
this.timeout(10 * 1000) | ||
|
||
const key = 'keyA' | ||
const value = Buffer.from('hello data') | ||
|
||
await daemons[0].client.dht.put(key, value) | ||
|
||
const data = await daemons[1].client.dht.get(key) | ||
|
||
expect(data).to.equalBytes(data) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict' | ||
|
||
require('./go2go') | ||
require('./go2js') | ||
require('./js2go') | ||
require('./js2js') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
chai.use(require('dirty-chai')) | ||
chai.use(require('chai-bytes')) | ||
const expect = chai.expect | ||
|
||
const spawnDaemons = require('../../utils/spawnDaemons') | ||
|
||
describe.skip('dht.contentFetching', () => { | ||
let daemons | ||
|
||
// Start Daemons | ||
before(async function () { | ||
this.timeout(20 * 1000) | ||
|
||
daemons = await spawnDaemons(2, ['js', 'go'], { dht: true }) | ||
|
||
// connect them | ||
const identify0 = await daemons[0].client.identify() | ||
|
||
await daemons[1].client.connect(identify0.peerId, identify0.addrs) | ||
|
||
// jsDaemon1 will take some time to get the peers | ||
await new Promise(resolve => setTimeout(resolve, 1000)) | ||
}) | ||
|
||
// Stop daemons | ||
after(async function () { | ||
await Promise.all( | ||
daemons.map((daemon) => daemon.stop()) | ||
) | ||
}) | ||
|
||
it('js peer to go peer', async function () { | ||
this.timeout(10 * 1000) | ||
|
||
const key = 'keyA' | ||
const value = Buffer.from('hello data') | ||
|
||
await daemons[0].client.dht.put(key, value) | ||
|
||
const data = await daemons[1].client.dht.get(key) | ||
|
||
expect(data).to.equalBytes(data) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
chai.use(require('dirty-chai')) | ||
chai.use(require('chai-bytes')) | ||
const expect = chai.expect | ||
|
||
const spawnDaemons = require('../../utils/spawnDaemons') | ||
|
||
describe('dht.contentFetching', () => { | ||
let daemons | ||
|
||
// Start Daemons | ||
before(async function () { | ||
this.timeout(20 * 1000) | ||
|
||
daemons = await spawnDaemons(2, 'js', { dht: true }) | ||
|
||
// connect them | ||
const identify0 = await daemons[0].client.identify() | ||
|
||
await daemons[1].client.connect(identify0.peerId, identify0.addrs) | ||
|
||
// jsDaemon1 will take some time to get the peers | ||
await new Promise(resolve => setTimeout(resolve, 1000)) | ||
}) | ||
|
||
// Stop daemons | ||
after(async function () { | ||
await Promise.all( | ||
daemons.map((daemon) => daemon.stop()) | ||
) | ||
}) | ||
|
||
it('js peer to js peer', async function () { | ||
this.timeout(10 * 1000) | ||
|
||
const key = 'keyA' | ||
const value = Buffer.from('hello data') | ||
|
||
await daemons[0].client.dht.put(key, value) | ||
|
||
const data = await daemons[1].client.dht.get(key) | ||
|
||
expect(data).to.equalBytes(data) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
chai.use(require('dirty-chai')) | ||
chai.use(require('chai-bytes')) | ||
const expect = chai.expect | ||
|
||
const CID = require('cids') | ||
const spawnDaemons = require('../../utils/spawnDaemons') | ||
|
||
describe('dht.contentRouting', () => { | ||
let daemons | ||
let identify0 | ||
|
||
// Start Daemons | ||
before(async function () { | ||
this.timeout(20 * 1000) | ||
|
||
daemons = await spawnDaemons(2, 'go', { dht: true }) | ||
|
||
// connect them | ||
identify0 = await daemons[0].client.identify() | ||
|
||
await daemons[1].client.connect(identify0.peerId, identify0.addrs) | ||
|
||
// get the peers in the table | ||
await new Promise(resolve => setTimeout(resolve, 1000)) | ||
}) | ||
|
||
// Stop daemons | ||
after(async function () { | ||
await Promise.all( | ||
daemons.map((daemon) => daemon.stop()) | ||
) | ||
}) | ||
|
||
it('go peer to go peer', async function () { | ||
const cid = new CID('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp39') | ||
|
||
await daemons[0].client.dht.provide(cid) | ||
|
||
const findProviders = daemons[1].client.dht.findProviders(cid) | ||
let providers = [] | ||
|
||
for await (const provider of findProviders) { | ||
providers.push(provider) | ||
} | ||
|
||
expect(providers).to.exist() | ||
expect(providers[0]).to.exist() | ||
expect(providers[0].id.toB58String()).to.equal(identify0.peerId.toB58String()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
chai.use(require('dirty-chai')) | ||
chai.use(require('chai-bytes')) | ||
const expect = chai.expect | ||
|
||
const CID = require('cids') | ||
const spawnDaemons = require('../../utils/spawnDaemons') | ||
|
||
describe('dht.contentRouting', () => { | ||
let daemons | ||
let identify0 | ||
|
||
// Start Daemons | ||
before(async function () { | ||
this.timeout(20 * 1000) | ||
|
||
daemons = await spawnDaemons(2, ['go', 'js'], { dht: true }) | ||
|
||
// connect them | ||
identify0 = await daemons[0].client.identify() | ||
|
||
await daemons[1].client.connect(identify0.peerId, identify0.addrs) | ||
|
||
// get the peers in the table | ||
await new Promise(resolve => setTimeout(resolve, 1000)) | ||
}) | ||
|
||
// Stop daemons | ||
after(async function () { | ||
await Promise.all( | ||
daemons.map((daemon) => daemon.stop()) | ||
) | ||
}) | ||
|
||
it('go peer to js peer', async function () { | ||
const cid = new CID('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp39') | ||
|
||
await daemons[0].client.dht.provide(cid) | ||
|
||
const findProviders = daemons[1].client.dht.findProviders(cid) | ||
let providers = [] | ||
|
||
for await (const provider of findProviders) { | ||
providers.push(provider) | ||
} | ||
|
||
expect(providers).to.exist() | ||
expect(providers[0]).to.exist() | ||
expect(providers[0].id.toB58String()).to.equal(identify0.peerId.toB58String()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict' | ||
|
||
require('./go2go') | ||
require('./go2js') | ||
require('./js2go') | ||
require('./js2js') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
chai.use(require('dirty-chai')) | ||
chai.use(require('chai-bytes')) | ||
const expect = chai.expect | ||
|
||
const CID = require('cids') | ||
const spawnDaemons = require('../../utils/spawnDaemons') | ||
|
||
describe('dht.contentRouting', () => { | ||
let daemons | ||
let identify0 | ||
|
||
// Start Daemons | ||
before(async function () { | ||
this.timeout(20 * 1000) | ||
|
||
daemons = await spawnDaemons(2, ['js', 'go'], { dht: true }) | ||
|
||
// connect them | ||
identify0 = await daemons[0].client.identify() | ||
|
||
await daemons[1].client.connect(identify0.peerId, identify0.addrs) | ||
|
||
// get the peers in the table | ||
await new Promise(resolve => setTimeout(resolve, 1000)) | ||
}) | ||
|
||
// Stop daemons | ||
after(async function () { | ||
await Promise.all( | ||
daemons.map((daemon) => daemon.stop()) | ||
) | ||
}) | ||
|
||
it('go peer to js peer', async function () { | ||
const cid = new CID('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp39') | ||
|
||
await daemons[0].client.dht.provide(cid) | ||
|
||
const findProviders = daemons[1].client.dht.findProviders(cid) | ||
let providers = [] | ||
|
||
for await (const provider of findProviders) { | ||
providers.push(provider) | ||
} | ||
|
||
expect(providers).to.exist() | ||
expect(providers[0]).to.exist() | ||
expect(providers[0].id.toB58String()).to.equal(identify0.peerId.toB58String()) | ||
}) | ||
}) |
Oops, something went wrong.