Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPFS plugin separation of concerns #930

Merged
merged 30 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ebf6541
separate ipfs plugin and ipfs-resolver plugin, add ipfs plugin interface
pileks Jun 17, 2022
32731d2
Merge branch 'prealpha-dev' into pileks-ipfs-plugin-separation-of-con…
pileks Jun 17, 2022
ff46e3f
fix up new plugins for polywrap rename
pileks Jun 17, 2022
b9db16b
Fix build issues introduced by new interface
pileks Jun 17, 2022
74d8d03
fix default-client-config
pileks Jun 19, 2022
924badb
fix lint
pileks Jun 19, 2022
e96b5e1
IPFS plugin basic tests
pileks Jun 20, 2022
5e04429
Remove redundant method in ipfs plugin, refactor
pileks Jun 20, 2022
1d76be3
fix test breaking in CI
pileks Jun 20, 2022
9378615
Increase jest timeout for CI
pileks Jun 20, 2022
ecaf297
IPFS URI Resolver basic test
pileks Jun 20, 2022
52643e1
add e2e test for ipfs-resolver-plugin-js
pileks Jun 21, 2022
fd936b3
increase timeout for ipfs-resolver tests
pileks Jun 21, 2022
7caad9f
Merge remote-tracking branch 'origin/prealpha-dev' into pileks-ipfs-p…
pileks Jun 22, 2022
459cc2e
fix package.json
pileks Jun 22, 2022
11a2e9d
remove catToString from IPFS interface and plugin
pileks Jun 22, 2022
289a72f
resolve PR comments
pileks Jun 23, 2022
45d11dd
Merge remote-tracking branch 'origin/prealpha-dev' into pileks-ipfs-p…
pileks Jun 23, 2022
28c5bc0
removed unused functions and types
nerfZael Jun 23, 2022
d1751eb
refactored ipfs client handling in tests
nerfZael Jun 23, 2022
e1aead0
locked dependencies and replaced the deprecated cids package with the…
nerfZael Jun 23, 2022
7fba2be
Merge pull request #949 from polywrap/nerfzael-uri-resolver-test-fixes
dOrgJelli Jun 23, 2022
fc355e2
Code style changes
pileks Jun 23, 2022
989a19f
Merge remote-tracking branch 'origin/prealpha-dev' into pileks-ipfs-p…
pileks Jun 23, 2022
85f03ad
update yarn.lock
pileks Jun 23, 2022
539c77a
Merge remote-tracking branch 'origin/prealpha-dev' into pileks-ipfs-p…
pileks Jun 25, 2022
098b5d0
fix IPFS plugin manifest import redirect
pileks Jun 25, 2022
3b3d37d
IPFS Resolver manifest correct name
pileks Jun 25, 2022
48707c2
merge prealpha-dev
dOrgJelli Jun 27, 2022
b056f87
remove unnecessary .gitignore + .nvmrc files
dOrgJelli Jun 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions packages/core-interfaces/file-system/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions packages/core-interfaces/ipfs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO
16 changes: 16 additions & 0 deletions packages/core-interfaces/ipfs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@polywrap/ipfs-interface",
"description": "Polywrap Ipfs Interface",
"private": true,
"version": "0.0.1-prealpha.89",
"scripts": {
"build": "node ../../../dependencies/node_modules/polywrap/bin/polywrap build",
"lint": "eslint --color -c ../../../.eslintrc.js .",
"test:env:up": "npx polywrap infra up --modules=eth-ens-ipfs",
"test:env:down": "npx polywrap infra down --modules=eth-ens-ipfs",
"deploy": "node ../../../dependencies/node_modules/polywrap/bin/polywrap deploy"
},
"devDependencies": {
"polywrap": "0.0.1-prealpha.89"
}
}
5 changes: 5 additions & 0 deletions packages/core-interfaces/ipfs/polywrap.deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
format: 0.0.1-prealpha.1
stages:
ipfs_deploy:
package: ipfs
uri: fs/./build
5 changes: 5 additions & 0 deletions packages/core-interfaces/ipfs/polywrap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
format: 0.0.1-prealpha.9
name: IPFS
language: interface
deploy: ./polywrap.deploy.yaml
schema: ./src/schema.graphql
30 changes: 30 additions & 0 deletions packages/core-interfaces/ipfs/src/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
type Module {
cat(cid: String!, options: Options): Bytes!

resolve(cid: String!, options: Options): ResolveResult

addFile(data: Bytes!): String!
}

type ResolveResult {
cid: String!
provider: String!
}

