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

feat(e2e): new offer sync validation in buy BTC test #17430

Merged
merged 1 commit into from
Mar 5, 2025

Conversation

Vere-Grey
Copy link
Contributor

minor name refactoring

Description

This starts covering some of the advance trading scenarios. I wanted originally just move time in compared offer view. But it seems the refresh is not tied to browser time. So page.clock.forward did nothing. Instead I used change of fiat input to trigger one.

Related Issue

Resolve 17364

Screenshots:

@Vere-Grey Vere-Grey requested a review from HajekOndrej March 5, 2025 18:04
@Vere-Grey Vere-Grey self-assigned this Mar 5, 2025
Copy link

coderabbitai bot commented Mar 5, 2025

Walkthrough

This pull request adds a new JSON file that provides updated Bitcoin quote data with detailed information for cryptocurrency transactions. The new data includes exchange details, fiat and cryptocurrency currencies, rates, payment methods, and various limits and identifiers. Additionally, multiple test files and a page object file have been updated to integrate the new JSON data. Method names within the trading page object have been refactored—from names like setYouBuyAmount, setYouSellAmount, and setYouSwapAmount to fillBuyForm, fillSellForm, and fillSwapForm—and corresponding tests have been adjusted to use these updated method names. The changes also include the addition of a new import for the JSON file in both the module export file and relevant test files to support updated transaction and validation logic.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for this 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.

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

🧹 Nitpick comments (1)
packages/suite-desktop-core/e2e/support/pageObjects/tradingPage.ts (1)

408-422: Enhanced reusability by parameterizing the quotes validation.

The validateBuyQuotes method now accepts a quotesResponse parameter instead of hardcoding a reference to buyQuotesBTC. This makes the method more flexible and reusable across different test scenarios, including the new offer refresh validation.

Consider adding type annotations to the quotesResponse parameter to make the expected data structure clearer:

