'use strict';

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

var PeerId = require('peer-id');
var multiaddr = require('multiaddr');
var chai_js = require('aegir/utils/chai.js');
var mocha = require('../utils/mocha.js');
var env_js = require('ipfs-utils/src/env.js');
var ipfsOptionsWebsocketsFilterAll = require('../utils/ipfs-options-websockets-filter-all.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var PeerId__default = /*#__PURE__*/_interopDefaultLegacy(PeerId);

function testAddrs(factory, options) {
  const ipfsOptions = ipfsOptionsWebsocketsFilterAll.ipfsOptionsWebsocketsFilterAll();
  const describe = mocha.getDescribe(options);
  const it = mocha.getIt(options);
  describe('.swarm.addrs', function () {
    this.timeout(80 * 1000);
    let ipfsA;
    let ipfsB;
    let ipfsBId;
    before(async () => {
      ipfsA = (await factory.spawn({
        type: 'proc',
        ipfsOptions
      })).api;
      ipfsB = (await factory.spawn({ type: env_js.isWebWorker ? 'go' : undefined })).api;
      ipfsBId = await ipfsB.id();
      await ipfsA.swarm.connect(ipfsBId.addresses[0]);
    });
    after(() => factory.clean());
    it('should get a list of node addresses', async () => {
      const peers = await ipfsA.swarm.addrs();
      chai_js.expect(peers).to.not.be.empty();
      chai_js.expect(peers).to.be.an('array');
      for (const peer of peers) {
        chai_js.expect(PeerId__default["default"].parse(peer.id)).to.be.ok();
        chai_js.expect(peer).to.have.a.property('addrs').that.is.an('array');
        for (const ma of peer.addrs) {
          chai_js.expect(multiaddr.Multiaddr.isMultiaddr(ma)).to.be.true();
        }
      }
    });
  });
}

exports.testAddrs = testAddrs;
