Skip to content
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: fix integration & unit tests #14

Merged
merged 48 commits into from
Nov 26, 2024

Conversation

jim380
Copy link
Contributor

@jim380 jim380 commented Nov 20, 2024

Overview

Summary by CodeRabbit

  • New Features

    • Streamlined handling of the StateRoot in transaction execution and chain initialization processes.
  • Bug Fixes

    • Improved type consistency in state root assertions during tests.
  • Tests

    • Adjusted test functions to enhance the initialization of prevStateRoot and simplify assertions for state root comparisons.

Copy link

coderabbitai bot commented Nov 20, 2024

Walkthrough

The changes involve modifications to the execution.go, execution_test.go, and integration_test.go files. In execution.go, the handling of the StateRoot in the InitChain and ExecuteTxs methods has been simplified by directly accessing it from payloadResult.ExecutionPayload, eliminating unnecessary hexadecimal conversions. The test files have been updated to reflect these changes, with adjustments made to the handling of the prevStateRoot variable in execution_test.go and alterations in type comparison for assertions in integration_test.go.

Changes

File Change Summary
execution.go - Simplified StateRoot handling in InitChain and ExecuteTxs by removing hex conversion.
execution_test.go - Adjusted prevStateRoot initialization in TestEngineAPIExecutionClient_ExecuteTxs.
- Simplified assertion for stateRoot comparison.
integration_test.go - Modified assertion in TestExecutionClientLifecycle to compare rollkit_types.Hash objects.

Possibly related PRs

Suggested reviewers

  • gupadhyaya

Poem

🐇 In the code where the rabbits play,
Simplified paths now lead the way.
No more hex, just a direct flow,
Clarity blooms, watch it grow!
With tests aligned, all's set to run,
Hopping along, we’ve just begun! 🌼


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jim380 jim380 changed the title Execution API Follow-up test: fix unit tests Nov 20, 2024
@jim380 jim380 changed the title test: fix unit tests test: fix integration & unit tests Nov 20, 2024
@jim380 jim380 marked this pull request as ready for review November 20, 2024 22:48
Copy link

@coderabbitai coderabbitai bot left a 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 (7)
execution_test.go (1)

Line range hint 80-117: Consider adding test cases for edge scenarios

While the current changes improve the test, consider adding test cases for:

  • Invalid state root formats
  • Error scenarios when state root validation fails
  • Edge cases with empty or malformed state roots

This would enhance the test coverage and ensure robust handling of state roots.

integration_test.go (3)

203-204: Consider improving test maintainability

The hardcoded state root value makes the test brittle and harder to maintain. Consider:

  1. Adding a comment explaining why this specific state root is expected
  2. Deriving the expected state root dynamically if possible

Example improvement:

+        // This state root is expected after executing a single transfer transaction
+        // with value 1 ETH from the test account to TEST_TO_ADDRESS
         newStateroot := common.HexToHash("0x362b7d8a31e7671b0f357756221ac385790c25a27ab222dc8cbdd08944f5aea4")
         assert.Equal(t, rollkit_types.Hash(newStateroot[:]), stateroot)

Line range hint 89-91: Improve container startup reliability

The current implementation uses a fixed sleep duration which could lead to flaky tests. Consider implementing a more robust wait mechanism.

Example improvement:

-    // a reasonable time to wait for the container to start!
-    // do we want a more predictable elaborate code to wait for the container to be running?
-    time.Sleep(50 * time.Millisecond)
+    // Wait for the container to be ready by polling the HTTP endpoint
+    ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+    defer cancel()
+    for {
+        select {
+        case <-ctx.Done():
+            t.Fatal("timeout waiting for container to start")
+        default:
+            if _, err := ethclient.Dial(TEST_ETH_URL); err == nil {
+                return
+            }
+            time.Sleep(100 * time.Millisecond)
+        }
+    }

Line range hint 156-204: Consider adding error case tests

The test suite thoroughly covers the happy path but could benefit from additional test cases for error scenarios:

  1. Invalid transactions
  2. Network failures
  3. Timeout scenarios

Would you like me to help create additional test cases for these scenarios?

execution.go (3)

148-151: Consider adding nil check for ExecutionPayload

While the state root handling has been simplified, consider adding a defensive nil check for payloadResult.ExecutionPayload before accessing the StateRoot to prevent potential panic.

+	if payloadResult.ExecutionPayload == nil {
+		return execution_types.Hash{}, 0, fmt.Errorf("nil execution payload")
+	}
 	stateRoot := payloadResult.ExecutionPayload.StateRoot
 	rollkitStateRoot := execution_types.Hash(stateRoot[:])

148-151: Inconsistent state root handling between InitChain and ExecuteTxs

There's an inconsistency in how the state root is handled:

  • InitChain uses execution_types.Hash(stateRoot[:])
  • ExecuteTxs uses payloadResult.ExecutionPayload.StateRoot.Bytes()

Both approaches work but using different methods could lead to confusion. Consider standardizing the approach across both methods.

For ExecuteTxs, consider using:

-	return payloadResult.ExecutionPayload.StateRoot.Bytes(), payloadResult.ExecutionPayload.GasUsed, nil
+	stateRoot := payloadResult.ExecutionPayload.StateRoot
+	return execution_types.Hash(stateRoot[:]), payloadResult.ExecutionPayload.GasUsed, nil

Also applies to: 266-266


148-151: Consider adding documentation for state root handling

Given that this code is part of a test fix PR and involves changes to state root handling, consider adding documentation to explain:

  • Why the state root is handled differently in InitChain vs ExecuteTxs
  • The relationship between common.Hash and execution_types.Hash
  • Any assumptions about the Engine API payload structure

This will help future maintainers understand the design decisions.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1403e27 and 0d60d58.

📒 Files selected for processing (3)
  • execution.go (1 hunks)
  • execution_test.go (2 hunks)
  • integration_test.go (1 hunks)
🔇 Additional comments (3)
execution_test.go (2)

80-87: LGTM: Improved test initialization with explicit state root

The change improves test clarity by using a known state root value instead of an empty hash, making the test setup more explicit and realistic.


117-117: LGTM: Simplified state root assertion

The assertion has been simplified to directly compare execution_types.Hash values without unnecessary intermediate conversions, making the test more maintainable.

integration_test.go (1)

204-204: LGTM! Type consistency improvement

The change correctly ensures type consistency by comparing state roots using rollkit_types.Hash type, which aligns with the changes in execution.go.

@tzdybal
Copy link
Member

tzdybal commented Nov 25, 2024

Tests are working correctly, except the waiting for docker containers 👍

@tzdybal
Copy link
Member

tzdybal commented Nov 26, 2024

Merging as is, will followup.

@tzdybal tzdybal merged commit d93d12c into rollkit:main Nov 26, 2024
14 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants