diff --git a/test/helpers/hardware-wallet.ts b/test/helpers/hardware-wallet.ts index e5aaead..c69b340 100644 --- a/test/helpers/hardware-wallet.ts +++ b/test/helpers/hardware-wallet.ts @@ -16,9 +16,11 @@ import { expectText, formatSats, getAccessibleText, + getAddressFromQRCode, getAmountUnder, getTextUnder, sleep, + swipeFullScreen, tap, tapFirstByAccessibilityIdPrefix, typeText, @@ -190,17 +192,57 @@ export async function expectHardwareWalletBalance( ); } -export async function fundHardwareWalletAndAcknowledge( - fixture: TrezorEmulatorFixture, - { sats = 15_000, blocksToMine = 1 }: { sats?: number; blocksToMine?: number } = {} -) { - await deposit(fixture.address.value, sats); +export async function fundHardwareWalletAndAcknowledge({ + sats = 15_000, + blocksToMine = 1, +}: { sats?: number; blocksToMine?: number } = {}) { + const address = await getHardwareReceiveAddress(); + await swipeFullScreen('down'); + await deposit(address, sats); if (blocksToMine > 0) { await mineBlocks(blocksToMine); } await acknowledgeReceivedPaymentIfPresent(); } +async function getHardwareReceiveAddress(): Promise { + await doNavigationClose(); + await tap('Receive'); + await elementById('ReceiveScreen').waitForDisplayed({ timeout: 30_000 }); + + let defaultTabAddress = ''; + try { + defaultTabAddress = await getAddressFromQRCode('bitcoin'); + } catch { + // Default tab may not have a QR yet (for example while lightning is still loading). + } + + await elementById('Tab-trezor').waitForDisplayed({ timeout: 30_000 }); + await browser.waitUntil( + async () => { + try { + await tap('Tab-trezor'); + const address = await peekQrOnchainAddress(); + return Boolean(address && address !== defaultTabAddress); + } catch { + return false; + } + }, + { + timeout: 30_000, + interval: 500, + timeoutMsg: 'Timed out waiting for hardware receive address', + } + ); + + return getAddressFromQRCode('bitcoin'); +} + +async function peekQrOnchainAddress(): Promise { + const uri = (await getAccessibleText(elementById('QRCode'))).trim(); + return uri.replace(/^bitcoin:/i, '').replace(/\?.*$/, ''); +} + export async function expectHardwareWalletReceivedActivity(sats: number) { await doNavigationClose(); await elementById('ActivityHardware').waitForDisplayed(); diff --git a/test/specs/hardware-wallet.e2e.ts b/test/specs/hardware-wallet.e2e.ts index dbe6efc..d2a1144 100644 --- a/test/specs/hardware-wallet.e2e.ts +++ b/test/specs/hardware-wallet.e2e.ts @@ -25,7 +25,6 @@ import { startHardwareWalletFlowFromSuggestion, stopTrezorEmulator, transferHardwareWalletToSpending, - type TrezorEmulatorFixture, } from '../helpers/hardware-wallet'; import { ensureLocalFunds, getBackend, getExternalAddress } from '../helpers/regtest'; import { reinstallApp } from '../helpers/setup'; @@ -34,7 +33,6 @@ import { ciIt } from '../helpers/suite'; describe('@hardware_wallet - Hardware Wallet', () => { const walletLabel = 'E2E Trezor'; const renamedWalletLabel = 'E2E Renamed Trezor'; - let trezorFixture: TrezorEmulatorFixture; let electrum: Awaited> | undefined; before(async function () { @@ -43,7 +41,7 @@ describe('@hardware_wallet - Hardware Wallet', () => { }); beforeEach(async () => { - trezorFixture = ensureTrezorEmulator({ fresh: true }); + ensureTrezorEmulator({ fresh: true }); await reinstallApp(); await completeOnboarding(); await electrum?.waitForSync(); @@ -77,7 +75,7 @@ describe('@hardware_wallet - Hardware Wallet', () => { const sats = 15_000; await connectHardwareWalletFromSettings(walletLabel); - await fundHardwareWalletAndAcknowledge(trezorFixture, { sats }); + await fundHardwareWalletAndAcknowledge({ sats }); await expectHardwareWalletReceivedActivity(sats); await doNavigationClose(); await expectTotalBalance(sats); @@ -97,7 +95,7 @@ describe('@hardware_wallet - Hardware Wallet', () => { const transferSats = 20_000; await connectHardwareWalletFromSettings(walletLabel); - await fundHardwareWalletAndAcknowledge(trezorFixture, { sats: fundingSats }); + await fundHardwareWalletAndAcknowledge({ sats: fundingSats }); await expectHardwareWalletBalance(fundingSats); await transferHardwareWalletToSpending({ amountSats: transferSats, @@ -127,7 +125,7 @@ describe('@hardware_wallet - Hardware Wallet', () => { // connect hardware wallet and send onchain await connectHardwareWalletFromSettings(walletLabel); - await fundHardwareWalletAndAcknowledge(trezorFixture, { sats: fundingSats }); + await fundHardwareWalletAndAcknowledge({ sats: fundingSats }); await expectHardwareWalletBalance(fundingSats); await expectTotalBalance(fundingSats * 2); await sendOnchainFromHardwareWallet({