-
Notifications
You must be signed in to change notification settings - Fork 245
test: add e2e tests for force inclusion (part 2) #2970
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).
|
|
Claude finished @julienrbrt's task in 2m 17s —— View job Code Review CompleteI've reviewed the force inclusion e2e tests added in this PR. Overall, the tests are well-structured and comprehensive, covering important security scenarios. Below is my detailed feedback organized by category. SummaryStrengths:
Areas for Improvement:
1. Code Quality & ArchitectureStrengths:
Issues:File: test/e2e/evm_force_inclusion_e2e_test.go Issue 1: File permissions (line 45) err = os.WriteFile(genesisPath, newData, 0644)The file is written with world-readable permissions ( Recommendation: Use Issue 2: Code duplication in setup functions The setup functions Recommendation: Extract common sequencer setup logic into a reusable helper function that accepts configuration parameters (like force inclusion namespace, port, etc.). Issue 3: Magic numbers throughout the tests Multiple hardcoded values appear without explanation:
Recommendation: Define these as named constants at the package level with explanatory comments: const (
ForceInclusionTestEpoch = 2 // DA blocks before force inclusion must occur
ForceInclusionTimeout = 30 * time.Second
ChainAdvanceTransactions = 15 // Number of txs to advance past epoch boundary
StopDetectionThreshold = 10 // Consecutive checks before confirming node stopped
)Issue 4: Verbose comments (as author noted) Lines 371-406 contain an extremely detailed comment block for 2. Error Handling & ResilienceIssues:Issue 5: Missing error check (line 146) client, err := ethclient.Dial(seqEthURL)
require.NoError(t, err)
defer client.Close()The Recommendation: defer func() {
if err := client.Close(); err != nil {
t.Logf("Failed to close client: %v", err)
}
}()This pattern appears multiple times (lines 146, 244, 248, 426, 430). Issue 6: Inconsistent error messages Line 205: The error messages don't follow a consistent capitalization pattern. Some start with lowercase, some with uppercase. Go convention is lowercase for error messages. Issue 7: Overly broad require checks Line 71: Using Recommendation: if errField, ok := res["error"]; ok && errField != nil {
require.Fail(t, "RPC returned error: %v", errField)
}3. SecurityIssues:Issue 8: HTTP client without timeout (line 62) resp, err := http.Post(fiUrl, "application/json", bytes.NewBuffer(jsonData))The HTTP client uses the default Recommendation: ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, fiUrl, bytes.NewBuffer(jsonData))
require.NoError(t, err)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)Issue 9: Unvalidated JSON response (lines 68-72) var res map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&res)
require.NoError(t, err)
require.Nil(t, res["error"], "RPC returned error: %v", res["error"])
require.NotNil(t, res["result"], "RPC result is nil")The code doesn't validate the structure of the JSON response before accessing fields. This could panic if the response structure is unexpected. Issue 10: Potential sensitive data in logs Throughout the tests, transaction hashes and other potentially sensitive data are logged. While this is a test environment, consider whether this establishes a pattern that might leak into production code. 4. Performance & Resource EfficiencyIssues:Issue 11: Resource leak - unclosed DA client (line 457) defer blobClient.Close()The Issue 12: Inefficient polling loop (lines 502-555) for i := 0; i < 120; i++ {
time.Sleep(500 * time.Millisecond)
// ... checks ...
}This polling loop runs for up to 60 seconds with fixed 500ms intervals. It performs multiple RPC calls per iteration which could be optimized. Recommendation: Use Issue 13: Sequential transaction sending in loop (lines 483-488) for i := 0; i < 15; i++ {
txExtra := evm.GetRandomTransaction(t, TestPrivateKey, TestToAddress, DefaultChainID, DefaultGasLimit, &nonce)
err = seqClient.SendTransaction(context.Background(), txExtra)
require.NoError(t, err)
time.Sleep(400 * time.Millisecond)
}This loop could benefit from batch sending or at least removing the sleep if the goal is to quickly advance the chain. The 400ms sleep seems arbitrary. Issue 14: Context usage inconsistency Line 152, 255, 437, 485: Recommendation: Create a single test context at the beginning and reuse it: ctx := context.Background()
// Use ctx throughout5. Testing & ReliabilityIssues:Issue 15: All tests are skipped (lines 127, 180, 407) t.Skip() // To re-enable after https://github.com/evstack/ev-node/issues/2965All three tests are skipped. While the issue reference explains why, this means the PR adds untested code. Ensure the tests are re-enabled once #2965 is resolved. Issue 16: Non-deterministic test behavior The malicious sequencer test (lines 406-563) relies on timing assumptions and may be flaky:
Recommendation: Consider adding configurable timeouts and making the test more deterministic by directly querying DA state rather than relying on timing. Issue 17: Missing negative test cases The tests cover happy paths and one malicious scenario, but missing:
Issue 18: Test dependencies The tests depend on external components (DA layer, sequencer, full node) which could make them brittle. Consider adding retries or more robust waiting mechanisms. 6. Documentation & Developer ExperienceStrengths:
Issues:Issue 19: Missing package-level documentation The file lacks a package comment explaining the force inclusion feature being tested. Developers unfamiliar with the feature would benefit from a high-level overview. Recommendation: Add a package comment at the top explaining:
Issue 20: Unclear helper function naming
Issue 21: Inconsistent logging style Some logs use emoji (line 537: 7. Dependencies (go.mod/go.sum changes)The PR adds Line 468: zerolog.Nop(),Issue 22: Unnecessary direct dependency Adding a logging library just to pass Recommendation: Check if Recommendations SummaryHigh Priority:
Medium Priority: Low Priority: ConclusionThe tests provide valuable coverage for force inclusion functionality, especially the malicious sequencer detection scenario. The code is generally well-written and follows existing patterns in the codebase. The main concerns are resource management, some security best practices, and test determinism. Once the resource leaks are fixed and the tests are re-enabled (after #2965), this will be a solid addition to the test suite. Tasks
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2970 +/- ##
==========================================
+ Coverage 57.75% 57.83% +0.07%
==========================================
Files 97 97
Lines 9303 9303
==========================================
+ Hits 5373 5380 +7
+ Misses 3326 3319 -7
Partials 604 604
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:
|
Forgot to push this other AI created test in this PR: #2964.
A bit verbose qua comments for my liking, but i've left it as it makes debugging easy.