Skip to content

test: use abort instead of teardown in contracts/access failure tests - #472

Merged
ericnordelo merged 4 commits into
mainfrom
ref-fail-test
Jul 13, 2026
Merged

test: use abort instead of teardown in contracts/access failure tests#472
ericnordelo merged 4 commits into
mainfrom
ref-fail-test

Conversation

@0xNeshi

@0xNeshi 0xNeshi commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Aligning with STYLEGUIDE.md

PR Checklist

  • Tests
  • Documentation
  • Changelog

Summary by CodeRabbit

  • Tests
    • Updated several expected-failure test cases across access-control, delayed, and two-step suites to explicitly end with an abort after the failure-triggering action.
    • Adjusted termination/cleanup flows so tests no longer reach normal completion paths when failures are expected.
    • Removed or simplified test-only termination and lint/annotation allowances used by the affected test setups.
    • No user-facing product behavior changes.

@0xNeshi 0xNeshi self-assigned this Jul 10, 2026
@coderabbitai

coderabbitai Bot commented Jul 10, 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: 860fce87-5d68-4f97-a427-60494e06d02e

📥 Commits

Reviewing files that changed from the base of the PR and between 689cec9 and d3ccd2b.

📒 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

Expected-failure tests across three Move test suites now explicitly abort after failure-triggering operations, replacing numeric abort sentinels, normal completion, and selected cleanup paths.

Changes

Expected-failure test updates

