Skip to content

fix: fixing e2e test for authorizations#2176

Merged
stalniy merged 2 commits intoakash-network:mainfrom
jzsfkzm:bugfixes/authorization-e2e
Dec 1, 2025
Merged

fix: fixing e2e test for authorizations#2176
stalniy merged 2 commits intoakash-network:mainfrom
jzsfkzm:bugfixes/authorization-e2e

Conversation

@jzsfkzm
Copy link
Contributor

@jzsfkzm jzsfkzm commented Nov 8, 2025

@stalniy I changed how authorization e2e works, now it would import a second wallet by mnemonic, and this wallet would be authorizing the test wallet to spend.
Second wallet is represented by AUTHORIZING_WALLET_MNEMONIC in the env vars, I used this mnemonic for testing purposes: useful custom fit trophy hub proud quit grape mutual curtain ceiling foil

However, when I switch to sandbox, authorizing starts not working (thus the whole e2e test is breaking), with Insufficent funds error, despite the fact the wallet is topped up before use. Any ideas why this would happen?

Summary by CodeRabbit

  • Tests
    • Enhanced wallet authorization test coverage for multi-wallet import scenarios
    • Improved wallet setup robustness and test environment configuration

@jzsfkzm jzsfkzm requested a review from a team as a code owner November 8, 2025 15:02
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 8, 2025

Walkthrough

The PR refactors UI test wallet setup infrastructure by removing BrowserContext dependency from wallet helpers, introducing environment-based second wallet import capability via new importSecondWallet function, and updating test fixtures to accommodate the new wallet import flow during authorization testing.

Changes

Cohort / File(s) Summary
Test configuration
apps/deploy-web/tests/ui/fixture/test-env.config.ts
Added AUTHORIZING_WALLET_MNEMONIC environment variable as required string to test schema and propagated it into testEnvConfig
Wallet setup helpers
apps/deploy-web/tests/ui/fixture/wallet-setup.ts
Removed BrowserContext parameter from setupWallet and importWalletToLeap; added importSecondWallet and importSecondWalletToLeap functions for second wallet import; increased timeout in getExtensionPage
Test fixture integration
apps/deploy-web/tests/ui/fixture/context-with-extension.ts
Updated setupWallet call to pass only extPage parameter instead of context, extPage
Authorization spending test
apps/deploy-web/tests/ui/authorize-spending.spec.ts
Imported testEnvConfig and importSecondWallet; refactored setup to obtain extension page explicitly and added second wallet import step using mnemonic from config

Sequence Diagram(s)

sequenceDiagram
    participant Test as authorize-spending.spec.ts
    participant Setup as wallet-setup.ts
    participant Leap as Leap Extension
    
    Test->>Setup: setupWallet(extPage)
    Setup->>Setup: importWalletToLeap(page)
    Setup->>Leap: Import primary wallet
    Leap-->>Setup: wallet imported
    Setup->>Test: ✓ ready
    
    Test->>Setup: importSecondWallet(extPage, mnemonic)
    Setup->>Setup: importSecondWalletToLeap(page, mnemonic)
    Setup->>Leap: Validate & import secondary wallet
    Leap-->>Setup: wallet imported
    Setup->>Setup: Reload page & top up
    Setup->>Test: ✓ second wallet ready
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Function signature changes: setupWallet and importWalletToLeap now require only Page parameter instead of BrowserContext, Page—verify all call sites are updated correctly across test files
  • New wallet import logic: importSecondWallet and importSecondWalletToLeap implementation needs validation for correct mnemonic handling, UI interaction sequence, and wallet state management
  • Environment configuration propagation: Ensure AUTHORIZING_WALLET_MNEMONIC is properly threaded through config and test initialization
  • Extension page timeout adjustment: Verify the increased timeout doesn't negatively impact test performance or mask timing issues

Possibly related PRs

Suggested reviewers

  • stalniy
  • baktun14

Poem

🐰 A second wallet hops into our test,
No context needed, just a page—how blessed!
Environment secrets guide the way,
Leap extensions leap another day! 🌙✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title describes fixing an e2e test for authorizations, which aligns with the main objective of refactoring the authorization test to import a second wallet. However, the title is somewhat generic using 'fixing' and doesn't specify what the actual fix entails (e.g., that it involves importing a second wallet for authorization).
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Nov 8, 2025

Codecov Report

❌ Patch coverage is 0% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.28%. Comparing base (5df2064) to head (c5b6d73).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...b/src/components/authorizations/Authorizations.tsx 0.00% 40 Missing ⚠️
...loy-web/src/components/settings/SettingsLayout.tsx 0.00% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2176      +/-   ##
==========================================
- Coverage   47.61%   47.28%   -0.34%     
==========================================
  Files        1036     1026      -10     
  Lines       29356    29008     -348     
  Branches     7589     7549      -40     
==========================================
- Hits        13978    13716     -262     
+ Misses      14979    14893      -86     
  Partials      399      399              
