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 pathrm.js
63 lines (48 loc) · 2 KB
/
rm.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
/* eslint-env mocha */
import { expect } from 'aegir/chai'
import { getDescribe, getIt } from '../utils/mocha.js'
import { multiaddr, isMultiaddr } from '@multiformats/multiaddr'
/**
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
/**
* @param {Factory} factory
* @param {object} options
*/
export function testRm (factory, options) {
const describe = getDescribe(options)
const it = getIt(options)
const invalidArg = 'this/Is/So/Invalid/'
const validIp4 = multiaddr('/ip4/104.236.176.52/tcp/4001/p2p/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z')
describe('.bootstrap.rm', function () {
this.timeout(100 * 1000)
/** @type {import('ipfs-core-types').IPFS} */
let ipfs
before(async () => { ipfs = (await factory.spawn()).api })
after(() => factory.clean())
it('should return an error when called with an invalid arg', () => {
// @ts-expect-error invalid input
return expect(ipfs.bootstrap.rm(invalidArg)).to.eventually.be.rejected
.and.be.an.instanceOf(Error)
})
it('should return a list containing the peer removed when called with a valid arg (ip4)', async () => {
const addRes = await ipfs.bootstrap.add(validIp4)
expect(addRes).to.be.eql({ Peers: [validIp4] })
const rmRes = await ipfs.bootstrap.rm(validIp4)
expect(rmRes).to.be.eql({ Peers: [validIp4] })
const peers = rmRes.Peers
expect(peers).to.have.property('length').that.is.equal(1)
})
it('removes a peer from the bootstrap list', async () => {
const peer = multiaddr('/ip4/111.111.111.111/tcp/1001/p2p/QmXFX2P5ammdmXQgfqGkfswtEVFsZUJ5KeHRXQYCTdiTAb')
await ipfs.bootstrap.add(peer)
let list = await ipfs.bootstrap.list()
expect(list.Peers).to.deep.include(peer)
const res = await ipfs.bootstrap.rm(peer)
expect(res).to.be.eql({ Peers: [peer] })
list = await ipfs.bootstrap.list()
expect(list.Peers).to.not.deep.include(peer)
expect(res.Peers.every(ma => isMultiaddr(ma))).to.be.true()
})
})
}