Layer / File(s) Summary
Access-control rejection tests
contracts/access/tests/access_control_tests.move
Replaces abort 999 sentinels with bare abort statements and updates setup and cleanup attributes.
Delayed-operation failure tests
contracts/access/tests/delayed_tests.move
Replaces test.end() and selected cleanup paths with explicit aborts after expected failures.
Two-step transfer failure tests
contracts/access/tests/two_step_tests.move
Replaces test.end() with unconditional aborts after rejected transfer operations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: bidzyyys, immrsd

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is too sparse for the template; it omits the issue reference and a real summary of the changes beyond a styleguide note. Add a brief change summary, include the required 'Resolves #' line, and note any relevant test/doc/changelog status.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: replacing teardown patterns with aborts in access failure tests.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ref-fail-test

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

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.57%. Comparing base (c42028f) to head (d3ccd2b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #472      +/-   ##
==========================================
+ Coverage   96.51%   96.57%   +0.05%     
==========================================
  Files          34       34              
  Lines        3414     3414              
  Branches      799      799              
==========================================
+ Hits         3295     3297       +2     
  Misses         73       73              
+ Partials       46       44       -2     
Flag Coverage Δ
contracts/access 65.46% <ø> (ø)
contracts/allowance 52.40% <ø> (ø)
contracts/finance 26.66% <ø> (ø)
contracts/timelock 54.32% <ø> (ø)
contracts/utils 44.09% <ø> (ø)
math/core 87.04% <ø> (+0.14%) ⬆️
math/fixed_point 63.70% <ø> (ø)

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (3)
contracts/access/tests/two_step_tests.move (1)

506-532: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Helper functions retain dead cleanup unreachable after the expected-abort call.

expect_wrapper_mismatch (line 512, second.return_val(obj, borrow_token)) and expect_object_mismatch (line 528, wrapper.return_val(bogus_cap, borrow_token)) are each the expected failure point (EWrongTwoStepTransferWrapper/EWrongTwoStepTransferObject), yet both helpers continue with unwrap/delete calls afterward that can never execute. Same root cause as the equivalent helpers in delayed_tests.move.

As per path instructions, STYLEGUIDE.md says expected-failure tests should "not perform any cleanup or normal termination logic" and should "end at the failure boundary."

♻️ Proposed fix
 fun expect_wrapper_mismatch(
     mut first: two_step_transfer::TwoStepTransferWrapper<DummyCap>,
     mut second: two_step_transfer::TwoStepTransferWrapper<DummyCap>,
     ctx: &mut TxContext,
 ) {
     let (obj, borrow_token) = first.borrow_val();
     second.return_val(obj, borrow_token);
-
-    let DummyCap { id } = first.unwrap(ctx);
-    id.delete();
-    let DummyCap { id } = second.unwrap(ctx);
-    id.delete();
 }
 fun expect_object_mismatch(
     mut wrapper: two_step_transfer::TwoStepTransferWrapper<DummyCap>,
     ctx: &mut TxContext,
 ) {
     let (borrowed_cap, borrow_token) = wrapper.borrow_val();
     let DummyCap { id } = borrowed_cap;
     id.delete();
     let bogus_cap = new_cap(ctx);
     wrapper.return_val(bogus_cap, borrow_token);
-
-    let DummyCap { id } = wrapper.unwrap(ctx);
-    id.delete();
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contracts/access/tests/two_step_tests.move` around lines 506 - 532, Remove
the unreachable cleanup and normal-termination logic after the expected aborts
in expect_wrapper_mismatch and expect_object_mismatch. End each helper
immediately after second.return_val(obj, borrow_token) and
wrapper.return_val(bogus_cap, borrow_token), respectively, leaving the helpers
focused solely on reaching the expected failure boundary.

Source: Path instructions

contracts/access/tests/access_control_tests.move (1)

1156-1170: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Residual cleanup before abort violates the abort-boundary convention.

cancel_admin_transfer_rejects_non_root (line 1168) and cancel_delay_change_rejects_non_root (line 1956) both call clock::destroy_for_testing(clk) after the failing operation and before abort 999. This is exactly the "cleanup after failure" pattern the rest of the file (and this PR) removes elsewhere - the call is unreachable dead code since the preceding line always aborts.

As per path instructions, STYLEGUIDE.md states tests should "not perform any cleanup or normal termination logic; the test should end at the failure boundary with an explicit abort."

♻️ Proposed fix (apply to both tests)
     scenario.next_tx(`@0xC`);
     let mut ac = take_ac(&scenario);
     ac.cancel_default_admin_transfer(scenario.ctx());
-    clock::destroy_for_testing(clk);
     abort 999
 }
     scenario.next_tx(`@0xB`);
     let mut ac = take_ac(&scenario);
     ac.cancel_default_admin_delay_change(&clk, scenario.ctx());
-    clock::destroy_for_testing(clk);
     abort 999
 }

Also applies to: 1944-1958

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contracts/access/tests/access_control_tests.move` around lines 1156 - 1170,
Remove the unreachable clock::destroy_for_testing(clk) cleanup calls from both
cancel_admin_transfer_rejects_non_root and cancel_delay_change_rejects_non_root,
leaving each test to end immediately after the expected-failure operation with
abort 999.

Source: Path instructions

contracts/access/tests/delayed_tests.move (1)

376-516: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Helper functions still contain dead cleanup code unreachable after the guaranteed-abort call.

attempt_double_schedule, attempt_execute_before_delay, attempt_early_unwrap, attempt_double_unwrap, expect_cancel_without_pending, expect_execute_without_pending, expect_unwrap_without_pending, expect_return_wrong_wrapper, and expect_return_wrong_object all place object-deletion / clock::destroy_for_testing statements after the call that is expected to abort (e.g. the second schedule_transfer/schedule_unwrap call, or the mismatched return_val/cancel_schedule/execute_transfer/unwrap call). Since these helpers are each called from exactly one expected_failure test, this trailing code is unreachable. unwrap_wrong_action_fails (line 346-347) in this same file already demonstrates the pattern of dropping such trailing cleanup in favor of a minimal binding + abort, so these helpers are inconsistent with the convention the rest of the PR applies.

As per path instructions, STYLEGUIDE.md's testing convention says expected-failure tests should "not perform any cleanup or normal termination logic" and should "end at the failure boundary."

♻️ Example fix for `expect_cancel_without_pending`
 fun expect_cancel_without_pending(
     mut wrapper: delayed_transfer::DelayedTransferWrapper<DummyCap>,
     ctx: &mut TxContext,
 ) {
     wrapper.cancel_schedule();
-
-    let mut clk = clock::create_for_testing(ctx);
-    clk.set_for_testing(0);
-    wrapper.schedule_unwrap(&clk, ctx);
-    clk.set_for_testing(1);
-    let obj = wrapper.unwrap(&clk, ctx);
-    let DummyCap { id } = obj;
-    id.delete();
-    clock::destroy_for_testing(clk);
 }
Similar trims apply to the other listed helpers.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contracts/access/tests/delayed_tests.move` around lines 376 - 516, Remove all
unreachable cleanup and post-failure logic from the listed expected-failure
helpers: attempt_double_schedule, attempt_execute_before_delay,
attempt_early_unwrap, attempt_double_unwrap, expect_cancel_without_pending,
expect_execute_without_pending, expect_unwrap_without_pending,
expect_return_wrong_wrapper, and expect_return_wrong_object. Make each helper
end at the operation expected to abort, retaining only the minimal setup and
bindings needed to reach that failure, consistent with unwrap_wrong_action_fails
and the testing convention.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contracts/access/tests/delayed_tests.move`:
- Line 167: Remove the trailing bare `abort` statements from the
expected-failure test cases in the delayed access tests, including the case
around the helper call at this location. Apply the same cleanup to every
matching trailing `abort` in the file, leaving the helper calls as the
terminating statements.

---

Nitpick comments:
In `@contracts/access/tests/access_control_tests.move`:
- Around line 1156-1170: Remove the unreachable clock::destroy_for_testing(clk)
cleanup calls from both cancel_admin_transfer_rejects_non_root and
cancel_delay_change_rejects_non_root, leaving each test to end immediately after
the expected-failure operation with abort 999.

In `@contracts/access/tests/delayed_tests.move`:
- Around line 376-516: Remove all unreachable cleanup and post-failure logic
from the listed expected-failure helpers: attempt_double_schedule,
attempt_execute_before_delay, attempt_early_unwrap, attempt_double_unwrap,
expect_cancel_without_pending, expect_execute_without_pending,
expect_unwrap_without_pending, expect_return_wrong_wrapper, and
expect_return_wrong_object. Make each helper end at the operation expected to
abort, retaining only the minimal setup and bindings needed to reach that
failure, consistent with unwrap_wrong_action_fails and the testing convention.

In `@contracts/access/tests/two_step_tests.move`:
- Around line 506-532: Remove the unreachable cleanup and normal-termination
logic after the expected aborts in expect_wrapper_mismatch and
expect_object_mismatch. End each helper immediately after second.return_val(obj,
borrow_token) and wrapper.return_val(bogus_cap, borrow_token), respectively,
leaving the helpers focused solely on reaching the expected failure boundary.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 39099e2f-3f6a-4cb9-86ee-6bf6809ccdc9

📥 Commits

Reviewing files that changed from the base of the PR and between c42028f and 6c5f4f4.

📒 Files selected for processing (3)
  • contracts/access/tests/access_control_tests.move
  • contracts/access/tests/delayed_tests.move
  • contracts/access/tests/two_step_tests.move

Comment thread contracts/access/tests/delayed_tests.move

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contracts/access/tests/access_control_tests.move`:
- Line 40: Remove the #[allow(lint(share_owned))] attribute from the test-only
declaration in the access control tests, then update the affected test code to
resolve the underlying share_owned lint without any lint-suppression attributes.
- Around line 1160-1162: Remove the unreachable clock::destroy_for_testing
cleanup calls from the expected-failure tests near
ac.cancel_default_admin_transfer and the corresponding second occurrence,
leaving abort immediately after the operation that is expected to fail.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d3de5cdb-1b8a-4a3c-890f-47adec3d5b51

📥 Commits

Reviewing files that changed from the base of the PR and between 6c5f4f4 and e5ed1c3.

📒 Files selected for processing (1)
  • contracts/access/tests/access_control_tests.move

Comment thread contracts/access/tests/access_control_tests.move Outdated
Comment thread contracts/access/tests/access_control_tests.move
Comment thread contracts/access/tests/access_control_tests.move
@0xNeshi
0xNeshi requested a review from ericnordelo July 10, 2026 11:12

@ericnordelo ericnordelo left a comment

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.

LGTM!

@ericnordelo
ericnordelo merged commit f880455 into main Jul 13, 2026
32 checks passed
@ericnordelo
ericnordelo deleted the ref-fail-test branch July 13, 2026 09:56
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.

2 participants