From c18e21f20f6e50bf83fe9ca5a344d77793f2929b Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 16 Mar 2016 14:47:21 +0000 Subject: [PATCH] jsipfs swarm; libp2p start and stop; not fail on browser tests. separate browser and node.js swarm tests --- README.md | 4 ++-- karma.conf.js | 3 ++- package.json | 2 +- src/http-api/index.js | 27 +++++++++++----------- src/ipfs-core/index.js | 19 +++++++++++---- tests/otherconfig | 2 +- tests/repo-example/config | 2 +- tests/test-cli/test-id.js | 11 +++++---- tests/test-core/browser.js | 12 +++++++++- tests/test-core/index.js | 4 +++- tests/test-core/test-config.js | 4 ++-- tests/test-core/test-id.js | 2 +- tests/test-core/test-swarm-browser.js | 0 tests/test-core/test-swarm-node.js | 33 +++++++++++++++++++++++++++ tests/test-http-api/test-id.js | 12 +++++++--- 15 files changed, 100 insertions(+), 37 deletions(-) create mode 100644 tests/test-core/test-swarm-browser.js create mode 100644 tests/test-core/test-swarm-node.js diff --git a/README.md b/README.md index 977c3512c4..5006bb96b6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -js-ipfs -======= +IPFS JavaScript Implementation +============================== [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) ![Build Status](https://travis-ci.org/ipfs/js-ipfs.svg?style=flat-square)](https://travis-ci.org/ipfs/js-ipfs) ![](https://img.shields.io/badge/coverage-75%25-yellow.svg?style=flat-square) [![Dependency Status](https://david-dm.org/ipfs/js-ipfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) diff --git a/karma.conf.js b/karma.conf.js index 5ced2208cd..5675220731 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -22,7 +22,8 @@ module.exports = function (config) { externals: { fs: '{}', 'node-forge': 'forge', - 'ipfs-data-importing': '{ import: {} }' + 'ipfs-data-importing': '{ import: {} }', + 'libp2p-ipfs': {} // to be 'libp2p-ipfs-browser' }, node: { Buffer: true diff --git a/package.json b/package.json index 82b8cc8308..87d6638dfb 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "ipfs-multipart": "^0.1.0", "ipfs-repo": "^0.5.0", "joi": "^8.0.2", - "libp2p-ipfs": "^0.1.0", + "libp2p-ipfs": "^0.2.0", "lodash.get": "^4.0.0", "lodash.set": "^4.0.0", "peer-id": "^0.6.0", diff --git a/src/http-api/index.js b/src/http-api/index.js index de961a5902..fec9c540d0 100644 --- a/src/http-api/index.js +++ b/src/http-api/index.js @@ -48,17 +48,17 @@ exports.start = (callback) => { // load routes require('./routes')(server) - // TODO start libp2p.Node - - server.start((err) => { - if (err) { - return callback(err) - } - const api = server.select('API') - const gateway = server.select('Gateway') - console.log('API is listening on: ' + api.info.uri) - console.log('Gateway (readonly) is listening on: ' + gateway.info.uri) - callback() + ipfs.libp2p.start(() => { + server.start((err) => { + if (err) { + return callback(err) + } + const api = server.select('API') + const gateway = server.select('Gateway') + console.log('API is listening on: ' + api.info.uri) + console.log('Gateway (readonly) is listening on: ' + gateway.info.uri) + callback() + }) }) }) }) @@ -67,6 +67,7 @@ exports.start = (callback) => { exports.stop = (callback) => { const repoPath = process.env.IPFS_PATH || os.homedir() + '/.ipfs' fs.unlinkSync(repoPath + '/api') - // TODO stop libp2p - exports.server.stop(callback) + exports.ipfs.libp2p.stop(() => { + exports.server.stop(callback) + }) } diff --git a/src/ipfs-core/index.js b/src/ipfs-core/index.js index 990d75101c..2e66dea3a2 100644 --- a/src/ipfs-core/index.js +++ b/src/ipfs-core/index.js @@ -12,6 +12,7 @@ const Id = require('peer-id') const Info = require('peer-info') const multiaddr = require('multiaddr') const importer = require('ipfs-data-importing').import +const libp2p = require('libp2p-ipfs') exports = module.exports = IPFS @@ -27,7 +28,7 @@ function IPFS (repo) { const blockS = new BlockService(repo) const dagS = new DAGService(blockS) var peerInfo - // var libp2pNode + var libp2pNode this.load = (callback) => { repo.exists((err, exists) => { @@ -305,13 +306,21 @@ function IPFS (repo) { } this.libp2p = { - start: () => { - + start: (callback) => { + libp2pNode = new libp2p.Node(peerInfo) + libp2pNode.start(() => { + // TODO connect to bootstrap nodes, it will get us more addrs + peerInfo.multiaddrs.forEach((ma) => { + console.log('Swarm listening on', ma.toString()) + }) + callback() + }) }, - stop: () => { + stop: (callback) => { + libp2pNode.swarm.close(callback) }, swarm: { - peers: notImpl, + peers: () => {}, addrs: notImpl, connect: notImpl, disconnect: notImpl, diff --git a/tests/otherconfig b/tests/otherconfig index 40abcaf546..870bb826f0 100644 --- a/tests/otherconfig +++ b/tests/otherconfig @@ -15,7 +15,7 @@ "Addresses": { "Swarm": ["/ip4/0.0.0.0/tcp/4001", "/ip6/::/tcp/4001"], "API": "/ip4/127.0.0.1/tcp/6001", - "Gateway": "/ip4/127.0.0.1/tcp/9090" + "Gateway": "/ip4/127.0.0.1/tcp/9080" }, "Mounts": { "IPFS": "/ipfs", diff --git a/tests/repo-example/config b/tests/repo-example/config index 7acd853818..6d33fee2ac 100644 --- a/tests/repo-example/config +++ b/tests/repo-example/config @@ -1 +1 @@ -{"Identity":{"PeerID":"QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A","PrivKey":"CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu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QEjb5Onn5mZnGDh+72BxLNdgwBkhO0OCdpdISqk0F0Pxby22DFOKXZEpiyI9XYP1C8wPiJsShGm2yEwBPWXnrrZNWczaVuCbXHrZkWQogBDG3HGXNdU4MAWCyiYlyinIBpPpoAJZSzpGLmWbMWh28+RJS6AQX6KHrK1o2uw=="},"Datastore":{"Type":"","Path":"","StorageMax":"","StorageGCWatermark":0,"GCPeriod":"","Params":null,"NoSync":false},"Addresses":{"Swarm":["/ip4/0.0.0.0/tcp/4001","/ip6/::/tcp/4001"],"API":"/ip4/127.0.0.1/tcp/6001","Gateway":"/ip4/127.0.0.1/tcp/9090"},"Mounts":{"IPFS":"/ipfs","IPNS":"/ipns","FuseAllowOther":false},"Version":{"Current":"0.4.0-dev","Check":"error","CheckDate":"0001-01-01T00:00:00Z","CheckPeriod":"172800000000000","AutoUpdate":"minor"},"Discovery":{"MDNS":{"Enabled":true,"Interval":10}},"Ipns":{"RepublishPeriod":"","RecordLifetime":"","ResolveCacheSize":128},"Bootstrap":["/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ","/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z","/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM","/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm","/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu","/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64","/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd","/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3","/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx"],"Tour":{"Last":""},"Gateway":{"HTTPHeaders":null,"RootRedirect":"","Writable":false},"SupernodeRouting":{"Servers":["/ip4/104.236.176.52/tcp/4002/ipfs/QmXdb7tWTxdFEQEFgWBqkuYSrZd3mXrC7HxkD4krGNYx2U","/ip4/104.236.179.241/tcp/4002/ipfs/QmVRqViDByUxjUMoPnjurjKvZhaEMFDtK35FJXHAM4Lkj6","/ip4/104.236.151.122/tcp/4002/ipfs/QmSZwGx8Tn8tmcM4PtDJaMeUQNRhNFdBLVGPzRiNaRJtFH","/ip4/162.243.248.213/tcp/4002/ipfs/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP","/ip4/128.199.219.111/tcp/4002/ipfs/Qmb3brdCYmKG1ycwqCbo6LUwWxTuo3FisnJV2yir7oN92R","/ip4/104.236.76.40/tcp/4002/ipfs/QmdRBCV8Cz2dGhoKLkD3YjPwVFECmqADQkx5ZteF2c6Fy4","/ip4/178.62.158.247/tcp/4002/ipfs/QmUdiMPci7YoEUBkyFZAh2pAbjqcPr7LezyiPD2artLw3v","/ip4/178.62.61.185/tcp/4002/ipfs/QmVw6fGNqBixZE4bewRLT2VXX7fAHUHs8JyidDiJ1P7RUN"]},"API":{"HTTPHeaders":null},"Swarm":{"AddrFilters":null},"Log":{"MaxSizeMB":250,"MaxBackups":1,"MaxAgeDays":0}} \ No newline at end of file +{"Identity":{"PeerID":"QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A","PrivKey":"CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5c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Pjwm/U9V0gdAl2+r50HAoGALtsKqMvhv8HucAMBPrLikhXP/8um8mMKFMrzfqZ+otxfHzlhI0L08Bo3jQrb0Z7ByNY6M8epOmbCKADsbWcVre/AAY0ZkuSZK/CaOXNX/AhMKmKJh8qAOPRY02LIJRBCpfS4czEdnfUhYV/TYiFNnKRj57PPYZdTzUsxa/yVTmECgYBr7slQEjb5Onn5mZnGDh+72BxLNdgwBkhO0OCdpdISqk0F0Pxby22DFOKXZEpiyI9XYP1C8wPiJsShGm2yEwBPWXnrrZNWczaVuCbXHrZkWQogBDG3HGXNdU4MAWCyiYlyinIBpPpoAJZSzpGLmWbMWh28+RJS6AQX6KHrK1o2uw=="},"Datastore":{"Type":"","Path":"","StorageMax":"","StorageGCWatermark":0,"GCPeriod":"","Params":null,"NoSync":false},"Addresses":{"Swarm":["/ip4/0.0.0.0/tcp/0"],"API":"/ip4/127.0.0.1/tcp/6001","Gateway":"/ip4/127.0.0.1/tcp/9095"},"Mounts":{"IPFS":"/ipfs","IPNS":"/ipns","FuseAllowOther":false},"Version":{"Current":"0.4.0-dev","Check":"error","CheckDate":"0001-01-01T00:00:00Z","CheckPeriod":"172800000000000","AutoUpdate":"minor"},"Discovery":{"MDNS":{"Enabled":true,"Interval":10}},"Ipns":{"RepublishPeriod":"","RecordLifetime":"","ResolveCacheSize":128},"Bootstrap":["/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ","/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z","/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM","/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm","/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu","/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64","/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd","/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3","/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx"],"Tour":{"Last":""},"Gateway":{"HTTPHeaders":null,"RootRedirect":"","Writable":false},"SupernodeRouting":{"Servers":["/ip4/104.236.176.52/tcp/4002/ipfs/QmXdb7tWTxdFEQEFgWBqkuYSrZd3mXrC7HxkD4krGNYx2U","/ip4/104.236.179.241/tcp/4002/ipfs/QmVRqViDByUxjUMoPnjurjKvZhaEMFDtK35FJXHAM4Lkj6","/ip4/104.236.151.122/tcp/4002/ipfs/QmSZwGx8Tn8tmcM4PtDJaMeUQNRhNFdBLVGPzRiNaRJtFH","/ip4/162.243.248.213/tcp/4002/ipfs/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP","/ip4/128.199.219.111/tcp/4002/ipfs/Qmb3brdCYmKG1ycwqCbo6LUwWxTuo3FisnJV2yir7oN92R","/ip4/104.236.76.40/tcp/4002/ipfs/QmdRBCV8Cz2dGhoKLkD3YjPwVFECmqADQkx5ZteF2c6Fy4","/ip4/178.62.158.247/tcp/4002/ipfs/QmUdiMPci7YoEUBkyFZAh2pAbjqcPr7LezyiPD2artLw3v","/ip4/178.62.61.185/tcp/4002/ipfs/QmVw6fGNqBixZE4bewRLT2VXX7fAHUHs8JyidDiJ1P7RUN"]},"API":{"HTTPHeaders":null},"Swarm":{"AddrFilters":null},"Log":{"MaxSizeMB":250,"MaxBackups":1,"MaxAgeDays":0}} diff --git a/tests/test-cli/test-id.js b/tests/test-cli/test-id.js index 786d6cf181..0eddca0604 100644 --- a/tests/test-cli/test-id.js +++ b/tests/test-cli/test-id.js @@ -11,13 +11,13 @@ describe('id', () => { .run((err, stdout, exitcode) => { var expected = [ "{ ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A',", " PublicKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=',", - " Addresses: [ '/ip4/0.0.0.0/tcp/4001', '/ip6/::/tcp/4001' ],", + " Addresses: [ '/ip4/0.0.0.0/tcp/0'],", " AgentVersion: 'js-ipfs',", " ProtocolVersion: '9000' }" ] expect(stdout[0]).to.equal(expected[0]) expect(stdout[1]).to.equal(expected[1]) - expect(stdout[2]).to.equal(expected[2]) + // expect(stdout[2]).to.equal(expected[2]) expect(stdout[3]).to.equal(expected[3]) expect(stdout[4]).to.equal(expected[4]) expect(stdout[5]).to.equal(expected[5]) @@ -48,15 +48,16 @@ describe('id', () => { it('get the id', (done) => { nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'id']) .run((err, stdout, exitcode) => { - var expected = [ "{ ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A',", + var expected = [ + "{ ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A',", " PublicKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=',", - " Addresses: [ '/ip4/0.0.0.0/tcp/4001', '/ip6/::/tcp/4001' ],", + " Addresses: [ '/ip4/0.0.0.0/tcp/0' ],", " AgentVersion: 'js-ipfs',", " ProtocolVersion: '9000' }" ] expect(stdout[0]).to.equal(expected[0]) expect(stdout[1]).to.equal(expected[1]) - expect(stdout[2]).to.equal(expected[2]) + // expect(stdout[2]).to.equal(expected[2]) expect(stdout[3]).to.equal(expected[3]) expect(stdout[4]).to.equal(expected[4]) expect(stdout[5]).to.equal(expected[5]) diff --git a/tests/test-core/browser.js b/tests/test-core/browser.js index ef09f016b2..9a6e631e32 100644 --- a/tests/test-core/browser.js +++ b/tests/test-core/browser.js @@ -47,6 +47,16 @@ describe('IPFS Repo Tests on the Browser', function () { const testsContext = require.context('.', true, /test-*/) testsContext .keys() - .forEach((key) => testsContext(key)) + .filter((key) => { + if (key === './test-swarm-node.js' || + key === './test-swarm-node') { + return false + } else { + return true + } + }) + .forEach((key) => { + testsContext(key) + }) }) }) diff --git a/tests/test-core/index.js b/tests/test-core/index.js index 5e6f69e73d..e1d9e20eb8 100644 --- a/tests/test-core/index.js +++ b/tests/test-core/index.js @@ -26,7 +26,9 @@ describe('core', () => { const tests = fs.readdirSync(__dirname) tests.filter((file) => { - if (file === 'index.js' || file === 'browser.js') { + if (file === 'index.js' || + file === 'browser.js' || + file === 'test-swarm-browser.js') { return false } else { return true diff --git a/tests/test-core/test-config.js b/tests/test-core/test-config.js index 54bf233099..cbbd86a24f 100644 --- a/tests/test-core/test-config.js +++ b/tests/test-core/test-config.js @@ -15,9 +15,9 @@ describe('config', () => { GCPeriod: '', Params: null, NoSync: false }, - Addresses: { Swarm: [ '/ip4/0.0.0.0/tcp/4001', '/ip6/::/tcp/4001' ], + Addresses: { Swarm: [ '/ip4/0.0.0.0/tcp/0' ], API: '/ip4/127.0.0.1/tcp/6001', - Gateway: '/ip4/127.0.0.1/tcp/9090' }, + Gateway: '/ip4/127.0.0.1/tcp/9095' }, Mounts: { IPFS: '/ipfs', IPNS: '/ipns', FuseAllowOther: false }, Version: { Current: '0.4.0-dev', Check: 'error', diff --git a/tests/test-core/test-id.js b/tests/test-core/test-id.js index 4e7130a294..1520af1839 100644 --- a/tests/test-core/test-id.js +++ b/tests/test-core/test-id.js @@ -18,7 +18,7 @@ describe('id', () => { expect(err).to.not.exist expect(id).to.deep.equal({ ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A', PublicKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=', - Addresses: [ '/ip4/0.0.0.0/tcp/4001', '/ip6/::/tcp/4001' ], + Addresses: [ '/ip4/0.0.0.0/tcp/0' ], AgentVersion: 'js-ipfs', ProtocolVersion: '9000' }) diff --git a/tests/test-core/test-swarm-browser.js b/tests/test-core/test-swarm-browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/test-core/test-swarm-node.js b/tests/test-core/test-swarm-node.js new file mode 100644 index 0000000000..7843cbd866 --- /dev/null +++ b/tests/test-core/test-swarm-node.js @@ -0,0 +1,33 @@ +/* eslint-env mocha */ + +const expect = require('chai').expect + +process.env.IPFS_PATH = process.cwd() + '/tests/repo-example' +const IPFS = require('../../src/ipfs-core') + +describe('swarm', () => { + var ipfs + + before((done) => { + ipfs = new IPFS() + ipfs.load(done) + }) + + it('start', (done) => { + ipfs.libp2p.start((err) => { + expect(err).to.not.exist + done() + }) + }) + + it.skip('swarm peers', (done) => {}) + it.skip('swarm connect', (done) => {}) + it.skip('swarm disconnect', (done) => {}) + + it('stop', (done) => { + ipfs.libp2p.stop((err) => { + expect(err).to.not.exist + done() + }) + }) +}) diff --git a/tests/test-http-api/test-id.js b/tests/test-http-api/test-id.js index cef1b6e671..856ac2b3a9 100644 --- a/tests/test-http-api/test-id.js +++ b/tests/test-http-api/test-id.js @@ -17,7 +17,10 @@ describe('id', () => { method: 'GET', url: '/api/v0/id' }, (res) => { - expect(res.result).to.deep.equal(idResult) + expect(res.result.ID).to.equal(idResult.ID) + expect(res.result.PublicKey).to.equal(idResult.PublicKey) + expect(res.result.AgentVersion).to.equal(idResult.AgentVersion) + expect(res.result.ProtocolVersion).to.equal(idResult.ProtocolVersion) done() }) }) @@ -36,7 +39,10 @@ describe('id', () => { it('get the id', (done) => { ctl.id((err, result) => { expect(err).to.not.exist - expect(result).to.deep.equal(idResult) + expect(result.ID).to.equal(idResult.ID) + expect(result.PublicKey).to.equal(idResult.PublicKey) + expect(result.AgentVersion).to.equal(idResult.AgentVersion) + expect(result.ProtocolVersion).to.equal(idResult.ProtocolVersion) done() }) }) @@ -46,7 +52,7 @@ describe('id', () => { const idResult = { ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A', PublicKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=', - Addresses: [ '/ip4/0.0.0.0/tcp/4001', '/ip6/::/tcp/4001' ], + Addresses: [ '/ip4/0.0.0.0/tcp/0' ], AgentVersion: 'js-ipfs', ProtocolVersion: '9000' }