add certtification workflow test

This commit is contained in:
poka 2022-08-24 21:53:16 +02:00
parent fbc8cbd0d9
commit a03f711539
15 changed files with 245 additions and 150 deletions

View File

@ -1,105 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/models/widgets_keys.dart';
import 'package:integration_test/integration_test.dart';
import 'package:gecko/main.dart' as app;
import 'tests_utility.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('Ğecko basics', () {
testWidgets('Import chests', (tester) async {
app.main();
await tester.pumpAndSettle(const Duration(seconds: 1));
// Change Duniter endpoint to local
await changeNode(tester);
// Delete all existing chests
await deleteAllWallets(tester);
// Restore a chest
await restoreChest(tester);
// Execute a transaction to test2
await payTest2(tester);
});
});
}
Future changeNode(WidgetTester tester) async {
final ipAddress = dotenv.env['ip_address'] ?? '127.0.0.1';
log.d('ip address: $ipAddress');
await goKey(tester, keyDrawerMenu);
await goKey(tester, keyParameters);
await goKey(tester, keySelectDuniterNodeDropDown, duration: 5);
await goKey(tester, keySelectDuniterNode('Personnalisé'), selectLast: true);
await enterText(tester, keyCustomDuniterEndpoint, 'ws://$ipAddress:9944');
// await sleep(tester, 10000);
await goKey(tester, keyConnectToEndpoint);
await isIconPresent(tester, Icons.add_card_sharp,
timeout: const Duration(seconds: 8));
await goBack(tester);
// await waitFor(tester, 'Vous êtes bien connecté');
}
// Customs actions
Future deleteAllWallets(WidgetTester tester) async {
if (await isPresent(tester, 'Rechercher')) {
await goKey(tester, keyDrawerMenu);
await goKey(tester, keyParameters);
await goKey(tester, keyDeleteAllWallets);
await goKey(tester, keyConfirm);
await tester.pumpAndSettle();
}
}
Future restoreChest(WidgetTester tester) async {
await goKey(tester, keyRestoreChest);
Clipboard.setData(const ClipboardData(
text:
'pipe paddle ketchup filter life ice feel embody glide quantum ride usage'));
await tester.pumpAndSettle();
await goKey(tester, keyPastMnemonic);
await tester.pumpAndSettle();
await goKey(tester, keyGoNext);
await goKey(tester, keyGoNext);
await goKey(tester, keyGoNext);
await goKey(tester, keyGoNext);
final isCached = await isIconPresent(tester, Icons.check_box);
if (!isCached) await goKey(tester, keyCachePassword);
await enterText(tester, keyPinForm, 'AAAAA');
await waitFor(tester, 'Accéder à mon coffre');
await goKey(tester, keyGoWalletsHome);
await waitFor(tester, 'ĞD');
await goBack(tester);
await waitFor(tester, "y'a pas de lézard");
}
Future payTest2(WidgetTester tester) async {
await waitFor(tester, 'Rechercher');
await goKey(tester, keyOpenSearch);
await enterText(tester, keySearchField,
'5E4i8vcNjnrDp21Sbnp32WHm2gz8YP3GGFwmdpfg5bHd8Whb');
await goKey(tester, keyConfirmSearch);
await waitFor(tester, 'Hd8Whb');
await goKey(tester,
keySearchResult('5E4i8vcNjnrDp21Sbnp32WHm2gz8YP3GGFwmdpfg5bHd8Whb'));
await waitFor(tester, 'Hd8Whb');
await waitFor(tester, 'ĞD');
await goKey(tester, keyPay);
await enterText(tester, keyAmountField, '2.14');
await goKey(tester, keyConfirmPayment);
await sleep(tester);
await spawnBlock(tester, keyCloseTransactionScreen);
await waitFor(tester, 'validé !', timeout: const Duration(seconds: 1));
await goKey(tester, keyCloseTransactionScreen);
await waitFor(tester, 'Hd8Whb');
}

View File

