From 82c89350e8e16286825dc1f8c0103d3eaf390da2 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 16 Apr 2021 14:57:01 +0100 Subject: [PATCH] chore: fix types (#321) - Remove bignumber.js in favour of BigInt - Use ipld-block in favour of the old ipfs-core-types - Use blockstore from ipfs-repo instead of the old ipfs-core-types --- package.json | 12 ++-- src/decision-engine/index.js | 9 +-- src/index.js | 53 +++------------- src/network.js | 30 ++------- src/notifications.js | 2 +- src/stats/index.js | 5 +- src/stats/stat.js | 14 ++-- src/types/message/index.js | 4 +- src/types/wantlist/entry.js | 12 +--- src/types/wantlist/index.js | 4 -- src/utils/sorted-map.js | 6 -- src/want-manager/index.js | 4 -- test/bitswap-stats.js | 88 +++++++++++++------------- test/utils.spec.js | 2 +- test/utils/create-libp2p-node.js | 5 +- test/utils/create-temp-repo-browser.js | 2 - test/utils/create-temp-repo-nodejs.js | 3 - 17 files changed, 84 insertions(+), 171 deletions(-) diff --git a/package.json b/package.json index d57bf3ba..fbfabfd9 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "src" ], "scripts": { + "prepare": "npm run build", "build": "npm run build:proto && npm run build:proto-types && npm run build:bundle", "build:proto": "pbjs -t static-module -w commonjs --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/types/message/message.js src/types/message/message.proto", "build:proto-types": "pbts -o src/types/message/message.d.ts src/types/message/message.js", @@ -70,15 +71,15 @@ "assert": "^2.0.0", "benchmark": "^2.1.4", "delay": "^5.0.0", - "ipfs-repo": "^9.0.0", + "ipfs-repo": "^9.1.0", "ipfs-utils": "^6.0.1", "iso-random-stream": "^2.0.0", "it-all": "^1.0.5", "it-drain": "^1.0.4", - "libp2p": "^0.30.9", + "libp2p": "0.31.0-rc.0", "libp2p-kad-dht": "^0.21.0", "libp2p-mplex": "^0.10.2", - "libp2p-secio": "^0.13.1", + "libp2p-noise": "^2.0.5", "libp2p-tcp": "^0.15.3", "lodash.difference": "^4.5.0", "lodash.flatten": "^4.4.0", @@ -97,16 +98,15 @@ "dependencies": { "abort-controller": "^3.0.0", "any-signal": "^2.1.2", - "bignumber.js": "^9.0.0", "cids": "^1.1.6", "debug": "^4.2.0", - "ipfs-core-types": "^0.3.1", "ipld-block": "^0.11.0", "it-length-prefixed": "^5.0.2", "it-pipe": "^1.1.0", "just-debounce-it": "^1.1.0", - "libp2p-interfaces": "^0.8.3", + "libp2p-interfaces": "^0.10.0", "moving-average": "^1.0.1", + "multiaddr": "^9.0.1", "multicodec": "^3.0.1", "multihashing-async": "^2.1.2", "native-abort-controller": "^1.0.3", diff --git a/src/decision-engine/index.js b/src/decision-engine/index.js index 39541acd..2e0ba543 100644 --- a/src/decision-engine/index.js +++ b/src/decision-engine/index.js @@ -1,9 +1,9 @@ 'use strict' /** - * @typedef {import('peer-id')} PeerId - * @typedef {import('ipfs-core-types/src/block-service').Block} Block + * @typedef {import('ipld-block')} Block * @typedef {import('../types/message/entry')} BitswapMessageEntry + * @typedef {import('peer-id')} PeerId */ const CID = require('cids') @@ -34,7 +34,7 @@ const MAX_SIZE_REPLACE_HAS_WITH_BLOCK = 1024 class DecisionEngine { /** * @param {PeerId} peerId - * @param {import('ipfs-core-types/src/block-store').BlockStore} blockstore + * @param {import('ipfs-repo').Blockstore} blockstore * @param {import('../network')} network * @param {import('../stats')} stats * @param {Object} [opts] @@ -180,15 +180,16 @@ class DecisionEngine { /** * @param {PeerId} peerId - * @returns {import('ipfs-core-types/src/bitswap').LedgerForPeer|null} */ ledgerForPeer (peerId) { const peerIdStr = peerId.toB58String() const ledger = this.ledgerMap.get(peerIdStr) + if (!ledger) { return null } + return { peer: ledger.partner.toPrint(), value: ledger.debtRatio(), diff --git a/src/index.js b/src/index.js index 3a6af632..b0fafc7c 100644 --- a/src/index.js +++ b/src/index.js @@ -10,11 +10,7 @@ const { AbortController } = require('native-abort-controller') const { anySignal } = require('any-signal') /** - * @typedef {import('ipfs-core-types/src/basic').AbortOptions} AbortOptions - * @typedef {import('ipfs-core-types/src/bitswap').Bitswap} API - * @typedef {import('ipfs-core-types/src/bitswap').WantListEntry} WantListEntry - * @typedef {import('ipfs-core-types/src/bitswap').LedgerForPeer} LedgerForPeer - * @typedef {import('ipfs-core-types/src/block-service').Block} Block + * @typedef {import('ipld-block')} Block * @typedef {import('peer-id')} PeerId * @typedef {import('./types/message')} BitswapMessage * @typedef {import('cids')} CID @@ -40,13 +36,11 @@ const statsKeys = [ /** * JavaScript implementation of the Bitswap 'data exchange' protocol * used by IPFS. - * - * @implements {API} */ class Bitswap { /** * @param {import('libp2p')} libp2p - * @param {import('ipfs-core-types/src/block-store').BlockStore} blockstore + * @param {import('ipfs-repo').Blockstore} blockstore * @param {Object} [options] * @param {boolean} [options.statsEnabled=false] * @param {number} [options.statsComputeThrottleTimeout=1000] @@ -91,7 +85,6 @@ class Bitswap { * * @param {PeerId} peerId * @param {BitswapMessage} incoming - * @returns {Promise} */ async _receiveMessage (peerId, incoming) { try { @@ -130,7 +123,6 @@ class Bitswap { * @param {PeerId} peerId * @param {Block} block * @param {boolean} wasWanted - * @returns {Promise} */ async _handleReceivedBlock (peerId, block, wasWanted) { this._log('received block') @@ -166,7 +158,6 @@ class Bitswap { * handle errors on the receiving channel * * @param {Error} err - * @returns {void} */ _receiveError (err) { this._log.error('ReceiveError: %s', err.message) @@ -192,16 +183,10 @@ class Bitswap { this._stats.disconnected(peerId) } - /** - * @returns {void} - */ enableStats () { this._stats.enable() } - /** - * @returns {void} - */ disableStats () { this._stats.disable() } @@ -210,8 +195,7 @@ class Bitswap { * Return the current wantlist for a given `peerId` * * @param {PeerId} peerId - * @param {AbortOptions} [_options] - * @returns {Map} + * @param {any} [_options] */ wantlistForPeer (peerId, _options) { return this.engine.wantlistForPeer(peerId) @@ -221,7 +205,6 @@ class Bitswap { * Return ledger information for a given `peerId` * * @param {PeerId} peerId - * @returns {null|LedgerForPeer} */ ledgerForPeer (peerId) { return this.engine.ledgerForPeer(peerId) @@ -234,14 +217,12 @@ class Bitswap { * @param {CID} cid * @param {Object} [options] * @param {AbortSignal} [options.signal] - * @returns {Promise} */ async get (cid, options = {}) { /** * @param {CID} cid * @param {Object} options * @param {AbortSignal} options.signal - * @returns {Promise} */ const fetchFromNetwork = (cid, options) => { // add it to the want list - n.b. later we will abort the AbortSignal @@ -258,7 +239,6 @@ class Bitswap { * @param {CID} cid * @param {Object} options * @param {AbortSignal} options.signal - * @returns {Promise} */ const loadOrFetchFromNetwork = async (cid, options) => { try { @@ -314,7 +294,6 @@ class Bitswap { * @param {AsyncIterable|Iterable} cids * @param {Object} [options] * @param {AbortSignal} [options.signal] - * @returns {AsyncIterable} */ async * getMany (cids, options = {}) { for await (const cid of cids) { @@ -331,7 +310,6 @@ class Bitswap { * AbortSignal in to `.get` or `.getMany` and abort it. * * @param {CID[]|CID} cids - * @returns {void} */ unwant (cids) { const cidsArray = Array.isArray(cids) ? cids : [cids] @@ -346,7 +324,6 @@ class Bitswap { * call `unwant(cids)` instead. * * @param {CID[]|CID} cids - * @returns {void} */ cancelWants (cids) { this.wm.cancelWants(Array.isArray(cids) ? cids : [cids]) @@ -357,8 +334,7 @@ class Bitswap { * send it to nodes that have it in their wantlist. * * @param {Block} block - * @param {AbortOptions} [_options] - * @returns {Promise} + * @param {any} [_options] */ async put (block, _options) { await this.blockstore.put(block) @@ -370,7 +346,6 @@ class Bitswap { * send it to nodes that have it them their wantlist. * * @param {AsyncIterable|Iterable} blocks - * @returns {AsyncIterable} */ async * putMany (blocks) { for await (const block of this.blockstore.putMany(blocks)) { @@ -396,36 +371,28 @@ class Bitswap { } /** - * Get the current list of wants. - * - * @returns {Iterable<[string, WantListEntry]>} + * Get the current list of wants */ getWantlist () { return this.wm.wantlist.entries() } /** - * Get the current list of partners. - * - * @returns {PeerId[]} + * Get the current list of partners */ peers () { return this.engine.peers() } /** - * Get stats about the bitswap node. - * - * @returns {import('ipfs-core-types/src/bitswap').Stats} + * Get stats about the bitswap node */ stat () { return this._stats } /** - * Start the bitswap node. - * - * @returns {void} + * Start the bitswap node */ start () { this.wm.start() @@ -434,9 +401,7 @@ class Bitswap { } /** - * Stop the bitswap node. - * - * @returns {void} + * Stop the bitswap node */ stop () { this._stats.stop() diff --git a/src/network.js b/src/network.js index a0637259..1e2ed7fb 100644 --- a/src/network.js +++ b/src/network.js @@ -12,11 +12,9 @@ const logger = require('./utils').logger /** * @typedef {import('peer-id')} PeerId * @typedef {import('cids')} CID - * @typedef {import('multiaddr')} Multiaddr - * - * @typedef {Object} Connection - * @property {string} id - * @property {PeerId} remotePeer + * @typedef {import('multiaddr').Multiaddr} Multiaddr + * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream * * @typedef {Object} Provider * @property {PeerId} id @@ -100,9 +98,8 @@ class Network { * @private * @param {object} connection * @param {string} connection.protocol - The protocol the stream is running - * @param {Stream} connection.stream - A duplex iterable stream + * @param {MuxedStream} connection.stream - A duplex iterable stream * @param {Connection} connection.connection - A libp2p Connection - * @returns {Promise} */ async _onConnection ({ protocol, stream, connection }) { if (!this._running) { return } @@ -143,7 +140,6 @@ class Network { /** * @private * @param {PeerId} peerId - * @returns {void} */ _onPeerDisconnect (peerId) { this._bitswap._onPeerDisconnected(peerId) @@ -177,7 +173,6 @@ class Network { * @param {CID} cid * @param {Object} [options] * @param {AbortSignal} [options.signal] - * @returns {Promise} */ async findAndConnect (cid, options) { const connectAttempts = [] @@ -194,7 +189,6 @@ class Network { * @param {CID} cid * @param {Object} [options] * @param {AbortSignal} [options.signal] - * @returns {Promise} */ async provide (cid, options) { // @ts-expect-error - contentRouting takes no options @@ -207,7 +201,6 @@ class Network { * * @param {PeerId} peer * @param {Message} msg - * @returns {Promise} */ async sendMessage (peer, msg) { if (!this._running) throw new Error('network isn\'t running') @@ -215,7 +208,8 @@ class Network { const stringId = peer.toB58String() this._log('sendMessage to %s', stringId, msg) - const { stream, protocol } = await this._dialPeer(peer) + const connection = await this._libp2p.dial(peer) + const { stream, protocol } = await connection.newStream([BITSWAP120, BITSWAP110, BITSWAP100]) /** @type {Uint8Array} */ let serialized @@ -253,16 +247,6 @@ class Network { return this._libp2p.dial(peer, options) } - /** - * Dial to the peer and try to use the most recent Bitswap - * - * @private - * @param {PeerId|Multiaddr} peer - */ - _dialPeer (peer) { - return this._libp2p.dialProtocol(peer, [BITSWAP120, BITSWAP110, BITSWAP100]) - } - /** * @private * @param {PeerId} peer @@ -280,7 +264,7 @@ class Network { /** * - * @param {Stream} stream + * @param {MuxedStream} stream * @param {Uint8Array} msg * @param {*} log */ diff --git a/src/notifications.js b/src/notifications.js index 00332fb4..a27bb166 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -9,7 +9,7 @@ const CONSTANTS = require('./constants') const logger = require('./utils').logger /** - * @typedef {import('ipfs-core-types/src/block-service').Block} Block + * @typedef {import('ipld-block')} Block */ /** diff --git a/src/stats/index.js b/src/stats/index.js index cba5eb50..d860156f 100644 --- a/src/stats/index.js +++ b/src/stats/index.js @@ -4,8 +4,8 @@ const { EventEmitter } = require('events') const Stat = require('./stat') /** + * @typedef {import('cids')} CID * @typedef {import('peer-id')} PeerId - * @typedef {import('ipfs-core-types/src/bitswap').Stats} API */ /** @@ -22,9 +22,6 @@ const defaultOptions = { ]) } -/** - * @implements {API} - */ class Stats extends EventEmitter { /** * @param {string[]} [initialCounters] diff --git a/src/stats/stat.js b/src/stats/stat.js index bf49dc27..1bbf7442 100644 --- a/src/stats/stat.js +++ b/src/stats/stat.js @@ -1,7 +1,6 @@ 'use strict' const { EventEmitter } = require('events') -const { BigNumber: Big } = require('bignumber.js') const MovingAverage = require('moving-average') /** @@ -24,7 +23,7 @@ class Stats extends EventEmitter { this._options = options /** @type {Op[]} */ this._queue = [] - /** @type {Record} */ + /** @type {Record} */ this._stats = {} this._frequencyLastTime = Date.now() @@ -37,7 +36,7 @@ class Stats extends EventEmitter { this._update = this._update.bind(this) initialCounters.forEach((key) => { - this._stats[key] = new Big(0) + this._stats[key] = BigInt(0) this._movingAverages[key] = {} this._options.movingAverageIntervals.forEach((interval) => { const ma = this._movingAverages[key][interval] = MovingAverage(interval) @@ -173,14 +172,11 @@ class Stats extends EventEmitter { throw new Error(`invalid increment number: ${inc}`) } - let n - if (!Object.prototype.hasOwnProperty.call(this._stats, key)) { - n = this._stats[key] = new Big(0) - } else { - n = this._stats[key] + this._stats[key] = BigInt(0) } - this._stats[key] = n.plus(inc) + + this._stats[key] = BigInt(this._stats[key]) + BigInt(inc) if (!this._frequencyAccumulators[key]) { this._frequencyAccumulators[key] = 0 diff --git a/src/types/message/index.js b/src/types/message/index.js index d8aea23a..85af8a4e 100644 --- a/src/types/message/index.js +++ b/src/types/message/index.js @@ -19,7 +19,7 @@ class BitswapMessage { /** @type {Map} */ this.wantlist = new Map() - /** @type {Map} */ + /** @type {Map} */ this.blocks = new Map() /** @type {Map} */ @@ -72,7 +72,7 @@ class BitswapMessage { } /** - * @param {import('ipfs-core-types/src/block-service').Block} block + * @param {import('ipld-block')} block * @returns {void} */ addBlock (block) { diff --git a/src/types/wantlist/entry.js b/src/types/wantlist/entry.js index 25120063..347e9d82 100644 --- a/src/types/wantlist/entry.js +++ b/src/types/wantlist/entry.js @@ -1,12 +1,5 @@ 'use strict' -/** - * @typedef {import('ipfs-core-types/src/bitswap').WantListEntry} API - */ - -/** - * @implements {API} - */ class WantListEntry { /** * @param {import('cids')} cid @@ -41,15 +34,12 @@ class WantListEntry { } /** - * @param {API} other - * @returns {boolean} + * @param {any} other */ equals (other) { - // @ts-expect-error _refCounter is not specified by the interface return (this._refCounter === other._refCounter) && this.cid.equals(other.cid) && this.priority === other.priority && - // @ts-expect-error - wantType is not specified by the interface this.wantType === other.wantType } } diff --git a/src/types/wantlist/index.js b/src/types/wantlist/index.js index 56ce4899..dcb5b631 100644 --- a/src/types/wantlist/index.js +++ b/src/types/wantlist/index.js @@ -26,7 +26,6 @@ class Wantlist { * @param {CID} cid * @param {number} priority * @param {import('../message/message').Message.Wantlist.WantType} wantType - * @returns {void} */ add (cid, priority, wantType) { // Have to import here to avoid circular reference @@ -53,7 +52,6 @@ class Wantlist { /** * @param {CID} cid - * @returns {void} */ remove (cid) { const cidStr = cid.toString('base58btc') @@ -103,9 +101,7 @@ class Wantlist { } /** - * * @param {CID} cid - * @returns {Entry|undefined} */ contains (cid) { const cidStr = cid.toString('base58btc') diff --git a/src/utils/sorted-map.js b/src/utils/sorted-map.js index bfada300..83e5abfd 100644 --- a/src/utils/sorted-map.js +++ b/src/utils/sorted-map.js @@ -27,7 +27,6 @@ class SortedMap extends Map { * Call indexOf() to get the index _before_ the change happens. * * @param {number} i - the index of entry whose position should be updated. - * @returns {void} */ update (i) { if (i < 0 || i >= this._keys.length) { @@ -82,7 +81,6 @@ class SortedMap extends Map { /** * @param {Key} k - * @returns {number} */ indexOf (k) { if (!this.has(k)) { @@ -129,9 +127,6 @@ class SortedMap extends Map { return lower } - /** - * @returns {IterableIterator} - */ * keys () { for (const k of this._keys) { yield k @@ -204,7 +199,6 @@ class SortedMap extends Map { * @private * @param {Key} a * @param {Key} b - * @returns {number} */ _kCmp (a, b) { return this._cmp( diff --git a/src/want-manager/index.js b/src/want-manager/index.js index 30a26c5d..1c2daca1 100644 --- a/src/want-manager/index.js +++ b/src/want-manager/index.js @@ -13,7 +13,6 @@ const logger = require('../utils').logger module.exports = class WantManager { /** - * * @param {PeerId} peerId * @param {import('../network')} network * @param {import('../stats')} stats @@ -148,8 +147,6 @@ module.exports = class WantManager { /** * Returns a list of all currently connected peers - * - * @returns {string[]} */ connectedPeers () { return Array.from(this.peers.keys()) @@ -165,7 +162,6 @@ module.exports = class WantManager { /** * @param {PeerId} peerId */ - disconnected (peerId) { this._stopPeerHandler(peerId) } diff --git a/test/bitswap-stats.js b/test/bitswap-stats.js index c9597cb9..a160ceea 100644 --- a/test/bitswap-stats.js +++ b/test/bitswap-stats.js @@ -86,7 +86,7 @@ describe('bitswap stats', () => { expectedStats.forEach((key) => { expect(snapshot).to.have.property(key) - expect(snapshot[key].eq(0)).to.be.true() + expect(snapshot[key]).to.equal(0n) }) const movingAverages = stats.movingAverages @@ -103,15 +103,15 @@ describe('bitswap stats', () => { it('updates blocks received', (done) => { bs.stat().once('update', (stats) => { - expect(stats.blocksReceived.eq(2)).to.be.true() - expect(stats.dataReceived.eq(96)).to.be.true() - expect(stats.dupBlksReceived.eq(0)).to.be.true() - expect(stats.dupDataReceived.eq(0)).to.be.true() - expect(stats.blocksSent.eq(0)).to.be.true() - expect(stats.dataSent.eq(0)).to.be.true() - expect(stats.providesBufferLength.eq(0)).to.be.true() - expect(stats.wantListLength.eq(0)).to.be.true() - expect(stats.peerCount.eq(1)).to.be.true() + expect(stats.blocksReceived).to.equal(2n) + expect(stats.dataReceived).to.equal(96n) + expect(stats.dupBlksReceived).to.equal(0n) + expect(stats.dupDataReceived).to.equal(0n) + expect(stats.blocksSent).to.equal(0n) + expect(stats.dataSent).to.equal(0n) + expect(stats.providesBufferLength).to.equal(0n) + expect(stats.wantListLength).to.equal(0n) + expect(stats.peerCount).to.equal(1n) // test moving averages const movingAverages = bs.stat().movingAverages @@ -143,13 +143,13 @@ describe('bitswap stats', () => { it('updates duplicate blocks counters', (done) => { bs.stat().once('update', (stats) => { - expect(stats.blocksReceived.eq(4)).to.be.true() - expect(stats.dataReceived.eq(192)).to.be.true() - expect(stats.dupBlksReceived.eq(2)).to.be.true() - expect(stats.dupDataReceived.eq(96)).to.be.true() - expect(stats.blocksSent.eq(0)).to.be.true() - expect(stats.dataSent.eq(0)).to.be.true() - expect(stats.providesBufferLength.eq(0)).to.be.true() + expect(stats.blocksReceived).to.equal(4n) + expect(stats.dataReceived).to.equal(192n) + expect(stats.dupBlksReceived).to.equal(2n) + expect(stats.dupDataReceived).to.equal(96n) + expect(stats.blocksSent).to.equal(0n) + expect(stats.dataSent).to.equal(0n) + expect(stats.providesBufferLength).to.equal(0n) done() }) @@ -184,15 +184,15 @@ describe('bitswap stats', () => { it('updates stats on transfer', async () => { const originalStats = bs.stat().snapshot - expect(originalStats.blocksReceived.toNumber()).to.equal(4) - expect(originalStats.dataReceived.toNumber()).to.equal(192) - expect(originalStats.dupBlksReceived.toNumber()).to.equal(2) - expect(originalStats.dupDataReceived.toNumber()).to.equal(96) - expect(originalStats.blocksSent.toNumber()).to.equal(0) - expect(originalStats.dataSent.toNumber()).to.equal(0) - expect(originalStats.providesBufferLength.toNumber()).to.equal(0) - expect(originalStats.wantListLength.toNumber()).to.equal(0) - expect(originalStats.peerCount.toNumber()).to.equal(1) + expect(originalStats.blocksReceived).to.equal(4n) + expect(originalStats.dataReceived).to.equal(192n) + expect(originalStats.dupBlksReceived).to.equal(2n) + expect(originalStats.dupDataReceived).to.equal(96n) + expect(originalStats.blocksSent).to.equal(0n) + expect(originalStats.dataSent).to.equal(0n) + expect(originalStats.providesBufferLength).to.equal(0n) + expect(originalStats.wantListLength).to.equal(0n) + expect(originalStats.peerCount).to.equal(1n) const deferred = pEvent(bs.stat(), 'update') @@ -201,15 +201,15 @@ describe('bitswap stats', () => { const nextStats = await deferred - expect(nextStats.blocksReceived.toNumber()).to.equal(4) - expect(nextStats.dataReceived.toNumber()).to.equal(192) - expect(nextStats.dupBlksReceived.toNumber()).to.equal(2) - expect(nextStats.dupDataReceived.toNumber()).to.equal(96) - expect(nextStats.blocksSent.toNumber()).to.equal(1) - expect(nextStats.dataSent.toNumber()).to.equal(48) - expect(nextStats.providesBufferLength.toNumber()).to.equal(0) - expect(nextStats.wantListLength.toNumber()).to.equal(0) - expect(nextStats.peerCount.toNumber()).to.equal(2) + expect(nextStats.blocksReceived).to.equal(4n) + expect(nextStats.dataReceived).to.equal(192n) + expect(nextStats.dupBlksReceived).to.equal(2n) + expect(nextStats.dupDataReceived).to.equal(96n) + expect(nextStats.blocksSent).to.equal(1n) + expect(nextStats.dataSent).to.equal(48n) + expect(nextStats.providesBufferLength).to.equal(0n) + expect(nextStats.wantListLength).to.equal(0n) + expect(nextStats.peerCount).to.equal(2n) }) it('has peer stats', async () => { @@ -221,15 +221,15 @@ describe('bitswap stats', () => { const stats = await pEvent(peerStats, 'update') - expect(stats.blocksReceived.toNumber()).to.equal(1) - expect(stats.dataReceived.toNumber()).to.equal(49) - expect(stats.dupBlksReceived.toNumber()).to.equal(0) - expect(stats.dupDataReceived.toNumber()).to.equal(0) - expect(stats.blocksSent.toNumber()).to.equal(0) - expect(stats.dataSent.toNumber()).to.equal(0) - expect(stats.providesBufferLength.toNumber()).to.equal(0) - expect(stats.wantListLength.toNumber()).to.equal(0) - expect(stats.peerCount.toNumber()).to.equal(1) + expect(stats.blocksReceived).to.equal(1n) + expect(stats.dataReceived).to.equal(49n) + expect(stats.dupBlksReceived).to.equal(0n) + expect(stats.dupDataReceived).to.equal(0n) + expect(stats.blocksSent).to.equal(0n) + expect(stats.dataSent).to.equal(0n) + expect(stats.providesBufferLength).to.equal(0n) + expect(stats.wantListLength).to.equal(0n) + expect(stats.peerCount).to.equal(1n) const ma = peerStats.movingAverages.dataReceived[60000] expect(ma.movingAverage()).to.be.above(0) diff --git a/test/utils.spec.js b/test/utils.spec.js index f4c611ad..ecf98f7f 100644 --- a/test/utils.spec.js +++ b/test/utils.spec.js @@ -31,7 +31,7 @@ describe('utils spec', function () { }) it('pullAllWith', () => { - var array = [{ x: 1, y: 2 }, { x: 3, y: 4 }, { x: 5, y: 6 }] + const array = [{ x: 1, y: 2 }, { x: 3, y: 4 }, { x: 5, y: 6 }] const actual = pullAllWith( (a, b) => (a.x === b.x && a.y === b.y), diff --git a/test/utils/create-libp2p-node.js b/test/utils/create-libp2p-node.js index 32eefa0a..ca006eb8 100644 --- a/test/utils/create-libp2p-node.js +++ b/test/utils/create-libp2p-node.js @@ -4,8 +4,7 @@ const TCP = require('libp2p-tcp') // @ts-ignore const MPLEX = require('libp2p-mplex') -// @ts-ignore -const SECIO = require('libp2p-secio') +const { NOISE } = require('libp2p-noise') const libp2p = require('libp2p') const KadDHT = require('libp2p-kad-dht') const PeerId = require('peer-id') @@ -26,7 +25,7 @@ class Node extends libp2p { MPLEX ], connEncryption: [ - SECIO + NOISE ], dht: KadDHT }, diff --git a/test/utils/create-temp-repo-browser.js b/test/utils/create-temp-repo-browser.js index 973bec2f..c7b23c76 100644 --- a/test/utils/create-temp-repo-browser.js +++ b/test/utils/create-temp-repo-browser.js @@ -1,7 +1,6 @@ /* global self */ 'use strict' -// @ts-ignore const IPFSRepo = require('ipfs-repo') // @ts-ignore @@ -11,7 +10,6 @@ async function createTempRepo () { const date = Date.now().toString() const path = `/bitswap-tests-${date}-${Math.random()}` - /** @type {import('ipfs-core-types/src/repo').Repo & { teardown: () => void}} */ const repo = new IPFSRepo(path) await repo.init({}) await repo.open() diff --git a/test/utils/create-temp-repo-nodejs.js b/test/utils/create-temp-repo-nodejs.js index 55567a74..e41d1958 100644 --- a/test/utils/create-temp-repo-nodejs.js +++ b/test/utils/create-temp-repo-nodejs.js @@ -1,6 +1,5 @@ 'use strict' -// @ts-ignore const IPFSRepo = require('ipfs-repo') const pathJoin = require('path').join const os = require('os') @@ -12,8 +11,6 @@ const promisify = require('promisify-es6') async function createTempRepo () { const date = Date.now().toString() const path = pathJoin(os.tmpdir(), `bitswap-tests-${date}-${Math.random()}`) - - /** @type {import('ipfs-core-types/src/repo').Repo & { teardown: () => Promise}} */ const repo = new IPFSRepo(path) repo.teardown = async () => {