'use strict';

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

var fromString = require('uint8arrays/from-string');
var cid = require('multiformats/cid');
var chai_js = require('aegir/utils/chai.js');
var mocha = require('../utils/mocha.js');
var testTimeout = require('../utils/test-timeout.js');

function testStat(factory, options) {
  const describe = mocha.getDescribe(options);
  const it = mocha.getIt(options);
  describe('.block.stat', () => {
    const data = fromString.fromString('blorb');
    let ipfs;
    let cid$1;
    before(async () => {
      ipfs = (await factory.spawn()).api;
      cid$1 = await ipfs.block.put(data);
    });
    after(() => factory.clean());
    it('should respect timeout option when statting a block', () => {
      return testTimeout(() => ipfs.block.stat(cid.CID.parse('QmVwdDCY4SPGVFnNCiZnX5CtzwWDn6kAM98JXzKxE3kCmn'), { timeout: 1 }));
    });
    it('should stat by CID', async () => {
      const stats = await ipfs.block.stat(cid$1);
      chai_js.expect(stats.cid.toString()).to.equal(cid$1.toString());
      chai_js.expect(stats).to.have.property('size', data.length);
    });
    it('should return error for missing argument', () => {
      return chai_js.expect(ipfs.block.stat(null)).to.eventually.be.rejected.and.be.an.instanceOf(Error);
    });
    it('should return error for invalid argument', () => {
      return chai_js.expect(ipfs.block.stat('invalid')).to.eventually.be.rejected.and.be.an.instanceOf(Error);
    });
  });
}

exports.testStat = testStat;
