Skip to content

Conversation

@Benzbeeb
Copy link
Collaborator

@Benzbeeb Benzbeeb commented Sep 19, 2025

  • Updated ValidateAddressesOrHexAddresses to return nil for empty input.
  • Added a test case for empty string input in TestValidateAddressesOrHexAddresses.

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow-up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • Bug Fixes
    • Improved address validation to accept empty input without error, preventing false validation failures when fields are left blank.
  • Tests
    • Expanded test coverage to include empty input scenarios for address validation.

- Updated ValidateAddressesOrHexAddresses to return nil for empty input.
- Added a test case for empty string input in TestValidateAddressesOrHexAddresses.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 19, 2025

Walkthrough

An early return was added to ValidateAddressesOrHexAddresses to accept an empty string as valid input. Corresponding unit test coverage was updated by adding a test case asserting no error for empty input. No public APIs or signatures were changed.

Changes

Cohort / File(s) Summary
Validation logic
common/validate.go
Added early guard: if input string is empty, return nil before validation loop; no signature changes.
Validation tests
common/validate_test.go
Added test case "empty string" expecting no error from ValidateAddressesOrHexAddresses.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant V as ValidateAddressesOrHexAddresses

  Caller->>V: ValidateAddressesOrHexAddresses(s)
  alt s == ""
    note right of V: New early guard
    V-->>Caller: nil (no error)
  else s != ""
    V->>V: Iterate addresses / hex addresses
    V-->>Caller: nil or error
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A whisker twitch, a tidy fix,
If empty, skip the validation tricks.
Tests now nod, “all clear, proceed,”
A gentle hop to meet the need.
Carrots saved, no loops to start—
Early return, efficient art. 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "feat: add handling for empty string in address validation" succinctly and accurately summarizes the primary change in the PR — introducing an early guard to treat empty input as valid in ValidateAddressesOrHexAddresses (with a corresponding test). It is specific, clear, and not misleading or overly broad.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-empty-address

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

Copy link
Contributor

@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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
common/validate.go (1)

121-129: Potential panic and incorrect error message in ValidateDecFromStr.

Indexing str[0] before checking len(str) can panic on empty input, and the error says “cannot be positive” when the string is actually negative.

-func ValidateDecFromStr(str string) error {
-    if str[0] == '-' {
-        return fmt.Errorf("decimal string cannot be positive")
-    }
-    if len(str) == 0 {
-        return ErrLegacyEmptyDecimalStr
-    }
+func ValidateDecFromStr(str string) error {
+    if len(str) == 0 {
+        return ErrLegacyEmptyDecimalStr
+    }
+    if str[0] == '-' {
+        return fmt.Errorf("decimal string cannot be negative")
+    }
🧹 Nitpick comments (1)
common/validate.go (1)

382-386: Trim tokens and skip empties to handle whitespace and trailing commas gracefully.

Prevents false negatives for inputs like "addr1, addr2" and treats whitespace-only as empty. If acceptable, apply:

- for _, address := range strings.Split(s, ",") {
-     if err := ValidateAnyHexAddressOrAddress(address); err != nil {
-         return err
-     }
- }
+ for _, address := range strings.Split(s, ",") {
+     address = strings.TrimSpace(address)
+     if address == "" {
+         continue
+     }
+     if err := ValidateAnyHexAddressOrAddress(address); err != nil {
+         return err
+     }
+ }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 148cc0e and 0ace7c7.

📒 Files selected for processing (2)
  • common/validate.go (1 hunks)
  • common/validate_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Run Integration Tests on Ubuntu
🔇 Additional comments (2)
common/validate_test.go (1)

280-284: LGTM: empty-input test covers the new behavior.

Nice parity with ValidateAddresses treating empty as valid.

Consider adding follow-ups if you adopt whitespace handling:

  • "whitespace only" input: " " → no error
  • spaces around tokens: "addr1, addr2" → no error
common/validate.go (1)

379-381: Approve: empty-input early return is correct.

Matches ValidateAddresses; tests (common/validate_test.go — TestValidateAddressesOrHexAddresses includes an empty-string case expecting no error) and the only non-test caller found is models/minitia/launch.go (registers this validator), so this is backward‑compatible.

@Benzbeeb Benzbeeb merged commit aabecc7 into main Sep 19, 2025
8 checks passed
@Benzbeeb Benzbeeb deleted the fix-empty-address branch September 19, 2025 06:24
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