mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 03:59:23 +00:00
0fcfd76afd
Some checks failed
Cache Dependencies / test (push) Has been cancelled
* feat: Integration tests setup and tests for Disclaimer, Welcome and Setup Pin Code pages * feat: Integration test flow from start to restoring a wallet successfully done * test: Dashboard view test and linking to flow * feat: Testing the Exchange flow section, selecting sending and receiving currencies * test: Successfully create an exchange section * feat: Implement flow up to sending section * test: Complete Exchange flow * fix dependency issue * test: Final cleanups * feat: Add CI to run automated integration tests withan android emulator * feat: Adjust Automated integration test CI to run on ubuntu 20.04-a * fix: Move integration test CI into PR test build CI * ci: Add automated test ci which is a streamlined replica of pr test build ci * ci: Re-add step to access branch name * ci: Add KVM * ci: Add filepath to trigger the test run from * ci: Add required key * ci: Add required key * ci: Add missing secret key * ci: Add missing secret key * ci: Add nano secrets to workflow * ci: Switch step to free space on runner * ci: Remove timeout from workflow * ci: Confirm impact that removing copy_monero_deps would have on entire workflow time * ci: Update CI and temporarily remove cache related to emulator * ci: Remove dynamic java version * ci: Temporarily switch CI * ci: Switch to 11.x jdk * ci: Temporarily switch CI * ci: Revert ubuntu version * ci: Add more api levels * ci: Add more target options * ci: Settled on stable emulator matrix options * ci: Add more target options * ci: Modify flow * ci: Streamline api levels to 28 and 29 * ci: One more trial * ci: Switch to flutter drive * ci: Reduce options * ci: Remove haven from test * ci: Check for solana in list * ci: Adjust amounts and currencies for exchange flow * ci: Set write response on failure to true * ci: Split ci to funds and non funds related tests * test: Test for Send flow scenario and minor restructuring for test folders and files * chore: cleanup * ci: Pause CI for now * ci: Pause CI for now * ci: Pause CI for now * test: Restore wallets integration automated tests * Fix: Add keys back to currency amount textfield widget * fix: Switch variable name * fix: remove automation for now * tests: Automated tests for Create wallets flow * tests: Further optimize common flows * tests: Add missing await for call * tests: Confirm Seeds Display Properly WIP * tests: Confirm Seeds Display Correctly Automated Tests * fix: Add missing pubspec params for bitcoin and bitcoin_cash * feat: Automated Tests for Transaction History Flow * fix: Add missing pubspec parameter * feat: Automated Integration Tests for Transaction History flow * test: Updating send page robot and also syncing branch with main * test: Modifying tests to flow with wallet grouping implementation * fix: Issue with transaction history test * fix: Modifications to the PR and add automated confirmation for checking that all wallet types are restored or created correctly * test: Attempting automation for testing * fix: Issue from merge conflicts * test: Remove automation of test in this PR --------- Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
330 lines
11 KiB
Dart
330 lines
11 KiB
Dart
import 'package:cake_wallet/generated/i18n.dart';
|
|
import 'package:cake_wallet/src/screens/exchange/exchange_page.dart';
|
|
import 'package:cake_wallet/src/screens/exchange/widgets/present_provider_picker.dart';
|
|
import 'package:cw_core/crypto_currency.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import '../components/common_test_cases.dart';
|
|
|
|
class ExchangePageRobot {
|
|
ExchangePageRobot(this.tester) : commonTestCases = CommonTestCases(tester);
|
|
|
|
final WidgetTester tester;
|
|
late CommonTestCases commonTestCases;
|
|
|
|
Future<void> isExchangePage() async {
|
|
await commonTestCases.isSpecificPage<ExchangePage>();
|
|
await commonTestCases.defaultSleepTime();
|
|
}
|
|
|
|
void hasResetButton() {
|
|
commonTestCases.hasText(S.current.reset);
|
|
}
|
|
|
|
void displaysPresentProviderPicker() {
|
|
commonTestCases.hasType<PresentProviderPicker>();
|
|
}
|
|
|
|
Future<void> displayBothExchangeCards() async {
|
|
final ExchangePage exchangeCard = tester.widget<ExchangePage>(
|
|
find.byType(ExchangePage),
|
|
);
|
|
|
|
final depositKey = exchangeCard.depositKey;
|
|
final receiveKey = exchangeCard.receiveKey;
|
|
|
|
final depositExchangeCard = find.byKey(depositKey);
|
|
expect(depositExchangeCard, findsOneWidget);
|
|
|
|
final receiveExchangeCard = find.byKey(receiveKey);
|
|
expect(receiveExchangeCard, findsOneWidget);
|
|
}
|
|
|
|
void confirmRightComponentsDisplayOnDepositExchangeCards() {
|
|
ExchangePage exchangePage = tester.widget(find.byType(ExchangePage));
|
|
final exchangeViewModel = exchangePage.exchangeViewModel;
|
|
final depositCardPrefix = 'deposit_exchange_card';
|
|
|
|
commonTestCases.hasValueKey('${depositCardPrefix}_title_key');
|
|
commonTestCases.hasValueKey('${depositCardPrefix}_currency_picker_button_key');
|
|
commonTestCases.hasValueKey('${depositCardPrefix}_selected_currency_text_key');
|
|
commonTestCases.hasValueKey('${depositCardPrefix}_amount_textfield_key');
|
|
|
|
exchangePage.depositKey.currentState!.changeLimits(min: '0.1');
|
|
|
|
commonTestCases.hasValueKey('${depositCardPrefix}_min_limit_text_key');
|
|
|
|
final initialCurrency = exchangeViewModel.depositCurrency;
|
|
if (initialCurrency.tag != null) {
|
|
commonTestCases.hasValueKey('${depositCardPrefix}_selected_currency_tag_text_key');
|
|
}
|
|
|
|
if (exchangeViewModel.hasAllAmount) {
|
|
commonTestCases.hasValueKey('${depositCardPrefix}_send_all_button_key');
|
|
}
|
|
|
|
if (exchangeViewModel.isMoneroWallet) {
|
|
commonTestCases.hasValueKey('${depositCardPrefix}_address_book_button_key');
|
|
}
|
|
|
|
if (exchangeViewModel.isDepositAddressEnabled) {
|
|
commonTestCases.hasValueKey('${depositCardPrefix}_editable_address_textfield_key');
|
|
} else {
|
|
commonTestCases.hasValueKey('${depositCardPrefix}_non_editable_address_textfield_key');
|
|
commonTestCases.hasValueKey('${depositCardPrefix}_copy_refund_address_button_key');
|
|
}
|
|
|
|
// commonTestCases.hasValueKey('${depositCardPrefix}_max_limit_text_key');
|
|
}
|
|
|
|
void confirmRightComponentsDisplayOnReceiveExchangeCards() {
|
|
ExchangePage exchangePage = tester.widget(find.byType(ExchangePage));
|
|
final exchangeViewModel = exchangePage.exchangeViewModel;
|
|
final receiveCardPrefix = 'receive_exchange_card';
|
|
|
|
commonTestCases.hasValueKey('${receiveCardPrefix}_title_key');
|
|
commonTestCases.hasValueKey('${receiveCardPrefix}_currency_picker_button_key');
|
|
commonTestCases.hasValueKey('${receiveCardPrefix}_selected_currency_text_key');
|
|
commonTestCases.hasValueKey('${receiveCardPrefix}_amount_textfield_key');
|
|
commonTestCases.hasValueKey('${receiveCardPrefix}_min_limit_text_key');
|
|
|
|
final initialCurrency = exchangeViewModel.receiveCurrency;
|
|
if (initialCurrency.tag != null) {
|
|
commonTestCases.hasValueKey('${receiveCardPrefix}_selected_currency_tag_text_key');
|
|
}
|
|
|
|
if (exchangeViewModel.hasAllAmount) {
|
|
commonTestCases.hasValueKey('${receiveCardPrefix}_send_all_button_key');
|
|
}
|
|
|
|
if (exchangeViewModel.isMoneroWallet) {
|
|
commonTestCases.hasValueKey('${receiveCardPrefix}_address_book_button_key');
|
|
}
|
|
|
|
commonTestCases.hasValueKey('${receiveCardPrefix}_editable_address_textfield_key');
|
|
}
|
|
|
|
Future<void> selectDepositCurrency(CryptoCurrency depositCurrency) async {
|
|
final depositPrefix = 'deposit_exchange_card';
|
|
final currencyPickerKey = '${depositPrefix}_currency_picker_button_key';
|
|
final currencyPickerDialogKey = '${depositPrefix}_currency_picker_dialog_button_key';
|
|
|
|
await commonTestCases.tapItemByKey(currencyPickerKey);
|
|
commonTestCases.hasValueKey(currencyPickerDialogKey);
|
|
|
|
ExchangePage exchangePage = tester.widget(find.byType(ExchangePage));
|
|
final exchangeViewModel = exchangePage.exchangeViewModel;
|
|
|
|
if (depositCurrency == exchangeViewModel.depositCurrency) {
|
|
await commonTestCases.defaultSleepTime();
|
|
await commonTestCases
|
|
.tapItemByKey('picker_items_index_${depositCurrency.name}_selected_item_button_key');
|
|
return;
|
|
}
|
|
|
|
await commonTestCases.dragUntilVisible(
|
|
'picker_items_index_${depositCurrency.name}_button_key',
|
|
'picker_scrollbar_key',
|
|
);
|
|
await commonTestCases.defaultSleepTime();
|
|
|
|
await commonTestCases.tapItemByKey('picker_items_index_${depositCurrency.name}_button_key');
|
|
}
|
|
|
|
Future<void> selectReceiveCurrency(CryptoCurrency receiveCurrency) async {
|
|
final receivePrefix = 'receive_exchange_card';
|
|
final currencyPickerKey = '${receivePrefix}_currency_picker_button_key';
|
|
final currencyPickerDialogKey = '${receivePrefix}_currency_picker_dialog_button_key';
|
|
|
|
await commonTestCases.tapItemByKey(currencyPickerKey);
|
|
commonTestCases.hasValueKey(currencyPickerDialogKey);
|
|
|
|
ExchangePage exchangePage = tester.widget(find.byType(ExchangePage));
|
|
final exchangeViewModel = exchangePage.exchangeViewModel;
|
|
|
|
if (receiveCurrency == exchangeViewModel.receiveCurrency) {
|
|
await commonTestCases
|
|
.tapItemByKey('picker_items_index_${receiveCurrency.name}_selected_item_button_key');
|
|
return;
|
|
}
|
|
|
|
await commonTestCases.dragUntilVisible(
|
|
'picker_items_index_${receiveCurrency.name}_button_key',
|
|
'picker_scrollbar_key',
|
|
);
|
|
await commonTestCases.defaultSleepTime();
|
|
|
|
await commonTestCases.tapItemByKey('picker_items_index_${receiveCurrency.name}_button_key');
|
|
}
|
|
|
|
Future<void> enterDepositAmount(String amount) async {
|
|
await commonTestCases.enterText(amount, 'deposit_exchange_card_amount_textfield_key');
|
|
}
|
|
|
|
Future<void> enterDepositRefundAddress({String? depositAddress}) async {
|
|
ExchangePage exchangePage = tester.widget(find.byType(ExchangePage));
|
|
final exchangeViewModel = exchangePage.exchangeViewModel;
|
|
|
|
if (exchangeViewModel.isDepositAddressEnabled && depositAddress != null) {
|
|
await commonTestCases.enterText(
|
|
depositAddress, 'deposit_exchange_card_editable_address_textfield_key');
|
|
}
|
|
}
|
|
|
|
Future<void> enterReceiveAddress(String receiveAddress) async {
|
|
await commonTestCases.enterText(
|
|
receiveAddress,
|
|
'receive_exchange_card_editable_address_textfield_key',
|
|
);
|
|
await commonTestCases.defaultSleepTime();
|
|
}
|
|
|
|
Future<void> onExchangeButtonPressed() async {
|
|
await commonTestCases.tapItemByKey('exchange_page_exchange_button_key');
|
|
await commonTestCases.defaultSleepTime();
|
|
}
|
|
|
|
bool hasMaxLimitError() {
|
|
final maxErrorText = find.text(S.current.error_text_input_above_maximum_limit);
|
|
|
|
bool hasMaxError = maxErrorText.tryEvaluate();
|
|
|
|
return hasMaxError;
|
|
}
|
|
|
|
bool hasMinLimitError() {
|
|
final minErrorText = find.text(S.current.error_text_input_below_minimum_limit);
|
|
|
|
bool hasMinError = minErrorText.tryEvaluate();
|
|
|
|
return hasMinError;
|
|
}
|
|
|
|
bool hasTradeCreationFailureError() {
|
|
final tradeCreationFailureDialogButton =
|
|
find.byKey(ValueKey('exchange_page_trade_creation_failure_dialog_button_key'));
|
|
|
|
bool hasTradeCreationFailure = tradeCreationFailureDialogButton.tryEvaluate();
|
|
tester.printToConsole('Trade not created error: $hasTradeCreationFailure');
|
|
return hasTradeCreationFailure;
|
|
}
|
|
|
|
Future<void> onTradeCreationFailureDialogButtonPressed() async {
|
|
await commonTestCases.tapItemByKey('exchange_page_trade_creation_failure_dialog_button_key');
|
|
}
|
|
|
|
/// Handling Trade Failure Errors or errors shown through the Failure Dialog.
|
|
///
|
|
/// Simulating the user's flow and response when this error comes up.
|
|
/// Examples are:
|
|
/// - No provider can handle this trade error,
|
|
/// - Trade amount below limit error.
|
|
Future<void> _handleTradeCreationFailureErrors() async {
|
|
bool isTradeCreationFailure = false;
|
|
|
|
isTradeCreationFailure = hasTradeCreationFailureError();
|
|
|
|
int maxRetries = 20;
|
|
int retries = 0;
|
|
|
|
while (isTradeCreationFailure && retries < maxRetries) {
|
|
await tester.pump();
|
|
|
|
await onTradeCreationFailureDialogButtonPressed();
|
|
|
|
await commonTestCases.defaultSleepTime(seconds: 5);
|
|
|
|
await onExchangeButtonPressed();
|
|
|
|
isTradeCreationFailure = hasTradeCreationFailureError();
|
|
retries++;
|
|
}
|
|
}
|
|
|
|
/// Handles the min limit error.
|
|
///
|
|
/// Simulates the user's flow and response when it comes up.
|
|
///
|
|
/// Has a max retry of 20 times.
|
|
Future<void> _handleMinLimitError(String initialAmount) async {
|
|
bool isMinLimitError = false;
|
|
|
|
isMinLimitError = hasMinLimitError();
|
|
|
|
double amount;
|
|
|
|
amount = double.parse(initialAmount);
|
|
|
|
int maxRetries = 20;
|
|
int retries = 0;
|
|
|
|
while (isMinLimitError && retries < maxRetries) {
|
|
amount++;
|
|
tester.printToConsole('Amount: $amount');
|
|
|
|
enterDepositAmount(amount.toString());
|
|
|
|
await commonTestCases.defaultSleepTime();
|
|
|
|
await onExchangeButtonPressed();
|
|
|
|
isMinLimitError = hasMinLimitError();
|
|
|
|
retries++;
|
|
}
|
|
|
|
if (retries >= maxRetries) {
|
|
tester.printToConsole('Max retries reached for minLimit Error. Exiting loop.');
|
|
}
|
|
}
|
|
|
|
/// Handles the max limit error.
|
|
///
|
|
/// Simulates the user's flow and response when it comes up.
|
|
///
|
|
/// Has a max retry of 20 times.
|
|
Future<void> _handleMaxLimitError(String initialAmount) async {
|
|
bool isMaxLimitError = false;
|
|
|
|
isMaxLimitError = hasMaxLimitError();
|
|
|
|
double amount;
|
|
|
|
amount = double.parse(initialAmount);
|
|
|
|
int maxRetries = 20;
|
|
int retries = 0;
|
|
|
|
while (isMaxLimitError && retries < maxRetries) {
|
|
amount++;
|
|
tester.printToConsole('Amount: $amount');
|
|
|
|
enterDepositAmount(amount.toString());
|
|
|
|
await commonTestCases.defaultSleepTime();
|
|
|
|
await onExchangeButtonPressed();
|
|
|
|
isMaxLimitError = hasMaxLimitError();
|
|
|
|
retries++;
|
|
}
|
|
|
|
if (retries >= maxRetries) {
|
|
tester.printToConsole('Max retries reached for maxLimit Error. Exiting loop.');
|
|
}
|
|
}
|
|
|
|
Future<void> handleErrors(String initialAmount) async {
|
|
await tester.pumpAndSettle();
|
|
|
|
await _handleMinLimitError(initialAmount);
|
|
|
|
await _handleMaxLimitError(initialAmount);
|
|
|
|
await _handleTradeCreationFailureErrors();
|
|
|
|
await commonTestCases.defaultSleepTime();
|
|
}
|
|
}
|