Skip to content

Commit

Permalink
made wasm templates more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
krisbitney committed Oct 24, 2023
1 parent 7b52e35 commit ab96c7f
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 16 deletions.
7 changes: 0 additions & 7 deletions packages/templates/wasm/assemblyscript/polywrap.deploy.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion packages/templates/wasm/assemblyscript/polywrap.test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: template-wasm-rs
format: 0.1.0
validation: "./workflows/validator.cue"
validation: "./polywrap.test.cue"
jobs:
sampleMethod:
steps:
Expand Down
11 changes: 7 additions & 4 deletions packages/templates/wasm/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion packages/templates/wasm/typescript/polywrap.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
type Module {
foo(bar: String!): String!
sampleMethod(arg: String!): SampleResult!
}

type SampleResult {
result: String!
}
11 changes: 11 additions & 0 deletions packages/templates/wasm/typescript/polywrap.test.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package e2e

sampleMethod: {
$0: {
data: {
value: "polywrap from sample_method"
},
error?: _|_,
}
}

10 changes: 10 additions & 0 deletions packages/templates/wasm/typescript/polywrap.test.yaml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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<App.Template_SampleResult>({
uri: wrapperUri,
method: "sampleMethod",
args: { arg: expected }
});

expect(result.ok).toBeTruthy();
if (!result.ok) return;
expect(result.value.result).toEqual(expected);
});
});
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#import * into Template from "wrap://ens/sample.eth"
8 changes: 5 additions & 3 deletions packages/templates/wasm/typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}
}

0 comments on commit ab96c7f

Please sign in to comment.