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

chore(e2e): tolerate multiple runs of precompiled tests #3256

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Dec 6, 2024

Closes #3201

Use relative balances when possible in the precompiled contract tests to enable running multiple times.

The staking contracts cannot be run multiple times so disable them if the block height is greater than 100 (indicating an unclean test environment).

I need to add a CI check that verifies e2e can be run multiple times to prevent future regressions.

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced end-to-end testing functionality with improved conditional logic based on blockchain state.
    • Added utility functions for simplified arithmetic operations on large integers.
  • Bug Fixes

    • Improved robustness of tests by ensuring clean state checks for ERC20 token allowances and balances.
  • Documentation

    • Updated comments for clarity on expected outcomes and balance checks in tests.

@gartnera gartnera added the no-changelog Skip changelog CI check label Dec 6, 2024
@gartnera gartnera requested a review from a team as a code owner December 6, 2024 22:00
Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

📝 Walkthrough

Walkthrough

The pull request introduces enhancements to end-to-end tests in the local.go, helpers.go, and test_precompiles_bank.go files. Key modifications include the addition of a block height variable to conditionally execute tests based on the system state, the implementation of utility functions for arithmetic operations on *big.Int, and improved balance checks in precompiles tests. These changes ensure that tests run under appropriate conditions and maintain a clean state, enhancing the robustness and clarity of the testing framework.

Changes

File Path Change Summary
cmd/zetae2e/local/local.go Added variable e2eStartHeight to capture block height; modified logic for running precompiled contract tests based on this height; moved MintERC20OnEvm call to before each test.
e2e/e2etests/helpers.go Added utility functions bigAdd and bigSub for addition and subtraction of *big.Int.
e2e/e2etests/test_precompiles_bank.go Updated TestPrecompilesBank to ensure zero allowance before tests; modified balance checks to use initial balances.
e2e/e2etests/test_precompiles_bank_through_contract.go Updated TestPrecompilesBankThroughContract to reset allowance and use starting balances for assertions.

Assessment against linked issues

Objective Addressed Explanation
Ensure precompiles tests can run multiple times (3201)
Fix balance assertions to reflect actual state (3201)
Enable tests to be run in a clean state (3201)

Possibly related PRs

Suggested labels

UPGRADE_TESTS, stateful-precompile, V2_TESTS

Suggested reviewers

  • fbac
  • kingpinXD
  • swift1337
  • ws4charlie
  • lumtis
  • skosito
  • brewmaster012

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.

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.

@gartnera gartnera changed the title chore(e2e): tolerate multiple runs of precompile tests chore(e2e): tolerate multiple runs of precompiled tests Dec 6, 2024
Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.75%. Comparing base (bc1d8ae) to head (e88efb7).
Report is 3 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #3256   +/-   ##
========================================
  Coverage    61.74%   61.75%           
========================================
  Files          431      431           
  Lines        30772    30772           
========================================
+ Hits         19001    19004    +3     
+ Misses       10914    10911    -3     
  Partials       857      857           

see 4 files with indirect coverage changes

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

🧹 Outside diff range and nitpick comments (2)
cmd/zetae2e/local/local.go (1)

381-391: Enhance Test Independence by Eliminating Block Height Dependency

Relying on e2eStartHeight < 100 to conditionally execute tests introduces external dependencies on the system state. Consider refactoring the tests to be idempotent and independent of the block height, ensuring they can run reliably in any environment.

e2e/e2etests/test_precompiles_bank.go (1)

63-69: Refactor Balance Initialization into Helper Function

The code for initializing and capturing starting balances is similar across multiple tests. Consider abstracting this into a helper function to reduce duplication and improve maintainability.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2cd0b73 and e88efb7.

