-
Notifications
You must be signed in to change notification settings - Fork 50
fix: allow invoking with Uint8Array #947
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
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
83aacb8
fix: allow invoking with Uint8Array
Niraj-Kamdar 2e19f57
refactor: types
Niraj-Kamdar e33a70e
fix: use Uint8Array instead of Arraybuffer in TS for Bytes
Niraj-Kamdar c1d46fc
refactor: DRY
Niraj-Kamdar de0b1d9
Merge remote-tracking branch 'upstream/prealpha-dev' into nk/msgpack-…
Niraj-Kamdar 2cdd29d
chore: update yarn.lock
Niraj-Kamdar 511a7b6
wip
Niraj-Kamdar aaa1140
Merge remote-tracking branch 'upstream/prealpha-dev' into nk/msgpack-…
Niraj-Kamdar 1754e9a
fix(templates): tests
Niraj-Kamdar b7f25bf
chore: minor fixes
Niraj-Kamdar b414dc1
refactor: remove unnecessary code
Niraj-Kamdar 5087572
refactor: remove unnecessary code
Niraj-Kamdar 1c4164f
chore: remove yarn.lock file
Niraj-Kamdar 2be39bc
chore: use msgpack to encode data instead passing blob
Niraj-Kamdar dbcdb8c
Merge remote-tracking branch 'upstream/prealpha-dev' into nk/msgpack-…
Niraj-Kamdar f0b9ca4
fix(client-js): remove deps of http from the plugin subinvoke test
Niraj-Kamdar 648db28
Merge remote-tracking branch 'upstream/prealpha-dev' into nk/msgpack-…
Niraj-Kamdar 021e9cb
Merge remote-tracking branch 'upstream/prealpha-dev' into nk/msgpack-…
Niraj-Kamdar 08926c8
fix: use generic ArrayBufferView instead of Uint8Array
Niraj-Kamdar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
packages/js/client/src/__tests__/core/plugin-subinvoke.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,73 @@ | ||||||
import { Client, PluginModule } from "@polywrap/core-js"; | ||||||
import { PolywrapClient } from "../.."; | ||||||
|
||||||
describe("plugin-subinvoke", () => { | ||||||
const mockPlugin = () => { | ||||||
class MockPlugin extends PluginModule<Record<string, unknown>> { | ||||||
public async call( | ||||||
args: { input: Uint8Array }, | ||||||
client: Client | ||||||
): Promise<ArrayBuffer> { | ||||||
const res = await client.invoke({ | ||||||
uri: "ens/is-even.eth", | ||||||
method: "isEven", | ||||||
args: args.input, | ||||||
}); | ||||||
return res.data as ArrayBuffer; | ||||||
} | ||||||
} | ||||||
|
||||||
return { | ||||||
factory: () => new MockPlugin({}), | ||||||
manifest: { | ||||||
schema: ``, | ||||||
implements: [], | ||||||
}, | ||||||
}; | ||||||
}; | ||||||
|
||||||
const isEvenPlugin = () => { | ||||||
class IsEvenPlugin extends PluginModule<Record<string, unknown>> { | ||||||
public isEven(args: {num: number}, client: Client): boolean { | ||||||
return (args.num & 1) ? false : true; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
|
||||||
return { | ||||||
factory: () => new IsEvenPlugin({}), | ||||||
manifest: { | ||||||
schema: ``, | ||||||
implements: [], | ||||||
}, | ||||||
}; | ||||||
}; | ||||||
|
||||||
test("call", async () => { | ||||||
const client = new PolywrapClient({ | ||||||
plugins: [ | ||||||
{ | ||||||
uri: "ens/demo.eth", | ||||||
plugin: mockPlugin(), | ||||||
}, | ||||||
{ | ||||||
uri: "ens/is-even.eth", | ||||||
plugin: isEvenPlugin(), | ||||||
} | ||||||
], | ||||||
}); | ||||||
|
||||||
// msgpackEncode({num: 10000}) -> [129, 163, 110, 117, 109, 205, 39, 16] | ||||||
const input = Uint8Array.from([129, 163, 110, 117, 109, 205, 39, 16]) | ||||||
|
||||||
const result = await client.invoke({ | ||||||
uri: "ens/demo.eth", | ||||||
method: "call", | ||||||
args: { | ||||||
input, | ||||||
}, | ||||||
}); | ||||||
|
||||||
expect(result.error).toBeFalsy(); | ||||||
expect(result.data).toBeTruthy(); | ||||||
}); | ||||||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.