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

Improve tests for batched transactions #239

Merged
merged 4 commits into from
May 30, 2024

Conversation

sideninja
Copy link
Contributor

@sideninja sideninja commented May 10, 2024

Description

Improve testing of batched transactions.


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • New Features

    • Enhanced the batch processing of Ethereum value transfer transactions in end-to-end tests.
  • Tests

    • Improved test logic to handle multiple value transfers and batch transactions.
    • Updated test functions to create and manage batch transactions more efficiently.
    • Refined batch retrieval of transaction details and assertions.

These changes improve the robustness and efficiency of our testing processes, ensuring better performance and reliability.

Copy link
Contributor

coderabbitai bot commented May 10, 2024

Warning

Rate limit exceeded

@m-Peter has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 34 minutes and 41 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 608059e and 1909727.

Walkthrough

The recent updates enhance the testing framework for Ethereum transactions by incorporating batch processing capabilities. The primary changes involve creating, encoding, and sending multiple transactions in batches within the TestWeb3_E2E function, and adjusting the setup function in helpers.go to streamline error handling. Additionally, the batch retrieval logic in eth_batch_retrieval_test.js has been refined to perform detailed assertions on transaction details.

Changes

File Path Change Summary
tests/e2e_web3js_test.go Added imports and modified the TestWeb3_E2E function to handle batch transactions, including creating, encoding, and sending multiple transactions.
tests/helpers.go Updated runWeb3TestWithSetup to simplify the setup function, removing error handling and ensuring the setup function is called directly.
tests/web3js/eth_batch_retrieval_test.js Refined logic for batch retrieval of transactions, iterating over transactions, retrieving details, and performing assertions based on batch size.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant T as Test Function
    participant E as Ethereum Library
    participant B as Batch Processor
    participant A as Assertions

    T->>E: Create multiple transactions
    E->>B: Encode transactions
    B->>T: Return encoded transactions
    T->>B: Send batch transactions
    B->>T: Confirm transactions sent
    T->>A: Perform assertions on batch transactions
    A->>T: Return results
Loading

Possibly related issues

  • Add support for batched transactions #224: The changes in this PR directly address the need for supporting batched transactions by updating the test framework to handle multiple transactions in a single block.

Poem

In code we weave a batch so grand,
Transactions flow, hand in hand.
With tests refined and errors gone,
Our blockchain dance goes on and on.
🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

Copy link
Contributor

@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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 553fca6 and 5163f65.
Files selected for processing (3)
  • tests/e2e_web3js_test.go (2 hunks)
  • tests/helpers.go (1 hunks)
  • tests/web3js/eth_batch_retrieval_test.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • tests/web3js/eth_batch_retrieval_test.js
Additional comments not posted (7)
tests/e2e_web3js_test.go (6)

4-4: Import of encoding/hex is appropriate for handling hexadecimal encoding required for transaction data.


7-7: Import of github.com/onflow/go-ethereum/common is necessary for Ethereum common utilities, which are essential for address handling in the tests.


8-8: Import of github.com/onflow/go-ethereum/crypto is crucial for cryptographic functions like signing transactions, which is used extensively in the test setup.


9-9: Import of github.com/stretchr/testify/require is used for assertions within the test functions, ensuring that the tests fail fast on errors.


10-10: Import of math/big is used for handling large integers in Ethereum transactions, which is necessary for the test scenarios.


45-86: The modifications in TestWeb3_E2E to handle batch transactions are well-implemented. The setup for creating multiple transactions and the subsequent assertions are correctly structured to ensure that each transaction in the batch is processed successfully.

tests/helpers.go (1)

111-114: The modification in runWeb3TestWithSetup to remove the error return from the setup function parameter simplifies the test setup process. This change likely reduces boilerplate error handling and makes the function easier to use in test scenarios.

Copy link
Collaborator

@m-Peter m-Peter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@m-Peter m-Peter self-assigned this May 30, 2024
@m-Peter m-Peter added this to the Flow-EVM-M2 milestone May 30, 2024
Copy link
Contributor

