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

fix: add ledger test for bitcoin api calls #5581

Merged
merged 1 commit into from
Jun 28, 2024

Conversation

fbwoolf
Copy link
Contributor

@fbwoolf fbwoolf commented Jun 27, 2024

Did a bunch of research and testing to understand how to write a test to see if we are making any bitcoin api calls on the homepage if only Stacks keys are present. The test here checks a bug where the requests were being made when a user clicked to change accounts. I tried quite a few things attempting to catch the timeout exception correctly if no requests are made, and I ended up coming across this that helped me: microsoft/playwright#20372 (comment)

Hoping this is right. I made sure the test failed withBitcoinKeysOnly and withStacksAndBitcoinKeys, but that it passes withStacksKeysOnly ...so I think it is working correctly.

While working on this, I realized there was a bug with useInfiniteQuery which was causing the linked bug where queries were running even though we were disabling them with !!address, see:
https://stackoverflow.com/questions/72753877/useinfinitequerys-enabled-option-in-react-query-doesnt-work

And, fixed/installed here from mono repo: leather-io/mono#246

Summary by CodeRabbit

  • Chores

    • Updated @leather.io/query dependency to version 0.9.3.
  • Tests

    • Enhanced tests to improve handling of bitcoin requests.

Copy link

coderabbitai bot commented Jun 27, 2024

Walkthrough

The recent update involves incrementing the version of the @leather.io/query dependency from 0.9.2 to 0.9.3 in the package.json file. Additionally, in the ledger.spec.ts test file, there's been an importation of types for HomePage, the introduction of the interceptBitcoinRequests function, and alterations to a bitcoin request handling test case.

Changes

File Change Summary
package.json Updated the version of @leather.io/query dependency from 0.9.2 to 0.9.3.
tests/specs/ledger/ledger.spec.ts Added type imports for HomePage, a new interceptBitcoinRequests function, and modified a test case.

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

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.

@fbwoolf fbwoolf linked an issue Jun 27, 2024 that may be closed by this pull request
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 65131b0 and e35506e.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (2)
  • package.json (1 hunks)
  • tests/specs/ledger/ledger.spec.ts (3 hunks)
Files skipped from review due to trivial changes (1)
  • package.json
Additional comments not posted (3)
tests/specs/ledger/ledger.spec.ts (3)

2-2: Type import for HomePage added.

This import is correctly added as a type import, which ensures it's used for type checking and doesn't result in runtime overhead.


4-4: Import of SettingsSelectors added.

This import is necessary for accessing selectors used in the test cases, ensuring that the tests are robust and maintainable.


14-19: New function interceptBitcoinRequests defined.

The function is well-implemented for intercepting specific API requests. However, consider verifying the appropriateness of the 1000 ms timeout in different network conditions.

Comment on lines +46 to +55
test('there are no bitcoin requests', async ({ homePage }) => {
const requestPromise = interceptBitcoinRequests(homePage);

await homePage.page.getByTestId(SettingsSelectors.CurrentAccountDisplayName).click();

await test
.expect(async () => await test.expect(requestPromise).rejects.toThrowError())
.toPass()
.catch();
});
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Explicit error handling needed in test case.

The test case for ensuring no Bitcoin API calls is correctly structured. However, the catch block is currently empty, which may suppress errors silently. Ensure that errors are handled explicitly to catch and address any potential issues during test execution.

  • File: tests/specs/ledger/ledger.spec.ts
  • Lines: 46-55
Analysis chain

Test case for no Bitcoin API calls.

The test case is correctly structured to ensure that no Bitcoin API calls are made under specific conditions. However, ensure that the catch block is appropriately handling any potential errors that could arise during the test execution.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the error handling in the test case.

# Test: Search for error handling patterns in other tests.
rg --type python $'catch'

Length of output: 55



Script:

#!/bin/bash
# Description: Verify the error handling in the test case.

# Test: Search for error handling patterns in TypeScript tests.
rg --type typescript 'catch'

Length of output: 63



Script:

#!/bin/bash
# Description: Verify the error handling in the test case.

# Test: Search for error handling patterns in TypeScript tests.
rg --type ts 'catch'

Length of output: 6694

@fbwoolf fbwoolf force-pushed the fix/ledger-test-for-bitcoin-api-calls branch from e35506e to 00804b3 Compare June 27, 2024 20:58
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 e35506e and 00804b3.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (2)
  • package.json (1 hunks)
  • tests/specs/ledger/ledger.spec.ts (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • package.json
  • tests/specs/ledger/ledger.spec.ts

Copy link
Collaborator

@kyranjamie kyranjamie left a comment

Choose a reason for hiding this comment

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

Great to see test coverage expanded @fbwoolf

So if bitcoin requests are made, the tests here fail?

Copy link
Contributor

@alter-eggo alter-eggo left a comment

Choose a reason for hiding this comment

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

💪

Copy link
Contributor

@pete-watters pete-watters left a comment

Choose a reason for hiding this comment

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

Cool PR and a good find that we can use to help with other tests in the future also

@kyranjamie
Copy link
Collaborator

Wrong issue referenced btw

image

@fbwoolf
Copy link
Contributor Author

fbwoolf commented Jun 28, 2024

Wrong issue referenced btw

How do I ref issues in the other repo? 🤔 Can't include in commit msg?

@pete-watters
Copy link
Contributor

pete-watters commented Jun 28, 2024

Wrong issue referenced btw

How do I ref issues in the other repo? 🤔 Can't include in commit msg?

You can do it in the commit message using the full path - git commit -a -m "fix: good work Fara, ref leather-io/issues#XXX"

@fbwoolf fbwoolf force-pushed the fix/ledger-test-for-bitcoin-api-calls branch from 00804b3 to cbd52ae Compare June 28, 2024 16:37
@fbwoolf fbwoolf force-pushed the fix/ledger-test-for-bitcoin-api-calls branch from cbd52ae to e18cc9b Compare June 28, 2024 16:38
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 00804b3 and e18cc9b.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (2)
  • package.json (1 hunks)
  • tests/specs/ledger/ledger.spec.ts (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • package.json
  • tests/specs/ledger/ledger.spec.ts

@fbwoolf fbwoolf added this pull request to the merge queue Jun 28, 2024
Merged via the queue into dev with commit 26b6b4f Jun 28, 2024
29 checks passed
@fbwoolf fbwoolf deleted the fix/ledger-test-for-bitcoin-api-calls branch June 28, 2024 17: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.

Add Ledger test for checking bitcoin api calls
4 participants