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

Commit 0c09622

Browse files
update block tests
1 parent 2b6cb0b commit 0c09622

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/block.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@ const multihash = require('multihashes')
99
const CID = require('cids')
1010

1111
function expectKey (block, expected, callback) {
12-
block.key((err, key) => {
13-
if (err) {
14-
return callback(err)
15-
}
16-
expect(key).to.be.eql(expected)
17-
callback()
18-
})
12+
expect(block.cid.multihash).to.be.eql(expected)
13+
callback()
1914
}
2015

2116
module.exports = (common) => {
@@ -44,21 +39,21 @@ module.exports = (common) => {
4439
it('.put a buffer', (done) => {
4540
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
4641
const cid = new CID(expectedHash)
47-
const blob = Buffer('blorb')
42+
const blob = new Buffer('blorb')
4843

49-
ipfs.block.put(blob, cid, (err, block) => {
44+
ipfs.block.put(blob, (err, block) => {
5045
expect(err).to.not.exist
51-
expect(block).to.have.a.property('data', blob)
46+
expect(block.data).to.be.eql(blob)
5247
expectKey(block, multihash.fromB58String(expectedHash), done)
5348
})
5449
})
5550

5651
it('.put a block', (done) => {
5752
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
5853
const cid = new CID(expectedHash)
59-
const blob = new Block(new Buffer('blorb'))
54+
const blob = new Block(new Buffer('blorb'), cid)
6055

61-
ipfs.block.put(blob, cid, (err, block) => {
56+
ipfs.block.put(blob, (err, block) => {
6257
expect(err).to.not.exist
6358
expect(block.data).to.eql(new Buffer('blorb'))
6459
expectKey(block, multihash.fromB58String(expectedHash), done)
@@ -67,7 +62,7 @@ module.exports = (common) => {
6762

6863
it('.put a block (without using CID, legacy mode)', (done) => {
6964
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
70-
const blob = new Block(new Buffer('blorb'))
65+
const blob = new Block(new Buffer('blorb'), new CID(expectedHash))
7166

7267
ipfs.block.put(blob, (err, block) => {
7368
expect(err).to.not.exist
@@ -79,7 +74,7 @@ module.exports = (common) => {
7974
it('.put error with array of blocks', (done) => {
8075
const blob = Buffer('blorb')
8176

82-
ipfs.block.put([blob, blob], 'fake cids', (err) => {
77+
ipfs.block.put([blob, blob], (err) => {
8378
expect(err).to.be.an.instanceof(Error)
8479
done()
8580
})

0 commit comments

Comments
 (0)