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

Commit

Permalink
fix: files and pubsub ci (#37)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
vasco-santos authored and Alan Shaw committed Oct 24, 2018
1 parent 1fd66fd commit b271ea8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 35 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
32 changes: 23 additions & 9 deletions test/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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))
Expand All @@ -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 }))
)
})

Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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
}
Expand Down
26 changes: 5 additions & 21 deletions test/utils/daemon.js
Original file line number Diff line number Diff line change
@@ -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)
}
Expand Down

0 comments on commit b271ea8

Please sign in to comment.