Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
feat: block API updated to use CID
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Oct 21, 2016
1 parent 3fdad1c commit 75f8899
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "interface-ipfs-core",
"version": "0.15.0",
"description": "A test suite and interface you can use to implement a IPFS core interface.",
"main": "lib/index.js",
"main": "src/index.js",
"jsnext:main": "src/index.js",
"scripts": {
"test": "exit(0)",
Expand Down Expand Up @@ -51,4 +51,4 @@
"greenkeeperio-bot <support@greenkeeper.io>",
"nginnever <ginneversource@gmail.com>"
]
}
}
21 changes: 13 additions & 8 deletions src/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
const expect = require('chai').expect
const Block = require('ipfs-block')
const multihash = require('multihashes')
const CID = require('cids')

module.exports = (common) => {
describe('.block', () => {
Expand Down Expand Up @@ -34,23 +35,25 @@ module.exports = (common) => {
describe('callback API', () => {
it('.put a buffer', (done) => {
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
const cid = new CID(expectedHash)
const blob = Buffer('blorb')

ipfs.block.put(blob, (err, block) => {
ipfs.block.put(blob, cid, (err, block) => {
expect(err).to.not.exist
expect(block.key).to.eql(multihash.fromB58String(expectedHash))
expect(block.key('sha2-256')).to.eql(multihash.fromB58String(expectedHash))
expect(block).to.have.a.property('data', blob)
done()
})
})

it('.put a block', (done) => {
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
const cid = new CID(expectedHash)
const blob = new Block(new Buffer('blorb'))

ipfs.block.put(blob, (err, block) => {
ipfs.block.put(blob, cid, (err, block) => {
expect(err).to.not.exist
expect(block.key).to.eql(multihash.fromB58String(expectedHash))
expect(block.key('sha2-256')).to.eql(multihash.fromB58String(expectedHash))
expect(block.data).to.eql(new Buffer('blorb'))
done()
})
Expand All @@ -59,26 +62,28 @@ module.exports = (common) => {
it('.put error with array of blocks', () => {
const blob = Buffer('blorb')

ipfs.block.put([blob, blob], (err) => {
ipfs.block.put([blob, blob], 'fake cids', (err) => {
expect(err).to.be.an.instanceof(Error)
})
})

it('block.get', (done) => {
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
const cid = new CID(hash)

ipfs.block.get(hash, (err, block) => {
ipfs.block.get(cid, (err, block) => {
expect(err).to.not.exist
expect(block.key).to.eql(multihash.fromB58String(hash))
expect(block.key('sha2-256')).to.eql(cid.multihash)
expect(block.data).to.eql(new Buffer('blorb'))
done()
})
})

it('block.stat', (done) => {
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
const cid = new CID(hash)

ipfs.block.stat(hash, (err, stats) => {
ipfs.block.stat(cid, (err, stats) => {
expect(err).to.not.exist
expect(stats).to.have.property('key')
expect(stats).to.have.property('size')
Expand Down

0 comments on commit 75f8899

Please sign in to comment.