From 3e5ed076fc7e656652755f47db131b57c64d464c Mon Sep 17 00:00:00 2001 From: Victor Bjelkholm Date: Sat, 17 Sep 2016 17:49:13 +0200 Subject: [PATCH] Move tests from js-ipfs-api to interface-ipfs-core --- src/dht.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/index.js | 1 + 2 files changed, 63 insertions(+) create mode 100644 src/dht.js diff --git a/src/dht.js b/src/dht.js new file mode 100644 index 00000000..0953d517 --- /dev/null +++ b/src/dht.js @@ -0,0 +1,62 @@ +/* eslint-env mocha */ +'use strict' + +const expect = require('chai').expect + +module.exports = (common) => { + describe.only('.dht', () => { + let ipfs + + before((done) => { + common.setup((err, factory) => { + expect(err).to.not.exists + factory.spawnNode((err, node) => { + expect(err).to.not.exist + ipfs = node + done() + }) + }) + }) + + after((done) => { + common.teardown(done) + }) + xdescribe('.findpeer', () => {}) + describe('.get', (done) => { + it('errors when getting a non-existent key from the DHT', (done) => { + ipfs.dht.get('non-existing', {timeout: '100ms'}, (err, value) => { + expect(err).to.be.an.instanceof(Error) + done() + }) + }) + // belongs in put or integration + it('puts and gets a key value pair in the DHT', (done) => { + ipfs.dht.put('scope', 'interplanetary', (err, res) => { + expect(err).to.not.exist + + expect(res).to.be.an('array') + + done() + // bug: https://github.com/ipfs/go-ipfs/issues/1923#issuecomment-152932234 + // apiClients.a.dht.get('scope', (err, value) => { + // expect(err).to.not.exist + // expect(value).to.be.equal('interplanetary') + // done() + // }) + }) + }) + }) + xdescribe('.put', () => {}) + xdescribe('.query', () => {}) + describe('.findprovs', () => { + it('finds providers', (done) => { + ipfs.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { + expect(err).to.not.exist + + expect(res).to.be.an('array') + done() + }) + }) + }) + }) +} diff --git a/src/index.js b/src/index.js index ee35b234..33865f9b 100644 --- a/src/index.js +++ b/src/index.js @@ -7,3 +7,4 @@ exports.pin = require('./pin') exports.generic = require('./generic') exports.swarm = require('./swarm') exports.block = require('./block') +exports.dht = require('./dht')