This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathput.js
48 lines (40 loc) · 1.44 KB
/
put.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* eslint-env mocha */
'use strict'
const { getDescribe, getIt, expect } = require('../utils/mocha')
const all = require('it-all')
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
/**
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
/**
* @param {Factory} factory
* @param {Object} options
*/
module.exports = (factory, options) => {
const describe = getDescribe(options)
const it = getIt(options)
describe('.dht.put', function () {
/** @type {import('ipfs-core-types').IPFS} */
let nodeA
/** @type {import('ipfs-core-types').IPFS} */
let nodeB
/** @type {import('ipfs-core-types/src/root').IDResult} */
let nodeBId
before(async () => {
nodeA = (await factory.spawn()).api
nodeB = (await factory.spawn()).api
nodeBId = await nodeB.id()
await nodeA.swarm.connect(nodeBId.addresses[0])
})
after(() => factory.clean())
it('should put a value to the DHT', async function () {
const { cid } = await nodeA.add('should put a value to the DHT')
const publish = await nodeA.name.publish(cid)
const record = await nodeA.dht.get(uint8ArrayFromString(`/ipns/${publish.name}`))
const value = await all(nodeA.dht.put(uint8ArrayFromString(`/ipns/${publish.name}`), record, { verbose: true }))
expect(value).to.has.length(3)
expect(value[2].id.toString()).to.be.equal(nodeBId.id)
expect(value[2].type).to.be.equal(5)
})
})
}