This repository has been 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
/
utils.js
72 lines (67 loc) · 2.38 KB
/
utils.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
60
61
62
63
64
65
66
67
68
69
70
71
72
import { expect } from 'aegir/chai'
/**
* @param {any} n
*/
const isBigInt = (n) => {
return typeof n === 'bigint'
}
/**
* @param {Error | null} err
* @param {import('ipfs-core-types/src/bitswap').Stats} stats
*/
export function expectIsBitswap (err, stats) {
expect(err).to.not.exist()
expect(stats).to.exist()
expect(stats).to.have.a.property('provideBufLen')
expect(stats).to.have.a.property('wantlist')
expect(stats).to.have.a.property('peers')
expect(stats).to.have.a.property('blocksReceived')
expect(stats).to.have.a.property('dataReceived')
expect(stats).to.have.a.property('blocksSent')
expect(stats).to.have.a.property('dataSent')
expect(stats).to.have.a.property('dupBlksReceived')
expect(stats).to.have.a.property('dupDataReceived')
expect(stats.provideBufLen).to.a('number')
expect(stats.wantlist).to.be.an('array')
expect(stats.peers).to.be.an('array')
expect(isBigInt(stats.blocksReceived)).to.eql(true)
expect(isBigInt(stats.dataReceived)).to.eql(true)
expect(isBigInt(stats.blocksSent)).to.eql(true)
expect(isBigInt(stats.dataSent)).to.eql(true)
expect(isBigInt(stats.dupBlksReceived)).to.eql(true)
expect(isBigInt(stats.dupDataReceived)).to.eql(true)
}
/**
* @param {Error | null} err
* @param {import('ipfs-core-types/src/stats').BWResult} stats
*/
export function expectIsBandwidth (err, stats) {
expect(err).to.not.exist()
expect(stats).to.exist()
expect(stats).to.have.a.property('totalIn')
expect(stats).to.have.a.property('totalOut')
expect(stats).to.have.a.property('rateIn')
expect(stats).to.have.a.property('rateOut')
expect(isBigInt(stats.totalIn)).to.eql(true)
expect(isBigInt(stats.totalOut)).to.eql(true)
expect(stats.rateIn).to.be.a('number')
expect(stats.rateOut).to.be.a('number')
}
/**
* @param {Error | null} err
* @param {import('ipfs-core-types/src/repo').StatResult} res
*/
export function expectIsRepo (err, res) {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res).to.have.a.property('numObjects')
expect(res).to.have.a.property('repoSize')
expect(res).to.have.a.property('repoPath')
expect(res).to.have.a.property('version')
expect(res).to.have.a.property('storageMax')
expect(isBigInt(res.numObjects)).to.eql(true)
expect(isBigInt(res.repoSize)).to.eql(true)
expect(isBigInt(res.storageMax)).to.eql(true)
expect(res.repoPath).to.be.a('string')
expect(res.version).to.be.a('string')
}