-
Notifications
You must be signed in to change notification settings - Fork 174
fix(rpc): guard nil height deref in CometBlockResultByNumber #1067
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,80 @@ | ||||||||||||||||||
| package backend | ||||||||||||||||||
|
|
||||||||||||||||||
| import ( | ||||||||||||||||||
| "context" | ||||||||||||||||||
| "errors" | ||||||||||||||||||
| "testing" | ||||||||||||||||||
|
|
||||||||||||||||||
| "github.com/stretchr/testify/mock" | ||||||||||||||||||
| "github.com/stretchr/testify/require" | ||||||||||||||||||
|
|
||||||||||||||||||
| tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" | ||||||||||||||||||
|
|
||||||||||||||||||
| "github.com/cosmos/evm/rpc/backend/mocks" | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| func TestCometBlockResultByNumber_NilHeightErrorPath(t *testing.T) { | ||||||||||||||||||
| testCases := []struct { | ||||||||||||||||||
| name string | ||||||||||||||||||
| height *int64 | ||||||||||||||||||
| rpcErr error | ||||||||||||||||||
| expectPanic bool | ||||||||||||||||||
| expectErr bool | ||||||||||||||||||
|
||||||||||||||||||
| expectPanic bool | |
| expectErr bool | |
| testCases := []struct { | |
| name string | |
| height *int64 | |
| rpcErr error | |
| expectErr bool | |
| }{ |
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.
Ambiguous height in error message when caller passes
nilWhen
CometBlockResultByNumberis called with anilheight (i.e., "fetch latest block"),heightAttrdefaults to0. IfBlockResultsthen fails, the error message will read"failed to fetch block result from CometBFT 0: ...", which is indistinguishable from a caller that explicitly requested block 0 (which is also remapped tonil). This is a pre-existing ambiguity but the fix keeps it intact.Consider using a more descriptive format string to differentiate the two cases, for example:
This is a minor style concern and does not affect correctness.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!