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

Commit 75f8899

Browse files
committed
feat: block API updated to use CID
1 parent 3fdad1c commit 75f8899

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "interface-ipfs-core",
33
"version": "0.15.0",
44
"description": "A test suite and interface you can use to implement a IPFS core interface.",
5-
"main": "lib/index.js",
5+
"main": "src/index.js",
66
"jsnext:main": "src/index.js",
77
"scripts": {
88
"test": "exit(0)",
@@ -51,4 +51,4 @@
5151
"greenkeeperio-bot <support@greenkeeper.io>",
5252
"nginnever <ginneversource@gmail.com>"
5353
]
54-
}
54+
}

src/block.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
const expect = require('chai').expect
77
const Block = require('ipfs-block')
88
const multihash = require('multihashes')
9+
const CID = require('cids')
910

1011
module.exports = (common) => {
1112
describe('.block', () => {
@@ -34,23 +35,25 @@ module.exports = (common) => {
3435
describe('callback API', () => {
3536
it('.put a buffer', (done) => {
3637
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
38+
const cid = new CID(expectedHash)
3739
const blob = Buffer('blorb')
3840

39-
ipfs.block.put(blob, (err, block) => {
41+
ipfs.block.put(blob, cid, (err, block) => {
4042
expect(err).to.not.exist
41-
expect(block.key).to.eql(multihash.fromB58String(expectedHash))
43+
expect(block.key('sha2-256')).to.eql(multihash.fromB58String(expectedHash))
4244
expect(block).to.have.a.property('data', blob)
4345
done()
4446
})
4547
})
4648

4749
it('.put a block', (done) => {
4850
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
51+
const cid = new CID(expectedHash)
4952
const blob = new Block(new Buffer('blorb'))
5053

51-
ipfs.block.put(blob, (err, block) => {
54+
ipfs.block.put(blob, cid, (err, block) => {
5255
expect(err).to.not.exist
53-
expect(block.key).to.eql(multihash.fromB58String(expectedHash))
56+
expect(block.key('sha2-256')).to.eql(multihash.fromB58String(expectedHash))
5457
expect(block.data).to.eql(new Buffer('blorb'))
5558
done()
5659
})
@@ -59,26 +62,28 @@ module.exports = (common) => {
5962
it('.put error with array of blocks', () => {
6063
const blob = Buffer('blorb')
6164

62-
ipfs.block.put([blob, blob], (err) => {
65+
ipfs.block.put([blob, blob], 'fake cids', (err) => {
6366
expect(err).to.be.an.instanceof(Error)
6467
})
6568
})
6669

6770
it('block.get', (done) => {
6871
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
72+
const cid = new CID(hash)
6973

70-
ipfs.block.get(hash, (err, block) => {
74+
ipfs.block.get(cid, (err, block) => {
7175
expect(err).to.not.exist
72-
expect(block.key).to.eql(multihash.fromB58String(hash))
76+
expect(block.key('sha2-256')).to.eql(cid.multihash)
7377
expect(block.data).to.eql(new Buffer('blorb'))
7478
done()
7579
})
7680
})
7781

7882
it('block.stat', (done) => {
7983
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
84+
const cid = new CID(hash)
8085

81-
ipfs.block.stat(hash, (err, stats) => {
86+
ipfs.block.stat(cid, (err, stats) => {
8287
expect(err).to.not.exist
8388
expect(stats).to.have.property('key')
8489
expect(stats).to.have.property('size')

0 commit comments

Comments
 (0)