-
Notifications
You must be signed in to change notification settings - Fork 149
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: mock mainnet btc blockstream requests #5642
Conversation
WalkthroughRecent updates mainly focus on enhancing asynchronous operations, refining mock data setups, and using constants for API base URLs in tests. Key changes include introducing concurrency in Changes
Sequence DiagramssequenceDiagram
participant Test as Test
participant MockAPIs as Mock APIs
participant MockUTXOs as Mock UTXOs
participant Blockstream as Blockstream API
Test ->> MockAPIs: setupMockApis()
MockAPIs ->> MockUTXOs: mockMainnetTestAccountBlockstreamRequests(page)
MockUTXOs ->> Blockstream: GET /api/address/**/txs
Blockstream -->> MockUTXOs: Return empty JSON array
MockUTXOs -->> MockAPIs: Mock responses configured
MockAPIs -->> Test: setup complete
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
tests/mocks/mock-apis.ts
Outdated
|
||
export async function setupMockApis(page: Page) { | ||
await page.route(/chrome-extension/, route => route.continue()); | ||
await page.route(/github/, route => route.fulfill(json({}))); | ||
await page.route('https://api.hiro.so/', route => route.fulfill()); | ||
await page.route('https://api.testnet.hiro.so/', route => route.fulfill()); | ||
await mockStacksFeeRequests(page); | ||
await Promise.all([mockMainnetTestAccountBlockstreamRequests(page), mockStacksFeeRequests(page)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the Promise.all
really needed here, given it's just for the definition of the mock? You could equally await the 5 lines above too, but haven't seen this done in docs
When I mocked just there it also didn't fix the test, I actually had to put it directly in |
b963ac1
to
414e4b8
Compare
There was a problem hiding this 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
Files selected for processing (3)
- tests/mocks/mock-apis.ts (1 hunks)
- tests/mocks/mock-utxos.ts (2 hunks)
- tests/specs/send/send-btc.spec.ts (3 hunks)
Additional context used
Gitleaks
tests/mocks/mock-utxos.ts
53-53: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
57-57: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
72-72: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
75-75: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
90-90: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
93-93: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
97-97: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
100-100: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
Additional comments not posted (8)
tests/mocks/mock-apis.ts (2)
5-5
: Approved: New import formockMainnetTestAccountBlockstreamRequests
.The new import aligns with the added functionality for mocking mainnet BTC requests.
8-15
: Efficient use ofPromise.all
, but reconsider necessity.The use of
Promise.all
is efficient for concurrent execution of asynchronous operations. However, reconsider if it's necessary given the context of defining mocks.tests/mocks/mock-utxos.ts (3)
1-3
: Approved: New imports forPage
andTEST_ACCOUNT_1_NATIVE_SEGWIT_ADDRESS
.The new imports are necessary for the added functionality.
43-114
: Approved: New arraymockMainnetNsTransactionsTestAccount
.The array structure is well-defined and includes detailed transaction data necessary for mocking responses.
Tools
Gitleaks
53-53: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
57-57: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
72-72: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
75-75: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
90-90: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
93-93: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
97-97: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
100-100: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
116-131
: Approved: New async functionmockMainnetTestAccountBlockstreamRequests
.The function correctly sets up request routes and uses
Promise.all
for concurrent execution of asynchronous operations.tests/specs/send/send-btc.spec.ts (3)
7-7
: Approved: Updated import statement to includeBESTINSLOT_API_BASE_URL_TESTNET
.The updated import statement is correct and aligns with the usage of the new constant.
130-130
: Approved: Replaced hardcoded API base URL withBESTINSLOT_API_BASE_URL_TESTNET
.The replacement improves maintainability by using a constant instead of hardcoded values.
143-143
: Approved: Replaced hardcoded API base URL withBESTINSLOT_API_BASE_URL_TESTNET
.The replacement improves maintainability by using a constant instead of hardcoded values.
There was a problem hiding this 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, codebase verification and nitpick comments (1)
tests/mocks/mock-apis.ts (1)
8-15
: Asynchronous handling is acceptable, but consider simplifying.Using
Promise.all
is efficient for handling multiple asynchronous operations concurrently. However, if the operations are not interdependent, you might consider awaiting them sequentially for better readability.- await Promise.all([ - page.route(/chrome-extension/, route => route.continue()), - page.route(/github/, route => route.fulfill(json({}))), - page.route('https://api.hiro.so/', route => route.fulfill()), - page.route('https://api.testnet.hiro.so/', route => route.fulfill()), - mockMainnetTestAccountBlockstreamRequests(page), - mockStacksFeeRequests(page), - ]); + await page.route(/chrome-extension/, route => route.continue()); + await page.route(/github/, route => route.fulfill(json({}))); + await page.route('https://api.hiro.so/', route => route.fulfill()); + await page.route('https://api.testnet.hiro.so/', route => route.fulfill()); + await mockMainnetTestAccountBlockstreamRequests(page); + await mockStacksFeeRequests(page);
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- tests/mocks/mock-apis.ts (1 hunks)
- tests/mocks/mock-utxos.ts (2 hunks)
- tests/specs/onboarding/onboarding.spec.ts (1 hunks)
- tests/specs/send/send-btc.spec.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/specs/send/send-btc.spec.ts
Additional context used
Gitleaks
tests/mocks/mock-utxos.ts
53-53: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
57-57: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
72-72: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
75-75: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
90-90: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
93-93: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
97-97: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
100-100: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
Additional comments not posted (6)
tests/mocks/mock-apis.ts (1)
5-5
: Import is appropriate.The new import for
mockMainnetTestAccountBlockstreamRequests
is correctly added.tests/specs/onboarding/onboarding.spec.ts (2)
64-64
: Function signature update is acceptable.Adding the
page
parameter to the function signature ensures that the new route can be set up correctly.
67-71
: Correctly setting up the new route.The route for
blockstream.info/api/address/**/txs
is correctly set up to fulfill with an empty JSON array. This will mock the response as intended.tests/mocks/mock-utxos.ts (3)
1-3
: Imports are appropriate.The new imports for
Page
andTEST_ACCOUNT_1_NATIVE_SEGWIT_ADDRESS
are correctly added.
43-114
: Mock transactions array is well-defined.The
mockMainnetNsTransactionsTestAccount
array is correctly defined with detailed transaction data. However, ensure that no sensitive data is included.Tools
Gitleaks
53-53: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
57-57: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
72-72: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
75-75: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
90-90: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
93-93: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
97-97: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
100-100: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
116-130
: Function to handle BTC Blockstream requests is correctly implemented.The
mockMainnetTestAccountBlockstreamRequests
function correctly sets up routes to mock responses for BTC Blockstream requests. UsingPromise.all
here is efficient.
This pr mocks btc blockstream mainnet requests
Summary by CodeRabbit
New Features
Bug Fixes
Tests