test(nft): cover canonical_hash branches → patch coverage to 100%#777
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📝 WalkthroughWalkthroughThis PR adds two regression tests for the Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
crates/sentrix-nft/src/collection.rscrates/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"); |
There was a problem hiding this comment.
🧹 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")).
Follow-up to #776. Codecov patch on #776 flagged 15 uncovered lines in
sentrix-nft/src/collection.rscanonical_hash(patch 90.38%, the file at 81%). These are the branches the original tests didn't exercise:max_supply(theSomearm)uri_hash/metadata_hash(theSomearm — no public setter yet)Tests added
Some(max_supply), non-empty token URI, single-token approval, and operator-for-all (toggling the operator moves the hash).uri_hash/metadata_hashintegrity hashes have no public setter, so theSomearm is only reachable by setting the pub fields directly on a live token; verifies they're part of the committed canonical hash.canonical_hashis now fully covered in bothcollection.rsandregistry.rs(verified locally: 0 uncovered lines in the function).Note on scope
Only
sentrix-nftis in thecargo-llvm-covpackage set (the EVM-touching crates incl.sentrix-coreare excluded due to revm instrumentation brittleness on CI), so the codecov patch % is computed oversentrix-nftonly. The newsentrix-corelogic 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 linesSummary by CodeRabbit