diff --git a/package.json b/package.json index 77e41304..dfd0e391 100644 --- a/package.json +++ b/package.json @@ -39,10 +39,10 @@ "async": "^2.6.1", "bl": "^2.0.1", "bs58": "^4.0.1", - "buffer-loader": "~0.0.1", + "buffer-loader": "~0.1.0", "chai": "^4.1.2", - "cross-env": "^5.2.0", "cids": "~0.5.3", + "cross-env": "^5.2.0", "detect-node": "^2.0.3", "dir-compare": "^1.4.0", "dirty-chai": "^2.0.1", @@ -51,10 +51,10 @@ "form-data": "^2.3.2", "go-ipfs-dep": "~0.4.17", "hat": "0.0.3", - "ipfs": "~0.31.6", - "ipfs-api": "^24.0.0", - "ipfsd-ctl": "~0.39.1", + "ipfs": "~0.33.0-rc.2", + "ipfs-api": "^25.0.0", "ipfs-unixfs": "~0.1.15", + "ipfsd-ctl": "~0.39.1", "left-pad": "^1.3.0", "libp2p-websocket-star-rendezvous": "~0.2.3", "lodash": "^4.17.10", diff --git a/test/files.js b/test/files.js index a2d83632..efee4c6b 100644 --- a/test/files.js +++ b/test/files.js @@ -94,6 +94,20 @@ const compareErrors = (...ops) => { }) } +// TODO: remove after https://github.com/crypto-browserify/randombytes/pull/16 released +const MAX_BYTES = 65536 +function randomBytes (num) { + if (num < 1) return Buffer.alloc(0) + if (num <= MAX_BYTES) return crypto.randomBytes(num) + + const chunks = Array(Math.floor(num / MAX_BYTES)) + .fill(MAX_BYTES) + .concat(num % MAX_BYTES) + .map(n => crypto.randomBytes(n)) + + return Buffer.concat(chunks) +} + describe('files', function () { this.timeout(50 * 1000) @@ -141,7 +155,7 @@ describe('files', function () { }) it('uses raw nodes for leaf data', () => { - const data = crypto.randomBytes(1024 * 300) + const data = randomBytes(1024 * 300) const testLeavesAreRaw = (daemon) => { return addFile(daemon, data) .then(file => checkNodeTypes(daemon, file)) @@ -166,8 +180,8 @@ describe('files', function () { const path = `/test-dir-${Math.random()}` return compare( - go.api.files.mkdir(path).then(() => go.api.files.mkdir(path, {p: true})), - js.api.files.mkdir(path).then(() => js.api.files.mkdir(path, {p: true})) + go.api.files.mkdir(path).then(() => go.api.files.mkdir(path, { p: true })), + js.api.files.mkdir(path).then(() => js.api.files.mkdir(path, { p: true })) ) }) @@ -229,7 +243,7 @@ describe('files', function () { }) it('big files', () => { - const data = crypto.randomBytes(1024 * 3000) + const data = randomBytes(1024 * 3000) return compare( testHashesAreEqual(go, data), @@ -238,8 +252,8 @@ describe('files', function () { }) it('files that have had data appended', () => { - const initialData = crypto.randomBytes(1024 * 300) - const appendedData = crypto.randomBytes(1024 * 300) + const initialData = randomBytes(1024 * 300) + const appendedData = randomBytes(1024 * 300) return compare( appendData(go, initialData, appendedData), @@ -249,8 +263,8 @@ describe('files', function () { it('files that have had data overwritten', () => { const bytes = 1024 * 300 - const initialData = crypto.randomBytes(bytes) - const newData = crypto.randomBytes(bytes) + const initialData = randomBytes(bytes) + const newData = randomBytes(bytes) return compare( overwriteData(go, initialData, newData), @@ -271,7 +285,7 @@ describe('files', function () { }) it('big files with CIDv1', () => { - const data = crypto.randomBytes(1024 * 3000) + const data = randomBytes(1024 * 3000) const options = { cidVersion: 1 } diff --git a/test/utils/daemon.js b/test/utils/daemon.js index c75d840a..f6d18e51 100644 --- a/test/utils/daemon.js +++ b/test/utils/daemon.js @@ -1,32 +1,16 @@ 'use strict' -const os = require('os') -const path = require('path') -const hat = require('hat') -const waterfall = require('async/waterfall') const DaemonFactory = require('ipfsd-ctl') const goDf = DaemonFactory.create() const jsDf = DaemonFactory.create({ type: 'js' }) const spawnInitAndStartDaemon = (factory) => { - const dir = path.join(os.tmpdir(), hat()) - let instance - return new Promise((resolve, reject) => { - waterfall([ - (cb) => factory.spawn({ - repoPath: dir, - disposable: false, - initOptions: { - bits: 1024 - } - }, cb), - (node, cb) => { - instance = node - instance.init(cb) - }, - (cb) => instance.start((error) => cb(error, instance)) - ], (error) => { + factory.spawn({ + initOptions: { + bits: 1024 + } + }, (error, instance) => { if (error) { return reject(error) }