Skip to content

chore: code-style fixes per STYLEGUIDE#392

Open
bidzyyys wants to merge 3 commits into
mainfrom
chore/code-style-fixes
Open

chore: code-style fixes per STYLEGUIDE#392
bidzyyys wants to merge 3 commits into
mainfrom
chore/code-style-fixes

Conversation

@bidzyyys

@bidzyyys bidzyyys commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

General code-style cleanup against STYLEGUIDE.md. Does not close any issue.

Changes

  • STYLEGUIDE.md — codify doc-comments as the API source of truth (rendered by sui move build --doc, consumed by AI-integrator tooling):
    • #### Aborts lists every error a function can raise, including errors propagated from internal calls;
    • state caller preconditions and map each to its error;
    • #### Parameters / #### Returns only where they add detail beyond the one-line summary (a trivial getter needs neither);
    • pin-exact exception: approximation tests that check an on-chain result against an off-chain mathematical reference within a tolerance (e.g. assert!(diff < epsilon)) stay bound-based — do not convert to assert_eq!.
  • Struct field docs — document the hot-potato struct fields in access (delayed/two_step Borrow, two_step RequestBorrow) and fixed_point Components.
  • Test naming — drop the test_ prefix from access_control_tests functions (descriptive names per STYLEGUIDE Testing), matching the sibling test modules.

Verification

sui move test --build-env testnet --lint --warnings-are-errors and sui move build --doc --build-env testnet, all green:

  • contracts/access — 137 tests
  • math/core — 753 tests
  • math/fixed_point — 426 tests

Out of scope (follow-up)

access_control_tests still carries #[allow(lint(...))] (4) and abort 999 sentinels (43); removing them requires restructuring the expected-failure tests (and resolving share_owned) and is left to a separate focused PR.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Updated the Move style guide to clarify testing rules for tolerance-based approximation tests and to require richer public-function doc-comments, including complete Aborts/error documentation and caller preconditions.
    • Refreshed introductory text in the LLMs documentation and added clearer public type doc-comments.
  • Style
    • Reformatted internal “hot potato” transfer helper structs and added field-level documentation with no behavioral changes.
  • Tests
    • Expanded and reshaped AccessControl test coverage, including renamed cases and additional negative/boundary scenarios for admin/role and default-admin delay behaviors.

- STYLEGUIDE: codify doc-comments as the API source of truth — Aborts lists every error (including propagated), preconditions map to their error, and Parameters/Returns are included only where they add detail beyond the summary; add a pin-exact exception for tolerance/approximation assertions (e.g. fixed-point log/sqrt vs an off-chain reference).
- Document struct fields on the access hot-potato structs (delayed/two_step Borrow, two_step RequestBorrow) and fixed_point Components.
- Drop the test_ prefix from access_control_tests functions (descriptive names per STYLEGUIDE Testing).

