'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var mocha = require('../utils/mocha.js');
var utils = require('./utils.js');
var env_js = require('ipfs-utils/src/env.js');
var ipfsOptionsWebsocketsFilterAll = require('../utils/ipfs-options-websockets-filter-all.js');
var cid = require('multiformats/cid');

function testWantlistForPeer(factory, options) {
  const ipfsOptions = ipfsOptionsWebsocketsFilterAll.ipfsOptionsWebsocketsFilterAll();
  const describe = mocha.getDescribe(options);
  const it = mocha.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: env_js.isWebWorker ? 'go' : undefined })).api;
      ipfsB.block.get(cid.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 utils.waitForWantlistKey(ipfsA, key, {
        peerId: ipfsBId.id,
        timeout: 60 * 1000
      });
    });
  });
}

exports.testWantlistForPeer = testWantlistForPeer;
