Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit b271ea8

Browse files
vasco-santosAlan Shaw
authored andcommitted
fix: files and pubsub ci (#37)
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 1fd66fd commit b271ea8

File tree

3 files changed

+33
-35
lines changed

3 files changed

+33
-35
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
"async": "^2.6.1",
4040
"bl": "^2.0.1",
4141
"bs58": "^4.0.1",
42-
"buffer-loader": "~0.0.1",
42+
"buffer-loader": "~0.1.0",
4343
"chai": "^4.1.2",
44-
"cross-env": "^5.2.0",
4544
"cids": "~0.5.3",
45+
"cross-env": "^5.2.0",
4646
"detect-node": "^2.0.3",
4747
"dir-compare": "^1.4.0",
4848
"dirty-chai": "^2.0.1",
@@ -51,10 +51,10 @@
5151
"form-data": "^2.3.2",
5252
"go-ipfs-dep": "~0.4.17",
5353
"hat": "0.0.3",
54-
"ipfs": "~0.31.6",
55-
"ipfs-api": "^24.0.0",
56-
"ipfsd-ctl": "~0.39.1",
54+
"ipfs": "~0.33.0-rc.2",
55+
"ipfs-api": "^25.0.0",
5756
"ipfs-unixfs": "~0.1.15",
57+
"ipfsd-ctl": "~0.39.1",
5858
"left-pad": "^1.3.0",
5959
"libp2p-websocket-star-rendezvous": "~0.2.3",
6060
"lodash": "^4.17.10",

test/files.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ const compareErrors = (...ops) => {
9494
})
9595
}
9696

97+
// TODO: remove after https://github.com/crypto-browserify/randombytes/pull/16 released
98+
const MAX_BYTES = 65536
99+
function randomBytes (num) {
100+
if (num < 1) return Buffer.alloc(0)
101+
if (num <= MAX_BYTES) return crypto.randomBytes(num)
102+
103+
const chunks = Array(Math.floor(num / MAX_BYTES))
104+
.fill(MAX_BYTES)
105+
.concat(num % MAX_BYTES)
106+
.map(n => crypto.randomBytes(n))
107+
108+
return Buffer.concat(chunks)
109+
}
110+
97111
describe('files', function () {
98112
this.timeout(50 * 1000)
99113

@@ -141,7 +155,7 @@ describe('files', function () {
141155
})
142156

143157
it('uses raw nodes for leaf data', () => {
144-
const data = crypto.randomBytes(1024 * 300)
158+
const data = randomBytes(1024 * 300)
145159
const testLeavesAreRaw = (daemon) => {
146160
return addFile(daemon, data)
147161
.then(file => checkNodeTypes(daemon, file))
@@ -166,8 +180,8 @@ describe('files', function () {
166180
const path = `/test-dir-${Math.random()}`
167181

168182
return compare(
169-
go.api.files.mkdir(path).then(() => go.api.files.mkdir(path, {p: true})),
170-
js.api.files.mkdir(path).then(() => js.api.files.mkdir(path, {p: true}))
183+
go.api.files.mkdir(path).then(() => go.api.files.mkdir(path, { p: true })),
184+
js.api.files.mkdir(path).then(() => js.api.files.mkdir(path, { p: true }))
171185
)
172186
})
173187

@@ -229,7 +243,7 @@ describe('files', function () {
229243
})
230244

231245
it('big files', () => {
232-
const data = crypto.randomBytes(1024 * 3000)
246+
const data = randomBytes(1024 * 3000)
233247

234248
return compare(
235249
testHashesAreEqual(go, data),
@@ -238,8 +252,8 @@ describe('files', function () {
238252
})
239253

240254
it('files that have had data appended', () => {
241-
const initialData = crypto.randomBytes(1024 * 300)
242-
const appendedData = crypto.randomBytes(1024 * 300)
255+
const initialData = randomBytes(1024 * 300)
256+
const appendedData = randomBytes(1024 * 300)
243257

244258
return compare(
245259
appendData(go, initialData, appendedData),
@@ -249,8 +263,8 @@ describe('files', function () {
249263

250264
it('files that have had data overwritten', () => {
251265
const bytes = 1024 * 300
252-
const initialData = crypto.randomBytes(bytes)
253-
const newData = crypto.randomBytes(bytes)
266+
const initialData = randomBytes(bytes)
267+
const newData = randomBytes(bytes)
254268

255269
return compare(
256270
overwriteData(go, initialData, newData),
@@ -271,7 +285,7 @@ describe('files', function () {
271285
})
272286

273287
it('big files with CIDv1', () => {
274-
const data = crypto.randomBytes(1024 * 3000)
288+
const data = randomBytes(1024 * 3000)
275289
const options = {
276290
cidVersion: 1
277291
}

test/utils/daemon.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,16 @@
11
'use strict'
22

3-
const os = require('os')
4-
const path = require('path')
5-
const hat = require('hat')
6-
const waterfall = require('async/waterfall')
73
const DaemonFactory = require('ipfsd-ctl')
84
const goDf = DaemonFactory.create()
95
const jsDf = DaemonFactory.create({ type: 'js' })
106

117
const spawnInitAndStartDaemon = (factory) => {
12-
const dir = path.join(os.tmpdir(), hat())
13-
let instance
14-
158
return new Promise((resolve, reject) => {
16-
waterfall([
17-
(cb) => factory.spawn({
18-
repoPath: dir,
19-
disposable: false,
20-
initOptions: {
21-
bits: 1024
22-
}
23-
}, cb),
24-
(node, cb) => {
25-
instance = node
26-
instance.init(cb)
27-
},
28-
(cb) => instance.start((error) => cb(error, instance))
29-
], (error) => {
9+
factory.spawn({
10+
initOptions: {
11+
bits: 1024
12+
}
13+
}, (error, instance) => {
3014
if (error) {
3115
return reject(error)
3216
}

0 commit comments

Comments
 (0)