@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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5163f65 and 1b2318e.

Files selected for processing (1)
  • tests/web3js/eth_batch_retrieval_test.js (1 hunks)
Additional context used
Biome
tests/web3js/eth_batch_retrieval_test.js

[error] 9-9: This let declares a variable that is only assigned once.


[error] 10-10: This let declares a variable that is only assigned once.


[error] 12-12: This let declares a variable that is only assigned once.


[error] 16-16: This let declares a variable that is only assigned once.

Additional comments not posted (1)
tests/web3js/eth_batch_retrieval_test.js (1)

6-23: The logic and assertions in the test function appear correct and effectively test the batch transaction retrieval.

@m-Peter m-Peter force-pushed the gregor/batched-transactions-testing branch from 1b2318e to 608059e Compare May 30, 2024 11:42
Copy link
Contributor

@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: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1b2318e and 608059e.

Files selected for processing (3)
  • tests/e2e_web3js_test.go (2 hunks)
  • tests/helpers.go (1 hunks)
  • tests/web3js/eth_batch_retrieval_test.js (1 hunks)
Additional context used
Biome
tests/web3js/eth_batch_retrieval_test.js

[error] 8-8: This let declares a variable that is only assigned once.


[error] 9-9: This let declares a variable that is only assigned once.


[error] 11-11: This let declares a variable that is only assigned once.


[error] 15-15: This let declares a variable that is only assigned once.

Additional comments not posted (2)
tests/e2e_web3js_test.go (1)

50-91: The refactoring of runWeb3TestWithSetup to handle batch transactions is well done. The use of require.NoError ensures that any errors are caught immediately, which is crucial for transaction handling.

tests/helpers.go (1)

112-115: The simplification of the setupFunc parameter in runWeb3TestWithSetup is a good improvement. Removing the error return type simplifies the function signature and error handling.

let latestHeight = await web3.eth.getBlockNumber()
let block = await web3.eth.getBlock(latestHeight)
assert.lengthOf(block.transactions, 2)
let latestHeight = await web3.eth.getBlockNumber()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using const for latestHeight as it is assigned only once.

- let latestHeight = await web3.eth.getBlockNumber()
+ const latestHeight = await web3.eth.getBlockNumber()

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.

Suggested change
let latestHeight = await web3.eth.getBlockNumber()
const latestHeight = await web3.eth.getBlockNumber()

assert.equal(block.hash, deployTx.blockHash)
assert.equal(0, deployTx.type)
assert.equal(0, deployTx.transactionIndex)
let batchSize = 10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using const for batchSize as it is assigned only once.

- let batchSize = 10
+ const batchSize = 10

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.

Suggested change
let batchSize = 10
const batchSize = 10

let block = await web3.eth.getBlock(latestHeight)
assert.lengthOf(block.transactions, 2)
let latestHeight = await web3.eth.getBlockNumber()
let block = await web3.eth.getBlock(latestHeight)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using const for block as it is assigned only once.

- let block = await web3.eth.getBlock(latestHeight)
+ const block = await web3.eth.getBlock(latestHeight)

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.

Suggested change
let block = await web3.eth.getBlock(latestHeight)
const block = await web3.eth.getBlock(latestHeight)

assert.equal(0, callTx.type)
assert.equal(1, callTx.transactionIndex)
for (let i = 0; i < block.transactions.length; i++) {
let tx = await web3.eth.getTransactionFromBlock(latestHeight, i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using const for tx as it is assigned only once.

- let tx = await web3.eth.getTransactionFromBlock(latestHeight, i)
+ const tx = await web3.eth.getTransactionFromBlock(latestHeight, i)

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.

Suggested change
let tx = await web3.eth.getTransactionFromBlock(latestHeight, i)
const tx = await web3.eth.getTransactionFromBlock(latestHeight, i)

@m-Peter m-Peter merged commit 86dc85e into main May 30, 2024
2 checks passed
@m-Peter m-Peter deleted the gregor/batched-transactions-testing branch May 30, 2024 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants