feat: validate transaction label size#617
Conversation
Just to avoid having huge data stored in the labels and i think 256 chars should be more than enough for a transaction label.
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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.
🧹 Nitpick comments (1)
key-wallet/src/managed_account/transaction_record.rs (1)
344-348: Consider testing that a valid label is preserved when an invalid one is rejected.The current test verifies that
labelremainsNoneafter the error, but the label was already cleared at line 341. To fully exercise the atomic behavior (existing label unchanged on error), consider setting a valid label first, then attempting to set an over-limit one.🧪 Suggested test improvement
// Exceeding max length returns an error + record.set_label("Preserved Label".to_string()).unwrap(); let long_label = "x".repeat(MAX_LABEL_LENGTH + 1); assert!(record.set_label(long_label).is_err()); - assert_eq!(record.label, None); // unchanged + assert_eq!(record.label, Some("Preserved Label".to_string())); // unchanged from valid label // Exactly max length is fine🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@key-wallet/src/managed_account/transaction_record.rs` around lines 344 - 348, Update the test to verify atomic behavior of set_label: first set a valid label via record.set_label(valid_label) and assert it returns Ok and record.label equals that valid value, then attempt to set the over-length label using record.set_label(long_label) and assert it returns Err and that record.label is still the original valid label (unchanged). Use the existing MAX_LABEL_LENGTH, record.set_label, and record.label symbols to locate and modify the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@key-wallet/src/managed_account/transaction_record.rs`:
- Around line 344-348: Update the test to verify atomic behavior of set_label:
first set a valid label via record.set_label(valid_label) and assert it returns
Ok and record.label equals that valid value, then attempt to set the over-length
label using record.set_label(long_label) and assert it returns Err and that
record.label is still the original valid label (unchanged). Use the existing
MAX_LABEL_LENGTH, record.set_label, and record.label symbols to locate and
modify the test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: bfc39b86-d0ff-454c-97a5-8a5827781cd9
📒 Files selected for processing (1)
key-wallet/src/managed_account/transaction_record.rs
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v0.42-dev #617 +/- ##
=============================================
+ Coverage 67.21% 67.58% +0.37%
=============================================
Files 321 321
Lines 68249 68268 +19
=============================================
+ Hits 45874 46142 +268
+ Misses 22375 22126 -249
|
Just to avoid having huge data stored in the labels and i think 256 chars should be more than enough for a transaction label.
Summary by CodeRabbit