@ -2,7 +2,7 @@
"first_ud": 10000,
"first_ud_reeval": 100,
"genesis_parameters": {
"genesis_certs_expire_on": 2102400,
"genesis_certs_expire_on": 50,
"genesis_certs_min_received": 3,
"genesis_memberships_expire_on": 1051200,
"genesis_smith_certs_expire_on": 2102400,

View File

@ -0,0 +1,193 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/models/widgets_keys.dart';
import 'package:integration_test/integration_test.dart';
import 'package:gecko/main.dart' as app;
import 'tests_utility.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('Gecko complete', (tester) async {
app.main();
await tester.pumpAndSettle(const Duration(seconds: 1));
// Change Duniter endpoint to local
await changeNode(tester);
// Delete all existing chests
await deleteAllWallets(tester);
// Restore a chest
await restoreChest(tester);
// Execute a transaction to test2
await payTest2(tester);
// Certify test5 account with 3 account to become member
await certifyTest5(tester);
});
}
Future changeNode(WidgetTester tester) async {
final ipAddress = dotenv.env['ip_address'] ?? '127.0.0.1';
log.d('ip address: $ipAddress');
await goKey(tester, keyDrawerMenu);
await goKey(tester, keyParameters);
await goKey(tester, keySelectDuniterNodeDropDown, duration: 5);
await goKey(tester, keySelectDuniterNode('Personnalisé'), selectLast: true);
await enterText(tester, keyCustomDuniterEndpoint, 'ws://$ipAddress:9944');
// await sleep(tester, 10000);
await goKey(tester, keyConnectToEndpoint);
await isIconPresent(tester, Icons.add_card_sharp,
timeout: const Duration(seconds: 8));
await goBack(tester);
// await waitFor(tester, 'Vous êtes bien connecté');
}
// Customs actions
Future deleteAllWallets(WidgetTester tester) async {
if (await isPresent(tester, 'Rechercher')) {
await goKey(tester, keyDrawerMenu);
await goKey(tester, keyParameters);
await goKey(tester, keyDeleteAllWallets);
await goKey(tester, keyConfirm);
await tester.pumpAndSettle();
}
}
Future restoreChest(WidgetTester tester) async {
await goKey(tester, keyRestoreChest);
Clipboard.setData(const ClipboardData(
text:
'pipe paddle ketchup filter life ice feel embody glide quantum ride usage'));
await tester.pumpAndSettle();
await goKey(tester, keyPastMnemonic);
await tester.pumpAndSettle();
await goKey(tester, keyGoNext);
await goKey(tester, keyGoNext);
await goKey(tester, keyGoNext);
await goKey(tester, keyGoNext);
final isCached = await isIconPresent(tester, Icons.check_box);
if (!isCached) await goKey(tester, keyCachePassword);
await enterText(tester, keyPinForm, 'AAAAA');
await waitFor(tester, 'Accéder à mon coffre');
await goKey(tester, keyGoWalletsHome);
await waitFor(tester, 'ĞD');
// Test add a new derivation
await addDerivation(tester);
await goKey(tester,
keyOpenWallet('5Dq3giahrBfykJogPetZJ2jjSmhw49Fa7i6qKkseUvRJ2T3R'));
await goKey(tester, keyCopyAddress);
await waitFor(tester, 'Cette adresse a été copié');
await goBack(tester);
await goBack(tester);
await waitFor(tester, "y'a pas de lézard");
}
Future payTest2(WidgetTester tester) async {
await waitFor(tester, 'Rechercher');
await goKey(tester, keyOpenSearch);
final addressToSearch = (await Clipboard.getData('text/plain'))!.text;
final endAddress = addressToSearch!.substring(addressToSearch.length - 6);
expect(addressToSearch, '5Dq3giahrBfykJogPetZJ2jjSmhw49Fa7i6qKkseUvRJ2T3R');
await enterText(tester, keySearchField, addressToSearch);
await goKey(tester, keyConfirmSearch);
await waitFor(tester, endAddress);
await goKey(tester, keySearchResult(addressToSearch));
await waitFor(tester, endAddress);
await waitFor(tester, '0.0 ĞD');
await goKey(tester, keyPay);
await enterText(tester, keyAmountField, '12.14');
await goKey(tester, keyConfirmPayment);
// await sleep(tester);
await spawnBlock(tester, keyCloseTransactionScreen);
await waitFor(tester, 'validé !', timeout: const Duration(seconds: 1));
await goKey(tester, keyCloseTransactionScreen);
await waitFor(tester, '12.14');
await spawnBlock(tester, keyViewActivity);
await waitFor(tester, '9.14');
}
Future addDerivation(WidgetTester tester) async {
await goKey(tester, keyAddDerivation);
await waitFor(tester, 'Portefeuille 5');
}
Future certifyTest5(WidgetTester tester) async {
// Create identity with Test1 account
// await spawnBlock(tester, keyViewActivity, 5);
// await sleep(tester);
await goKey(tester, keyCertify);
await goKey(tester, keyConfirm);
await spawnBlock(tester, keyViewActivity);
await waitFor(tester, 'validé !', timeout: const Duration(seconds: 1));
await goKey(tester, keyCloseTransactionScreen);
await waitFor(tester, 'Identité créée');
// Confirm Identity Test5
await goKey(tester, keyAppBarChest, duration: 300);
await goKey(tester,
keyOpenWallet('5Dq3giahrBfykJogPetZJ2jjSmhw49Fa7i6qKkseUvRJ2T3R'));
await goKey(tester, keyCopyAddress);
await goKey(tester, keyConfirmIdentity);
await enterText(tester, keyEnterIdentityUsername, 'test5');
await goKey(tester, keyConfirm);
await spawnBlock(tester, keyCloseTransactionScreen);
await waitFor(tester, 'validé !', timeout: const Duration(seconds: 1));
await goKey(tester, keyCloseTransactionScreen);
await waitFor(tester, 'Identité confirmée');
await goBack(tester);
await goKey(tester,
keyOpenWallet('5E4i8vcNjnrDp21Sbnp32WHm2gz8YP3GGFwmdpfg5bHd8Whb'));
await goKey(tester, keySetDefaultWallet);
await waitFor(tester, 'Ce portefeuille est celui par defaut');
await goKey(tester, keyAppBarSearch);
final addressToSearch = (await Clipboard.getData('text/plain'))!.text;
final endAddress = addressToSearch!.substring(addressToSearch.length - 6);
expect(addressToSearch, '5Dq3giahrBfykJogPetZJ2jjSmhw49Fa7i6qKkseUvRJ2T3R');
await enterText(tester, keySearchField, addressToSearch);
await goKey(tester, keyConfirmSearch);
await waitFor(tester, endAddress);
await goKey(tester, keySearchResult(addressToSearch));
await waitFor(tester, endAddress);
await waitFor(tester, '1');
// Certify with test2 account
await goKey(tester, keyCertify);
await goKey(tester, keyConfirm);
await spawnBlock(tester, keyViewActivity);
await waitFor(tester, 'validé !', timeout: const Duration(seconds: 1));
await goKey(tester, keyCloseTransactionScreen);
await waitFor(tester, '2');
// Change default wallet to test3
await goKey(tester, keyPay);
await goKey(tester, keyChangeChest);
await goKey(tester,
keySelectThisWallet('5FhTLzXLNBPmtXtDBFECmD7fvKmTtTQDtvBTfVr97tachA1p'));
await goKey(tester, keyConfirm);
await sleep(tester);
// Certify with test3 account
await goKey(tester, keyCertify);
await goKey(tester, keyConfirm);
await spawnBlock(tester, keyViewActivity);
await waitFor(tester, 'validé !', timeout: const Duration(seconds: 1));
await goKey(tester, keyCloseTransactionScreen);
await waitFor(tester, 'Vous devez attendre');
// Check if test5 is member
await goKey(tester, keyAppBarChest, duration: 300);
await goKey(tester,
keyOpenWallet('5Dq3giahrBfykJogPetZJ2jjSmhw49Fa7i6qKkseUvRJ2T3R'));
await waitFor(tester, 'Membre validé !');
}

