Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CW 882: Integrate Seed Verification Flow To Integration Tests #1966

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
550 changes: 271 additions & 279 deletions .github/workflows/automated_integration_test.yml

Large diffs are not rendered by default.

36 changes: 17 additions & 19 deletions cw_solana/lib/solana_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class SolanaWalletClient {
transactionDetails.addAll(response);

// to avoid reaching the node RPS limit
await Future.delayed(Duration(milliseconds: 500));
await Future.delayed(const Duration(milliseconds: 500));
}

for (final tx in transactionDetails) {
Expand Down Expand Up @@ -379,18 +379,16 @@ class SolanaWalletClient {
required double solBalance,
required double fee,
}) async {
return true;
// TODO: this is not doing what the name inclines
// final rent =
// await _client!.getMinimumBalanceForMintRentExemption(commitment: Commitment.confirmed);
//
// final rentInSol = (rent / lamportsPerSol).toDouble();
//
// final remnant = solBalance - (inputAmount + fee);
//
// if (remnant > rentInSol) return true;
//
// return false;
final rent =
await _client!.getMinimumBalanceForMintRentExemption(commitment: Commitment.confirmed);

final rentInSol = (rent / lamportsPerSol).toDouble();

final remnant = solBalance - (inputAmount + fee);

if (remnant > rentInSol) return true;

return false;
}

Future<PendingSolanaTransaction> _signNativeTokenTransaction({
Expand Down Expand Up @@ -542,7 +540,7 @@ class SolanaWalletClient {
),
);

await Future.delayed(Duration(seconds: 5));
await Future.delayed(const Duration(seconds: 5));
}
} catch (e) {
throw SolanaCreateAssociatedTokenAccountException(e.toString());
Expand All @@ -569,7 +567,7 @@ class SolanaWalletClient {
);

bool hasSufficientFundsLeft = await hasSufficientFundsLeftForRent(
inputAmount: inputAmount,
inputAmount: 0,
fee: fee,
solBalance: solBalance,
);
Expand All @@ -586,12 +584,12 @@ class SolanaWalletClient {
);

sendTx() async {
await Future.delayed(Duration(seconds: 3));
await Future.delayed(const Duration(seconds: 3));

return await sendTransaction(
signedTransaction: signedTx,
commitment: commitment,
);
signedTransaction: signedTx,
commitment: commitment,
);
}

