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

fix: allow invoking with Uint8Array #947

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
63 changes: 63 additions & 0 deletions packages/js/client/src/__tests__/core/plugin-subinvoke.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Client, msgpackEncode, PluginModule } from "@polywrap/core-js";
import { PolywrapClient } from "../..";

describe("plugin-subinvoke", () => {
const mockPlugin = () => {
class MockPlugin extends PluginModule<Record<string, unknown>> {
public async call(
input: { input: Uint8Array },
client: Client
): Promise<ArrayBuffer> {
const res = await client.invoke({
uri: "ens/http.polywrap.eth",
Niraj-Kamdar marked this conversation as resolved.
Show resolved Hide resolved
method: "get",
input: input.input,
noDecode: true,
});
return res.data as ArrayBuffer;
}
}

return {
factory: () => new MockPlugin({}),
manifest: {
schema: ``,
implements: [],
},
};
};

test("call", async () => {
const client = new PolywrapClient({
plugins: [
{
uri: "ens/demo.eth",
plugin: mockPlugin(),
},
],
});

const input = new Uint8Array(
msgpackEncode({
url: "https://jsonplaceholder.typicode.com/posts",
request: {
headers: [],
urlParams: [],
responseType: 0,
body: "",
},
})
);

const result = await client.invoke({
uri: "ens/demo.eth",
method: "call",
input: {
input,
},
});

expect(result.error).toBeFalsy();
expect(result.data).toBeTruthy();
});
});
4 changes: 1 addition & 3 deletions packages/js/client/src/plugin/PluginWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ export class PluginWrapper extends Wrapper {
await this._sanitizeAndLoadEnv(client, module);

let jsInput: Record<string, unknown>;

// If the input is a msgpack buffer, deserialize it
if (input instanceof ArrayBuffer) {
if (input instanceof ArrayBuffer || input instanceof Uint8Array) {
Niraj-Kamdar marked this conversation as resolved.
Show resolved Hide resolved
const result = msgpackDecode(input);

Tracer.addEvent("msgpack-decoded", result);
Expand Down
5 changes: 4 additions & 1 deletion packages/js/client/src/wasm/WasmWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ export class WasmWrapper extends Wrapper {
invokeResult: {} as InvokeResult,
method,
sanitizeEnv: {},
args: input instanceof ArrayBuffer ? input : msgpackEncode(input),
args:
input instanceof ArrayBuffer || input instanceof Uint8Array
? input
: msgpackEncode(input),
};

const abort = (message: string) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/js/core/src/types/Invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface InvokeOptions<
* Input arguments for the method, structured as a map,
* removing the chance of incorrectly ordering arguments.
*/
input?: Record<string, unknown> | ArrayBuffer;
input?: Record<string, unknown> | Uint8Array | ArrayBuffer;

/**
* Filters the [[InvokeResult]] data properties. The key
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fileSystemPlugin } from "../index";
import { fileSystemPlugin } from "..";
import { PolywrapClient, PolywrapClientConfig } from "@polywrap/client-js";
import { FileSystem_Module, FileSystem_EncodingEnum } from "../wrap";
import fs from "fs";
Expand Down
2 changes: 1 addition & 1 deletion packages/js/plugins/file-system/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { PluginFactory } from "@polywrap/core-js";
type NoConfig = Record<string, never>;

export class FileSystemPlugin extends Module<NoConfig> {
async readFile(input: Input_readFile, _client: Client): Promise<ArrayBuffer> {
async readFile(input: Input_readFile, _client: Client): Promise<Uint8Array> {
return fs.promises.readFile(input.path);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type Int = number;
export type Int8 = number;
export type Int16 = number;
export type Int32 = number;
export type Bytes = ArrayBuffer;
export type Bytes = Uint8Array;
export type BigInt = string;
export type BigNumber = string;
export type Json = string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type Int = number;
export type Int8 = number;
export type Int16 = number;
export type Int32 = number;
export type Bytes = ArrayBuffer;
export type Bytes = Uint8Array;
export type BigInt = string;
export type BigNumber = string;
export type Json = string;
Expand Down
3 changes: 2 additions & 1 deletion packages/templates/wasm/assemblyscript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
"test:env:up": "npx polywrap infra up --modules=eth-ens-ipfs",
"test:env:down": "npx polywrap infra down --modules=eth-ens-ipfs",
"deploy": "npx polywrap deploy",
"test": "yarn test:e2e && yarn test:workflow",
"test:e2e": "yarn build && yarn test:e2e:codegen && jest --passWithNoTests --runInBand --verbose",
"test:e2e:codegen": "npx polywrap app codegen -m ./src/__tests__/types/polywrap.app.yaml -c ./src/__tests__/types/wrap",
"test:workflow": "yarn build && yarn test:env:up && sleep 5 && npx polywrap run ./workflows/e2e.yaml && yarn test:env:down"
"test:workflow": "yarn build && yarn test:env:up && sleep 5 && npx polywrap run ./workflows/e2e.yaml -c ./workflows/config.ts && yarn test:env:down"
},
"devDependencies": {
"@polywrap/ethereum-plugin-js": "0.0.1-prealpha.89",
Expand Down
13 changes: 0 additions & 13 deletions packages/templates/wasm/assemblyscript/workflows/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,6 @@ function getPlugins(
}),
},
],
interfaces: [
{
interface: coreInterfaceUris.uriResolver.uri,
implementations: [
"wrap://ens/ipfs.polywrap.eth",
"wrap://ens/ens.polywrap.eth",
],
},
{
interface: coreInterfaceUris.logger.uri,
implementations: ["wrap://ens/js-logger.polywrap.eth"],
},
],
};
}

Expand Down
6 changes: 0 additions & 6 deletions packages/templates/wasm/assemblyscript/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ jobs:
- uri: fs/build
method: deployContract
input:
connection:
networkNameOrChainId: testnet
jobs:
case1:
steps:
Expand All @@ -15,11 +13,7 @@ jobs:
input:
address: "$cases.0.data"
value: 100
connection:
networkNameOrChainId: testnet
- uri: fs/build
method: getData
input:
address: "$cases.0.data"
connection:
networkNameOrChainId: testnet
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type Int = number;
export type Int8 = number;
export type Int16 = number;
export type Int32 = number;
export type Bytes = ArrayBuffer;
export type Bytes = Uint8Array;
export type BigInt = string;
export type BigNumber = string;
export type Json = string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type Int = number;
export type Int8 = number;
export type Int16 = number;
export type Int32 = number;
export type Bytes = ArrayBuffer;
export type Bytes = Uint8Array;
export type BigInt = string;
export type BigNumber = string;
export type Json = string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type Int = number;
export type Int8 = number;
export type Int16 = number;
export type Int32 = number;
export type Bytes = ArrayBuffer;
export type Bytes = Uint8Array;
export type BigInt = string;
export type BigNumber = string;
export type Json = string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type Int = number;
export type Int8 = number;
export type Int16 = number;
export type Int32 = number;
export type Bytes = ArrayBuffer;
export type Bytes = Uint8Array;
export type BigInt = string;
export type BigNumber = string;
export type Json = string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type Int = number;
export type Int8 = number;
export type Int16 = number;
export type Int32 = number;
export type Bytes = ArrayBuffer;
export type Bytes = Uint8Array;
export type BigInt = string;
export type BigNumber = string;
export type Json = string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type Int = number;
export type Int8 = number;
export type Int16 = number;
export type Int32 = number;
export type Bytes = ArrayBuffer;
export type Bytes = Uint8Array;
export type BigInt = string;
export type BigNumber = string;
export type Json = string;
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5609,6 +5609,11 @@ caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001035, can
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001358.tgz#473d35dabf5e448b463095cab7924e96ccfb8c00"
integrity sha512-hvp8PSRymk85R20bsDra7ZTCpSVGN/PAz9pSAjPSjKC+rNmnUk5vCRgJwiTT/O4feQ/yu/drvZYpKxxhbFuChw==

caniuse-lite@^1.0.30001358:
version "1.0.30001358"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001358.tgz#473d35dabf5e448b463095cab7924e96ccfb8c00"
integrity sha512-hvp8PSRymk85R20bsDra7ZTCpSVGN/PAz9pSAjPSjKC+rNmnUk5vCRgJwiTT/O4feQ/yu/drvZYpKxxhbFuChw==

capture-exit@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/capture-exit/-/capture-exit-2.0.0.tgz#fb953bfaebeb781f62898239dabb426d08a509a4"
Expand Down Expand Up @@ -7289,6 +7294,11 @@ electron-to-chromium@^1.3.378, electron-to-chromium@^1.4.164:
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.168.tgz#8f6bda320a434ac963850d18e41d83220973cbdd"
integrity sha512-yz247hclRBaP8ABB1hf9kL7AMfa+yC2hB9F3XF8Y87VWMnYgq4QYvV6acRACcDkTDxfGQ4GYK/aZPQiuFMGbaA==

electron-to-chromium@^1.4.164:
version "1.4.167"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.167.tgz#72424aebc85df12c5331d37b1bcfd1ae01322c55"
integrity sha512-lPHuHXBwpkr4RcfaZBKm6TKOWG/1N9mVggUpP4fY3l1JIUU2x4fkM8928smYdZ5lF+6KCTAxo1aK9JmqT+X71Q==

elliptic@6.5.4, elliptic@^6.5.3:
version "6.5.4"
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb"
Expand Down