-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: typegen support for passing Uint8Array
as Vec<u8>
#2884
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@fuel-ts/abi-typegen": patch | ||
--- | ||
|
||
feat: add typegen support for passing `Uint8Array` as `Vec<u8>` |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -34,6 +34,19 @@ describe('Vector Tests', () => { | |||||||||
expect(value).toStrictEqual(INPUT); | ||||||||||
}); | ||||||||||
|
||||||||||
it('should test u8 vector input/output as Uint8Array', async () => { | ||||||||||
using contractInstance = await setupContract(); | ||||||||||
const INPUT = [8, 6, 7, 5, 3, 0, 9]; | ||||||||||
const INPUT_AS_UINT8_ARRAY = Uint8Array.from(INPUT); | ||||||||||
Comment on lines
+39
to
+40
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
Is it worth adding the types here, to ensure they work as intended? 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. @petertonysmith94 there's a separate issue for those types #2785, but I'm gonna be making changes to this PR regardless: #2884 (comment) |
||||||||||
|
||||||||||
const { waitForResult } = await contractInstance.functions | ||||||||||
.echo_u8(INPUT_AS_UINT8_ARRAY) | ||||||||||
.call<Uint8Array>(); | ||||||||||
const { value } = await waitForResult(); | ||||||||||
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. We are always returning a 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. @nedsalk that's a great catch. I completely missed this. I considered this deeper approach with changes deeper inside the Vec type but thought I might be able to get away with something quick like this. I will revert this PR and come back with a better approach that is more modular and flexible |
||||||||||
|
||||||||||
expect(Uint8Array.from(value)).toStrictEqual(INPUT_AS_UINT8_ARRAY); | ||||||||||
}); | ||||||||||
|
||||||||||
it('should test u16 vector input/output', async () => { | ||||||||||
using contractInstance = await setupContract(); | ||||||||||
const INPUT = [8, 6, 7, 5, 3, 0, 9]; | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be a problem for
u16
andu32
values becauseBigNumberish
is used for them as well, but theUint8Array
cannot store their values and that is the reason why I created #2785. Users might get the false impression that they can passUint8Array
foru16
andu32
vectors.I think that this problem cannot be solved on the level of the generated types like this; rather, the checks must be done somewhere in typegen where abi type parsing is happening.