-
Couldn't load subscription status.
- Fork 2
feat: defined type #27
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
Conversation
WalkthroughThis pull request updates the package version and refactors the MoveBuilder API. It renames methods in the MoveBuilder class, updates their return types, and enhances error handling. The exports in the public API have been expanded with new type definitions, and a new types file has been added. Test cases have been updated to reflect these naming and output changes. Additionally, Move contract files have been modified to incorporate friend module declarations and new friend-accessible functions, along with adjustments in configuration. Changes
Sequence Diagram(s)sequenceDiagram
participant Hihi as test::hihi
participant Dummy as test::dummy
Hihi->>Dummy: call return_10_by_friend()
Dummy-->>Hihi: returns 10
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🔭 Outside diff range comments (2)
src/builder.ts (2)
319-342:⚠️ Potential issueFix inconsistent error message.
The error message at line 339 says "Failed to decode module bytes," which can cause confusion since this method is nameddecodeScriptBytes.Apply this change to ensure a relevant error message:
- throw new Error('Failed to decode module bytes') + throw new Error('Failed to decode script bytes')
349-381: 🛠️ Refactor suggestionUpdate error message to match function logic.
The error message at line 369 also says "Failed to decode module bytes," whilereadModuleInfois intended to read module info. This mismatch could cause debugging confusion.Proposed fix:
- throw new Error('Failed to decode module bytes') + throw new Error('Failed to read module info')
🧹 Nitpick comments (2)
test/build.spec.ts (2)
136-144: Remove duplicate test case.This test case is nearly identical to the previous "reads module info correctly" test at lines 109-122. Consider removing this duplicate to avoid test redundancy.
139-139: Remove unnecessary empty line.This empty line can be removed for better code formatting.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
package.json(1 hunks)src/builder.ts(5 hunks)src/index.ts(1 hunks)src/types/index.ts(1 hunks)src/types/type.ts(1 hunks)test/build.spec.ts(3 hunks)test/contract/dummy/Move.toml(1 hunks)test/contract/dummy/sources/dummy.move(2 hunks)test/contract/dummy/sources/hihi.move(1 hunks)test/script.spec.ts(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- package.json
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Test & Build
🔇 Additional comments (12)
test/contract/dummy/Move.toml (1)
10-10: Configuration change aligns with module namespace update.This change in the address configuration aligns with the module namespace update from
test2::hihitotest::hihiobserved in other files. The removal oftest2="_"while keepingtest="_"ensures consistency across the codebase.src/types/index.ts (1)
6-6: Good addition of type exports.Exporting type definitions from the new
type.tsfile enhances the module's public API and ensures type consistency throughout the codebase.test/contract/dummy/sources/hihi.move (2)
1-3: Module namespace updated with correct dependency.The module namespace has been changed from
test2::hihitotest::hihi, which aligns with the configuration changes in Move.toml. The import for the dummy module has been correctly added to support the new friend relationship.
11-14: Good implementation of friend function call.The new
call_friendfunction correctly utilizes the friend relationship established with the dummy module, callingdummy::return_10_by_friend(). This demonstrates proper usage of the Move language's friend access control.test/contract/dummy/sources/dummy.move (2)
2-2: Friend declaration correctly added.The friend declaration for the hihi module is properly specified, establishing the necessary access control relationship.
12-14: Well-implemented friend-accessible function.The
return_10_by_friendfunction is correctly implemented with thepublic(friend)visibility modifier, making it accessible only to the declared friend modules liketest::hihi.src/builder.ts (1)
289-312: Looks good overall.
The null-check and returning a strongly-typed interface (DecodedModuleBytes) is a clean approach.src/index.ts (1)
1-8: LGTM: Clean export additions.The additional type exports (
ModuleInfo,DecodedModuleBytes,DecodedScriptBytes) are well-structured and enhance the module's public API with more specific type definitions.test/script.spec.ts (1)
19-28: LGTM: Clean test update.The change from
decode_script_bytestodecodeScriptBytesmaintains consistent camelCase naming conventions, and the structured object assertion improves readability and type safety compared to string comparison.src/types/type.ts (1)
9-22: LGTM: Well-structured interfaces.The
DecodedScriptBytesandModuleInfointerfaces are properly defined with appropriate types that match their usage in the codebase.test/build.spec.ts (2)
36-106: LGTM: Well-structured test updates.The changes to method names (from snake_case to camelCase) and the shift to structured object assertions improve readability and type safety. The test comprehensively validates both modules' functionality.
114-121: LGTM: Clean module info test.The test correctly verifies the
readModuleInfofunctionality with appropriate assertions.
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.
Actionable comments posted: 1
🧹 Nitpick comments (4)
src/types/type.ts (3)
1-24: Add documentation and consider using more specific types.The
DecodedModuleBytesinterface is well structured and addresses the previous feedback by properly typing the array properties. However, adding JSDoc comments would improve developer experience and code maintainability.Consider also using more specific types for fields like
visibilitywhich likely has a limited set of valid values (e.g., using a string union type or enum).+/** + * Represents a decoded Move module with its metadata and structure. + */ export interface DecodedModuleBytes { + /** The address where the module is deployed */ address: string + /** The name of the module */ name: string + /** List of friend modules that have access to internal functions */ friends: string[] + /** List of functions exposed by this module */ exposed_functions: { name: string - visibility: string + visibility: "public" | "friend" | "private" | string is_entry: boolean is_view: boolean generic_type_params: string[] params: string[] return: string[] }[] + /** List of structs defined in this module */ structs: { name: string is_native: boolean - abilities: string[] + abilities: ("copy" | "drop" | "store" | "key" | string)[] generic_type_params: string[] fields: { name: string type: string }[] }[] }
26-34: Document theDecodedScriptBytesinterface and consider using a union type for visibility.Similar to the previous interface, this would benefit from JSDoc documentation to explain its purpose and properties.
+/** + * Represents a decoded Move script with its metadata and structure. + */ export interface DecodedScriptBytes { + /** The name of the script */ name: string - visibility: string + /** The visibility level of the script */ + visibility: "public" | "friend" | "private" | string + /** Whether this is an entry function that can be called directly */ is_entry: boolean + /** Whether this is a view function (read-only) */ is_view: boolean + /** List of generic type parameters */ generic_type_params: string[] + /** List of parameter types */ params: string[] + /** List of return types */ return: string[] }
36-39: Document theModuleInfointerface for completeness.Although this is a simple interface, adding JSDoc comments would maintain consistency with the other interfaces.
+/** + * Basic information about a Move module. + */ export interface ModuleInfo { + /** The address where the module is deployed */ address: string + /** The name of the module */ name: string }test/contract/dummy/sources/hihi.move (1)
4-6: New struct added with appropriate abilitiesThe
HiHistruct with thestoreability allows this type to be stored inside other structs or in global storage. The inclusion of this struct follows Move's best practices.Consider adding a comment explaining the purpose of this struct and how it's intended to be used within the module.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/types/type.ts(1 hunks)test/build.spec.ts(3 hunks)test/contract/dummy/sources/hihi.move(1 hunks)
🔇 Additional comments (7)
test/contract/dummy/sources/hihi.move (2)
1-2: Module namespace has changed appropriatelyThe module name has been changed from
test2::hihitotest::hihi, which matches the namespace change reflected in the test file'sadditionalNamedAddressesconfiguration.
2-2: Added required import for friend functionalityThe import statement for
test::dummyis correctly added, which is necessary to access the friend function.test/build.spec.ts (5)
18-18: Address configuration simplified for clarityThe
additionalNamedAddressesconfiguration has been reduced to just include thetestmodule at address0x4, which matches the module namespace change in hihi.move.
36-70: Test updated to verify module friend relationshipsThe test expectations have been properly updated to use the new camelCase API method
decodeModuleBytes. The test now correctly verifies that:
- The dummy module declares the hihi module as a friend
- The new friend-visible function
return_10_by_friendis properly exposed- The function signature and visibility are correctly set
This ensures that the friend module pattern is working as expected.
72-114: Test updated to verify new struct and functionThe test verifies that the code changes in hihi.move are correctly reflected after compilation:
- The new
call_friendfunction is properly exposed- The new
HiHistruct with the correct field and ability is detected- The visibility and signature information are correctly maintained
All expectations match the changes made to the source file.
122-129: Module info reading test updated properlyThe test has been updated to use the new camelCase method
readModuleInfoand properly verifies that both modules have the expected address and name.
146-150: Duplicate test updated with new API methodThis second test for reading module info has been correctly updated to use the new
readModuleInfomethod, maintaining consistency.
Summary by CodeRabbit
Chores
New Features