Flag Coverage Δ *Carryforward flag
api 81.84% <ø> (ø) Carriedforward from 5df2064
deploy-web 26.43% <0.00%> (+<0.01%) ⬆️
log-collector ?
notifications 87.94% <ø> (ø) Carriedforward from 5df2064
provider-console 81.48% <ø> (ø) Carriedforward from 5df2064
provider-proxy 84.35% <ø> (ø) Carriedforward from 5df2064

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...components/authorizations/DeploymentGrantTable.tsx 0.00% <ø> (ø)
...eb/src/components/authorizations/FeeGrantTable.tsx 0.00% <ø> (ø)
...web/src/components/wallet/CustodialWalletPopup.tsx 62.50% <ø> (ø)
...loy-web/src/components/settings/SettingsLayout.tsx 0.00% <0.00%> (ø)
...b/src/components/authorizations/Authorizations.tsx 0.00% <0.00%> (ø)

... and 11 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@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 (1)
apps/deploy-web/tests/ui/fixture/wallet-setup.ts (1)

171-206: Consider adding balance confirmation wait after faucet request.

The topUpWallet function makes a faucet request but doesn't wait for the transaction to be confirmed on-chain. This could cause the "Insufficient funds" error mentioned in the PR description when tests attempt transactions before the funds arrive.

Add a polling mechanism to wait for balance update:

     if (response.status >= 300) {
       console.error(`Unexpected faucet response status: ${response.status}`);
       console.error("Faucet response:", await response.text());
+      return;
     }
