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

feat: add wrapper subinvoke test case #1328

Merged
merged 4 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions packages/js/client/src/__tests__/e2e/test-cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1119,3 +1119,23 @@ export const runComplexEnvs = async (
array: [32, 23],
});
};

export const runSubinvokeTest = async (
client: PolywrapClient,
uri: string,
) => {
{
const response = await client.invoke({
uri,
method: "add",
args: {
a: 1,
b: 2
},
});

if (!response.ok) fail(response.error);
expect(response.value).toBeTruthy();
expect(response.value).toEqual(3);
}
};
22 changes: 22 additions & 0 deletions packages/js/client/src/__tests__/e2e/wasm-as.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,28 @@ describe("wasm-as test cases", () => {
await TestCases.runAsyncifyTest(client, wrapperUri);
});

it("subinvoke", async() => {
const wrapperPath = `${GetPathToTestWrappers()}/wasm-as/simple-subinvoke/invoke`;
const wrapperUri = `fs/${wrapperPath}/build`;

const subwrapperPath = `${GetPathToTestWrappers()}/wasm-as/simple-subinvoke/subinvoke`;
const subwrapperUri = `fs/${subwrapperPath}/build`;

await buildWrapper(subwrapperPath);
await buildWrapper(wrapperPath);

const client = await getClient({
redirects: [
{
from: "ens/add.eth",
to: subwrapperUri
}
]
});

await TestCases.runSubinvokeTest(client, wrapperUri);
})

it("bigint-type", async () => {
const wrapperPath = `${GetPathToTestWrappers()}/wasm-as/bigint-type`;
const wrapperUri = `fs/${wrapperPath}/build`;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "test-case-simple-invoke",
"private": true,
"dependencies": {
"@polywrap/wasm-as": "0.9.1",
"assemblyscript": "0.19.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format: 0.2.0
project:
name: Simple
type: wasm/assemblyscript
source:
schema: ./schema.graphql
module: ./src/index.ts
import_abis:
- uri: ens/add.eth
abi: ../subinvoke/build/wrap.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import * into Add from "ens/add.eth"

type Module {
add(a: Int!, b: Int!): Int!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Args_add, Add_Module } from "./wrap";
import { Args_add as ImportedArgs_add } from "./wrap/imported/Add_Module/serialization";

export function add(args: Args_add): i32 {
let importedArgs: ImportedArgs_add = {
a: args.a,
b: args.b
}
return Add_Module.add(importedArgs).unwrap()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "test-case-simple-subinvoke",
"private": true,
"dependencies": {
"@polywrap/wasm-as": "0.9.1",
"assemblyscript": "0.19.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
format: 0.2.0
project:
name: Simple
type: wasm/assemblyscript
source:
schema: ./schema.graphql
module: ./src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type Module {
add(a: Int!, b: Int!): Int!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Args_add } from "./wrap";

export function add(args: Args_add): i32 {
return args.a + args.b
}