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

E2E: Check receive addr on emulator #17500

Merged

Conversation

Vere-Grey
Copy link
Contributor

@Vere-Grey Vere-Grey commented Mar 10, 2025

This PR introduces first asserts of what is actually displayed on emulator to our e2e tests. So far we checked values only on prompt in the suite. Now we have custom Matcher toDisplayReceiveAddress which is to be called on expect(devicePrompt object) and takes parameter of address and optional parameter of tranformMode. The optional parameter is there because I have encountered two ways how address is displayed on the emulator.

    // Address is split to lines on Display so it can fit. There are different formats:
    // 1. Four tetragrams of address:
    // bc1q pyfv fvm5 2zx7
    // gek8 6ajj 5pkk ne3h
    // 385a da8r 2y
    // 1. Full lines (18 chars) of address:
    // bc1qpyfvfvm52zx7ge
    // k86ajj5pkkne3h385a
    // da8r2y

The assert is used in every test operating with receive address.
I have added also two other asserts but their use would be complicated now. Because of how we resuse some methods in Trading tests. I need rethink that and choose correct approach. Also I dont want this PR to be too big.

@Vere-Grey Vere-Grey self-assigned this Mar 10, 2025
Copy link

coderabbitai bot commented Mar 10, 2025

Walkthrough

The changes span multiple files within the project’s end-to-end testing suite. In the core page objects, the DevicePrompt class has introduced two new methods for debugging and validating JSON display content. The trading and passphrase test files have adjusted the address verification process by replacing previous formatting functions with a direct use of a new formatAddress utility. Test assertions have been modified to ensure that device prompts are properly displayed and that the addresses shown match expected values. In the custom matchers file, new types and helper functions have been introduced to support address formatting modes and improve display content comparisons. Additionally, intermediate variables used for address formatting have been removed in favor of passing raw address values directly during trade confirmations, streamlining the address handling process across various tests.

✨ Finishing Touches
  • 📝 Generate Docstrings

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

@Vere-Grey Vere-Grey force-pushed the feat/suite-desktop-core/e2e-check-receieve-addr-on-emulator branch from 43eca0c to c9bf981 Compare March 10, 2025 08:55
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 (3)
packages/suite-desktop-core/e2e/support/testExtends/customMatchers.ts (3)

30-41: Well-structured display content comparison function

This helper function encapsulates the common logic needed for all display-related matchers, avoiding code duplication. The use of lodash's isEqual ensures proper deep comparison of nested objects.

Consider adding a more specific type for expectedContent rather than any to improve type safety.

