fryorcraken.eth 889ec4d45c
feat: split bootstrap logic
Split the bootstrap logic in 2 different classes that implement the
libp2p peer discovery class.

This enables better tree shaking when not using the heaviest version
(DNS Discovery).

It also means using libp2p interface directly when customizing the peer
discovery logic.

Finally, the `default` method is still available via the
`defaultBootstrap` option.
2022-08-07 12:03:05 +10:00

36 lines
1.0 KiB
TypeScript

import { expect } from "chai";
import { getPseudoRandomSubset } from "../random_subset";
describe("Discovery", () => {
it("returns all values when wanted number matches available values", function () {
const values = ["a", "b", "c"];
const res = getPseudoRandomSubset(values, 3);
expect(res.length).to.eq(3);
expect(res.includes("a")).to.be.true;
expect(res.includes("b")).to.be.true;
expect(res.includes("c")).to.be.true;
});
it("returns all values when wanted number is greater than available values", function () {
const values = ["a", "b", "c"];
const res = getPseudoRandomSubset(values, 5);
expect(res.length).to.eq(3);
expect(res.includes("a")).to.be.true;
expect(res.includes("b")).to.be.true;
expect(res.includes("c")).to.be.true;
});
it("returns a subset of values when wanted number is lesser than available values", function () {
const values = ["a", "b", "c"];
const res = getPseudoRandomSubset(values, 2);
expect(res.length).to.eq(2);
});
});