-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(feetiers): Reject malformed address in query #2653
Conversation
WalkthroughThe changes in this pull request enhance the Changes
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
User: "alice", | ||
}, | ||
res: nil, | ||
err: status.Error(codes.InvalidArgument, "user address is valid bech32 address"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the error message be saying the address is invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (1)
protocol/x/feetiers/keeper/grpc_query_test.go (1)
61-61
: Consider using test constants for the Bech32 addressThe hardcoded Bech32 address might be environment-specific. Consider moving it to a test constants file or using a helper function to generate valid test addresses.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
protocol/x/feetiers/keeper/grpc_query.go
(2 hunks)protocol/x/feetiers/keeper/grpc_query_test.go
(2 hunks)
🔇 Additional comments (1)
protocol/x/feetiers/keeper/grpc_query.go (1)
6-7
: LGTM: Required import for Bech32 address validation
The addition of the cosmos-sdk types package is necessary for implementing the address validation feature.
|
||
if _, err := sdk.AccAddressFromBech32(req.User); err != nil { | ||
return nil, status.Error(codes.InvalidArgument, "user address is valid bech32 address") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix grammatical error in error message
The error message has incorrect grammar which could confuse users.
Apply this fix:
- return nil, status.Error(codes.InvalidArgument, "user address is valid bech32 address")
+ return nil, status.Error(codes.InvalidArgument, "user address is not a valid bech32 address")
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if _, err := sdk.AccAddressFromBech32(req.User); err != nil { | |
return nil, status.Error(codes.InvalidArgument, "user address is valid bech32 address") | |
} | |
if _, err := sdk.AccAddressFromBech32(req.User); err != nil { | |
return nil, status.Error(codes.InvalidArgument, "user address is not a valid bech32 address") | |
} |
"Malformed address": { | ||
req: &types.QueryUserFeeTierRequest{ | ||
User: "alice", | ||
}, | ||
res: nil, | ||
err: status.Error(codes.InvalidArgument, "user address is valid bech32 address"), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Update error message to match implementation fix
Once the error message is fixed in the implementation, update this test case to match the new message.
Apply this fix after updating the implementation:
- err: status.Error(codes.InvalidArgument, "user address is valid bech32 address"),
+ err: status.Error(codes.InvalidArgument, "user address is not a valid bech32 address"),
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"Malformed address": { | |
req: &types.QueryUserFeeTierRequest{ | |
User: "alice", | |
}, | |
res: nil, | |
err: status.Error(codes.InvalidArgument, "user address is valid bech32 address"), | |
}, | |
"Malformed address": { | |
req: &types.QueryUserFeeTierRequest{ | |
User: "alice", | |
}, | |
res: nil, | |
err: status.Error(codes.InvalidArgument, "user address is not a valid bech32 address"), | |
}, |
❌ No backport have been created
GitHub error: |
@Mergifyio backport release/protocol/v8.x |
✅ Backports have been created
|
@Mergifyio backport release/protocol/v7.x |
✅ Backports have been created
|
There was a problem hiding this 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
🧹 Outside diff range and nitpick comments (1)
protocol/x/feetiers/client/cli/query_test.go (1)
Line range hint
59-64
: Enhance test coverage for the address validation feature.While the test verifies that the command executes successfully with a valid Bech32 address, it could be improved in several ways:
- Add assertions to verify the response content matches expected values
- Add negative test cases for malformed addresses to ensure proper error handling
Consider adding the following test cases:
func TestQueryUserFeeTier(t *testing.T) { net, ctx := setupNetwork(t) + + tests := []struct { + name string + address string + expectedError string + }{ + { + name: "valid bech32 address", + address: "dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4", + }, + { + name: "malformed address", + address: "invalid-address", + expectedError: "invalid address", + }, + { + name: "empty address", + address: "", + expectedError: "invalid address", + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdQueryUserFeeTier(), []string{tc.address}) + if tc.expectedError != "" { + require.Error(t, err) + require.Contains(t, err.Error(), tc.expectedError) + return + } + require.NoError(t, err) + var resp types.QueryUserFeeTierResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + // TODO: Add assertions for expected response values + }) + } - - out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdQueryUserFeeTier(), []string{"dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4"}) - - require.NoError(t, err) - var resp types.QueryUserFeeTierResponse - require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) }
(cherry picked from commit d8a1d79)
(cherry picked from commit d8a1d79)
) Co-authored-by: Teddy Ding <[email protected]>
) Co-authored-by: Teddy Ding <[email protected]>
Changelist
https://dydx-team.slack.com/archives/C03FVKBHD5H/p1732319479334399
Test Plan
Unit test
Author/Reviewer Checklist
state-breaking
label.indexer-postgres-breaking
label.PrepareProposal
orProcessProposal
, manually add the labelproposal-breaking
.feature:[feature-name]
.backport/[branch-name]
.refactor
,chore
,bug
.Summary by CodeRabbit
New Features
Bug Fixes
Tests