Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 572194e

Browse files
committed
fix: update dht tests
1 parent 332cefb commit 572194e

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

js/src/dht/get.js

+27-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ module.exports = (createCommon, options) => {
3030

3131
nodeA = nodes[0]
3232
nodeB = nodes[1]
33-
3433
connect(nodeA, nodeB.peerId.addresses[0], done)
3534
})
3635
})
@@ -45,7 +44,7 @@ module.exports = (createCommon, options) => {
4544
})
4645
})
4746

48-
it('should get a value after it was put on another node', function (done) {
47+
it.skip('should get a value after it was added on another node', function (done) {
4948
this.timeout(80 * 1000)
5049

5150
// TODO - this test needs to keep tryingl instead of the setTimeout
@@ -63,5 +62,31 @@ module.exports = (createCommon, options) => {
6362
}
6463
], done)
6564
})
65+
66+
it('should get a value after it was put on another node', function (done) {
67+
this.timeout(80 * 1000)
68+
const multihash = Buffer.from('/v/hello')
69+
const data = Buffer.from('data')
70+
71+
// Rewrite validators
72+
nodeA._libp2pNode._dht.validators.v = nodeB._libp2pNode._dht.validators.v = {
73+
func (key, publicKey, callback) {
74+
setImmediate(callback)
75+
},
76+
sign: false
77+
}
78+
79+
// Rewrite selectors
80+
nodeA._libp2pNode._dht.selectors.v = () => 0
81+
82+
waterfall([
83+
(cb) => nodeB.dht.put(multihash, data, cb),
84+
(cb) => nodeA.dht.get(multihash, (err, res) => {
85+
expect(err).to.not.exist()
86+
expect(res).to.eql(data)
87+
cb()
88+
})
89+
], done)
90+
})
6691
})
6792
}

js/src/dht/put.js

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,50 @@
11
/* eslint-env mocha */
22
'use strict'
33

4+
const { spawnNodesWithId } = require('../utils/spawn')
45
const { getDescribe, getIt, expect } = require('../utils/mocha')
6+
const { connect } = require('../utils/swarm')
57

68
module.exports = (createCommon, options) => {
79
const describe = getDescribe(options)
810
const it = getIt(options)
911
const common = createCommon()
1012

1113
describe('.dht.put', function () {
14+
this.timeout(80 * 1000)
15+
16+
let nodeA
17+
let nodeB
18+
1219
before(function (done) {
1320
// CI takes longer to instantiate the daemon, so we need to increase the
1421
// timeout for the before step
1522
this.timeout(60 * 1000)
1623

1724
common.setup((err, factory) => {
1825
expect(err).to.not.exist()
19-
done()
26+
27+
spawnNodesWithId(2, factory, (err, nodes) => {
28+
expect(err).to.not.exist()
29+
30+
nodeA = nodes[0]
31+
nodeB = nodes[1]
32+
connect(nodeA, nodeB.peerId.addresses[0], done)
33+
})
2034
})
2135
})
2236

2337
after((done) => common.teardown(done))
2438

25-
it.skip('should put a value on the DHT', (done) => {
26-
// TODO: implement me
39+
it('should put a value on the DHT and it become provided by the peer', (done) => {
40+
this.timeout(80 * 1000)
41+
const key = Buffer.from('QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn')
42+
const data = Buffer.from('data')
43+
44+
nodeA.dht.put(key, data, (err) => {
45+
expect(err).to.not.exist()
46+
done()
47+
})
2748
})
2849
})
2950
}

0 commit comments

Comments
 (0)