type Options {
"""
Timeout (in ms) for the operation.
Fallback providers are used if timeout is reached.
"""
timeout: UInt32

"""
The IPFS provider to be used
"""
provider: String

"""
Disable querying providers in parallel when resolving URIs
"""
disableParallelRequests: Boolean
}
2 changes: 0 additions & 2 deletions packages/core-interfaces/logger/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions packages/core-interfaces/uri-resolver/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions packages/js/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@polywrap/tracing-js": "0.0.1-prealpha.89",
"@polywrap/uts46-plugin-js": "0.0.1-prealpha.89",
"@polywrap/fs-resolver-plugin-js": "0.0.1-prealpha.89",
"@polywrap/ipfs-resolver-plugin-js": "0.0.1-prealpha.89",
"graphql": "15.5.0",
"js-yaml": "3.14.0",
"uuid": "8.3.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const defaultPlugins = [
"wrap://ens/graph-node.polywrap.eth",
"wrap://ens/fs.polywrap.eth",
"wrap://ens/fs-resolver.polywrap.eth",
"wrap://ens/ipfs-resolver.polywrap.eth",
pileks marked this conversation as resolved.
Show resolved Hide resolved
];

describe("plugin-wrapper", () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/js/client/src/__tests__/core/resolveUri.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ describe("resolveUri", () => {
result: {
uri: ipfsUri,
wrapper: true,
implementationUri: new Uri("wrap://ens/ipfs.polywrap.eth"),
implementationUri: new Uri("wrap://ens/ipfs-resolver.polywrap.eth"),
},
},
]);
Expand Down Expand Up @@ -395,7 +395,7 @@ describe("resolveUri", () => {
result: {
uri: ipfsUri,
wrapper: true,
implementationUri: new Uri("wrap://ens/ipfs.polywrap.eth"),
implementationUri: new Uri("wrap://ens/ipfs-resolver.polywrap.eth"),
},
},
]);
Expand Down Expand Up @@ -522,7 +522,7 @@ describe("resolveUri", () => {
result: {
uri: ipfsUri,
wrapper: true,
implementationUri: new Uri("wrap://ens/ipfs.polywrap.eth"),
implementationUri: new Uri("wrap://ens/ipfs-resolver.polywrap.eth"),
},
},
]);
Expand Down Expand Up @@ -586,7 +586,7 @@ describe("resolveUri", () => {
result: {
uri: ipfsUri,
wrapper: true,
implementationUri: new Uri("wrap://ens/ipfs.polywrap.eth"),
implementationUri: new Uri("wrap://ens/ipfs-resolver.polywrap.eth"),
},
},
]);
Expand Down Expand Up @@ -650,7 +650,7 @@ describe("resolveUri", () => {
result: {
uri: ipfsUri,
wrapper: true,
implementationUri: new Uri("wrap://ens/ipfs.polywrap.eth"),
implementationUri: new Uri("wrap://ens/ipfs-resolver.polywrap.eth"),
},
},
]);
Expand Down Expand Up @@ -730,7 +730,7 @@ describe("resolveUri", () => {
result: {
uri: ipfsUri,
wrapper: true,
implementationUri: new Uri("wrap://ens/ipfs.polywrap.eth"),
implementationUri: new Uri("wrap://ens/ipfs-resolver.polywrap.eth"),
},
},
]);
Expand Down
3 changes: 2 additions & 1 deletion packages/js/client/src/__tests__/core/sanity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ describe("sanity", () => {
new Uri("wrap://ens/graph-node.polywrap.eth"),
new Uri("wrap://ens/fs.polywrap.eth"),
new Uri("wrap://ens/fs-resolver.polywrap.eth"),
new Uri("wrap://ens/ipfs-resolver.polywrap.eth"),
]);
expect(client.getInterfaces()).toStrictEqual([
{
interface: coreInterfaceUris.uriResolver,
implementations: [
new Uri("wrap://ens/ipfs.polywrap.eth"),
new Uri("wrap://ens/ipfs-resolver.polywrap.eth"),
new Uri("wrap://ens/ens.polywrap.eth"),
new Uri("wrap://ens/fs-resolver.polywrap.eth"),
],
Expand Down
10 changes: 9 additions & 1 deletion packages/js/client/src/default-client-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
RedirectsResolver,
} from "@polywrap/core-js";
import { ipfsPlugin } from "@polywrap/ipfs-plugin-js";
import { ipfsResolverPlugin } from "@polywrap/ipfs-resolver-plugin-js";
import { ethereumPlugin } from "@polywrap/ethereum-plugin-js";
import { ensPlugin } from "@polywrap/ens-plugin-js";
import { graphNodePlugin } from "@polywrap/graph-node-plugin-js";
Expand Down Expand Up @@ -85,12 +86,19 @@ export const getDefaultClientConfig = Tracer.traceFunc(
uri: new Uri("wrap://ens/fs-resolver.polywrap.eth"),
plugin: fileSystemResolverPlugin({}),
},
{
uri: new Uri("wrap://ens/ipfs-resolver.polywrap.eth"),
plugin: ipfsResolverPlugin({
provider: defaultIpfsProviders[0],
fallbackProviders: defaultIpfsProviders.slice(1),
}),
},
],
interfaces: [
{
interface: coreInterfaceUris.uriResolver,
implementations: [
new Uri("wrap://ens/ipfs.polywrap.eth"),
new Uri("wrap://ens/ipfs-resolver.polywrap.eth"),
new Uri("wrap://ens/ens.polywrap.eth"),
new Uri("wrap://ens/fs-resolver.polywrap.eth"),
],
Expand Down
7 changes: 4 additions & 3 deletions packages/js/plugins/ipfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"@dorgjelli-test/ipfs-http-client-lite": "0.3.1",
"@polywrap/core-js": "0.0.1-prealpha.89",
"abort-controller": "3.0.0",
"cids": "^1.1.4",
"is-ipfs": "1.0.3"
"is-ipfs": "1.0.3",
"multiformats": "9.7.0"
},
"devDependencies": {
"@types/jest": "26.0.8",
Expand All @@ -34,7 +34,8 @@
"rimraf": "3.0.2",
"ts-jest": "26.5.4",
"ts-node": "8.10.2",
"typescript": "4.0.7"
"typescript": "4.0.7",
"@polywrap/test-env-js": "0.0.1-prealpha.89"
},
"gitHead": "7346adaf5adb7e6bbb70d9247583e995650d390a",
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions packages/js/plugins/ipfs/polywrap.plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ language: plugin/typescript
module: ./src/index.ts
schema: ./src/schema.graphql
import_redirects:
- uri: "ens/uri-resolver.core.polywrap.eth"
schema: ../../../core-interfaces/uri-resolver/src/schema.graphql
- uri: "ens/ipfs.polywrap.eth"
schema: ../../../core-interfaces/ipfs/build/schema.graphql
93 changes: 89 additions & 4 deletions packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,90 @@
/* eslint-disable @typescript-eslint/no-empty-function */
// TODO: create client, add plugin, test all the methods
describe("TODO", () => {
it("TODO", () => {});
import { PolywrapClient } from "@polywrap/client-js";
import {
initTestEnvironment,
providers,
stopTestEnvironment,
} from "@polywrap/test-env-js";

import { ipfsPlugin } from "..";
import { IpfsClient, IpfsFileInfo } from "../utils/IpfsClient";
import { Ipfs_Module } from "../wrap";

const createIpfsClient = require("@dorgjelli-test/ipfs-http-client-lite");

jest.setTimeout(300000);

describe("IPFS Plugin", () => {
let client: PolywrapClient;
let ipfs: IpfsClient;

const sampleFileTextContents = "Hello World!";
let sampleFileIpfsInfo: IpfsFileInfo;
const sampleFileBuffer = Buffer.from(sampleFileTextContents, "utf-8");

beforeAll(async () => {
await initTestEnvironment();
ipfs = createIpfsClient(providers.ipfs);

client = new PolywrapClient({
plugins: [
{
uri: "wrap://ens/ipfs.polywrap.eth",
plugin: ipfsPlugin({
provider: providers.ipfs,
}),
},
],
});

let ipfsAddResult = await ipfs.add(sampleFileBuffer);
sampleFileIpfsInfo = ipfsAddResult[0];
});

afterAll(async () => {
await stopTestEnvironment();
});

it("Should cat a file successfully", async () => {
expect(sampleFileIpfsInfo).toBeDefined();

let result = await Ipfs_Module.cat(
{ cid: sampleFileIpfsInfo.hash.toString() },
client
);

expect(result.error).toBeFalsy();

expect(result.data).toEqual(sampleFileBuffer);
});

it("Should resolve a file successfully", async () => {
expect(sampleFileIpfsInfo).toBeDefined();

let result = await Ipfs_Module.resolve(
{ cid: sampleFileIpfsInfo.hash.toString() },
client
);

expect(result.error).toBeFalsy();

expect(result.data).toEqual({
cid: `/ipfs/${sampleFileIpfsInfo.hash.toString()}`,
provider: providers.ipfs,
});
});

it("Should add a file successfully", async () => {
const expectedContents = "A new sample file";
const contentsBuffer = Buffer.from(expectedContents, "utf-8");

let result = await Ipfs_Module.addFile({ data: contentsBuffer }, client);

expect(result.error).toBeFalsy();

expect(result.data).toBeTruthy();

const addedFileBuffer = await ipfs.cat(result.data as string);

expect(contentsBuffer).toEqual(addedFileBuffer);
});
});
Loading