From ab96c7f1f81022f301458cb7452e3e615251c356 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Tue, 24 Oct 2023 16:58:53 +0500 Subject: [PATCH] made wasm templates more consistent --- .../wasm/assemblyscript/polywrap.deploy.yaml | 7 ----- .../validator.cue => polywrap.test.cue} | 0 .../wasm/assemblyscript/polywrap.test.yaml | 2 +- .../templates/wasm/typescript/package.json | 11 ++++--- .../wasm/typescript/polywrap.graphql | 6 +++- .../wasm/typescript/polywrap.test.cue | 11 +++++++ .../wasm/typescript/polywrap.test.yaml | 10 ++++++ .../src/__tests__/e2e/integration.spec.ts | 31 +++++++++++++++++++ .../src/__tests__/types/polywrap.app.yaml | 9 ++++++ .../src/__tests__/types/schema.graphql | 1 + .../templates/wasm/typescript/src/index.ts | 8 +++-- 11 files changed, 80 insertions(+), 16 deletions(-) delete mode 100644 packages/templates/wasm/assemblyscript/polywrap.deploy.yaml rename packages/templates/wasm/assemblyscript/{workflows/validator.cue => polywrap.test.cue} (100%) create mode 100644 packages/templates/wasm/typescript/polywrap.test.cue create mode 100644 packages/templates/wasm/typescript/polywrap.test.yaml create mode 100644 packages/templates/wasm/typescript/src/__tests__/e2e/integration.spec.ts create mode 100644 packages/templates/wasm/typescript/src/__tests__/types/polywrap.app.yaml create mode 100644 packages/templates/wasm/typescript/src/__tests__/types/schema.graphql diff --git a/packages/templates/wasm/assemblyscript/polywrap.deploy.yaml b/packages/templates/wasm/assemblyscript/polywrap.deploy.yaml deleted file mode 100644 index f0444053fc..0000000000 --- a/packages/templates/wasm/assemblyscript/polywrap.deploy.yaml +++ /dev/null @@ -1,7 +0,0 @@ -format: "0.1" -stages: - ipfs_deploy: - package: ipfs - uri: fs/./build - config: - gatewayUri: "https://ipfs.wrappers.io" \ No newline at end of file diff --git a/packages/templates/wasm/assemblyscript/workflows/validator.cue b/packages/templates/wasm/assemblyscript/polywrap.test.cue similarity index 100% rename from packages/templates/wasm/assemblyscript/workflows/validator.cue rename to packages/templates/wasm/assemblyscript/polywrap.test.cue diff --git a/packages/templates/wasm/assemblyscript/polywrap.test.yaml b/packages/templates/wasm/assemblyscript/polywrap.test.yaml index 1cb06da5f4..c622bccd27 100644 --- a/packages/templates/wasm/assemblyscript/polywrap.test.yaml +++ b/packages/templates/wasm/assemblyscript/polywrap.test.yaml @@ -1,6 +1,6 @@ name: template-wasm-rs format: 0.1.0 -validation: "./workflows/validator.cue" +validation: "./polywrap.test.cue" jobs: sampleMethod: steps: diff --git a/packages/templates/wasm/typescript/package.json b/packages/templates/wasm/typescript/package.json index 41a85158d2..a8009740e6 100644 --- a/packages/templates/wasm/typescript/package.json +++ b/packages/templates/wasm/typescript/package.json @@ -6,10 +6,13 @@ "main": "build/index.js", "scripts": { "bundle": "rollup -c", - "codegen": "polywrap codegen --verbose", - "build": "yarn bundle && npx polywrap build --no-codegen", - "test": "jest --passWithNoTests --runInBand --verbose", - "deploy": "polywrap deploy" + "codegen": "npx polywrap codegen", + "build": "yarn codegen && yarn bundle && npx polywrap build --no-codegen", + "deploy": "npx polywrap deploy", + "test": "yarn test:e2e && yarn test:workflow", + "test:e2e": "yarn test:e2e:codegen && cargo test --release", + "test:e2e:codegen": "npx polywrap codegen -m ./tests/types/polywrap.app.yaml -g ./tests/types/wrap", + "test:workflow": "npx polywrap test" }, "dependencies": { "tslib": "^2.6.2" diff --git a/packages/templates/wasm/typescript/polywrap.graphql b/packages/templates/wasm/typescript/polywrap.graphql index a527c058c2..5b34469c7e 100644 --- a/packages/templates/wasm/typescript/polywrap.graphql +++ b/packages/templates/wasm/typescript/polywrap.graphql @@ -1,3 +1,7 @@ type Module { - foo(bar: String!): String! + sampleMethod(arg: String!): SampleResult! +} + +type SampleResult { + result: String! } diff --git a/packages/templates/wasm/typescript/polywrap.test.cue b/packages/templates/wasm/typescript/polywrap.test.cue new file mode 100644 index 0000000000..72c37000a6 --- /dev/null +++ b/packages/templates/wasm/typescript/polywrap.test.cue @@ -0,0 +1,11 @@ +package e2e + +sampleMethod: { + $0: { + data: { + value: "polywrap from sample_method" + }, + error?: _|_, + } +} + diff --git a/packages/templates/wasm/typescript/polywrap.test.yaml b/packages/templates/wasm/typescript/polywrap.test.yaml new file mode 100644 index 0000000000..560e8b604e --- /dev/null +++ b/packages/templates/wasm/typescript/polywrap.test.yaml @@ -0,0 +1,10 @@ +name: template-wasm-ts +format: 0.1.0 +validation: "./polywrap.test.cue" +jobs: + sampleMethod: + steps: + - uri: fs/build + method: sampleMethod + args: + arg: "polywrap" diff --git a/packages/templates/wasm/typescript/src/__tests__/e2e/integration.spec.ts b/packages/templates/wasm/typescript/src/__tests__/e2e/integration.spec.ts new file mode 100644 index 0000000000..55913c174a --- /dev/null +++ b/packages/templates/wasm/typescript/src/__tests__/e2e/integration.spec.ts @@ -0,0 +1,31 @@ +import { PolywrapClient } from "@polywrap/client-js"; +import * as App from "../types/wrap"; +import path from "path"; + +jest.setTimeout(60000); + +describe("Template Wrapper End to End Tests", () => { + + const client: PolywrapClient = new PolywrapClient(); + let wrapperUri: string; + + beforeAll(() => { + const dirname: string = path.resolve(__dirname); + const wrapperPath: string = path.join(dirname, "..", "..", ".."); + wrapperUri = `fs/${wrapperPath}/build`; + }) + + it("calls sampleMethod", async () => { + const expected: string = "polywrap"; + + const result = await client.invoke({ + uri: wrapperUri, + method: "sampleMethod", + args: { arg: expected } + }); + + expect(result.ok).toBeTruthy(); + if (!result.ok) return; + expect(result.value.result).toEqual(expected); + }); +}); diff --git a/packages/templates/wasm/typescript/src/__tests__/types/polywrap.app.yaml b/packages/templates/wasm/typescript/src/__tests__/types/polywrap.app.yaml new file mode 100644 index 0000000000..c084aed0f0 --- /dev/null +++ b/packages/templates/wasm/typescript/src/__tests__/types/polywrap.app.yaml @@ -0,0 +1,9 @@ +format: 0.3.0 +project: + name: sample-typescript-type-generation + type: app/typescript +source: + schema: ./schema.graphql + import_abis: + - uri: "wrap://ens/sample.eth" + abi: "../../../build/wrap.info" diff --git a/packages/templates/wasm/typescript/src/__tests__/types/schema.graphql b/packages/templates/wasm/typescript/src/__tests__/types/schema.graphql new file mode 100644 index 0000000000..6d75bfc9bc --- /dev/null +++ b/packages/templates/wasm/typescript/src/__tests__/types/schema.graphql @@ -0,0 +1 @@ +#import * into Template from "wrap://ens/sample.eth" diff --git a/packages/templates/wasm/typescript/src/index.ts b/packages/templates/wasm/typescript/src/index.ts index fb25fe8ea7..135f6e6ba1 100644 --- a/packages/templates/wasm/typescript/src/index.ts +++ b/packages/templates/wasm/typescript/src/index.ts @@ -1,7 +1,9 @@ -import { Args_foo, ModuleBase } from "./wrap"; +import { Args_sampleMethod, SampleResult, ModuleBase } from "./wrap"; export class Module extends ModuleBase { - foo(args: Args_foo): string { - throw new Error("Not implemented"); + sampleMethod(args: Args_sampleMethod): SampleResult { + return { + result: args.arg, + }; } }