From ee9856b138056adc1d8d7fdfd6ce74748a653ef4 Mon Sep 17 00:00:00 2001 From: parodyBit Date: Tue, 17 Oct 2023 19:51:09 -0600 Subject: [PATCH] feat: ability clear database for e2e test - add `testingDeleteStorage` to the globals file - check if we need to delete the database before the initial screen loads --- .env.example | 27 ++++++++++++++++--- integration_test/main.dart | 10 ++++--- integration_test/test_utils.dart | 15 ++++++++++- lib/globals.dart | 2 ++ lib/main.dart | 6 ++++- lib/screens/login/view/init_screen.dart | 13 +++++++-- lib/util/extensions/string_extensions.dart | 2 ++ lib/util/storage/path_provider_interface.dart | 5 ++-- 8 files changed, 66 insertions(+), 14 deletions(-) diff --git a/.env.example b/.env.example index 9d1b39cd..05f4a13a 100644 --- a/.env.example +++ b/.env.example @@ -2,8 +2,27 @@ EXPLORER_ADDRESS = 'witnet.network' EXPLORER_DEV_ADDRESS = '0.0.0.0' # [ Integration Test Settings ] -# uncomment the line below and add your password to run automatic integration tests with a new or existing database -# PASSWORD = '' -# MNEMONIC = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about' + +# how long to delay on the first screen +# INIT_E2E_DELAY_IN_SECONDS = 5 + # The default time to wait between actions, value is in milliseconds -DELAY = 1000 \ No newline at end of file +# DELAY = 1000 + +# Boolean as a string to delete the test database between tests +# DELETE_TEST_STORAGE = 'false' + +# The default password +# PASSWORD = 'password' + +# Here is the default test recovery in all forms for a wallet: mnemonic, xprv, sheikah, myWitWallet +# The BIP39 entropy is 0x00000000000000000000000000000000 +# MNEMONIC = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about' +# SHEIKAH_XPRV = 'xprv1yd5j548gfk6fc5an0n4r4mvp8kxq6pxcwynajfhc2evp6enm98fvxtawxr7z5z5yt0m83tlry8dzk8ygea2nk2nfqdlg76mn5e9k0x32ty0tewqe888cj6fap7e84s9zkgd5rkvjpdff4ylyx55xup6x3aqlwnq4wgl3mc0m5d8gphkpad7cr7ydt43c052pu4sec0kf4mtjye5l5lqu9m4vmdprh63w8l8vpxu6hrjrsh8lgsxs8t75pw4ppvr6tz86fydhxs0atgacfx29z35uavxy468h' +# MWW_XPRV = 'xprv1m9datmt8l4qyqa2nf7lxrw76vu3kyy63qndhtpjyezm7rjrlqrqjh23yks7zjwycud9k25g20rjqkl7uyfcvq6e246du73cl8hhcfa2xwm6cun5ma69jrtyyzjzm0nqwurwa8vg5pxhd9wxu2lgrpmwknsl3yk3t4qn5au4mnf33qpnk3gg7e093nkk0kqzhfkecg45jm0qsczellg6hll4nzuldckjvj6xku75gmhjc340jau26t634c98ke3a454mqjsxtvfs53f2464jfyhd605hqs0lu' +# WALLET_XPRV = '' + +# The Node Xprv is derived from the mnemonic: +# "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent" +# The BIP39 entropy is 0x000000000000000000000000000000000000000000000000 +# NODE_XPRV = 'xprv1qrgqgjwqnprj4g74wjpgad6k7xa37qmxjk3nf5wakgka9d0hgmzvkqr88hgnklzs0x86x487nyr34uq7ujracm36wcgplftzsuaswe533ufnfx6r' \ No newline at end of file diff --git a/integration_test/main.dart b/integration_test/main.dart index 9ddfea61..64f79eaf 100644 --- a/integration_test/main.dart +++ b/integration_test/main.dart @@ -1,16 +1,18 @@ -import 'e2e_auth_preferences_test.dart'; -import 'e2e_import_mnemonic_test.dart'; -import 'e2e_show_node_stats.dart'; -import "e2e_mnemonic_test.dart"; import 'package:flutter_test/flutter_test.dart'; + +import 'e2e_mnemonic_test.dart'; +import 'e2e_import_mnemonic_test.dart'; import 'e2e_re_establish_wallet.dart'; import "e2e_import_xprv_test.dart"; import "e2e_export_xprv_test.dart"; import 'e2e_import_xprv_from_sheikah_test.dart'; +import 'e2e_auth_preferences_test.dart'; import 'e2e_sign_message_test.dart'; import 'e2e_update_wallet_test.dart'; +import 'e2e_show_node_stats.dart'; import 'package:my_wit_wallet/globals.dart' as globals; + void main() async { globals.testingActive = true; diff --git a/integration_test/test_utils.dart b/integration_test/test_utils.dart index 5beef096..69ac44c2 100644 --- a/integration_test/test_utils.dart +++ b/integration_test/test_utils.dart @@ -1,10 +1,14 @@ +import 'dart:io'; import 'package:flutter/material.dart'; + import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:my_wit_wallet/main.dart' as myWitWallet; + import 'package:my_wit_wallet/widgets/PaddedButton.dart'; import 'package:my_wit_wallet/widgets/select.dart'; +import 'package:my_wit_wallet/main.dart' as myWitWallet; + bool walletsExist = false; int defaultDelay = int.parse(dotenv.env['DELAY'] ?? '100'); @@ -13,6 +17,15 @@ String password = dotenv.env['PASSWORD'] ?? "password"; String mnemonic = dotenv.env['MNEMONIC'] ?? "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"; +/// The Node Xprv is derived from the mnemonic: +/// "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent" +String nodeXprv = dotenv.env['NODE_XPRV'] ?? + 'xprv1qrgqgjwqnprj4g74wjpgad6k7xa37qmxjk3nf5wakgka9d0hgmzvkqr88hgnklzs0x86x487nyr34uq7ujracm36wcgplftzsuaswe533ufnfx6r'; +String sheikahXprv = dotenv.env['SHEIKAH_XPRV'] ?? + "xprv1yd5j548gfk6fc5an0n4r4mvp8kxq6pxcwynajfhc2evp6enm98fvxtawxr7z5z5yt0m83tlry8dzk8ygea2nk2nfqdlg76mn5e9k0x32ty0tewqe888cj6fap7e84s9zkgd5rkvjpdff4ylyx55xup6x3aqlwnq4wgl3mc0m5d8gphkpad7cr7ydt43c052pu4sec0kf4mtjye5l5lqu9m4vmdprh63w8l8vpxu6hrjrsh8lgsxs8t75pw4ppvr6tz86fydhxs0atgacfx29z35uavxy468h"; +String mwwXprv = dotenv.env['MWW_XPRV'] ?? + "xprv1m9datmt8l4qyqa2nf7lxrw76vu3kyy63qndhtpjyezm7rjrlqrqjh23yks7zjwycud9k25g20rjqkl7uyfcvq6e246du73cl8hhcfa2xwm6cun5ma69jrtyyzjzm0nqwurwa8vg5pxhd9wxu2lgrpmwknsl3yk3t4qn5au4mnf33qpnk3gg7e093nkk0kqzhfkecg45jm0qsczellg6hll4nzuldckjvj6xku75gmhjc340jau26t634c98ke3a454mqjsxtvfs53f2464jfyhd605hqs0lu"; + Finder widgetByType(Type type) => find.byType(type); Finder widgetByText(String text) => find.text(text); diff --git a/lib/globals.dart b/lib/globals.dart index 05549d2e..522abd39 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -1,3 +1,5 @@ bool testingActive = false; +bool testingDeleteStorage = false; bool biometricsAuthInProgress = false; bool avoidBiometrics = false; +bool firstRun = false; diff --git a/lib/main.dart b/lib/main.dart index 3f618425..cdc017a8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -11,11 +11,13 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:my_wit_wallet/theme/wallet_theme.dart'; import 'package:my_wit_wallet/util/preferences.dart'; import 'package:my_wit_wallet/globals.dart' as globals; +import 'package:my_wit_wallet/util/extensions/string_extensions.dart'; void main() async { await dotenv.load(fileName: ".env"); Locator.setup(); WidgetsFlutterBinding.ensureInitialized(); + globals.firstRun = true; if (Platform.isWindows || Platform.isMacOS || Platform.isLinux) { await windowManager.ensureInitialized(); @@ -34,13 +36,15 @@ void main() async { }); } if (globals.testingActive) { - print("This is a testing environment!"); + String deleteStorageFlag = dotenv.env['DELETE_TEST_STORAGE'] ?? 'false'; + globals.testingDeleteStorage = deleteStorageFlag.toBoolean(); } SystemChrome.setPreferredOrientations( [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); ApiDatabase apiDatabase = Locator.instance(); await apiDatabase.openDatabase(); + if (globals.testingActive) await apiDatabase.lockDatabase(); CryptoIsolate cryptoIsolate = Locator.instance(); await cryptoIsolate.init(); diff --git a/lib/screens/login/view/init_screen.dart b/lib/screens/login/view/init_screen.dart index 16eeb96a..59682c1a 100644 --- a/lib/screens/login/view/init_screen.dart +++ b/lib/screens/login/view/init_screen.dart @@ -8,6 +8,7 @@ import 'package:my_wit_wallet/widgets/layouts/layout.dart'; import 'package:my_wit_wallet/widgets/carousel.dart'; import 'package:my_wit_wallet/shared/locator.dart'; import 'package:my_wit_wallet/shared/api_database.dart'; +import 'package:my_wit_wallet/globals.dart' as globals; class InitScreen extends StatefulWidget { static final route = '/'; @@ -49,8 +50,16 @@ class InitScreenState extends State with TickerProviderStateMixin { } Future loadInitialScreen() async { - WalletStorage storage = - await Locator.instance().loadWalletsDatabase(); + ApiDatabase database = Locator.instance(); + if (globals.testingActive && + globals.testingDeleteStorage && + globals.firstRun) { + await database.deleteAllWallets(); + await database.openDatabase(); + globals.firstRun = false; + } + WalletStorage storage = await database.loadWalletsDatabase(); + if (storage.wallets.isNotEmpty) { // There are wallets stored return LoginForm(mainComponents: mainComponents()); diff --git a/lib/util/extensions/string_extensions.dart b/lib/util/extensions/string_extensions.dart index c0ce2250..ccdaa13c 100644 --- a/lib/util/extensions/string_extensions.dart +++ b/lib/util/extensions/string_extensions.dart @@ -22,4 +22,6 @@ extension StringExtension on String { .split(' ') .map((str) => str.capitalize()) .join(' '); + + bool toBoolean() => this == 'true' || this == 'True'; } diff --git a/lib/util/storage/path_provider_interface.dart b/lib/util/storage/path_provider_interface.dart index 7188e0e9..c7138240 100644 --- a/lib/util/storage/path_provider_interface.dart +++ b/lib/util/storage/path_provider_interface.dart @@ -1,6 +1,6 @@ import 'dart:convert'; import 'dart:io' as io; - +import 'package:my_wit_wallet/globals.dart' as globals; import 'package:path_provider/path_provider.dart'; import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; import 'dart:io'; @@ -75,7 +75,8 @@ class PathProviderInterface { } String getDbWalletsPath() { - return getFilePath('wallets', 'wit'); + return getFilePath( + globals.testingActive ? 'test-wallets' : 'wallets', 'wit'); } Future fileExists(String filename) async =>