diff --git a/src/cli/commands/block/stat.js b/src/cli/commands/block/stat.js index c1107f77df..7fefee7e7a 100644 --- a/src/cli/commands/block/stat.js +++ b/src/cli/commands/block/stat.js @@ -29,7 +29,7 @@ module.exports = { } if (typeof block.Key !== 'string') { - block.Key = bs58.encode(block.Key).toString() + block.key = bs58.encode(block.key).toString() } Object.keys(block).forEach((key) => { diff --git a/src/core/ipfs/libp2p.js b/src/core/ipfs/libp2p.js index 8aa70aeb85..c2a05a0a5b 100644 --- a/src/core/ipfs/libp2p.js +++ b/src/core/ipfs/libp2p.js @@ -1,14 +1,12 @@ 'use strict' -const peerId = require('peer-id') const multiaddr = require('multiaddr') const Libp2pNode = require('libp2p-ipfs').Node -const mafmt = require('mafmt') const OFFLINE_ERROR = require('../utils').OFFLINE_ERROR module.exports = function libp2p (self) { - // NOTE: TODO CONSIDER/ CONSIDERING putting all of libp2p (start, stop, peerbook and so on) inside the libp2p object and reduce one layer + // NOTE: TODO CONSIDER/CONSIDERING putting all of libp2p (start, stop, peerbook and so on) inside the libp2p object and reduce one layer return { start: (callback) => { @@ -64,22 +62,7 @@ module.exports = function libp2p (self) { maddr = multiaddr(maddr) } - if (!mafmt.IPFS.matches(maddr.toString())) { - return callback(new Error('multiaddr not valid')) - } - - let ipfsIdB58String - maddr.stringTuples().forEach((tuple) => { - if (tuple[0] === 421) { - ipfsIdB58String = tuple[1] - } - }) - - const id = peerId.createFromB58String(ipfsIdB58String) - - self._libp2pNode.dialByMultiaddr(maddr, (err) => { - callback(err, id) - }) + self._libp2pNode.dialByMultiaddr(maddr, callback) }, disconnect: (maddr, callback) => { if (!self.isOnline()) { diff --git a/src/http-api/resources/swarm.js b/src/http-api/resources/swarm.js index 004c241e97..ff67faf122 100644 --- a/src/http-api/resources/swarm.js +++ b/src/http-api/resources/swarm.js @@ -72,7 +72,7 @@ exports.connect = { handler: (request, reply) => { const addr = request.pre.args.addr - request.server.app.ipfs.libp2p.swarm.connect(addr, (err, res) => { + request.server.app.ipfs.libp2p.swarm.connect(addr, (err) => { if (err) { log.error(err) return reply({ @@ -82,7 +82,7 @@ exports.connect = { } return reply({ - Strings: [`connect ${res.toB58String()} success`] + Strings: [`connect ${addr} success`] }) }) } diff --git a/test/core/node-only/test-swarm-2.js b/test/core/node-only/test-swarm-2.js new file mode 100644 index 0000000000..3023f0de6c --- /dev/null +++ b/test/core/node-only/test-swarm-2.js @@ -0,0 +1,23 @@ +/* eslint-env mocha */ + +'use strict' + +/* +const test = require('interface-ipfs-core') +const IPFSFactory = require('../../utils/factory-core') + +let factory + +const common = { + setup: function (cb) { + factory = new IPFSFactory() + cb(null, factory) + }, + teardown: function (cb) { + factory.dismantle(cb) + } +} +*/ +// TODO +// Needs: https://github.com/ipfs/js-libp2p-ipfs/pull/16 +// test.swarm(common) diff --git a/test/http-api/index.js b/test/http-api/index.js index c6f25f7a26..0d31d0faaf 100644 --- a/test/http-api/index.js +++ b/test/http-api/index.js @@ -47,7 +47,7 @@ describe('HTTP API', () => { }) }) - describe.only('## interface-ipfs-core tests over ipfs-api', () => { + describe('## interface-ipfs-core tests over ipfs-api', () => { const tests = fs.readdirSync(path.join(__dirname, '/interface-ipfs-core-over-ipfs-api')) tests.filter((file) => { diff --git a/test/http-api/interface-ipfs-core-over-ipfs-api/test-files.js b/test/http-api/interface-ipfs-core-over-ipfs-api/test-files.js index e69de29bb2..4a322b948e 100644 --- a/test/http-api/interface-ipfs-core-over-ipfs-api/test-files.js +++ b/test/http-api/interface-ipfs-core-over-ipfs-api/test-files.js @@ -0,0 +1,24 @@ +/* eslint-env mocha */ + +'use strict' + +/* +const test = require('interface-ipfs-core') +const FactoryClient = require('./../../utils/factory-http') + +let fc + +const common = { + setup: function (callback) { + fc = new FactoryClient() + callback(null, fc) + }, + teardown: function (callback) { + fc.dismantle(callback) + } +} +*/ + +// TODO +// needs: https://github.com/ipfs/js-ipfs/pull/323 +// test.files(common) diff --git a/test/http-api/interface-ipfs-core-over-ipfs-api/test-swarm.js b/test/http-api/interface-ipfs-core-over-ipfs-api/test-swarm.js index e69de29bb2..c8e332e12d 100644 --- a/test/http-api/interface-ipfs-core-over-ipfs-api/test-swarm.js +++ b/test/http-api/interface-ipfs-core-over-ipfs-api/test-swarm.js @@ -0,0 +1,23 @@ +/* eslint-env mocha */ + +'use strict' + +/* +const test = require('interface-ipfs-core') +const FactoryClient = require('./../../utils/factory-http') + +let fc + +const common = { + setup: function (callback) { + fc = new FactoryClient() + callback(null, fc) + }, + teardown: function (callback) { + fc.dismantle(callback) + } +} +*/ +// TODO +// Needs: https://github.com/ipfs/js-libp2p-ipfs/pull/16 +// test.swarm(common) diff --git a/test/http-api/ipfs-api/test-block.js b/test/http-api/ipfs-api/test-block.js index 6bc1f07800..1632f8a654 100644 --- a/test/http-api/ipfs-api/test-block.js +++ b/test/http-api/ipfs-api/test-block.js @@ -2,20 +2,21 @@ 'use strict' const expect = require('chai').expect +const multihash = require('multihashes') module.exports = (ctl) => { describe('.block', () => { describe('.put', () => { it('updates value', (done) => { - const filePath = 'test/test-data/hello' + const data = new Buffer('hello world\n') const expectedResult = { - Key: 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', - Size: 12 + key: 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', + size: 12 } - ctl.block.put(filePath, (err, res) => { + ctl.block.put(data, (err, block) => { expect(err).not.to.exist - expect(res).to.deep.equal(expectedResult) + expect(block.key).to.deep.equal(multihash.fromB58String(expectedResult.key)) done() }) }) @@ -39,7 +40,7 @@ module.exports = (ctl) => { it('returns value', (done) => { ctl.block.get('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', (err, result) => { expect(err).to.not.exist - expect(result.toString()) + expect(result.data.toString()) .to.equal('hello world\n') done() }) @@ -64,9 +65,9 @@ module.exports = (ctl) => { it('returns value', (done) => { ctl.block.stat('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', (err, result) => { expect(err).to.not.exist - expect(result.Key) + expect(result.key) .to.equal('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') - expect(result.Size).to.equal(12) + expect(result.size).to.equal(12) done() }) })