View File

@ -4,7 +4,8 @@
# MP="`( cd \"$MP\" && pwd )`"
# cd $MP
args="$@"
testName=$1
[[ ! $testName ]] && testName='gecko_complete'
# Get local IP and set .env
ip_address=$(hostname -I | awk '{print $1}')
@ -18,7 +19,7 @@ docker-compose up -d
cd ../..
# Start integration test
flutter test integration_test/app_test.dart
flutter test integration_test/$testName.dart
# Stop Duniter
cd integration_test/duniter

View File

@ -1,10 +1,11 @@
// CUSTOM METHODES
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:provider/provider.dart';
// CUSTOM METHODS
Future sleep(WidgetTester tester, [int time = 1000]) async {
await Future.delayed(Duration(milliseconds: time));
}
@ -72,17 +73,10 @@ Future<bool> isIconPresent(WidgetTester tester, IconData icon,
return finder.evaluate().isEmpty ? false : true;
}
Future spawnBlock(WidgetTester tester, Key customKey) async {
final BuildContext context =
tester.element(find.byKey(customKey));
Future spawnBlock(WidgetTester tester, Key customKey, [int number = 1]) async {
await sleep(tester, 1000);
final BuildContext context = tester.element(find.byKey(customKey));
SubstrateSdk sub = Provider.of<SubstrateSdk>(context, listen: false);
await sub.spawnBlock();
}
extension Truncate on String {
String truncate({required int max, String suffix = ''}) {
return length < max
? this
: '${substring(0, substring(0, max - suffix.length).lastIndexOf(" "))}$suffix';
}
sub.spawnBlock(number);
await sleep(tester, 500);
}

View File

@ -110,7 +110,7 @@ Future<void> main() async {
supportedLocales: const [Locale('en'), Locale('fr'), Locale('es')],
path: 'assets/translations',
fallbackLocale: const Locale('en'),
child: Gecko(indexerEndpoint),
child: const Gecko(),
),
),
);
@ -122,15 +122,14 @@ Future<void> main() async {
supportedLocales: const [Locale('en'), Locale('fr'), Locale('es')],
path: 'assets/translations',
fallbackLocale: const Locale('en'),
child: Gecko(indexerEndpoint),
child: const Gecko(),
),
);
}
}
class Gecko extends StatelessWidget {
const Gecko(this.indexerEndpoint, {Key? key}) : super(key: key);
final String? indexerEndpoint;
const Gecko({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {

View File

@ -5,6 +5,9 @@ const keyInfoPopup = Key('keyInfoPopup');
const keyGoNext = Key('keyGoNext');
const keyCancel = Key('keyCancel');
const keyConfirm = Key('keyConfirm');
const keyAppBarSearch = Key('keyAppBarSearch');
const keyAppBarQrcode = Key('keyAppBarQrcode');
const keyAppBarChest = Key('keyAppBarChest');
// Home
const keyParameters = Key('keyParameters');
@ -28,6 +31,8 @@ const keySetDefaultWallet = Key('keySetDefaultWallet');
const keyDeleteWallet = Key('keyDeleteWallet');
const keyWalletName = Key('keyWalletName');
const keyRenameWallet = Key('keyRenameWallet');
const keyConfirmIdentity = Key('keyConfirmIdentity');
const keyEnterIdentityUsername = Key('keyEnterIdentityUsername');
// Chest options
const keyShowSeed = Key('keyShowSeed');
@ -79,7 +84,9 @@ const keySearchField = Key('keySearchField');
const keyConfirmSearch = Key('keyConfirmSearch');
// Unit keys
Key keyMnemonicWord(String word) => Key('keyMnemonicWord$word');
Key keyTransaction(int keyId) => Key('keyTransaction$keyId');
Key keyMnemonicWord(String word) => Key('keyMnemonicWord$word');
Key keySearchResult(String keyId) => Key('keySearchResult$keyId');
Key keySelectDuniterNode(String keyId) => Key('keySelectDuniterNode$keyId');
Key keyOpenWallet(String keyId) => Key('keyOpenWallet$keyId');
Key keySelectThisWallet(String keyId) => Key('keySelectThisWallet$keyId');

View File

@ -11,6 +11,7 @@ import 'package:flutter/services.dart';
import 'dart:async';
import 'package:gecko/globals.dart';
import 'package:gecko/models/wallet_data.dart';
import 'package:gecko/models/widgets_keys.dart';
import 'package:gecko/providers/my_wallets.dart';
import 'package:gecko/providers/wallets_profiles.dart';
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
@ -148,6 +149,7 @@ class HomeProvider with ChangeNotifier {
const Spacer(),
const SizedBox(width: 11),
IconButton(
key: keyAppBarSearch,
iconSize: 40,
icon: const Image(image: AssetImage('assets/loupe-noire.png')),
onPressed: () {
@ -165,7 +167,7 @@ class HomeProvider with ChangeNotifier {
),
const SizedBox(width: 22),
const Spacer(),
IconButton(
IconButton(key: keyAppBarQrcode,
iconSize: 70,
icon: const Image(image: AssetImage('assets/qrcode-scan.png')),
onPressed: () async {
@ -178,7 +180,7 @@ class HomeProvider with ChangeNotifier {
),
const Spacer(),
const SizedBox(width: 15),
IconButton(
IconButton(key: keyAppBarChest,
iconSize: 60,
icon: const Image(image: AssetImage('assets/wallet.png')),
onPressed: () async {

View File

@ -941,8 +941,7 @@ newKeySig: $newKeySig""");
Future spawnBlock([int number = 1]) async {
for (var i = 1; i <= number; i++) {
await sdk.webView!
.evalJavascript('api.rpc.engine.createBlock(true, true)');
sdk.webView!.evalJavascript('api.rpc.engine.createBlock(true, true)');
}
}

View File

@ -238,7 +238,7 @@ class WalletOptionsProvider with ChangeNotifier {
height: 100,
child: Column(children: [
const SizedBox(height: 20),
TextField(
TextField(key: keyEnterIdentityUsername,
onChanged: (_) => notifyListeners(),
inputFormatters: <TextInputFormatter>[
// FilteringTextInputFormatter.allow(RegExp("[0-9a-zA-Z]")),
@ -259,7 +259,7 @@ class WalletOptionsProvider with ChangeNotifier {
Consumer<WalletOptionsProvider>(
builder: (context, wOptions, _) {
return TextButton(
key: keyInfoPopup,
key: keyConfirm,
child: Text(
"validate".tr(),
style: TextStyle(

View File

@ -132,22 +132,24 @@ class HomeScreen extends StatelessWidget {
// sub.nodeConnected = false;
// }
HomeProvider homeProvider =
Provider.of<HomeProvider>(ctx, listen: false);
Connectivity()
.onConnectivityChanged
.listen((ConnectivityResult result) async {
log.d('Network changed: $result');
if (result == ConnectivityResult.none) {
sub.nodeConnected = false;
await sub.sdk.api.setting.unsubscribeBestNumber();
homeProvider.changeMessage(
"notConnectedToInternet".tr(), 0);
sub.reload();
} else {
await sub.connectNode(ctx);
}
});
// TODO: fix random bad network status on startup
// HomeProvider homeProvider =
// Provider.of<HomeProvider>(ctx, listen: false);
// Connectivity()
// .onConnectivityChanged
// .listen((ConnectivityResult result) async {
// log.d('Network changed: $result');
// if (result == ConnectivityResult.none) {
// sub.nodeConnected = false;
// await sub.sdk.api.setting.unsubscribeBestNumber();
// homeProvider.changeMessage(
// "notConnectedToInternet".tr(), 0);
// sub.reload();
// } else {
// await sub.connectNode(ctx);
// }
// });
await sub.connectNode(ctx);
}
// _duniterIndexer.checkIndexerEndpointBackground();
});

View File

@ -47,6 +47,7 @@ class ChooseWalletScreen extends StatelessWidget {
width: 470,
height: 70,
child: ElevatedButton(
key: keyConfirm,
style: ElevatedButton.styleFrom(
elevation: 4,
primary: orangeC, // background
@ -123,6 +124,7 @@ class ChooseWalletScreen extends StatelessWidget {
Padding(
padding: const EdgeInsets.all(16),
child: GestureDetector(
key: keySelectThisWallet(repository.address!),
onTap: () {
selectedWallet = repository;
myWalletProvider.rebuildWidget();

View File

@ -292,7 +292,7 @@ class WalletOptions extends StatelessWidget {
SizedBox(
width: 320,
height: 60,
child: ElevatedButton(
child: ElevatedButton(key: keyConfirmIdentity,
style: ElevatedButton.styleFrom(
elevation: 4,
primary: orangeC, // background

View File

@ -200,6 +200,7 @@ class WalletsHome extends StatelessWidget {
Padding(
padding: const EdgeInsets.all(16),
child: GestureDetector(
key: keyOpenWallet(repository.address!),
onTap: () {
walletOptions.getAddress(
currentChestNumber, repository.derivation!);

View File

@ -481,7 +481,7 @@ class WalletViewScreen extends StatelessWidget {
),
const SizedBox(height: 10),
Consumer<SubstrateSdk>(builder: (context, sub, _) {
return InkWell(
return InkWell(key: keyChangeChest,
onTap: () async {
String? pin;
if (myWalletProvider.pinCode == '') {