-  async validateBuyQuotes(quotesResponse: any[]) {
+  async validateBuyQuotes(quotesResponse: Array<{
+    paymentMethod: string;
+    error?: string;
+    exchange: string;
+    receiveStringAmount: string;
+  }>) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f31397 and 3de0259.

📒 Files selected for processing (13)
  • packages/suite-desktop-core/e2e/fixtures/invity/buy/quotes-bitcoin-update.json (1 hunks)
  • packages/suite-desktop-core/e2e/fixtures/invity/index.ts (2 hunks)
  • packages/suite-desktop-core/e2e/support/pageObjects/tradingPage.ts (5 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/buy-bitcoin.test.ts (3 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/buy-ethereum.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/buy-solana-token.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/sell-bitcoin.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/sell-ethereum-token.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/sell-solana.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/swap-coin-to-token.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/swap-coins.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/swap-token-to-coin.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/swap-tokens.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/suite-desktop-core/e2e/fixtures/invity/buy/quotes-bitcoin-update.json
🧰 Additional context used
🧠 Learnings (4)
packages/suite-desktop-core/e2e/tests/trading/swap-coins.test.ts (2)
Learnt from: Vere-Grey
PR: trezor/trezor-suite#17199
File: packages/suite-desktop-core/e2e/tests/trading/swap-coin-to-token.test.ts:34-38
Timestamp: 2025-02-24T15:31:48.018Z
Learning: Network configuration changes (enableNetwork/disableNetwork) in e2e tests only affect the specific suite instance and modify network visibility within that suite. Test isolation is handled by the framework.
Learnt from: Vere-Grey
PR: trezor/trezor-suite#17423
File: packages/suite-desktop-core/e2e/tests/trading/swap-coin-to-token.test.ts:38-39
Timestamp: 2025-03-05T16:14:27.095Z
Learning: In the Trezor Suite e2e tests, Bitcoin is discovered by default, so there's no need to call `await dashboardPage.discoveryShouldFinish()` after activating coins in tests that only work with Bitcoin.
packages/suite-desktop-core/e2e/tests/trading/swap-coin-to-token.test.ts (2)
Learnt from: Vere-Grey
PR: trezor/trezor-suite#17199
File: packages/suite-desktop-core/e2e/tests/trading/swap-coin-to-token.test.ts:34-38
Timestamp: 2025-02-24T15:31:48.018Z
Learning: Network configuration changes (enableNetwork/disableNetwork) in e2e tests only affect the specific suite instance and modify network visibility within that suite. Test isolation is handled by the framework.
Learnt from: Vere-Grey
PR: trezor/trezor-suite#17423
File: packages/suite-desktop-core/e2e/tests/trading/swap-coin-to-token.test.ts:38-39
Timestamp: 2025-03-05T16:14:27.095Z
Learning: In the Trezor Suite e2e tests, Bitcoin is discovered by default, so there's no need to call `await dashboardPage.discoveryShouldFinish()` after activating coins in tests that only work with Bitcoin.
packages/suite-desktop-core/e2e/tests/trading/swap-tokens.test.ts (1)
Learnt from: Vere-Grey
PR: trezor/trezor-suite#17199
File: packages/suite-desktop-core/e2e/tests/trading/swap-coin-to-token.test.ts:34-38
Timestamp: 2025-02-24T15:31:48.018Z
Learning: Network configuration changes (enableNetwork/disableNetwork) in e2e tests only affect the specific suite instance and modify network visibility within that suite. Test isolation is handled by the framework.
packages/suite-desktop-core/e2e/tests/trading/swap-token-to-coin.test.ts (2)
Learnt from: Vere-Grey
PR: trezor/trezor-suite#17423
File: packages/suite-desktop-core/e2e/tests/trading/swap-coin-to-token.test.ts:38-39
Timestamp: 2025-03-05T16:14:27.095Z
Learning: In the Trezor Suite e2e tests, Bitcoin is discovered by default, so there's no need to call `await dashboardPage.discoveryShouldFinish()` after activating coins in tests that only work with Bitcoin.
Learnt from: Vere-Grey
PR: trezor/trezor-suite#17199
File: packages/suite-desktop-core/e2e/tests/trading/swap-coin-to-token.test.ts:34-38
Timestamp: 2025-02-24T15:31:48.018Z
Learning: Network configuration changes (enableNetwork/disableNetwork) in e2e tests only affect the specific suite instance and modify network visibility within that suite. Test isolation is handled by the framework.
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=other, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=passphrase, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: build-web
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: Analyze with CodeQL (javascript)
🔇 Additional comments (24)
packages/suite-desktop-core/e2e/fixtures/invity/index.ts (2)

2-2: New fixture file added for updated Bitcoin quotes.

Good addition of a new import for buyQuotesBTCUpdate from 'quotes-bitcoin-update.json'. This aligns with the PR objective of enhancing offer sync validation in buy BTC tests.


90-90: Appropriate export of the new fixture.

Correctly exporting the newly imported buyQuotesBTCUpdate fixture to make it available for test files.

packages/suite-desktop-core/e2e/tests/trading/sell-ethereum-token.test.ts (1)

51-51: Method name refactoring improves clarity.

Good renaming from setYouSellAmount to fillSellForm which is more descriptive of the action being performed. This is a positive change for code readability and maintainability.

packages/suite-desktop-core/e2e/tests/trading/swap-coins.test.ts (1)

55-55: Clear method renaming enhances test readability.

Good refactoring from setYouSwapAmount to fillSwapForm which provides a more intuitive description of the action being performed.

Based on the retrieved learnings, I noticed that you've properly implemented network configuration in your e2e tests, understanding that these changes only affect the specific suite instance under test.

packages/suite-desktop-core/e2e/tests/trading/buy-ethereum.test.ts (1)

37-37: Consistent method renaming improves API clarity.

Good renaming from setYouBuyAmount to fillBuyForm which maintains consistency with the other trading form methods. This refactoring provides a more intuitive understanding of what the method does.

packages/suite-desktop-core/e2e/tests/trading/swap-tokens.test.ts (1)

46-46: Method name refactoring is consistent with project changes

The method name has been updated from setYouSwapAmount to fillSwapForm, which is part of a broader refactoring across the trading page object methods. This change improves readability by making the method name more descriptive of its actual purpose - filling out a form rather than just setting an amount.

packages/suite-desktop-core/e2e/tests/trading/swap-token-to-coin.test.ts (1)

46-46: Method name change maintains consistency

This change from setYouSwapAmount to fillSwapForm aligns with the method naming pattern established across other trading test files. The functionality remains the same while the name more accurately describes the action being performed.

packages/suite-desktop-core/e2e/tests/trading/sell-solana.test.ts (1)

67-67: Method renamed for consistent API

The method name change from setYouSellAmount to fillSellForm follows the same pattern applied to other trading methods. This makes the trading page API more consistent (fillBuyForm, fillSellForm, fillSwapForm) and better describes that the method completes the entire form rather than just setting an amount.

packages/suite-desktop-core/e2e/tests/trading/swap-coin-to-token.test.ts (2)

46-46: Method name refactoring improves code clarity

The changed method name from setYouSwapAmount to fillSwapForm is more descriptive and follows the consistent naming pattern established across all trading functionality. This naming convention better indicates that the method handles the complete form filling process.


36-38: Leveraging network configuration knowledge effectively

Your approach to explicitly enabling/disabling required networks (enabling SOL and ETH while disabling BTC) is correctly implemented. This aligns with previous learnings that network configuration changes only affect the specific suite instance and that test isolation is handled by the framework.

packages/suite-desktop-core/e2e/tests/trading/sell-bitcoin.test.ts (1)

49-49: Method name change looks good and is more descriptive.

The renamed method fillSellForm is more descriptive than the previous setYouSellAmount, as it better represents the action of populating the entire sell form rather than just setting an amount. This change improves code clarity and is consistent with similar method renames across the codebase.

packages/suite-desktop-core/e2e/tests/trading/buy-solana-token.test.ts (1)

47-51: Method name change is consistent and more descriptive.

The renamed method fillBuyForm better represents the action of filling the entire form rather than just setting an amount. This change maintains naming consistency with other similar methods throughout the trading test suite.

packages/suite-desktop-core/e2e/tests/trading/buy-bitcoin.test.ts (8)

4-10: Good addition of the new import for updated quote data.

The addition of buyQuotesBTCUpdate enables testing of the offer refresh functionality, which is an important part of the test case for validating sync behavior.


18-25: Clear constant definitions for the updated test flow.

These new constants properly define expected values for the updated flow. The variable names are descriptive and follow the established naming pattern. The comment on line 21 helps explain why index 11 is chosen for the second offer.


38-44: Test title and implementation now match the PR objective.

The test has been updated to focus on "Buy Bitcoin from compared offer" which aligns with the PR objective of testing offer sync validation. The first step correctly uses the renamed fillBuyForm method.


46-52: Good addition of form validation check.

Adding the check for the formatted fiat input value (line 47) ensures the form is correctly displaying the expected value after filling. The validation of quotes using the parameterized method is a good approach.


54-62: Excellent implementation of offer refresh validation.

This new test step properly tests the offer refresh functionality triggered by changing the fiat input. It:

  1. Sets up a route mock for updated quotes
  2. Waits for the quote request to be sent
  3. Updates the input value
  4. Waits for the request to complete
  5. Validates the updated quotes are displayed correctly

This implementation addresses the PR objective of testing offer sync validation without relying on page.clock.forward.


64-66: Concise step for selecting the second offer.

This step clearly demonstrates selecting the second offer from the comparison view, which is an essential part of the test flow.


71-71: Correctly updated expected confirmation value.

The test now correctly expects the updated fiat amount in the confirmation screen, which matches the selected second offer.


81-81: Method name change is consistent with other updates.

The renamed method fillBuyForm is used consistently in both test cases, improving clarity and maintainability.

packages/suite-desktop-core/e2e/support/pageObjects/tradingPage.ts (4)

7-7: Imported invityEndpoint directly instead of through a relative path.

This change simplifies the import and helps maintain consistency in importing the endpoint definitions.


273-297: Method renamed for clarity and improved implementation.

The method renaming from setYouBuyAmount to fillBuyForm better represents the function's purpose - it fills out the entire buy form, not just setting an amount. The implementation remains solid, with proper awaiting on network requests and validations.


300-323: Method renamed for clarity and implementation remains solid.

The method renaming from setYouSellAmount to fillSellForm follows the same pattern as the buy form method. The implementation includes proper error checking for insufficient funds, which is a good practice.


326-352: Method renamed to be consistent with other form-filling methods.

The method renaming from setYouSwapAmount to fillSwapForm maintains consistency with the other method renames. The implementation properly waits for account changes to take effect before proceeding.

@Vere-Grey Vere-Grey merged commit 69a426e into develop Mar 5, 2025
27 of 28 checks passed
@Vere-Grey Vere-Grey deleted the feat/suite-desktop-core/e2e-quotes-refresh branch March 5, 2025 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants