Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

chore: upgrade ipfsd-ctl #1088

Merged
merged 1 commit into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ module.exports = {
singleRun: true
},
hooks: {
pre: server.start.bind(server),
post: server.stop.bind(server)
browser: {
pre: () => server.start(),
post: () => server.stop()
}
}
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
"test:node": "aegir test -t node",
"test:browser": "aegir test -t browser",
"test:webworker": "aegir test -t webworker",
"test:electron-main": "aegir test -t electron-main",
"test:electron-renderer": "aegir test -t electron-renderer",
"test:chrome": "aegir test -t browser -t webworker -- --browsers ChromeHeadless",
"test:firefox": "aegir test -t browser -t webworker -- --browsers FirefoxHeadless",
"lint": "aegir lint",
"build": "aegir build",
"release": "aegir release ",
Expand Down Expand Up @@ -90,11 +94,12 @@
"aegir": "^20.0.0",
"browser-process-platform": "~0.1.1",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"cross-env": "^5.2.0",
"dirty-chai": "^2.0.1",
"go-ipfs-dep": "^0.4.22",
"interface-ipfs-core": "^0.111.0",
"ipfsd-ctl": "~0.43.0",
"ipfsd-ctl": "~0.45.0",
"nock": "^10.0.2",
"stream-equal": "^1.1.1"
},
Expand Down
4 changes: 2 additions & 2 deletions src/utils/send-files-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ module.exports = (send, path) => {
qs['raw-leaves'] = propOrProp(options, 'raw-leaves', 'rawLeaves')
qs['only-hash'] = propOrProp(options, 'only-hash', 'onlyHash')
qs['wrap-with-directory'] = propOrProp(options, 'wrap-with-directory', 'wrapWithDirectory')
qs['pin'] = propOrProp(options, 'pin')
qs['preload'] = propOrProp(options, 'preload')
qs.pin = propOrProp(options, 'pin')
qs.preload = propOrProp(options, 'preload')
qs.hash = propOrProp(options, 'hash', 'hashAlg')

if (options.strategy === 'trickle' || options.trickle) {
Expand Down
37 changes: 14 additions & 23 deletions test/commands.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,25 @@ describe('.commands', function () {
let ipfsd
let ipfs

before((done) => {
f.spawn({ initOptions: { bits: 1024, profile: 'test' } }, (err, _ipfsd) => {
expect(err).to.not.exist()
ipfsd = _ipfsd
ipfs = ipfsClient(_ipfsd.apiAddr)
done()
before(async () => {
ipfsd = await f.spawn({
initOptions: {
bits: 1024,
profile: 'test'
}
})
ipfs = ipfsClient(ipfsd.apiAddr)
})

after((done) => {
if (!ipfsd) return done()
ipfsd.stop(done)
after(async () => {
if (ipfsd) {
await ipfsd.stop()
}
})

it('lists commands', (done) => {
ipfs.commands((err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
done()
})
})
it('lists commands', async () => {
const res = await ipfs.commands()

describe('promise', () => {
it('lists commands', () => {
return ipfs.commands()
.then((res) => {
expect(res).to.exist()
})
})
expect(res).to.exist()
})
})
32 changes: 13 additions & 19 deletions test/constructor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,36 +109,30 @@ describe('ipfs-http-client constructor tests', () => {
let apiAddr
let ipfsd

before(function (done) {
before(async function () {
this.timeout(60 * 1000) // slow CI

f.spawn({ initOptions: { bits: 1024, profile: 'test' } }, (err, node) => {
expect(err).to.not.exist()
ipfsd = node
apiAddr = node.apiAddr.toString()
done()
})
ipfsd = await f.spawn({ initOptions: { bits: 1024, profile: 'test' } })
apiAddr = ipfsd.apiAddr.toString()
})

after((done) => {
if (!ipfsd) return done()
ipfsd.stop(done)
after(async () => {
if (ipfsd) {
await ipfsd.stop()
}
})

it('can connect to an ipfs http api', (done) => {
clientWorks(ipfsClient(apiAddr), done)
it('can connect to an ipfs http api', async () => {
await clientWorks(ipfsClient(apiAddr))
})
})
})

function clientWorks (client, done) {
client.id((err, id) => {
expect(err).to.not.exist()
async function clientWorks (client) {
const id = await client.id()

expect(id).to.have.a.property('id')
expect(id).to.have.a.property('publicKey')
done()
})
expect(id).to.have.a.property('id')
expect(id).to.have.a.property('publicKey')
}

function expectConfig (ipfs, { host, port, protocol, apiPath }) {
Expand Down
36 changes: 21 additions & 15 deletions test/custom-headers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@ describe('custom headers', function () {
let ipfs
let ipfsd
// initialize ipfs with custom headers
before(done => {
f.spawn({ initOptions: { bits: 1024, profile: 'test' } }, (err, _ipfsd) => {
expect(err).to.not.exist()
ipfsd = _ipfsd
ipfs = ipfsClient({
host: 'localhost',
port: 6001,
protocol: 'http',
headers: {
authorization: 'Bearer ' + 'YOLO'
}
})
done()
before(async () => {
ipfsd = await f.spawn({
initOptions: {
bits: 1024,
profile: 'test'
}
})

ipfs = ipfsClient({
host: 'localhost',
port: 6001,
protocol: 'http',
headers: {
authorization: 'Bearer ' + 'YOLO'
}
})
})

it('are supported', done => {
it('are supported', (done) => {
// spin up a test http server to inspect the requests made by the library
const server = require('http').createServer((req, res) => {
req.on('data', () => {})
Expand All @@ -57,5 +59,9 @@ describe('custom headers', function () {
})
})

after(done => ipfsd.stop(done))
after(async () => {
if (ipfsd) {
await ipfsd.stop()
}
})
})
88 changes: 39 additions & 49 deletions test/dag.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const chaiAsPromised = require('chai-as-promised')
const expect = chai.expect
chai.use(dirtyChai)
const series = require('async/series')
chai.use(chaiAsPromised)
const { DAGNode } = require('ipld-dag-pb')
const CID = require('cids')
const ipfsClient = require('../src')
Expand All @@ -18,67 +19,56 @@ let ipfs

describe('.dag', function () {
this.timeout(20 * 1000)
before(function (done) {
series([
(cb) => f.spawn({ initOptions: { bits: 1024, profile: 'test' } }, (err, _ipfsd) => {
expect(err).to.not.exist()
ipfsd = _ipfsd
ipfs = ipfsClient(_ipfsd.apiAddr)
cb()
})
], done)
before(async function () {
ipfsd = await f.spawn({
initOptions: {
bits: 1024,
profile: 'test'
}
})
ipfs = ipfsClient(ipfsd.apiAddr)
})

after((done) => {
if (!ipfsd) return done()
ipfsd.stop(done)
after(async () => {
if (ipfsd) {
await ipfsd.stop()
}
})

it('should be able to put and get a DAG node with format dag-pb', (done) => {
it('should be able to put and get a DAG node with format dag-pb', async () => {
const data = Buffer.from('some data')
const node = DAGNode.create(data)

ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
expect(err).to.not.exist()
cid = cid.toV0()
expect(cid.codec).to.equal('dag-pb')
cid = cid.toBaseEncodedString('base58btc')
// expect(cid).to.equal('bafybeig3t3eugdchignsgkou3ly2mmy4ic4gtfor7inftnqn3yq4ws3a5u')
expect(cid).to.equal('Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr')
ipfs.dag.get(cid, (err, result) => {
expect(err).to.not.exist()
expect(result.value.Data).to.deep.equal(data)
done()
})
})
let cid = await ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' })
cid = cid.toV0()
expect(cid.codec).to.equal('dag-pb')
cid = cid.toBaseEncodedString('base58btc')
// expect(cid).to.equal('bafybeig3t3eugdchignsgkou3ly2mmy4ic4gtfor7inftnqn3yq4ws3a5u')
expect(cid).to.equal('Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr')

const result = await ipfs.dag.get(cid)

expect(result.value.Data).to.deep.equal(data)
})

it('should be able to put and get a DAG node with format dag-cbor', (done) => {
it('should be able to put and get a DAG node with format dag-cbor', async () => {
const cbor = { foo: 'dag-cbor-bar' }
ipfs.dag.put(cbor, { format: 'dag-cbor', hashAlg: 'sha2-256' }, (err, cid) => {
expect(err).to.not.exist()
expect(cid.codec).to.equal('dag-cbor')
cid = cid.toBaseEncodedString('base32')
expect(cid).to.equal('bafyreic6f672hnponukaacmk2mmt7vs324zkagvu4hcww6yba6kby25zce')
ipfs.dag.get(cid, (err, result) => {
expect(err).to.not.exist()
expect(result.value).to.deep.equal(cbor)
done()
})
})
let cid = await ipfs.dag.put(cbor, { format: 'dag-cbor', hashAlg: 'sha2-256' })

expect(cid.codec).to.equal('dag-cbor')
cid = cid.toBaseEncodedString('base32')
expect(cid).to.equal('bafyreic6f672hnponukaacmk2mmt7vs324zkagvu4hcww6yba6kby25zce')

const result = await ipfs.dag.get(cid)

expect(result.value).to.deep.equal(cbor)
})

it('should callback with error when missing DAG resolver for multicodec from requested CID', (done) => {
ipfs.block.put(Buffer.from([0, 1, 2, 3]), {
it('should callback with error when missing DAG resolver for multicodec from requested CID', async () => {
const block = await ipfs.block.put(Buffer.from([0, 1, 2, 3]), {
cid: new CID('z8mWaJ1dZ9fH5EetPuRsj8jj26pXsgpsr')
}, (err, block) => {
expect(err).to.not.exist()

ipfs.dag.get(block.cid, (err, result) => {
expect(result).to.not.exist()
expect(err.message).to.equal('Missing IPLD format "git-raw"')
done()
})
})

await expect(ipfs.dag.get(block.cid)).to.be.rejectedWith('Missing IPLD format "git-raw"')
})
})
Loading