tests: Confirm Seeds Display Correctly Automated Tests

This commit is contained in:
Blazebrain 2024-08-19 16:27:35 +01:00
parent 4555b0bd94
commit d197b7150a
10 changed files with 323 additions and 72 deletions

View file

@ -31,6 +31,11 @@ class CommonTestCases {
expect(typeWidget, findsOneWidget);
}
bool isKeyPresent(String key) {
final typeWidget = find.byKey(ValueKey(key));
return typeWidget.tryEvaluate();
}
void hasValueKey(String key) {
final typeWidget = find.byKey(ValueKey(key));
expect(typeWidget, findsOneWidget);

View file

@ -99,10 +99,8 @@ class CommonTestFlows {
Future<void> switchToWalletMenuFromDashboardPage() async {
_tester.printToConsole('Switching to Wallet Menu');
await _dashboardPageRobot.openDrawerMenu();
await _commonTestCases.defaultSleepTime();
await _dashboardPageRobot.dashboardMenuWidgetRobot.navigateToWalletMenu();
await _commonTestCases.defaultSleepTime();
}
//* ========== Handles creating new wallet flow from wallet list/menu ===============

View file

@ -29,4 +29,11 @@ class DashboardMenuWidgetRobot {
await commonTestCases.tapItemByKey('dashboard_page_menu_widget_wallet_menu_button_key');
await commonTestCases.defaultSleepTime();
}
Future<void> navigateToSecurityAndBackupPage() async {
await commonTestCases.tapItemByKey(
'dashboard_page_menu_widget_security_and_backup_button_key',
);
await commonTestCases.defaultSleepTime();
}
}

View file

@ -77,6 +77,7 @@ class DashboardPageRobot {
Future<void> openDrawerMenu() async {
await commonTestCases.tapItemByKey('dashboard_page_wallet_menu_button_key');
await commonTestCases.defaultSleepTime();
}
Future<void> navigateToBuyPage() async {

View file

@ -0,0 +1,24 @@
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/screens/settings/security_backup_page.dart';
import 'package:flutter_test/flutter_test.dart';
import '../components/common_test_cases.dart';
class SecurityAndBackupPageRobot {
SecurityAndBackupPageRobot(this.tester) : commonTestCases = CommonTestCases(tester);
final WidgetTester tester;
final CommonTestCases commonTestCases;
Future<void> isSecurityAndBackupPage() async {
await commonTestCases.isSpecificPage<SecurityBackupPage>();
}
void hasTitle() {
commonTestCases.hasText(S.current.security_and_backup);
}
Future<void> navigateToShowKeysPage() async {
await commonTestCases.tapItemByKey('security_backup_page_show_keys_button_key');
}
}

View file

@ -0,0 +1,162 @@
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/reactions/wallet_connect.dart';
import 'package:cake_wallet/src/screens/wallet_keys/wallet_keys_page.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cw_core/monero_wallet_keys.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cw_monero/monero_wallet.dart';
import 'package:cw_wownero/wownero_wallet.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:polyseed/polyseed.dart';
import '../components/common_test_cases.dart';
class WalletKeysAndSeedPageRobot {
WalletKeysAndSeedPageRobot(this.tester) : commonTestCases = CommonTestCases(tester);
final WidgetTester tester;
final CommonTestCases commonTestCases;
Future<void> isWalletKeysAndSeedPage() async {
await commonTestCases.isSpecificPage<WalletKeysPage>();
}
void hasTitle() {
final walletKeysPage = tester.widget<WalletKeysPage>(find.byType(WalletKeysPage));
final walletKeysViewModel = walletKeysPage.walletKeysViewModel;
commonTestCases.hasText(walletKeysViewModel.title);
}
void hasShareWarning() {
commonTestCases.hasText(S.current.do_not_share_warning_text.toUpperCase());
}
Future<void> confirmWalletCredentials(WalletType walletType) async {
final walletKeysPage = tester.widget<WalletKeysPage>(find.byType(WalletKeysPage));
final walletKeysViewModel = walletKeysPage.walletKeysViewModel;
final appStore = walletKeysViewModel.appStore;
final walletName = walletType.name;
bool hasSeed = appStore.wallet!.seed != null;
bool hasHexSeed = appStore.wallet!.hexSeed != null;
bool hasPrivateKey = appStore.wallet!.privateKey != null;
if (walletType == WalletType.monero) {
final moneroWallet = appStore.wallet as MoneroWallet;
final lang = PolyseedLang.getByPhrase(moneroWallet.seed);
final legacySeed = moneroWallet.seedLegacy(lang.nameEnglish);
_confirmMoneroWalletCredentials(
appStore,
walletName,
moneroWallet.seed,
legacySeed,
);
}
if (walletType == WalletType.wownero) {
final wowneroWallet = appStore.wallet as WowneroWallet;
final lang = PolyseedLang.getByPhrase(wowneroWallet.seed);
final legacySeed = wowneroWallet.seedLegacy(lang.nameEnglish);
_confirmMoneroWalletCredentials(
appStore,
walletName,
wowneroWallet.seed,
legacySeed,
);
}
if (walletType == WalletType.bitcoin ||
walletType == WalletType.litecoin ||
walletType == WalletType.bitcoinCash) {
commonTestCases.hasText(appStore.wallet!.seed!);
tester.printToConsole('$walletName wallet has seeds properly displayed');
}
if (isEVMCompatibleChain(walletType) ||
walletType == WalletType.solana ||
walletType == WalletType.tron) {
if (hasSeed) {
commonTestCases.hasText(appStore.wallet!.seed!);
tester.printToConsole('$walletName wallet has seeds properly displayed');
}
if (hasPrivateKey) {
commonTestCases.hasText(appStore.wallet!.privateKey!);
tester.printToConsole('$walletName wallet has private key properly displayed');
}
}
if (walletType == WalletType.nano || walletType == WalletType.banano) {
if (hasSeed) {
commonTestCases.hasText(appStore.wallet!.seed!);
tester.printToConsole('$walletName wallet has seeds properly displayed');
}
if (hasHexSeed) {
commonTestCases.hasText(appStore.wallet!.hexSeed!);
tester.printToConsole('$walletName wallet has hexSeed properly displayed');
}
if (hasPrivateKey) {
commonTestCases.hasText(appStore.wallet!.privateKey!);
tester.printToConsole('$walletName wallet has private key properly displayed');
}
}
await commonTestCases.defaultSleepTime(seconds: 5);
}
void _confirmMoneroWalletCredentials(
AppStore appStore,
String walletName,
String seed,
String legacySeed,
) {
final keys = appStore.wallet!.keys as MoneroWalletKeys;
final hasPublicSpendKey = commonTestCases.isKeyPresent(
'${walletName}_wallet_public_spend_key_item_key',
);
final hasPrivateSpendKey = commonTestCases.isKeyPresent(
'${walletName}_wallet_private_spend_key_item_key',
);
final hasPublicViewKey = commonTestCases.isKeyPresent(
'${walletName}_wallet_public_view_key_item_key',
);
final hasPrivateViewKey = commonTestCases.isKeyPresent(
'${walletName}_wallet_private_view_key_item_key',
);
final hasSeeds = seed.isNotEmpty;
final hasSeedLegacy = Polyseed.isValidSeed(seed);
if (hasPublicSpendKey) {
commonTestCases.hasText(keys.publicSpendKey);
tester.printToConsole('$walletName wallet has public spend key properly displayed');
}
if (hasPrivateSpendKey) {
commonTestCases.hasText(keys.privateSpendKey);
tester.printToConsole('$walletName wallet has private spend key properly displayed');
}
if (hasPublicViewKey) {
commonTestCases.hasText(keys.publicViewKey);
tester.printToConsole('$walletName wallet has public view key properly displayed');
}
if (hasPrivateViewKey) {
commonTestCases.hasText(keys.privateViewKey);
tester.printToConsole('$walletName wallet has private view key properly displayed');
}
if (hasSeeds) {
commonTestCases.hasText(seed);
tester.printToConsole('$walletName wallet has seeds properly displayed');
}
if (hasSeedLegacy) {
commonTestCases.hasText(legacySeed);
tester.printToConsole('$walletName wallet has legacy seeds properly displayed');
}
}
Future<void> backToDashboard() async {
tester.printToConsole('Going back to dashboard from credentials page');
await commonTestCases.goBack();
await commonTestCases.goBack();
}
}

View file

@ -0,0 +1,102 @@
import 'package:cake_wallet/wallet_types.g.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import '../components/common_test_constants.dart';
import '../components/common_test_flows.dart';
import '../robots/auth_page_robot.dart';
import '../robots/dashboard_page_robot.dart';
import '../robots/security_and_backup_page_robot.dart';
import '../robots/wallet_keys_robot.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
AuthPageRobot authPageRobot;
CommonTestFlows commonTestFlows;
DashboardPageRobot dashboardPageRobot;
WalletKeysAndSeedPageRobot walletKeysAndSeedPageRobot;
SecurityAndBackupPageRobot securityAndBackupPageRobot;
testWidgets(
'Confirm if the seeds display properly',
(tester) async {
authPageRobot = AuthPageRobot(tester);
commonTestFlows = CommonTestFlows(tester);
dashboardPageRobot = DashboardPageRobot(tester);
walletKeysAndSeedPageRobot = WalletKeysAndSeedPageRobot(tester);
securityAndBackupPageRobot = SecurityAndBackupPageRobot(tester);
// Start the app
await commonTestFlows.startAppFlow(
ValueKey('confirm_creds_display_correctly_flow_app_key'),
);
await commonTestFlows.welcomePageToCreateNewWalletFlow(
WalletType.solana,
CommonTestConstants.pin,
);
await dashboardPageRobot.confirmWalletTypeIsDisplayedCorrectly(WalletType.solana);
await _confirmSeedsFlowForWalletType(
WalletType.solana,
authPageRobot,
dashboardPageRobot,
securityAndBackupPageRobot,
walletKeysAndSeedPageRobot,
);
// Do the same for other available wallet types
for (var walletType in availableWalletTypes) {
if (walletType == WalletType.solana) {
continue;
}
await commonTestFlows.switchToWalletMenuFromDashboardPage();
await commonTestFlows.createNewWalletFromWalletMenu(walletType);
await dashboardPageRobot.confirmWalletTypeIsDisplayedCorrectly(walletType);
await _confirmSeedsFlowForWalletType(
walletType,
authPageRobot,
dashboardPageRobot,
securityAndBackupPageRobot,
walletKeysAndSeedPageRobot,
);
}
await Future.delayed(Duration(seconds: 15));
},
);
}
Future<void> _confirmSeedsFlowForWalletType(
WalletType walletType,
AuthPageRobot authPageRobot,
DashboardPageRobot dashboardPageRobot,
SecurityAndBackupPageRobot securityAndBackupPageRobot,
WalletKeysAndSeedPageRobot walletKeysAndSeedPageRobot,
) async {
await dashboardPageRobot.openDrawerMenu();
await dashboardPageRobot.dashboardMenuWidgetRobot.navigateToSecurityAndBackupPage();
await securityAndBackupPageRobot.navigateToShowKeysPage();
final onAuthPage = authPageRobot.onAuthPage();
if (onAuthPage) {
await authPageRobot.enterPinCode(CommonTestConstants.pin, false);
}
await walletKeysAndSeedPageRobot.isWalletKeysAndSeedPage();
walletKeysAndSeedPageRobot.hasTitle();
walletKeysAndSeedPageRobot.hasShareWarning();
walletKeysAndSeedPageRobot.confirmWalletCredentials(walletType);
await walletKeysAndSeedPageRobot.backToDashboard();
}

View file

@ -3,41 +3,10 @@ PODS:
- Flutter
- MTBBarcodeScanner
- SwiftProtobuf
- BigInt (5.2.0)
- connectivity_plus (0.0.1):
- Flutter
- ReachabilitySwift
- CryptoSwift (1.8.2)
- cw_haven (0.0.1):
- cw_haven/Boost (= 0.0.1)
- cw_haven/Haven (= 0.0.1)
- cw_haven/OpenSSL (= 0.0.1)
- cw_haven/Sodium (= 0.0.1)
- cw_shared_external
- Flutter
- cw_haven/Boost (0.0.1):
- cw_shared_external
- Flutter
- cw_haven/Haven (0.0.1):
- cw_shared_external
- Flutter
- cw_haven/OpenSSL (0.0.1):
- cw_shared_external
- Flutter
- cw_haven/Sodium (0.0.1):
- cw_shared_external
- Flutter
- cw_shared_external (0.0.1):
- cw_shared_external/Boost (= 0.0.1)
- cw_shared_external/OpenSSL (= 0.0.1)
- cw_shared_external/Sodium (= 0.0.1)
- Flutter
- cw_shared_external/Boost (0.0.1):
- Flutter
- cw_shared_external/OpenSSL (0.0.1):
- Flutter
- cw_shared_external/Sodium (0.0.1):
- Flutter
- device_display_brightness (0.0.1):
- Flutter
- device_info_plus (0.0.1):
@ -101,8 +70,6 @@ PODS:
- Flutter
- MTBBarcodeScanner (5.0.11)
- OrderedSet (5.0.0)
- package_info (0.0.1):
- Flutter
- package_info_plus (0.4.5):
- Flutter
- path_provider_foundation (0.0.1):
@ -133,9 +100,6 @@ PODS:
- Toast (4.1.1)
- uni_links (0.0.1):
- Flutter
- UnstoppableDomainsResolution (4.0.0):
- BigInt
- CryptoSwift
- url_launcher_ios (0.0.1):
- Flutter
- wakelock_plus (0.0.1):
@ -147,8 +111,6 @@ DEPENDENCIES:
- barcode_scan2 (from `.symlinks/plugins/barcode_scan2/ios`)
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
- CryptoSwift
- cw_haven (from `.symlinks/plugins/cw_haven/ios`)
- cw_shared_external (from `.symlinks/plugins/cw_shared_external/ios`)
- device_display_brightness (from `.symlinks/plugins/device_display_brightness/ios`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- devicelocale (from `.symlinks/plugins/devicelocale/ios`)
@ -161,7 +123,6 @@ DEPENDENCIES:
- fluttertoast (from `.symlinks/plugins/fluttertoast/ios`)
- in_app_review (from `.symlinks/plugins/in_app_review/ios`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- package_info (from `.symlinks/plugins/package_info/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
@ -171,14 +132,12 @@ DEPENDENCIES:
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- sp_scanner (from `.symlinks/plugins/sp_scanner/ios`)
- uni_links (from `.symlinks/plugins/uni_links/ios`)
- UnstoppableDomainsResolution (~> 4.0.0)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
- wakelock_plus (from `.symlinks/plugins/wakelock_plus/ios`)
- workmanager (from `.symlinks/plugins/workmanager/ios`)
SPEC REPOS:
https://github.com/CocoaPods/Specs.git:
- BigInt
- CryptoSwift
- DKImagePickerController
- DKPhotoGallery
@ -190,17 +149,12 @@ SPEC REPOS:
- SwiftProtobuf
- SwiftyGif
- Toast
- UnstoppableDomainsResolution
EXTERNAL SOURCES:
barcode_scan2:
:path: ".symlinks/plugins/barcode_scan2/ios"
connectivity_plus:
:path: ".symlinks/plugins/connectivity_plus/ios"
cw_haven:
:path: ".symlinks/plugins/cw_haven/ios"
cw_shared_external:
:path: ".symlinks/plugins/cw_shared_external/ios"
device_display_brightness:
:path: ".symlinks/plugins/device_display_brightness/ios"
device_info_plus:
@ -225,8 +179,6 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/in_app_review/ios"
integration_test:
:path: ".symlinks/plugins/integration_test/ios"
package_info:
:path: ".symlinks/plugins/package_info/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
path_provider_foundation:
@ -254,11 +206,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
barcode_scan2: 0af2bb63c81b4565aab6cd78278e4c0fa136dbb0
BigInt: f668a80089607f521586bbe29513d708491ef2f7
connectivity_plus: bf0076dd84a130856aa636df1c71ccaff908fa1d
CryptoSwift: c63a805d8bb5e5538e88af4e44bb537776af11ea
cw_haven: b3e54e1fbe7b8e6fda57a93206bc38f8e89b898a
cw_shared_external: 2972d872b8917603478117c9957dfca611845a92
device_display_brightness: 1510e72c567a1f6ce6ffe393dcd9afd1426034f7
device_info_plus: c6fb39579d0f423935b0c9ce7ee2f44b71b9fce6
devicelocale: b22617f40038496deffba44747101255cee005b0
@ -275,7 +224,6 @@ SPEC CHECKSUMS:
integration_test: 13825b8a9334a850581300559b8839134b124670
MTBBarcodeScanner: f453b33c4b7dfe545d8c6484ed744d55671788cb
OrderedSet: aaeb196f7fef5a9edf55d89760da9176ad40b93c
package_info: 873975fc26034f0b863a300ad47e7f1ac6c7ec62
package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6
@ -291,11 +239,10 @@ SPEC CHECKSUMS:
SwiftyGif: 706c60cf65fa2bc5ee0313beece843c8eb8194d4
Toast: 1f5ea13423a1e6674c4abdac5be53587ae481c4e
uni_links: d97da20c7701486ba192624d99bffaaffcfc298a
UnstoppableDomainsResolution: c3c67f4d0a5e2437cb00d4bd50c2e00d6e743841
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe
wakelock_plus: 78ec7c5b202cab7761af8e2b2b3d0671be6c4ae1
workmanager: 0afdcf5628bbde6924c21af7836fed07b42e30e6
PODFILE CHECKSUM: a2fe518be61cdbdc5b0e2da085ab543d556af2d3
PODFILE CHECKSUM: e448f662d4c41f0c0b1ccbb78afd57dbf895a597
COCOAPODS: 1.15.2

View file

@ -25,23 +25,25 @@ class WalletKeysPage extends BasePage {
@override
Widget trailing(BuildContext context) => IconButton(
onPressed: () async {
final url = await walletKeysViewModel.url;
key: ValueKey('wallet_keys_page_fullscreen_qr_button_key'),
onPressed: () async {
final url = await walletKeysViewModel.url;
BrightnessUtil.changeBrightnessForFunction(() async {
await Navigator.pushNamed(
context,
Routes.fullscreenQR,
arguments: QrViewData(data: url.toString(), version: QrVersions.auto),
);
});
},
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
hoverColor: Colors.transparent,
icon: Image.asset(
'assets/images/qr_code_icon.png',
));
BrightnessUtil.changeBrightnessForFunction(() async {
await Navigator.pushNamed(
context,
Routes.fullscreenQR,
arguments: QrViewData(data: url.toString(), version: QrVersions.auto),
);
});
},
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
hoverColor: Colors.transparent,
icon: Image.asset(
'assets/images/qr_code_icon.png',
),
);
@override
Widget body(BuildContext context) {
@ -93,6 +95,7 @@ class WalletKeysPage extends BasePage {
final item = walletKeysViewModel.items[index];
return GestureDetector(
key: item.key,
onTap: () {
ClipboardUtil.setSensitiveDataToClipboard(ClipboardData(text: item.value));
showBar<void>(context, S.of(context).copied_key_to_clipboard(item.title));

View file

@ -57,6 +57,8 @@ abstract class WalletKeysViewModelBase with Store {
final String _walletName;
AppStore get appStore => _appStore;
final AppStore _appStore;
final int _restoreHeight;