Skip to content

Commit

Permalink
feat: ability clear database for e2e test
Browse files Browse the repository at this point in the history
- add `testingDeleteStorage` to the globals file
- check if we need to delete the database before the initial screen loads
  • Loading branch information
parodyBit committed Oct 19, 2023
1 parent fe11eb2 commit ee9856b
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 14 deletions.
27 changes: 23 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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'
10 changes: 6 additions & 4 deletions integration_test/main.dart
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
15 changes: 14 additions & 1 deletion integration_test/test_utils.dart
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions lib/globals.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
bool testingActive = false;
bool testingDeleteStorage = false;
bool biometricsAuthInProgress = false;
bool avoidBiometrics = false;
bool firstRun = false;
6 changes: 5 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<ApiDatabase>();
await apiDatabase.openDatabase();
if (globals.testingActive) await apiDatabase.lockDatabase();

CryptoIsolate cryptoIsolate = Locator.instance<CryptoIsolate>();
await cryptoIsolate.init();
Expand Down
13 changes: 11 additions & 2 deletions lib/screens/login/view/init_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '/';
Expand Down Expand Up @@ -49,8 +50,16 @@ class InitScreenState extends State<InitScreen> with TickerProviderStateMixin {
}

Future<Widget> loadInitialScreen() async {
WalletStorage storage =
await Locator.instance<ApiDatabase>().loadWalletsDatabase();
ApiDatabase database = Locator.instance<ApiDatabase>();
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());
Expand Down
2 changes: 2 additions & 0 deletions lib/util/extensions/string_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ extension StringExtension on String {
.split(' ')
.map((str) => str.capitalize())
.join(' ');

bool toBoolean() => this == 'true' || this == 'True';
}
5 changes: 3 additions & 2 deletions lib/util/storage/path_provider_interface.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -75,7 +75,8 @@ class PathProviderInterface {
}

String getDbWalletsPath() {
return getFilePath('wallets', 'wit');
return getFilePath(
globals.testingActive ? 'test-wallets' : 'wallets', 'wit');
}

Future<bool> fileExists(String filename) async =>
Expand Down

0 comments on commit ee9856b

Please sign in to comment.