feat: add MoveOption.Address and MoveVector.Address factory methods#855
feat: add MoveOption.Address and MoveVector.Address factory methods#855gregnazario wants to merge 1 commit intomainfrom
Conversation
Add Address factory methods to both MoveOption and MoveVector for consistency with other Move primitive types. MoveOption was missing an Address convenience method, which made it harder for users to work with optional address values. - MoveOption.Address(value?) creates MoveOption<AccountAddress> from AccountAddressInput (string, Uint8Array, or AccountAddress) - MoveVector.Address(values) creates MoveVector<AccountAddress> from an array of AccountAddressInput values - Add comprehensive unit tests for serialization/deserialization of both new factory methods Co-authored-by: Greg Nazario <greg@gnazar.io>
There was a problem hiding this comment.
Pull request overview
Adds missing Address convenience factory methods to the BCS Move helpers so address is supported consistently alongside other Move primitives.
Changes:
- Add
MoveVector.Address(values)to constructMoveVector<AccountAddress>fromAccountAddressInput[]. - Add
MoveOption.Address(value?)to constructMoveOption<AccountAddress>fromAccountAddressInput | null | undefined. - Extend BCS helper unit tests and update changelog entries for the new factories.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/bcs/serializable/moveStructs.ts |
Adds MoveVector.Address and MoveOption.Address factory methods (with AccountAddress conversion). |
tests/unit/bcsHelper.test.ts |
Adds/extends unit tests covering MoveOption.Address and MoveVector.Address creation + serde roundtrips. |
CHANGELOG.md |
Documents the newly added factory methods under Unreleased “Added”. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * Factory method to generate a MoveOption<AccountAddress> from an `AccountAddressInput` or `undefined`. | ||
| * | ||
| * @example | ||
| * MoveOption.Address("0x1").isSome() === true; | ||
| * MoveOption.Address().isSome() === false; | ||
| * MoveOption.Address(undefined).isSome() === false; | ||
| * @param value the value used to fill the MoveOption. If `value` is undefined |
There was a problem hiding this comment.
The JSDoc for MoveOption.Address says it builds from an AccountAddressInput or undefined, but the signature and implementation also treat null as empty. Please update the doc/comment (including the @param description/examples) to reflect null being accepted, for consistency with the behavior and other MoveOption.* factories.
| * Factory method to generate a MoveOption<AccountAddress> from an `AccountAddressInput` or `undefined`. | |
| * | |
| * @example | |
| * MoveOption.Address("0x1").isSome() === true; | |
| * MoveOption.Address().isSome() === false; | |
| * MoveOption.Address(undefined).isSome() === false; | |
| * @param value the value used to fill the MoveOption. If `value` is undefined | |
| * Factory method to generate a MoveOption<AccountAddress> from an `AccountAddressInput`, `undefined`, or `null`. | |
| * | |
| * @example | |
| * MoveOption.Address("0x1").isSome() === true; | |
| * MoveOption.Address().isSome() === false; | |
| * MoveOption.Address(undefined).isSome() === false; | |
| * MoveOption.Address(null).isSome() === false; | |
| * @param value the value used to fill the MoveOption. If `value` is undefined or null |
| it("creates a MoveOption.Address with undefined correctly", () => { | ||
| expect(MoveOption.Address(undefined).isSome()).toBe(false); | ||
| expect(MoveOption.Address().isSome()).toBe(false); | ||
| expect(MoveOption.Address(null).isSome()).toBe(false); | ||
| }); |
There was a problem hiding this comment.
This test name says it only covers undefined, but the assertions also cover the no-arg and null cases. Consider renaming the test to reflect all the inputs it validates (e.g., "with undefined/null/no-arg creates an empty option").
Description
Add
Addressfactory methods to bothMoveOptionandMoveVectorfor consistency with all other Move primitive types (U8, U16, U32, U64, U128, U256, Bool, I8–I256, MoveString).Previously,
MoveOptionandMoveVectorwere missing convenience factory methods for theaddressprimitive type, requiring users to manually constructnew MoveOption(AccountAddress.from("0x1"))instead of the simplerMoveOption.Address("0x1").New factory methods:
MoveOption.Address(value?)— createsMoveOption<AccountAddress>fromAccountAddressInput(string, Uint8Array, or AccountAddress). Passingundefined/null/no argument creates an empty option.MoveVector.Address(values)— createsMoveVector<AccountAddress>from an array ofAccountAddressInputvalues.Test Plan
tests/unit/bcsHelper.test.tscovering:MoveOption.Addresswith string, long-form address, andAccountAddressinstancesMoveOption.Addresswithundefined/null/no-arg for empty optionsMoveOption.AddressandMoveVector.AddressMoveVector.Addresswith string addresses,AccountAddressinstances, and empty arraysAddressto existingundefinedoption andunwraperror testsnpx vitest run tests/unit/bcsHelper.test.ts)pnpm check(Biome lint + format) passespnpm buildsucceedsRelated Links
Resolves the feature request in this PR for
MoveOptionto support all Move primitives includingaddress.Checklist
pnpm fmt?CHANGELOG.md?