ethpm / ethpm.js

Javascript library for EthPM package manifest and registry operations
https://ethpm.github.io/ethpm.js/
MIT License
13 stars 7 forks source link

Add IPFS integration #6

Closed adrianmcli closed 6 years ago

adrianmcli commented 6 years ago

Starting this PR for easy reference. Will eventually fix #3.

@gnidan I need a bit of guidance here, I've got a bunch of questions.

Questions

I've noted each question as a TODO inside the diff (feel free to leave line comments), but is also summarized here:

  1. Can you point me towards specific examples or documentation on how to do read/write/predictUri with IPFS? I haven't really worked with IPFS before and I'm not sure where to start. The terminology is really throwing me for a loop.

  2. Could you help me scope out what tests and how they should be written?

  3. I have the four .ts files for each of the functions, but I'm not sure how to connect them to the rest of the library.

  4. For the read function test, I need to be able to grab the value inside of the Maybe context. In Haskell, I would use pattern matching for this. I'm not sure how I would do this with Typescript. (fixed w/ simple undefined check)

  5. Finally, let me know if I'm on track or further guidance if I am significantly off track.

gnidan commented 6 years ago
  1. Can you point me towards specific examples or documentation on how to do read/write/predictUri with IPFS? I haven't really worked with IPFS before and I'm not sure where to start. The terminology is really throwing me for a loop.
  1. Could you help me scope out what tests and how they should be written?

I think for this, unit tests won't be so important, because mostly the module is just a wrapper around whatever IPFS lib you're using. I think a better strategy would be to make integration tests in src/storage/ipfs/test that instantiate EthPM and then use the IPFS lib to verify the contents are getting written.

For these, you might emulate these main integration tests: https://github.com/ethpm/ethpm.js/blob/master/src/test/ethpm.ts

  1. I have the four .ts files for each of the functions, but I'm not sure how to connect them to the rest of the library.

Does the export keyword work? I'd say look here for comparison: https://github.com/ethpm/ethpm.js/blob/master/test/stub/storage/index.ts

  1. Finally, let me know if I'm on track or further guidance if I am significantly off track.

Looks on-track to me!

adrianmcli commented 6 years ago

Thanks, I'm going to turn your reply into action points for me:

adrianmcli commented 6 years ago

Just an update, currently having a problem running IPFS for the integration test. I did a git bisect and it seems the problem was introduced in this commit:

f0953498a97bfb51bac69762f5cc9c8f8e668b5d is the first bad commit
commit f0953498a97bfb51bac69762f5cc9c8f8e668b5d
Author: g. nicholas d'andrea <gnidan@users.noreply.github.com>
Date:   Wed Aug 22 19:39:59 2018 -0400

    Add IPFS hash generation

    - Use technique described at https://stackoverflow.com/a/51304779
    - Test that piper-coin's hash for standard-token matches ours

    (Adding this now to start building stubbed IPFS resolver)

I think either ipfs-unixfs or ipld-dag-pb is causing issues with the dependency tree and it ends up messing with something that ipfs is using. I need to look into this further if I am going to be able to do the integration test.

adrianmcli commented 6 years ago

@gnidan

Replication instructions

Here is a test script I use to see if it works:

// script.js
const IPFSFactory = require("ipfsd-ctl");

const f = IPFSFactory.create({ type: "js" });
f.spawn((err, ipfsd) => {
  console.log(err);
  console.log(ipfsd);
  ipfsd.stop()
});

And I run it simply by executing node script.js.

Steps

Here are the steps you can take to replicate the problem on your computer:

  1. Check out this commit: https://github.com/ethpm/ethpm.js/commit/6d743fe44c2de9c5aa01c658e9499938348ba04d

  2. Wipe your node modules rm -rf node_modules and then yarn add ipfs ipfsd-ctl

  3. Try the script node script.js and see that it works fine (i.e. logs out an object, no error)

  4. Check out this commit: https://github.com/ethpm/ethpm.js/commit/f0953498a97bfb51bac69762f5cc9c8f8e668b5d

  5. Repeat steps 2 and 3, note that an error is now thrown