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

test: bypass sign in step, faster #5423

Merged
merged 1 commit into from
May 23, 2024
Merged

Conversation

kyranjamie
Copy link
Collaborator

@kyranjamie kyranjamie commented May 22, 2024

Try out Leather build cd0dc59Extension build, Test report, Storybook, Chromatic

Testing alternative sign in step for tests, avoiding the password entry operation entirely

Summary by CodeRabbit

  • Refactor
    • Significantly refactored the signInWithTestAccount method in the OnboardingPage class to improve the sign-in process for test accounts, enhancing reliability and performance during onboarding.

Copy link

coderabbitai bot commented May 22, 2024

Walkthrough

The signInWithTestAccount method in the OnboardingPage class has been refactored significantly to improve the sign-in process. Changes include the introduction of a new constant testAccountDerivedKey, enhancements to the isSignedIn function, modifications to the loop condition, and updates to the usage of chrome.storage.

Changes

File Change Summary
tests/page-object-models/onboarding... Refactored signInWithTestAccount method, added testAccountDerivedKey, updated isSignedIn function, modified loop condition, and adjusted chrome.storage usage and page interactions.

In code we trust, with changes bright,
The tests now run, from day to night.
With keys derived and loops refined,
Our pages load, so well-aligned.
Through storage paths, the data flows,
Onboarding smooth, as springtime grows. 🌸


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.

@kyranjamie kyranjamie force-pushed the test/faster-wallet-restore branch 4 times, most recently from 9a43a7f to 3de9da6 Compare May 22, 2024 16:25
@kyranjamie kyranjamie requested review from fbwoolf and alter-eggo May 22, 2024 16:36
@kyranjamie kyranjamie marked this pull request as ready for review May 22, 2024 16:36
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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 281e718 and 7a6b518.
Files selected for processing (1)
  • tests/page-object-models/onboarding.page.ts (2 hunks)
Additional comments not posted (2)
tests/page-object-models/onboarding.page.ts (2)

282-283: Ensure the hardcoded key does not pose a security risk.

#!/bin/bash
# Description: Verify that the hardcoded key is not sensitive or used in production environments.

# Test: Search for the key usage across the codebase. Expect: No occurrences in production code.
rg --type typescript 'd904f412b8d116540017c302f3f7033813c95902af5a067c7befcc34fa5e5290709f157f80548603a1e4f8edc2c0d5d7'

295-307: Verify the loop's logic and ensure it does not lead to infinite loops.

#!/bin/bash
# Description: Verify the loop's logic by checking for potential conditions that could lead to an infinite loop.

# Test: Review the logic manually and ensure there are conditions that will eventually stop the loop.
# Manual review needed.

tests/page-object-models/onboarding.page.ts Outdated Show resolved Hide resolved
@kyranjamie kyranjamie force-pushed the test/faster-wallet-restore branch from 7a6b518 to 5954857 Compare May 22, 2024 16:48
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: 3

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 7a6b518 and 5954857.
Files selected for processing (1)
  • tests/page-object-models/onboarding.page.ts (2 hunks)
Additional comments not posted (2)
tests/page-object-models/onboarding.page.ts (2)

282-283: Secure the testAccountDerivedKey constant.
[SECURITY]

  • The value of testAccountDerivedKey appears to be hardcoded, which could lead to security vulnerabilities if exposed. Consider fetching this key from a secure environment variable or encrypting it before use.

296-305: Review the use of browser storage for sensitive data.
[SECURITY]

  • Storing sensitive information such as wallet states and encryption keys in browser storage (local and session) can be risky. Consider encrypting this data before storage or using more secure storage solutions.

tests/page-object-models/onboarding.page.ts Outdated Show resolved Hide resolved
Comment on lines +285 to +295
const isSignedIn = async () => {
const { encryptionKey } = await this.page.evaluate(async () =>
chrome.storage.session.get(['encryptionKey'])
);
const hasSessionKey = encryptionKey === testAccountDerivedKey;
const hasAssetsTab = this.page.getByText('Assets');
const hasActivityTab = this.page.getByText('Activity');

return hasSessionKey && hasAssetsTab && hasActivityTab;
Copy link

Choose a reason for hiding this comment

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

Improve the robustness of the isSignedIn function.

  • Relying solely on UI elements (like 'Assets' and 'Activity' tabs) for sign-in verification can be fragile and prone to break if the UI changes. Consider adding more concrete checks, such as HTTP response statuses or specific API call successes, to verify the sign-in status.

Comment on lines 296 to 316
do {
await this.page.evaluate(
async walletState => await chrome.storage.local.set({ 'persist:root': walletState }),
async walletState => chrome.storage.local.set({ 'persist:root': walletState }),
testSoftwareAccountDefaultWalletState
);
await this.page.goto(`chrome-extension://${id}/index.html`, {
waitUntil: 'networkidle',
});
}
await test.expect(this.page.getByText('Enter your password')).toBeVisible();
await this.page.getByRole('textbox').fill(TEST_PASSWORD);
await this.page.getByRole('button', { name: 'Continue' }).click();
await this.page.waitForURL('**' + RouteUrls.Home);
await this.page.locator('text="Account 1"').waitFor();

await this.page.evaluate(
async encryptionKey => chrome.storage.session.set({ encryptionKey }),
testAccountDerivedKey
);

await this.page.goto(`chrome-extension://${id}/index.html`, { waitUntil: 'networkidle' });
} while (!(await isSignedIn()));
Copy link

Choose a reason for hiding this comment

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

Prevent potential infinite loops in the sign-in process.

  • The current implementation could potentially lead to an infinite loop if the isSignedIn condition is never satisfied. Consider adding a maximum iteration count or a timeout mechanism to prevent this scenario.

@kyranjamie kyranjamie force-pushed the test/faster-wallet-restore branch from 5954857 to cd0dc59 Compare May 23, 2024 08:12
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: 4

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 5954857 and cd0dc59.
Files selected for processing (1)
  • tests/page-object-models/onboarding.page.ts (2 hunks)

tests/page-object-models/onboarding.page.ts Show resolved Hide resolved
tests/page-object-models/onboarding.page.ts Show resolved Hide resolved
@kyranjamie kyranjamie added this pull request to the merge queue May 23, 2024
Merged via the queue into dev with commit 722d504 May 23, 2024
30 checks passed
@kyranjamie kyranjamie deleted the test/faster-wallet-restore branch May 23, 2024 11:01
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