fix: guard CoreContract register_username against empty string input#457
Conversation
📝 WalkthroughWalkthroughIntroduces username registration validation to the contract by adding a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
|
@cypriannwokolo2-creator Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@onchain/contracts/core_contract/src/registration.rs`:
- Around line 126-131: The rustfmt failure is caused by inconsistent formatting
around the UTF-8 conversion and trimming; adjust the block that defines
username_str and trimmed to follow standard Rust formatting (consistent
indentation, no extra blank lines, and proper chaining). Locate the code using
core::str::from_utf8(username.as_ref()) assigned to username_str and the
subsequent let trimmed = username_str.trim(); then reformat that small block to
a single idiomatic snippet (no stray blank lines, aligned let bindings) so
rustfmt passes.
- Around line 124-135: register_username currently only validates input; update
it to persist the trimmed username into contract storage and emit the
username_registered_event so get_username can read it later. Specifically, after
UTF-8 conversion and trimming (retain the existing CoreError::InvalidUsername
check), store the trimmed username under the same storage key/namespace used by
get_username and then call username_registered_event with the Env and the stored
username; ensure you handle any necessary ownership/Bytes conversions and keep
the validation logic intact.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: df89f3be-d71e-4521-b9d4-0da2e5f7bd51
📒 Files selected for processing (4)
onchain/contracts/core_contract/src/lib.rsonchain/contracts/core_contract/src/registration.rsonchain/contracts/core_contract/src/test.rsonchain/shared/src/errors.rs
Closes #437
fix: guard CoreContract register_username against empty string input
Summary by CodeRabbit
New Features
Tests