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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sideninja
Copy link
Member

@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

  • Tests
    • Enhanced end-to-end testing for Web3 transactions with batch processing capabilities.
    • Simplified test setup processes by removing error returns in setup functions.
    • Improved batch retrieval logic in JavaScript tests to handle multiple transactions efficiently.

Copy link

coderabbitai bot commented May 10, 2024

Walkthrough

The recent updates focus on enhancing batch processing capabilities in Ethereum-related tests. Changes include the introduction of new imports, modifications to transaction handling to support batch operations, and simplification of test setup functions. This streamlines the testing process and expands the test coverage for batch transactions in a blockchain context.

Changes

File Path Change Summary
tests/e2e_web3js_test.go Added multiple imports and updated functions to support batch transaction processing.
tests/helpers.go Simplified the runWeb3TestWithSetup function by removing the error return from the setup function.
tests/web3js/.../eth_batch_retrieval_test.js Enhanced batch retrieval logic for transactions and improved assertion handling based on batch size.

🐇✨
Oh, in the code where bytes flow,
Batched transactions, off they go!
With hex and hashes, tests now thrive,
In digital burrows, they come alive!
Cheers to changes, small and big,
In the warren of code, we dance and dig! 🎉
🐇💻


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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

@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.

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, block.number)
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

assert.equal(tx.blockNumber, block.number, "wrong block number")
assert.equal(tx.blockHash, block.hash, "wrong block hash")
assert.equal(tx.type, 0, "wrong type")
//assert.equal(tx.transactionIndex, i, "wrong index")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
//assert.equal(tx.transactionIndex, i, "wrong index")
assert.equal(tx.transactionIndex, i, "wrong index")

for (let i = 0; i < block.transactions.length; i++) {
let tx = await web3.eth.getTransactionFromBlock(latestHeight, block.number)
console.log(tx)
console.log("-----")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we can remove these 2 console.log statements.

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!

@@ -37,40 +42,48 @@ func TestWeb3_E2E(t *testing.T) {
})

t.Run("batch run transactions", func(t *testing.T) {
runWeb3TestWithSetup(t, "eth_batch_retrieval_test", func(emu emulator.Emulator) error {
tx1, err := cadence.NewString("f9015880808301e8488080b901086060604052341561000f57600080fd5b60eb8061001d6000396000f300606060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063c6888fa1146044575b600080fd5b3415604e57600080fd5b606260048080359060200190919050506078565b6040518082815260200191505060405180910390f35b60007f24abdb5865df5079dcc5ac590ff6f01d5c16edbc5fab4e195d9febd1114503da600783026040518082815260200191505060405180910390a16007820290509190505600a165627a7a7230582040383f19d9f65246752244189b02f56e8d0980ed44e7a56c0b200458caad20bb002982052fa09c05a7389284dc02b356ec7dee8a023c5efd3a9d844fa3c481882684b0640866a057e96d0a71a857ed509bb2b7333e78b2408574b8cc7f51238f25c58812662653")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know that it's impossible to understand what these 2 transactions did 😅
I believe it was a good test case scenario though, it was basically a contract deployment, followed by a contract function call. But I suppose that such logic must already have been tested against in the flow-go repository.

Copy link
Member Author

Choose a reason for hiding this comment

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

I plan to add more complex transactions as well, but I prefer actually building them not just passing payload, that way is clear what they do and it's easier to change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In Review
Development

Successfully merging this pull request may close these issues.

None yet

2 participants