Skip to content

test: remove #[test_only] from *_tests modules#389

Merged
0xNeshi merged 5 commits into
mainfrom
remove-test-only
Jun 18, 2026
Merged

test: remove #[test_only] from *_tests modules#389
0xNeshi merged 5 commits into
mainfrom
remove-test-only

Conversation

@0xNeshi

@0xNeshi 0xNeshi commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

As per docs, the #[test_only] attribute is used to only include the annotated code in the final bytecode output if the mode is set to test, i.e. sui move build --mode test or sui move test (uses --mode test by default).
This is used when some module in the sources/* contains test-specific code (see move best practices)

However, any module inside the tests/* directory is by default only ever included in the final bytecode if --mode test is set (see Move Book > Packages).
Confirmed this claim locally.

Removing the attribute from modules inside tests/* results in no bytecode changes in any mode.

Summary by CodeRabbit

  • Tests
    • Removed test-only compilation restrictions across many Move test suites and helper utilities, making these modules available outside test-only build contexts.
    • Updated select test helper constructs to remove test-only gating (including module/fixture annotations), without changing any test logic or assertions.

@0xNeshi 0xNeshi self-assigned this Jun 16, 2026
@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: cee10688-5631-42f4-982f-f1e1cc752826

📥 Commits

Reviewing files that changed from the base of the PR and between ce86970 and db8fa58.

📒 Files selected for processing (1)
  • contracts/access/tests/access_control_tests.move
🚧 Files skipped from review as they are similar to previous changes (1)
  • contracts/access/tests/access_control_tests.move

📝 Walkthrough

Walkthrough

The PR uniformly removes #[test_only] attributes from module declarations, public structs, and helper functions across all test files in the contracts/access, contracts/utils, math/core, and math/fixed_point packages. No test logic, function bodies, or signatures are changed. A total of 58 attribute removals span 7 test modules in access, 4 in utils, 12 in math/core, 19 in math/fixed_point sd29x9 (plus internal), and 16 in math/fixed_point ud30x9.

Changes

Remove #[test_only] from test modules across all packages

Layer / File(s) Summary
access package test modules
contracts/access/tests/access_control_tests.move, contracts/access/tests/delayed_tests.move, contracts/access/tests/foreign_role.move, contracts/access/tests/two_step_tests.move
Removes #[test_only] from module declarations and item-level declarations: setup and take_ac helpers in access_control_tests (with added explanatory comment); DummyCap struct in delayed_tests; module in foreign_role; DummyCap struct and dummy_ctx_with_sender helper in two_step_tests.
utils package test modules
contracts/utils/tests/rate_limiter_tests.move, contracts/utils/examples/rate_limiter/tests/faucet_tests.move, contracts/utils/examples/rate_limiter/tests/rare_coin_tests.move, contracts/utils/examples/rate_limiter/tests/staking_vault_tests.move
Removes #[test_only] from module declarations in rate_limiter_tests and all three rate_limiter example test modules.
math/core test modules
math/core/tests/common_tests.move, math/core/tests/decimal_scaling_tests.move, math/core/tests/macros/is_power_of_ten.move, math/core/tests/macros/median.move, math/core/tests/macros/quick_sort.move, math/core/tests/u8_tests.move, math/core/tests/u16_tests.move, math/core/tests/u32_tests.move, math/core/tests/u64_tests.move, math/core/tests/u256_tests.move, math/core/tests/u512_tests.move
Removes #[test_only] from module declarations across all math/core test files; quick_sort also loses the attribute on its Transfer struct.
math/fixed_point sd29x9 and internal test modules
math/fixed_point/tests/internal/raw_log2_tests.move, math/fixed_point/tests/sd29x9_tests/arithmetic_tests.move, math/fixed_point/tests/sd29x9_tests/ceil_tests.move, math/fixed_point/tests/sd29x9_tests/comparison_tests.move, math/fixed_point/tests/sd29x9_tests/conversion_tests.move, math/fixed_point/tests/sd29x9_tests/div_tests.move, math/fixed_point/tests/sd29x9_tests/floor_tests.move, math/fixed_point/tests/sd29x9_tests/helpers.move, math/fixed_point/tests/sd29x9_tests/ln_tests.move, math/fixed_point/tests/sd29x9_tests/log10_tests.move, math/fixed_point/tests/sd29x9_tests/log2_tests.move, math/fixed_point/tests/sd29x9_tests/mod_tests.move, math/fixed_point/tests/sd29x9_tests/mul_tests.move, math/fixed_point/tests/sd29x9_tests/negate_tests.move, math/fixed_point/tests/sd29x9_tests/pow_tests.move, math/fixed_point/tests/sd29x9_tests/rem_tests.move, math/fixed_point/tests/sd29x9_tests/sqrt_tests.move, math/fixed_point/tests/sd29x9_tests/unchecked_tests.move, math/fixed_point/tests/sd29x9_tests/wrap_tests.move
Removes #[test_only] from module declarations in the sd29x9 fixed-point test suite (19 files) and the internal raw_log2 test module.
math/fixed_point ud30x9 test modules
math/fixed_point/tests/ud30x9_tests/abs_tests.move, math/fixed_point/tests/ud30x9_tests/arithmetic_tests.move, math/fixed_point/tests/ud30x9_tests/bitwise_tests.move, math/fixed_point/tests/ud30x9_tests/casting_tests.move, math/fixed_point/tests/ud30x9_tests/ceil_tests.move, math/fixed_point/tests/ud30x9_tests/comparison_tests.move, math/fixed_point/tests/ud30x9_tests/conversion_tests.move, math/fixed_point/tests/ud30x9_tests/div_tests.move, math/fixed_point/tests/ud30x9_tests/floor_tests.move, math/fixed_point/tests/ud30x9_tests/helpers.move, math/fixed_point/tests/ud30x9_tests/ln_tests.move, math/fixed_point/tests/ud30x9_tests/log10_tests.move, math/fixed_point/tests/ud30x9_tests/log2_tests.move, math/fixed_point/tests/ud30x9_tests/mul_tests.move, math/fixed_point/tests/ud30x9_tests/pow_tests.move, math/fixed_point/tests/ud30x9_tests/sqrt_tests.move, math/fixed_point/tests/ud30x9_tests/unchecked_tests.move, math/fixed_point/tests/ud30x9_tests/wrap_tests.move
Removes #[test_only] from module declarations in the ud30x9 fixed-point test suite (16 files).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • OpenZeppelin/contracts-sui#286: Adds fixed-point sqrt implementation plus sd29x9_sqrt_tests and ud30x9_sqrt_tests test modules marked #[test_only]; main PR removes the #[test_only] attribute from these test modules.
  • OpenZeppelin/contracts-sui#320: Adds the new raw_log2_tests module marked #[test_only]; main PR removes that attribute from the same module.

Suggested reviewers

  • bidzyyys
  • immrsd

Poem

🐇 Hop hop, the #[test_only] tags must go,
Fifty-eight files trimmed in one tidy row,
No logic changed, no struct unseen,
Just attribute dust swept sparkling clean.
The bunny cheers: less noise, more code glow! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: removing #[test_only] attributes from test modules.
Description check ✅ Passed The description is thorough and well-structured, explaining the rationale, Move documentation references, and local validation, but lacks the PR checklist items required by the template.
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 remove-test-only

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

@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.90%. Comparing base (d0fd11a) to head (34c8330).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #389   +/-   ##
=======================================
  Coverage   78.90%   78.90%           
=======================================
  Files          23       23           
  Lines        1782     1782           
  Branches      640      640           
=======================================
  Hits         1406     1406           
  Misses        341      341           
  Partials       35       35           
Flag Coverage Δ
contracts/access 65.40% <ø> (ø)
contracts/utils 44.09% <ø> (ø)
math/fixed_point 56.59% <ø> (ø)

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 bidzyyys left a comment

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.

LGTM

@ericnordelo

Copy link
Copy Markdown
Member

Do we have to remove them though? Is there a benefit from removing them that outweights quickly recognizing these items as test only? I think it helps with understanding the code faster visually.

Comment thread contracts/access/tests/access_control_tests.move
@0xNeshi 0xNeshi requested a review from ericnordelo June 17, 2026 13:48
@0xNeshi 0xNeshi merged commit 1ab78d8 into main Jun 18, 2026
17 of 18 checks passed
@0xNeshi 0xNeshi deleted the remove-test-only branch June 18, 2026 10:44
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