final pendingTransaction = PendingSolanaTransaction(
Expand Down
5 changes: 5 additions & 0 deletions integration_test/components/common_test_cases.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

class CommonTestCases {
WidgetTester tester;
Expand Down Expand Up @@ -171,4 +172,8 @@ class CommonTestCases {

Future<void> defaultSleepTime({int seconds = 2}) async =>
await Future.delayed(Duration(seconds: seconds));

Future<void> takeScreenshots(String screenshotName) async {
await (tester.binding as IntegrationTestWidgetsFlutterBinding).takeScreenshot(screenshotName);
}
}
4 changes: 2 additions & 2 deletions integration_test/components/common_test_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class CommonTestConstants {
static final String exchangeTestAmount = '0.01';
static final WalletType testWalletType = WalletType.solana;
static final String testWalletName = 'Integrated Testing Wallet';
static final CryptoCurrency testReceiveCurrency = CryptoCurrency.usdtSol;
static final CryptoCurrency testDepositCurrency = CryptoCurrency.sol;
static final CryptoCurrency testReceiveCurrency = CryptoCurrency.sol;
static final CryptoCurrency testDepositCurrency = CryptoCurrency.usdtSol;
static final String testWalletAddress = '5v9gTW1yWPffhnbNKuvtL2frevAf4HpBMw8oYnfqUjhm';
}
39 changes: 27 additions & 12 deletions integration_test/components/common_test_flows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import '../robots/new_wallet_type_page_robot.dart';
import '../robots/pre_seed_page_robot.dart';
import '../robots/restore_from_seed_or_key_robot.dart';
import '../robots/restore_options_page_robot.dart';
import '../robots/seed_verification_page_robot.dart';
import '../robots/setup_pin_code_robot.dart';
import '../robots/wallet_group_description_page_robot.dart';
import '../robots/wallet_list_page_robot.dart';
Expand All @@ -40,6 +41,7 @@ class CommonTestFlows {
_walletListPageRobot = WalletListPageRobot(_tester),
_newWalletTypePageRobot = NewWalletTypePageRobot(_tester),
_restoreOptionsPageRobot = RestoreOptionsPageRobot(_tester),
_seedVerificationPageRobot = SeedVerificationPageRobot(_tester),
_createPinWelcomePageRobot = CreatePinWelcomePageRobot(_tester),
_restoreFromSeedOrKeysPageRobot = RestoreFromSeedOrKeysPageRobot(_tester),
_walletGroupDescriptionPageRobot = WalletGroupDescriptionPageRobot(_tester);
Expand All @@ -58,6 +60,7 @@ class CommonTestFlows {
final NewWalletTypePageRobot _newWalletTypePageRobot;
final RestoreOptionsPageRobot _restoreOptionsPageRobot;
final CreatePinWelcomePageRobot _createPinWelcomePageRobot;
final SeedVerificationPageRobot _seedVerificationPageRobot;
final RestoreFromSeedOrKeysPageRobot _restoreFromSeedOrKeysPageRobot;
final WalletGroupDescriptionPageRobot _walletGroupDescriptionPageRobot;

Expand Down Expand Up @@ -87,7 +90,8 @@ class CommonTestFlows {
await _confirmPreSeedInfo();

await _confirmWalletDetails();
await _commonTestCases.defaultSleepTime();

await _verifyWalletSeed();
}

//* ========== Handles flow from welcome to restoring wallet from seeds ===============
Expand Down Expand Up @@ -150,6 +154,9 @@ class CommonTestFlows {
await _confirmPreSeedInfo();

await _confirmWalletDetails();

await _verifyWalletSeed();

await _commonTestCases.defaultSleepTime();
}

Expand Down Expand Up @@ -240,8 +247,10 @@ class CommonTestFlows {

if (Platform.isLinux) {
// manual pin input
await _restoreFromSeedOrKeysPageRobot.enterPasswordForWalletRestore(CommonTestConstants.pin.join(""));
await _restoreFromSeedOrKeysPageRobot.enterPasswordRepeatForWalletRestore(CommonTestConstants.pin.join(""));
await _restoreFromSeedOrKeysPageRobot
.enterPasswordForWalletRestore(CommonTestConstants.pin.join(""));
await _restoreFromSeedOrKeysPageRobot
.enterPasswordRepeatForWalletRestore(CommonTestConstants.pin.join(""));
}

await _newWalletPageRobot.onNextButtonPressed();
Expand All @@ -264,13 +273,17 @@ class CommonTestFlows {

// await _walletSeedPageRobot.onCopySeedsButtonPressed();

await _walletSeedPageRobot.onSeedPageVerifyButtonPressed();
// Turns out the popup about "Copied to clipboard" prevents
//the button from being pressed on the first try, by just
//tapping it again we fix it.
// await _walletSeedPageRobot.onSeedPageVerifyButtonPressed();

await _walletSeedPageRobot.onOpenWalletButtonPressed();
await _walletSeedPageRobot.onVerifySeedButtonPressed();
}

//* ============ Handles Wallet Seed Verification Page ==================

Future<void> _verifyWalletSeed() async {
await _seedVerificationPageRobot.isSeedVerificationPage();

_seedVerificationPageRobot.hasTitle();

await _seedVerificationPageRobot.verifyWalletSeeds();
}

//* Main Restore Actions - On the RestoreFromSeed/Keys Page - Restore from Seeds Action
Expand All @@ -293,8 +306,10 @@ class CommonTestFlows {

if (Platform.isLinux) {
// manual pin input
await _restoreFromSeedOrKeysPageRobot.enterPasswordForWalletRestore(CommonTestConstants.pin.join(""));
await _restoreFromSeedOrKeysPageRobot.enterPasswordRepeatForWalletRestore(CommonTestConstants.pin.join(""));
await _restoreFromSeedOrKeysPageRobot
.enterPasswordForWalletRestore(CommonTestConstants.pin.join(""));
await _restoreFromSeedOrKeysPageRobot
.enterPasswordRepeatForWalletRestore(CommonTestConstants.pin.join(""));
}

await _restoreFromSeedOrKeysPageRobot.onRestoreWalletButtonPressed();
Expand Down
1 change: 1 addition & 0 deletions integration_test/robots/auth_page_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class AuthPageRobot extends PinCodeWidgetRobot {

Future<void> isAuthPage() async {
await commonTestCases.isSpecificPage<AuthPage>();
await commonTestCases.takeScreenshots('auth_page');
}

void hasTitle() {
Expand Down
1 change: 1 addition & 0 deletions integration_test/robots/create_pin_welcome_page_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CreatePinWelcomePageRobot {

Future<void> isCreatePinWelcomePage() async {
await commonTestCases.isSpecificPage<CreatePinWelcomePage>();
await commonTestCases.takeScreenshots('create_pin_welcome_page');
}

void hasTitle() {
Expand Down
1 change: 1 addition & 0 deletions integration_test/robots/dashboard_menu_widget_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class DashboardMenuWidgetRobot {
late CommonTestCases commonTestCases;

Future<void> hasMenuWidget() async {
await commonTestCases.takeScreenshots('menu_widget_page');
commonTestCases.hasType<MenuWidget>();
}

Expand Down
1 change: 1 addition & 0 deletions integration_test/robots/dashboard_page_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class DashboardPageRobot {

Future<void> isDashboardPage() async {
await commonTestCases.isSpecificPage<DashboardPage>();
await commonTestCases.takeScreenshots('dashboard_page');
}

Future<void> confirmWalletTypeIsDisplayedCorrectly(
Expand Down
1 change: 1 addition & 0 deletions integration_test/robots/disclaimer_page_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class DisclaimerPageRobot {

Future<void> isDisclaimerPage() async {
await commonTestCases.isSpecificPage<DisclaimerPage>();
await commonTestCases.takeScreenshots('disclaimer_page');
}

void hasCheckIcon(bool hasBeenTapped) {
Expand Down
1 change: 1 addition & 0 deletions integration_test/robots/exchange_confirm_page_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ExchangeConfirmPageRobot {

Future<void> isExchangeConfirmPage() async {
await commonTestCases.isSpecificPage<ExchangeConfirmPage>();
await commonTestCases.takeScreenshots('exchange_confirm_page');
}

void confirmComponentsOfTradeDisplayProperly() {
Expand Down
1 change: 1 addition & 0 deletions integration_test/robots/exchange_page_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ExchangePageRobot {

Future<void> isExchangePage() async {
await commonTestCases.isSpecificPage<ExchangePage>();
await commonTestCases.takeScreenshots('exchange_page');
await commonTestCases.defaultSleepTime();
}

Expand Down
2 changes: 2 additions & 0 deletions integration_test/robots/exchange_trade_page_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class ExchangeTradePageRobot {

Future<void> isExchangeTradePage() async {
await commonTestCases.isSpecificPage<ExchangeTradePage>();
await commonTestCases.takeScreenshots('exchange_trade_page');

}

void hasInformationDialog() {
Expand Down
1 change: 1 addition & 0 deletions integration_test/robots/new_wallet_page_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class NewWalletPageRobot {

Future<void> isNewWalletPage() async {
await commonTestCases.isSpecificPage<NewWalletPage>();
await commonTestCases.takeScreenshots('new_wallet_page');
}

Future<void> enterWalletName(String walletName) async {
Expand Down
1 change: 1 addition & 0 deletions integration_test/robots/new_wallet_type_page_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class NewWalletTypePageRobot {

Future<void> isNewWalletTypePage() async {
await commonTestCases.isSpecificPage<NewWalletTypePage>();
await commonTestCases.takeScreenshots('new_wallet_type_page');
}

void displaysCorrectTitle(bool isCreate) {
Expand Down
1 change: 1 addition & 0 deletions integration_test/robots/pin_code_widget_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class PinCodeWidgetRobot {
);
}

await commonTestCases.takeScreenshots('pin_code_widget');
await commonTestCases.defaultSleepTime();
}
}
1 change: 1 addition & 0 deletions integration_test/robots/pre_seed_page_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class PreSeedPageRobot {

Future<void> isPreSeedPage() async {
await commonTestCases.isSpecificPage<PreSeedPage>();
await commonTestCases.takeScreenshots('pre_seed_page');
}

Future<void> onConfirmButtonPressed() async {
Expand Down
3 changes: 1 addition & 2 deletions integration_test/robots/restore_from_seed_or_key_robot.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'package:cake_wallet/entities/seed_type.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/screens/restore/wallet_restore_page.dart';
import 'package:cake_wallet/src/widgets/seed_widget.dart';
import 'package:cake_wallet/src/widgets/validable_annotated_editable_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import '../components/common_test_cases.dart';
Expand All @@ -16,6 +14,7 @@ class RestoreFromSeedOrKeysPageRobot {

Future<void> isRestoreFromSeedKeyPage() async {
await commonTestCases.isSpecificPage<WalletRestorePage>();
await commonTestCases.takeScreenshots('wallet_restore_page');
}

Future<void> confirmViewComponentsDisplayProperlyPerPageView() async {
Expand Down
1 change: 1 addition & 0 deletions integration_test/robots/restore_options_page_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class RestoreOptionsPageRobot {

Future<void> isRestoreOptionsPage() async {
await commonTestCases.isSpecificPage<RestoreOptionsPage>();
await commonTestCases.takeScreenshots('restore_options');
}

void hasRestoreOptionsButton() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SecurityAndBackupPageRobot {

Future<void> isSecurityAndBackupPage() async {
await commonTestCases.isSpecificPage<SecurityBackupPage>();
await commonTestCases.takeScreenshots('security_backup_page');
}

void hasTitle() {
Expand Down
42 changes: 42 additions & 0 deletions integration_test/robots/seed_verification_page_robot.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/screens/seed/seed_verification/seed_verification_page.dart';
import 'package:flutter_test/flutter_test.dart';

import '../components/common_test_cases.dart';

class SeedVerificationPageRobot {
SeedVerificationPageRobot(this.tester) : commonTestCases = CommonTestCases(tester);

final WidgetTester tester;
final CommonTestCases commonTestCases;

Future<void> isSeedVerificationPage() async {
await commonTestCases.isSpecificPage<SeedVerificationPage>();
await commonTestCases.takeScreenshots('seed_verification_page');
}

void hasTitle() {
commonTestCases.hasText(S.current.verify_seed);
}

Future<void> verifyWalletSeeds() async {
final seedVerificationPage =
tester.widget<SeedVerificationPage>(find.byType(SeedVerificationPage));

final walletSeedViewModel = seedVerificationPage.walletSeedViewModel;

while (!walletSeedViewModel.isVerificationComplete) {
final currentCorrectWord = walletSeedViewModel.currentCorrectWord;

await commonTestCases.tapItemByKey(
'seed_verification_option_${currentCorrectWord}_button_key',
);

await commonTestCases.defaultSleepTime(seconds: 1);
}

await commonTestCases.tapItemByKey('wallet_seed_page_open_wallet_button_key');

await commonTestCases.defaultSleepTime();
}
}
Loading
Loading