📒 Files selected for processing (4)
  • cmd/zetae2e/local/local.go (3 hunks)
  • e2e/e2etests/helpers.go (1 hunks)
  • e2e/e2etests/test_precompiles_bank.go (5 hunks)
  • e2e/e2etests/test_precompiles_bank_through_contract.go (5 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
e2e/e2etests/helpers.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/e2etests/test_precompiles_bank.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/e2etests/test_precompiles_bank_through_contract.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

cmd/zetae2e/local/local.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

🔇 Additional comments (18)
cmd/zetae2e/local/local.go (2)

221-223: Block Height Retrieval Implemented Correctly

The retrieval of e2eStartHeight ensures that the current block height is captured before test execution. This is correctly implemented.


288-290: Consistent Minting of ERC20 Tokens Before Tests

Calling MintERC20OnEvm(1e10) prior to each test ensures a consistent state for ERC20 token availability.

e2e/e2etests/helpers.go (1)

189-197: Utility Functions Improve Code Readability

The addition of bigAdd and bigSub functions provides clear and concise operations for big integer arithmetic, enhancing code readability.

e2e/e2etests/test_precompiles_bank_through_contract.go (8)

Line range hint 50-54: Proper Reset of Allowance and Balance in Test Cleanup

Resetting the allowance and balance ensures that tests can run multiple times without interference from previous states, improving test reliability.


63-69: Initialization of Starting Balances Enhances Test Accuracy

Capturing the starting balances for the spender and bank addresses allows for precise balance assertions throughout the test.


76-78: Balance Assertions Use Starting Balances Appropriately

Using the starting balances in assertions ensures accuracy and adaptability, especially if the initial balances change.


89-91: Balances Remain Unchanged After Failed Deposit Attempt

Verifying that balances remain the same after a failed operation confirms that the contract handles error conditions correctly.


102-104: Correct Handling of Deposit Amount Exceeding Balance

The test accurately checks that depositing an amount higher than the available balance fails as expected.


111-117: Successful Deposit Updates Balances Appropriately

After a successful deposit, the balances are updated correctly, reflecting the transfer of tokens.


127-137: Withdrawal Amount Validation Works as Intended

Attempting to withdraw more than the available balance fails, indicating proper validation in the withdrawal logic.


144-146: Balances Restored After Successful Withdrawal

Upon successful withdrawal, the balances return to their initial state, demonstrating correct function behavior.

e2e/e2etests/test_precompiles_bank.go (7)

49-54: Ensuring Zero Allowance Before Test Execution

Resetting the allowance to zero before the test begins prevents interference from previous test runs and ensures a clean testing environment.


111-118: Accurate Balance Update Verification After Deposit

The assertions confirm that balances are updated correctly following a deposit, ensuring the contract's deposit functionality works as intended.


123-128: Maintaining Token Lock State Post-Failed Withdrawal

After a failed withdrawal attempt, the bank's token balance remains unchanged, indicating proper handling of unsuccessful operations.


140-145: Successful Withdrawal Reflects Correct Balance Adjustments

Balances are correctly adjusted following a successful withdrawal, validating the withdrawal logic.


160-168: Spender's Cosmos Balance Reset to Initial State

The test confirms that the spender's cosmos balance returns to the initial state after withdrawal, ensuring consistency.


170-178: Spender's ZRC20 Balance Restored Post-Withdrawal

The spender's ZRC20 balance matches the starting balance after withdrawal, indicating that tokens are returned properly.


180-188: Bank's ZRC20 Balance Correct After Transactions

The bank's ZRC20 balance reflects the correct amount after deposit and withdrawal operations, confirming accurate balance management.

Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ws4charlie ws4charlie left a comment

Choose a reason for hiding this comment

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

lgtm

@gartnera gartnera added this pull request to the merge queue Dec 9, 2024
Merged via the queue into develop with commit 1329066 Dec 9, 2024
46 of 50 checks passed
@gartnera gartnera deleted the e2e-precompiles-relative branch December 9, 2024 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking:cli no-changelog Skip changelog CI check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix precompiles E2E tests when running test-tss-migration
3 participants