Test fast keychain generation

This commit is contained in:
poka 2021-04-29 02:12:14 +02:00
parent 5027b4eb2a
commit 5c97742167
6 changed files with 139 additions and 71 deletions

View File

@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:gecko/models/generateWallets.dart';
import 'package:gecko/models/myWallets.dart';
import 'package:gecko/models/walletOptions.dart';
import 'package:provider/provider.dart';
// ignore: must_be_immutable
@ -30,6 +31,8 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
Provider.of<GenerateWalletsProvider>(context);
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context);
WalletOptionsProvider _walletOptions =
Provider.of<WalletOptionsProvider>(context);
final int _currentChest = _myWalletProvider.getCurrentChest();
this._mnemonicController.text = generatedMnemonic;
@ -67,6 +70,7 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
fontWeight: FontWeight.w400),
)),
TextFormField(
key: Key('askedWord'),
focusNode: _wordFocus,
autofocus: true,
enabled: !_generateWalletProvider.isAskedWordValid,
@ -95,6 +99,7 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
fontWeight: FontWeight.w400),
)),
TextFormField(
key: Key('walletName'),
focusNode: _generateWalletProvider.walletNameFocus,
inputFormatters: [
FilteringTextInputFormatter.allow(
@ -119,6 +124,7 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
width: 200,
height: 50,
child: ElevatedButton(
key: Key('confirmStorage'),
style: ElevatedButton.styleFrom(
elevation: 12,
primary: Colors.green[
@ -137,14 +143,13 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
false;
_generateWalletProvider.askedWordColor =
Colors.black;
WidgetsBinding.instance
.addPostFrameCallback((_) {
_myWalletProvider.listWallets =
_myWalletProvider
.readAllWallets(_currentChest);
scheduleMicrotask(() {
_myWalletProvider.rebuildWidget();
});
_myWalletProvider.listWallets =
_myWalletProvider
.readAllWallets(_currentChest);
_myWalletProvider.getDefaultWallet();
scheduleMicrotask(() {
_walletOptions.reloadBuild();
_myWalletProvider.rebuildWidget();
});
Navigator.popUntil(
context, ModalRoute.withName('/'));

View File

@ -71,6 +71,7 @@ class GenerateWalletsScreen extends StatelessWidget {
alignment: Alignment.centerRight,
children: <Widget>[
TextField(
key: Key('generatedPin'),
enabled: false,
controller: _generateWalletProvider.pin,
maxLines: 1,
@ -93,6 +94,7 @@ class GenerateWalletsScreen extends StatelessWidget {
),
SizedBox(height: 20),
ElevatedButton(
key: Key('storeKeychain'),
style: ElevatedButton.styleFrom(
primary: Color(0xffFFD68E), // background
onPrimary: Colors.black, // foreground

View File

@ -35,7 +35,7 @@ class SettingsScreen extends StatelessWidget {
body: Column(children: <Widget>[
SizedBox(height: 40),
SizedBox(
height: 50,
height: 70,
width: 500,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
@ -52,27 +52,30 @@ class SettingsScreen extends StatelessWidget {
if (value == true) {Navigator.pop(context)}
}),
child: Text("Importer un portefeuille Cesium",
style: TextStyle(fontSize: 15)))),
SizedBox(height: 20),
style: TextStyle(fontSize: 16)))),
SizedBox(height: 30),
SizedBox(
height: 50,
height: 70,
width: 500,
child: ElevatedButton(
key: Key('generateKeychain'),
style: ElevatedButton.styleFrom(
elevation: 5,
primary: Color(0xFFFFCA6F), // background
onPrimary: Colors.black, // foreground
),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return GenerateWalletsScreen();
}),
).then((value) => {
if (value == true) {Navigator.pop(context)}
}),
onPressed: !_myWallets.checkIfWalletExist()
? () => Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return GenerateWalletsScreen();
}),
).then((value) => {
if (value == true) {Navigator.pop(context)}
})
: null,
child: Text("Générer un nouveau trousseau",
style: TextStyle(fontSize: 15)))),
style: TextStyle(fontSize: 16)))),
Expanded(
child: Align(
alignment: Alignment.bottomCenter,
@ -90,8 +93,7 @@ class SettingsScreen extends StatelessWidget {
log.i('Suppression de tous les wallets'),
await _myWallets.deleteAllWallet(context)
},
child: Text(
"EFFACER TOUS MES PORTEFEUILLES, LE TEMPS DE L'ALPHA",
child: Text("EFFACER TOUS MES PORTEFEUILLES",
style: TextStyle(fontSize: 20)))))),
SizedBox(height: 50),
]));

View File

@ -35,7 +35,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
version: "2.6.0"
audioplayers:
dependency: "direct main"
description:
@ -926,7 +926,7 @@ packages:
name: vm_service
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.0+1"
version: "6.2.0"
watcher:
dependency: transitive
description:

View File

@ -49,7 +49,7 @@ dependencies:
audioplayers: ^0.18.1
flutter_driver:
sdk: flutter
test: ^1.16.6
test: ^1.16.8
unorm_dart: ^0.2.0
flutter_icons:

View File