Verified with sui move test --lint --warnings-are-errors and build --doc (testnet): access 137, math/core 753, math/fixed_point 426 — all green.
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.88%. Comparing base (cdd87d1) to head (210a1a9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #392      +/-   ##
==========================================
- Coverage   78.90%   78.88%   -0.02%     
==========================================
  Files          23       23              
  Lines        1782     1781       -1     
  Branches      640      640              
==========================================
- Hits         1406     1405       -1     
  Misses        341      341              
  Partials       35       35              
Flag Coverage Δ
contracts/access 65.46% <ø> (+0.05%) ⬆️
contracts/utils 44.09% <ø> (ø)
math/fixed_point 56.51% <ø> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bidzyyys

Copy link
Copy Markdown
Collaborator Author

Comment thread STYLEGUIDE.md

#[test]
#[allow(lint(share_owned))]
fun test_new_with_otw_succeeds() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have to remove this? Similar to removing test_only from the module definition, I think it may harm readability. I think this prefix helps to quickly recognize that a function is a tests, for example, when you are ctrl+shift+F through the workspace, similar to why keeping the tests suffix in the file name helps with readability even when is not a requirement. cc @0xNeshi for you thoughts too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@0xNeshi 0xNeshi Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I agree with Daniel's choice here.

Ctrl+shift+F-ing is straightforward even without the prefix, as you have many indicators you're looking at a test function: #[test] attribute, _tests suffix in the file name, name describes a flow instead of an action (and usually includes succeeds/fails).

I'd go as far as removing the _tests suffix from test module names (like is done in Rust), but having that suffix is a convention in Move on Sui (aligns test module name with the file name).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This one is the one that has the less strong argument to keep, so I'm ok with removing it. But to me is not the same as removing test_only annotations inside test files, or removing the test suffix on test files, in the sense that there is no an easy visual way then of recognizing these elements without checking the path to see where they are contained, for example when you do ctrl+P on cursor, or when you ctrl+shft+F. It looks like a regression to me on those cases, since there is no clear advantage besides removing a few short lines of code.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm ok with leaving test_ prefix. It doesn't improve clarity for me, but I don't mind leaving it if it helps you.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b2f85bdc-c05b-4e4b-97de-c2be9dad819c

📥 Commits

Reviewing files that changed from the base of the PR and between 645efdc and 210a1a9.

📒 Files selected for processing (1)
  • llms.txt
✅ Files skipped from review due to trivial changes (1)
  • llms.txt

📝 Walkthrough

Walkthrough

Refines STYLEGUIDE.md with rules for approximation #[random_test] functions and public-function #### Aborts doc-comment requirements. Adds per-field doc-comments to Borrow, RequestBorrow, and Components structs. Updates llms.txt introduction. Renames and expands access_control_tests.move test functions with new state-consistency and boundary cases.

Changes

Documentation and Test Hygiene

Layer / File(s) Summary
STYLEGUIDE.md: random_test and Aborts doc rules
STYLEGUIDE.md
Adds an exception that approximation-style #[random_test] functions using epsilon/tolerance must stay bound-based and not be rewritten with assert_eq!. Expands public-function doc-comment rules to mandate a complete #### Aborts section listing all errors (including propagated ones) and explicit caller preconditions.
Struct field documentation
contracts/access/sources/ownership_transfer/delayed.move, contracts/access/sources/ownership_transfer/two_step.move, math/fixed_point/sources/sd29x9/sd29x9_base.move
Reformats Borrow and RequestBorrow from single-line to multi-line structs with per-field doc-comments (wrapper_id, object_id). Adds module-level and neg-field doc-comments to Components. No field types or public signatures change.
llms.txt introduction update
llms.txt
Rewrites the opening introductory paragraph to emphasize "Audited, composable Move building blocks," adjust sentence flow and phrasing around reviewed primitives, and guide readers to browse the catalogs below. Document structure and other sections remain unchanged.
access_control_tests: constructor, grant/revoke/renounce, set_role_admin
contracts/access/tests/access_control_tests.move
Renames test functions across constructor, grant_role, revoke_role, renounce_role, and set_role_admin sections. Adds a companion negative test ensuring the previous admin no longer has grant authority after set_role_admin shifts the role admin.
access_control_tests: read-only queries and auth issuance
contracts/access/tests/access_control_tests.move
Renames has_role, assert_has_role, get_role_admin, protected_root, delay-persistence, and auth-issuance test functions including non-member, foreign-role, and root-holder failure paths.
access_control_tests: admin transfer/accept/cancel and pending-state regression
contracts/access/tests/access_control_tests.move
Renames and extends admin transfer/accept tests with exact-delay boundary acceptance. Adds a state-consistency regression verifying cancel_default_admin_transfer fully clears pending state so a subsequent begin_default_admin_transfer produces correct values. Adds composability-chain negative test.
access_control_tests: renounce, delay changes, auto-apply, and cancellation
contracts/access/tests/access_control_tests.move
Renames begin/accept admin renounce tests and adds mismatched pending-action kind rejection. Renames delay-change tests for cap/boundary/overwrite behavior. Covers automatic delay application and cancellation noninterference paths including the "apply elapsed pending before new schedule" sequence.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

  • OpenZeppelin/contracts-sui#370: Both PRs modify STYLEGUIDE.md — the retrieved PR introduced the initial coding conventions and the current PR refines #[random_test] and #### Aborts doc-comment requirements.
  • OpenZeppelin/contracts-sui#338: Both PRs modify access_control_tests.move around default-admin-delay change and clock-aware timing assertions including cancel and elapsed-delay boundary scenarios.
  • OpenZeppelin/contracts-sui#394: Both PRs modify llms.txt documentation — the retrieved PR introduced the initial LLM guide and the current PR refines its introduction text.

Suggested reviewers

  • immrsd
  • 0xNeshi

Poem

🐇 Hoppity-hop through the style guide I go,
Fixing the rules so the docs clearly show.
Aborts must be listed, each error in line,
Hot-potato structs now have comments so fine.
And random tests keep their epsilon bound—
No assert_eq! where approximations are found! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: code-style fixes implementing STYLEGUIDE standards across documentation, struct fields, and test naming.
Description check ✅ Passed The description comprehensively covers the changes, includes verification steps with test results, and clearly identifies out-of-scope items; the PR Checklist template structure is not critical for non-feature PRs like this styleguide cleanup.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/code-style-fixes

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread STYLEGUIDE.md
- Document public functions with at least `Parameters` and `Returns`; include an
`Aborts` section whenever a function can abort
- Document public functions: include `#### Parameters` and `#### Returns` where
they add detail beyond the one-line summary — a trivial getter whose summary

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
they add detail beyond the one-line summary a trivial getter whose summary
they add detail beyond the one-line summary - a trivial getter whose summary

Update all em dashes into regular dashes, see #388

Comment thread STYLEGUIDE.md
Comment on lines +252 to +254
already states what it returns needs neither. Always include an `#### Aborts`
section whenever a function can abort, listing **every** error it can raise —
including errors propagated from internal calls

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Apply this rule to all existing functions, i.e. double check if all docs follow this rule.

Also, align the following docs:

  • in math/core none of the fun inv_mod and fun mul_mod implementations list the actual underlying abort error, e.g. see u16.move and u256.move
  • in macros.move, in the fun mul_div, the format of the #### Aborts message is misaligned with existing convention

Comment thread STYLEGUIDE.md
Comment on lines +252 to +254
already states what it returns needs neither. Always include an `#### Aborts`
section whenever a function can abort, listing **every** error it can raise —
including errors propagated from internal calls

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Specify should the #### Aborts section appear if no custom errors are emitted.
Two options:

  1. No section - any native errors (e.g. arithmetic) are implied
  2. Display section, but only if native errors can appear

Currently there are functions that don't follow any established convention:

Comment thread STYLEGUIDE.md
section whenever a function can abort, listing **every** error it can raise —
including errors propagated from internal calls
- State caller preconditions explicitly and map each to the error it fails with
(e.g. "Aborts with `EUnauthorized` if the caller lacks the role")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
(e.g. "Aborts with `EUnauthorized` if the caller lacks the role")
(e.g. "`EUnauthorized` if the caller lacks the role")

This is the actual current convention, see access_control.move.
Related to this, align the abort message format of decimal_scaling.move > validate_decimals.

bidzyyys added 2 commits June 17, 2026 15:11
Drop the hardcoded primitive list (access control / math / rate limiting) from the blockquote — it drifts as the library grows. Reframe around discovery.
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