feat: add unit tests CI workflow (#3640)
What changed, and why it matters
This commit adds a new automated unit-test workflow to the project's GitHub Actions CI pipeline and fixes several existing tests that were failing. It also makes a small UI improvement (adding a 'truncateLabel' option for settings rows) and updates a secrets-import helper to include Bitcoin configuration. There is no security-relevant change here.
No security action required. This is a routine CI/test maintenance commit. Reviewers may optionally verify that placeholder secrets are indeed non-sensitive and that no real credentials are committed.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff introduces a standalone ‘unit_tests’ job in .github/workflows/pr_test_build_linux.yml that runs flutter test for every package containing a test directory, reports per-package results, and uses placeholder secrets so tests do not depend on real API keys. It removes two old package-specific test steps from the build job. Test files are updated to match current code behavior (address validator regex expectations, top-bar widget API, wallet info spacing, money text localization). A new truncateLabel flag is threaded through ListItemRegularRow and its widget to ellipsize long labels. tool/import_secrets_config.dart gains Bitcoin output handling, and cw_nano/.gitignore is added.
Changed components
.github/workflows/pr_test_build_linux.ymltest/core/address_validator_test.darttest/core/lightning_invoice_service_test.darttest/new-ui/widgets/coins_page/top_bar_widget/top_bar_test.darttest/new-ui/widgets/coins_page/wallet_info_test.darttest/new-ui/widgets/money/money_text_test.dartlib/entities/new_ui_entities/list_item/list_item_regular_row.dartlib/new-ui/pages/settings_page.dartlib/src/widgets/new_list_row/list_item_regular_row_widget.dartlib/src/widgets/new_list_row/new_list_section.darttool/import_secrets_config.dartcw_nano/.gitignoreInspect captured patch +162 / −46
### .github/workflows/pr_test_build_linux.yml
@@ -331,10 +331,95 @@ jobs:
path: ${{ github.workspace }}/build/linux/x64/release/cakewallet_linux.zip
name: cakewallet_linux
- - name: Test [cw_core]
- timeout-minutes: 15
- run: cd cw_core && flutter test
+ unit_tests:
+ needs: final
+ runs-on: puzl-ubuntu-latest
+ timeout-minutes: 90
+ container:
+ image: ghcr.io/cake-tech/cake_wallet:debian13-flutter3.41.9-ndkr28-go1.24.1-ruststablenightly
+ volumes:
+ - /var/run/docker.sock:/var/run/docker.sock
+ steps:
+ - name: Fix github actions messing up $HOME...
+ run: "echo HOME=/root | sudo tee -a $GITHUB_ENV"
+
+ - uses: actions/checkout@v4
+ if: ${{ env.ACT != 'true' }}
+ with:
+ ref: ${{ github.event.pull_request.head.sha }}
+ repository: ${{ github.event.pull_request.head.repo.full_name }}
+
+ - name: Docker sock permissions
+ run: sudo chmod 666 /var/run/docker.sock || true
+
+ - name: Log in to GitHub Container Registry
+ uses: docker/login-action@v3
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: configure git
+ run: |
+ git config --global --add safe.directory '*'
+ git config --global user.email "ci@cakewallet.com"
+ git config --global user.name "CakeWallet CI"
+ git config --global --unset-all credential.helper || true
+ git config --global url."https://x-access-token:${{ github.token }}@github.com/".insteadOf "https://github.com/"
+
+ - name: Extract native dependencies
+ run: ./scripts/linux/docker/build.sh --extract
+
+ - name: Execute Build and Setup Commands
+ run: |
+ pushd scripts/linux
+ source ./app_env.sh cakewallet
+ ./app_config.sh
+ popd
+
+ - name: Install Flutter dependencies
+ run: |
+ flutter pub get
- - name: Test [cw_monero]
- timeout-minutes: 15
- run: cd cw_monero && flutter test
+ # The tests must not depend on real API keys, so the placeholder generator is used
+ # instead of the repository secrets.
+ - name: Generate placeholder secrets
+ run: |
+ dart run tool/generate_new_secrets.dart
+
+ - name: Build generated code
+ run: |
+ ./model_generator.sh
+
+ - name: Generate localization
+ run: |
+ dart run tool/generate_localization.dart
+
+ - name: Compile graphics
+ run: |
+ ./compile_graphics.sh
+
+ # Every package with a test directory is run, and a failure in one package does not
+ # stop the others, so the summary names every package that is red.
+ - name: Run unit tests
+ run: |
+ failed=()
+ printf "| Package | Result |\n|---|---|\n" >> "$GITHUB_STEP_SUMMARY"
+ for pkg in . cw_*; do
+ if [[ ! -d "$pkg/test" ]]; then
+ continue
+ fi
+ name=$(basename "$(cd "$pkg" && pwd)")
+ echo "=== flutter test: $name ==="
+ if (cd "$pkg" && flutter test); then
+ echo "| $name | passed |" >> "$GITHUB_STEP_SUMMARY"
+ else
+ failed+=("$name")
+ echo "| $name | FAILED |" >> "$GITHUB_STEP_SUMMARY"
+ fi
+ done
+ if (( ${#failed[@]} > 0 )); then
+ echo "::error::Unit tests failed in: ${failed[*]}"
+ exit 1
+ fi
+ echo "All unit tests passed"
### cw_nano/.gitignore
@@ -0,0 +1,28 @@
+# Miscellaneous
+*.class
+*.log
+*.pyc
+*.swp
+.DS_Store
+.atom/
+.buildlog/
+.history
+.svn/
+migrate_working_dir/
+
+# IntelliJ related
+*.iml
+*.ipr
+*.iws
+.idea/
+
+# The .vscode folder contains launch configuration and tasks you configure in
+# VS Code which you may wish to be included in version control, so this line
+# is commented out by default.
+#.vscode/
+
+# Flutter/Dart/Pub related
+**/doc/api/
+.dart_tool/
+.packages
+build/
### lib/entities/new_ui_entities/list_item/list_item_regular_row.dart
@@ -15,6 +15,7 @@ class ListItemRegularRow extends ListItem {
this.bottomWidget,
this.trailingWidget,
this.truncateTrailingText = false,
+ this.truncateLabel = false,
this.foregroundColor,
this.trailingIconSize,
this.copyableText,
@@ -38,6 +39,7 @@ class ListItemRegularRow extends ListItem {
final Widget? bottomWidget;
final Widget? trailingWidget;
final bool truncateTrailingText;
+ final bool truncateLabel;
final Color? subtitleColor;
final Color? foregroundColor;
final double? trailingIconSize;
### lib/new-ui/pages/settings_page.dart
@@ -295,6 +295,7 @@ class SettingsMainPage extends StatelessWidget {
"wallet_type_settings": [
ListItemRegularRow(
keyValue: "wallet_type_settings",
+ truncateLabel: true,
label: _walletSettingsResolver.titleFor(
dashboardViewModel.wallet.type,
S.of(context),
@@ -333,6 +334,7 @@ class SettingsMainPage extends StatelessWidget {
ListItemRegularRow _buildRow(BuildContext context, SettingsListItem item) => ListItemRegularRow(
keyValue: item.route,
+ truncateLabel: true,
label: item.title,
iconPath: item.iconPath,
onTap: () => _openItem(context, item),
@@ -399,6 +401,7 @@ class WalletSettingsPage extends StatelessWidget {
.map(
(item) => ListItemRegularRow(
keyValue: item.route,
+ truncateLabel: true,
label: item.title,
iconPath: item.iconPath,
onTap: () => _openItem(context, item),
### lib/src/widgets/new_list_row/list_item_regular_row_widget.dart
@@ -20,6 +20,7 @@ class ListItemRegularRowWidget extends StatelessWidget {
this.showArrow = true,
this.trailingIconPath,
this.truncateTrailingText = false,
+ this.truncateLabel = false,
this.foregroundColor,
this.trailingIconSize,
this.bottomWidget,
@@ -48,6 +49,7 @@ class ListItemRegularRowWidget extends StatelessWidget {
final Widget? bottomWidget;
final Widget? trailingWidget;
final bool truncateTrailingText;
+ final bool truncateLabel;
final Color? foregroundColor;
final double? trailingIconSize;
final String? copyableText;
@@ -76,6 +78,9 @@ class ListItemRegularRowWidget extends StatelessWidget {
isFirstInSection: isFirstInSection,
isLastInSection: isLastInSection,
builder: (context, textStyle, labelStyle) {
+ final labelTextStyle = foregroundColor == null
+ ? textStyle
+ : textStyle.copyWith(color: foregroundColor);
final leadingIcon = iconPath != null
? CakeImageWidget(
imageUrl: iconPath!,
@@ -150,10 +155,17 @@ class ListItemRegularRowWidget extends StatelessWidget {
Row(
spacing: 4,
children: [
- Text(label,
- style: foregroundColor == null
- ? textStyle
- : textStyle.copyWith(color: foregroundColor)),
+ if (truncateLabel)
+ Flexible(
+ child: Text(
+ label,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: labelTextStyle,
+ ),
+ )
+ else
+ Text(label, style: labelTextStyle),
if (secondaryLabel != null)
Text(
secondaryLabel!,
### lib/src/widgets/new_list_row/new_list_section.dart
@@ -105,6 +105,7 @@ class NewListSections extends StatelessWidget {
isLastInSection: isLast,
showArrow: item.showArrow,
truncateTrailingText: item.truncateTrailingText,
+ truncateLabel: item.truncateLabel,
foregroundColor: item.foregroundColor,
copyableText: item.copyableText,
trailingIconSize: item.trailingIconSize,
### test/core/address_validator_test.dart
@@ -12,7 +12,7 @@ void main() {
test('returns correct pattern for Bitcoin', () {
final pattern = AddressValidator.getPattern(CryptoCurrency.btc);
expect(pattern, isNotEmpty);
- expect(pattern, contains('(bc|tb)1q'));
+ expect(pattern, contains("bc1q[ac-hj-np-z02-9]{25,39}"));
});
test('returns correct pattern for Ethereum', () {
@@ -30,8 +30,8 @@ void main() {
test('returns correct pattern for Litecoin', () {
final pattern = AddressValidator.getPattern(CryptoCurrency.ltc);
expect(pattern, isNotEmpty);
- expect(pattern,
- contains('(bc|tb|ltc)1q[ac-hj-np-z02-9]{25,39}|(ltc|t)mweb1q[ac-hj-np-z02-9]{90,120}'));
+ expect(pattern, contains("ltc1q[ac-hj-np-z02-9]{25,39}"));
+ expect(pattern, contains("(ltc|t)mweb1q[ac-hj-np-z02-9]{90,120}"));
});
test('returns empty string for unknown currency', () {
### test/core/lightning_invoice_service_test.dart
@@ -1,31 +0,0 @@
-import "package:cake_wallet/core/lightning_invoice_service.dart";
-import "package:cw_core/lnurl.dart";
-import "package:cw_core/utils/proxy_wrapper.dart";
-import "package:cw_core/utils/tor/abstract.dart";
-import "package:flutter_test/flutter_test.dart";
-
-Future<void> main() async {
- CakeTor.instance = await CakeTorInstance.getInstance();
-
- group("lightning_invoice_service", () {
- test("Should resolve an empty Bolt11 invoice konsti@cake.cash", () async {
- final invoice = await getBolt11FromLightingAddress("konsti@cake.cash");
-
- expect(invoice, isNotNull);
- expect(isBolt11ZeroInvoice(invoice!), isTrue);
- });
-
- test("Should not resolve an empty Bolt11 invoice viksharma@cluborange.org", () async {
- final invoice = await getBolt11FromLightingAddress("viksharma@cluborange.org");
-
- expect(invoice, isNull);
- });
-
- test("Should resolve an Bolt11 invoice viksharma@cluborange.org", () async {
- final invoice =
- await getBolt11FromLightingAddress("viksharma@cluborange.org", amount: 1000000000);
-
- expect(invoice, isNotNull);
- });
- });
-}
### test/new-ui/widgets/coins_page/top_bar_widget/top_bar_test.dart
@@ -56,6 +56,7 @@ void _stubDashboardViewModel(
bool silentPaymentsScanningActive = false,
}) {
when(() => dashboardViewModel.hasLightning).thenReturn(hasLightning);
+ when(() => dashboardViewModel.lightningMode).thenReturn(false);
when(() => dashboardViewModel.isSyncHeavy).thenReturn(isSyncHeavy);
when(() => dashboardViewModel.isTorEnabled).thenReturn(false);
when(() => dashboardViewModel.hasMweb).thenReturn(false);
@@ -71,7 +72,6 @@ void _stubDashboardViewModel(
}
Widget _buildTopBar(DashboardViewModel dashboardViewModel) => TopBar(
- lightningMode: false,
onLightningSwitchPress: () {},
dashboardViewModel: dashboardViewModel,
onSettingsButtonPress: () {},
### test/new-ui/widgets/coins_page/wallet_info_test.dart
@@ -47,7 +47,7 @@ void main() {
expect(
tester.getRect(find.text(walletName)).left -
tester.getRect(find.byKey(const ValueKey("hardware_wallet_icon"))).right,
- 4,
+ 8,
);
expect(
### test/new-ui/widgets/money/money_text_test.dart
@@ -1,5 +1,7 @@
import "package:cake_wallet/entities/balance_display_mode.dart";
import "package:cake_wallet/entities/bitcoin_amount_display_mode.dart";
+import "package:cake_wallet/generated/i18n.dart";
+import "package:cake_wallet/locales/locale.dart";
import "package:cake_wallet/new-ui/widgets/money/money_settings_cubit.dart";
import "package:cake_wallet/new-ui/widgets/money/money_text.dart";
import "package:cw_core/amount/money.dart";
@@ -56,6 +58,8 @@ Future<FakeMoneySettingsCubit> _pump(
addTearDown(cubit.close);
await tester.pumpWidget(
MaterialApp(
+ localizationsDelegates: localizationDelegates,
+ supportedLocales: S.delegate.supportedLocales,
home: BlocProvider<MoneySettingsCubit>.value(
value: cubit,
child: Scaffold(body: Center(child: child)),
### tool/import_secrets_config.dart
@@ -44,6 +44,12 @@ Future<void> importSecretsConfig() async {
final tronOutput =
tronInput.keys.fold('', (String acc, String val) => acc + generateConst(val, tronInput));
+ final bitcoinOutputFile = File(bitcoinOutputPath);
+ final bitcoinInput =
+ json.decode(File(bitcoinConfigPath).readAsStringSync()) as Map<String, dynamic>;
+ final bitcoinOutput = bitcoinInput.keys
+ .fold("", (String acc, String val) => acc + generateConst(val, bitcoinInput));
+
final nanoOutputFile = File(nanoOutputPath);
final nanoInput = json.decode(File(nanoConfigPath).readAsStringSync()) as Map<String, dynamic>;
final nanoOutput =
@@ -73,6 +79,12 @@ Future<void> importSecretsConfig() async {
await tronOutputFile.writeAsString(tronOutput);
+ if (bitcoinOutputFile.existsSync()) {
+ await bitcoinOutputFile.delete();
+ }
+
+ await bitcoinOutputFile.writeAsString(bitcoinOutput);
+
if (nanoOutputFile.existsSync()) {
await nanoOutputFile.delete();
}Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.