-
Notifications
You must be signed in to change notification settings - Fork 201
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
test(evm): grpc_query full coverage #1907
Conversation
WalkthroughThe recent updates to the Changes
Sequence Diagram(s) (Beta)Poem
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1907 +/- ##
==========================================
+ Coverage 62.34% 63.13% +0.78%
==========================================
Files 245 245
Lines 15949 16011 +62
==========================================
+ Hits 9944 10108 +164
+ Misses 5269 5161 -108
- Partials 736 742 +6
|
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: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- CHANGELOG.md (1 hunks)
- x/evm/evmtest/eth.go (1 hunks)
- x/evm/keeper/grpc_query_test.go (6 hunks)
- x/evm/keeper/keeper_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
- x/evm/keeper/keeper_test.go
Additional comments not posted (11)
x/evm/keeper/grpc_query_test.go (10)
26-33
: New functionTraceNibiTransfer
correctly simulates a transaction trace response.
35-49
: New functionTraceERC20Transfer
correctly simulates a transaction trace response for ERC20 transfers.
Line range hint
80-114
: Modification in test case names and scenarios forTestQueryNibiruAccount
enhances clarity and coverage.
217-229
: New test casesad: validator account not found
correctly handles the scenario where a validator account is not found.
470-523
: New functionTestQueryEthCall
provides comprehensive testing for Ethereum call functionality.
525-599
: New functionTestQueryBalance
effectively tests balance querying with scenarios for zero and non-zero balances.
601-636
: New functionTestQueryBaseFee
correctly tests the querying of base fee values.
638-747
: New functionTestEstimateGasForEvmCallType
provides thorough testing for gas estimation in various scenarios.
749-817
: New functionTestTestTraceTx
effectively tests transaction tracing.
819-889
: New functionTestTestTraceBlock
effectively tests block tracing.CHANGELOG.md (1)
69-69
: The changelog entry for PR #1907 is correctly formatted and placed under the appropriate section.
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.
Looks great overall. Left a few quick review comments
x/evm/keeper/grpc_query_test.go
Outdated
func(deps *evmtest.TestDeps) (req In, wantResp Out) { | ||
txMsg, predecessors := s.ExecuteERC20Transfer(deps) | ||
|
||
req = &evm.QueryTraceTxRequest{ | ||
Msg: txMsg, | ||
Predecessors: predecessors, | ||
} | ||
wantResp = TraceERC20Transfer() | ||
return req, wantResp | ||
}, |
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.
I would write the ExecuteERC20Transfer
function as taking arguments (deps, s)
rather than including it as a function on the suite. That will make it easier to pull out the testutil to the evmtest
import if we want to leverage it in other places (like nibiru/eth
or nibiru/app
)
Perhaps the ExecuteNibiTransfer
fits this criterion as well.
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.
Extraced these methods to evmtest/tx.go
x/evm/keeper/grpc_query_test.go
Outdated
func GenerateEthAddress() gethcommon.Address { | ||
privateKey, _ := crypto.GenerateKey() | ||
publicKey := privateKey.Public() | ||
publicKeyECDSA, _ := publicKey.(*ecdsa.PublicKey) | ||
return crypto.PubkeyToAddress(*publicKeyECDSA) |
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.
This should be replaced with the equivalent util fn from evmtest
if possible. It looks almost the same as evmtest.NewEthAccInfo
from eth.go.
If these functions are not the same, can you add it to evmtest
and put a function comment on the difference?
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.
yes, pretty similar thing. Removed
x/evm/keeper/grpc_query_test.go
Outdated
"github.com/NibiruChain/nibiru/x/common/testutil/testapp" | ||
"github.com/NibiruChain/nibiru/x/evm" | ||
"github.com/NibiruChain/nibiru/x/evm/evmtest" | ||
) | ||
|
||
func InvalidEthAddr() string { return "0x0000" } | ||
|
||
func TraceNibiTransfer() string { | ||
return `{ | ||
"gas": 21000, |
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.
Why is it this number specifically? Rather, can you replace this with the causal constant from "gethparams" and use fmt.Sprintf
?
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.
21000
is gethparams.TxGas
. Replaced the hardcode but that number is everywhere...
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 (2)
x/evm/evmtest/tx.go (2)
137-153
: The functionExecuteNibiTransfer
is well-implemented with proper error handling and response validation. However, consider adding more detailed comments explaining the purpose and the process of each step for better maintainability.Tools
golangci-lint
[error] 137-137: undefined: TestDeps (typecheck)
[error] 139-139: undefined: NewEthAccInfo (typecheck)
202-222
: The functionGenerateAndSignEthTxMsg
effectively marshals transaction arguments and handles errors appropriately. However, consider adding more inline comments to explain the logic, especially around gas estimation and transaction signing, to enhance readability and maintainability.Tools
golangci-lint
[error] 202-202: undefined: TestDeps (typecheck)
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- CHANGELOG.md (1 hunks)
- x/evm/evmtest/tx.go (2 hunks)
- x/evm/keeper/grpc_query_test.go (6 hunks)
Files skipped from review as they are similar to previous changes (1)
- CHANGELOG.md
Additional context used
golangci-lint
x/evm/evmtest/tx.go
[error] 25-25: undefined: TestDeps (typecheck)
[error] 43-43: undefined: TestDeps (typecheck)
[error] 93-93: undefined: TestDeps (typecheck)
[error] 137-137: undefined: TestDeps (typecheck)
[error] 156-156: undefined: TestDeps (typecheck)
[error] 202-202: undefined: TestDeps (typecheck)
[error] 139-139: undefined: NewEthAccInfo (typecheck)
[error] 158-158: undefined: SmartContract_FunToken (typecheck)
[error] 181-181: undefined: NewEthAccInfo (typecheck)
Additional comments not posted (3)
x/evm/evmtest/tx.go (2)
5-17
: The imports added are necessary for the new functionalities introduced in this file. However, ensure that all these libraries are used effectively in the code to avoid unnecessary dependencies.
156-199
: The functionExecuteERC20Transfer
is comprehensive and handles multiple steps including contract deployment and ERC-20 transfer. Ensure that theSmartContract_FunToken
andNewEthAccInfo
are defined and accessible as they are used here.Verification successful
The definitions for
SmartContract_FunToken
andNewEthAccInfo
are present and accessible in the codebase:
SmartContract_FunToken
is defined inx/evm/evmtest/fixtures.go
.NewEthAccInfo
is defined inx/evm/evmtest/eth.go
.These definitions are accessible from the context of
x/evm/evmtest/tx.go
.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the definitions and accessibility of SmartContract_FunToken and NewEthAccInfo. # Test: Search for the definitions in the project. rg --type go $'SmartContract_FunToken|NewEthAccInfo'Length of output: 5849
Tools
golangci-lint
[error] 156-156: undefined: TestDeps (typecheck)
[error] 158-158: undefined: SmartContract_FunToken (typecheck)
[error] 181-181: undefined: NewEthAccInfo (typecheck)
x/evm/keeper/grpc_query_test.go (1)
Line range hint
77-111
: The test cases forTestQueryNibiruAccount
are well-structured and cover both positive and negative scenarios. Ensure that theNewEthAccInfo
function is properly defined and accessible, as it is used here.Verification successful
The
NewEthAccInfo
function is defined inx/evm/evmtest/eth.go
at line 22. This confirms that the function is properly defined and accessible for use in the test cases.
x/evm/evmtest/eth.go:22: func NewEthAccInfo() EthPrivKeyAcc {
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the definition and accessibility of NewEthAccInfo. # Test: Search for the definition in the project. rg --type go $'NewEthAccInfo'Length of output: 5401
x/evm/keeper/grpc_query_test.go
Outdated
func TraceNibiTransfer() string { | ||
return `{ | ||
"gas": 21000, | ||
"failed": false, | ||
"returnValue": "", | ||
"structLogs": [] | ||
}` | ||
} |
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.
The function TraceNibiTransfer
returns a hardcoded JSON string. Ensure that this output is aligned with the expected format and values in the context of the application. Consider using a struct and marshalling it to JSON for better maintainability and to avoid mistakes in JSON formatting.
- return `{
- "gas": 21000,
- "failed": false,
- "returnValue": "",
- "structLogs": []
- }`
+ type TraceResult struct {
+ Gas int `json:"gas"`
+ Failed bool `json:"failed"`
+ ReturnValue string `json:"returnValue"`
+ StructLogs []struct{} `json:"structLogs"`
+ }
+ result := TraceResult{
+ Gas: 21000,
+ Failed: false,
+ ReturnValue: "",
+ StructLogs: make([]struct{}, 0),
+ }
+ jsonResult, _ := json.Marshal(result)
+ return string(jsonResult)
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.
func TraceNibiTransfer() string { | |
return `{ | |
"gas": 21000, | |
"failed": false, | |
"returnValue": "", | |
"structLogs": [] | |
}` | |
} | |
func TraceNibiTransfer() string { | |
type TraceResult struct { | |
Gas int `json:"gas"` | |
Failed bool `json:"failed"` | |
ReturnValue string `json:"returnValue"` | |
StructLogs []struct{} `json:"structLogs"` | |
} | |
result := TraceResult{ | |
Gas: 21000, | |
Failed: false, | |
ReturnValue: "", | |
StructLogs: make([]struct{}, 0), | |
} | |
jsonResult, _ := json.Marshal(result) | |
return string(jsonResult) | |
} |
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)
x/evm/keeper/grpc_query_test.go (1)
[!TIP]
Codebase VerificationEnsure consistency in error messages and consider using constants.
The error messages "not a valid ethereum hex addr" and "validator not found" are hardcoded in multiple places within the
x/evm/keeper
directory. To avoid discrepancies and ease maintenance, consider defining these error messages as constants and using them throughout the codebase.
x/evm/keeper/grpc_query_test.go
x/evm/keeper/grpc_query.go
Analysis chain
Line range hint
78-112
: Ensure consistency in error messages and consider using constants.The error messages such as "not a valid ethereum hex addr" and "validator not found" should be consistent across the test suite. Consider defining these as constants to avoid discrepancies and ease maintenance.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Search for inconsistent error messages across test files. rg --type go 'not a valid ethereum hex addr' x/evm/keeper/ rg --type go 'validator not found' x/evm/keeper/Length of output: 433
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- x/evm/keeper/grpc_query_test.go (6 hunks)
Additional comments not posted (1)
x/evm/keeper/grpc_query_test.go (1)
451-451
: Ensure error handling is consistent.It appears that the error is checked twice which might be redundant. Please verify if this is intentional or an oversight.
func TraceNibiTransfer() string { | ||
return fmt.Sprintf(`{ | ||
"gas": %d, | ||
"failed": false, | ||
"returnValue": "", | ||
"structLogs": [] | ||
}`, gethparams.TxGas) | ||
} |
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 TraceNibiTransfer
to use structured data for JSON serialization.
This change will improve maintainability and ensure consistency in data structure. Here's a suggested refactor:
- return fmt.Sprintf(`{
- "gas": %d,
- "failed": false,
- "returnValue": "",
- "structLogs": []
- }`, gethparams.TxGas)
+ type TraceResult struct {
+ Gas int `json:"gas"`
+ Failed bool `json:"failed"`
+ ReturnValue string `json:"returnValue"`
+ StructLogs []struct{} `json:"structLogs"`
+ }
+ result := TraceResult{
+ Gas: int(gethparams.TxGas),
+ Failed: false,
+ ReturnValue: "",
+ StructLogs: make([]struct{}, 0),
+ }
+ jsonResult, _ := json.Marshal(result)
+ return string(jsonResult)
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.
func TraceNibiTransfer() string { | |
return fmt.Sprintf(`{ | |
"gas": %d, | |
"failed": false, | |
"returnValue": "", | |
"structLogs": [] | |
}`, gethparams.TxGas) | |
} | |
func TraceNibiTransfer() string { | |
type TraceResult struct { | |
Gas int `json:"gas"` | |
Failed bool `json:"failed"` | |
ReturnValue string `json:"returnValue"` | |
StructLogs []struct{} `json:"structLogs"` | |
} | |
result := TraceResult{ | |
Gas: int(gethparams.TxGas), | |
Failed: false, | |
ReturnValue: "", | |
StructLogs: make([]struct{}, 0), | |
} | |
jsonResult, _ := json.Marshal(result) | |
return string(jsonResult) | |
} |
func TraceERC20Transfer() string { | ||
return `{ | ||
"gas": 35062, | ||
"failed": false, | ||
"returnValue": "0000000000000000000000000000000000000000000000000000000000000001", | ||
"structLogs": [ | ||
{ | ||
"pc": 0, | ||
"op": "PUSH1", | ||
"gas": 30578, | ||
"gasCost": 3, | ||
"depth": 1, | ||
"stack": [] | ||
}` | ||
} |
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 TraceERC20Transfer
to use structured data for JSON serialization.
Similar to the previous comment, using structured data will enhance clarity and maintainability. Here's a suggested refactor:
- return `{
- "gas": 35062,
- "failed": false,
- "returnValue": "0000000000000000000000000000000000000000000000000000000000000001",
- "structLogs": [
- {
- "pc": 0,
- "op": "PUSH1",
- "gas": 30578,
- "gasCost": 3,
- "depth": 1,
- "stack": []
- }`
+ type TraceERC20Result struct {
+ Gas int `json:"gas"`
+ Failed bool `json:"failed"`
+ ReturnValue string `json:"returnValue"`
+ StructLogs []struct{
+ Pc int `json:"pc"`
+ Op string `json:"op"`
+ Gas int `json:"gas"`
+ GasCost int `json:"gasCost"`
+ Depth int `json:"depth"`
+ Stack []interface{} `json:"stack"`
+ } `json:"structLogs"`
+ }
+ result := TraceERC20Result{
+ Gas: 35062,
+ Failed: false,
+ ReturnValue: "0000000000000000000000000000000000000000000000000000000000000001",
+ StructLogs: []struct{
+ Pc: 0,
+ Op: "PUSH1",
+ Gas: 30578,
+ GasCost: 3,
+ Depth: 1,
+ Stack: make([]interface{}, 0),
+ },
+ }
+ jsonResult, _ := json.Marshal(result)
+ return string(jsonResult)
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.
func TraceERC20Transfer() string { | |
return `{ | |
"gas": 35062, | |
"failed": false, | |
"returnValue": "0000000000000000000000000000000000000000000000000000000000000001", | |
"structLogs": [ | |
{ | |
"pc": 0, | |
"op": "PUSH1", | |
"gas": 30578, | |
"gasCost": 3, | |
"depth": 1, | |
"stack": [] | |
}` | |
} | |
func TraceERC20Transfer() string { | |
type TraceERC20Result struct { | |
Gas int `json:"gas"` | |
Failed bool `json:"failed"` | |
ReturnValue string `json:"returnValue"` | |
StructLogs []struct { | |
Pc int `json:"pc"` | |
Op string `json:"op"` | |
Gas int `json:"gas"` | |
GasCost int `json:"gasCost"` | |
Depth int `json:"depth"` | |
Stack []interface{} `json:"stack"` | |
} `json:"structLogs"` | |
} | |
result := TraceERC20Result{ | |
Gas: 35062, | |
Failed: false, | |
ReturnValue: "0000000000000000000000000000000000000000000000000000000000000001", | |
StructLogs: []struct { | |
Pc: 0, | |
Op: "PUSH1", | |
Gas: 30578, | |
GasCost: 3, | |
Depth: 1, | |
Stack: make([]interface{}, 0), | |
}, | |
} | |
jsonResult, _ := json.Marshal(result) | |
return string(jsonResult) | |
} |
commit b5687130ff5f3d020a3b14d219fec3a816579c30 Author: Unique-Divine <[email protected]> Date: Wed Jun 5 20:57:44 2024 -0500 chore: run tidy commit 1f1f938 Merge: 3e3cc83 bbcc6f8 Author: Unique-Divine <[email protected]> Date: Wed Jun 5 19:16:30 2024 -0500 Merge branch 'main' into ud/fix-race-condition commit 3e3cc83 Author: Unique-Divine <[email protected]> Date: Wed Jun 5 19:15:40 2024 -0500 chore: changelog commit 3876ccb Author: Unique-Divine <[email protected]> Date: Wed Jun 5 19:04:00 2024 -0500 refactor: more consistent test names commit aaa0a19 Author: Unique-Divine <[email protected]> Date: Wed Jun 5 18:53:09 2024 -0500 test(oracle): Fix missing tear down step for oracle integration test commit 8c3c35e Author: Unique-Divine <[email protected]> Date: Wed Jun 5 17:55:56 2024 -0500 chore: add test comands to justfile commit 4916282 Merge: 64ed0a2 e7e708d Author: Unique-Divine <[email protected]> Date: Fri May 31 09:35:33 2024 -0500 Merge branch 'main' into ud/fix-race-condition commit 64ed0a2 Author: Unique-Divine <[email protected]> Date: Fri May 31 01:44:55 2024 -0500 fix(gosdk): tests parallel race condition
…nibiru into test/evm-grpc-query
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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- CHANGELOG.md (1 hunks)
- app/evmante_fees.go (1 hunks)
- gosdk/gosdk_test.go (1 hunks)
- x/tokenfactory/cli/cli_test.go (1 hunks)
Files skipped from review due to trivial changes (3)
- app/evmante_fees.go
- gosdk/gosdk_test.go
- x/tokenfactory/cli/cli_test.go
Files skipped from review as they are similar to previous changes (1)
- CHANGELOG.md
Summary by CodeRabbit
New Features
grpc_query
functionality in the EVM module.Bug Fixes
Refactor