Files
hash-wallet/integration_test/components/common_test_flows.dart
T
c417207007 CW 882: Integrate Seed Verification Flow To Integration Tests (#1966)
* fix: Generic fixes

* fix: Modify hasSufficientFundsForRent to work for spl transactions

* feat: Integrate seed verification into integration tests

* fix: Adjust workflow file

* chore: Remove previous working directory

* fix: Revert change

* chore: Remove step to setup kvm, already existing in new setup

* chore: Remove a couple of steps from workflow

* chore: Try switching test commands

* fix: Switch back to flutter drive

* fix: Flutter error when running tests with Flutter drive

* feat: Add screenshots to individual test pages and modify integration test script to add a watch dog to prevent infinite running on CI

* feat: Implement transaction success info robot and fix issue with send flow test

* fix: Improve integration testing for exchange flow and clean up logic and resulting errors

* fix: Handle duplicate words for seeds and test restore through seeds

* fix: Optimize implementation for transactions history test

* Skip seed verification when in debug and when not in CI flow

* chore: Remove print statements and add TODOs

* fix: Upgrade version for upload action

* fix: Add missing secrets to testing workflow file

* fix tests not working in latest main [skip slack]

 # Conflicts:
 #	lib/src/screens/wallet_keys/wallet_keys_page.dart

* add zano seed [skip slack] [run tests]

* disable exchange_flow_test.dart [run tests] [skip slack]

* Run tests on linux always (since nobody ever used [run tests])

* fix tests after ui updates

* [skip slack] tests update

* Fixing tests WIP

* Fix create wallet integraiton test flow

* Update and fix Exchange flow test flow

* Switch printV to printToConsole

* Adjustments to the the flows on Send and Exchange

* feat: Modify Exchange and send tests to fit new flow

* fix:
- Pause screenshots for now, results in a super large json response file
- Fix delay on send bottomsheet because of pumpAndSettle animation
- Fix issue with integration test runner script

* fix(integration-tests): Fix issues relating to send flow integration tests.

This change:
- Handles the slider during the send confirmation flow during the send integration test
- Adds the missing seeds for the restore flow to the relevant workflow files

* feat: Enhance Send flow Automation Integration Test Flow

This change:
- Updates test wallet address in CommonTestConstants.
- Modifies startAppFlow to accept a dynamic key.
- Improves waitForSendPage and checkIfSendPageIsVisible methods for better page visibility handling.
- Adds validateWalletBalance method to ensure sufficient funds before sending.
- Enhances transaction success flow handling in SendPageRobot.

* refactor: Update SendPageRobot for improved transaction state handling

This change:
- Adds support for the TransactionCommitted state in the SendPageRobot.
- Removes the handleSendResult method to streamline the send flow.
- Enhances checks for successful transaction completion by verifying navigation to the DashboardPage.
- Improves visibility handling for the contact addition dialog in the transaction success flow.

* chore: Update automated integration test workflow

This change:
- Updates apkl file naming to use sanitized branch names for better consistency.
- Adds a step to output system environment information to aid in troubleshooting.
- Enhances KVM setup with checks to see if device exists and there is proper permission.
- Adjusts working directory references for Android emulator setup.

* chore: Enhance automated integration test workflow

This change:
- Adds cleanup steps for existing emulator processes to ensure fresh environment.
- Updates APK file naming to use sanitized branch names for consistency.
- Enhances debug output for APK file creation and searching, improving visibility during the workflow.

* chore: Modify apk file renaming step in workflow

* chore: Enhance automated integration test workflow

This change:
- Increases timeout for integration tests to 60 minutes.
- Adds a timeout of 90 minutes for the automated integration test job.
- Improves KVM setup with detailed checks and outputs for existing device, permissions, and functionality.
- Adds system resource checks to provide information on memory, disk space, and CPU cores during the workflow.
- Implements error handling for the integration test runner to ensure graceful failure reporting.

* chore: Enhance AVD configuration and emulator management in integration test workflow

* refactor: Improve transaction history flow tests and item visibility checks

This change:
- Enhances the scrolling logic in the CommonTestCases to check for item visibility before scrolling.
- Adds error handling and logging for transaction history checks in TransactionsPageRobot.
- Adds comprehensive item checks and scrolling for more reliable tests.

* refactor: Modify integration test runner for improved error handling and logging

This change:
- Implements error handling and logging throughout the integration test runner.
- Introduces a cleanup function for data directories and signal handling.
- Enhances test execution with retry logic and detailed duration tracking.
- Provides a comprehensive summary of test results, including passed and failed tests with their durations.

* refactor: Update error handling in transaction history flow tests

* refactor: Remove manual emulator startup logic from integration test workflow

This change simplifies the automated integration test workflow by removing the manual emulator startup process, which was previously included to handle cases where no emulator was running. The workflow now focuses on checking the emulator status and gathering device information without attempting to start an emulator manually.

* refactor: Enhance integration test workflow and error handling

* feat: Add emulator readiness checks and enhance send flow tests

This change:
- Modifies the send flow test to send $1 worth of any of the wallet currencies
- Set up switching between test wallet in case there's zero balance in any of the wallets when the test is run
- Add a mini script to check emulator readiness for the tests

* fix: More CI workflow errors for the tests

* refactor: Update emulator readiness checks and error handling in CI workflow

* fix: Readiness check successful but broken pipe when accessing settings service, plus some syntax errors in the workflow

* refactor: Enhance integration tests with improved visibility checks and timing adjustments

This change:
- Adds visibility checks for widgets before interaction in various test flows.
- Introduces consistent pump and settle durations to ensure UI stability during tests.
- Refines scrolling logic to confirm wallet types are visible before selection.
- Updates tap actions to include warnings for missed taps, improving test reliability.

* fix: Issues with confirm seeds and keys Automated test

* fix: Add missing await for tap calls

* fix: Temporarily disable CI workflow and minor cleanup to testflows

* fix: Add missing keys to CI workflow

* chore: Temporarily disable Automation CI

* chore: Cleanup

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
Co-authored-by: Czarek Nakamoto <cyjan@mrcyjanek.net>
2025-07-17 06:23:04 +03:00

401 lines
14 KiB
Dart

import 'dart:io';
import 'package:cake_wallet/entities/seed_type.dart';
import 'package:cake_wallet/reactions/bip39_wallet_utils.dart';
import 'package:cake_wallet/wallet_types.g.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:cake_wallet/main.dart' as app;
import '../robots/create_pin_welcome_page_robot.dart';
import '../robots/new_wallet_page_robot.dart';
import '../robots/new_wallet_type_page_robot.dart';
import '../robots/pre_seed_page_robot.dart';
import '../robots/restore_from_seed_or_key_robot.dart';
import '../robots/restore_options_page_robot.dart';
import '../robots/seed_verification_page_robot.dart';
import '../robots/setup_pin_code_robot.dart';
import '../robots/wallet_group_description_page_robot.dart';
import '../robots/wallet_list_page_robot.dart';
import '../robots/wallet_seed_page_robot.dart';
import '../robots/welcome_page_robot.dart';
import 'common_test_cases.dart';
import 'package:cake_wallet/.secrets.g.dart' as secrets;
import 'common_test_constants.dart';
class CommonTestFlows {
CommonTestFlows(this._tester)
: _commonTestCases = CommonTestCases(_tester),
_welcomePageRobot = WelcomePageRobot(_tester),
_preSeedPageRobot = PreSeedPageRobot(_tester),
_setupPinCodeRobot = SetupPinCodeRobot(_tester),
_newWalletPageRobot = NewWalletPageRobot(_tester),
_walletSeedPageRobot = WalletSeedPageRobot(_tester),
_walletListPageRobot = WalletListPageRobot(_tester),
_newWalletTypePageRobot = NewWalletTypePageRobot(_tester),
_restoreOptionsPageRobot = RestoreOptionsPageRobot(_tester),
_seedVerificationPageRobot = SeedVerificationPageRobot(_tester),
_createPinWelcomePageRobot = CreatePinWelcomePageRobot(_tester),
_restoreFromSeedOrKeysPageRobot = RestoreFromSeedOrKeysPageRobot(_tester),
_walletGroupDescriptionPageRobot = WalletGroupDescriptionPageRobot(_tester);
final WidgetTester _tester;
final CommonTestCases _commonTestCases;
final WelcomePageRobot _welcomePageRobot;
final PreSeedPageRobot _preSeedPageRobot;
final SetupPinCodeRobot _setupPinCodeRobot;
final NewWalletPageRobot _newWalletPageRobot;
final WalletSeedPageRobot _walletSeedPageRobot;
final WalletListPageRobot _walletListPageRobot;
final NewWalletTypePageRobot _newWalletTypePageRobot;
final RestoreOptionsPageRobot _restoreOptionsPageRobot;
final CreatePinWelcomePageRobot _createPinWelcomePageRobot;
final SeedVerificationPageRobot _seedVerificationPageRobot;
final RestoreFromSeedOrKeysPageRobot _restoreFromSeedOrKeysPageRobot;
final WalletGroupDescriptionPageRobot _walletGroupDescriptionPageRobot;
//* ========== Handles flow to start the app afresh and accept disclaimer =============
Future<void> startAppFlow(Key key) async {
await app.main(topLevelKey: key);
await _tester.pump(Duration(seconds: 2));
// // --------- Disclaimer Page ------------
// // Tap checkbox to accept disclaimer
// await _disclaimerPageRobot.tapDisclaimerCheckbox();
// // Tap accept button
// await _disclaimerPageRobot.tapAcceptButton();
}
//* ========== Handles flow from welcome to creating a new wallet ===============
Future<void> welcomePageToCreateNewWalletFlow(
WalletType walletTypeToCreate,
List<int> walletPin,
) async {
await _welcomeToCreateWalletPath(walletTypeToCreate, walletPin);
await _generateNewWalletDetails();
await _confirmPreSeedInfo();
await _confirmWalletDetails();
await _verifyWalletSeed();
}
//* ========== Handles flow from welcome to restoring wallet from seeds ===============
Future<void> welcomePageToRestoreWalletThroughSeedsFlow(
WalletType walletTypeToRestore,
String walletSeed,
List<int> walletPin,
) async {
await _welcomeToRestoreFromSeedsOrKeysPath(walletTypeToRestore, walletPin);
await _restoreFromSeeds(walletTypeToRestore, walletSeed);
}
//* ========== Handles flow from welcome to restoring wallet from keys ===============
Future<void> welcomePageToRestoreWalletThroughKeysFlow(
WalletType walletTypeToRestore,
List<int> walletPin,
) async {
await _welcomeToRestoreFromSeedsOrKeysPath(walletTypeToRestore, walletPin);
await _restoreFromKeys();
}
void confirmAllAvailableWalletTypeIconsDisplayCorrectly() {
for (var walletType in availableWalletTypes) {
final imageUrl = walletTypeToCryptoCurrency(walletType).iconPath;
final walletIconFinder = find.image(
Image.asset(
imageUrl!,
width: 32,
height: 32,
).image,
);
expect(walletIconFinder, findsAny);
}
}
//* ========== Handles creating new wallet flow from wallet list/menu ===============
Future<void> createNewWalletFromWalletMenu(WalletType walletTypeToCreate) async {
_tester.printToConsole('Creating ${walletTypeToCreate.name} Wallet');
await _tester.pumpAndSettle(Duration(milliseconds: 1000));
await _walletListPageRobot.navigateToCreateNewWalletPage();
await _commonTestCases.defaultSleepTime();
await _selectWalletTypeForWallet(walletTypeToCreate);
await _commonTestCases.defaultSleepTime();
// ---- Wallet Group/New Seed Implementation Comes here
await _walletGroupDescriptionPageFlow(true, walletTypeToCreate);
await _generateNewWalletDetails();
await _confirmPreSeedInfo();
await _confirmWalletDetails();
await _verifyWalletSeed();
await _commonTestCases.defaultSleepTime();
}
Future<void> _walletGroupDescriptionPageFlow(bool isNewSeed, WalletType walletType) async {
if (!isBIP39Wallet(walletType)) return;
await _walletGroupDescriptionPageRobot.isWalletGroupDescriptionPage();
if (isNewSeed) {
await _walletGroupDescriptionPageRobot.navigateToCreateNewSeedPage();
} else {
await _walletGroupDescriptionPageRobot.navigateToChooseWalletGroup();
}
}
//* ========== Handles restore wallet flow from wallet list/menu ===============
Future<void> restoreWalletFromWalletMenu(WalletType walletType, String walletSeed) async {
_tester.printToConsole('Restoring ${walletType.name} Wallet');
await _walletListPageRobot.navigateToRestoreWalletOptionsPage();
await _commonTestCases.defaultSleepTime();
if (!Platform.isLinux) await _restoreOptionsPageRobot.navigateToRestoreFromSeedsOrKeysPage();
if (!Platform.isLinux) await _commonTestCases.defaultSleepTime();
await _selectWalletTypeForWallet(walletType);
await _commonTestCases.defaultSleepTime();
await _restoreFromSeeds(walletType, walletSeed);
await _commonTestCases.defaultSleepTime();
}
//* ========== Handles setting up pin code for wallet on first install ===============
Future<void> setupPinCodeForWallet(List<int> pin) async {
if (Platform.isLinux) return;
// ----------- SetupPinCode Page -------------
// Confirm initial defaults - Widgets to be displayed etc
await _setupPinCodeRobot.isSetupPinCodePage();
await _setupPinCodeRobot.enterPinCode(pin);
await _setupPinCodeRobot.enterPinCode(pin);
await _setupPinCodeRobot.tapSuccessButton();
}
Future<void> _welcomeToCreateWalletPath(
WalletType walletTypeToCreate,
List<int> pin,
) async {
await _createPinWelcomePageRobot.tapSetAPinButton();
await setupPinCodeForWallet(pin);
await _welcomePageRobot.navigateToCreateNewWalletPage();
await _selectWalletTypeForWallet(walletTypeToCreate);
if (_welcomePageRobot.hasNewSingleSeedButton()) {
await _welcomePageRobot.tapNewSingleSeed();
}
}
Future<void> _welcomeToRestoreFromSeedsOrKeysPath(
WalletType walletTypeToRestore,
List<int> pin,
) async {
await _createPinWelcomePageRobot.tapSetAPinButton();
await setupPinCodeForWallet(pin);
await _welcomePageRobot.navigateToRestoreWalletPage();
if (!Platform.isLinux) await _restoreOptionsPageRobot.navigateToRestoreFromSeedsOrKeysPage();
await _selectWalletTypeForWallet(walletTypeToRestore);
}
//* ============ Handles New Wallet Type Page ==================
Future<void> _selectWalletTypeForWallet(WalletType type) async {
// ----------- NewWalletType Page -------------
_tester.printToConsole('Selecting wallet type: ${type.name}');
await _tester.pumpAndSettle(Duration(milliseconds: 1000));
await _newWalletTypePageRobot.findParticularWalletTypeInScrollableList(type);
_tester.printToConsole('Tapping wallet type: ${type.name}');
await _newWalletTypePageRobot.selectWalletType(type);
await _tester.pumpAndSettle(Duration(milliseconds: 500));
_tester.printToConsole('Pressing next button');
await _newWalletTypePageRobot.onNextButtonPressed();
await _tester.pumpAndSettle(Duration(milliseconds: 2000));
_tester.printToConsole('Wallet type selection completed for: ${type.name}');
}
//* ============ Handles New Wallet Page ==================
Future<void> _generateNewWalletDetails() async {
_tester.printToConsole('Attempting to find NewWalletPage...');
await _tester.pumpAndSettle(Duration(milliseconds: 1000));
await _newWalletPageRobot.isNewWalletPage();
_tester.printToConsole('NewWalletPage found successfully');
await _newWalletPageRobot.generateWalletName();
if (Platform.isLinux) {
// manual pin input
await _restoreFromSeedOrKeysPageRobot
.enterPasswordForWalletRestore(CommonTestConstants.pin.join(""));
await _restoreFromSeedOrKeysPageRobot
.enterPasswordRepeatForWalletRestore(CommonTestConstants.pin.join(""));
}
await _newWalletPageRobot.onNextButtonPressed();
}
//* ============ Handles Pre Seed Page =====================
Future<void> _confirmPreSeedInfo() async {
await _preSeedPageRobot.isPreSeedPage();
await _preSeedPageRobot.onConfirmButtonPressed();
}
//* ============ Handles Wallet Seed Page ==================
Future<void> _confirmWalletDetails() async {
await _walletSeedPageRobot.isWalletSeedPage();
_walletSeedPageRobot.confirmWalletDetailsDisplayCorrectly();
_walletSeedPageRobot.confirmWalletSeedReminderDisplays();
// await _walletSeedPageRobot.onCopySeedsButtonPressed();
await _walletSeedPageRobot.onVerifySeedButtonPressed();
}
//* ============ Handles Wallet Seed Verification Page ==================
Future<void> _verifyWalletSeed() async {
await _seedVerificationPageRobot.isSeedVerificationPage();
_seedVerificationPageRobot.hasTitle();
await _seedVerificationPageRobot.verifyWalletSeeds();
}
//* Main Restore Actions - On the RestoreFromSeed/Keys Page - Restore from Seeds Action
Future<void> _restoreFromSeeds(WalletType type, String walletSeed) async {
// ----------- RestoreFromSeedOrKeys Page -------------
await _restoreFromSeedOrKeysPageRobot.selectWalletNameFromAvailableOptions();
await _restoreFromSeedOrKeysPageRobot.enterSeedPhraseForWalletRestore(walletSeed);
final numberOfWords = walletSeed.split(' ').length;
if (numberOfWords == 25 && (type == WalletType.monero)) {
await _restoreFromSeedOrKeysPageRobot
.chooseSeedTypeForMoneroOrWowneroWallets(MoneroSeedType.legacy);
// Using a constant value of 2831400 for the blockheight as its the restore blockheight for our testing wallet
await _restoreFromSeedOrKeysPageRobot
.enterBlockHeightForWalletRestore(secrets.moneroTestWalletBlockHeight);
}
if (Platform.isLinux) {
// manual pin input
await _restoreFromSeedOrKeysPageRobot
.enterPasswordForWalletRestore(CommonTestConstants.pin.join(""));
await _restoreFromSeedOrKeysPageRobot
.enterPasswordRepeatForWalletRestore(CommonTestConstants.pin.join(""));
}
await _restoreFromSeedOrKeysPageRobot.onRestoreWalletButtonPressed();
}
//* Main Restore Actions - On the RestoreFromSeed/Keys Page - Restore from Keys Action
Future<void> _restoreFromKeys() async {
await _commonTestCases.swipePage();
await _commonTestCases.defaultSleepTime();
await _restoreFromSeedOrKeysPageRobot.selectWalletNameFromAvailableOptions(
isSeedFormEntry: false,
);
await _restoreFromSeedOrKeysPageRobot.enterSeedPhraseForWalletRestore('');
await _restoreFromSeedOrKeysPageRobot.onRestoreWalletButtonPressed();
}
//* ====== Utility Function to get test wallet seeds for each wallet type ========
String getWalletSeedsByWalletType(WalletType walletType) {
switch (walletType) {
case WalletType.monero:
return secrets.moneroTestWalletSeeds;
case WalletType.bitcoin:
return secrets.bitcoinTestWalletSeeds;
case WalletType.ethereum:
return secrets.ethereumTestWalletSeeds;
case WalletType.litecoin:
return secrets.litecoinTestWalletSeeds;
case WalletType.bitcoinCash:
return secrets.bitcoinCashTestWalletSeeds;
case WalletType.polygon:
return secrets.polygonTestWalletSeeds;
case WalletType.solana:
return secrets.solanaTestWalletSeeds;
case WalletType.tron:
return secrets.tronTestWalletSeeds;
case WalletType.nano:
return secrets.nanoTestWalletSeeds;
case WalletType.wownero:
return secrets.wowneroTestWalletSeeds;
case WalletType.zano:
return secrets.zanoTestWalletSeeds;
case WalletType.decred:
return secrets.decredTestWalletSeeds;
case WalletType.none:
case WalletType.haven:
case WalletType.banano:
throw Exception("Unable to get seeds for ${walletType}");
}
}
//* ====== Utility Function to get test receive address for each wallet type ========
String getReceiveAddressByWalletType(WalletType walletType) {
switch (walletType) {
case WalletType.monero:
return secrets.moneroTestWalletReceiveAddress;
case WalletType.bitcoin:
return secrets.bitcoinTestWalletReceiveAddress;
case WalletType.ethereum:
return secrets.ethereumTestWalletReceiveAddress;
case WalletType.litecoin:
return secrets.litecoinTestWalletReceiveAddress;
case WalletType.bitcoinCash:
return secrets.bitcoinCashTestWalletReceiveAddress;
case WalletType.polygon:
return secrets.polygonTestWalletReceiveAddress;
case WalletType.solana:
return secrets.solanaTestWalletReceiveAddress;
case WalletType.tron:
return secrets.tronTestWalletReceiveAddress;
case WalletType.nano:
return secrets.nanoTestWalletReceiveAddress;
case WalletType.wownero:
return secrets.wowneroTestWalletReceiveAddress;
default:
return '';
}
}
}