Skip to content

Commit d01525b

Browse files
committed
feat: Add emulator readiness checks and enhance send flow tests
This change: - Modifies the send flow test to send $1 worth of any of the wallet currencies - Set up switching between test wallet in case there's zero balance in any of the wallets when the test is run - Add a mini script to check emulator readiness for the tests
1 parent 30afdba commit d01525b

File tree

4 files changed

+283
-26
lines changed

4 files changed

+283
-26
lines changed

.github/workflows/automated_integration_test.yml

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,49 @@ jobs:
444444
~/.android/adb*
445445
key: avd-${{ matrix.api-level }}
446446

447+
- name: 🔧 Prepare emulator utilities
448+
run: |
449+
# Create a helper script for emulator readiness checks
450+
cat > /tmp/emulator_ready.sh << 'EOF'
451+
#!/bin/bash
452+
453+
echo "=== Emulator Readiness Check ==="
454+
455+
# Wait for boot completion
456+
echo "1. Checking boot completion..."
457+
timeout 300 bash -c 'until adb shell getprop sys.boot_completed 2>/dev/null | grep -q "1"; do sleep 5; echo " Waiting for boot completion..."; done'
458+
if [ $? -eq 0 ]; then
459+
echo "✅ Boot completed"
460+
else
461+
echo "❌ Boot completion timeout"
462+
return 1
463+
fi
464+
465+
# Wait for input service
466+
echo "2. Checking input service..."
467+
timeout 60 bash -c 'until adb shell service list 2>/dev/null | grep -q "input"; do sleep 2; echo " Waiting for input service..."; done'
468+
if [ $? -eq 0 ]; then
469+
echo "✅ Input service ready"
470+
else
471+
echo "❌ Input service timeout"
472+
return 1
473+
fi
474+
475+
# Wait for package manager
476+
echo "3. Checking package manager..."
477+
timeout 60 bash -c 'until adb shell pm list packages 2>/dev/null >/dev/null; do sleep 2; echo " Waiting for package manager..."; done'
478+
if [ $? -eq 0 ]; then
479+
echo "✅ Package manager ready"
480+
else
481+
echo "❌ Package manager timeout"
482+
return 1
483+
fi
484+
485+
echo "✅ Emulator is fully ready"
486+
EOF
487+
488+
chmod +x /tmp/emulator_ready.sh
489+
447490
- name: 🦾 Create AVD and generate snapshot for caching
448491
if: steps.avd-cache.outputs.cache-hit != 'true'
449492
uses: reactivecircus/android-emulator-runner@v2
@@ -453,10 +496,13 @@ jobs:
453496
# arch: ${{ matrix.arch }}
454497
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -read-only -memory 1024
455498
working-directory: ${{ github.workspace }}
456-
disable-animations: false
499+
disable-animations: true
457500
script: |
458501
echo "=== AVD Snapshot Generation ==="
459-
echo "Generated AVD snapshot for caching."
502+
503+
# Use the helper script to ensure emulator is fully ready
504+
/tmp/emulator_ready.sh
505+
460506
echo "=== Checking emulator status before termination ==="
461507
adb devices || echo "ADB devices check failed"
462508
echo "=== AVD snapshot generation complete ==="
@@ -495,6 +541,11 @@ jobs:
495541
chmod a+rx integration_test_runner.sh
496542
497543
echo "=== Running integration tests ==="
544+
545+
# Ensure emulator is fully ready before running tests
546+
echo "Final emulator readiness check..."
547+
/tmp/emulator_ready.sh
548+
498549
# Add error handling for the test runner
499550
if ./integration_test_runner.sh; then
500551
echo "Integration tests completed successfully"