@ -30,17 +30,35 @@ void main() {
}
});
// *** Global functions *** //
// Function to tap the widget by key
Future tapOn(String key) async {
await driver.tap(find.byValueKey(key));
}
// Easy get text
Future<String> getText(String text) async {
return await driver.getText(find.byValueKey(
text,
));
}
// Function to go back to previous screen
Future goBack() async {
await Process.run(
'adb',
<String>['shell', 'input', 'keyevent', 'KEYCODE_BACK'],
runInShell: true,
);
}
// Easy sleep
Future sleep(int _time) async {
await Future.delayed(Duration(milliseconds: _time));
}
// Test if widget exist on screen, return a boolean
Future<bool> isPresent(SerializableFinder byValueKey,
{Duration timeout = const Duration(seconds: 1)}) async {
try {
@ -51,6 +69,61 @@ void main() {
}
}
// Create a derivation
Future createDerivation(String _name) async {
await tapOn('addDerivation');
await sleep(100);
await driver.enterText(_name);
await tapOn('validDerivation');
await sleep(300);
}
// Delete a derivation
Future deleteWallet(bool _confirm) async {
await tapOn('deleteWallet');
await sleep(100);
_confirm ? await tapOn('confirmDeleting') : await tapOn('cancelDeleting');
await sleep(300);
}
// Delete all wallets
Future deleteAllWallets() async {
await tapOn('drawerMenu');
await sleep(300);
await tapOn('parameters');
await sleep(300);
await tapOn('deleteAllWallets');
await sleep(300);
await tapOn('confirmDeletingAllWallets');
await sleep(300);
}
// Fast creation of new Keychain
Future<String> createNewKeychain(String name) async {
await tapOn('drawerMenu');
await sleep(300);
await tapOn('parameters');
await sleep(300);
await tapOn('generateKeychain');
while (await getText('generatedPin') == '') {
print('Waiting for pin code generation...');
await sleep(100);
}
pinCode = await getText('generatedPin');
await tapOn('storeKeychain');
await sleep(100);
await driver.enterText('triche');
await tapOn('walletName');
await driver.enterText(name);
await tapOn('confirmStorage');
await sleep(300);
return pinCode;
}
// *** Begin of tests *** //
test('OnBoarding - Open wallets management', (
{timeout: Timeout.none}) async {
// await driver.runUnsynchronized(() async { // Needed if we want to manage async drivers
@ -62,14 +135,9 @@ void main() {
// If a wallet exist, go to delete theme all
if (!await isPresent(find.byValueKey('goStep1'))) {
await goBack();
await tapOn('drawerMenu');
await sleep(300);
await tapOn('parameters');
await sleep(300);
await tapOn('deleteAllWallets');
await sleep(300);
await tapOn('confirmDeletingAllWallets');
await sleep(300);
await deleteAllWallets();
await driver.tap(manageWalletsFinder);
}
@ -186,24 +254,13 @@ void main() {
"Top !\n\nVotre trousseau de clef et votre portefeuille ont été créés avec un immense succès.\n\nFélicitations !");
});
test('My wallets - Create a derivation and display it', (
test('My wallets - Create a derivations, open thems, tap all buttons', (
{timeout: Timeout.none}) async {
await tapOn('goWalletHome');
expect(await getText('myWallets'), "Mes portefeuilles");
await sleep(300);
// Create a derivation
Future createDerivation(String _name) async {
await tapOn('addDerivation');
await sleep(100);
await driver.enterText(_name);
await tapOn('validDerivation');
await sleep(300);
}
// Add a second derivation
await createDerivation('Derivation 2');
@ -240,19 +297,11 @@ void main() {
await sleep(100);
await tapOn('displayBalance');
// Delete a derivation
Future deleteWallet(bool _confirm) async {
await tapOn('deleteWallet');
await sleep(100);
_confirm
? await tapOn('confirmDeleting')
: await tapOn('cancelDeleting');
await sleep(300);
}
// Delete third derivation
await deleteWallet(true);
});
test('My wallets - Extra tests', ({timeout: Timeout.none}) async {
// Add derivation 5,6 and 7
await createDerivation('Derivation 5');
await createDerivation('Derivation 6');
@ -314,7 +363,7 @@ void main() {
await createDerivation('Derivation 20');
await sleep(400);
// Scroll the wallet screen
// Scroll the wallet screen until Derivation 20 and open it
await driver.scrollUntilVisible(
find.byValueKey('listWallets'),
find.text('Derivation 20'),
@ -325,6 +374,10 @@ void main() {
await sleep(400);
await driver.tap(find.text('Derivation 20'));
await tapOn('copyPubkey');
});
test('Search - Search Pi profile, navigate in history transactions', (
{timeout: Timeout.none}) async {
await goBack();
await goBack();
await sleep(200);
@ -351,21 +404,27 @@ void main() {
// await Clipboard.getData(Clipboard.kTextPlain);
// await driver.enterText(pubkeyCopied.text);
await sleep(300);
}, timeout: Timeout(Duration(minutes: globalTimeout)));
test('Wallet generation - Fast wallets generations', (
{timeout: Timeout.none}) async {
await goBack();
await goBack();
await deleteAllWallets();
await sleep(100);
final String pincode = await createNewKeychain('Fast wallet');
await sleep(100);
await tapOn('manageWallets');
await sleep(200);
await driver.enterText(pincode);
await sleep(100);
await createDerivation('Derivation 2');
await sleep(100);
await driver.tap(find.text('Fast wallet'));
await driver.waitFor(find.text('Fast wallet'));
// Wait 3 seconds at the end
await sleep(3000);
}, timeout: Timeout(Duration(minutes: globalTimeout)));
});
}, timeout: Timeout(Duration(minutes: globalTimeout)));
}
// Function to go back to previous screen
Future goBack() async {
await Process.run(
'adb',
<String>['shell', 'input', 'keyevent', 'KEYCODE_BACK'],
runInShell: true,
);
}
Future sleep(int _time) async {
await Future.delayed(Duration(milliseconds: _time));
}