+
+    // Wait for balance to update (poll for up to 60 seconds)
+    for (let i = 0; i < 30; i++) {
+      await wait(2000);
+      const newBalance = await getBalance(accounts[0].address);
+      if (newBalance > balance) {
+        console.log(`Wallet topped up successfully. New balance: ${newBalance} uakt`);
+        return;
+      }
+    }
+    console.warn("Faucet request succeeded but balance did not update within 60 seconds");
   } catch (error) {

You'll need to import wait at the top if not already imported:

import { setTimeout as wait } from "timers/promises";
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd46e86 and 0f7ff47.

📒 Files selected for processing (4)
  • apps/deploy-web/tests/ui/authorize-spending.spec.ts (2 hunks)
  • apps/deploy-web/tests/ui/fixture/context-with-extension.ts (1 hunks)
  • apps/deploy-web/tests/ui/fixture/test-env.config.ts (1 hunks)
  • apps/deploy-web/tests/ui/fixture/wallet-setup.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/deploy-web/tests/ui/fixture/context-with-extension.ts
  • apps/deploy-web/tests/ui/fixture/test-env.config.ts
  • apps/deploy-web/tests/ui/fixture/wallet-setup.ts
  • apps/deploy-web/tests/ui/authorize-spending.spec.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/deploy-web/tests/ui/fixture/context-with-extension.ts
  • apps/deploy-web/tests/ui/fixture/test-env.config.ts
  • apps/deploy-web/tests/ui/fixture/wallet-setup.ts
  • apps/deploy-web/tests/ui/authorize-spending.spec.ts
**/*.spec.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/no-jest-mock.mdc)

Don't use jest.mock() to mock dependencies in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test.

**/*.spec.{ts,tsx}: Use setup function instead of beforeEach in test files
setup function must be at the bottom of the root describe block in test files
setup function creates an object under test and returns it
setup function should accept a single parameter with inline type definition
Don't use shared state in setup function
Don't specify return type of setup function

Files:

  • apps/deploy-web/tests/ui/authorize-spending.spec.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: jzsfkzm
Repo: akash-network/console PR: 2039
File: apps/deploy-web/tests/ui/change-wallets.spec.ts:4-10
Timestamp: 2025-10-15T16:39:55.348Z
Learning: In the Akash Console E2E tests using the context-with-extension fixture, the first wallet is automatically created during fixture setup via `importWalletToLeap` in `apps/deploy-web/tests/ui/fixture/wallet-setup.ts`, so tests that call `frontPage.createWallet()` are creating a second wallet to test wallet switching functionality.
📚 Learning: 2025-10-15T16:39:55.348Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 2039
File: apps/deploy-web/tests/ui/change-wallets.spec.ts:4-10
Timestamp: 2025-10-15T16:39:55.348Z
Learning: In the Akash Console E2E tests using the context-with-extension fixture, the first wallet is automatically created during fixture setup via `importWalletToLeap` in `apps/deploy-web/tests/ui/fixture/wallet-setup.ts`, so tests that call `frontPage.createWallet()` are creating a second wallet to test wallet switching functionality.

Applied to files:

  • apps/deploy-web/tests/ui/fixture/context-with-extension.ts
  • apps/deploy-web/tests/ui/fixture/test-env.config.ts
  • apps/deploy-web/tests/ui/fixture/wallet-setup.ts
  • apps/deploy-web/tests/ui/authorize-spending.spec.ts
🧬 Code graph analysis (2)
apps/deploy-web/tests/ui/fixture/context-with-extension.ts (1)
apps/deploy-web/tests/ui/fixture/wallet-setup.ts (1)
  • setupWallet (29-34)
apps/deploy-web/tests/ui/authorize-spending.spec.ts (3)
apps/deploy-web/tests/ui/fixture/wallet-setup.ts (2)
  • getExtensionPage (15-27)
  • importSecondWallet (36-40)
apps/deploy-web/tests/ui/fixture/testing-helpers.ts (1)
  • clickCopyAddressButton (31-39)
apps/deploy-web/tests/ui/fixture/test-env.config.ts (1)
  • testEnvConfig (11-16)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
🔇 Additional comments (7)
apps/deploy-web/tests/ui/fixture/context-with-extension.ts (1)

56-56: LGTM! Signature update aligns with refactored wallet setup.

The updated call correctly matches the new setupWallet(page: Page) signature in wallet-setup.ts.

apps/deploy-web/tests/ui/fixture/wallet-setup.ts (4)

23-23: LGTM! Increased timeout improves reliability.

The timeout increase from 5,000ms to 10,000ms for waiting for the page event provides better resilience for slower test environments.


29-34: LGTM! Simplified signature removes unnecessary parameter.

The refactored setupWallet signature correctly removes the BrowserContext parameter that was not being used, making the API cleaner.


36-40: New second wallet import function looks good, but note timing consideration.

The importSecondWallet function properly encapsulates the second wallet import flow. However, be aware that topUpWallet doesn't wait for on-chain confirmation of the faucet transaction, which may contribute to the "Insufficient funds" error mentioned in the PR description.

See the comment on authorize-spending.spec.ts lines 67-69 for details on the timing issue.


141-169: New helper function is well-implemented with proper validation.

The importSecondWalletToLeap function correctly:

  • Validates the mnemonic is set and has 12 words
  • Navigates the wallet import UI flow
  • Returns a wallet instance for further operations

Note that after this function executes, the Leap extension will have the second wallet as the active wallet. This is intentional for the authorization test flow where the second wallet grants authorization to the first wallet.

apps/deploy-web/tests/ui/authorize-spending.spec.ts (1)

67-69: Potential timing issue: faucet top-up may not complete before authorization.

The flow imports a second wallet and calls topUpWallet, but the topUpWallet function (in wallet-setup.ts) only makes the faucet HTTP request without waiting for on-chain confirmation. The authorization transaction on line 74-75 may execute before the funds arrive, causing the "Insufficient funds" error mentioned in the PR description.

Consider adding a wait/retry mechanism after the faucet request in topUpWallet to ensure funds are available:

// In wallet-setup.ts topUpWallet function, after the faucet request:
// Wait for balance to update (with timeout)
for (let i = 0; i < 30; i++) {
  await wait(2000); // Wait 2 seconds
  const newBalance = await getBalance(accounts[0].address);
  if (newBalance > balance) {
    return; // Funds arrived
  }
}
console.warn("Faucet funds may not have arrived yet");

Alternatively, run a script to verify the current faucet behavior:

#!/bin/bash
# Check faucet endpoint and recent transaction times
curl -s "$(node -e "console.log(require('@akashnetwork/net').netConfig.getFaucetUrl('sandbox'))")" || echo "Faucet URL not accessible"
⛔ Skipped due to learnings
Learnt from: jzsfkzm
Repo: akash-network/console PR: 2039
File: apps/deploy-web/tests/ui/change-wallets.spec.ts:4-10
Timestamp: 2025-10-15T16:39:55.348Z
Learning: In the Akash Console E2E tests using the context-with-extension fixture, the first wallet is automatically created during fixture setup via `importWalletToLeap` in `apps/deploy-web/tests/ui/fixture/wallet-setup.ts`, so tests that call `frontPage.createWallet()` are creating a second wallet to test wallet switching functionality.
Learnt from: stalniy
Repo: akash-network/console PR: 2138
File: apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.ts:379-382
Timestamp: 2025-10-31T11:26:42.138Z
Learning: In TypeScript/JavaScript, the pattern of checking a cached value and then performing an async operation to fetch it without proper synchronization is race condition unsafe:
```typescript
private async getAddress() {
  if (!this.address) {
    this.address = await this.wallet.getFirstAddress();
  }
  return this.address;
}
```
Multiple concurrent calls can all pass the `if (!this.address)` check before any of them sets the value, leading to duplicate async operations. This should be flagged as a race condition. Proper synchronization (mutex, atomic promise caching, or guaranteed single-threaded execution) is required.
apps/deploy-web/tests/ui/fixture/test-env.config.ts (1)

6-6: Make AUTHORIZING_WALLET_MNEMONIC optional since only one test uses it.

The field is only used in authorize-spending.spec.ts (line 69), but defining it as required (z.string()) will fail validation for all test runs that don't set this environment variable. Tests that don't perform authorization won't have this variable available.

Change to one of:

  • z.string().optional() - allow tests without authorization to run
  • z.string().default("...") - if a safe default test mnemonic exists

@stalniy stalniy force-pushed the bugfixes/authorization-e2e branch from 0f7ff47 to b1e39b1 Compare December 1, 2025 11:17
@stalniy stalniy force-pushed the bugfixes/authorization-e2e branch from b1e39b1 to c5b6d73 Compare December 1, 2025 11:19
@stalniy stalniy merged commit 7ba2f4e into akash-network:main Dec 1, 2025
62 checks passed
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

Comments