integration_test/components/common_test_constants.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:cw_core/wallet_type.dart';
44
class CommonTestConstants {
55
static final pin = [0, 8, 0, 1];
66
static final String sendTestAmount = '0.00008';
7+
static final String sendTestFiatAmount = '1.00';
78
static final String exchangeTestAmount = '0.01';
89
static final WalletType testWalletType = WalletType.solana;
910
static final String testWalletName = 'Integrated Testing Wallet';

integration_test/robots/send_page_robot.dart

Lines changed: 128 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:async';
33
import 'package:cake_wallet/core/execution_state.dart';
44
import 'package:cake_wallet/generated/i18n.dart';
55
import 'package:cake_wallet/src/screens/send/send_page.dart';
6+
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
67
import 'package:cake_wallet/src/widgets/primary_button.dart';
78
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
89
import 'package:cw_core/crypto_currency.dart';
@@ -146,27 +147,59 @@ class SendPageRobot {
146147
await commonTestCases.defaultSleepTime();
147148
}
148149

149-
Future<void> enterAmount(String amount) async {
150-
await commonTestCases.enterText(amount, 'send_page_amount_textfield_key');
150+
Future<void> enterSendAmount(String amount, {bool isFiat = false}) async {
151+
await commonTestCases.enterText(
152+
amount,
153+
isFiat ? 'send_page_fiat_amount_textfield_key' : 'send_page_amount_textfield_key',
154+
);
155+
}
156+
157+
String _getTextFromField(ValueKey<String> key) {
158+
final field = find.byKey(key);
159+
if (!field.tryEvaluate()) return '';
160+
final baseTextFormField = tester.widget<BaseTextFormField>(field);
161+
return baseTextFormField.controller?.text ?? '';
151162
}
152163

153-
Future<void> validateWalletBalance() async {
164+
/// Validates wallet balance for $1 send by checking against the converted crypto amount
165+
/// Returns true if wallet has sufficient balance, false otherwise
166+
Future<bool> validateWalletBalanceForOneDollarSend() async {
154167
SendPage sendPage = tester.widget(find.byType(SendPage));
155168
final sendViewModel = sendPage.sendViewModel;
156169

157170
final balance = await sendViewModel.sendingBalance;
158-
final amount = double.tryParse(CommonTestConstants.sendTestAmount) ?? 0.0;
159171

160-
tester.printToConsole('Wallet balance: $balance, sending amount: $amount');
172+
await setupOneDollarSend();
173+
174+
// Get the crypto amount that was set for the $1 send
175+
String cryptoAmount = _getTextFromField(ValueKey('send_page_amount_textfield_key'));
176+
if (cryptoAmount.isEmpty || cryptoAmount == '0' || cryptoAmount == '0.0') {
177+
cryptoAmount = '0.001'; // fallback amount
178+
}
179+
180+
final amount = double.tryParse(cryptoAmount) ?? 0.0;
181+
182+
tester.printToConsole(
183+
'Wallet balance: $balance, sending amount for \$${CommonTestConstants.sendTestFiatAmount}: $cryptoAmount',
184+
);
161185

162186
if (balance.isEmpty || double.tryParse(balance) == null) {
163-
throw Exception('Invalid wallet balance: $balance');
187+
tester.printToConsole('Invalid wallet balance: $balance');
188+
return false;
164189
}
165190

166191
final balanceValue = double.parse(balance);
167192
if (balanceValue < amount) {
168-
throw Exception('Insufficient balance: $balanceValue < $amount');
193+
tester.printToConsole(
194+
'Insufficient balance for \$${CommonTestConstants.sendTestFiatAmount} send: $balanceValue < $amount',
195+
);
196+
return false;
169197
}
198+
199+
tester.printToConsole(
200+
'Wallet has sufficient balance for \$${CommonTestConstants.sendTestFiatAmount} send',
201+
);
202+
return true;
170203
}
171204

172205
Future<void> selectTransactionPriority({TransactionPriority? priority}) async {
@@ -596,4 +629,92 @@ class SendPageRobot {
596629
await commonTestCases.defaultSleepTime();
597630
}
598631
}
632+
633+
//* ---- Fiat/Crypto Amount Validation -----
634+
Future<void> testFiatAmountEntry() async {
635+
tester.printToConsole('Testing fiat amount entry...');
636+
637+
await enterSendAmount('');
638+
await enterSendAmount('', isFiat: true);
639+
await commonTestCases.defaultSleepTime();
640+
641+
await enterSendAmount(CommonTestConstants.sendTestFiatAmount, isFiat: true);
642+
await commonTestCases.defaultSleepTime();
643+
644+
// Wait for conversion to complete
645+
await tester.pump(Duration(seconds: 3));
646+
await tester.pumpAndSettle();
647+
648+
// Next we get the crypto amount value and validate it's not 0
649+
final cryptoAmount = _getTextFromField(ValueKey('send_page_amount_textfield_key'));
650+
651+
tester.printToConsole(
652+
'Crypto amount after entering \$${CommonTestConstants.sendTestFiatAmount}: $cryptoAmount',
653+
);
654+
655+
if (cryptoAmount.isNotEmpty && cryptoAmount != '0' && cryptoAmount != '0.0') {
656+
tester.printToConsole('Fiat to crypto conversion working - crypto amount: $cryptoAmount');
657+
} else {
658+
tester.printToConsole(
659+
'Fiat to crypto conversion may not be working - crypto amount: $cryptoAmount',
660+
);
661+
}
662+
}
663+
664+
Future<void> testCryptoAmountEntry() async {
665+
tester.printToConsole('Testing crypto amount entry...');
666+
667+
await enterSendAmount('');
668+
await enterSendAmount('', isFiat: true);
669+
await commonTestCases.defaultSleepTime();
670+
671+
String cryptoAmount = '0.001';
672+
673+
await enterSendAmount(cryptoAmount);
674+
await commonTestCases.defaultSleepTime();
675+
676+
// Wait for conversion to complete
677+
await tester.pump(Duration(seconds: 3));
678+
await tester.pumpAndSettle();
679+
680+
// Get the fiat amount value and validate it's not 0
681+
final fiatAmount = _getTextFromField(ValueKey('send_page_fiat_amount_textfield_key'));
682+
683+
tester.printToConsole('Fiat amount after entering $cryptoAmount: $fiatAmount');
684+
685+
if (fiatAmount.isNotEmpty && fiatAmount != '0' && fiatAmount != '0.0') {
686+
tester.printToConsole('Crypto to fiat conversion working, fiat amount: $fiatAmount');
687+
} else {
688+
tester.printToConsole(
689+
'Crypto to fiat conversion may not be working - fiat amount: $fiatAmount');
690+
}
691+
}
692+
693+
Future<void> setupOneDollarSend() async {
694+
// Clear existing amounts
695+
await enterSendAmount('');
696+
await enterSendAmount('', isFiat: true);
697+
await commonTestCases.defaultSleepTime();
698+
699+
await enterSendAmount(CommonTestConstants.sendTestFiatAmount, isFiat: true);
700+
await commonTestCases.defaultSleepTime();
701+
702+
// Wait for conversion to complete
703+
await tester.pump(Duration(seconds: 3));
704+
await tester.pumpAndSettle();
705+
706+
// Get the converted crypto amount
707+
String cryptoAmount = _getTextFromField(ValueKey('send_page_amount_textfield_key'));
708+
if (cryptoAmount.isEmpty || cryptoAmount == '0' || cryptoAmount == '0.0') {
709+
cryptoAmount = '0.001'; // fallback amount
710+
}
711+
712+
tester.printToConsole(
713+
'Sending $cryptoAmount (equivalent to \$${CommonTestConstants.sendTestFiatAmount}) to test wallet',
714+
);
715+
716+
// Update the amount field with the converted value
717+
await enterSendAmount(cryptoAmount);
718+
await commonTestCases.defaultSleepTime();
719+
}
599720
}

0 commit comments

Comments
 (0)