ipld / js-ipld

The JavaScript Implementation of IPLD
https://ipld.io
MIT License
119 stars 37 forks source link

Usage instructions fail when run in jest. #289

Closed OR13 closed 3 years ago

OR13 commented 4 years ago
    "ipfs-block-service": "^0.18.0",
    "ipfs-repo": "^6.0.3",
    "ipld": "^0.27.1",

Type: Bug

Severity: High

Description:

Readme usage instructions don't work... https://github.com/ipld/js-ipld#usage

Steps to reproduce the error:

(typescript, but just drop the any's...)

const path = require('path');
const Ipld = require('ipld');
const IpfsRepo = require('ipfs-repo');
const IpfsBlockService = require('ipfs-block-service');

jest.setTimeout(10 * 1000);
it('can put and get ipld', done => {
  const initIpld = (ipfsRepoPath: any, callback: any) => {
    const repo = new IpfsRepo(ipfsRepoPath);
    repo.init({}, (err: any) => {
      if (err) {
        return callback(err);
      }
      repo.open((err: any) => {
        if (err) {
          return callback(err);
        }
        const blockService = new IpfsBlockService(repo);
        const ipld = new Ipld({ blockService: blockService });
        return callback(null, ipld);
      });
    });
  };

  initIpld(path.join(__dirname, './ipld-golem'), (err: any, ipld: any) => {
    // Do something with the `ipld`, e.g. `ipld.get(…)`
    console.log(err, ipld);
    done();
  });
});

test hangs for 10 seconds, done is never called... can't use ipld.

rvagg commented 4 years ago

was this working before for you and only just stopped working, or are you trying this from scratch without it previously working?

vmx commented 4 years ago

Thanks for your bug report. The problem is that ipfs-repo is using async/await instead of callbacks. The updated code can be found here https://github.com/ipld/js-ipld/pull/290/files#diff-04c6e90faac2675aa89e2176d2eec7d8.