-
Notifications
You must be signed in to change notification settings - Fork 246
test: evm contract interaction #3006
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
Conversation
|
The latest Buf updates on your PR. Results from workflow CI / buf-check (pull_request).
|
Summary of ChangesHello @alpe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the end-to-end test coverage for EVM functionality by introducing tests for smart contract deployment, state manipulation, and event emission. These additions aim to validate core EVM interactions within the system, addressing a previously identified testing gap and improving overall system reliability. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Claude finished @alpe's task in 2m 22s —— View job Code Review CompleteI've performed a comprehensive review of the EVM contract interaction tests. This is a valuable addition to test coverage that addresses an important blind spot. Below are my findings organized by priority and category. Critical Issues1. Inefficient Error Handling in
|
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.
Code Review
This pull request adds valuable end-to-end tests for EVM contract deployment, interaction, and event handling, which is a great step towards improving test coverage. My review focuses on enhancing the robustness, readability, and maintainability of these new tests. I've suggested changes to correct misleading log messages, improve the test failure logic to fail faster and provide clearer errors, and refactor hardcoded values into constants.
| require.Eventually(t, func() bool { | ||
| receipt, err := client.TransactionReceipt(ctx, storeTxHash) | ||
| if err != nil { | ||
| return false | ||
| } | ||
| if receipt != nil { | ||
| if receipt.Status == 1 { | ||
| return true | ||
| } | ||
| t.Logf("Store tx failed! Status: %d, GasUsed: %d", receipt.Status, receipt.GasUsed) | ||
| return false | ||
| } | ||
| return false | ||
| }, 15*time.Second, 500*time.Millisecond, "Store transaction should be included") |
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 current implementation of require.Eventually will continue to retry until timeout even if the transaction has definitively failed (i.e., receipt.Status == 0). This slows down test execution and can produce a less informative timeout error message. It's better to fail fast in case of a transaction failure by using require assertions inside the Eventually block.
require.Eventually(t, func() bool {
receipt, err := client.TransactionReceipt(ctx, storeTxHash)
if err != nil {
return false // Not found yet, retry
}
if receipt.Status != 1 {
t.Logf("Store tx failed! Status: %d, GasUsed: %d", receipt.Status, receipt.GasUsed)
require.FailNow(t, "transaction failed with status 0")
}
return true
}, 15*time.Second, 500*time.Millisecond, "Store transaction should be included")| require.Eventually(t, func() bool { | ||
| receipt, err := client.TransactionReceipt(ctx, triggerTxHash) | ||
| if err == nil && receipt != nil && receipt.Status == 1 { | ||
| triggerReceipt = receipt | ||
| return true | ||
| } | ||
| return false | ||
| }, 15*time.Second, 500*time.Millisecond, "Trigger transaction should be included") |
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 current implementation of require.Eventually will continue to retry until timeout even if the transaction has definitively failed (i.e., receipt.Status == 0). This slows down test execution and can produce a less informative timeout error message. It's better to fail fast in case of a transaction failure.
require.Eventually(t, func() bool {
receipt, err := client.TransactionReceipt(ctx, triggerTxHash)
if err != nil {
return false // Not found yet, retry
}
if receipt.Status != 1 {
t.Logf("Trigger tx failed! Status: %d, GasUsed: %d", receipt.Status, receipt.GasUsed)
require.FailNow(t, "transaction failed with status 0")
}
triggerReceipt = receipt
return true
}, 15*time.Second, 500*time.Millisecond, "Trigger transaction should be included")| require.Eventually(t, func() bool { | ||
| receipt, err := client.TransactionReceipt(ctx, deployTxHash) | ||
| if err == nil && receipt != nil && receipt.Status == 1 { | ||
| contractAddress = receipt.ContractAddress | ||
| return true | ||
| } | ||
| return false | ||
| }, 20*time.Second, 500*time.Millisecond, "Contract deployment should be included") |
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 current implementation of require.Eventually will continue to retry until timeout even if the transaction has definitively failed (i.e., receipt.Status == 0). This slows down test execution and can produce a less informative timeout error message. It's better to fail fast in case of a transaction failure.
require.Eventually(t, func() bool {
receipt, err := client.TransactionReceipt(ctx, deployTxHash)
if err != nil {
return false // Not found yet, retry
}
if receipt.Status != 1 {
t.Logf("Contract deployment tx failed! Status: %d, GasUsed: %d", receipt.Status, receipt.GasUsed)
require.FailNow(t, "transaction failed with status 0")
}
contractAddress = receipt.ContractAddress
return true
}, 20*time.Second, 500*time.Millisecond, "Contract deployment should be included")| t.Logf("✅ Contract deployed at: %s", contractAddress.Hex()) | ||
|
|
||
| // 2. Call store(42) -> 42 is 0x2a | ||
| t.Log("Calling set(42)...") |
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 log message "Calling set(42)..." is inconsistent with the smart contract's function name, which is store. To improve clarity and consistency with the contract's source code provided in the comments, please update the log message.
| t.Log("Calling set(42)...") | |
| t.Log("Calling store(42)...") |
| Gas: 500000, // Should be plenty for simple SSTORE | ||
| GasPrice: big.NewInt(30000000000), |
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 values for Gas (500000) and GasPrice (30000000000) are hardcoded. These "magic numbers" are repeated in TestEvmContractEvents and deployContract, making them difficult to maintain. It would be better to define them as named constants at the top of the file for better clarity and easier modification.
| t.Log("✅ Store transaction confirmed") | ||
|
|
||
| // 3. Call retrieve() and verify result | ||
| t.Log("Calling get() to verify state...") |
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.
| // deployContract helps deploy a contract and waits for its inclusion. | ||
| // Returns the deployed contract address and the next nonce. | ||
| func deployContract(t *testing.T, ctx context.Context, client *ethclient.Client, bytecodeStr string, nonce uint64, privateKey *ecdsa.PrivateKey, chainID *big.Int) (common.Address, uint64) { | ||
| bytecode, err := hexutil.Decode("0x" + bytecodeStr) |
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 line hexutil.Decode("0x" + bytecodeStr) is fragile. If bytecodeStr already contains a "0x" prefix, the decoding will fail. The hexutil.Decode function can handle strings with or without the "0x" prefix. To make this helper function more robust and reusable, it's better to remove the explicit prefix concatenation.
bytecode, err := hexutil.Decode(bytecodeStr)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3006 +/- ##
=======================================
Coverage 57.96% 57.96%
=======================================
Files 110 110
Lines 10526 10526
=======================================
Hits 6101 6101
Misses 3774 3774
Partials 651 651
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Overview
This was a blind spot in e2e tests.
Added 2 new tests for basic coverage (mostly AI generated)