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 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
25a8393
fix: Generic fixes
Blazebrain Dec 20, 2024
e3c4f7a
Merge branch 'main' of https://github.com/cake-tech/cake_wallet
Blazebrain Jan 13, 2025
1335627
fix: Modify hasSufficientFundsForRent to work for spl transactions
Blazebrain Jan 14, 2025
ecc0156
feat: Integrate seed verification into integration tests
Blazebrain Jan 16, 2025
f5cc30b
Merge branch 'main' of https://github.com/cake-tech/cake_wallet into …
Blazebrain Jan 16, 2025
50c82e0
fix: Adjust workflow file
Blazebrain Jan 16, 2025
ff3606a
chore: Remove previous working directory
Blazebrain Jan 16, 2025
4707dc8
fix: Revert change
Blazebrain Jan 16, 2025
164ae7e
chore: Remove step to setup kvm, already existing in new setup
Blazebrain Jan 16, 2025
45aed18
chore: Remove a couple of steps from workflow
Blazebrain Jan 16, 2025
3ca0334
chore: Try switching test commands
Blazebrain Jan 16, 2025
5060cbe
fix: Switch back to flutter drive
Blazebrain Jan 16, 2025
85f8ebb
fix: Flutter error when running tests with Flutter drive
Blazebrain Jan 16, 2025
ee067cc
Merge branch 'main' into Integrate-Seed-Verification-Flow-To-Integrat…
OmarHatem28 Jan 17, 2025
b0602f8
feat: Add screenshots to individual test pages and modify integration…
Blazebrain Jan 17, 2025
3216a87
Merge branch 'Integrate-Seed-Verification-Flow-To-Integration-Tests' …
Blazebrain Jan 17, 2025
17285bd
feat: Implement transaction success info robot and fix issue with sen…
Blazebrain Jan 17, 2025
640766d
fix: Improve integration testing for exchange flow and clean up logic…
Blazebrain Jan 20, 2025
b83cf66
fix: Handle duplicate words for seeds and test restore through seeds
Blazebrain Jan 20, 2025
35d5a10
fix: Optimize implementation for transactions history test
Blazebrain Jan 22, 2025
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
544 changes: 265 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
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
41 changes: 41 additions & 0 deletions integration_test/robots/seed_verification_page_robot.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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>();
}

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();
}
}
14 changes: 6 additions & 8 deletions integration_test/robots/wallet_seed_page_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class WalletSeedPageRobot {
await commonTestCases.isSpecificPage<WalletSeedPage>();
}

Future<void> onSeedPageVerifyButtonPressed() async {
Future<void> onVerifySeedButtonPressed() async {
await commonTestCases.tapItemByKey('wallet_seed_page_verify_seed_button_key');
await commonTestCases.defaultSleepTime();
}

Future<void> onOpenWalletButtonPressed() async {
await commonTestCases.tapItemByKey('wallet_seed_page_open_wallet_button_key');
Future<void> onSaveSeedButtonPressed() async {
await commonTestCases.tapItemByKey('wallet_seed_page_save_seeds_button_key');
await commonTestCases.defaultSleepTime();
}

Expand All @@ -40,12 +40,10 @@ class WalletSeedPageRobot {
final walletSeedViewModel = walletSeedPage.walletSeedViewModel;

final walletName = walletSeedViewModel.name;
final walletSeeds = walletSeedViewModel.seed;

final walletSeeds = walletSeedViewModel.seedSplit;
commonTestCases.hasText(walletName);
final seedList = walletSeeds.trim().split(" ");
for (final seedWord in seedList) {
commonTestCases.hasTextAtLestOnce(seedWord);
for (var seed in walletSeeds) {
commonTestCases.hasTextAtLestOnce(seed);
}
}

Expand Down
13 changes: 12 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/root/root.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/store/authentication_store.dart';
import 'package:cake_wallet/test_asset_bundles.dart';
import 'package:cake_wallet/themes/theme_base.dart';
import 'package:cake_wallet/utils/device_info.dart';
import 'package:cake_wallet/utils/exception_handler.dart';
Expand Down Expand Up @@ -80,8 +81,18 @@ Future<void> runAppWithZone({Key? topLevelKey}) async {
ledgerFile.writeAsStringSync("$content\n${event.message}");
});
}
// Basically when we're running a test
if (topLevelKey != null) {
runApp(
DefaultAssetBundle(
bundle: TestAssetBundle(),
child: App(key: topLevelKey),
),
);
} else {
runApp(App(key: topLevelKey));
}

runApp(App(key: topLevelKey));
isAppRunning = true;
}, (error, stackTrace) async {
if (!isAppRunning) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ class SeedVerificationPage extends BasePage {
child: walletSeedViewModel.isVerificationComplete ||
walletSeedViewModel.verificationIndices.isEmpty
? SeedVerificationSuccessView(
key: ValueKey('seed_verification_success_view_page'),
imageColor: titleColor(context),
)
: SeedVerificationStepView(
key: ValueKey('seed_verification_step_view_page'),
walletSeedViewModel: walletSeedViewModel,
questionTextColor: titleColor(context),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class SeedVerificationStepView extends StatelessWidget {
children: walletSeedViewModel.currentOptions.map(
(option) {
return GestureDetector(
key: ValueKey('seed_verification_option_${option}_button_key'),
onTap: () async {
if (walletSeedViewModel.wrongEntries > 2) return;

Expand Down
15 changes: 15 additions & 0 deletions lib/test_asset_bundles.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'dart:convert';

import 'package:flutter/services.dart';

class TestAssetBundle extends CachingAssetBundle {
@override
Future<String> loadString(String key, {bool cache = true}) async {
final ByteData data = await load(key);

return utf8.decode(data.buffer.asUint8List());
}

@override
Future<ByteData> load(String key) async => rootBundle.load(key);
}
4 changes: 2 additions & 2 deletions lib/utils/feature_flag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ class FeatureFlag {
static const bool isExolixEnabled = true;
static const bool isInAppTorEnabled = false;
static const bool isBackgroundSyncEnabled = false;
static const int verificationWordsCount = kDebugMode ? 0 : 2;
}
static const int verificationWordsCount = 2;
}
Loading