-const compareDisplayContent = async (
-    devicePrompt: DevicePrompt,
-    expectedContent: any,
-    errorMessage: string,
+const compareDisplayContent = async (
+    devicePrompt: DevicePrompt,
+    expectedContent: { header: any; body: any[]; footer: string },
+    errorMessage: string,

49-70: Comprehensive address transformation function with excellent documentation

The transformAddress function is well-documented with clear comments explaining the different address formatting modes. The implementation handles both modes appropriately.

However, the function doesn't handle invalid modes. While the type system should prevent this at compile time, it would be safer to add a fallback or error case.

const transformAddress = (address: string, mode: TransformMods = 'fourTetragrams') => {
    // ... existing code ...
    
    if (mode === 'fourTetragrams') {
        return addNewlinesToAddress(formatAddress(address), fourTetragramsOfAddress, ' \n');
    }

    if (mode === 'fullLine') {
        return addNewlinesToAddress(address, fullLineOfAddress, ' \n ');
    }
+    
+    // Fallback to fourTetragrams if somehow an invalid mode is provided
+    return addNewlinesToAddress(formatAddress(address), fourTetragramsOfAddress, ' \n');
};

161-173: New matcher for validating transaction summary display

This matcher handles the validation of transaction summaries, including total amount and fee information. The expected content structure accurately represents the device display format.

The structure of the body array is somewhat complex (array of arrays). Consider adding a comment explaining this structure to aid future maintenance.

    async toDisplaySummary(devicePrompt: DevicePrompt, totalAmount: string, feeAmount: string) {
+        // Body is represented as an array of text segments, where each segment is an array
+        // This matches the display's internal representation of content
        const expectedContent = {
            header: { title: 'Summary' },
            body: [['Total amount'], [totalAmount], [' '], ['incl. Transaction fee'], [feeAmount]],
            footer: 'Swipe up',
        };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 04cc60b and 43eca0c.

📒 Files selected for processing (13)
  • packages/suite-desktop-core/e2e/support/pageObjects/devicePrompt.ts (1 hunks)
  • packages/suite-desktop-core/e2e/support/pageObjects/tradingPage.ts (2 hunks)
  • packages/suite-desktop-core/e2e/support/testExtends/customMatchers.ts (5 hunks)
  • packages/suite-desktop-core/e2e/tests/passphrase/passphrase-cardano.test.ts (2 hunks)
  • packages/suite-desktop-core/e2e/tests/passphrase/passphrase-reconnection.test.ts (3 hunks)
  • packages/suite-desktop-core/e2e/tests/passphrase/passphrase.test.ts (5 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/buy-bitcoin.test.ts (2 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/buy-solana-token.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)
  • packages/suite-desktop-core/e2e/tests/wallet/cardano.test.ts (3 hunks)
🧰 Additional context used
🧠 Learnings (2)
packages/suite-desktop-core/e2e/tests/trading/swap-coin-to-token.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 (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.
⏰ 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: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: build-web
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: Analyze with CodeQL (javascript)
🔇 Additional comments (36)
packages/suite-desktop-core/e2e/tests/trading/swap-coin-to-token.test.ts (1)

61-61: Simplified address handling improves test clarity

The change removes the formatAddress call, passing the raw receiveAddress directly to confirmTrade. This aligns with the PR objective of introducing a custom matcher for address validation, moving the formatting logic out of individual test cases.

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

60-60: Streamlined address handling consistent with PR goals

The change removes the intermediate formattedReceiveAddress variable, passing the raw receiveAddress directly to confirmTrade. This is consistent with the changes in other trading tests, centralizing the address formatting logic.


74-74: Verification step is already using the raw address

Good to see the test was already verifying against the raw receiveAddress rather than the formatted version, which makes this refactoring cleaner and more consistent.

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

57-57: Address handling refactored for consistency

The change removes the formatAddress call, passing the raw receiveAddress directly to confirmTrade. This is consistent with the changes in other trading tests and supports the new address validation approach.

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

69-69: Simplified address handling improves test maintenance

The change removes the formatAddress call, passing the raw receiveAddress directly to confirmTrade. This is consistent with the changes in other trading tests and centralizes address formatting logic.


74-74: Verification already uses raw address - good consistency

The test already verifies against the raw receiveAddress, making the refactoring of the confirmTrade call more consistent with existing verification logic.

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

68-68: Address formatting simplified

The formatAddress function call has been removed, and the raw receiveAddress is now passed directly to the confirmTrade method. This simplifies the code and aligns with the PR's objective of improving address verification.


82-82: Address formatting simplified

Similar to the previous instance, the raw receiveAddress is now passed directly to the confirmTrade method without formatting.

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

60-60: Address formatting simplified

The formatAddress function call has been removed, and the raw receiveAddress is now passed directly to the confirmTrade method, consistent with the changes in other trading test files.

packages/suite-desktop-core/e2e/tests/passphrase/passphrase-reconnection.test.ts (3)

1-1: Added formatAddress import

Added import for the formatAddress function which is now used for address formatting throughout the test.


41-43: Enhanced address verification

The address verification has been improved with:

  1. Using formatAddress to format the address consistently
  2. Explicitly checking that the device prompt is shown
  3. Using the new custom matcher toDisplayReceiveAddress to verify the address display on the emulator

This aligns with the PR objective of enhancing address verification on the emulator.


70-72: Enhanced address verification

Similar to the previous instance, the address verification has been improved with the same pattern of formatting, confirmation prompt checking, and using the new custom matcher.

packages/suite-desktop-core/e2e/tests/wallet/cardano.test.ts (3)

2-2: Added formatAddress import

Added import for the formatAddress function used for address formatting in the test.


5-6: Simplified variable declaration

Replaced formattedReceiveAddress with receiveAddress using the raw Cardano address, which is more consistent with the approach in other tests.


57-63: Enhanced Cardano address verification

The verification process for Cardano addresses has been significantly improved:

  1. Using devicePrompt.confirmOnDevicePromptIsShown() to verify the prompt is displayed
  2. Using the new custom matcher toDisplayReceiveAddress with 'fullLine' transform mode for Cardano addresses
  3. Adding explicit user confirmation with trezorUserEnvLink.pressYes()
  4. Using formatAddress for consistent address formatting

These changes enhance the test robustness by verifying both the UI display and the emulator display of the address.

packages/suite-desktop-core/e2e/tests/passphrase/passphrase-cardano.test.ts (4)

1-1: Good addition of formatAddress import

Importing the formatAddress utility function is a good replacement for the removed splitStringEveryNCharacters import, providing a more standardized way to format addresses for display and verification.


4-5: Updated address string looks good

The updated Cardano address is longer and more realistic, which should improve test robustness for address display verification.


59-61: Improved address verification approach

Replacing toContainText with toHaveText and using the standardized formatAddress function improves consistency and readability in address verification.


63-65: Great addition of emulator display verification

This new assertion directly verifies that the address is correctly displayed on the device emulator, which aligns perfectly with the PR objective of enhancing e2e testing to check receive addresses on the emulator.

packages/suite-desktop-core/e2e/support/pageObjects/devicePrompt.ts (2)

90-96: Useful debugging method for display JSON

This helper method provides a convenient way to quickly access and debug the JSON content from the device display during test development, which will help troubleshoot issues with display assertions.


98-123: Well-structured display content extraction implementation

The implementation nicely handles:

  1. Retrieving the debug state from the device
  2. Parsing and validating the JSON structure
  3. Throwing descriptive errors for invalid content
  4. Extracting and organizing the relevant display sections

This method forms the foundation for the new display verification assertions and includes helpful comments about future extensibility.

packages/suite-desktop-core/e2e/tests/passphrase/passphrase.test.ts (5)

3-3: Good adoption of formatAddress utility

Using the standardized formatAddress utility instead of splitStringEveryNCharacters improves consistency across tests.


26-26: Good addition of devicePrompt parameter

Adding the devicePrompt parameter to the test context allows for verification of address display on the emulator.


46-48: Improved address verification with emulator display check

The test now properly verifies that:

  1. The UI shows the correctly formatted address
  2. The device prompt is displayed
  3. The device displays the expected receive address

This multi-layered verification approach improves test reliability.


73-75: Consistent verification pattern for second address

Applying the same verification pattern to the second address check maintains consistency throughout the test.


93-95: Consistent verification pattern for third address

The verification pattern is consistently applied to the third address check as well, demonstrating good test design.

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

8-8: Good import of formatAddress utility

Adding formatAddress to the imports ensures consistent address formatting across different components of the application.


369-369: Improved verification flow in confirmTrade method

Adding the device prompt confirmation check before other assertions ensures proper sequencing of verification steps.


371-374: Enhanced address verification in trading flow

The updated implementation:

  1. Verifies the UI shows the correctly formatted address using formatAddress
  2. Adds verification that the device properly displays the receive address

This brings trading flow address verification in line with the enhanced testing approach used in other tests.

packages/suite-desktop-core/e2e/support/testExtends/customMatchers.ts (7)

3-3: Import from lodash for deep comparison

The import of isEqual from lodash is appropriate for performing deep comparisons between complex objects in the new matcher functions.


5-6: Good addition of imports from internal modules

These imports are needed for the new matchers and helper functions. The formatAddress function is reused from common utilities, promoting code reuse.


8-8: Clear type definition for transformation modes

The TransformMods type clearly defines the two supported address transformation modes that are used throughout the code.


43-48: Utility function for address formatting with newlines

This helper function correctly handles the address formatting by adding newlines according to the provided regex pattern. The implementation is concise and focused.


127-144: New matcher for validating receive address display

This matcher cleanly implements the functionality described in the PR objectives for verifying the display of receive addresses on the emulator. The function handles address transformation properly and creates the expected structure for comparison.


146-159: New matcher for validating recipient address display

Similar to the receive address matcher but with appropriate adjustments for the recipient address display structure. The code reuses the existing transformation logic, maintaining consistency.


30-173: Consider adding tests for the new matcher functions

The PR adds several new matchers and utility functions that are critical for validating device displays. While these are part of the testing framework themselves, consider adding unit tests specifically for these functions to ensure they transform addresses and compare content correctly in all edge cases.

For example, test cases could verify:

  1. Address transformation with different formats and lengths
  2. Content comparison with varying structures
  3. Error messages when comparisons fail

This would help ensure the reliability of these matchers when used in actual test scenarios.

Comment on lines +146 to +185
async toDisplayRecipientAddress(devicePrompt: DevicePrompt, expectedAddress: string) {
const transformedExpectedAddress = transformAddress(expectedAddress);
const expectedContent = {
header: { title: 'Address', subtitle: 'Recipient #1' },
body: [transformedExpectedAddress],
footer: 'Swipe up',
};

return await compareDisplayContent(
devicePrompt,
expectedContent,
'expect Recipient address to match',
);
},

async toDisplaySummary(devicePrompt: DevicePrompt, totalAmount: string, feeAmount: string) {
const expectedContent = {
header: { title: 'Summary' },
body: [['Total amount'], [totalAmount], [' '], ['incl. Transaction fee'], [feeAmount]],
footer: 'Swipe up',
};

return await compareDisplayContent(
devicePrompt,
expectedContent,
'expect Summary to match',
);
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These two matchers are not used yet.

Comment on lines -69 to +68
await tradingPage.confirmTrade('Bitcoin #1', formatAddress(receiveAddress));
await tradingPage.confirmTrade('Bitcoin #1', receiveAddress);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to unify in what form address is expected in toDisplayReceiveAddress parameter. It is just a address string without any formating.

Comment on lines -4 to +6
const formattedReceiveAddress =
'addr _tes t1qp hsv6 vspp 4l3n vmqz w529 teq2 ha08 s0fg jvzg hzh6 28uc cfey 0wtr gp5r mxvl d7kh c745 x9mk 7gts 5ctu zerl f4ed rq5a t0x5';
const receiveAddress =
'addr_test1qphsv6vspp4l3nvmqzw529teq2ha08s0fgjvzghzh628uccfey0wtrgp5rmxvld7khc745x9mk7gts5ctuzerlf4edrq5at0x5';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The toDisplayReceiveAddress expected address without any formating or newlines

Comment on lines 370 to 375
if (addressToCheck) {
await expect(this.devicePrompt.outputValueOf('address')).toHaveText(addressToCheck);
await expect(this.devicePrompt.outputValueOf('address')).toHaveText(
formatAddress(addressToCheck),
);
await expect(this.devicePrompt).toDisplayReceiveAddress(addressToCheck);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

await expect(this.devicePrompt).toDisplayReceiveAddress(addressToCheck); expects address parameter without any formating. So I have modified this method.

@Vere-Grey Vere-Grey force-pushed the feat/suite-desktop-core/e2e-check-receieve-addr-on-emulator branch from c9bf981 to 454750d Compare March 11, 2025 07:18
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 (6)
packages/suite-desktop-core/e2e/tests/passphrase/passphrase-reconnection.test.ts (2)

41-43: Use explicit transform mode for clarity
The default transform mode is 'fourTetragrams'. If your address is expected to appear in a specific layout, consider specifying 'fullLine' for consistency.


70-72: Extract repeated address checks
These lines duplicate the verification pattern used above. Consider creating a helper function for maintainability and to limit future drift between identical checks.

packages/suite-desktop-core/e2e/tests/wallet/cardano.test.ts (1)

5-6: Encourage centralized test data
This explicit address constant is fine, but if it's reused elsewhere, consider moving it into a shared constants file to reduce duplication.

packages/suite-desktop-core/e2e/support/pageObjects/devicePrompt.ts (1)

90-96: Avoid using errors for debugging
debugJSONFromDisplay() ends the test by throwing an error. If you want to inspect the output but keep the test running, consider console logging instead.

packages/suite-desktop-core/e2e/support/testExtends/customMatchers.ts (2)

8-8: Potential extension
TransformMods currently supports 'fourTetragrams' | 'fullLine'. If more display modes arise, consider expanding this to avoid conditionals scattered throughout the code.


147-151: Expand transform options for recipient
toDisplayRecipientAddress() defaults to 'fourTetragrams'. If you need 'fullLine' or future formats, consider adding a transform parameter as well.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c9bf981 and 454750d.

📒 Files selected for processing (16)
  • packages/suite-desktop-core/e2e/support/pageObjects/devicePrompt.ts (1 hunks)
  • packages/suite-desktop-core/e2e/support/pageObjects/tradingPage.ts (1 hunks)
  • packages/suite-desktop-core/e2e/support/testExtends/customMatchers.ts (5 hunks)
  • packages/suite-desktop-core/e2e/support/pageObjects/devicePrompt.ts (2 hunks)
  • packages/suite-desktop-core/e2e/support/pageObjects/tradingPage.ts (2 hunks)
  • packages/suite-desktop-core/e2e/support/testExtends/customMatchers.ts (4 hunks)
  • packages/suite-desktop-core/e2e/tests/passphrase/passphrase-cardano.test.ts (2 hunks)
  • packages/suite-desktop-core/e2e/tests/passphrase/passphrase-reconnection.test.ts (3 hunks)
  • packages/suite-desktop-core/e2e/tests/passphrase/passphrase.test.ts (5 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/buy-bitcoin.test.ts (2 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/buy-solana-token.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)
  • packages/suite-desktop-core/e2e/tests/wallet/cardano.test.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (11)
  • packages/suite-desktop-core/e2e/tests/trading/swap-coin-to-token.test.ts
  • packages/suite-desktop-core/e2e/tests/trading/swap-token-to-coin.test.ts
  • packages/suite-desktop-core/e2e/tests/trading/buy-bitcoin.test.ts
  • packages/suite-desktop-core/e2e/tests/trading/swap-tokens.test.ts
  • packages/suite-desktop-core/e2e/support/pageObjects/tradingPage.ts
  • packages/suite-desktop-core/e2e/support/pageObjects/devicePrompt.ts
  • packages/suite-desktop-core/e2e/tests/passphrase/passphrase-cardano.test.ts
  • packages/suite-desktop-core/e2e/tests/passphrase/passphrase.test.ts
  • packages/suite-desktop-core/e2e/tests/trading/swap-coins.test.ts
  • packages/suite-desktop-core/e2e/support/pageObjects/tradingPage.ts
  • packages/suite-desktop-core/e2e/tests/trading/buy-solana-token.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: build-web
  • GitHub Check: Analyze with CodeQL (javascript)
🔇 Additional comments (9)
packages/suite-desktop-core/e2e/tests/wallet/cardano.test.ts (4)

24-24: No concerns
This line looks good as-is.


57-59: Informative transform mode
Specifying 'fullLine' clarifies the expected device layout. This is a good example of explicit test behavior.


61-62: Check whitespace consistency
formatAddress(receiveAddress) might not align perfectly with 'fullLine' in some edge cases. Verify that the displayed spacing remains correct.

Would you like me to generate a script to compare both outputs and confirm no unintended whitespace differences?


2-2:

✅ Verification successful

Validate cross-file usage
Ensure formatAddress yields an address string that's compatible with your device prompt checks. If you rely on 'fullLine' mode in other tests, verify there's no mismatch.


🏁 Script executed:

#!/bin/bash
# Search for occurrences of formatAddress usage
rg -A 2 "formatAddress"

Length of output: 13656


Confirmed Cross-File Consistency for formatAddress
The usage of formatAddress in packages/suite-desktop-core/e2e/tests/wallet/cardano.test.ts is consistent with its use in other test files. Its output, which enriches the address string by splitting into 4-character segments, aligns with the expected formatting for device prompt validations. There’s no indication of a mismatch with any "'fullLine' mode" requirements. Please continue to monitor related tests, ensuring that if any tests demand an uninterrupted address line, corresponding adjustments are made.

packages/suite-desktop-core/e2e/support/pageObjects/devicePrompt.ts (1)

98-118: Validate single-paragraph assumption
getDisplayContent() throws if more than one paragraph is present. Ensure no future scenarios require multiple paragraphs.

packages/suite-desktop-core/e2e/support/testExtends/customMatchers.ts (4)

5-5: Confirm usage of formatAddress
Because transformAddress may already call formatAddress, double-check that the extra import here does not introduce duplicate or conflicting logic.


43-48: Regex-based edge cases
addNewlinesToAddress might behave unexpectedly if the address includes unusual spacing or partial chunk sizes. Make sure these cases are tested.


49-70: Ensure consistent formatting
For 'fourTetragrams', you call formatAddress. For 'fullLine', you rely on the raw string. Verify that this discrepancy is intentional and doesn't introduce conflicting output.


127-131: Flexible transform mode
Accepting transformMode here provides useful versatility for verifying different display layouts.

@Vere-Grey Vere-Grey force-pushed the feat/suite-desktop-core/e2e-check-receieve-addr-on-emulator branch from 454750d to 441672f Compare March 12, 2025 09:41
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: 1

🧹 Nitpick comments (5)
packages/suite-desktop-core/e2e/tests/passphrase/passphrase-reconnection.test.ts (2)

41-43: Consider consolidating repeated test steps into a helper.
Lines 41-43 seem nearly identical to lines 70-72. A dedicated helper function (e.g., verifyAddressPrompt(abcAddr)) could reduce duplication and improve maintainability.


70-72: Repeated logic for address validation.
This block repeats the same three-step sequence as lines 41-43. Refactoring into a shared utility or helper would simplify future updates and testing.

packages/suite-desktop-core/e2e/support/pageObjects/devicePrompt.ts (2)

90-96: Handle potential parse errors in the debug method.
If debugState.tokens are not valid JSON, this will crash abruptly. Consider wrapping JSON.parse in a try/catch or validating the input to avoid uncaught parse errors.


98-123: Use typed structures or robust checks for JSON structure.
Accessing json.content.content.paragraphs can break if the structure changes. Defining a clear interface or adding fallback checks would improve maintainability.

packages/suite-desktop-core/e2e/tests/wallet/cardano.test.ts (1)

24-24: Remove or clarify commented-out lines if no longer needed.
Leaving stale comments can cause confusion. Consider deleting or explaining the reason for keeping them commented out.

Also applies to: 27-27, 31-31

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 454750d and 441672f.

📒 Files selected for processing (13)
  • packages/suite-desktop-core/e2e/support/pageObjects/devicePrompt.ts (1 hunks)
  • packages/suite-desktop-core/e2e/support/pageObjects/tradingPage.ts (2 hunks)
  • packages/suite-desktop-core/e2e/support/testExtends/customMatchers.ts (5 hunks)
  • packages/suite-desktop-core/e2e/tests/passphrase/passphrase-cardano.test.ts (2 hunks)
  • packages/suite-desktop-core/e2e/tests/passphrase/passphrase-reconnection.test.ts (3 hunks)
  • packages/suite-desktop-core/e2e/tests/passphrase/passphrase.test.ts (5 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/buy-bitcoin.test.ts (2 hunks)
  • packages/suite-desktop-core/e2e/tests/trading/buy-solana-token.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)
  • packages/suite-desktop-core/e2e/tests/wallet/cardano.test.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (9)
  • packages/suite-desktop-core/e2e/tests/trading/swap-tokens.test.ts
  • packages/suite-desktop-core/e2e/tests/trading/swap-token-to-coin.test.ts
  • packages/suite-desktop-core/e2e/tests/trading/buy-bitcoin.test.ts
  • packages/suite-desktop-core/e2e/tests/trading/buy-solana-token.test.ts
  • packages/suite-desktop-core/e2e/tests/trading/swap-coin-to-token.test.ts
  • packages/suite-desktop-core/e2e/tests/passphrase/passphrase-cardano.test.ts
  • packages/suite-desktop-core/e2e/tests/trading/swap-coins.test.ts
  • packages/suite-desktop-core/e2e/tests/passphrase/passphrase.test.ts
  • packages/suite-desktop-core/e2e/support/pageObjects/tradingPage.ts
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: build-web
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: Setup and Cache Dependencies
🔇 Additional comments (12)
packages/suite-desktop-core/e2e/tests/wallet/cardano.test.ts (4)

2-2: No issues with the new import.
The import of formatAddress aligns with the test’s formatting requirements.


5-6: Initialization of the receive address looks good.
Defining a straightforward constant for the test ensures clarity for Cardano address verification.


57-62: Clear step sequence for verifying 'Legacy Testnet' address.
Displaying the prompt, checking with toDisplayReceiveAddress, and pressing 'Yes' is logically consistent. No issues.


64-65: Follow-up address confirmation appears consistent.
Verifying the output value and re-checking the prompt is a good approach to ensure the correct address is still displayed.

packages/suite-desktop-core/e2e/support/testExtends/customMatchers.ts (8)

3-3: “lodash/isEqual” import is appropriate.
Deep equality checks are beneficial for comparing structured test objects.


5-6: Import of additional utilities from common and DevicePrompt recognized.
These imports support new matchers and align with the broader test framework updates.


8-8: Definition of “LineFormats” is clear.
Using a union type for address formatting modes is straightforward and expressive.


30-42: compareDisplayContent function logically compares expected vs. actual.
Uses devicePrompt.getDisplayContent and isEqual; the diff in error messages is helpful for debugging.


43-48: addNewlinesToAddress function is concise.
Trimming and splitting by regex is an efficient approach for device-side text formatting checks.


127-156: toDisplayReceiveAddress matches the new device JSON structure.
Headers, body, and footers are well-handled with fallback to 'Swipe up' or 'Tap to continue' for different contexts.


158-171: toDisplayRecipientAddress ensures clarity for multi-recipient flows.
Subtitle “Recipient #1” is explicit. The approach is coherent with the reusability of address formatting logic.


173-185: toDisplaySummary thoroughly checks total amount and fee.
This matcher enforces a consistent summary layout, improving test reliability.

Comment on lines +49 to +70
const transformAddress = (address: string, lineFormat: LineFormats = 'fourTetragrams') => {
// Address is split to lines on Display so it can fit. There are different formats:
// 1. Four tetragrams of address:
// bc1q pyfv fvm5 2zx7
// gek8 6ajj 5pkk ne3h
// 385a da8r 2y
// 1. Full lines (18 chars) of address:
// bc1qpyfvfvm52zx7ge
// k86ajj5pkkne3h385a
// da8r2y
// We want to evaluate format and existence of newlines in the address.
const fourTetragramsOfAddress = /(\S+\s\S+\s\S+\s\S+)/g; //4 x 4 characters
const fullLineOfAddress = /.{18}/g; //18 characters

if (lineFormat === 'fourTetragrams') {
return addNewlinesToAddress(formatAddress(address), fourTetragramsOfAddress, ' \n');
}

if (lineFormat === 'fullLine') {
return addNewlinesToAddress(address, fullLineOfAddress, ' \n ');
}
};
Copy link

@coderabbitai coderabbitai bot Mar 12, 2025

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify omission of formatAddress in 'fullLine'.
“fourTetragrams” utilizes formatAddress, but “fullLine” does not. If that is intentional, all good. Otherwise, confirm consistency or consider unifying.


🏁 Script executed:

#!/bin/bash
# Verify usage of “fullLine” vs. “fourTetragrams” across the codebase to ensure consistency and no overlooked calls
rg 'lineFormat: .fullLine' -A 5
rg 'lineFormat: .fourTetragrams' -A 5

Length of output: 2099


Inconsistency in Address Formatting for "fullLine" vs. "fourTetragrams"

It appears that in the transformAddress function (file: packages/suite-desktop-core/e2e/support/testExtends/customMatchers.ts), the "fourTetragrams" branch applies formatAddress(address) before adding newlines, whereas the "fullLine" branch does not call formatAddress. However, tests (e.g., in packages/suite-desktop-core/e2e/tests/wallet/cardano.test.ts and packages/suite-desktop-core/e2e/tests/passphrase/passphrase-cardano.test.ts) expect the output to match formatAddress(receiveAddress) when lineFormat is set to "fullLine".

  • Issue: "fullLine" currently omits formatAddress, leading to an inconsistency with the "fourTetragrams" branch.
  • Action Required: Confirm whether this omission is intentional. If not, consider applying formatAddress in the "fullLine" branch (or update the tests as needed) to ensure that both formatting modes behave consistently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is intentional. formatAddress() transform address to tetragrams

Copy link

Choose a reason for hiding this comment

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

@Vere-Grey Thanks for the clarification! I understand now - formatAddress() is specifically for transforming addresses into tetragrams, which is needed only for the 'fourTetragrams' format. For the 'fullLine' format, you're deliberately using the raw address since it's meant to display full lines without tetragram formatting.

This design approach makes perfect sense for handling the different display modes on the emulator.


✏️ Learnings added
Learnt from: Vere-Grey
PR: trezor/trezor-suite#17500
File: packages/suite-desktop-core/e2e/support/testExtends/customMatchers.ts:49-70
Timestamp: 2025-03-12T10:05:27.207Z
Learning: In the `transformAddress` function used for e2e testing in Trezor Suite, `formatAddress()` is intentionally applied only to the 'fourTetragrams' format (which displays addresses in groups of 4 characters), and not to the 'fullLine' format (which displays addresses in lines of up to 18 characters without tetragram grouping).

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Comment on lines +27 to +31
// await settingsPage.coins.openNetworkAdvanceSettings('tada');
// await expect(settingsPage.modal).toHaveScreenshot('cardano-advanced-settings.png', {
// mask: [settingsPage.coins.coinAddressInput],
// });
await settingsPage.modalCloseButton.click();
// await settingsPage.modalCloseButton.click();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These steps were here just for the toHaveScreenshot

Comment on lines +137 to +148
if (options.specialAccountType) {
expectedContent = {
header: { title: 'Receive address' },
body: [[options.specialAccountType], transformedExpectedAddress],
footer: 'Tap to continue',
};
} else {
expectedContent = {
header: { title: 'Receive address' },
body: [transformedExpectedAddress],
footer: 'Swipe up',
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know if there will be more special ways of displaying the information.
Maybe it is now worth to validate the address on test net and complicate this method?
We have other cardano test on normal net with this validation 🤔

@Vere-Grey Vere-Grey merged commit b79c1ea into develop Mar 12, 2025
28 checks passed
@Vere-Grey Vere-Grey deleted the feat/suite-desktop-core/e2e-check-receieve-addr-on-emulator branch March 12, 2025 11:33
@martykan
Copy link
Member

Seeing a bunch of issues like this
Screenshot 2025-03-12 at 15 03 42

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.

3 participants