Skip to content

Commit

Permalink
test for receive and send xtz
Browse files Browse the repository at this point in the history
  • Loading branch information
hvthhien committed Jul 8, 2022
1 parent c124584 commit 0da66c6
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 191 deletions.
2 changes: 2 additions & 0 deletions .env.example_testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TEZOS_FAUCET_URL=
TEZOS_FAUCET_AUTH_TOKEN=
152 changes: 97 additions & 55 deletions integration_test/send_xtz_test.dart
Original file line number Diff line number Diff line change
@@ -1,91 +1,133 @@
import 'package:autonomy_flutter/common/injector.dart';
import 'package:autonomy_flutter/database/cloud_database.dart';
import 'package:autonomy_flutter/main.dart';
import 'package:autonomy_flutter/service/configuration_service.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

import '../lib/main.dart' as app;
import 'test_util.dart';

void main() {
void main() async {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('xtz test', () {
testWidgets('send xtz', (tester) async {
app.main();
await tester.pumpAndSettle(Duration(seconds: 2));
await tester.pumpWidget(AutonomyApp());
testWidgets('receive and send xtz', (tester) async {
await onboardingSteps(tester);

await tester.tap(find.byTooltip("Settings"));
await tester.pump(Duration(seconds: 3));

await tester.pumpAndSettle(Duration(seconds: 3));
expect(find.text("Accounts"), findsOneWidget);
await tester.tap(find.text("Default"));

expect(find.text('AUTONOMY'), findsOneWidget);
await tester.pumpAndSettle();

await injector<ConfigurationService>().setFinishedSurvey([Survey.onboarding]);
final xtzWallet = await (await injector<CloudDatabase>()
.personaDao
.getDefaultPersonas())
.first
.wallet()
.getTezosWallet();
await depositTezos(xtzWallet.address);

final Finder startButton = find.text("START");
if (startButton.evaluate().isNotEmpty) {
// Fresh start
await tester.tap(startButton);
await tester.pumpAndSettle(Duration(seconds: 60));

await tester.pumpAndSettle();
final Finder xtzRow = find.text("Tezos (XTZ)");
await tester.tap(xtzRow.first);

final Finder continueButton = find.text("CONTINUE");
await tester.tap(continueButton);
await tester.pumpAndSettle(Duration(seconds: 2));

await tester.pumpAndSettle();
await tester.tap(find.text("SEND"));
await tester.pumpAndSettle();

final Finder notNowButton = find.text("NOT NOW");
if (notNowButton.evaluate().isNotEmpty) {
await tester.tap(notNowButton);
await tester.pumpAndSettle();
}
await tester.enterText(
find.byType(TextField).first, 'tz1Td5qwQxz5mDZiwk7TsRGhDU2HBvXgULip');
await tester.pumpAndSettle(Duration(seconds: 1));
await tester.testTextInput.receiveAction(TextInputAction.done);

final Finder createAccountButton = find.text("No");
await tester.tap(createAccountButton);
await tester.pumpAndSettle(Duration(seconds: 10));

await tester.pumpAndSettle(Duration(seconds: 4));
await tester.pumpAndSettle(Duration(seconds: 1));
await tester.tap(find.textContaining("Max"));
await tester.pumpAndSettle();

final Finder continueButton2 = find.text("CONTINUE");
await tester.tap(continueButton2);
await tester.tap(find.text("REVIEW"));
await tester.pumpAndSettle();

await tester.pumpAndSettle();
await tester.tap(find.text("SEND"));
await tester.pumpAndSettle(Duration(seconds: 10));

final Finder skipButton = find.text("SKIP");
await tester.tap(skipButton);
//Expect to comeback to wallet detail after sending successfully
expect(find.text("SEND"), findsOneWidget);
expect(find.text("RECEIVE"), findsOneWidget);
});
});
}

await tester.pumpAndSettle();
Future<void> onboardingSteps(WidgetTester tester) async {
app.main();
await tester.pumpAndSettle(Duration(seconds: 5));
await tester.pumpWidget(AutonomyApp());

final Finder continueButton3 = find.text("CONTINUE");
await tester.tap(continueButton3);
await tester.pumpAndSettle(Duration(seconds: 3));

await tester.pumpAndSettle(Duration(seconds: 2));
expect(find.text('AUTONOMY'), findsOneWidget);

expect(find.text("Collection"), findsOneWidget);
} else {
//Restore
final Finder restoreButton = find.text("RESTORE");
await tester.tap(restoreButton);
await injector<ConfigurationService>().setFinishedSurvey([Survey.onboarding]);

await tester.pumpAndSettle(Duration(seconds: 3));
final Finder startButton = find.text("START");
if (startButton.evaluate().isNotEmpty) {
// Fresh start
await tester.tap(startButton);

final Finder notNowButton = find.text("NOT NOW");
if (notNowButton.evaluate().isNotEmpty) {
await tester.tap(notNowButton);
await tester.pumpAndSettle();
}
}
await tester.pumpAndSettle();

await tester.tap(find.byTooltip("Settings"));
await tester.pump(Duration(seconds: 1));
final Finder continueButton = find.text("CONTINUE");
await tester.tap(continueButton);

expect(find.text("Accounts"), findsOneWidget);
await tester.tap(find.text("Default"));
await tester.pumpAndSettle();

final Finder notNowButton = find.text("NOT NOW");
if (notNowButton.evaluate().isNotEmpty) {
await tester.tap(notNowButton);
await tester.pumpAndSettle();
});
});
}
}

