Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: dht #7

Merged
merged 3 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@
"dirty-chai": "^2.0.1",
"go-libp2p-dep": "^6.0.30",
"libp2p-daemon": "~0.2.0",
"libp2p-daemon-client": "~0.1.1",
"libp2p-daemon-client": "~0.1.2",
"multiaddr": "^6.0.6",
"rimraf": "^2.6.3"
},
"contributors": [],
"dependencies": {
"cids": "~0.5.7",
"execa": "^1.0.0"
}
}
9 changes: 9 additions & 0 deletions test/dht/README.md
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
48 changes: 48 additions & 0 deletions test/dht/content-fetching/go2go.js
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)
})
})
48 changes: 48 additions & 0 deletions test/dht/content-fetching/go2js.js
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)
})
})
6 changes: 6 additions & 0 deletions test/dht/content-fetching/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'

require('./go2go')
require('./go2js')
require('./js2go')
require('./js2js')
48 changes: 48 additions & 0 deletions test/dht/content-fetching/js2go.js
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)
})
})
48 changes: 48 additions & 0 deletions test/dht/content-fetching/js2js.js
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)
})
})
54 changes: 54 additions & 0 deletions test/dht/content-routing/go2go.js
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())
})
})
54 changes: 54 additions & 0 deletions test/dht/content-routing/go2js.js
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())
})
})
6 changes: 6 additions & 0 deletions test/dht/content-routing/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'

require('./go2go')
require('./go2js')
require('./js2go')
require('./js2js')
54 changes: 54 additions & 0 deletions test/dht/content-routing/js2go.js
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())
})
})
Loading