diff --git a/package.json b/package.json index e2c79bd52e..b0a4c65a90 100644 --- a/package.json +++ b/package.json @@ -204,7 +204,7 @@ "execa": "^2.0.4", "form-data": "^2.5.1", "hat": "0.0.3", - "interface-ipfs-core": "^0.115.0", + "interface-ipfs-core": "^0.115.1", "ipfs-interop": "~0.1.0", "ipfsd-ctl": "^0.47.2", "libp2p-websocket-star": "~0.10.2", diff --git a/test/cli/bitswap.js b/test/cli/bitswap.js index 24bc6371fb..cac76152b3 100644 --- a/test/cli/bitswap.js +++ b/test/cli/bitswap.js @@ -30,69 +30,65 @@ describe('bitswap', () => runOn((thing) => { }) }) - before(function (done) { - const test = (cb) => { - ipfs('bitswap wantlist') - .then(out => cb(null, out.includes(key0) && out.includes(key1))) - .catch(cb) + before(async () => { + const test = async () => { + const out = await ipfs('bitswap wantlist') + + return out.includes(key0) && out.includes(key1) } - waitFor(test, { + await waitFor(test, { name: `${key0} and ${key1} to be wanted`, timeout: 60 * 1000 - }, done) + }) }) - it('wantlist', function () { - return ipfs('bitswap wantlist').then((out) => { - expect(out).to.include(key0) - expect(out).to.include(key1) - }) + it('wantlist', async function () { + const out = await ipfs('bitswap wantlist') + expect(out).to.include(key0) + expect(out).to.include(key1) }) - it('should get wantlist with CIDs encoded in specified base', function () { + it('should get wantlist with CIDs encoded in specified base', async function () { this.timeout(20 * 1000) - return ipfs('bitswap wantlist --cid-base=base64').then((out) => { - expect(out).to.include(new CID(key1).toBaseEncodedString('base64') + '\n') - }) + + const out = await ipfs('bitswap wantlist --cid-base=base64') + expect(out).to.include(new CID(key1).toBaseEncodedString('base64') + '\n') }) - it('wantlist peerid', function () { + it('wantlist peerid', async function () { this.timeout(20 * 1000) - return ipfs('bitswap wantlist ' + peerId).then((out) => { - expect(out).to.eql('') - }) + + const out = await ipfs('bitswap wantlist ' + peerId) + expect(out).to.eql('') }) - it('stat', function () { + it('stat', async function () { this.timeout(20 * 1000) - return ipfs('bitswap stat').then((out) => { - expect(out).to.include([ - 'bitswap status', - ' blocks received: 0', - ' dup blocks received: 0', - ' dup data received: 0B', - // We sometimes pick up partners while the tests run and the order of - // wanted keys is not defined so our assertion ends here. - ' wantlist [2 keys]' - ].join('\n')) - - expect(out).to.include(key0) - expect(out).to.include(key1) - }) + const out = await ipfs('bitswap stat') + expect(out).to.include([ + 'bitswap status', + ' blocks received: 0', + ' dup blocks received: 0', + ' dup data received: 0B', + // We sometimes pick up partners while the tests run and the order of + // wanted keys is not defined so our assertion ends here. + ' wantlist [2 keys]' + ].join('\n')) + expect(out).to.include(key0) + expect(out).to.include(key1) }) - it('should get stats with wantlist CIDs encoded in specified base', function () { + it('should get stats with wantlist CIDs encoded in specified base', async function () { this.timeout(20 * 1000) - return ipfs('bitswap stat --cid-base=base64').then((out) => { - expect(out).to.include(new CID(key1).toBaseEncodedString('base64')) - }) + + const out = await ipfs('bitswap stat --cid-base=base64') + expect(out).to.include(new CID(key1).toBaseEncodedString('base64')) }) - it('unwant', function () { - return ipfs('bitswap unwant ' + key0).then((out) => { - expect(out).to.eql(`Key ${key0} removed from wantlist\n`) - }) + it('unwant', async function () { + const out = await ipfs('bitswap unwant ' + key0) + expect(out).to.eql(`Key ${key0} removed from wantlist\n`) }) })) diff --git a/test/cli/block.js b/test/cli/block.js index 8de1be03f3..c00e06caf7 100644 --- a/test/cli/block.js +++ b/test/cli/block.js @@ -11,82 +11,71 @@ describe('block', () => runOnAndOff((thing) => { ipfs = thing.ipfs }) - it('put', function () { + it('put', async function () { this.timeout(40 * 1000) - return ipfs('block put test/fixtures/test-data/hello').then((out) => { - expect(out).to.eql('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n') - }) + + const out = await ipfs('block put test/fixtures/test-data/hello') + expect(out).to.eql('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n') }) - it('put with flags, format and mhtype', function () { + it('put with flags, format and mhtype', async function () { this.timeout(40 * 1000) - return ipfs('block put --format eth-block --mhtype keccak-256 test/fixtures/test-data/eth-block') - .then((out) => - expect(out).to.eql('bagiacgzarkhijr4xmbp345ovwwxra7kcecrnwcwtl7lg3g7d2ogyprdswjwq\n')) + const out = await ipfs('block put --format eth-block --mhtype keccak-256 test/fixtures/test-data/eth-block') + expect(out).to.eql('bagiacgzarkhijr4xmbp345ovwwxra7kcecrnwcwtl7lg3g7d2ogyprdswjwq\n') }) - it('should put and print CID encoded in specified base', function () { + it('should put and print CID encoded in specified base', async function () { this.timeout(40 * 1000) - return ipfs('block put test/fixtures/test-data/hello --cid-base=base64').then((out) => { - expect(out).to.eql('mAXASIKlIkE8vD0ebj4GXaUswGEsNLtHBzSoewPuF0pmhkqRH\n') - }) + const out = await ipfs('block put test/fixtures/test-data/hello --cid-base=base64') + expect(out).to.eql('mAXASIKlIkE8vD0ebj4GXaUswGEsNLtHBzSoewPuF0pmhkqRH\n') }) - it('get', function () { + it('get', async function () { this.timeout(40 * 1000) - return ipfs('block get QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') - .then((out) => expect(out).to.eql('hello world\n')) + const out = await ipfs('block get QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') + expect(out).to.eql('hello world\n') }) - it('get block from file without a final newline', function () { + it('get block from file without a final newline', async function () { this.timeout(40 * 1000) - return ipfs('block put test/fixtures/test-data/no-newline').then((out) => { - expect(out).to.eql('QmTwbQs4sGcCiPxV97SpbHS7QgmVg9SiKxcG1AcF1Ly2SL\n') - return ipfs('block get QmTwbQs4sGcCiPxV97SpbHS7QgmVg9SiKxcG1AcF1Ly2SL') - }) - .then((out) => expect(out).to.eql('there is no newline at end of this file')) + const out = await ipfs('block put test/fixtures/test-data/no-newline') + expect(out).to.eql('QmTwbQs4sGcCiPxV97SpbHS7QgmVg9SiKxcG1AcF1Ly2SL\n') + + const out2 = await ipfs('block get QmTwbQs4sGcCiPxV97SpbHS7QgmVg9SiKxcG1AcF1Ly2SL') + expect(out2).to.eql('there is no newline at end of this file') }) - it('stat', function () { + it('stat', async function () { this.timeout(40 * 1000) - return ipfs('block stat QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') - .then((out) => { - expect(out).to.eql([ - 'Key: QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', - 'Size: 12' - ].join('\n') + '\n') - }) + const out = await ipfs('block stat QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') + expect(out).to.eql([ + 'Key: QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', + 'Size: 12' + ].join('\n') + '\n') }) - it('should stat and print CID encoded in specified base', function () { + it('should stat and print CID encoded in specified base', async function () { this.timeout(80 * 1000) - return ipfs('block put test/fixtures/test-data/hello') - .then((out) => { - expect(out).to.eql('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n') - return ipfs('block stat QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp --cid-base=base64') - }) - .then((out) => { - expect(out).to.eql([ - 'Key: mAXASIKlIkE8vD0ebj4GXaUswGEsNLtHBzSoewPuF0pmhkqRH', - 'Size: 12' - ].join('\n') + '\n') - }) + const out = await ipfs('block put test/fixtures/test-data/hello') + expect(out).to.eql('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n') + + const out2 = await ipfs('block stat QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp --cid-base=base64') + expect(out2).to.eql([ + 'Key: mAXASIKlIkE8vD0ebj4GXaUswGEsNLtHBzSoewPuF0pmhkqRH', + 'Size: 12' + ].join('\n') + '\n') }) - it.skip('rm', function () { + it.skip('rm', async function () { this.timeout(40 * 1000) - return ipfs('block rm QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') - .then((out) => { - expect(out).to.eql( - 'removed QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n' - ) - }) + const out = await ipfs('block rm QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') + expect(out).to.eql('removed QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n') }) })) diff --git a/test/cli/bootstrap.js b/test/cli/bootstrap.js index f71fee2d84..262f80e97e 100644 --- a/test/cli/bootstrap.js +++ b/test/cli/bootstrap.js @@ -57,50 +57,47 @@ describe('bootstrap', () => runOnAndOff((thing) => { '/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD' ] - it('add default', function () { + it('add default', async function () { this.timeout(40 * 1000) - return ipfs('bootstrap add --default').then((out) => { - expect(out).to.equal(defaultList.join('\n') + '\n') - }) + const out = await ipfs('bootstrap add --default') + expect(out).to.equal(defaultList.join('\n') + '\n') }) - it('list the bootstrap nodes', function () { + it('list the bootstrap nodes', async function () { this.timeout(40 * 1000) - return ipfs('bootstrap list').then((out) => { - expect(out).to.equal(defaultList.join('\n') + '\n') - }) + const out = await ipfs('bootstrap list') + expect(out).to.equal(defaultList.join('\n') + '\n') }) - it('add another bootstrap node', function () { + it('add another bootstrap node', async function () { this.timeout(40 * 1000) - return ipfs('bootstrap add /ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD').then((out) => { - expect(out).to.equal('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD\n') - return ipfs('bootstrap list') - }).then((out) => expect(out).to.equal(updatedList.join('\n') + '\n')) + const out = await ipfs('bootstrap add /ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD') + expect(out).to.equal('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD\n') + + const out2 = await ipfs('bootstrap list') + expect(out2).to.equal(updatedList.join('\n') + '\n') }) - it('rm a bootstrap node', function () { + it('rm a bootstrap node', async function () { this.timeout(40 * 1000) - return ipfs('bootstrap rm /ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD').then((out) => { - expect(out).to.equal('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD\n') - return ipfs('bootstrap list') - }).then((out) => { - expect(out).to.equal(defaultList.join('\n') + '\n') - }) + const out = await ipfs('bootstrap rm /ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD') + expect(out).to.equal('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD\n') + + const out2 = await ipfs('bootstrap list') + expect(out2).to.equal(defaultList.join('\n') + '\n') }) - it('rm all bootstrap nodes', function () { + it('rm all bootstrap nodes', async function () { this.timeout(40 * 1000) - return ipfs('bootstrap rm --all').then((out) => { - expect(out).to.equal('') - return ipfs('bootstrap list') - }).then((out) => { - expect(out).to.equal('') - }) + const out = await ipfs('bootstrap rm --all') + expect(out).to.equal('') + + const out2 = await ipfs('bootstrap list') + expect(out2).to.equal('') }) })) diff --git a/test/cli/commands.js b/test/cli/commands.js index 1e193257a6..e445892a72 100644 --- a/test/cli/commands.js +++ b/test/cli/commands.js @@ -13,9 +13,8 @@ describe('commands', () => runOnAndOff((thing) => { ipfs = thing.ipfs }) - it('list the commands', () => { - return ipfs('commands').then((out) => { - expect(out.split('\n')).to.have.length(commandCount + 1) - }) + it('list the commands', async () => { + const out = await ipfs('commands') + expect(out.split('\n')).to.have.length(commandCount + 1) }) })) diff --git a/test/cli/config.js b/test/cli/config.js index f9d1c0458a..0a8158e65e 100644 --- a/test/cli/config.js +++ b/test/cli/config.js @@ -27,70 +27,62 @@ describe('config', () => runOnAndOff((thing) => { describe('get/set', function () { this.timeout(40 * 1000) - it('set a config key with a string value', () => { - return ipfs('config foo bar').then((out) => { - expect(updatedConfig().foo).to.equal('bar') - }) + it('set a config key with a string value', async () => { + await ipfs('config foo bar') + expect(updatedConfig().foo).to.equal('bar') }) - it('set a config key with true', () => { - return ipfs('config foo true --bool').then((out) => { - expect(updatedConfig().foo).to.equal(true) - }) + it('set a config key with true', async () => { + await ipfs('config foo true --bool') + expect(updatedConfig().foo).to.equal(true) }) - it('set a config key with false', () => { - return ipfs('config foo false --bool').then((out) => { - expect(updatedConfig().foo).to.equal(false) - }) + it('set a config key with false', async () => { + await ipfs('config foo false --bool') + expect(updatedConfig().foo).to.equal(false) }) - it('set a config key with null', () => { - return ipfs('config foo null --json').then((out) => { - expect(updatedConfig().foo).to.equal(null) - }) + it('set a config key with null', async () => { + await ipfs('config foo null --json') + expect(updatedConfig().foo).to.equal(null) }) - it('set a config key with json', () => { - return ipfs('config foo {"bar":0} --json').then((out) => { - expect(updatedConfig().foo).to.deep.equal({ bar: 0 }) - }) + it('set a config key with json', async () => { + await ipfs('config foo {"bar":0} --json') + expect(updatedConfig().foo).to.deep.equal({ bar: 0 }) }) - it('set a config key with invalid json', () => { - return ipfs.fail('config foo {"bar:0"} --json') + it('set a config key with invalid json', async () => { + await ipfs.fail('config foo {"bar:0"} --json') }) - it('get a config key value', () => { - return ipfs('config Identity.PeerID').then((out) => { - expect(out).to.exist() - }) + it('get a config key value', async () => { + const out = await ipfs('config Identity.PeerID') + expect(out).to.exist() }) - it('call config with no arguments', () => { - return ipfs('config') - .then(out => expect(out).to.include('Not enough non-option arguments: got 0, need at least 1')) + it('call config with no arguments', async () => { + const out = await ipfs('config') + expect(out).to.include('Not enough non-option arguments: got 0, need at least 1') }) }) describe('show', function () { this.timeout(40 * 1000) - it('returns the full config', () => { - return ipfs('config show').then((out) => { - expect(JSON.parse(out)).to.be.eql(updatedConfig()) - }) + it('returns the full config', async () => { + const out = await ipfs('config show') + expect(JSON.parse(out)).to.be.eql(updatedConfig()) }) }) describe.skip('replace', () => { - it('replace config with file', () => { + it('replace config with file', async () => { const filePath = 'test/fixtures/test-data/otherconfig' const expectedConfig = JSON.parse(fs.readFileSync(filePath, 'utf8')) - return ipfs(`config replace ${filePath}`).then((out) => { - expect(updatedConfig()).to.be.eql(expectedConfig) - }) + await ipfs(`config replace ${filePath}`) + expect(updatedConfig()).to.be.eql(expectedConfig) }) after(() => { diff --git a/test/cli/daemon.js b/test/cli/daemon.js index 5f222ceaeb..1be77940d6 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -13,17 +13,11 @@ const tempWrite = require('temp-write') const pkg = require('../../package.json') const skipOnWindows = isWindows() ? it.skip : it -const daemonReady = (daemon, cb) => { - let r = null - const p = new Promise((resolve, reject) => { - daemon.stdout.on('data', async (data) => { +const daemonReady = (daemon) => { + return new Promise((resolve, reject) => { + daemon.stdout.on('data', (data) => { if (data.toString().includes('Daemon is ready')) { - try { - r = await cb() - } catch (err) { - reject(err) - } - daemon.cancel() + resolve() } }) daemon.stderr.on('data', (data) => { @@ -33,16 +27,7 @@ const daemonReady = (daemon, cb) => { reject(new Error('Daemon didn\'t start ' + data.toString('utf8'))) } }) - daemon.then(() => resolve(r)).catch(err => { - if (r && err.killed) { - return resolve(r) - } - - reject(err) - }) }) - - return p } const checkLock = (repo) => { // skip on windows @@ -320,7 +305,8 @@ describe('daemon', () => { const configPath = tempWrite.sync('{"Addresses": {"API": "/ip4/127.0.0.1/tcp/9999"}}', 'config.json') const daemon = ipfs(`daemon --init-config ${configPath}`) - const r = await daemonReady(daemon, () => ipfs('config \'Addresses.API\'')) - expect(r).to.be.eq('/ip4/127.0.0.1/tcp/9999\n') + await daemonReady(daemon) + const out = await ipfs('config \'Addresses.API\'') + expect(out).to.be.eq('/ip4/127.0.0.1/tcp/9999\n') }) }) diff --git a/test/cli/dag.js b/test/cli/dag.js index fc13380dc6..f4094777eb 100644 --- a/test/cli/dag.js +++ b/test/cli/dag.js @@ -12,17 +12,16 @@ describe('dag', () => runOnAndOff.off((thing) => { ipfs = thing.ipfs }) - it('get', function () { + it('get', async function () { this.timeout(20 * 1000) // put test eth-block - return ipfs(`block put --format eth-block --mhtype keccak-256 ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/eth-block`).then((out) => { - expect(out).to.eql('bagiacgzarkhijr4xmbp345ovwwxra7kcecrnwcwtl7lg3g7d2ogyprdswjwq\n') - // lookup path on eth-block - return ipfs('dag get bagiacgzarkhijr4xmbp345ovwwxra7kcecrnwcwtl7lg3g7d2ogyprdswjwq/parentHash') - }).then((out) => { - const expectHash = Buffer.from('c8c0a17305adea9bbb4b98a52d44f0c1478f5c48fc4b64739ee805242501b256', 'hex') - expect(out).to.be.eql('0x' + expectHash.toString('hex') + '\n') - }) + const out = await ipfs(`block put --format eth-block --mhtype keccak-256 ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/eth-block`) + expect(out).to.eql('bagiacgzarkhijr4xmbp345ovwwxra7kcecrnwcwtl7lg3g7d2ogyprdswjwq\n') + + // lookup path on eth-block + const out2 = await ipfs('dag get bagiacgzarkhijr4xmbp345ovwwxra7kcecrnwcwtl7lg3g7d2ogyprdswjwq/parentHash') + const expectHash = Buffer.from('c8c0a17305adea9bbb4b98a52d44f0c1478f5c48fc4b64739ee805242501b256', 'hex') + expect(out2).to.be.eql('0x' + expectHash.toString('hex') + '\n') }) })) diff --git a/test/cli/dht.js b/test/cli/dht.js index b4655bb6d4..3e066ac270 100644 --- a/test/cli/dht.js +++ b/test/cli/dht.js @@ -7,7 +7,6 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const parallel = require('async/parallel') const path = require('path') const DaemonFactory = require('ipfsd-ctl') const df = DaemonFactory.create({ @@ -56,91 +55,66 @@ describe.skip('dht', () => { }) // get ids - before(function (done) { + before(async function () { this.timeout(80 * 1000) - parallel([ - (cb) => nodes[0].api.id((err, res) => { - expect(err).to.not.exist() - - idA = res.id - cb() - }), - (cb) => nodes[1].api.id((err, res) => { - expect(err).to.not.exist() - - multiaddrB = res.addresses[0] - idB = res.id - cb() - }) - ], done) + + const res = await Promise.all([ + nodes[0].api.id(), + nodes[1].api.id() + ]) + + idA = res[0].id + idB = res[1].id + multiaddrB = res[1].addresses[0] }) // connect daemons - before(function (done) { + before(function () { this.timeout(80 * 1000) - nodes[0].api.swarm.connect(multiaddrB, done) + return nodes[0].api.swarm.connect(multiaddrB) }) after(() => Promise.all(nodes.map((node) => node.stop()))) - it('should be able to put a value to the dht and get it afterwards', function () { + it('should be able to put a value to the dht and get it afterwards', async function () { this.timeout(60 * 1000) const key = 'testkey' const value = 'testvalue' - return ipfsA(`dht put ${key} ${value}`) - .then((res) => { - expect(res).to.exist() + const res = await ipfsA(`dht put ${key} ${value}`) + expect(res).to.exist() - return ipfsB(`dht get ${key}`) - }) - .then((res) => { - expect(res).to.exist() - expect(res).to.have.string(value) - }) + const res2 = await ipfsB(`dht get ${key}`) + expect(res2).to.have.string(value) }) - it('should be able to provide data and to be present in the findproviders', function () { + it('should be able to provide data and to be present in the findproviders', async function () { this.timeout(60 * 1000) - let cidAdded - - return ipfsA('add src/init-files/init-docs/readme') - .then((res) => { - expect(res).to.exist() - cidAdded = res.split(' ')[1] - - return ipfsA(`dht provide ${cidAdded}`) - }) - .then((res) => { - expect(res).to.exist() - - return ipfsB(`dht findprovs ${cidAdded}`) - }) - .then((res) => { - expect(res).to.exist() - expect(res).to.have.string(idA) - }) + + const res = await ipfsA('add src/init-files/init-docs/readme') + expect(res).to.exist() + const cidAdded = res.split(' ')[1] + + const res2 = await ipfsA(`dht provide ${cidAdded}`) + expect(res2).to.exist() + + const res3 = await ipfsB(`dht findprovs ${cidAdded}`) + expect(res3).to.have.string(idA) }) - it('findpeer', function () { + it('findpeer', async function () { this.timeout(60 * 1000) - return ipfsA(`dht findpeer ${idB}`) - .then((res) => { - expect(res).to.exist() - expect(res).to.have.string(multiaddrB) - }) + const res = await ipfsA(`dht findpeer ${idB}`) + expect(res).to.have.string(multiaddrB) }) - it('query', function () { + it('query', async function () { this.timeout(60 * 1000) - return ipfsA(`dht query ${idB}`) - .then((res) => { - expect(res).to.exist() - expect(res).to.have.string(idB) - }) + const res = await ipfsA(`dht query ${idB}`) + expect(res).to.have.string(idB) }) }) diff --git a/test/cli/dns.js b/test/cli/dns.js index 2f7a9fab10..93e4610e3b 100644 --- a/test/cli/dns.js +++ b/test/cli/dns.js @@ -13,49 +13,44 @@ describe('dns', () => runOnAndOff((thing) => { ipfs = thing.ipfs }) - it('recursively resolve ipfs.io dns', function () { + it('recursively resolve ipfs.io dns', async function () { this.timeout(60 * 1000) - return ipfs('dns ipfs.io').then((res) => { - expect(res.substr(0, 6)).to.eql('/ipfs/') - const resultingDomainOrCid = res.split('/')[2].trim() - expect(isIPFS.cid(resultingDomainOrCid)).to.eql(true) - }) + const res = await ipfs('dns ipfs.io') + expect(res.substr(0, 6)).to.eql('/ipfs/') + const resultingDomainOrCid = res.split('/')[2].trim() + expect(isIPFS.cid(resultingDomainOrCid)).to.eql(true) }) - it('recursively resolve _dnslink.ipfs.io dns', function () { + it('recursively resolve _dnslink.ipfs.io dns', async function () { this.timeout(60 * 1000) - return ipfs('dns _dnslink.ipfs.io').then((res) => { - expect(res.substr(0, 6)).to.eql('/ipfs/') - const resultingDomainOrCid = res.split('/')[2].trim() - expect(isIPFS.cid(resultingDomainOrCid)).to.eql(true) - }) + const res = await ipfs('dns _dnslink.ipfs.io') + expect(res.substr(0, 6)).to.eql('/ipfs/') + const resultingDomainOrCid = res.split('/')[2].trim() + expect(isIPFS.cid(resultingDomainOrCid)).to.eql(true) }) - it('non-recursive resolve ipfs.io', function () { + it('non-recursive resolve ipfs.io', async function () { this.timeout(60 * 1000) - return ipfs('dns --recursive false ipfs.io').then((res) => { - expect(res.substr(0, 6)).to.eql('/ipns/') - const resultingDomainOrCid = res.split('/')[2].trim() - expect(isIPFS.cid(resultingDomainOrCid)).to.eql(false) - }) + const res = await ipfs('dns --recursive false ipfs.io') + expect(res.substr(0, 6)).to.eql('/ipns/') + const resultingDomainOrCid = res.split('/')[2].trim() + expect(isIPFS.cid(resultingDomainOrCid)).to.eql(false) }) - it('resolve subdomain docs.ipfs.io dns', function () { + it('resolve subdomain docs.ipfs.io dns', async function () { this.timeout(60 * 1000) - return ipfs('dns docs.ipfs.io').then(res => { - expect(res.substr(0, 6)).to.eql('/ipfs/') - }) + const res = await ipfs('dns docs.ipfs.io') + expect(res.substr(0, 6)).to.eql('/ipfs/') }) - it('resolve subdomain _dnslink.docs.ipfs.io dns', function () { + it('resolve subdomain _dnslink.docs.ipfs.io dns', async function () { this.timeout(60 * 1000) - return ipfs('dns _dnslink.docs.ipfs.io').then(res => { - expect(res.substr(0, 6)).to.eql('/ipfs/') - }) + const res = await ipfs('dns _dnslink.docs.ipfs.io') + expect(res.substr(0, 6)).to.eql('/ipfs/') }) })) diff --git a/test/cli/file.js b/test/cli/file.js index 261c4c0777..f7852c89ef 100644 --- a/test/cli/file.js +++ b/test/cli/file.js @@ -9,29 +9,30 @@ const dir = 'Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z' describe('file ls', () => runOnAndOff((thing) => { let ipfs - before(function () { + before(async function () { this.timeout(50 * 1000) ipfs = thing.ipfs - return ipfs('add -r test/fixtures/test-data/recursive-get-dir') + await ipfs('add -r test/fixtures/test-data/recursive-get-dir') }) - it('prints a filename', () => { - return ipfs(`file ls ${file}`) - .then((out) => expect(out).to.eql( - 'This functionality is deprecated, and will be removed in future versions. If possible, please use \'ipfs ls\' instead.\n' + - `${file}\n` - )) + it('prints a filename', async () => { + const out = await ipfs(`file ls ${file}`) + + expect(out).to.eql( + 'This functionality is deprecated, and will be removed in future versions. If possible, please use \'ipfs ls\' instead.\n' + + `${file}\n` + ) }) - it('prints the filenames in a directory', () => { - return ipfs(`file ls ${dir}`) - .then((out) => expect(out).to.eql( - 'This functionality is deprecated, and will be removed in future versions. If possible, please use \'ipfs ls\' instead.\n' + - 'QmamKEPmEH9RUsqRQsfNf5evZQDQPYL9KXg1ADeT7mkHkT\n' + - 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN\n' + - 'QmUqyZtPmsRy1U5Mo8kz2BAMmk1hfJ7yW1KAFTMB2odsFv\n' + - 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU\n' + - 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV\n' - )) + it('prints the filenames in a directory', async () => { + const out = await ipfs(`file ls ${dir}`) + expect(out).to.eql( + 'This functionality is deprecated, and will be removed in future versions. If possible, please use \'ipfs ls\' instead.\n' + + 'QmamKEPmEH9RUsqRQsfNf5evZQDQPYL9KXg1ADeT7mkHkT\n' + + 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN\n' + + 'QmUqyZtPmsRy1U5Mo8kz2BAMmk1hfJ7yW1KAFTMB2odsFv\n' + + 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU\n' + + 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV\n' + ) }) })) diff --git a/test/cli/files.js b/test/cli/files.js index 473ca81f61..62c3139b0c 100644 --- a/test/cli/files.js +++ b/test/cli/files.js @@ -12,6 +12,7 @@ const CID = require('cids') const mh = require('multihashes') const runOnAndOff = require('../utils/on-and-off') const clean = require('../utils/clean') +const delay = require('delay') // TODO: Test against all algorithms Object.keys(mh.names) // This subset is known to work with both go-ipfs and js-ipfs as of 2017-09-05 @@ -123,73 +124,55 @@ describe('files', () => runOnAndOff((thing) => { ipfs = thing.ipfs }) - it('add with progress', function () { + it('add with progress', async function () { this.timeout(30 * 1000) - return ipfs('add -p src/init-files/init-docs/readme') - .then((out) => { - expect(out) - .to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme\n') - }) + const out = await ipfs('add -p src/init-files/init-docs/readme') + expect(out) + .to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme\n') }) - it('add', function () { + it('add', async function () { this.timeout(30 * 1000) - return ipfs('add src/init-files/init-docs/readme') - .then((out) => { - expect(out) - .to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme\n') - }) + const out = await ipfs('add src/init-files/init-docs/readme') + expect(out) + .to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme\n') }) - it('add multiple', function () { + it('add multiple', async function () { this.timeout(30 * 1000) - return ipfs('add', 'src/init-files/init-docs/readme', 'test/fixtures/odd-name-[v0]/odd name [v1]/hello', '--wrap-with-directory') - .then((out) => { - expect(out) - .to.include('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme\n') - expect(out) - .to.include('added QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o hello\n') - }) + const out = await ipfs('add', 'src/init-files/init-docs/readme', 'test/fixtures/odd-name-[v0]/odd name [v1]/hello', '--wrap-with-directory') + expect(out) + .to.include('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme\n') + expect(out) + .to.include('added QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o hello\n') }) - it('add alias', function () { + it('add alias', async function () { this.timeout(30 * 1000) - return ipfs('add src/init-files/init-docs/readme') - .then((out) => { - expect(out) - .to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme\n') - }) + const out = await ipfs('add src/init-files/init-docs/readme') + expect(out) + .to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme\n') }) - it('add recursively test', function () { + it('add recursively test', async function () { this.timeout(60 * 1000) - return ipfs('add -r test/fixtures/test-data/recursive-get-dir') - .then((out) => { - // glob module does not return stable matches - recursiveGetDirResults.forEach(line => { // eslint-disable-line max-nested-callbacks - expect(out).to.include(line) - }) - }) + const out = await ipfs('add -r test/fixtures/test-data/recursive-get-dir') + expect(out).to.equal(recursiveGetDirResults.join('\n') + '\n') }) - it('add directory with trailing slash test', function () { + it('add directory with trailing slash test', async function () { this.timeout(30 * 1000) - return ipfs('add -r test/fixtures/test-data/recursive-get-dir/') - .then((out) => { - // glob module does not return stable matches - recursiveGetDirResults.forEach(line => { // eslint-disable-line max-nested-callbacks - expect(out).to.include(line) - }) - }) + const out = await ipfs('add -r test/fixtures/test-data/recursive-get-dir/') + expect(out).to.equal(recursiveGetDirResults.join('\n') + '\n') }) - it('add directory with odd name', function () { + it('add directory with odd name', async function () { this.timeout(30 * 1000) const expected = [ 'added QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o odd-name-[v0]/odd name [v1]/hello', @@ -197,308 +180,258 @@ describe('files', () => runOnAndOff((thing) => { 'added QmXJGoo27bg7ExNAtr9vRcivxDwcfHtkxatGno9HrUdR16 odd-name-[v0]' ] - return ipfs('add -r test/fixtures/odd-name-[v0]') - .then((out) => { - expect(out).to.eql(expected.join('\n') + '\n') - }) + const out = await ipfs('add -r test/fixtures/odd-name-[v0]') + expect(out).to.eql(expected.join('\n') + '\n') }) - it('add and wrap with a directory', function () { + it('add and wrap with a directory', async function () { this.timeout(30 * 1000) - return ipfs('add -w src/init-files/init-docs/readme').then((out) => { - expect(out).to.be.eql([ - 'added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme', - 'added QmapdaVPjHXdcswef82FnGQUauMNpk9xYFkLDZKgAxhMwq' - ].join('\n') + '\n') - }) + const out = await ipfs('add -w src/init-files/init-docs/readme') + expect(out).to.be.eql([ + 'added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme', + 'added QmapdaVPjHXdcswef82FnGQUauMNpk9xYFkLDZKgAxhMwq' + ].join('\n') + '\n') }) - it('add with cid-version=0', function () { + it('add with cid-version=0', async function () { this.timeout(30 * 1000) - return ipfs('add src/init-files/init-docs/readme --cid-version=0').then((out) => { - expect(out) - .to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme\n') - }) + const out = await ipfs('add src/init-files/init-docs/readme --cid-version=0') + expect(out) + .to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme\n') }) - it('add with cid-version=1 < default max chunk size', function () { + it('add with cid-version=1 < default max chunk size', async function () { this.timeout(30 * 1000) - return ipfs('add test/fixtures/less-than-default-max-chunk-size --cid-version=1') - .then((out) => { - expect(out) - .to.eql('added bafkreie3abdlmy7dtxddm4vkbhd2x2yax5scf4m35eyxf3ywj2uwkjbhgi less-than-default-max-chunk-size\n') - }) + const out = await ipfs('add test/fixtures/less-than-default-max-chunk-size --cid-version=1') + expect(out) + .to.eql('added bafkreie3abdlmy7dtxddm4vkbhd2x2yax5scf4m35eyxf3ywj2uwkjbhgi less-than-default-max-chunk-size\n') }) - it('add with cid-version=1 > default max chunk size', function () { + it('add with cid-version=1 > default max chunk size', async function () { this.timeout(30 * 1000) - return ipfs('add test/fixtures/greater-than-default-max-chunk-size --cid-version=1') - .then((out) => { - expect(out) - .to.eql('added bafybeiebjiahgamnil3r3os2hqorjualrgx6hpqh5zuqbhjmt7tyjqqttm greater-than-default-max-chunk-size\n') - }) + const out = await ipfs('add test/fixtures/greater-than-default-max-chunk-size --cid-version=1') + expect(out) + .to.eql('added bafybeiebjiahgamnil3r3os2hqorjualrgx6hpqh5zuqbhjmt7tyjqqttm greater-than-default-max-chunk-size\n') }) - it('add with cid-version=1 and raw-leaves=false < default max chunk size', function () { + it('add with cid-version=1 and raw-leaves=false < default max chunk size', async function () { this.timeout(30 * 1000) - return ipfs('add test/fixtures/less-than-default-max-chunk-size --cid-version=1 --raw-leaves=false') - .then((out) => { - expect(out) - .to.eql('added bafybeiaoh5okvpnuhndsz4kgdhulnkm566rz7w7il6r2zm6wxu5f5uqlsu less-than-default-max-chunk-size\n') - }) + const out = await ipfs('add test/fixtures/less-than-default-max-chunk-size --cid-version=1 --raw-leaves=false') + expect(out) + .to.eql('added bafybeiaoh5okvpnuhndsz4kgdhulnkm566rz7w7il6r2zm6wxu5f5uqlsu less-than-default-max-chunk-size\n') }) - it('add with cid-version=1 and raw-leaves=false > default max chunk size', function () { + it('add with cid-version=1 and raw-leaves=false > default max chunk size', async function () { this.timeout(30 * 1000) - return ipfs('add test/fixtures/greater-than-default-max-chunk-size --cid-version=1 --raw-leaves=false') - .then((out) => { - expect(out) - .to.eql('added bafybeiajpcrr2qglyeq3biilzt25ty6kpjs7huy2lfxopqfke6riaaxnim greater-than-default-max-chunk-size\n') - }) + const out = await ipfs('add test/fixtures/greater-than-default-max-chunk-size --cid-version=1 --raw-leaves=false') + expect(out) + .to.eql('added bafybeiajpcrr2qglyeq3biilzt25ty6kpjs7huy2lfxopqfke6riaaxnim greater-than-default-max-chunk-size\n') }) - it('add with cid-version=1 and raw-leaves=true < default max chunk size', function () { + it('add with cid-version=1 and raw-leaves=true < default max chunk size', async function () { this.timeout(30 * 1000) - return ipfs('add test/fixtures/less-than-default-max-chunk-size --cid-version=1 --raw-leaves=true') - .then((out) => { - expect(out) - .to.eql('added bafkreie3abdlmy7dtxddm4vkbhd2x2yax5scf4m35eyxf3ywj2uwkjbhgi less-than-default-max-chunk-size\n') - }) + const out = await ipfs('add test/fixtures/less-than-default-max-chunk-size --cid-version=1 --raw-leaves=true') + expect(out) + .to.eql('added bafkreie3abdlmy7dtxddm4vkbhd2x2yax5scf4m35eyxf3ywj2uwkjbhgi less-than-default-max-chunk-size\n') }) - it('add with cid-version=1 and raw-leaves=true > default max chunk size', function () { + it('add with cid-version=1 and raw-leaves=true > default max chunk size', async function () { this.timeout(30 * 1000) - return ipfs('add test/fixtures/greater-than-default-max-chunk-size --cid-version=1 --raw-leaves=true') - .then((out) => { - expect(out) - .to.eql('added bafybeiebjiahgamnil3r3os2hqorjualrgx6hpqh5zuqbhjmt7tyjqqttm greater-than-default-max-chunk-size\n') - }) + const out = await ipfs('add test/fixtures/greater-than-default-max-chunk-size --cid-version=1 --raw-leaves=true') + expect(out) + .to.eql('added bafybeiebjiahgamnil3r3os2hqorjualrgx6hpqh5zuqbhjmt7tyjqqttm greater-than-default-max-chunk-size\n') }) - it('add from pipe', () => { + it('add from pipe', async () => { const proc = ipfs('add') proc.stdin.write(Buffer.from('hello\n')) proc.stdin.end() - return proc - .then(out => { - expect(out) - .to.eql('added QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN\n') - }) + + const out = await proc + expect(out) + .to.eql('added QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN\n') }) - it('add --quiet', function () { + it('add --quiet', async function () { this.timeout(30 * 1000) - return ipfs('add -q src/init-files/init-docs/readme') - .then((out) => { - expect(out) - .to.eql('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB\n') - }) + const out = await ipfs('add -q src/init-files/init-docs/readme') + expect(out) + .to.eql('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB\n') }) - it('add --quieter', function () { + it('add --quieter', async function () { this.timeout(30 * 1000) - return ipfs('add -Q -w test/fixtures/test-data/hello') - .then((out) => { - expect(out) - .to.eql('QmYRMUVULBfj7WrdPESnwnyZmtayN6Sdrwh1nKcQ9QgQeZ\n') - }) + const out = await ipfs('add -Q -w test/fixtures/test-data/hello') + expect(out) + .to.eql('QmYRMUVULBfj7WrdPESnwnyZmtayN6Sdrwh1nKcQ9QgQeZ\n') }) - it('add --silent', function () { + it('add --silent', async function () { this.timeout(30 * 1000) - return ipfs('add --silent src/init-files/init-docs/readme') - .then((out) => { - expect(out) - .to.eql('') - }) + const out = await ipfs('add --silent src/init-files/init-docs/readme') + expect(out) + .to.eql('') }) - it('add --only-hash outputs correct hash', function () { - return ipfs('add --only-hash src/init-files/init-docs/readme') - .then(out => - expect(out) - .to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme\n') - ) + it('add --only-hash outputs correct hash', async function () { + const out = await ipfs('add --only-hash src/init-files/init-docs/readme') + expect(out) + .to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme\n') }) - it('add --only-hash does not add a file to the datastore', function () { + it('add --only-hash does not add a file to the datastore', async function () { this.timeout(30 * 1000) this.slow(10 * 1000) const content = hat() const filepath = path.join(os.tmpdir(), `${content}.txt`) fs.writeFileSync(filepath, content) - return ipfs(`add --only-hash ${filepath}`) - .then(out => { - const hash = out.split(' ')[1] + const out = await ipfs(`add --only-hash ${filepath}`) + const hash = out.split(' ')[1] - // 'jsipfs object get ' should timeout with the daemon on - // and should fail fast with the daemon off - return Promise.race([ - ipfs.fail(`object get ${hash}`), - new Promise((resolve, reject) => setTimeout(resolve, 4000)) - ]) - .then(() => clean(filepath)) - }) + // 'jsipfs object get ' should timeout with the daemon on + // and should fail fast with the daemon off + await Promise.race([ + ipfs.fail(`object get ${hash}`), + delay(4000) + ]) + await clean(filepath) }) - it('add pins by default', function () { + it('add pins by default', async function () { this.timeout(10 * 1000) const filePath = path.join(os.tmpdir(), hat()) const content = hat() fs.writeFileSync(filePath, content) - return ipfs(`add -Q ${filePath}`) - .then(out => { - const hash = out.trim() - return ipfs(`pin ls ${hash}`) - .then(ls => expect(ls).to.include(hash)) - }) - .then(() => clean(filePath)) + const out = await ipfs(`add -Q ${filePath}`) + const hash = out.trim() + const ls = await ipfs(`pin ls ${hash}`) + expect(ls).to.include(hash) + + await clean(filePath) }) - it('add does not pin with --pin=false', function () { + it('add does not pin with --pin=false', async function () { this.timeout(20 * 1000) const filePath = path.join(os.tmpdir(), hat()) const content = hat() fs.writeFileSync(filePath, content) - return ipfs(`add -Q --pin=false ${filePath}`) - .then(out => ipfs.fail(`pin ls ${out.trim()}`)) - .then(() => clean(filePath)) + const out = await ipfs(`add -Q --pin=false ${filePath}`) + await ipfs.fail(`pin ls ${out.trim()}`) + + await clean(filePath) }) HASH_ALGS.forEach((name) => { - it(`add with hash=${name} and raw-leaves=false`, function () { + it(`add with hash=${name} and raw-leaves=false`, async function () { this.timeout(30 * 1000) - return ipfs(`add src/init-files/init-docs/readme --hash=${name} --raw-leaves=false`) - .then((out) => { - const hash = out.split(' ')[1] - const cid = new CID(hash) - expect(mh.decode(cid.multihash).name).to.equal(name) - }) + const out = await ipfs(`add src/init-files/init-docs/readme --hash=${name} --raw-leaves=false`) + const hash = out.split(' ')[1] + const cid = new CID(hash) + expect(mh.decode(cid.multihash).name).to.equal(name) }) }) - it('should add and print CID encoded in specified base', function () { + it('should add and print CID encoded in specified base', async function () { this.timeout(30 * 1000) - return ipfs('add test/fixtures/test-data/hello --cid-base=base64') - .then((out) => { - expect(out).to.eql('added mAXASIEbUSBS5xa8UHDqqt8BdxehE6tX5HxKFiwIeukV2i0wO hello\n') - }) + const out = await ipfs('add test/fixtures/test-data/hello --cid-base=base64') + expect(out).to.eql('added mAXASIEbUSBS5xa8UHDqqt8BdxehE6tX5HxKFiwIeukV2i0wO hello\n') }) - it('cat', function () { + it('cat', async function () { this.timeout(30 * 1000) - return ipfs('cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB') - .then((out) => { - expect(out).to.eql(readme) - }) + const out = await ipfs('cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB') + expect(out).to.eql(readme) }) - it('cat alias', function () { + it('cat alias', async function () { this.timeout(20 * 1000) - return ipfs('cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB') - .then((out) => { - expect(out).to.eql(readme) - }) + const out = await ipfs('cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB') + expect(out).to.eql(readme) }) - it('cat part of a file using `count`', function () { + it('cat part of a file using `count`', async function () { this.timeout(30 * 1000) - return ipfs('cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB --offset 21 --count 5') - .then((out) => { - expect(out).to.eql(readme.substring(21, 26)) - }) + const out = await ipfs('cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB --offset 21 --count 5') + expect(out).to.eql(readme.substring(21, 26)) }) - it('cat part of a file using `length`', function () { + it('cat part of a file using `length`', async function () { this.timeout(30 * 1000) - return ipfs('cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB --offset 21 --length 5') - .then((out) => { - expect(out).to.eql(readme.substring(21, 26)) - }) + const out = await ipfs('cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB --offset 21 --length 5') + expect(out).to.eql(readme.substring(21, 26)) }) - it('cat non-existent file', () => { - return ipfs('cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB/dummy') - .then(() => expect.fail(0, 1, 'Should have thrown an error')) - .catch((err) => { - expect(err).to.exist() - }) + it('cat non-existent file', async () => { + const err = await ipfs.fail('cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB/dummy') + expect(err).to.exist() }) - it('get', function () { + it('get', async function () { this.timeout(20 * 1000) - return ipfs('get QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB') - .then((out) => { - expect(out) - .to.eql('Saving file(s) QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB\n') + const out = await ipfs('get QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB') + expect(out) + .to.eql('Saving file(s) QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB\n') - const file = path.join(process.cwd(), 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB') + const file = path.join(process.cwd(), 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB') - expect(fs.readFileSync(file).toString()).to.eql(readme) + expect(fs.readFileSync(file).toString()).to.eql(readme) - rimraf(file) - }) + rimraf(file) }) - it('get alias', function () { + it('get alias', async function () { this.timeout(20 * 1000) - return ipfs('get QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB') - .then((out) => { - expect(out) - .to.eql('Saving file(s) QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB\n') + const out = await ipfs('get QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB') + expect(out) + .to.eql('Saving file(s) QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB\n') - const file = path.join(process.cwd(), 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB') + const file = path.join(process.cwd(), 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB') - expect(fs.readFileSync(file).toString()).to.eql(readme) + expect(fs.readFileSync(file).toString()).to.eql(readme) - rimraf(file) - }) + rimraf(file) }) - it('get recursively', function () { + it('get recursively', async function () { this.timeout(20 * 1000) const outDir = path.join(process.cwd(), 'Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z') rimraf(outDir) - return ipfs('get Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z') - .then((out) => { - expect(out).to.eql( - 'Saving file(s) Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z\n' - ) - - const outDir = path.join(process.cwd(), 'Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z') - const expectedDir = path.join(process.cwd(), 'test', 'fixtures', 'test-data', 'recursive-get-dir') + const out = await ipfs('get Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z') + expect(out).to.eql( + 'Saving file(s) Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z\n' + ) - const compareResult = compareDir(outDir, expectedDir, { - compareContent: true, - compareSize: true - }) + const expectedDir = path.join(process.cwd(), 'test', 'fixtures', 'test-data', 'recursive-get-dir') + const compareResult = compareDir(outDir, expectedDir, { + compareContent: true, + compareSize: true + }) - expect(compareResult.differences).to.equal(0) - rimraf(outDir) - }) + expect(compareResult.differences).to.equal(0) + rimraf(outDir) }) })) diff --git a/test/cli/general.js b/test/cli/general.js index 0f20466fcd..ee26a51e67 100644 --- a/test/cli/general.js +++ b/test/cli/general.js @@ -5,17 +5,15 @@ const expect = require('chai').expect const runOnAndOff = require('../utils/on-and-off') describe('general cli options', () => runOnAndOff.off((thing) => { - it('should handle --silent flag', () => { - return thing.ipfs('help --silent').then((out) => { - expect(out).to.be.empty() - }) + it('should handle --silent flag', async () => { + const out = await thing.ipfs('help --silent') + expect(out).to.be.empty() }) - it('should handle unknown arguments correctly', () => { - return thing.ipfs('random --again').then((out) => { - expect(out).to.include('Unknown arguments: again, random') - expect(out).to.include('random') - expect(out).to.include('again') - }) + it('should handle unknown arguments correctly', async () => { + const out = await thing.ipfs('random --again') + expect(out).to.include('Unknown arguments: again, random') + expect(out).to.include('random') + expect(out).to.include('again') }) })) diff --git a/test/cli/init.js b/test/cli/init.js index e82c78b3f6..897936c07a 100644 --- a/test/cli/init.js +++ b/test/cli/init.js @@ -33,48 +33,43 @@ describe('init', function () { afterEach(() => clean(repoPath)) - it('basic', function () { - return ipfs('init').then((out) => { - expect(repoDirSync('blocks')).to.have.length.above(2) - expect(repoExistsSync('config')).to.equal(true) - expect(repoExistsSync('version')).to.equal(true) + it('basic', async function () { + const out = await ipfs('init') + expect(repoDirSync('blocks')).to.have.length.above(2) + expect(repoExistsSync('config')).to.equal(true) + expect(repoExistsSync('version')).to.equal(true) - // Test that the following was written when init-ing the repo - // jsipfs cat /ipfs/QmfGBRT6BbWJd7yUc2uYdaUZJBbnEFvTqehPFoSMQ6wgdr/readme - const command = out.substring(out.indexOf('cat'), out.length - 2 /* omit the newline char */) - return ipfs(command) - }).then((out) => expect(out).to.equal(readme)) + // Test that the following was written when init-ing the repo + // jsipfs cat /ipfs/QmfGBRT6BbWJd7yUc2uYdaUZJBbnEFvTqehPFoSMQ6wgdr/readme + const command = out.substring(out.indexOf('cat'), out.length - 2 /* omit the newline char */) + const out2 = await ipfs(command) + expect(out2).to.equal(readme) }) - it('bits', function () { - return ipfs('init --bits 1024').then(() => { - expect(repoDirSync('blocks')).to.have.length.above(2) - expect(repoExistsSync('config')).to.equal(true) - expect(repoExistsSync('version')).to.equal(true) - }) + it('bits', async function () { + await ipfs('init --bits 1024') + expect(repoDirSync('blocks')).to.have.length.above(2) + expect(repoExistsSync('config')).to.equal(true) + expect(repoExistsSync('version')).to.equal(true) }) - it('empty', function () { - return ipfs('init --bits 1024 --empty-repo true').then(() => { - expect(repoDirSync('blocks')).to.have.length(2) - expect(repoExistsSync('config')).to.equal(true) - expect(repoExistsSync('version')).to.equal(true) - }) + it('empty', async function () { + await ipfs('init --bits 1024 --empty-repo true') + expect(repoDirSync('blocks')).to.have.length(2) + expect(repoExistsSync('config')).to.equal(true) + expect(repoExistsSync('version')).to.equal(true) }) - it('should present ipfs path help when option help is received', function (done) { - ipfs('init --help').then((res) => { - expect(res).to.have.string('export IPFS_PATH=/path/to/ipfsrepo') - done() - }) + it('should present ipfs path help when option help is received', async function () { + const res = await ipfs('init --help') + expect(res).to.have.string('export IPFS_PATH=/path/to/ipfsrepo') }) - it('default config argument', () => { + it('default config argument', async () => { const configPath = tempWrite.sync('{"Addresses": {"API": "/ip4/127.0.0.1/tcp/9999"}}', 'config.json') - return ipfs(`init ${configPath}`).then((res) => { - const configRaw = fs.readFileSync(path.join(repoPath, 'config')).toString() - const config = JSON.parse(configRaw) - expect(config.Addresses.API).to.be.eq('/ip4/127.0.0.1/tcp/9999') - }) + await ipfs(`init ${configPath}`) + const configRaw = fs.readFileSync(path.join(repoPath, 'config')).toString() + const config = JSON.parse(configRaw) + expect(config.Addresses.API).to.be.eq('/ip4/127.0.0.1/tcp/9999') }) }) diff --git a/test/cli/key.js b/test/cli/key.js index 8a39c4919c..d75f88bf0b 100644 --- a/test/cli/key.js +++ b/test/cli/key.js @@ -15,39 +15,31 @@ describe('key', () => runOnAndOff.off((thing) => { ipfs = thing.ipfs }) - it('gen', function () { + it('gen', async function () { this.timeout(40 * 1000) - return ipfs(`${pass} key gen ${name} --type rsa --size 2048`) - .then((out) => { - expect(out).to.include(name) - }) + const out = await ipfs(`${pass} key gen ${name} --type rsa --size 2048`) + expect(out).to.include(name) }) - it('list', function () { + it('list', async function () { this.timeout(20 * 1000) - return ipfs(`${pass} key list`) - .then((out) => { - expect(out).to.include(name) - }) + const out = await ipfs(`${pass} key list`) + expect(out).to.include(name) }) - it('rename', function () { + it('rename', async function () { this.timeout(20 * 1000) - return ipfs(`${pass} key rename ${name} ${newName}`) - .then((out) => { - expect(out).to.include(newName) - }) + const out = await ipfs(`${pass} key rename ${name} ${newName}`) + expect(out).to.include(newName) }) - it('rm', function () { + it('rm', async function () { this.timeout(20 * 1000) - return ipfs(`${pass} key rm ${newName}`) - .then((out) => { - expect(out).to.include(newName) - }) + const out = await ipfs(`${pass} key rm ${newName}`) + expect(out).to.include(newName) }) })) diff --git a/test/cli/ls.js b/test/cli/ls.js index 3aca1f5a4a..d86c17490b 100644 --- a/test/cli/ls.js +++ b/test/cli/ls.js @@ -3,6 +3,7 @@ const expect = require('chai').expect const runOnAndOff = require('../utils/on-and-off') +const delay = require('delay') describe('ls', () => runOnAndOff((thing) => { let ipfs @@ -12,96 +13,89 @@ describe('ls', () => runOnAndOff((thing) => { return ipfs('add -r test/fixtures/test-data/recursive-get-dir') }) - it('prints added files', function () { + it('prints added files', async function () { this.timeout(20 * 1000) - return ipfs('ls Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z') - .then((out) => { - expect(out).to.eql( - 'QmamKEPmEH9RUsqRQsfNf5evZQDQPYL9KXg1ADeT7mkHkT - blocks/\n' + - 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3928 config\n' + - 'QmUqyZtPmsRy1U5Mo8kz2BAMmk1hfJ7yW1KAFTMB2odsFv - datastore/\n' + - 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU - init-docs/\n' + - 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 2 version\n' - ) - }) + const out = await ipfs('ls Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z') + expect(out).to.eql( + 'QmamKEPmEH9RUsqRQsfNf5evZQDQPYL9KXg1ADeT7mkHkT - blocks/\n' + + 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3928 config\n' + + 'QmUqyZtPmsRy1U5Mo8kz2BAMmk1hfJ7yW1KAFTMB2odsFv - datastore/\n' + + 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU - init-docs/\n' + + 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 2 version\n' + ) }) - it('prints nothing for non-existant hashes', function () { - // If the daemon is off, ls should fail - // If the daemon is on, ls should search until it hits a timeout - return Promise.race([ - ipfs.fail('ls QmYmW4HiZhotsoSqnv2o1oSssvkRM8b9RweBoH7ao5nki2'), - new Promise((resolve, reject) => setTimeout(resolve, 4000)) - ]) - .catch(() => expect.fail(0, 1, 'Should have thrown or timedout')) + it('prints nothing for non-existant hashes', async function () { + if (thing.on) { + // If the daemon is on, ls should search until it hits a timeout + await Promise.race([ + ipfs('ls QmYmW4HiZhotsoSqnv2o1oSssvkRM8b9RweBoH7ao5nki2'), + delay(4000) + ]) + } else { + // If the daemon is off, ls should fail + await ipfs.fail('ls QmYmW4HiZhotsoSqnv2o1oSssvkRM8b9RweBoH7ao5nki2') + } }) - it('adds a header, -v', function () { + it('adds a header, -v', async function () { this.timeout(20 * 1000) - return ipfs('ls /ipfs/Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z -v') - .then((out) => { - expect(out).to.eql( - 'Hash Size Name\n' + - 'QmamKEPmEH9RUsqRQsfNf5evZQDQPYL9KXg1ADeT7mkHkT - blocks/\n' + - 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3928 config\n' + - 'QmUqyZtPmsRy1U5Mo8kz2BAMmk1hfJ7yW1KAFTMB2odsFv - datastore/\n' + - 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU - init-docs/\n' + - 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 2 version\n' - ) - }) + const out = await ipfs('ls /ipfs/Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z -v') + expect(out).to.eql( + 'Hash Size Name\n' + + 'QmamKEPmEH9RUsqRQsfNf5evZQDQPYL9KXg1ADeT7mkHkT - blocks/\n' + + 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3928 config\n' + + 'QmUqyZtPmsRy1U5Mo8kz2BAMmk1hfJ7yW1KAFTMB2odsFv - datastore/\n' + + 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU - init-docs/\n' + + 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 2 version\n' + ) }) - it('follows a path, /', function () { + it('follows a path, /', async function () { this.timeout(20 * 1000) - return ipfs('ls /ipfs/Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z/init-docs') - .then((out) => { - expect(out).to.eql( - 'QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1677 about\n' + - 'QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 189 contact\n' + - 'QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC - docs/\n' + - 'QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 311 help\n' + - 'QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1717 quick-start\n' + - 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1091 readme\n' + - 'QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1016 security-notes\n' + - 'QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te - tour/\n' - ) - }) + const out = await ipfs('ls /ipfs/Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z/init-docs') + expect(out).to.eql( + 'QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1677 about\n' + + 'QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 189 contact\n' + + 'QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC - docs/\n' + + 'QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 311 help\n' + + 'QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1717 quick-start\n' + + 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1091 readme\n' + + 'QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1016 security-notes\n' + + 'QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te - tour/\n' + ) }) - it('recursively follows folders, -r', function () { + it('recursively follows folders, -r', async function () { this.slow(2000) this.timeout(20 * 1000) - return ipfs('ls -r /ipfs/Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z/init-docs') - .then(out => { - expect(out).to.eql( - 'QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1677 about\n' + - 'QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 189 contact\n' + - 'QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC - docs/\n' + - 'QmQN88TEidd3RY2u3dpib49fERTDfKtDpvxnvczATNsfKT 6 index\n' + - 'QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 311 help\n' + - 'QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1717 quick-start\n' + - 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1091 readme\n' + - 'QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1016 security-notes\n' + - 'QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te - tour/\n' + - 'QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs 796 0.0-intro\n' - ) - }) + const out = await ipfs('ls -r /ipfs/Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z/init-docs') + expect(out).to.eql( + 'QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1677 about\n' + + 'QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 189 contact\n' + + 'QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC - docs/\n' + + 'QmQN88TEidd3RY2u3dpib49fERTDfKtDpvxnvczATNsfKT 6 index\n' + + 'QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 311 help\n' + + 'QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1717 quick-start\n' + + 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1091 readme\n' + + 'QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1016 security-notes\n' + + 'QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te - tour/\n' + + 'QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs 796 0.0-intro\n' + ) }) - it('should ls and print CIDs encoded in specified base', function () { + it('should ls and print CIDs encoded in specified base', async function () { this.timeout(20 * 1000) - return ipfs('ls Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z --cid-base=base64') - .then((out) => { - expect(out).to.eql( - 'mAXASILidvV1YroHLqBvmuXko1Ly1UVenZV1K+MvhsjXhdvZQ - blocks/\n' + - 'mAXASIBT4ZYkQw0IApLoNHBxSjpezyayKZHJyxmFKpt0I3sK5 3928 config\n' + - 'mAXASIGCpScP8zpa0CqUgyVCR/Cm0Co8pnULGe3seXSsOnJsJ - datastore/\n' + - 'mAXASIF58POI3+TbHb69iXpD3dRqfXusEj1mHMwPCFenM6HWZ - init-docs/\n' + - 'mAXASICiW5ai+KiU60glImEMMkiHaNSOAivpXspriIhJO8iHI 2 version\n' - ) - }) + const out = await ipfs('ls Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z --cid-base=base64') + expect(out).to.eql( + 'mAXASILidvV1YroHLqBvmuXko1Ly1UVenZV1K+MvhsjXhdvZQ - blocks/\n' + + 'mAXASIBT4ZYkQw0IApLoNHBxSjpezyayKZHJyxmFKpt0I3sK5 3928 config\n' + + 'mAXASIGCpScP8zpa0CqUgyVCR/Cm0Co8pnULGe3seXSsOnJsJ - datastore/\n' + + 'mAXASIF58POI3+TbHb69iXpD3dRqfXusEj1mHMwPCFenM6HWZ - init-docs/\n' + + 'mAXASICiW5ai+KiU60glImEMMkiHaNSOAivpXspriIhJO8iHI 2 version\n' + ) }) })) diff --git a/test/cli/name-pubsub.js b/test/cli/name-pubsub.js index de54ca5f33..f3e1126039 100644 --- a/test/cli/name-pubsub.js +++ b/test/cli/name-pubsub.js @@ -7,7 +7,6 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) const path = require('path') -const parallel = require('async/parallel') const ipfsExec = require('../utils/ipfs-exec') const DaemonFactory = require('ipfsd-ctl') @@ -58,95 +57,61 @@ describe('name-pubsub', () => { }) // Get node ids - before(function (done) { - parallel([ - (cb) => { - ipfsA('id').then((res) => { - nodeAId = JSON.parse(res) - cb() - }) - }, - (cb) => { - ipfsB('id').then((res) => { - const id = JSON.parse(res) - - nodeBId = id - bMultiaddr = id.addresses[0] - cb() - }) - } - ], done) + before(async function () { + const res = await Promise.all([ + ipfsA('id'), + ipfsB('id') + ]) + + nodeAId = JSON.parse(res[0]) + nodeBId = JSON.parse(res[1]) + bMultiaddr = nodeBId.addresses[0] }) // Connect - before(function () { - return ipfsA('swarm', 'connect', bMultiaddr) - .then((out) => { - expect(out).to.eql(`connect ${bMultiaddr} success\n`) - }) + before(async function () { + const out = await ipfsA('swarm', 'connect', bMultiaddr) + expect(out).to.eql(`connect ${bMultiaddr} success\n`) }) after(() => Promise.all(nodes.map((node) => node.stop()))) describe('pubsub commands', () => { - it('should get enabled state of pubsub', function () { - return ipfsA('name pubsub state') - .then((res) => { - expect(res).to.exist() - expect(res).to.have.string('enabled') // enabled - }) + it('should get enabled state of pubsub', async function () { + const res = await ipfsA('name pubsub state') + expect(res).to.have.string('enabled') // enabled }) - it('should subscribe on name resolve', function () { + it('should subscribe on name resolve', async function () { this.timeout(80 * 1000) - return ipfsB.fail(`name resolve ${nodeAId.id}`) - .then((err) => { - expect(err.all).to.include('was not found') - return ipfsB('pubsub ls') - }) - .then((res) => { - expect(res).to.exist() - expect(res).to.have.string('/record/') // have a record ipns subscribtion - return ipfsB('name pubsub subs') - }) - .then((res) => { - expect(res).to.exist() - expect(res).to.have.string(`/ipns/${nodeAId.id}`) // have subscription - }) + const err = await ipfsB.fail(`name resolve ${nodeAId.id}`) + expect(err.all).to.include('was not found') + + const ls = await ipfsB('pubsub ls') + expect(ls).to.have.string('/record/') // have a record ipns subscribtion + + const subs = await ipfsB('name pubsub subs') + expect(subs).to.have.string(`/ipns/${nodeAId.id}`) // have subscription }) - it('should be able to cancel subscriptions', function () { + it('should be able to cancel subscriptions', async function () { this.timeout(80 * 1000) - return ipfsA(`name pubsub cancel /ipns/${nodeBId.id}`) - .then((res) => { - expect(res).to.exist() - expect(res).to.have.string('no subscription') // tried to cancel a not yet subscribed id - - return ipfsA(`name resolve ${nodeBId.id}`) - }) - .catch((err) => { - expect(err).to.exist() // Not available (subscribed now) - - return ipfsA(`name pubsub cancel /ipns/${nodeBId.id}`) - }) - .then((res) => { - expect(res).to.exist() - expect(res).to.have.string('canceled') // canceled now - - return ipfsA('pubsub ls') - }) - .then((res) => { - expect(res).to.exist() - expect(res).to.not.have.string('/ipns/') // ipns subscribtion not available - - return ipfsA('name pubsub subs') - }) - .then((res) => { - expect(res).to.exist() - expect(res).to.not.have.string(`/ipns/${nodeBId.id}`) // ipns subscribtion not available - }) + const res = await ipfsA(`name pubsub cancel /ipns/${nodeBId.id}`) + expect(res).to.have.string('no subscription') // tried to cancel a not yet subscribed id + + const err = await ipfsA.fail(`name resolve ${nodeBId.id}`) + expect(err).to.exist() // Not available (subscribed now) + + const cancel = await ipfsA(`name pubsub cancel /ipns/${nodeBId.id}`) + expect(cancel).to.have.string('canceled') // canceled now + + const ls = await ipfsA('pubsub ls') + expect(ls).to.not.have.string('/ipns/') // ipns subscribtion not available + + const subs = await ipfsA('name pubsub subs') + expect(subs).to.not.have.string(`/ipns/${nodeBId.id}`) // ipns subscribtion not available }) }) }) @@ -175,28 +140,19 @@ describe('name-pubsub', () => { } }) - it('should get disabled state of pubsub', function () { - return ipfsA('name pubsub state') - .then((res) => { - expect(res).to.exist() - expect(res).to.have.string('disabled') - }) + it('should get disabled state of pubsub', async function () { + const res = await ipfsA('name pubsub state') + expect(res).to.have.string('disabled') }) - it('should get error getting the available subscriptions', function () { - return ipfsA('name pubsub subs') - .catch((err) => { - expect(err).to.exist() // error as it is disabled - expect(err.stdout).to.have.string('IPNS pubsub subsystem is not enabled') - }) + it('should get error getting the available subscriptions', async function () { + const err = await ipfsA.fail('name pubsub subs') + expect(err.stdout).to.have.string('IPNS pubsub subsystem is not enabled') }) - it('should get error canceling a subscription', function () { - return ipfsA('name pubsub cancel /ipns/QmSWxaPcGgf4TDnFEBDWz2JnbHywF14phmY9hNcAeBEK5v') - .catch((err) => { - expect(err).to.exist() // error as it is disabled - expect(err.stdout).to.have.string('IPNS pubsub subsystem is not enabled') - }) + it('should get error canceling a subscription', async function () { + const err = await ipfsA.fail('name pubsub cancel /ipns/QmSWxaPcGgf4TDnFEBDWz2JnbHywF14phmY9hNcAeBEK5v') + expect(err.stdout).to.have.string('IPNS pubsub subsystem is not enabled') }) }) }) diff --git a/test/cli/object.js b/test/cli/object.js index d341c51bc8..d653e2fb82 100644 --- a/test/cli/object.js +++ b/test/cli/object.js @@ -19,123 +19,108 @@ describe('object', () => runOnAndOff((thing) => { ipfs = thing.ipfs }) - it('new', () => { - return ipfs('object new').then((out) => { - expect(out).to.eql( - 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n\n' - ) - }) + it('new', async () => { + const out = await ipfs('object new') + expect(out).to.eql( + 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n\n' + ) }) - it('new unixfs-dir', () => { - return ipfs('object new unixfs-dir').then((out) => { - expect(out).to.eql( - 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn\n' - ) - }) + it('new unixfs-dir', async () => { + const out = await ipfs('object new unixfs-dir') + expect(out).to.eql( + 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn\n' + ) }) // TODO: unskip after switch to v1 CIDs by default - it.skip('should new and print CID encoded in specified base', () => { - return ipfs('object new --cid-base=base64').then((out) => { - expect(out).to.eql( - 'mAXASIOOwxEKY/BwUmvv0yJlvuSQnrkHkZJuTTKSVmRt4UrhV\n' - ) - }) + it.skip('should new and print CID encoded in specified base', async () => { + const out = await ipfs('object new --cid-base=base64') + expect(out).to.eql( + 'mAXASIOOwxEKY/BwUmvv0yJlvuSQnrkHkZJuTTKSVmRt4UrhV\n' + ) }) - it('get', () => { - return ipfs('object get QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n').then((out) => { - const result = JSON.parse(out) - expect(result.Links).to.eql([]) - expect(result.Data).to.eql('') - }) + it('get', async () => { + const out = await ipfs('object get QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n') + const result = JSON.parse(out) + expect(result.Links).to.eql([]) + expect(result.Data).to.eql('') }) - it('get with data', function () { + it('get with data', async function () { this.timeout(15 * 1000) - return ipfs('object new') - .then((out) => out.trim()) - .then((hash) => ipfs(`object patch set-data ${hash} ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/hello`)) - .then((out) => out.trim()) - .then((hash) => ipfs(`object get ${hash}`)) - .then((out) => { - const result = JSON.parse(out) - expect(result.Data).to.eql('aGVsbG8gd29ybGQK') - }) + const out = await ipfs('object new') + const out2 = await ipfs(`object patch set-data ${out.trim()} ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/hello`) + const res = await ipfs(`object get ${out2.trim()}`) + const result = JSON.parse(res) + + expect(result.Data).to.eql('aGVsbG8gd29ybGQK') }) - it('get while overriding data-encoding', function () { + it('get while overriding data-encoding', async function () { this.timeout(15 * 1000) - return ipfs('object new') - .then((out) => out.trim()) - .then((hash) => ipfs(`object patch set-data ${hash} ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/hello`)) - .then((out) => out.trim()) - .then((hash) => ipfs(`object get --data-encoding=utf8 ${hash}`)) - .then((out) => { - const result = JSON.parse(out) - expect(result.Data).to.eql('hello world\n') - }) + const out = await ipfs('object new') + const out2 = await ipfs(`object patch set-data ${out.trim()} ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/hello`) + const res = await ipfs(`object get --data-encoding=utf8 ${out2.trim()}`) + const result = JSON.parse(res) + + expect(result.Data).to.eql('hello world\n') }) - it('should get and print CIDs encoded in specified base', function () { + it('should get and print CIDs encoded in specified base', async function () { this.timeout(15 * 1000) - return ipfs(`add ${path.resolve(path.join(__dirname, '..'))}/fixtures/planets -r --cid-version=1`) - .then(out => { - const lines = out.trim().split('\n') - return lines[lines.length - 1].split(' ')[1] - }) - .then(cid => ipfs(`object get ${cid} --cid-base=base64`)) - .then(out => { - const result = JSON.parse(out) - expect(multibase.isEncoded(result.Hash)).to.deep.equal('base64') - result.Links.forEach(l => { - expect(multibase.isEncoded(l.Hash)).to.deep.equal('base64') - }) - }) - }) - it('put', () => { - return ipfs(`object put ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/node.json`).then((out) => { - expect(out).to.eql( - 'added QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm\n' - ) + const out = await ipfs(`add ${path.resolve(path.join(__dirname, '..'))}/fixtures/planets -r --cid-version=1`) + const lines = out.trim().split('\n') + const cid = lines[lines.length - 1].split(' ')[1] + const out2 = await ipfs(`object get ${cid} --cid-base=base64`) + const result = JSON.parse(out2) + + expect(multibase.isEncoded(result.Hash)).to.deep.equal('base64') + result.Links.forEach(l => { + expect(multibase.isEncoded(l.Hash)).to.deep.equal('base64') }) }) + it('put', async () => { + const out = await ipfs(`object put ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/node.json`) + + expect(out).to.eql( + 'added QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm\n' + ) + }) + // TODO: unskip after switch to v1 CIDs by default - it.skip('should put and print CID encoded in specified base', () => { - return ipfs(`object put ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/node.json --cid-base=base64`) - .then((out) => { - expect(out).to.eql( - 'added mAXASIKbM02Neyt6L1RRLYVEOuNlqDOzTvBboo3cI/u6f/+Vk\n' - ) - }) + it.skip('should put and print CID encoded in specified base', async () => { + const out = await ipfs(`object put ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/node.json --cid-base=base64`) + + expect(out).to.eql( + 'added mAXASIKbM02Neyt6L1RRLYVEOuNlqDOzTvBboo3cI/u6f/+Vk\n' + ) }) - it('stat', function () { + it('stat', async function () { this.timeout(40 * 1000) - return ipfs('object stat QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm').then((out) => { - expect(out).to.eql([ - 'NumLinks: 1', - 'BlockSize: 60', - 'LinksSize: 53', - 'DataSize: 7', - 'CumulativeSize: 68' - ].join('\n') + '\n') - }) + const out = await ipfs('object stat QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm') + expect(out).to.eql([ + 'NumLinks: 1', + 'BlockSize: 60', + 'LinksSize: 53', + 'DataSize: 7', + 'CumulativeSize: 68' + ].join('\n') + '\n') }) - it('data', () => { - return ipfs('object data QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm').then((out) => { - expect(out).to.eql('another') - }) + it('data', async () => { + const out = await ipfs('object data QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm') + expect(out).to.eql('another') }) - it('unaltered data', function () { + it('unaltered data', async function () { this.timeout(10 * 1000) // has to be big enough to span several DAGNodes @@ -144,39 +129,31 @@ describe('object', () => runOnAndOff((thing) => { fs.writeFileSync(file, data) - return ipfs(`add ${file}`) - .then((out) => { - return ipfs.raw(`object data ${out.split(' ')[1]}`) - }) - .then((out) => { - const meta = UnixFs.unmarshal(out) + const out = await ipfs(`add ${file}`) + const out2 = await ipfs.raw(`object data ${out.split(' ')[1]}`) + const meta = UnixFs.unmarshal(out2) - expect(meta.type).to.equal('file') - expect(meta.fileSize()).to.equal(data.length) - }) + expect(meta.type).to.equal('file') + expect(meta.fileSize()).to.equal(data.length) }) - it('links', () => { - return ipfs('object links QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm').then((out) => { - expect(out).to.eql( - 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V 8 some link\n' - ) - }) + it('links', async () => { + const out = await ipfs('object links QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm') + expect(out).to.eql( + 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V 8 some link\n' + ) }) - it('should get links and print CIDs encoded in specified base', () => { - return ipfs(`add ${path.resolve(path.join(__dirname, '..'))}/fixtures/planets -r --cid-version=1`) - .then(out => { - const lines = out.trim().split('\n') - return lines[lines.length - 1].split(' ')[1] - }) - .then(cid => ipfs(`object links ${cid} --cid-base=base64`)) - .then(out => { - out.trim().split('\n').forEach(line => { - const cid = line.split(' ')[0] - expect(multibase.isEncoded(cid)).to.deep.equal('base64') - }) - }) + it('should get links and print CIDs encoded in specified base', async () => { + const out = await ipfs(`add ${path.resolve(path.join(__dirname, '..'))}/fixtures/planets -r --cid-version=1`) + const lines = out.trim().split('\n') + const cid = await lines[lines.length - 1].split(' ')[1] + const out2 = await ipfs(`object links ${cid} --cid-base=base64`) + + out2.trim().split('\n').forEach(line => { + const cid = line.split(' ')[0] + expect(multibase.isEncoded(cid)).to.deep.equal('base64') + }) }) describe('patch', function () { @@ -186,72 +163,64 @@ describe('object', () => runOnAndOff((thing) => { await ipfs('object new') }) - it('append-data', () => { - return ipfs(`object patch append-data QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/badconfig`).then((out) => { - expect(out).to.eql( - 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6\n' - ) - }) + it('append-data', async () => { + const out = await ipfs(`object patch append-data QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/badconfig`) + expect(out).to.eql( + 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6\n' + ) }) // TODO: unskip after switch to v1 CIDs by default - it.skip('should append-data and print CID encoded in specified base', () => { - return ipfs(`object patch append-data QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/badconfig --cid-base=base64`).then((out) => { - expect(out).to.eql( - 'mAXASIP+BZ7jGtaTyLGOs0xYcQvH7K9kVKEbyzXAkwLoZwrRj\n' - ) - }) + it.skip('should append-data and print CID encoded in specified base', async () => { + const out = await ipfs(`object patch append-data QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/badconfig --cid-base=base64`) + expect(out).to.eql( + 'mAXASIP+BZ7jGtaTyLGOs0xYcQvH7K9kVKEbyzXAkwLoZwrRj\n' + ) }) - it('set-data', () => { - return ipfs(`object patch set-data QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6 ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/badconfig`).then((out) => { - expect(out).to.eql( - 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6\n' - ) - }) + it('set-data', async () => { + const out = await ipfs(`object patch set-data QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6 ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/badconfig`) + expect(out).to.eql( + 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6\n' + ) }) // TODO: unskip after switch to v1 CIDs by default - it.skip('should set-data and print CID encoded in specified base', () => { - return ipfs(`object patch set-data QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6 ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/badconfig --cid-base=base64`).then((out) => { - expect(out).to.eql( - 'mAXASIP+BZ7jGtaTyLGOs0xYcQvH7K9kVKEbyzXAkwLoZwrRj\n' - ) - }) + it.skip('should set-data and print CID encoded in specified base', async () => { + const out = await ipfs(`object patch set-data QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6 ${path.resolve(path.join(__dirname, '..'))}/fixtures/test-data/badconfig --cid-base=base64`) + expect(out).to.eql( + 'mAXASIP+BZ7jGtaTyLGOs0xYcQvH7K9kVKEbyzXAkwLoZwrRj\n' + ) }) - it('add-link', () => { - return ipfs('object patch add-link QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n foo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn').then((out) => { - expect(out).to.eql( - 'QmdVHE8fUD6FLNLugtNxqDFyhaCgdob372hs6BYEe75VAK\n' - ) - }) + it('add-link', async () => { + const out = await ipfs('object patch add-link QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n foo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn') + expect(out).to.eql( + 'QmdVHE8fUD6FLNLugtNxqDFyhaCgdob372hs6BYEe75VAK\n' + ) }) // TODO: unskip after switch to v1 CIDs by default - it.skip('should add-link and print CID encoded in specified base', () => { - return ipfs('object patch add-link QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n foo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn --cid-base=base64').then((out) => { - expect(out).to.eql( - 'mAXASIOEVPbXq2xYoEsRZhaPB61btcy1x359osjv4a2L/lgPs\n' - ) - }) + it.skip('should add-link and print CID encoded in specified base', async () => { + const out = await ipfs('object patch add-link QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n foo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn --cid-base=base64') + expect(out).to.eql( + 'mAXASIOEVPbXq2xYoEsRZhaPB61btcy1x359osjv4a2L/lgPs\n' + ) }) - it('rm-link', () => { - return ipfs('object patch rm-link QmdVHE8fUD6FLNLugtNxqDFyhaCgdob372hs6BYEe75VAK foo').then((out) => { - expect(out).to.eql( - 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n\n' - ) - }) + it('rm-link', async () => { + const out = await ipfs('object patch rm-link QmdVHE8fUD6FLNLugtNxqDFyhaCgdob372hs6BYEe75VAK foo') + expect(out).to.eql( + 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n\n' + ) }) // TODO: unskip after switch to v1 CIDs by default - it.skip('should rm-link and print CID encoded in specified base', () => { - return ipfs('object patch rm-link QmdVHE8fUD6FLNLugtNxqDFyhaCgdob372hs6BYEe75VAK foo --cid-base=base64').then((out) => { - expect(out).to.eql( - 'mAXASIOOwxEKY/BwUmvv0yJlvuSQnrkHkZJuTTKSVmRt4UrhV\n' - ) - }) + it.skip('should rm-link and print CID encoded in specified base', async () => { + const out = await ipfs('object patch rm-link QmdVHE8fUD6FLNLugtNxqDFyhaCgdob372hs6BYEe75VAK foo --cid-base=base64') + expect(out).to.eql( + 'mAXASIOOwxEKY/BwUmvv0yJlvuSQnrkHkZJuTTKSVmRt4UrhV\n' + ) }) }) })) diff --git a/test/cli/parser.js b/test/cli/parser.js index a8c9497f8b..660def1f60 100644 --- a/test/cli/parser.js +++ b/test/cli/parser.js @@ -15,31 +15,15 @@ describe('yargs cli parser', () => { cli = new YargsPromise(parser) }) - it('should handle --silent flag correctly', (done) => { - cli - .parse('serve --silent src/init-files/init-docs/readme') - .then(({ error, argv }) => { - expect(error).to.not.exist() - expect(argv).to.include({ silent: true, pass: '' }) - expect(argv.getIpfs.instance).to.exist() - done() - }) - .catch(({ error }) => { - done(error) - }) + it('should handle --silent flag correctly', async () => { + const { error, argv } = await cli.parse('serve --silent src/init-files/init-docs/readme') + expect(error).to.not.exist() + expect(argv).to.include({ silent: true, pass: '' }) }) - it('should handle --pass flag correctly', (done) => { - cli - .parse('serve --pass password') - .then(({ error, argv }) => { - expect(error).to.not.exist() - expect(argv).to.include({ silent: true, pass: '' }) - expect(argv.getIpfs.instance).to.exist() - done() - }) - .catch(({ error }) => { - done(error) - }) + it('should handle --pass flag correctly', async () => { + const { error, argv } = await cli.parse('serve --pass password') + expect(error).to.not.exist() + expect(argv).to.include({ silent: false, pass: 'password' }) }) }) diff --git a/test/cli/pin.js b/test/cli/pin.js index 15458c12cb..d8aa5e23c6 100644 --- a/test/cli/pin.js +++ b/test/cli/pin.js @@ -31,77 +31,63 @@ describe('pin', () => runOnAndOff(thing => { }) describe('rm', function () { - it('recursively (default)', () => { - return ipfs(`pin rm ${pins.root}`) - .then(out => expect(out).to.equal(`unpinned ${pins.root}\n`)) + it('recursively (default)', async () => { + const out = await ipfs(`pin rm ${pins.root}`) + expect(out).to.equal(`unpinned ${pins.root}\n`) }) - it('should rm and print CIDs encoded in specified base', function () { + it('should rm and print CIDs encoded in specified base', async function () { this.timeout(30 * 1000) - return ipfs(`add -r ${fixturePath}`) - .then(() => ipfs(`pin rm ${pins.root} --cid-base=base64`)) - .then(out => { - const b64CidStr = new CID(pins.root).toV1().toBaseEncodedString('base64') - expect(out).to.eql(`unpinned ${b64CidStr}\n`) - }) + await ipfs(`add -r ${fixturePath}`) + const out = await ipfs(`pin rm ${pins.root} --cid-base=base64`) + const b64CidStr = new CID(pins.root).toV1().toBaseEncodedString('base64') + expect(out).to.eql(`unpinned ${b64CidStr}\n`) }) }) describe('add', function () { - it('recursively (default)', () => { - return ipfs(`pin add ${pins.root}`) - .then(out => - expect(out).to.eql(`pinned ${pins.root} recursively\n`) - ) + it('recursively (default)', async () => { + const out = await ipfs(`pin add ${pins.root}`) + expect(out).to.eql(`pinned ${pins.root} recursively\n`) }) - it('direct', () => { - return ipfs(`pin add ${pins.solarWiki} --recursive false`) - .then(out => - expect(out).to.eql(`pinned ${pins.solarWiki} directly\n`) - ) + it('direct', async () => { + const out = await ipfs(`pin add ${pins.solarWiki} --recursive false`) + expect(out).to.eql(`pinned ${pins.solarWiki} directly\n`) }) - it('should add and print CIDs encoded in specified base', () => { - return ipfs(`pin add ${pins.root} --cid-base=base64`) - .then(out => { - const b64CidStr = new CID(pins.root).toV1().toBaseEncodedString('base64') - expect(out).to.eql(`pinned ${b64CidStr} recursively\n`) - }) + it('should add and print CIDs encoded in specified base', async () => { + const out = await ipfs(`pin add ${pins.root} --cid-base=base64`) + const b64CidStr = new CID(pins.root).toV1().toBaseEncodedString('base64') + expect(out).to.eql(`pinned ${b64CidStr} recursively\n`) }) }) describe('ls', function () { - it('lists all pins when no hash is passed', function () { - return ipfs('pin ls -q').then(out => { - const results = out.split('\n') - expect(results).to.include.members(Object.values(pins)) - }) + it('lists all pins when no hash is passed', async () => { + const out = await ipfs('pin ls -q') + const results = out.split('\n') + expect(results).to.include.members(Object.values(pins)) }) - it('handles multiple hashes', function () { - return ipfs(`pin ls ${pins.root} ${pins.solarWiki}`) - .then(out => { - expect(out).to.eql( - `${pins.root} recursive\n${pins.solarWiki} direct\n` - ) - }) + it('handles multiple hashes', async () => { + const out = await ipfs(`pin ls ${pins.root} ${pins.solarWiki}`) + expect(out).to.eql( + `${pins.root} recursive\n${pins.solarWiki} direct\n` + ) }) - it('can print quietly', function () { - return ipfs('pin ls -q').then(out => { - const firstLineParts = out.split(/\s/)[0].split(' ') - expect(firstLineParts).to.have.length(1) - }) + it('can print quietly', async () => { + const out = await ipfs('pin ls -q') + const firstLineParts = out.split(/\s/)[0].split(' ') + expect(firstLineParts).to.have.length(1) }) - it('should ls and print CIDs encoded in specified base', () => { - return ipfs(`pin ls ${pins.root} --cid-base=base64`) - .then(out => { - const b64CidStr = new CID(pins.root).toV1().toBaseEncodedString('base64') - expect(out).to.eql(`${b64CidStr} recursive\n`) - }) + it('should ls and print CIDs encoded in specified base', async () => { + const out = await ipfs(`pin ls ${pins.root} --cid-base=base64`) + const b64CidStr = new CID(pins.root).toV1().toBaseEncodedString('base64') + expect(out).to.eql(`${b64CidStr} recursive\n`) }) }) })) diff --git a/test/cli/ping.js b/test/cli/ping.js index 9eff4b094d..6d843bc113 100644 --- a/test/cli/ping.js +++ b/test/cli/ping.js @@ -57,10 +57,9 @@ describe('ping', function () { await ipfsdA.api.swarm.connect(bMultiaddr) }) - before((done) => { + before(() => { this.timeout(60 * 1000) cli = ipfsExec(ipfsdA.repoPath) - done() }) after(() => { @@ -74,7 +73,7 @@ describe('ping', function () { } }) - it('ping host', (done) => { + it('ping host', async () => { this.timeout(60 * 1000) const ping = cli(`ping ${ipfsdBId}`) const result = [] @@ -83,22 +82,17 @@ describe('ping', function () { result.push(...packets) }) - ping.stdout.on('end', () => { - expect(result).to.have.lengthOf(12) - expect(result[0]).to.equal(`PING ${ipfsdBId}`) - for (let i = 1; i < 11; i++) { - expect(result[i]).to.match(/^Pong received: time=\d+ ms$/) - } - expect(result[11]).to.match(/^Average latency: \d+(.\d+)?ms$/) - done() - }) + await ping - ping.catch((err) => { - expect(err).to.not.exist() - }) + expect(result).to.have.lengthOf(12) + expect(result[0]).to.equal(`PING ${ipfsdBId}`) + for (let i = 1; i < 11; i++) { + expect(result[i]).to.match(/^Pong received: time=\d+ ms$/) + } + expect(result[11]).to.match(/^Average latency: \d+(.\d+)?ms$/) }) - it('ping host with --n option', (done) => { + it('ping host with --n option', async () => { this.timeout(60 * 1000) const ping = cli(`ping --n 1 ${ipfsdBId}`) const result = [] @@ -107,20 +101,15 @@ describe('ping', function () { result.push(...packets) }) - ping.stdout.on('end', () => { - expect(result).to.have.lengthOf(3) - expect(result[0]).to.equal(`PING ${ipfsdBId}`) - expect(result[1]).to.match(/^Pong received: time=\d+ ms$/) - expect(result[2]).to.match(/^Average latency: \d+(.\d+)?ms$/) - done() - }) + await ping - ping.catch((err) => { - expect(err).to.not.exist() - }) + expect(result).to.have.lengthOf(3) + expect(result[0]).to.equal(`PING ${ipfsdBId}`) + expect(result[1]).to.match(/^Pong received: time=\d+ ms$/) + expect(result[2]).to.match(/^Average latency: \d+(.\d+)?ms$/) }) - it('ping host with --count option', (done) => { + it('ping host with --count option', async () => { this.timeout(60 * 1000) const ping = cli(`ping --count 1 ${ipfsdBId}`) const result = [] @@ -129,16 +118,11 @@ describe('ping', function () { result.push(...packets) }) - ping.stdout.on('end', () => { - expect(result).to.have.lengthOf(3) - expect(result[0]).to.equal(`PING ${ipfsdBId}`) - expect(result[1]).to.match(/^Pong received: time=\d+ ms$/) - expect(result[2]).to.match(/^Average latency: \d+(.\d+)?ms$/) - done() - }) + await ping - ping.catch((err) => { - expect(err).to.not.exist() - }) + expect(result).to.have.lengthOf(3) + expect(result[0]).to.equal(`PING ${ipfsdBId}`) + expect(result[1]).to.match(/^Pong received: time=\d+ ms$/) + expect(result[2]).to.match(/^Average latency: \d+(.\d+)?ms$/) }) }) diff --git a/test/cli/refs-local.js b/test/cli/refs-local.js index de1ecb02b2..0232c3a9d3 100644 --- a/test/cli/refs-local.js +++ b/test/cli/refs-local.js @@ -12,14 +12,13 @@ describe('refs-local', () => runOnAndOff((thing) => { return ipfs('add -r test/fixtures/test-data/recursive-get-dir') }) - it('prints CID of all blocks', function () { + it('prints CID of all blocks', async function () { this.timeout(20 * 1000) - return ipfs('refs-local') - .then((out) => { - const lines = out.split('\n') - expect(lines.includes('QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN')).to.eql(true) - expect(lines.includes('QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU')).to.eql(true) - }) + const out = await ipfs('refs-local') + const lines = out.split('\n') + + expect(lines.includes('QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN')).to.eql(true) + expect(lines.includes('QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU')).to.eql(true) }) })) diff --git a/test/cli/refs.js b/test/cli/refs.js index 5fea8bb34f..bd7704d400 100644 --- a/test/cli/refs.js +++ b/test/cli/refs.js @@ -13,38 +13,34 @@ describe('refs', () => runOnAndOff((thing) => { return ipfs('add -r test/fixtures/test-data/recursive-get-dir') }) - it('prints added files', function () { + it('prints added files', async function () { this.timeout(20 * 1000) - return ipfs('refs Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z') - .then((out) => { - expect(out).to.eql( - 'QmamKEPmEH9RUsqRQsfNf5evZQDQPYL9KXg1ADeT7mkHkT\n' + - 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN\n' + - 'QmUqyZtPmsRy1U5Mo8kz2BAMmk1hfJ7yW1KAFTMB2odsFv\n' + - 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU\n' + - 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV\n' - ) - }) + const out = await ipfs('refs Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z') + expect(out).to.eql( + 'QmamKEPmEH9RUsqRQsfNf5evZQDQPYL9KXg1ADeT7mkHkT\n' + + 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN\n' + + 'QmUqyZtPmsRy1U5Mo8kz2BAMmk1hfJ7yW1KAFTMB2odsFv\n' + + 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU\n' + + 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV\n' + ) }) - it('follows a path with recursion, /', function () { + it('follows a path with recursion, /', async function () { this.timeout(20 * 1000) - return ipfs('refs -r --format="" /ipfs/Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z/init-docs') - .then((out) => { - expect(out).to.eql( - 'about\n' + - 'contact\n' + - 'docs\n' + - 'index\n' + - 'help\n' + - 'quick-start\n' + - 'readme\n' + - 'security-notes\n' + - 'tour\n' + - '0.0-intro\n' - ) - }) + const out = await ipfs('refs -r --format="" /ipfs/Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z/init-docs') + expect(out).to.eql( + 'about\n' + + 'contact\n' + + 'docs\n' + + 'index\n' + + 'help\n' + + 'quick-start\n' + + 'readme\n' + + 'security-notes\n' + + 'tour\n' + + '0.0-intro\n' + ) }) })) diff --git a/test/cli/repo.js b/test/cli/repo.js index 3c83d2d468..f47437f67f 100644 --- a/test/cli/repo.js +++ b/test/cli/repo.js @@ -12,9 +12,8 @@ describe('repo', () => runOnAndOff((thing) => { ipfs = thing.ipfs }) - it('get the repo version', () => { - return ipfs('repo version').then((out) => { - expect(out).to.eql(`${repoVersion}\n`) - }) + it('get the repo version', async () => { + const out = await ipfs('repo version') + expect(out).to.eql(`${repoVersion}\n`) }) })) diff --git a/test/cli/swarm.js b/test/cli/swarm.js index 9a99cf1acc..2fca1d2899 100644 --- a/test/cli/swarm.js +++ b/test/cli/swarm.js @@ -68,42 +68,36 @@ describe('swarm', () => { after(() => Promise.all(nodes.map((node) => node.stop()))) - it('connect', () => { - return ipfsA('swarm', 'connect', bMultiaddr).then((out) => { - expect(out).to.eql(`connect ${bMultiaddr} success\n`) - }) + it('connect', async () => { + const out = await ipfsA('swarm', 'connect', bMultiaddr) + expect(out).to.eql(`connect ${bMultiaddr} success\n`) }) - it('peers', () => { - return ipfsA('swarm peers').then((out) => { - expect(out).to.eql(bMultiaddr + '\n') - }) + it('peers', async () => { + const out = await ipfsA('swarm peers') + expect(out).to.eql(bMultiaddr + '\n') }) - it('addrs', () => { - return ipfsA('swarm addrs').then((out) => { - expect(out).to.have.length.above(1) - }) + it('addrs', async () => { + const out = await ipfsA('swarm addrs') + expect(out).to.have.length.above(1) }) - it('addrs local', () => { - return ipfsA('swarm addrs local').then((out) => { - expect(out).to.have.length.above(1) - }) + it('addrs local', async () => { + const out = await ipfsA('swarm addrs local') + expect(out).to.have.length.above(1) }) - it('disconnect', () => { - return ipfsA('swarm', 'disconnect', bMultiaddr).then((out) => { - expect(out).to.eql( - `disconnect ${bMultiaddr} success\n` - ) - }) + it('disconnect', async () => { + const out = await ipfsA('swarm', 'disconnect', bMultiaddr) + expect(out).to.eql( + `disconnect ${bMultiaddr} success\n` + ) }) - it('`peers` should not throw after `disconnect`', () => { - return ipfsA('swarm peers').then((out) => { - expect(out).to.be.empty() - }) + it('`peers` should not throw after `disconnect`', async () => { + const out = await ipfsA('swarm peers') + expect(out).to.be.empty() }) }) diff --git a/test/cli/version.js b/test/cli/version.js index 5bf740eb15..67fe53a295 100644 --- a/test/cli/version.js +++ b/test/cli/version.js @@ -15,55 +15,45 @@ describe('version', () => runOnAndOff((thing) => { ipfs = thing.ipfs }) - it('get the version', () => - ipfs('version').then(out => - expect(out).to.eql( - `js-ipfs version: ${pkgversion}\n` - ) - ) - ) + it('get the version', async () => { + const out = await ipfs('version') + expect(out).to.eql(`js-ipfs version: ${pkgversion}\n`) + }) - it('handles --number', () => - ipfs('version --number').then(out => - expect(out).to.eql(`${pkgversion}\n`) - ) - ) + it('handles --number', async () => { + const out = await ipfs('version --number') + expect(out).to.eql(`${pkgversion}\n`) + }) - it('handles --commit', () => - ipfs('version --commit').then(out => - expect(out).to.eql(`js-ipfs version: ${pkgversion}-\n`) - ) - ) + it('handles --commit', async () => { + const out = await ipfs('version --commit') + expect(out).to.eql(`js-ipfs version: ${pkgversion}-\n`) + }) describe('handles --all', function () { - it('prints js-ipfs version', () => - ipfs('version --all').then(out => { - expect(out).to.include(`js-ipfs version: ${pkgversion}`) - }) - ) - - it('prints repo version', () => - ipfs('version --all').then(out => { - expect(out).to.include(`Repo version: ${repoVersion}`) - }) - ) - - it('prints arch/platform', () => - ipfs('version --all').then(out => { - expect(out).to.include(`System version: ${os.arch()}/${os.platform()}`) - }) - ) - - it('prints Node.js version', () => - ipfs('version --all').then(out => { - expect(out).to.include(`Node.js version: ${process.version}`) - }) - ) + it('prints js-ipfs version', async () => { + const out = await ipfs('version --all') + expect(out).to.include(`js-ipfs version: ${pkgversion}`) + }) + + it('prints repo version', async () => { + const out = await ipfs('version --all') + expect(out).to.include(`Repo version: ${repoVersion}`) + }) + + it('prints arch/platform', async () => { + const out = await ipfs('version --all') + expect(out).to.include(`System version: ${os.arch()}/${os.platform()}`) + }) + + it('prints Node.js version', async () => { + const out = await ipfs('version --all') + expect(out).to.include(`Node.js version: ${process.version}`) + }) }) - it('handles --repo', () => - ipfs('version --repo').then(out => - expect(out).to.eql(`${repoVersion}\n`) - ) - ) + it('handles --repo', async () => { + const out = await ipfs('version --repo') + expect(out).to.eql(`${repoVersion}\n`) + }) })) diff --git a/test/core/mfs-preload.spec.js b/test/core/mfs-preload.spec.js index 61de724f8a..3c066472cf 100644 --- a/test/core/mfs-preload.spec.js +++ b/test/core/mfs-preload.spec.js @@ -8,7 +8,7 @@ const expect = chai.expect chai.use(dirtyChai) const delay = require('delay') -const waitFor = require('../utils/wait-for').promises +const waitFor = require('../utils/wait-for') const mfsPreload = require('../../src/core/mfs-preload') const createMockFilesStat = (cids = []) => { diff --git a/test/core/name-pubsub.js b/test/core/name-pubsub.js index 8d433441aa..09d940c4af 100644 --- a/test/core/name-pubsub.js +++ b/test/core/name-pubsub.js @@ -10,15 +10,13 @@ chai.use(dirtyChai) const base64url = require('base64url') const { fromB58String } = require('multihashes') -const retry = require('async/retry') -const series = require('async/series') -const callbackify = require('callbackify') const peerId = require('peer-id') const isNode = require('detect-node') const ipns = require('ipns') const IPFS = require('../../src') const waitFor = require('../utils/wait-for') -const delay = require('interface-ipfs-core/src/utils/delay') +const delay = require('delay') +const promisify = require('promisify-es6') const DaemonFactory = require('ipfsd-ctl') const df = DaemonFactory.create({ @@ -81,7 +79,7 @@ describe('name-pubsub', function () { after(() => Promise.all(nodes.map((node) => node.stop()))) - it('should publish and then resolve correctly', function (done) { + it('should publish and then resolve correctly', async function () { this.timeout(80 * 1000) let subscribed = false @@ -90,51 +88,40 @@ describe('name-pubsub', function () { subscribed = true } - const alreadySubscribed = (cb) => { - return cb(null, subscribed === true) + const alreadySubscribed = () => { + return subscribed === true } // Wait until a peer subscribes a topic - const waitForPeerToSubscribe = (node, topic, callback) => { - retry({ - times: 5, - interval: 2000 - }, (next) => { - node.pubsub.peers(topic, (error, res) => { - if (error) { - return next(error) - } - - if (!res || !res.length) { - return next(new Error(`Could not find subscription for topic ${topic}`)) - } - - return next(null, res) - }) - }, callback) + const waitForPeerToSubscribe = async (node, topic) => { + for (let i = 0; i < 5; i++) { + const res = await node.pubsub.peers(topic) + + if (res && res.length) { + return + } + + await delay(2000) + } + + throw new Error(`Could not find subscription for topic ${topic}`) } const keys = ipns.getIdKeys(fromB58String(idA.id)) const topic = `${namespace}${base64url.encode(keys.routingKey.toBuffer())}` - nodeB.name.resolve(idA.id, (err) => { - expect(err).to.exist() - - series([ - (cb) => waitForPeerToSubscribe(nodeA, topic, cb), - (cb) => nodeB.pubsub.subscribe(topic, checkMessage, cb), - (cb) => nodeA.name.publish(ipfsRef, { resolve: false }, cb), - (cb) => waitFor((callback) => alreadySubscribed(callback), cb), - (cb) => setTimeout(() => cb(), 1000), // guarantee record is written - (cb) => nodeB.name.resolve(idA.id, cb) - ], (err, res) => { - expect(err).to.not.exist() - expect(res).to.exist() - - expect(res[5]).to.equal(ipfsRef) - done() - }) - }) + await nodeB.name.resolve(idA.id) + .then(() => expect.fail('should not have been able to resolve idA.id'), (err) => expect(err).to.exist()) + + await waitForPeerToSubscribe(nodeA, topic) + await nodeB.pubsub.subscribe(topic, checkMessage) + await nodeA.name.publish(ipfsRef, { resolve: false }) + await waitFor(alreadySubscribed) + await delay(1000) // guarantee record is written + + const res = await nodeB.name.resolve(idA.id) + + expect(res).to.equal(ipfsRef) }) it('should self resolve, publish and then resolve correctly', async function () { @@ -164,7 +151,7 @@ describe('name-pubsub', function () { expect(resolveA).to.be.eq(`/ipfs/${path}`) }) - it('should handle event on publish correctly', function (done) { + it('should handle event on publish correctly', async function () { this.timeout(80 * 1000) const testAccountName = 'test-account' @@ -179,45 +166,32 @@ describe('name-pubsub', function () { publishedMessageDataValue = publishedMessageData.value.toString('utf8') } - const alreadySubscribed = (cb) => { - return cb(null, publishedMessage !== null) + const alreadySubscribed = () => { + return publishedMessage !== null } // Create account for publish - nodeA.key.gen(testAccountName, { + const testAccount = await nodeA.key.gen(testAccountName, { type: 'rsa', size: 2048 - }, (err, testAccount) => { - expect(err).to.not.exist() - - const keys = ipns.getIdKeys(fromB58String(testAccount.id)) - const topic = `${namespace}${base64url.encode(keys.routingKey.toBuffer())}` - - series([ - (cb) => nodeB.pubsub.subscribe(topic, checkMessage, cb), - (cb) => nodeA.name.publish(ipfsRef, { resolve: false, key: testAccountName }, cb), - (cb) => waitFor((callback) => alreadySubscribed(callback), cb), - (cb) => peerId.createFromPubKey(publishedMessage.key, cb), - (cb) => peerId.createFromPubKey(publishedMessageData.pubKey, cb) - ], (err, res) => { - expect(err).to.not.exist() - expect(res).to.exist() - - const messageKey = res[3] - const pubKeyPeerId = res[4] - - expect(pubKeyPeerId.toB58String()).not.to.equal(messageKey.toB58String()) - expect(pubKeyPeerId.toB58String()).to.equal(testAccount.id) - expect(publishedMessage.from).to.equal(idA.id) - expect(messageKey.toB58String()).to.equal(idA.id) - expect(publishedMessageDataValue).to.equal(ipfsRef) - - // Verify the signature - callbackify(ipns.validate.bind(ipns))(pubKeyPeerId._pubKey, publishedMessageData, (err) => { - expect(err).to.not.exist() - done() - }) - }) }) + + const keys = ipns.getIdKeys(fromB58String(testAccount.id)) + const topic = `${namespace}${base64url.encode(keys.routingKey.toBuffer())}` + + await nodeB.pubsub.subscribe(topic, checkMessage) + await nodeA.name.publish(ipfsRef, { resolve: false, key: testAccountName }) + await waitFor(alreadySubscribed) + const messageKey = await promisify(peerId.createFromPubKey)(publishedMessage.key) + const pubKeyPeerId = await promisify(peerId.createFromPubKey)(publishedMessageData.pubKey) + + expect(pubKeyPeerId.toB58String()).not.to.equal(messageKey.toB58String()) + expect(pubKeyPeerId.toB58String()).to.equal(testAccount.id) + expect(publishedMessage.from).to.equal(idA.id) + expect(messageKey.toB58String()).to.equal(idA.id) + expect(publishedMessageDataValue).to.equal(ipfsRef) + + // Verify the signature + await ipns.validate(pubKeyPeerId._pubKey, publishedMessageData) }) }) diff --git a/test/http-api/block.js b/test/http-api/block.js deleted file mode 100644 index 8fc06f8d44..0000000000 --- a/test/http-api/block.js +++ /dev/null @@ -1,100 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) -const path = require('path') -const multihash = require('multihashes') -const waterfall = require('async/waterfall') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - IpfsClient: require('ipfs-http-client') -}) - -describe('block endpoint', () => { - let ipfs = null - let ipfsd = null - - before(async function () { - this.timeout(20 * 1000) - - ipfsd = await df.spawn({ - initOptions: { bits: 512 }, - config: { Bootstrap: [] }, - args: [] - }) - ipfs = ipfsd.api - }) - - after(() => ipfsd.stop()) - - describe('.block', () => { - describe('.put', () => { - it('updates value', (done) => { - const data = Buffer.from('hello world\n') - const expectedResult = { - key: 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', - size: 12 - } - - waterfall([ - (cb) => ipfs.block.put(data, cb), - (block, cb) => { - expect(block.cid.multihash).to.eql( - multihash.fromB58String(expectedResult.key) - ) - cb() - } - ], done) - }) - }) - - describe('.get', () => { - it('returns error for request with invalid argument', (done) => { - ipfs.block.get('invalid', (err, result) => { - expect(err).to.exist() - done() - }) - }) - - it('returns value', (done) => { - ipfs.block.get('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', (err, result) => { - expect(err).to.not.exist() - expect(result.data.toString()) - .to.equal('hello world\n') - done() - }) - }) - }) - - describe('.stat', () => { - it('returns error for request without argument', (done) => { - ipfs.block.stat(null, (err, result) => { - expect(err).to.exist() - done() - }) - }) - - it('returns error for request with invalid argument', (done) => { - ipfs.block.stat('invalid', (err, result) => { - expect(err).to.exist() - done() - }) - }) - - it('returns value', (done) => { - ipfs.block.stat('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', (err, result) => { - expect(err).to.not.exist() - expect(result.key) - .to.equal('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') - expect(result.size).to.equal(12) - done() - }) - }) - }) - }) -}) diff --git a/test/http-api/bootstrap.js b/test/http-api/bootstrap.js deleted file mode 100644 index d227496d5d..0000000000 --- a/test/http-api/bootstrap.js +++ /dev/null @@ -1,149 +0,0 @@ -/* eslint max-nested-callbacks: ["error", 8] */ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) -const path = require('path') -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - IpfsClient: require('ipfs-http-client') -}) - -describe('bootstrap endpoint', () => { - let ipfs = null - let ipfsd = null - before(async function () { - this.timeout(20 * 1000) - - ipfsd = await df.spawn({ - initOptions: { bits: 512 }, - config: { - Bootstrap: [], - Discovery: { - MDNS: { - Enabled: false - }, - webRTCStar: { - Enabled: false - } - } - } - }) - ipfs = ipfsd.api - }) - - after(() => ipfsd.stop()) - - describe('.bootstrap', () => { - const invalidArg = 'this/Is/So/Invalid/' - const validIp4 = '/ip4/101.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z' - let peers - - describe('.add', function () { - this.timeout(40 * 1000) - - it('returns an error when called with an invalid arg', (done) => { - ipfs.bootstrap.add(invalidArg, (err) => { - expect(err).to.be.an.instanceof(Error) - done() - }) - }) - - it('returns a list of containing the bootstrap peer when called with a valid arg (ip4)', (done) => { - ipfs.bootstrap.add(validIp4, (err, res) => { - expect(err).to.not.exist() - expect(res).to.be.eql({ Peers: [validIp4] }) - done() - }) - }) - - it('prevents duplicate inserts of bootstrap peers', () => { - return ipfs - .bootstrap - .rm(null, { all: true }) - .then((res) => { - expect(res.Peers.length).to.equal(0) - return ipfs.bootstrap.add(validIp4) - }) - .then(res => { - expect(res).to.be.eql({ Peers: [validIp4] }) - return ipfs.bootstrap.add(validIp4) - }) - .then((res) => { - expect(res).to.be.eql({ Peers: [validIp4] }) - return ipfs.bootstrap.list() - }) - .then((res) => { - expect(res).to.exist() - const insertPosition = res.Peers.indexOf(validIp4) - expect(insertPosition).to.not.equal(-1) - expect(res.Peers.length).to.equal(1) - }) - }) - - it('returns a list of bootstrap peers when called with the default option', (done) => { - ipfs.bootstrap.add({ default: true }, (err, res) => { - expect(err).to.not.exist() - peers = res.Peers - expect(peers).to.exist() - expect(peers.length).to.be.above(1) - done() - }) - }) - }) - - describe('.list', () => { - it('returns a list of peers', (done) => { - ipfs.bootstrap.list((err, res) => { - expect(err).to.not.exist() - peers = res.Peers - expect(peers).to.exist() - done() - }) - }) - }) - - describe('.rm', () => { - it('returns an error when called with an invalid arg', (done) => { - ipfs.bootstrap.rm(invalidArg, (err) => { - expect(err).to.be.an.instanceof(Error) - done() - }) - }) - - it('returns empty list because no peers removed when called without an arg or options', (done) => { - ipfs.bootstrap.rm(null, (err, res) => { - expect(err).to.not.exist() - peers = res.Peers - expect(peers).to.exist() - expect(peers.length).to.eql(0) - done() - }) - }) - - it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => { - ipfs.bootstrap.rm(validIp4, (err, res) => { - expect(err).to.not.exist() - - peers = res.Peers - expect(peers).to.exist() - expect(peers.length).to.eql(1) - done() - }) - }) - - it('returns list of all peers removed when all option is passed', (done) => { - ipfs.bootstrap.rm(null, { all: true }, (err, res) => { - expect(err).to.not.exist() - peers = res.Peers - expect(peers).to.exist() - done() - }) - }) - }) - }) -}) diff --git a/test/http-api/config.js b/test/http-api/config.js deleted file mode 100644 index a27439825f..0000000000 --- a/test/http-api/config.js +++ /dev/null @@ -1,144 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) - -const promisify = require('promisify-es6') -const ncp = promisify(require('ncp').ncp) -const rimraf = promisify(require('rimraf')) - -const isWindows = require('../utils/platforms').isWindows -const skipOnWindows = isWindows() ? describe.skip : describe - -const fs = require('fs') -const path = require('path') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - IpfsClient: require('ipfs-http-client') -}) - -skipOnWindows('config endpoint', () => { - const repoExample = path.join(__dirname, '../fixtures/go-ipfs-repo') - const repoPath = path.join(__dirname, '../repo-tests-run') - - let updatedConfig = null - - let ipfs = null - let ipfsd = null - - // wait until the repo is ready to use - before(function (done) { - this.timeout(10 * 1000) - - setTimeout(done, 5 * 1000) - }) - - before(async function () { - this.timeout(20 * 1000) - - await ncp(repoExample, repoPath) - - ipfsd = await df.spawn({ - repoPath: repoPath, - initOptions: { bits: 512 }, - config: { Bootstrap: [] }, - disposable: false, - start: true - }) - await ipfsd.start() - ipfs = ipfsd.api - - updatedConfig = () => { - const config = fs.readFileSync(path.join(__dirname, '../repo-tests-run/config')) - return JSON.parse(config, 'utf8') - } - }) - - after(async function () { - this.timeout(50 * 1000) - await rimraf(repoPath) - await ipfsd.stop() - }) - - describe('.config', () => { - it('.get returns error for request with invalid argument', (done) => { - ipfs.config.get('kittens', (err, res) => { - expect(err).to.exist() - done() - }) - }) - - it('.get returns value for request with argument', (done) => { - ipfs.config.get('API.HTTPHeaders', (err, value) => { - expect(err).not.to.exist() - expect(value).to.equal(null) - done() - }) - }) - - it('.set updates value for request with both args', (done) => { - ipfs.config.set('Datastore.Path', 'kitten', (err) => { - expect(err).not.to.exist() - done() - }) - }) - - it('.set returns error for request with both args and JSON flag with invalid JSON argument', (done) => { - ipfs.config.set('Datastore.Path', 'kitten', { json: true }, (err) => { - expect(err).to.exist() - done() - }) - }) - - it('.set updates value for request with both args and bool flag and true argument', (done) => { - ipfs.config.set('Datastore.Path', true, (err) => { - expect(err).not.to.exist() - done() - }) - }) - - it('.set updates value for request with both args and bool flag and false argument', (done) => { - ipfs.config.set('Datastore.Path', false, (err) => { - expect(err).not.to.exist() - done() - }) - }) - - it('.get updatedConfig', (done) => { - ipfs.config.get((err, config) => { - expect(err).not.to.exist() - expect(config).to.be.eql(updatedConfig()) - done() - }) - }) - - // This one is one stale mode till go-ipfs decides - // what to do with the .replace command - describe.skip('.replace', () => { - it('returns error if the config is invalid', (done) => { - const filePath = 'test/fixtures/test-data/badconfig' - - ipfs.config.replace(filePath, (err) => { - expect(err).to.exist() - done() - }) - }) - - it('updates value', (done) => { - const filePath = 'test/fixtures/test-data/otherconfig' - const expectedConfig = JSON.parse(fs.readFileSync(filePath, 'utf8')) - - ipfs.config.replace(filePath, (err) => { - expect(err).not.to.exist() - expect(expectedConfig).to.deep.equal(updatedConfig()) - done() - }) - }) - }) - }) -}) diff --git a/test/http-api/dns.js b/test/http-api/dns.js deleted file mode 100644 index 2003a838c0..0000000000 --- a/test/http-api/dns.js +++ /dev/null @@ -1,40 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) -const path = require('path') -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - IpfsClient: require('ipfs-http-client') -}) - -describe('dns endpoint', () => { - let ipfs = null - let ipfsd = null - before(async function () { - this.timeout(20 * 1000) - ipfsd = await df.spawn({ - initOptions: { bits: 512 }, - config: { Bootstrap: [] } - }) - ipfs = ipfsd.api - }) - - after(() => ipfsd.stop()) - - describe('.dns', () => { - it('resolve ipfs.io dns', function (done) { - this.timeout(40 * 1000) - - ipfs.dns('ipfs.io', (err, result) => { - expect(err).to.not.exist() - expect(result).to.exist() - done() - }) - }) - }) -}) diff --git a/test/http-api/files.js b/test/http-api/files.js deleted file mode 100644 index fc68c07266..0000000000 --- a/test/http-api/files.js +++ /dev/null @@ -1,409 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 8] */ -'use strict' - -const hat = require('hat') -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const DaemonFactory = require('ipfsd-ctl') -const expect = chai.expect -chai.use(dirtyChai) -const { - FILE_TYPES -} = require('ipfs-mfs') -const path = require('path') -const df = DaemonFactory.create({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - IpfsClient: require('ipfs-http-client') -}) - -describe('.files', () => { - let ipfs = null - let ipfsd = null - before(async function () { - this.timeout(20 * 1000) - ipfsd = await df.spawn({ - initOptions: { bits: 512 }, - config: { Bootstrap: [] } - }) - ipfs = ipfsd.api - }) - - after(function () { - this.timeout(20 * 1000) - if (ipfsd) { - return ipfsd.stop() - } - }) - - describe('.add', function () { - it('performs a speculative add, --only-hash', () => { - const content = hat() - - return ipfs.add(Buffer.from(content), { onlyHash: true }) - .then(files => { - const getAttempt = ipfs.object.get(files[0].hash) - .then(() => { - throw new Error('Should not find an object for content added with --only-hash') - }) - - return Promise.race([ - getAttempt, - new Promise((resolve, reject) => setTimeout(resolve, 4000)) - ]) - }) - }) - }) - - describe('.ls', function () { - it('lists empty directory', () => { - return ipfs.files.ls() - .then(files => { - expect(files).to.be.empty() - }) - }) - - it('lists files', () => { - const fileName = `single-file-${hat()}.txt` - - return ipfs.files.write(`/${fileName}`, Buffer.from('Hello world'), { - create: true - }) - .then(() => ipfs.files.ls()) - .then(files => { - expect(files.length).to.equal(1) - expect(files[0].name).to.equal(fileName) - }) - }) - - it('lists files in directories', () => { - const dirName = `dir-${hat()}` - const fileName = `file-in-dir-${hat()}.txt` - - return ipfs.files.write(`/${dirName}/${fileName}`, Buffer.from('Hello world'), { - create: true, - parents: true - }) - .then(() => ipfs.files.ls(`/${dirName}`)) - .then(files => { - expect(files.length).to.equal(1) - expect(files[0].name).to.equal(fileName) - }) - }) - }) - - describe('.cp', function () { - it('copies a file', () => { - const source = `source-file-${hat()}.txt` - const destination = `destination-file-${hat()}.txt` - - return ipfs.files.write(`/${source}`, Buffer.from('Hello world'), { - create: true - }) - .then(() => ipfs.files.cp(`/${source}`, `/${destination}`)) - .then(() => ipfs.files.ls('/', { - long: true - })) - .then(files => { - const sourceFile = files - .filter(file => file.name === source) - .pop() - - expect(sourceFile.type).to.equal(FILE_TYPES.file) - - const destFile = files - .filter(file => file.name === destination) - .pop() - - expect(destFile.type).to.equal(FILE_TYPES.file) - }) - }) - - it('copies a directory', () => { - const source = `source-dir-${hat()}` - const destination = `destination-dir-${hat()}` - - return ipfs.files.mkdir(`/${source}`) - .then(() => ipfs.files.cp(`/${source}`, `/${destination}`)) - .then(() => ipfs.files.ls('/', { - long: true - })) - .then(files => { - const sourceDir = files - .filter(file => file.name === source) - .pop() - - expect(sourceDir.type).to.equal(FILE_TYPES.directory) - - const destDir = files - .filter(file => file.name === destination) - .pop() - - expect(destDir.type).to.equal(FILE_TYPES.directory) - }) - }) - - it('copies a file with array args', () => { - const source = `source-file-${hat()}.txt` - const destination = `destination-file-${hat()}.txt` - - return ipfs.files.write(`/${source}`, Buffer.from('Hello world'), { - create: true - }) - .then(() => ipfs.files.cp([`/${source}`, `/${destination}`])) - .then(() => ipfs.files.ls('/', { - long: true - })) - .then(files => { - const sourceFile = files - .filter(file => file.name === source) - .pop() - - expect(sourceFile.type).to.equal(FILE_TYPES.file) - - const destFile = files - .filter(file => file.name === destination) - .pop() - - expect(destFile.type).to.equal(FILE_TYPES.file) - }) - }) - - it('copies a directory with array args', () => { - const source = `source-dir-${hat()}` - const destination = `destination-dir-${hat()}` - - return ipfs.files.mkdir(`/${source}`) - .then(() => ipfs.files.cp([`/${source}`, `/${destination}`])) - .then(() => ipfs.files.ls('/', { - long: true - })) - .then(files => { - const sourceDir = files - .filter(file => file.name === source) - .pop() - - expect(sourceDir.type).to.equal(FILE_TYPES.directory) - - const destDir = files - .filter(file => file.name === destination) - .pop() - - expect(destDir.type).to.equal(FILE_TYPES.directory) - }) - }) - }) - - describe('.mkdir', function () { - it('makes a directory', () => { - const directory = `directory-${hat()}` - - return ipfs.files.mkdir(`/${directory}`) - .then(() => ipfs.files.ls('/', { - long: true - })) - .then(files => { - const dir = files - .filter(file => file.name === directory) - .pop() - - expect(dir.type).to.equal(FILE_TYPES.directory) - }) - }) - }) - - describe('.mv', function () { - it('moves a file', () => { - const source = `source-file-${hat()}.txt` - const destination = `destination-file-${hat()}.txt` - - return ipfs.files.write(`/${source}`, Buffer.from('Hello world'), { - create: true - }) - .then(() => ipfs.files.mv(`/${source}`, `/${destination}`)) - .then(() => ipfs.files.ls('/')) - .then(files => { - const sourceFile = files - .filter(file => file.name === source) - .pop() - - expect(sourceFile).to.not.exist() - - const destFile = files - .filter(file => file.name === destination) - .pop() - - expect(destFile.type).to.equal(FILE_TYPES.file) - }) - }) - - it('moves a directory', () => { - const source = `source-dir-${hat()}` - const destination = `destination-dir-${hat()}` - - return ipfs.files.mkdir(`/${source}`) - .then(() => ipfs.files.mv(`/${source}`, `/${destination}`)) - .then(() => ipfs.files.ls('/', { - long: true - })) - .then(files => { - const sourceDir = files - .filter(file => file.name === source) - .pop() - - expect(sourceDir).to.not.exist() - - const destDir = files - .filter(file => file.name === destination) - .pop() - - expect(destDir.type).to.equal(FILE_TYPES.directory) - }) - }) - - it('moves a file with array args', () => { - const source = `source-file-${hat()}.txt` - const destination = `destination-file-${hat()}.txt` - - return ipfs.files.write(`/${source}`, Buffer.from('Hello world'), { - create: true - }) - .then(() => ipfs.files.mv([`/${source}`, `/${destination}`])) - .then(() => ipfs.files.ls('/')) - .then(files => { - const sourceFile = files - .filter(file => file.name === source) - .pop() - - expect(sourceFile).to.not.exist() - - const destFile = files - .filter(file => file.name === destination) - .pop() - - expect(destFile.type).to.equal(FILE_TYPES.file) - }) - }) - - it('moves a directory with array args', () => { - const source = `source-dir-${hat()}` - const destination = `destination-dir-${hat()}` - - return ipfs.files.mkdir(`/${source}`) - .then(() => ipfs.files.mv([`/${source}`, `/${destination}`])) - .then(() => ipfs.files.ls('/', { - long: true - })) - .then(files => { - const sourceDir = files - .filter(file => file.name === source) - .pop() - - expect(sourceDir).to.not.exist() - - const destDir = files - .filter(file => file.name === destination) - .pop() - - expect(destDir.type).to.equal(FILE_TYPES.directory) - }) - }) - }) - - describe('.read', function () { - it('reads a file', () => { - const fileName = `single-file-${hat()}.txt` - const content = Buffer.from('Hello world') - - return ipfs.files.write(`/${fileName}`, content, { - create: true - }) - .then(() => ipfs.files.read(`/${fileName}`)) - .then(buffer => { - expect(buffer).to.deep.equal(content) - }) - }) - }) - - describe('.rm', function () { - it('removes a file', () => { - const fileName = `single-file-${hat()}.txt` - - return ipfs.files.write(`/${fileName}`, Buffer.from('Hello world'), { - create: true - }) - .then(() => ipfs.files.rm(`/${fileName}`)) - .then(() => ipfs.files.ls('/')) - .then(files => { - const file = files - .filter(file => file.name === fileName) - .pop() - - expect(file).to.not.exist() - }) - }) - - it('removes a directory', () => { - const dirName = `dir-${hat()}` - const fileName = `file-in-dir-${hat()}.txt` - - return ipfs.files.write(`/${dirName}/${fileName}`, Buffer.from('Hello world'), { - create: true, - parents: true - }) - .then(() => ipfs.files.rm(`/${dirName}`, { - recursive: true - })) - .then(() => ipfs.files.ls('/')) - .then(files => { - const dir = files - .filter(file => file.name === dirName) - .pop() - - expect(dir).to.not.exist() - }) - }) - }) - - describe('.stat', function () { - it('stats a file', () => { - const fileName = `single-file-${hat()}.txt` - - return ipfs.files.write(`/${fileName}`, Buffer.from('Hello world'), { - create: true - }) - .then(() => ipfs.files.stat(`/${fileName}`)) - .then(stats => { - expect(stats).to.deep.equal({ - blocks: 1, - cumulativeSize: 69, - hash: 'Qmetpc7cZmN25Wcc6R27cGCAvCDqCS5GjHG4v7xABEfpmJ', - local: undefined, - size: 11, - sizeLocal: undefined, - type: 'file', - withLocality: false - }) - }) - }) - - it('stats a directory', () => { - const dirName = `dir-${hat()}` - - return ipfs.files.mkdir(`/${dirName}`) - .then(() => ipfs.files.stat(`/${dirName}`)) - .then(stats => { - expect(stats).to.deep.equal({ - blocks: 0, - cumulativeSize: 4, - hash: 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn', - local: undefined, - size: 0, - sizeLocal: undefined, - type: 'directory', - withLocality: false - }) - }) - }) - }) -}) diff --git a/test/http-api/id.js b/test/http-api/id.js deleted file mode 100644 index 9804b6b343..0000000000 --- a/test/http-api/id.js +++ /dev/null @@ -1,71 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) - -const promisify = require('promisify-es6') -const ncp = promisify(require('ncp').ncp) -const rimraf = promisify(require('rimraf')) -const path = require('path') - -const isWindows = require('../utils/platforms').isWindows -const skipOnWindows = isWindows() ? describe.skip : describe - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - IpfsClient: require('ipfs-http-client') -}) - -skipOnWindows('id endpoint', () => { - const repoExample = path.join(__dirname, '../fixtures/go-ipfs-repo') - const repoPath = path.join(__dirname, '../repo-tests-run') - - let ipfs = null - let ipfsd = null - before(async function () { - this.timeout(20 * 1000) - - await ncp(repoExample, repoPath) - ipfsd = await df.spawn({ - repoPath: repoPath, - initOptions: { bits: 512 }, - config: { Bootstrap: [] }, - disposable: false, - start: true - }) - await ipfsd.start() - ipfs = ipfsd.api - }) - - after(async () => { - await rimraf(repoPath) - return ipfsd.stop() - }) - - describe('.id', () => { - it('get the identity', (done) => { - ipfs.id((err, result) => { - expect(err).to.not.exist() - expect(result.id).to.equal(idResult.ID) - expect(result.publicKey).to.equal(idResult.PublicKey) - const agentComponents = result.agentVersion.split('/') - expect(agentComponents).lengthOf.above(1) - expect(agentComponents[0]).to.equal(idResult.AgentVersion) - expect(result.protocolVersion).to.equal(idResult.ProtocolVersion) - done() - }) - }) - }) -}) - -const idResult = { - ID: 'QmTuh8pVDCz5kbShrK8MJsJgTycCcGwZm8hQd8SxdbYmby', - PublicKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCiyLgGRpuGiorm6FzvBbrTU60e6iPMmwXL9mXyGitepQyeN7XF8e6cooFeJI/NIyvbmpa7rHCDzTWP+6ebIMOXjUjQDAgaYdHywKbAXi2cgh96yuTN+cfPJ0IVA1/4Xsn/mnaMmSNDxqnK3fExEDxZizL9iI7KQCGOHociwjNj2cqaz+4ldTQ6QBbqa8nBMbulUNtSzwihQHTHNVwhuYFGPXIIK8UhM1VR20HcCbX+TZ9RpBWLIGZgjJl2ClW7wLW1OAb55I/9CK6AmfOriVYSBxZSFi2jiPCGQmuzfiqEke6/hSZtxe8DRo8ELOQ9K2P3L27H2az2atis2FoqVY2LAgMBAAE=', - Addresses: ['/ip4/0.0.0.0/tcp/0'], - AgentVersion: 'js-ipfs', - ProtocolVersion: '9000' -} diff --git a/test/http-api/index.js b/test/http-api/index.js index a4cceb57a9..0c4cb6d793 100644 --- a/test/http-api/index.js +++ b/test/http-api/index.js @@ -1,12 +1,4 @@ 'use strict' -require('./block') -require('./bootstrap') -require('./config') -require('./dns') -require('./id') require('./routes') require('./interface') -require('./object') -require('./version') -require('./files') diff --git a/test/http-api/inject/bitswap.js b/test/http-api/inject/bitswap.js index c8dc80ca55..44c265267e 100644 --- a/test/http-api/inject/bitswap.js +++ b/test/http-api/inject/bitswap.js @@ -3,7 +3,7 @@ const expect = require('chai').expect const CID = require('cids') -const waitFor = require('../../utils/wait-for').promises +const waitFor = require('../../utils/wait-for') module.exports = (http) => { describe('/bitswap', () => { diff --git a/test/http-api/object.js b/test/http-api/object.js deleted file mode 100644 index e60235b470..0000000000 --- a/test/http-api/object.js +++ /dev/null @@ -1,368 +0,0 @@ -/* eslint max-nested-callbacks: ["error", 8] */ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) -const path = require('path') -const fs = require('fs') -const dagPB = require('ipld-dag-pb') -const DAGLink = dagPB.DAGLink - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - IpfsClient: require('ipfs-http-client') -}) - -function asJson (cb) { - return (err, result) => { - expect(err).to.not.exist() - const nodeJSON = result.toJSON() - cb(null, nodeJSON) - } -} - -describe('object endpoint', () => { - let ipfs = null - let ipfsd = null - before(async function () { - this.timeout(20 * 1000) - - ipfsd = await df.spawn({ - initOptions: { bits: 512 }, - config: { - Bootstrap: [], - Discovery: { - MDNS: { - Enabled: false - }, - webRTCStar: { - Enabled: false - } - } - } - }) - ipfs = ipfsd.api - }) - - after(() => ipfsd.stop()) - - describe('.object', () => { - it('.new', (done) => { - ipfs.object.new((err, cid) => { - expect(err).to.not.exist() - expect(cid.toBaseEncodedString()) - .to.equal('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n') - - ipfs.object.get(cid, asJson((err, res) => { - expect(err).to.not.exist() - expect(res.links).to.be.eql([]) - done() - })) - }) - }) - - describe('.get', () => { - it('returns error for request without argument', (done) => { - ipfs.object.get(null, (err, result) => { - expect(err).to.exist() - done() - }) - }) - - it('returns error for request with invalid argument', (done) => { - ipfs.object.get('invalid', { enc: 'base58' }, (err, result) => { - expect(err).to.exist() - done() - }) - }) - - it('returns value', (done) => { - ipfs.object.get('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n', { enc: 'base58' }, asJson((err, res) => { - expect(err).to.not.exist() - expect(res.links).to.be.eql([]) - expect(res.data).to.eql(Buffer.from('')) - done() - })) - }) - }) - - describe('.put', () => { - it('returns error if the node is invalid', (done) => { - const filePath = 'test/fixtures/test-data/badnode.json' - - ipfs.object.put(filePath, { enc: 'json' }, (err) => { - expect(err).to.exist() - done() - }) - }) - - it('updates value', (done) => { - const filePath = fs.readFileSync('test/fixtures/test-data/node.json') - const expectedResult = { - data: Buffer.from('another'), - links: [{ - name: 'some link', - cid: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V', - size: 8 - }], - size: 68 - } - - ipfs.object.put(filePath, { enc: 'json' }, (err, cid) => { - expect(err).to.not.exist() - expect(cid.toBaseEncodedString()) - .to.equal('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm') - - ipfs.object.get(cid, asJson((err, res) => { - expect(err).to.not.exist() - expect(res).to.eql(expectedResult) - done() - })) - }) - }) - }) - - describe('.stat', () => { - it('returns error for request without argument', (done) => { - ipfs.object.stat(null, (err, result) => { - expect(err).to.exist() - done() - }) - }) - - it('returns error for request with invalid argument', (done) => { - ipfs.object.stat('invalid', { enc: 'base58' }, (err, result) => { - expect(err).to.exist() - done() - }) - }) - - it('returns value', (done) => { - ipfs.object.stat('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm', { enc: 'base58' }, (err, result) => { - expect(err).to.not.exist() - expect(result.Hash).to.equal('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm') - expect(result.NumLinks).to.equal(1) - expect(result.BlockSize).to.equal(60) - expect(result.LinksSize).to.equal(60 - 7) - expect(result.DataSize).to.equal(7) - expect(result.CumulativeSize).to.equal(60 + 8) - done() - }) - }) - }) - - describe('.data', () => { - it('returns error for request without argument', (done) => { - ipfs.object.data(null, (err, result) => { - expect(err).to.exist() - done() - }) - }) - - it('returns error for request with invalid argument', (done) => { - ipfs.object.data('invalid', { enc: 'base58' }, (err, result) => { - expect(err).to.exist() - done() - }) - }) - - it('returns value', (done) => { - ipfs.object.data('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm', { enc: 'base58' }, (err, result) => { - expect(err).to.not.exist() - expect(result.toString()).to.equal('another') - done() - }) - }) - }) - - describe('.links', () => { - it('returns error for request without argument', (done) => { - ipfs.object.links(null, (err, result) => { - expect(err).to.exist() - done() - }) - }) - - it('returns error for request with invalid argument', (done) => { - ipfs.object.links('invalid', { enc: 'base58' }, (err, result) => { - expect(err).to.exist() - done() - }) - }) - - it('returns value', (done) => { - const expectedResult = { - name: 'some link', - cid: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V', - size: 8 - } - - ipfs.object.links('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm', { enc: 'base58' }, (err, result) => { - expect(err).to.not.exist() - expect(result[0].toJSON()).to.deep.equal(expectedResult) - done() - }) - }) - }) - - describe('.patch.appendData', () => { - it('returns error for request without key & data', (done) => { - ipfs.object.patch.appendData(null, null, (err) => { - expect(err).to.exist() - done() - }) - }) - - it('returns error for request without data', (done) => { - const filePath = 'test/fixtures/test-data/badnode.json' - - ipfs.object.patch.appendData(null, filePath, (err) => { - expect(err).to.exist() - done() - }) - }) - - it('updates value', (done) => { - const key = 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n' - const filePath = 'test/fixtures/test-data/badnode.json' - const expectedResult = { - data: fs.readFileSync(filePath), - links: [], - size: 19 - } - - ipfs.object.patch.appendData(key, filePath, { enc: 'base58' }, (err, cid) => { - expect(err).to.not.exist() - expect(cid.toBaseEncodedString()) - .to.equal('QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6') - - ipfs.object.get(cid, asJson((err, res) => { - expect(err).to.not.exist() - expect(res).to.eql(expectedResult) - done() - })) - }) - }) - }) - - describe('.patch.setData', () => { - it('returns error for request without key & data', (done) => { - ipfs.object.patch.setData(null, null, (err) => { - expect(err).to.exist() - done() - }) - }) - - it('returns error for request without data', (done) => { - const filePath = 'test/fixtures/test-data/badnode.json' - - ipfs.object.patch.setData(null, filePath, (err) => { - expect(err).to.exist() - done() - }) - }) - - it('updates value', (done) => { - const key = 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6' - const filePath = 'test/fixtures/test-data/badnode.json' - const expectedResult = { - data: fs.readFileSync(filePath), - links: [], - size: 19 - } - - ipfs.object.patch.setData(key, filePath, { enc: 'base58' }, (err, cid) => { - expect(err).to.not.exist() - expect(cid.toBaseEncodedString()) - .to.equal('QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6') - - ipfs.object.get(cid, asJson((err, res) => { - expect(err).to.not.exist() - expect(res).to.eql(expectedResult) - done() - })) - }) - }) - }) - - describe('.patch.addLink', () => { - it('returns error for request without arguments', (done) => { - ipfs.object.patch.addLink(null, null, null, (err) => { - expect(err).to.exist() - done() - }) - }) - - it('returns error for request only one invalid argument', (done) => { - ipfs.object.patch.addLink('invalid', null, null, (err) => { - expect(err).to.exist() - done() - }) - }) - - it('returns error for request without name', (done) => { - const root = 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' - const name = '' - const ref = 'QmTz3oc4gdpRMKP2sdGUPZTAGRngqjsi99BPoztyP53JMM' - const link = new DAGLink(name, 2, ref) - ipfs.object.patch.addLink(root, link, { enc: 'base58' }, (err) => { - expect(err).to.exist() - done() - }) - }) - - it('updates value', (done) => { - const root = 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n' - const name = 'foo' - const ref = 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' - const link = new DAGLink(name, 10, ref) - - ipfs.object.patch.addLink(root, link, { enc: 'base58' }, (err, cid) => { - expect(err).not.to.exist() - expect(cid.toBaseEncodedString()) - .to.equal('QmdVHE8fUD6FLNLugtNxqDFyhaCgdob372hs6BYEe75VAK') - - ipfs.object.get(cid, asJson((err, res) => { - expect(err).to.not.exist() - expect(res.links[0]).to.eql({ - name: 'foo', - cid: 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn', - size: 4 - }) - done() - })) - }) - }) - }) - - describe('.patch.rmLink', () => { - it('returns error for request without arguments', (done) => { - ipfs.object.patch.rmLink(null, null, (err) => { - expect(err).to.exist() - done() - }) - }) - - it('returns error for request only one invalid argument', (done) => { - ipfs.object.patch.rmLink('invalid', null, (err) => { - expect(err).to.exist() - done() - }) - }) - - it('returns error for request with invalid first argument', (done) => { - const root = '' - const link = 'foo' - - ipfs.object.patch.rmLink(root, link, (err) => { - expect(err).to.exist() - done() - }) - }) - }) - }) -}) diff --git a/test/http-api/version.js b/test/http-api/version.js deleted file mode 100644 index ef84dc792b..0000000000 --- a/test/http-api/version.js +++ /dev/null @@ -1,47 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) -const path = require('path') -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ exec: path.resolve(`${__dirname}/../../src/cli/bin.js`) }) - -describe('version endpoint', () => { - let ipfs = null - let ipfsd = null - before(async function () { - this.timeout(20 * 1000) - ipfsd = await df.spawn({ - initOptions: { bits: 512 }, - config: { - Bootstrap: [], - Discovery: { - MDNS: { - Enabled: false - }, - webRTCStar: { - Enabled: false - } - } - } - }) - ipfs = ipfsd.api - }) - - after(() => ipfsd.stop()) - - describe('.version', () => { - it('get the version', (done) => { - ipfs.version((err, result) => { - expect(err).to.not.exist() - expect(result).to.have.a.property('version') - expect(result).to.have.a.property('commit') - expect(result).to.have.a.property('repo') - done() - }) - }) - }) -}) diff --git a/test/utils/ipfs-exec.js b/test/utils/ipfs-exec.js index 0714526e96..ff657e034d 100644 --- a/test/utils/ipfs-exec.js +++ b/test/utils/ipfs-exec.js @@ -50,9 +50,6 @@ module.exports = (repoPath, opts) => { res.stdout = cp.stdout res.stderr = cp.stderr - // res.stdout.on('data', d => console.log(d+'')) - // res.stderr.on('data', d => console.log(d+'')) - return res } diff --git a/test/utils/on-and-off.js b/test/utils/on-and-off.js index d262876920..9b33de1969 100644 --- a/test/utils/on-and-off.js +++ b/test/utils/on-and-off.js @@ -16,7 +16,9 @@ const path = require('path') function off (tests) { describe('daemon off (directly to core)', function () { this.timeout(60 * 1000) - const thing = {} + const thing = { + off: true + } let repoPath before(function () { @@ -41,7 +43,9 @@ function off (tests) { function on (tests) { describe('daemon on (through http-api)', function () { this.timeout(60 * 1000) - const thing = {} + const thing = { + on: true + } let ipfsd before(async function () { diff --git a/test/utils/wait-for.js b/test/utils/wait-for.js index d610a455e2..29fc27a2c9 100644 --- a/test/utils/wait-for.js +++ b/test/utils/wait-for.js @@ -1,49 +1,15 @@ 'use strict' -// Wait for async function `test` to callback(null, true) or timeout after -// options.timeout milliseconds. -module.exports = function waitFor (test, options, callback) { - if (typeof options === 'function') { - callback = options - options = {} - } - - options = options || {} - options.timeout = options.timeout || 5000 - options.interval = options.interval || 0 - options.name = options.name || 'event' - - const start = Date.now() - - const check = () => { - test((err, arrived) => { - if (err) { - return callback(err) - } - - if (arrived) { - return callback() - } +const delay = require('delay') - if (Date.now() > start + options.timeout) { - return callback(new Error(`Timed out waiting for ${options.name}`)) - } - - setTimeout(check, options.interval) - }) - } - - check() -} - -module.exports.promises = async (test, options) => { +// Wait for async function `test` to resolve true or timeout after +// options.timeout milliseconds. +module.exports = async function waitFor (test, options) { options = Object.assign({ timeout: 5000, interval: 0, name: 'event' }, options) const start = Date.now() while (true) { - const arrived = await test() - - if (arrived) { + if (await test()) { return } @@ -51,6 +17,6 @@ module.exports.promises = async (test, options) => { throw new Error(`Timed out waiting for ${options.name}`) } - await new Promise(resolve => setTimeout(resolve, options.interval)) + await delay(options.interval) } }