import {
  getDescribe,
  getIt
} from '../utils/mocha.js';
import { waitForWantlistKey } from './utils.js';
import { isWebWorker } from 'ipfs-utils/src/env.js';
import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets-filter-all.js';
import { CID } from 'multiformats/cid';
export function testWantlistForPeer(factory, options) {
  const ipfsOptions = ipfsOptionsWebsocketsFilterAll();
  const describe = getDescribe(options);
  const it = getIt(options);
  describe('.bitswap.wantlistForPeer', function () {
    this.timeout(60 * 1000);
    let ipfsA;
    let ipfsB;
    const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR';
    before(async () => {
      ipfsA = (await factory.spawn({
        type: 'proc',
        ipfsOptions
      })).api;
      ipfsB = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api;
      ipfsB.block.get(CID.parse(key)).catch(() => {
      });
      const ipfsBId = await ipfsB.id();
      await ipfsA.swarm.connect(ipfsBId.addresses[0]);
    });
    after(() => factory.clean());
    it('should get the wantlist by peer ID for a different node', async () => {
      const ipfsBId = await ipfsB.id();
      return waitForWantlistKey(ipfsA, key, {
        peerId: ipfsBId.id,
        timeout: 60 * 1000
      });
    });
  });
}