This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathstat.js
59 lines (49 loc) · 1.67 KB
/
stat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* eslint-env mocha */
'use strict'
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
const { CID } = require('multiformats/cid')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const testTimeout = require('../utils/test-timeout')
/**
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
/**
* @param {Factory} factory
* @param {Object} options
*/
module.exports = (factory, options) => {
const describe = getDescribe(options)
const it = getIt(options)
describe('.block.stat', () => {
const data = uint8ArrayFromString('blorb')
/** @type {import('ipfs-core-types').IPFS} */
let ipfs
/** @type {CID} */
let cid
before(async () => {
ipfs = (await factory.spawn()).api
cid = await ipfs.block.put(data)
})
after(() => factory.clean())
it('should respect timeout option when statting a block', () => {
return testTimeout(() => ipfs.block.stat(CID.parse('QmVwdDCY4SPGVFnNCiZnX5CtzwWDn6kAM98JXzKxE3kCmn'), {
timeout: 1
}))
})
it('should stat by CID', async () => {
const stats = await ipfs.block.stat(cid)
expect(stats.cid.toString()).to.equal(cid.toString())
expect(stats).to.have.property('size', data.length)
})
it('should return error for missing argument', () => {
// @ts-expect-error invalid input
return expect(ipfs.block.stat(null)).to.eventually.be.rejected
.and.be.an.instanceOf(Error)
})
it('should return error for invalid argument', () => {
// @ts-expect-error invalid input
return expect(ipfs.block.stat('invalid')).to.eventually.be.rejected
.and.be.an.instanceOf(Error)
})
})
}