final Finder createAccountButton = find.text("No");
await tester.tap(createAccountButton);

await tester.pumpAndSettle(Duration(seconds: 4));
await tester.pumpAndSettle(Duration(seconds: 1));

final Finder continueButton2 = find.text("CONTINUE");
await tester.tap(continueButton2);

await tester.pumpAndSettle();

Future<void> addDelay(int ms) async {
await Future<void>.delayed(Duration(milliseconds: ms));
final Finder skipButton = find.text("SKIP");
await tester.tap(skipButton);

await tester.pumpAndSettle();

final Finder continueButton3 = find.text("CONTINUE");
await tester.tap(continueButton3);

await tester.pumpAndSettle(Duration(seconds: 2));

expect(find.text("Collection"), findsOneWidget);
} else {
//Restore
final Finder restoreButton = find.text("RESTORE");
await tester.tap(restoreButton);

await tester.pumpAndSettle(Duration(seconds: 3));

final Finder notNowButton = find.text("NOT NOW");
if (notNowButton.evaluate().isNotEmpty) {
await tester.tap(notNowButton);
await tester.pumpAndSettle();
}
}
}
22 changes: 22 additions & 0 deletions integration_test/test_util.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'dart:convert';

import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:http/http.dart' as http;

Future<void> addDelay(int ms) async {
await Future<void>.delayed(Duration(milliseconds: ms));
}

Future<void> depositTezos(String address) async {
final faucetUrl = dotenv.env['TEZOS_FAUCET_URL'] ?? '';
final token = dotenv.env['TEZOS_FAUCET_AUTH_TOKEN'] ?? '';

await http.post(
Uri.parse(faucetUrl),
body: json.encode({"address": address}),
headers: {
"Content-Type": "application/json",
"Authorization": "Basic $token",
},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import 'package:autonomy_flutter/screen/app_router.dart';
import 'package:autonomy_flutter/screen/settings/crypto/wallet_detail/tezos_transaction_row_view.dart';
import 'package:autonomy_flutter/util/error_handler.dart';
import 'package:autonomy_flutter/util/style.dart';
import 'package:autonomy_flutter/util/ui_helper.dart';
import 'package:flutter/material.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';

class TezosTXListView extends StatefulWidget {
final Future<String> address;
final String address;

const TezosTXListView({Key? key, required this.address}) : super(key: key);

@override
Expand All @@ -39,7 +39,9 @@ class _TezosTXListViewState extends State<TezosTXListView> {
}

Future<void> _fetchPage(int pageKey) async {
final address = await widget.address;
final address = widget.address;

if (address.isEmpty) return;

try {
final newItems = await injector<TZKTApi>().getOperations(
Expand Down Expand Up @@ -71,53 +73,48 @@ class _TezosTXListViewState extends State<TezosTXListView> {

@override
Widget build(BuildContext context) {
return FutureBuilder<String>(
builder: (context, snapshot) {
return snapshot.hasData
? CustomScrollView(
slivers: [
PagedSliverList.separated(
pagingController: _pagingController,
builderDelegate: PagedChildBuilderDelegate<TZKTOperation>(
animateTransitions: true,
newPageErrorIndicatorBuilder: (context) {
return Container(
padding: EdgeInsets.only(top: 30),
child: Text(
"Currently unable to load transaction data from tzkt.io.",
style: appTextTheme.bodyText1),
);
},
noItemsFoundIndicatorBuilder: (context) {
return Container(
padding: EdgeInsets.only(top: 30),
child: Text("Your transactions will appear here.",
style: appTextTheme.bodyText1),
);
},
itemBuilder: (context, item, index) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
child: TezosTXRowView(
tx: item, currentAddress: snapshot.data!),
onTap: () => Navigator.of(context).pushNamed(
AppRouter.tezosTXDetailPage,
arguments: {
"current_address": snapshot.data,
"tx": item,
},
),
);
},
),
separatorBuilder: (context, index) {
return Divider();
})
],
)
: Container();
},
future: widget.address,
);
return widget.address.isEmpty
? SizedBox()
: CustomScrollView(
slivers: [
PagedSliverList.separated(
pagingController: _pagingController,
builderDelegate: PagedChildBuilderDelegate<TZKTOperation>(
animateTransitions: true,
newPageErrorIndicatorBuilder: (context) {
return Container(
padding: EdgeInsets.only(top: 30),
child: Text(
"Currently unable to load transaction data from tzkt.io.",
style: appTextTheme.bodyText1),
);
},
noItemsFoundIndicatorBuilder: (context) {
return Container(
padding: EdgeInsets.only(top: 30),
child: Text("Your transactions will appear here.",
style: appTextTheme.bodyText1),
);
},
itemBuilder: (context, item, index) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
child: TezosTXRowView(
tx: item, currentAddress: widget.address),
onTap: () => Navigator.of(context).pushNamed(
AppRouter.tezosTXDetailPage,
arguments: {
"current_address": widget.address,
"tx": item,
},
),
);
},
),
separatorBuilder: (context, index) {
return Divider();
})
],
);
}
}
Loading

0 comments on commit 0da66c6

Please sign in to comment.