can spawn new block just after transactions

This commit is contained in:
poka 2022-08-24 06:36:26 +02:00
parent afae4130a6
commit 5744155400
9 changed files with 90 additions and 37 deletions

View File

@ -4,8 +4,10 @@ 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:gecko/providers/substrate_sdk.dart';
import 'package:integration_test/integration_test.dart';
import 'package:gecko/main.dart' as app;
import 'package:provider/provider.dart';
import 'tests_utility.dart';
void main() {
@ -15,9 +17,9 @@ void main() {
testWidgets('Import chests', (tester) async {
app.main();
await tester.pumpAndSettle(const Duration(seconds: 1));
final ipAddress = dotenv.env['ip_address'] ?? '127.0.0.1';
log.d('ip address: $ipAddress');
// Change Duniter endpoint to local
await changeNode(tester);
// Delete all existing chests
await deleteAllWallets(tester);
@ -25,12 +27,33 @@ void main() {
// Restore a chest
await restoreChest(tester);
// Execute a transaction to ChristCosmic
await payChrist(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);
// final BuildContext context = tester.element(find.byKey(keyDrawerMenu));
// SubstrateSdk sub = Provider.of<SubstrateSdk>(context, listen: false);
// await sub.spawnBlock(3);
// await waitFor(tester, 'Vous êtes bien connecté');
}
// Customs actions
Future deleteAllWallets(WidgetTester tester) async {
if (await isPresent(tester, 'Rechercher')) {
@ -46,7 +69,7 @@ Future restoreChest(WidgetTester tester) async {
await goKey(tester, keyRestoreChest);
Clipboard.setData(const ClipboardData(
text:
'smart joy blossom stomach champion fun diary relief gossip hospital logic bike'));
'pipe paddle ketchup filter life ice feel embody glide quantum ride usage'));
await tester.pumpAndSettle();
await goKey(tester, keyPastMnemonic);
await tester.pumpAndSettle();
@ -64,20 +87,27 @@ Future restoreChest(WidgetTester tester) async {
await waitFor(tester, "y'a pas de lézard");
}
Future payChrist(WidgetTester tester) async {
Future payTest2(WidgetTester tester) async {
await waitFor(tester, 'Rechercher');
await goKey(tester, keyOpenSearch);
await enterText(tester, keySearchField, 'ChristCosmic');
await enterText(tester, keySearchField,
'5E4i8vcNjnrDp21Sbnp32WHm2gz8YP3GGFwmdpfg5bHd8Whb');
await goKey(tester, keyConfirmSearch);
await waitFor(tester, 'XuiQeB');
await waitFor(tester, 'Hd8Whb');
await goKey(tester,
keyIndexerResult('5CJKhFCpdSpumgWjSZ3TQmejJuHV6iELJrtdrfs38SXuiQeB'));
await waitFor(tester, 'XuiQeB');
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 waitFor(tester, 'validé !', timeout: const Duration(seconds: 12));
await sleep(tester);
final BuildContext context =
tester.element(find.byKey(keyCloseTransactionScreen));
SubstrateSdk sub = Provider.of<SubstrateSdk>(context, listen: false);
await sub.spawnBlock();
await waitFor(tester, 'validé !', timeout: const Duration(seconds: 1));
await goKey(tester, keyCloseTransactionScreen);
await waitFor(tester, 'XuiQeB');
await waitFor(tester, 'Hd8Whb');
}

View File

@ -1,8 +1,8 @@
{
"first_ud": 1000,
"first_ud": 10000,
"first_ud_reeval": 100,
"genesis_parameters": {
"genesis_certs_expire_on": 10,
"genesis_certs_expire_on": 2102400,
"genesis_certs_min_received": 3,
"genesis_memberships_expire_on": 1051200,
"genesis_smith_certs_expire_on": 2102400,
@ -11,22 +11,22 @@
},
"identities": {
"test1": {
"balance": 1000,
"balance": 10000,
"certs": ["test2", "test3", "test4"],
"pubkey": "5FeggKqw2AbnGZF9Y9WPM2QTgzENS3Hit94Ewgmzdg5a3LNa"
},
"test2": {
"balance": 1000,
"balance": 10000,
"certs": ["test1", "test3", "test4"],
"pubkey": "5E4i8vcNjnrDp21Sbnp32WHm2gz8YP3GGFwmdpfg5bHd8Whb"
},
"test3": {
"balance": 1000,
"balance": 10000,
"certs": ["test1", "test2", "test4"],
"pubkey": "5FhTLzXLNBPmtXtDBFECmD7fvKmTtTQDtvBTfVr97tachA1p"
},
"test4": {
"balance": 1000,
"balance": 10000,
"certs": ["test1", "test2", "test3"],
"pubkey": "5DXJ4CusmCg8S1yF6JGVn4fxgk5oFx42WctXqHZ17mykgje5"
}
@ -50,10 +50,10 @@
"smith_membership_period": 1000,
"smith_pending_membership_period": 500,
"smiths_wot_first_cert_issuable_on": 20,
"smiths_wot_min_cert_for_membership": 2,
"wot_first_cert_issuable_on": 20,
"wot_min_cert_for_create_idty_right": 2,
"wot_min_cert_for_membership": 2
"smiths_wot_min_cert_for_membership": 3,
"wot_first_cert_issuable_on": 0,
"wot_min_cert_for_create_idty_right": 3,
"wot_min_cert_for_membership": 3
},
"smiths": {
"test1": {

View File

@ -12,6 +12,7 @@ echo "ip_address=$ip_address" > .env
## Start local Duniter node
cd integration_test/duniter
docker-compose down
rm -rf data/chains
docker-compose up -d
cd ../..

View File

@ -3,12 +3,16 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:gecko/globals.dart';
Future sleep(WidgetTester tester, [int time = 1000]) async {
await Future.delayed(Duration(milliseconds: time));
}
Future goKey(WidgetTester tester, Key buttonKey,
{Finder? customFinder, int duration = 100}) async {
{Finder? customFinder, int duration = 100, bool selectLast = false}) async {
await tester.pumpAndSettle(Duration(milliseconds: duration));
final Finder finder = customFinder ?? find.byKey(buttonKey);
log.d('INTEGRATION TEST: Tap on ${finder.description}}');
await tester.tap(finder);
await tester.tap(selectLast ? finder.last : finder);
// await tester.pumpAndSettle(Duration(milliseconds: duration));
}
@ -38,7 +42,6 @@ Future<void> waitFor(
do {
if (DateTime.now().isAfter(end)) {
throw Exception('Timed out waiting for text $text');
}

View File

@ -61,6 +61,9 @@ const keyCachePassword = Key('keyCachePassword');
// Settings
const keyDeleteAllWallets = Key('keyDeleteAllWallets');
const keySelectDuniterNodeDropDown = Key('keySelectDuniterNodeDropDown');
const keyCustomDuniterEndpoint = Key('keyCustomDuniterEndpoint');
const keyConnectToEndpoint = Key('keyConnectToEndpoint');
// Onboarding
const keyPastMnemonic = Key('keyPastMnemonic');
@ -77,6 +80,6 @@ const keyConfirmSearch = Key('keyConfirmSearch');
// Unit keys
Key keyMnemonicWord(String word) => Key('keyMnemonicWord$word');
Key keyIndexerResult(String keyId) => Key('keyIndexerResult$keyId');
Key keyTransaction(int keyId) => Key('keyTransaction$keyId');
Key keySearchResult(String keyId) => Key('keySearchResult$keyId');
Key keySelectDuniterNode(String keyId) => Key('keySelectDuniterNode$keyId');

View File

@ -301,7 +301,7 @@ class DuniterIndexer with ChangeNotifier {
Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
child: ListTile(
key: keyIndexerResult(profile['id']),
key: keySearchResult(profile['id']),
horizontalTitleGap: 40,
contentPadding: const EdgeInsets.all(5),
leading: cesiumPlusProvider.defaultAvatar(avatarSize),

View File

@ -873,7 +873,6 @@ newKeySig: $newKeySig""");
keyring.current.pubKey,
);
log.d(sender.address);
TxInfoData txInfo;
txInfo = TxInfoData(
@ -940,6 +939,13 @@ newKeySig: $newKeySig""");
await sdk.api.keyring.deleteAccount(keyring, keypair);
}
Future spawnBlock([int number = 1]) async {
for (var i = 1; i <= number; i++) {
await sdk.webView!
.evalJavascript('api.rpc.engine.createBlock(true, true)');
}
}
void reload() {
notifyListeners();
}

View File

@ -40,6 +40,9 @@ class HomeScreen extends StatelessWidget {
final bool isWalletsExists = myWalletProvider.checkIfWalletExist();
// sub.spawnBlock();
// log.d('message');
isTall = false;
ratio = 1;
if (MediaQuery.of(context).size.height >= 930) {
@ -122,17 +125,18 @@ class HomeScreen extends StatelessWidget {
myWalletProvider.rebuildWidget();
}
var connectivityResult =
await (Connectivity().checkConnectivity());
// var connectivityResult =
// await (Connectivity().checkConnectivity());
// if (connectivityResult != ConnectivityResult.mobile &&
// connectivityResult != ConnectivityResult.wifi) {
// homeProvider.changeMessage(
// "notConnectedToInternet".tr(), 0);
// sub.nodeConnected = false;
// }
HomeProvider homeProvider =
Provider.of<HomeProvider>(ctx, listen: false);
if (connectivityResult != ConnectivityResult.mobile &&
connectivityResult != ConnectivityResult.wifi) {
homeProvider.changeMessage(
"notConnectedToInternet".tr(), 0);
sub.nodeConnected = false;
}
Connectivity()
.onConnectivityChanged
.listen((ConnectivityResult result) async {

View File

@ -116,11 +116,14 @@ class SettingsScreen extends StatelessWidget {
Icon(sub.nodeConnected && !sub.isLoadingEndpoint
? Icons.check
: Icons.close),
if (sub.nodeConnected && !sub.isLoadingEndpoint)
const Icon(Icons.add_card_sharp, size: 0.01),
const Spacer(),
SizedBox(
width: 265,
child: Consumer<SettingsProvider>(builder: (context, set, _) {
return DropdownButtonHideUnderline(
key: keySelectDuniterNodeDropDown,
child: DropdownButton(
// alignment: AlignmentDirectional.topStart,
value: selectedDuniterEndpoint,
@ -128,6 +131,7 @@ class SettingsScreen extends StatelessWidget {
items: duniterBootstrapNodes
.map((NetworkParams endpointParams) {
return DropdownMenuItem(
key: keySelectDuniterNode(endpointParams.endpoint!),
value: endpointParams.endpoint,
child: Text(endpointParams.endpoint!),
);
@ -146,6 +150,7 @@ class SettingsScreen extends StatelessWidget {
? CircularProgressIndicator(color: orangeC)
: Consumer<SettingsProvider>(builder: (context, set, _) {
return IconButton(
key: keyConnectToEndpoint,
icon: Icon(
Icons.send,
color: selectedDuniterEndpoint !=
@ -186,6 +191,7 @@ class SettingsScreen extends StatelessWidget {
width: 200,
height: 50,
child: TextField(
key: keyCustomDuniterEndpoint,
controller: endpointController,
autocorrect: false,
),