Skip to content

test(nft): cover canonical_hash branches → patch coverage to 100%#777

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/nft-canonical-hash-coverage
Jun 3, 2026
Merged

test(nft): cover canonical_hash branches → patch coverage to 100%#777
github-actions[bot] merged 1 commit into
mainfrom
fix/nft-canonical-hash-coverage

Conversation

@satyakwok
Copy link
Copy Markdown
Collaborator

@satyakwok satyakwok commented Jun 3, 2026

Follow-up to #776. Codecov patch on #776 flagged 15 uncovered lines in sentrix-nft/src/collection.rs canonical_hash (patch 90.38%, the file at 81%). These are the branches the original tests didn't exercise:

  • bounded max_supply (the Some arm)
  • token uri_hash / metadata_hash (the Some arm — no public setter yet)
  • the operator-approvals loop

Tests added

  • lib.rs (black-box): collection with Some(max_supply), non-empty token URI, single-token approval, and operator-for-all (toggling the operator moves the hash).
  • collection.rs (white-box): uri_hash/metadata_hash integrity hashes have no public setter, so the Some arm is only reachable by setting the pub fields directly on a live token; verifies they're part of the committed canonical hash.

canonical_hash is now fully covered in both collection.rs and registry.rs (verified locally: 0 uncovered lines in the function).

Note on scope

Only sentrix-nft is in the cargo-llvm-cov package set (the EVM-touching crates incl. sentrix-core are excluded due to revm instrumentation brittleness on CI), so the codecov patch % is computed over sentrix-nft only. The new sentrix-core logic from #775/#776 (apply path, fingerprint, address validation) is tested (verified 86%+ locally) but not in the codecov number until the EVM crates can be instrumented on CI — tracked as separate follow-up.

Commands

  • cargo test -p sentrix-nft ✅ (45 + 2 doctests)
  • cargo fmt --check
  • cargo llvm-cov -p sentrix-nft ✅ canonical_hash 0 uncovered lines

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for canonical hash functionality, including scenarios for integrity field modifications and approval state transitions.

Patch coverage on #776 flagged 15 uncovered lines in collection.rs
canonical_hash — the branches the existing tests didn't hit:
bounded max_supply (Some arm), token uri_hash/metadata_hash (Some arm),
and the operator-approvals loop.

- lib.rs: black-box test covering Some(max_supply), non-empty token URI,
  single-token approval, and operator-for-all (toggle moves the hash).
- collection.rs: white-box test for uri_hash/metadata_hash — these
  integrity hashes have no public setter yet, so the Some arm is only
  reachable by setting the fields directly on a live token.

canonical_hash is now fully covered in both collection.rs and registry.rs.
@github-actions github-actions Bot enabled auto-merge (squash) June 3, 2026 17:29
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds two regression tests for the canonical_hash() methods in the NFT module. The first test (in collection.rs) verifies that the collection's canonical hash updates when token integrity fields (uri_hash and metadata_hash) are modified. The second test (in lib.rs) verifies that the registry's canonical hash updates through a sequence of approval state changes: setting token approval, enabling operator-for-all, and then revoking operator-for-all on a bounded collection with a minted token.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding tests to cover canonical_hash branches and achieve 100% patch coverage.
Description check ✅ Passed The description covers all essential sections including summary, scope (test-only), detailed test explanations, verification results, and commands run, with all relevant checkboxes marked appropriately.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/nft-canonical-hash-coverage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a 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

🤖 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 `@crates/sentrix-nft/src/collection.rs`:
- Line 715: Tests use tokens.get_mut(&1).expect("token 1") in one place but
tokens.get_mut(&1).unwrap() in another; make them consistent by replacing the
.unwrap() call with .expect("token 1") so both retrievals of token 1 use the
same explanatory message (search for tokens.get_mut(&1) and change the
occurrence that calls .unwrap() to .expect("token 1")).
🪄 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: ASSERTIVE

Plan: Pro Plus

Run ID: b4b74118-d703-41e5-81f2-435b98710e05

📥 Commits

Reviewing files that changed from the base of the PR and between a545a67 and 6c2b46f.

📒 Files selected for processing (2)
  • crates/sentrix-nft/src/collection.rs
  • crates/sentrix-nft/src/lib.rs

c.mint("0xadmin", "0xowner", 1, "", None).unwrap();
let baseline = c.canonical_hash();

let t = c.tokens.get_mut(&1).expect("token 1");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial | 💤 Low value

Prefer consistent error-handling style in tests.

Line 715 uses .expect("token 1") while line 723 uses .unwrap() for the same operation (retrieving token 1). For consistency and better failure messages, prefer .expect() throughout.

♻️ Proposed consistency fix
-        c.tokens.get_mut(&1).unwrap().metadata_hash = Some("cafe".into());
+        c.tokens.get_mut(&1).expect("token 1").metadata_hash = Some("cafe".into());

Also applies to: 723-723

🤖 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 `@crates/sentrix-nft/src/collection.rs` at line 715, Tests use
tokens.get_mut(&1).expect("token 1") in one place but
tokens.get_mut(&1).unwrap() in another; make them consistent by replacing the
.unwrap() call with .expect("token 1") so both retrievals of token 1 use the
same explanatory message (search for tokens.get_mut(&1) and change the
occurrence that calls .unwrap() to .expect("token 1")).

@github-actions github-actions Bot merged commit a20e844 into main Jun 3, 2026
17 checks passed
@satyakwok satyakwok deleted the fix/nft-canonical-hash-coverage branch June 3, 2026 18:11
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.

1 participant