Skip to content

feat: add MoveOption.Address and MoveVector.Address factory methods#855

Open
gregnazario wants to merge 1 commit intomainfrom
cursor/moveoption-primitive-support-4a7e
Open

feat: add MoveOption.Address and MoveVector.Address factory methods#855
gregnazario wants to merge 1 commit intomainfrom
cursor/moveoption-primitive-support-4a7e

Conversation

@gregnazario
Copy link
Collaborator

Description

Add Address factory methods to both MoveOption and MoveVector for consistency with all other Move primitive types (U8, U16, U32, U64, U128, U256, Bool, I8–I256, MoveString).

Previously, MoveOption and MoveVector were missing convenience factory methods for the address primitive type, requiring users to manually construct new MoveOption(AccountAddress.from("0x1")) instead of the simpler MoveOption.Address("0x1").

New factory methods:

  • MoveOption.Address(value?) — creates MoveOption<AccountAddress> from AccountAddressInput (string, Uint8Array, or AccountAddress). Passing undefined/null/no argument creates an empty option.
  • MoveVector.Address(values) — creates MoveVector<AccountAddress> from an array of AccountAddressInput values.

Test Plan

  • Added comprehensive unit tests in tests/unit/bcsHelper.test.ts covering:
    • MoveOption.Address with string, long-form address, and AccountAddress instances
    • MoveOption.Address with undefined/null/no-arg for empty options
    • Serialization and deserialization roundtrips for both MoveOption.Address and MoveVector.Address
    • MoveVector.Address with string addresses, AccountAddress instances, and empty arrays
    • Added Address to existing undefined option and unwrap error tests
  • All 26 BCS helper tests pass (npx vitest run tests/unit/bcsHelper.test.ts)
  • pnpm check (Biome lint + format) passes
  • pnpm build succeeds

Related Links

Resolves the feature request in this PR for MoveOption to support all Move primitives including address.

Checklist

  • Have you ran pnpm fmt?
  • Have you updated the CHANGELOG.md?
Open in Web Open in Cursor 

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>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 construct MoveVector<AccountAddress> from AccountAddressInput[].
  • Add MoveOption.Address(value?) to construct MoveOption<AccountAddress> from AccountAddressInput | 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.

Comment on lines +835 to +841
* 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
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
* 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

Copilot uses AI. Check for mistakes.
Comment on lines +618 to +622
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);
});
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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").

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants