From c78542efc5a8039bccc5903e10271f313210bf01 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Thu, 31 Aug 2023 22:02:16 +0300 Subject: [PATCH 1/5] draft rust tests in wrap-rust template --- packages/templates/wasm/rust/Cargo.toml | 9 ++++- packages/templates/wasm/rust/jest.config.js | 15 ------- packages/templates/wasm/rust/package.json | 4 +- .../src/__tests__/e2e/integration.spec.ts | 31 --------------- .../src/__tests__/types/polywrap.app.yaml | 9 ----- .../rust/src/__tests__/types/schema.graphql | 1 - packages/templates/wasm/rust/tests/e2e.rs | 39 +++++++++++++++++++ packages/templates/wasm/rust/tsconfig.json | 28 ------------- 8 files changed, 47 insertions(+), 89 deletions(-) delete mode 100644 packages/templates/wasm/rust/jest.config.js delete mode 100644 packages/templates/wasm/rust/src/__tests__/e2e/integration.spec.ts delete mode 100644 packages/templates/wasm/rust/src/__tests__/types/polywrap.app.yaml delete mode 100644 packages/templates/wasm/rust/src/__tests__/types/schema.graphql create mode 100644 packages/templates/wasm/rust/tests/e2e.rs delete mode 100644 packages/templates/wasm/rust/tsconfig.json diff --git a/packages/templates/wasm/rust/Cargo.toml b/packages/templates/wasm/rust/Cargo.toml index b5e4af31ea..ae83b5b56a 100644 --- a/packages/templates/wasm/rust/Cargo.toml +++ b/packages/templates/wasm/rust/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "template-wasm-rs" +name = "template_wasm_rs" version = "0.1.0" description = "A Polywrap Wasm wrapper template written in Rust" authors = ["Polywrap"] @@ -7,11 +7,16 @@ repository = "https://github.com/polywrap/monorepo" license = "MIT" edition = "2021" +include = ["src"] + [dependencies] -polywrap-wasm-rs = { version = "~0.11.0-pre.4" } +polywrap-wasm-rs = { version = "~0.11.2" } polywrap_msgpack_serde = "~0.0.2-beta.5" serde = { version = "1.0", features = ["derive"] } +[dev-dependencies] +polywrap = { version = "~0.1.8" } + [lib] crate-type = ["cdylib"] diff --git a/packages/templates/wasm/rust/jest.config.js b/packages/templates/wasm/rust/jest.config.js deleted file mode 100644 index 4a4c022f7b..0000000000 --- a/packages/templates/wasm/rust/jest.config.js +++ /dev/null @@ -1,15 +0,0 @@ -module.exports = { - collectCoverage: false, - preset: "ts-jest", - testEnvironment: "node", - testMatch: ["**/__tests__/**/?(*.)+(spec|test).[jt]s?(x)"], - globals: { - "ts-jest": { - tsconfig: "tsconfig.json", - diagnostics: false, - }, - }, - testPathIgnorePatterns: [ - "/.polywrap/" - ], -}; diff --git a/packages/templates/wasm/rust/package.json b/packages/templates/wasm/rust/package.json index 767f33589e..2ef7880e60 100644 --- a/packages/templates/wasm/rust/package.json +++ b/packages/templates/wasm/rust/package.json @@ -7,9 +7,7 @@ "codegen": "npx polywrap codegen", "build": "npx polywrap build", "deploy": "npx polywrap deploy", - "test": "yarn test:e2e && yarn test:workflow", - "test:e2e": "yarn test:e2e:codegen && jest --passWithNoTests --runInBand --verbose", - "test:e2e:codegen": "npx polywrap codegen -m ./src/__tests__/types/polywrap.app.yaml -g ./src/__tests__/types/wrap", + "test": "cargo test", "test:workflow": "npx polywrap test" }, "devDependencies": { diff --git a/packages/templates/wasm/rust/src/__tests__/e2e/integration.spec.ts b/packages/templates/wasm/rust/src/__tests__/e2e/integration.spec.ts deleted file mode 100644 index 55913c174a..0000000000 --- a/packages/templates/wasm/rust/src/__tests__/e2e/integration.spec.ts +++ /dev/null @@ -1,31 +0,0 @@ -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/rust/src/__tests__/types/polywrap.app.yaml b/packages/templates/wasm/rust/src/__tests__/types/polywrap.app.yaml deleted file mode 100644 index c084aed0f0..0000000000 --- a/packages/templates/wasm/rust/src/__tests__/types/polywrap.app.yaml +++ /dev/null @@ -1,9 +0,0 @@ -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/rust/src/__tests__/types/schema.graphql b/packages/templates/wasm/rust/src/__tests__/types/schema.graphql deleted file mode 100644 index 6d75bfc9bc..0000000000 --- a/packages/templates/wasm/rust/src/__tests__/types/schema.graphql +++ /dev/null @@ -1 +0,0 @@ -#import * into Template from "wrap://ens/sample.eth" diff --git a/packages/templates/wasm/rust/tests/e2e.rs b/packages/templates/wasm/rust/tests/e2e.rs new file mode 100644 index 0000000000..d3622571dd --- /dev/null +++ b/packages/templates/wasm/rust/tests/e2e.rs @@ -0,0 +1,39 @@ +use template_wasm_rs::wrap::module::ArgsSampleMethod; +use polywrap::{ + PolywrapClient, + PolywrapClientConfig, + polywrap_core::uri::Uri, +}; +use polywrap_msgpack_serde::to_vec; +use std::path::Path; + +fn get_client() -> PolywrapClient { + let mut config = PolywrapClientConfig::new(); + PolywrapClient::new(config.into()) +} + +pub fn get_wrap_uri() -> Result { + let path = Path::new("../build") + .canonicalize() + .map_err(|e| e.to_string())? + .into_os_string() + .into_string() + .map_err(|e| format!("{e:?}"))?; + let uri = Uri::try_from(path).map_err(|e| e.to_string())?; + Ok(uri) +} + +#[test] +fn sample_method() { + let uri = get_wrap_uri().unwrap(); + let args = ArgsSampleMethod { + arg: "input data".to_string(), + }; + let encoded_args = to_vec(&args).unwrap(); + + let response = get_client() + .invoke::(&uri, "sampleMethod", Some(&encoded_args), None, None) + .unwrap(); + + assert_eq!(response, "input data from sample_method"); +} diff --git a/packages/templates/wasm/rust/tsconfig.json b/packages/templates/wasm/rust/tsconfig.json deleted file mode 100644 index 75bfa86f2e..0000000000 --- a/packages/templates/wasm/rust/tsconfig.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "compilerOptions": { - "lib": [ - "es2015", - "es5", - "dom" - ], - "esModuleInterop": true, - "outDir": "build", - "moduleResolution": "node", - "declaration": true, - "preserveSymlinks": true, - "preserveWatchOutput": true, - "pretty": false, - "forceConsistentCasingInFileNames": true, - "noFallthroughCasesInSwitch": true, - "noImplicitAny": true, - "noImplicitReturns": true, - "noUnusedLocals": true, - "module": "commonjs", - "sourceMap": true, - "target": "es5", - "resolveJsonModule": true, - "strictNullChecks": true, - "experimentalDecorators": true - }, - "typeAcquisition": { "include": ["jest"] } -} \ No newline at end of file From 2c32efac348db413e8fa885ea0d84127cd3d3546 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Thu, 31 Aug 2023 22:34:08 +0300 Subject: [PATCH 2/5] passing rust tests in wrap-rust template --- .../lib/project/manifests/app/languages.ts | 9 +++++ packages/schema/bind/src/bindings/index.ts | 4 ++ packages/schema/bind/src/types.ts | 1 + packages/templates/wasm/rust/package.json | 4 +- .../templates/wasm/rust/polywrap.test.cue | 2 +- packages/templates/wasm/rust/src/lib.rs | 2 +- packages/templates/wasm/rust/tests/e2e.rs | 40 ++++--------------- .../templates/wasm/rust/tests/types/mod.rs | 1 + .../rust/tests/types/polywrap.app.graphql | 1 + .../wasm/rust/tests/types/polywrap.app.yaml | 6 +++ 10 files changed, 35 insertions(+), 35 deletions(-) create mode 100644 packages/templates/wasm/rust/tests/types/mod.rs create mode 100644 packages/templates/wasm/rust/tests/types/polywrap.app.graphql create mode 100644 packages/templates/wasm/rust/tests/types/polywrap.app.yaml diff --git a/packages/cli/src/lib/project/manifests/app/languages.ts b/packages/cli/src/lib/project/manifests/app/languages.ts index 58261477de..9fa02320f8 100644 --- a/packages/cli/src/lib/project/manifests/app/languages.ts +++ b/packages/cli/src/lib/project/manifests/app/languages.ts @@ -5,6 +5,9 @@ import { BindLanguage } from "@polywrap/schema-bind"; export const appManifestLanguages = { "app/typescript": "app/typescript", "app/python": "app/python", + "app/rust": "app/rust", + "app/kotlin": "app/kotlin", + "app/swift": "app/swift", }; export type AppManifestLanguages = typeof appManifestLanguages; @@ -25,6 +28,12 @@ export function appManifestLanguageToBindLanguage( return "app-ts"; case "app/python": return "app-py"; + case "app/rust": + return "app-rs"; + case "app/kotlin": + return "app-kt"; + case "app/swift": + return "app-swift"; default: throw Error( intlMsg.lib_language_unsupportedManifestLanguage({ diff --git a/packages/schema/bind/src/bindings/index.ts b/packages/schema/bind/src/bindings/index.ts index 09fab68f6d..a330b9aa23 100644 --- a/packages/schema/bind/src/bindings/index.ts +++ b/packages/schema/bind/src/bindings/index.ts @@ -49,6 +49,10 @@ export function getGenerateBindingFn( return WrapBindgen.getGenerateBindingFn( "wrapscan.io/polywrap/app-python-abi-bindgen@1" ); + case "app-rs": + return WrapBindgen.getGenerateBindingFn( + "wrapscan.io/polywrap/app-rust-abi-bindgen@1" + ); case "app-swift": return WrapBindgen.getGenerateBindingFn( "wrapscan.io/polywrap/app-swift-abi-bindgen@1" diff --git a/packages/schema/bind/src/types.ts b/packages/schema/bind/src/types.ts index 4496a7bc9c..87ebc41815 100644 --- a/packages/schema/bind/src/types.ts +++ b/packages/schema/bind/src/types.ts @@ -12,6 +12,7 @@ export const bindLanguage = { "plugin-swift": "plugin-swift", "app-ts": "app-ts", "app-py": "app-py", + "app-rs": "app-rs", "app-swift": "app-swift", "app-kt": "app-kt", }; diff --git a/packages/templates/wasm/rust/package.json b/packages/templates/wasm/rust/package.json index 2ef7880e60..68356ad96b 100644 --- a/packages/templates/wasm/rust/package.json +++ b/packages/templates/wasm/rust/package.json @@ -7,7 +7,9 @@ "codegen": "npx polywrap codegen", "build": "npx polywrap build", "deploy": "npx polywrap deploy", - "test": "cargo test", + "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" }, "devDependencies": { diff --git a/packages/templates/wasm/rust/polywrap.test.cue b/packages/templates/wasm/rust/polywrap.test.cue index a71f50ace0..72c37000a6 100644 --- a/packages/templates/wasm/rust/polywrap.test.cue +++ b/packages/templates/wasm/rust/polywrap.test.cue @@ -3,7 +3,7 @@ package e2e sampleMethod: { $0: { data: { - value: "polywrap" + value: "polywrap from sample_method" }, error?: _|_, } diff --git a/packages/templates/wasm/rust/src/lib.rs b/packages/templates/wasm/rust/src/lib.rs index 6503dc136b..5141adeb94 100644 --- a/packages/templates/wasm/rust/src/lib.rs +++ b/packages/templates/wasm/rust/src/lib.rs @@ -4,7 +4,7 @@ pub use wrap::*; impl ModuleTrait for Module { fn sample_method(args: ArgsSampleMethod) -> Result { return Ok(SampleResult { - result: args.arg + result: format!("{} from sample_method", args.arg), }); } } diff --git a/packages/templates/wasm/rust/tests/e2e.rs b/packages/templates/wasm/rust/tests/e2e.rs index d3622571dd..47dba6af73 100644 --- a/packages/templates/wasm/rust/tests/e2e.rs +++ b/packages/templates/wasm/rust/tests/e2e.rs @@ -1,39 +1,15 @@ -use template_wasm_rs::wrap::module::ArgsSampleMethod; -use polywrap::{ - PolywrapClient, - PolywrapClientConfig, - polywrap_core::uri::Uri, +mod types; +use crate::types::wrap::types::{ + TemplateModule, + TemplateModuleArgsSampleMethod }; -use polywrap_msgpack_serde::to_vec; -use std::path::Path; - -fn get_client() -> PolywrapClient { - let mut config = PolywrapClientConfig::new(); - PolywrapClient::new(config.into()) -} - -pub fn get_wrap_uri() -> Result { - let path = Path::new("../build") - .canonicalize() - .map_err(|e| e.to_string())? - .into_os_string() - .into_string() - .map_err(|e| format!("{e:?}"))?; - let uri = Uri::try_from(path).map_err(|e| e.to_string())?; - Ok(uri) -} #[test] fn sample_method() { - let uri = get_wrap_uri().unwrap(); - let args = ArgsSampleMethod { + let args = TemplateModuleArgsSampleMethod { arg: "input data".to_string(), }; - let encoded_args = to_vec(&args).unwrap(); - - let response = get_client() - .invoke::(&uri, "sampleMethod", Some(&encoded_args), None, None) - .unwrap(); - - assert_eq!(response, "input data from sample_method"); + let template: TemplateModule = TemplateModule::new(None, None, None); + let response = template.sample_method(&args, None, None, None).unwrap(); + assert_eq!(response.result, "input data from sample_method"); } diff --git a/packages/templates/wasm/rust/tests/types/mod.rs b/packages/templates/wasm/rust/tests/types/mod.rs new file mode 100644 index 0000000000..9fd51ef761 --- /dev/null +++ b/packages/templates/wasm/rust/tests/types/mod.rs @@ -0,0 +1 @@ +pub mod wrap; \ No newline at end of file diff --git a/packages/templates/wasm/rust/tests/types/polywrap.app.graphql b/packages/templates/wasm/rust/tests/types/polywrap.app.graphql new file mode 100644 index 0000000000..f3741e82c8 --- /dev/null +++ b/packages/templates/wasm/rust/tests/types/polywrap.app.graphql @@ -0,0 +1 @@ +#import * into Template from "fs/build" \ No newline at end of file diff --git a/packages/templates/wasm/rust/tests/types/polywrap.app.yaml b/packages/templates/wasm/rust/tests/types/polywrap.app.yaml new file mode 100644 index 0000000000..5f9fbba0da --- /dev/null +++ b/packages/templates/wasm/rust/tests/types/polywrap.app.yaml @@ -0,0 +1,6 @@ +format: 0.3.0 +project: + name: template-wasm-rs-app-types + type: app/rust +source: + schema: ./polywrap.app.graphql From facdaf1e0d6427b56705d6d6bef5e60303414640 Mon Sep 17 00:00:00 2001 From: Kris Bitney Date: Fri, 1 Sep 2023 13:03:49 +0100 Subject: [PATCH 3/5] Update packages/templates/wasm/rust/Cargo.toml Co-authored-by: Cesar Brazon --- packages/templates/wasm/rust/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/templates/wasm/rust/Cargo.toml b/packages/templates/wasm/rust/Cargo.toml index ae83b5b56a..cacbf89f9a 100644 --- a/packages/templates/wasm/rust/Cargo.toml +++ b/packages/templates/wasm/rust/Cargo.toml @@ -11,7 +11,7 @@ include = ["src"] [dependencies] polywrap-wasm-rs = { version = "~0.11.2" } -polywrap_msgpack_serde = "~0.0.2-beta.5" +polywrap_msgpack_serde = "0.0.2-beta.7" serde = { version = "1.0", features = ["derive"] } [dev-dependencies] From ed76091226a98d135041b52d94db276f74670236 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Fri, 1 Sep 2023 15:24:31 +0300 Subject: [PATCH 4/5] updated versions and js dependencies in wrap-rust template --- packages/templates/wasm/rust/Cargo.toml | 2 +- packages/templates/wasm/rust/package.json | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/templates/wasm/rust/Cargo.toml b/packages/templates/wasm/rust/Cargo.toml index cacbf89f9a..457be6b146 100644 --- a/packages/templates/wasm/rust/Cargo.toml +++ b/packages/templates/wasm/rust/Cargo.toml @@ -15,7 +15,7 @@ polywrap_msgpack_serde = "0.0.2-beta.7" serde = { version = "1.0", features = ["derive"] } [dev-dependencies] -polywrap = { version = "~0.1.8" } +polywrap = { version = "0.1.9-beta.2" } [lib] crate-type = ["cdylib"] diff --git a/packages/templates/wasm/rust/package.json b/packages/templates/wasm/rust/package.json index 68356ad96b..5bb56df739 100644 --- a/packages/templates/wasm/rust/package.json +++ b/packages/templates/wasm/rust/package.json @@ -13,10 +13,6 @@ "test:workflow": "npx polywrap test" }, "devDependencies": { - "@types/jest": "26.0.8", - "jest": "26.6.3", - "polywrap": "0.11.2", - "ts-jest": "26.5.4", - "typescript": "4.9.5" + "polywrap": "0.11.2" } } From 6f02090228a2dcd8b49d3dae59f6968205a8a873 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Fri, 1 Sep 2023 15:36:09 +0300 Subject: [PATCH 5/5] refactored tests dir in wrap-rust template --- packages/templates/wasm/rust/tests/it/mod.rs | 1 + packages/templates/wasm/rust/tests/{e2e.rs => it/module.rs} | 1 - packages/templates/wasm/rust/tests/mod.rs | 2 ++ 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 packages/templates/wasm/rust/tests/it/mod.rs rename packages/templates/wasm/rust/tests/{e2e.rs => it/module.rs} (97%) create mode 100644 packages/templates/wasm/rust/tests/mod.rs diff --git a/packages/templates/wasm/rust/tests/it/mod.rs b/packages/templates/wasm/rust/tests/it/mod.rs new file mode 100644 index 0000000000..a94a2104e7 --- /dev/null +++ b/packages/templates/wasm/rust/tests/it/mod.rs @@ -0,0 +1 @@ +pub mod module; \ No newline at end of file diff --git a/packages/templates/wasm/rust/tests/e2e.rs b/packages/templates/wasm/rust/tests/it/module.rs similarity index 97% rename from packages/templates/wasm/rust/tests/e2e.rs rename to packages/templates/wasm/rust/tests/it/module.rs index 47dba6af73..a738738bbc 100644 --- a/packages/templates/wasm/rust/tests/e2e.rs +++ b/packages/templates/wasm/rust/tests/it/module.rs @@ -1,4 +1,3 @@ -mod types; use crate::types::wrap::types::{ TemplateModule, TemplateModuleArgsSampleMethod diff --git a/packages/templates/wasm/rust/tests/mod.rs b/packages/templates/wasm/rust/tests/mod.rs new file mode 100644 index 0000000000..e727a250b9 --- /dev/null +++ b/packages/templates/wasm/rust/tests/mod.rs @@ -0,0 +1,2 @@ +mod it; +mod types; \ No newline at end of file