diff --git a/.gitignore b/.gitignore index 4d18d56eb7..25076c86b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ **/node_modules/ **/*.log +tests/repo-tests* # Logs logs diff --git a/src/cli/commands/bootstrap/add.js b/src/cli/commands/bootstrap/add.js new file mode 100644 index 0000000000..188198e438 --- /dev/null +++ b/src/cli/commands/bootstrap/add.js @@ -0,0 +1,20 @@ +'use strict' + +const Command = require('ronin').Command +const IPFS = require('../../../ipfs-core') +const debug = require('debug') +const log = debug('cli:version') +log.error = debug('cli:version:error') + +module.exports = Command.extend({ + desc: 'Show peers in the bootstrap list', + + options: {}, + + run: (multiaddr) => { + var node = new IPFS() + node.bootstrap.add(multiaddr, (err, list) => { + if (err) { return log.error(err) } + }) + } +}) diff --git a/src/cli/commands/bootstrap/list.js b/src/cli/commands/bootstrap/list.js new file mode 100644 index 0000000000..9f52b092a4 --- /dev/null +++ b/src/cli/commands/bootstrap/list.js @@ -0,0 +1,21 @@ +'use strict' + +const Command = require('ronin').Command +const IPFS = require('../../../ipfs-core') +const debug = require('debug') +const log = debug('cli:version') +log.error = debug('cli:version:error') + +module.exports = Command.extend({ + desc: 'Show peers in the bootstrap list', + + options: {}, + + run: (name) => { + var node = new IPFS() + node.bootstrap.list((err, list) => { + if (err) { return log.error(err) } + list.forEach(node => { console.log(node) }) + }) + } +}) diff --git a/src/cli/commands/bootstrap/rm.js b/src/cli/commands/bootstrap/rm.js new file mode 100644 index 0000000000..a3bca1059c --- /dev/null +++ b/src/cli/commands/bootstrap/rm.js @@ -0,0 +1,20 @@ +'use strict' + +const Command = require('ronin').Command +const IPFS = require('../../../ipfs-core') +const debug = require('debug') +const log = debug('cli:version') +log.error = debug('cli:version:error') + +module.exports = Command.extend({ + desc: 'Show peers in the bootstrap list', + + options: {}, + + run: (multiaddr) => { + var node = new IPFS() + node.bootstrap.rm(multiaddr, (err, list) => { + if (err) { return log.error(err) } + }) + } +}) diff --git a/src/http-api/routes/bootstrap.js b/src/http-api/routes/bootstrap.js new file mode 100644 index 0000000000..a5ae2a44e4 --- /dev/null +++ b/src/http-api/routes/bootstrap.js @@ -0,0 +1,22 @@ +'use strict' + +const server = require('./../index.js').server +const resources = require('./../resources') + +server.route({ + method: 'GET', + path: '/api/v0/bootstrap', + handler: resources.version.list +}) + +server.route({ + method: 'POST', + path: '/api/v0/boostrap', + handler: resources.version.add +}) + +server.route({ + method: 'DELETE', + path: '/api/v0/boostrap', + handler: resources.version.add +}) diff --git a/src/ipfs-core/config.js b/src/ipfs-core/config.js index 5a29168d0b..6f4b6ed266 100644 --- a/src/ipfs-core/config.js +++ b/src/ipfs-core/config.js @@ -4,4 +4,6 @@ const os = require('os') exports = module.exports -exports.repoPath = process.env.IPFS_PATH || os.homedir() + '/.ipfs' +exports.repoPath = function () { + return process.env.IPFS_PATH || os.homedir() + '/.ipfs' +} diff --git a/src/ipfs-core/index.js b/src/ipfs-core/index.js index 6f4da49bc6..697854894e 100644 --- a/src/ipfs-core/index.js +++ b/src/ipfs-core/index.js @@ -11,7 +11,7 @@ function IPFS () { throw new Error('Must be instantiated with new') } - var repo = new IPFSRepo(config.repoPath) + var repo = new IPFSRepo(config.repoPath()) this.daemon = callback => { // 1. read repo to get peer data @@ -76,4 +76,38 @@ function IPFS () { gc: function () {} } + + this.bootstrap = { + list: (callback) => { + repo.config.get((err, config) => { + if (err) { return callback(err) } + callback(null, config.Bootstrap) + }) + }, + add: (multiaddr, callback) => { + repo.config.get((err, config) => { + if (err) { return callback(err) } + config.Bootstrap.push(multiaddr) + repo.config.set(config, err => { + if (err) { return callback(err) } + + callback() + }) + }) + }, + rm: (multiaddr, callback) => { + repo.config.get((err, config) => { + if (err) { return callback(err) } + config.Bootstrap = config.Bootstrap.filter(mh => { + if (mh === multiaddr) { + return false + } else { return true } + }) + repo.config.set(config, err => { + if (err) { return callback(err) } + callback() + }) + }) + } + } } diff --git a/tests/repo-example/config b/tests/repo-example/config index 5811699b32..cbcdfe3b6e 100644 --- a/tests/repo-example/config +++ b/tests/repo-example/config @@ -1,88 +1 @@ -{ - "Identity": { - "PeerID": "QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A", - "PrivKey": "CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAECggEAZtju/bcKvKFPz0mkHiaJcpycy9STKphorpCT83srBVQi59CdFU6Mj+aL/xt0kCPMVigJw8P3/YCEJ9J+rS8BsoWE+xWUEsJvtXoT7vzPHaAtM3ci1HZd302Mz1+GgS8Epdx+7F5p80XAFLDUnELzOzKftvWGZmWfSeDnslwVONkL/1VAzwKy7Ce6hk4SxRE7l2NE2OklSHOzCGU1f78ZzVYKSnS5Ag9YrGjOAmTOXDbKNKN/qIorAQ1bovzGoCwx3iGIatQKFOxyVCyO1PsJYT7JO+kZbhBWRRE+L7l+ppPER9bdLFxs1t5CrKc078h+wuUr05S1P1JjXk68pk3+kQKBgQDeK8AR11373Mzib6uzpjGzgNRMzdYNuExWjxyxAzz53NAR7zrPHvXvfIqjDScLJ4NcRO2TddhXAfZoOPVH5k4PJHKLBPKuXZpWlookCAyENY7+Pd55S8r+a+MusrMagYNljb5WbVTgN8cgdpim9lbbIFlpN6SZaVjLQL3J8TWH6wKBgQDSChzItkqWX11CNstJ9zJyUE20I7LrpyBJNgG1gtvz3ZMUQCn3PxxHtQzN9n1P0mSSYs+jBKPuoSyYLt1wwe10/lpgL4rkKWU3/m1Myt0tveJ9WcqHh6tzcAbb/fXpUFT/o4SWDimWkPkuCb+8j//2yiXk0a/T2f36zKMuZvujqQKBgC6B7BAQDG2H2B/ijofp12ejJU36nL98gAZyqOfpLJ+FeMz4TlBDQ+phIMhnHXA5UkdDapQ+zA3SrFk+6yGk9Vw4Hf46B+82SvOrSbmnMa+PYqKYIvUzR4gg34rL/7AhwnbEyD5hXq4dHwMNsIDq+l2elPjwm/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/4001", - "/ip6/::/tcp/4001" - ], - "API": "/ip4/127.0.0.1/tcp/5001", - "Gateway": "/ip4/127.0.0.1/tcp/8080" - }, - "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/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAECggEAZtju/bcKvKFPz0mkHiaJcpycy9STKphorpCT83srBVQi59CdFU6Mj+aL/xt0kCPMVigJw8P3/YCEJ9J+rS8BsoWE+xWUEsJvtXoT7vzPHaAtM3ci1HZd302Mz1+GgS8Epdx+7F5p80XAFLDUnELzOzKftvWGZmWfSeDnslwVONkL/1VAzwKy7Ce6hk4SxRE7l2NE2OklSHOzCGU1f78ZzVYKSnS5Ag9YrGjOAmTOXDbKNKN/qIorAQ1bovzGoCwx3iGIatQKFOxyVCyO1PsJYT7JO+kZbhBWRRE+L7l+ppPER9bdLFxs1t5CrKc078h+wuUr05S1P1JjXk68pk3+kQKBgQDeK8AR11373Mzib6uzpjGzgNRMzdYNuExWjxyxAzz53NAR7zrPHvXvfIqjDScLJ4NcRO2TddhXAfZoOPVH5k4PJHKLBPKuXZpWlookCAyENY7+Pd55S8r+a+MusrMagYNljb5WbVTgN8cgdpim9lbbIFlpN6SZaVjLQL3J8TWH6wKBgQDSChzItkqWX11CNstJ9zJyUE20I7LrpyBJNgG1gtvz3ZMUQCn3PxxHtQzN9n1P0mSSYs+jBKPuoSyYLt1wwe10/lpgL4rkKWU3/m1Myt0tveJ9WcqHh6tzcAbb/fXpUFT/o4SWDimWkPkuCb+8j//2yiXk0a/T2f36zKMuZvujqQKBgC6B7BAQDG2H2B/ijofp12ejJU36nL98gAZyqOfpLJ+FeMz4TlBDQ+phIMhnHXA5UkdDapQ+zA3SrFk+6yGk9Vw4Hf46B+82SvOrSbmnMa+PYqKYIvUzR4gg34rL/7AhwnbEyD5hXq4dHwMNsIDq+l2elPjwm/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/4001","/ip6/::/tcp/4001"],"API":"/ip4/127.0.0.1/tcp/5001","Gateway":"/ip4/127.0.0.1/tcp/8080"},"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 diff --git a/tests/test-api/index.js b/tests/test-api/index.js index 42860fbd8f..50ddc4d406 100644 --- a/tests/test-api/index.js +++ b/tests/test-api/index.js @@ -4,21 +4,32 @@ const fs = require('fs') const expect = require('chai').expect -process.env.IPFS_PATH = process.cwd() + '/tests/repo-example' const api = require('../../src/http-api') +const ncp = require('ncp').ncp +const rimraf = require('rimraf') describe('api', () => { + const repoExample = process.cwd() + '/tests/repo-example' + const repoTests = process.cwd() + '/tests/repo-tests' + Date.now() + process.env.IPFS_PATH = repoTests + before(done => { - api.start(err => { + ncp(repoExample, repoTests, err => { expect(err).to.not.exist - done() + api.start(err => { + expect(err).to.not.exist + done() + }) }) }) after(done => { api.stop((err) => { expect(err).to.not.exist - done() + rimraf(repoTests, err => { + expect(err).to.not.exist + done() + }) }) }) diff --git a/tests/test-api/test-version.js b/tests/test-api/test-version.js index d04f6251f1..7c26451e1d 100644 --- a/tests/test-api/test-version.js +++ b/tests/test-api/test-version.js @@ -1,4 +1,5 @@ /* globals describe, it */ + 'use strict' const expect = require('chai').expect diff --git a/tests/test-cli-offline/index.js b/tests/test-cli-offline/index.js index f857c6c7c1..b240ee2327 100644 --- a/tests/test-cli-offline/index.js +++ b/tests/test-cli-offline/index.js @@ -1,11 +1,32 @@ -/* globals describe */ +/* globals describe, before, after */ 'use strict' -var fs = require('fs') +const fs = require('fs') +const ncp = require('ncp').ncp +const rimraf = require('rimraf') +const expect = require('chai').expect describe('cli-offline', () => { - var tests = fs.readdirSync(__dirname) + const repoExample = process.cwd() + '/tests/repo-example' + const repoTests = process.cwd() + '/tests/repo-tests' + Date.now() + + before(done => { + ncp(repoExample, repoTests, err => { + process.env.IPFS_PATH = repoTests + expect(err).to.equal(null) + done() + }) + }) + + after(done => { + rimraf(repoTests, err => { + expect(err).to.equal(null) + done() + }) + }) + + const tests = fs.readdirSync(__dirname) tests.filter(file => { if (file === 'index.js') { return false diff --git a/tests/test-cli-offline/test-bootstrap.js b/tests/test-cli-offline/test-bootstrap.js new file mode 100644 index 0000000000..f23dca6245 --- /dev/null +++ b/tests/test-cli-offline/test-bootstrap.js @@ -0,0 +1,75 @@ +/* globals describe, it */ + +'use strict' + +const expect = require('chai').expect +const nexpect = require('nexpect') + +describe('bootstrap', () => { + const defaultList = [ + '/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' + ] + + const updatedList = [ + '/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', + '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT' + ] + + it('list the bootstrap nodes', done => { + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list']) + .run((err, stdout, exitcode) => { + expect(stdout).to.deep.equal(defaultList) + expect(err).to.not.exist + expect(exitcode).to.equal(0) + done() + }) + }) + + it('add another bootstrap node', done => { + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'add', '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT']) + .run((err, stdout, exitcode) => { + expect(err).to.not.exist + expect(exitcode).to.equal(0) + + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list']) + .run((err, stdout, exitcode) => { + expect(stdout).to.deep.equal(updatedList) + expect(err).to.not.exist + expect(exitcode).to.equal(0) + done() + }) + }) + }) + + it('rm a bootstrap node', done => { + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'rm', '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT']) + .run((err, stdout, exitcode) => { + expect(err).to.not.exist + expect(exitcode).to.equal(0) + + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list']) + .run((err, stdout, exitcode) => { + expect(stdout).to.deep.equal(defaultList) + expect(err).to.not.exist + expect(exitcode).to.equal(0) + done() + }) + }) + }) +}) diff --git a/tests/test-cli/index.js b/tests/test-cli/index.js index b5bdd7df1b..2e8c768446 100644 --- a/tests/test-cli/index.js +++ b/tests/test-cli/index.js @@ -1,11 +1,32 @@ -/* globals describe */ +/* globals describe, before, after */ 'use strict' -var fs = require('fs') +const fs = require('fs') +const ncp = require('ncp').ncp +const rimraf = require('rimraf') +const expect = require('chai').expect describe('cli', () => { - var tests = fs.readdirSync(__dirname) + const repoExample = process.cwd() + '/tests/repo-example' + const repoTests = process.cwd() + '/tests/repo-tests' + Date.now() + + before(done => { + ncp(repoExample, repoTests, err => { + process.env.IPFS_PATH = repoTests + expect(err).to.equal(null) + done() + }) + }) + + after(done => { + rimraf(repoTests, err => { + expect(err).to.equal(null) + done() + }) + }) + + const tests = fs.readdirSync(__dirname) tests.filter(file => { if (file === 'index.js') { return false diff --git a/tests/test-core/index.js b/tests/test-core/index.js index 225b770f39..1ffbe277df 100644 --- a/tests/test-core/index.js +++ b/tests/test-core/index.js @@ -1,11 +1,32 @@ -/* globals describe */ +/* globals describe, before, after */ 'use strict' -var fs = require('fs') +const fs = require('fs') +const ncp = require('ncp').ncp +const rimraf = require('rimraf') +const expect = require('chai').expect describe('core', () => { - var tests = fs.readdirSync(__dirname) + const repoExample = process.cwd() + '/tests/repo-example' + const repoTests = process.cwd() + '/tests/repo-tests' + Date.now() + + before(done => { + ncp(repoExample, repoTests, err => { + process.env.IPFS_PATH = repoTests + expect(err).to.equal(null) + done() + }) + }) + + after(done => { + rimraf(repoTests, err => { + expect(err).to.equal(null) + done() + }) + }) + + const tests = fs.readdirSync(__dirname) tests.filter(file => { if (file === 'index.js') { return false diff --git a/tests/test-core/test-bootstrap.js b/tests/test-core/test-bootstrap.js new file mode 100644 index 0000000000..9566401b15 --- /dev/null +++ b/tests/test-core/test-bootstrap.js @@ -0,0 +1,67 @@ +/* globals describe, it */ + +'use strict' + +const expect = require('chai').expect + +process.env.IPFS_PATH = process.cwd() + '/tests/repo-example' +const IPFS = require('../../src/ipfs-core') + +describe('bootstrap', () => { + const ipfs = new IPFS() + + const defaultList = [ + '/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' + ] + + const updatedList = [ + '/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', + '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT' + ] + + it('get bootstrap list', done => { + ipfs.bootstrap.list((err, list) => { + expect(err).to.not.exist + expect(list).to.deep.equal(defaultList) + done() + }) + }) + + it('add a peer to the bootstrap list', done => { + ipfs.bootstrap.add('/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT', err => { + expect(err).to.not.exist + ipfs.bootstrap.list((err, list) => { + expect(err).to.not.exist + expect(list).to.deep.equal(updatedList) + done() + }) + }) + }) + + it('remove a peer from the bootstrap list', done => { + ipfs.bootstrap.rm('/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT', err => { + expect(err).to.not.exist + ipfs.bootstrap.list((err, list) => { + expect(err).to.not.exist + expect(list).to.deep.equal(defaultList) + done() + }) + }) + }) +})