taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

commit 6912efc8517fa2e05e80c130720803cd31285391
parent 89c4cc999e125ed16c82f6769290fa55c3b38749
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat, 17 Oct 2026 22:15:48 +0200

Add simulator for the wallet to drive the app and find issues.

Assisted by LLM

Diffstat:
Asimulator/.gitignore | 2++
Asimulator/README.md | 401+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/backend/exchange2.sh | 147+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/backend/services/README.md | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/backend/services/mailbox-sim.conf | 34++++++++++++++++++++++++++++++++++
Asimulator/backend/services/taldir-sim.conf | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/backend/services/taldir-validator.sh | 6++++++
Asimulator/backend/sim-exchange2.conf | 197+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/backend/sim-kyc.conf | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/backend/sim-twister.conf | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/backend/sim.conf | 374+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/backend/stack.sh | 366+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/corpus/uris.py | 150+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/coverage/app-operations.txt | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/coverage/gaps.py | 252+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/coverage/operations.py | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/coverage/report.sh | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/coverage/validate_ec.py | 131+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/campaign.py | 192+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/cli.py | 254+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/coverage.py | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/dbprobe.py | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/device.py | 515+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/episode.py | 255+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/explore.py | 213+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/forever.sh | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/matrix.py | 182+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/oracles.py | 488+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/phase.sh | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/probe.py | 98+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/qrsuite.py | 230+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/replay.py | 158+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/report.py | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/scenarios.py | 346+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/smoke_pay.py | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/smoke_withdraw.py | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/stack.py | 508+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/suite.py | 5755+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/twister.py | 186+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/driver/wallet.py | 200+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/emu/emu.sh | 208+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/emu/tls-names.sh | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/CAMPAIGN.md | 2007+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/PATCHES.md | 148+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/__pycache__/repro_untranslated_contacts_mailbox.cpython-313.pyc | 0
Asimulator/findings/a-failed-query-is-shown-as-an-empty-wallet.md | 139+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/aborted-credit-shows-the-whole-amount-as-fee.diff | 113+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/aborted-credit-shows-the-whole-amount-as-fee.md | 120+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/action-buttons-have-no-accessible-name.diff | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/action-buttons-have-no-accessible-name.md | 162+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/add-account-note-is-required-but-unmarked.diff | 13+++++++++++++
Asimulator/findings/add-account-note-is-required-but-unmarked.md | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/add-payment-service-fails-silently.md | 147+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/addglobalcurrencyexchange-null-masterpub.md | 154+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/alias-registration-hardcodes-the-directory.md | 143+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/amounts-without-currency-specification.diff | 182+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/amounts-without-currency-specification.md | 140+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/bitcoin-transfer-relabels-the-amount-as-btc.md | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/config-change-locks-the-wallet-out-of-its-database.diff | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/config-change-locks-the-wallet-out-of-its-database.md | 225+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/contacts-and-mailbox-cannot-be-translated.diff | 354+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/contacts-and-mailbox-cannot-be-translated.md | 177+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/delete-transaction-requeries-deleted-id.diff | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/delete-transaction-requeries-deleted-id.md | 117+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/deposit-does-not-guard-zero-amounts.md | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/dev-experiment-uri-exits-the-app.md | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/donation-statements-button-is-wired-to-nothing.diff | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/donation-statements-button-is-wired-to-nothing.md | 132+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/error-code-registry-behind-wallet-core.md | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/mailbox-payment-only-actionable-for-one-scheme.diff | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/mailbox-payment-only-actionable-for-one-scheme.md | 198+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/mailbox-private-keys-written-to-log.diff | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/mailbox-private-keys-written-to-log.md | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/new_finding.py | 149+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/payto-link-only-accepts-iban.diff | 44++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/payto-link-only-accepts-iban.md | 134+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/pos-confirmation-shows-five-codes.md | 107+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/purge-destroys-coins-and-history-without-saying-so.md | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/qr-camera-ignores-the-plane-strides.diff | 538+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/qr-camera-ignores-the-plane-strides.md | 297+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/refresh-fails-on-mixed-age-denominations.md | 117+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/release-error-screen-explains-nothing.diff | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/release-error-screen-explains-nothing.md | 225+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_aborted_fee.py | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_action_buttons_no_a11y_name.py | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_add_exchange_fails_silently.py | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_age_restricted_refresh_fails.py | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_config_change_db_ownership.py | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_delete_requeries_transaction.py | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_dev_experiment_uri_exits_app.py | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_failed_query_empty_state.py | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_global_currency_null_masterpub.py | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_mailbox_private_keys_in_log.py | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_pos_confirmation_codes.py | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_release_error_screen.py | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_unknown_currency_formatting.py | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_unknown_wire_method.py | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_unreachable_host_zombie_purchase.py | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_unspecced_amounts.py | 100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_untranslated_contacts_mailbox.py | 140+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_wallet_lock_bypass.py | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/repro_zero_deposit.py | 108+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/reset-dialog-puts-the-wipe-where-cancel-belongs.diff | 41+++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/reset-dialog-puts-the-wipe-where-cancel-belongs.md | 125+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/suspended-looks-like-completed-in-the-list.diff | 40++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/suspended-looks-like-completed-in-the-list.md | 137+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/taldir-protocol-version-mismatch.md | 108+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/unknown-wire-method-hangs-the-deposit-form.md | 166+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/unreachable-host-leaves-blank-retrying-purchase.diff | 21+++++++++++++++++++++
Asimulator/findings/unreachable-host-leaves-blank-retrying-purchase.md | 188+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/wallet-lock-opens-when-the-credential-is-gone.md | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/findings/word-currency-symbol-glued-to-amount.md | 125+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/tls/README.md | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asimulator/tls/go.mod | 3+++
Asimulator/tls/tlsproxy.go | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/.gitignore | 2++
Awallet-simulator/README.md | 401+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/backend/exchange2.sh | 147+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/backend/services/README.md | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/backend/services/mailbox-sim.conf | 34++++++++++++++++++++++++++++++++++
Awallet-simulator/backend/services/taldir-sim.conf | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/backend/services/taldir-validator.sh | 6++++++
Awallet-simulator/backend/sim-exchange2.conf | 197+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/backend/sim-kyc.conf | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/backend/sim-twister.conf | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/backend/sim.conf | 374+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/backend/stack.sh | 366+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/corpus/uris.py | 150+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/coverage/app-operations.txt | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/coverage/gaps.py | 252+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/coverage/operations.py | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/coverage/report.sh | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/coverage/validate_ec.py | 131+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/campaign.py | 192+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/cli.py | 254+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/coverage.py | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/dbprobe.py | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/device.py | 515+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/episode.py | 255+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/explore.py | 213+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/forever.sh | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/matrix.py | 182+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/oracles.py | 488+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/phase.sh | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/probe.py | 98+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/qrsuite.py | 230+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/replay.py | 158+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/report.py | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/scenarios.py | 346+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/smoke_pay.py | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/smoke_withdraw.py | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/stack.py | 508+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/suite.py | 5755+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/twister.py | 186+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/driver/wallet.py | 200+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/emu/emu.sh | 208+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/emu/tls-names.sh | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/CAMPAIGN.md | 2007+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/PATCHES.md | 148+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/__pycache__/repro_untranslated_contacts_mailbox.cpython-313.pyc | 0
Awallet-simulator/findings/a-failed-query-is-shown-as-an-empty-wallet.md | 139+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/aborted-credit-shows-the-whole-amount-as-fee.diff | 113+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/aborted-credit-shows-the-whole-amount-as-fee.md | 120+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/action-buttons-have-no-accessible-name.diff | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/action-buttons-have-no-accessible-name.md | 162+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/add-account-note-is-required-but-unmarked.diff | 13+++++++++++++
Awallet-simulator/findings/add-account-note-is-required-but-unmarked.md | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/add-payment-service-fails-silently.md | 147+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/addglobalcurrencyexchange-null-masterpub.md | 154+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/alias-registration-hardcodes-the-directory.md | 143+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/amounts-without-currency-specification.diff | 182+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/amounts-without-currency-specification.md | 140+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/bitcoin-transfer-relabels-the-amount-as-btc.md | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/config-change-locks-the-wallet-out-of-its-database.diff | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/config-change-locks-the-wallet-out-of-its-database.md | 225+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/contacts-and-mailbox-cannot-be-translated.diff | 354+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/contacts-and-mailbox-cannot-be-translated.md | 177+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/delete-transaction-requeries-deleted-id.diff | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/delete-transaction-requeries-deleted-id.md | 117+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/deposit-does-not-guard-zero-amounts.md | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/dev-experiment-uri-exits-the-app.md | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/donation-statements-button-is-wired-to-nothing.diff | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/donation-statements-button-is-wired-to-nothing.md | 132+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/error-code-registry-behind-wallet-core.md | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/mailbox-payment-only-actionable-for-one-scheme.diff | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/mailbox-payment-only-actionable-for-one-scheme.md | 198+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/mailbox-private-keys-written-to-log.diff | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/mailbox-private-keys-written-to-log.md | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/new_finding.py | 149+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/payto-link-only-accepts-iban.diff | 44++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/payto-link-only-accepts-iban.md | 134+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/pos-confirmation-shows-five-codes.md | 107+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/purge-destroys-coins-and-history-without-saying-so.md | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/qr-camera-ignores-the-plane-strides.diff | 538+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/qr-camera-ignores-the-plane-strides.md | 297+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/refresh-fails-on-mixed-age-denominations.md | 117+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/release-error-screen-explains-nothing.diff | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/release-error-screen-explains-nothing.md | 225+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_aborted_fee.py | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_action_buttons_no_a11y_name.py | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_add_exchange_fails_silently.py | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_age_restricted_refresh_fails.py | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_config_change_db_ownership.py | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_delete_requeries_transaction.py | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_dev_experiment_uri_exits_app.py | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_failed_query_empty_state.py | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_global_currency_null_masterpub.py | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_mailbox_private_keys_in_log.py | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_pos_confirmation_codes.py | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_release_error_screen.py | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_unknown_currency_formatting.py | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_unknown_wire_method.py | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_unreachable_host_zombie_purchase.py | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_unspecced_amounts.py | 100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_untranslated_contacts_mailbox.py | 140+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_wallet_lock_bypass.py | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/repro_zero_deposit.py | 108+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/reset-dialog-puts-the-wipe-where-cancel-belongs.diff | 41+++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/reset-dialog-puts-the-wipe-where-cancel-belongs.md | 125+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/suspended-looks-like-completed-in-the-list.diff | 40++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/suspended-looks-like-completed-in-the-list.md | 137+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/taldir-protocol-version-mismatch.md | 108+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/unknown-wire-method-hangs-the-deposit-form.md | 166+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/unreachable-host-leaves-blank-retrying-purchase.diff | 21+++++++++++++++++++++
Awallet-simulator/findings/unreachable-host-leaves-blank-retrying-purchase.md | 188+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/wallet-lock-opens-when-the-credential-is-gone.md | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/findings/word-currency-symbol-glued-to-amount.md | 125+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/tls/README.md | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet-simulator/tls/go.mod | 3+++
Awallet-simulator/tls/tlsproxy.go | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mwallet/build.gradle | 24++++++++++++++++++++++++
Awallet/src/androidTestSim/java/net/taler/wallet/sim/SimCoverageAnchorTest.kt | 43+++++++++++++++++++++++++++++++++++++++++++
Awallet/src/sim/AndroidManifest.xml | 33+++++++++++++++++++++++++++++++++
Awallet/src/sim/java/net/taler/wallet/sim/SimHooks.kt | 137+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awallet/src/sim/res/raw/sim_ca.crt | 20++++++++++++++++++++
Awallet/src/sim/res/xml/network_security_config.xml | 24++++++++++++++++++++++++
236 files changed, 47383 insertions(+), 0 deletions(-)

diff --git a/simulator/.gitignore b/simulator/.gitignore @@ -0,0 +1,2 @@ +# Generated by the simulator: coverage reports, episode artifacts, pulled logs. +out/ diff --git a/simulator/README.md b/simulator/README.md @@ -0,0 +1,401 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Wallet simulator + +Drives the Android wallet in an emulator against a local GNU Taler stack, to +measure how much of the app gets exercised and to find sequences that end in an +internal-core-error screen, a stuck transaction or a crash. + +## Where it runs + +Everything runs on `tripwire.taler.net` (256 cores, 251 GB RAM, KVM): the Taler +services, the emulators and the driver all live there, so the observe-act loop +never crosses the network. Only the APK is built elsewhere and copied in. + +``` +tripwire:/opt/taler-sim/ + backend/ sim.conf, stack.sh the Taler services + emu/ emu.sh AVD lifecycle, one AVD per worker + driver/ device.py stack.py emulator control, counterparty HTTP clients + apk/ wallet.apk pushed from a build host + run/ stack/env.json, logs, emulator logs +``` + +The checkout under `simulator/` in taler-android is the source of truth; push it +with + +```bash +rsync -a simulator/ root@tripwire.taler.net:/opt/taler-sim/ +``` + +## Running it + +Bring the stack and one emulator up, then check that the basics work: + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim + +backend/stack.sh start # wipes the DB, starts the services, ~15 s +emu/emu.sh create 0 # once per worker +emu/emu.sh boot 0 # ~50 s +emu/emu.sh prepare 0 # install the APK, kill animations, adb reverse +cd driver +python3 stack.py # merchant instance, bank accounts, top-ups +python3 smoke_withdraw.py # end-to-end withdrawal through the UI +python3 smoke_pay.py # order, pay, refund +``` + +Then drive it in earnest. One scenario, or a few, on one worker: + +```bash +python3 suite.py --list +SIM_WORKER=0 python3 suite.py history exchange_add_remove +``` + +Everything, across four emulators, with the findings merged: + +```bash +python3 campaign.py suite --workers 4 --tag try1 +python3 campaign.py explore --workers 4 --steps 150 --seed 42 +``` + +Unattended, round after round (provision, a random walk with a fresh seed, +then every scenario, dumping coverage after each phase): + +```bash +nohup setsid ./forever.sh 1 > /opt/taler-sim/run/forever.log 2>&1 & +tail -f /opt/taler-sim/run/rounds.log +touch /opt/taler-sim/run/STOP # stops after the round in flight +``` + +A set of scenarios that needs a different stack — KYC, or fault injection — +goes through `phase.sh`, which pauses the rounds, swaps the stack, runs them, +restores the default stack and resumes: + +```bash +./phase.sh sim-kyc.conf kyc_withdraw_trips_rule kyc_transaction_actions +./phase.sh sim-twister.conf twister_withdraw_faults twister_field_faults +SIM_DESTRUCTIVE=1 ./phase.sh sim.conf revoke_denomination +``` + +The environment reaches the scenarios, so a phase is also how a destructive +scenario gets a stack of its own to ruin. + +Reading the results: + +```bash +python3 report.py '*history*' --notes # episodes and their findings +python3 ../coverage/operations.py # wallet-core operations exercised +``` + +Coverage reports are built where the APK was built, because they need the +uninstrumented classes and the sources: + +```bash +rsync -a root@tripwire.taler.net:/opt/taler-sim/run/coverage/ /tmp/ec/ +JAVA_HOME=/home/claude/jdk-17 simulator/coverage/report.sh /tmp/ec +python3 simulator/coverage/gaps.py simulator/out/coverage/coverage.xml +``` + +`gaps.py` ranks what is still untouched. Four composables in that ranking have +no caller at all -- `PromptAddContactScreen`, `GridMenu`, `DemandAttention` and +`SelectExchangeDialogFragment`, about 190 lines -- so no scenario can ever +reach them. + +## The app under test + +The simulator drives the **`sim` build type** of the wallet +(`./gradlew :wallet:assembleFdroidSim`), which is `debug` plus two things: + +* `enableAndroidTestCoverage`, so the APK carries the JaCoCo agent and + `driver/coverage.py` can ask it for execution data mid-session; +* `wallet/src/sim/`, a receiver (`SimHooks`) for the two things adb cannot do — + dumping that coverage, and delivering an NDEF message the way a tapped NFC + tag would (the extra is a Parcelable, so `am start` cannot carry it). + +It keeps the `.debug` application id, so the package driven is the same +`net.taler.wallet.fdroid.debug` a developer would install, and it is never +published. + +One side effect worth knowing: `testBuildType "sim"` is what makes AGP create +an androidTest variant for this build type (and therefore instrument the app's +classes at all), and it also moves which unit-test task `:wallet:check` +resolves to — `testFdroidSimUnitTest` rather than `testFdroidDebugUnitTest`. +`sim` is `initWith debug`, so the same tests run against the same code, and CI +asks for `:wallet:check` rather than a task name. + +### Developer mode is mandatory + +`HandleUriScreen` only accepts `taler+http://` URIs when developer mode is on, +and `MainActivity` pushes the *persisted* flag into `MainViewModel` at every +start — so a debug build does **not** come up in developer mode, whatever +`BuildConfig.DEBUG` says. `Wallet.fresh_start()` therefore switches it on +through Settings before anything else; without that step every URI from a local +http stack comes back as "Unsupported URI". + +### A stack restart invalidates the wallet + +`stack.sh start` drops the database, so the exchange comes back with a new +master key and any coins already in the wallet are worthless. Always pair a +stack restart with a wallet wipe (`fresh_start()`, i.e. `pm clear`). + +## URL topology + +Every service is configured with a `http://localhost:<port>/` base URL, and the +driver maps those same ports into each emulator with `adb reverse`. One URL +namespace is therefore valid both on the host and inside the wallet, which +matters because the merchant and the bank hand out absolute URLs that both sides +have to be able to resolve. + +| Service | Port | +| --- | --- | +| donau | 8079 | +| merchant | 8080 | +| exchange | 8081 | +| libeufin-bank | 8082 | +| auditor | 8083 | + +Plain HTTP needs no patched app: `usesCleartextTraffic` is already set in the +wallet manifest, and wallet-core 1.6.42 (the version in the shipped +`net.taler:qtart` AAR) has retired its `allowHttp` flag — it logs +"allowHttp flag not supported anymore" and never requires TLS. A debug build +also starts in dev mode on its own, because `MainViewModel` seeds dev mode from +`BuildConfig.DEBUG`. + +## Config variants + +`backend/sim.conf` is the default stack. `SIM_CONF` selects a variant: + +| Variant | What it adds | +| --- | --- | +| `sim.conf` | exchange, merchant, libeufin bank, donau; two exchange accounts (x-taler-bank and IBAN) with a wire fee each, a signed Bitcoin address, terms of service, and age-restricted denominations | +| `sim-kyc.conf` | KYC on, with a rule that trips when more than EUR:5 is withdrawn in a day | +| `sim-twister.conf` | `taler-twister` in front of the exchange on port 8088, for fault injection | + +```bash +SIM_CONF=sim-twister.conf backend/stack.sh start +``` + +**Only one stack at a time.** The exchange's secmod helpers use a runtime +directory derived from the user, not from the config, so a second stack +started alongside the first takes its sockets away and both fail with +"Could not connect to taler-exchange-helper-secmod-cs". Stop one before +starting another, or give the second its own `TALER_RUNTIME_DIR`. + +### The second exchange + +`backend/exchange2.sh` runs a second, independent exchange on port 8091 from +`backend/sim-exchange2.conf`: its own database, offline key (so its own master +key), `TALER_RUNTIME_DIR` for the secmod sockets, and account at the stack's +libeufin bank. `stack.sh start` starts it as well unless `SIM_EXCHANGE2=0`, +and stops it first on the way down -- it has an account at a bank whose +database the stack wipes, so it cannot outlive a stack start. + +With only one payment service every "which one?" step picks the only +candidate: the exchange picker, "treat as global" and the balance scopes a +second service creates are unreachable without this. + +### Three things the default config gets wrong for a wallet + +Each cost this campaign a round or two to notice, and each is a one-line +config fix: + +* **A wire method the app does not know breaks the whole reply.** The + exchange's wire methods reach the app as an enum, and one unrecognised name + makes `getDepositWireTypes` throw rather than skipping it, which hangs the + add-account form (`findings/unknown-wire-method-hangs-the-deposit-form.md`). + `SIM_EXTRA_PAYTOS` therefore signs a Bitcoin address only; a Cyclos one is + opt-in, because keeping it would block every deposit scenario. +* **A wire method with no fee does not exist** as far as the wallet is + concerned. `taler-unified-setup.sh` signs a wire fee only for the method it + is told about with `-d`, and wallet-core hides every account whose method + has none, so a second enabled account stays invisible. `stack.sh` uploads a + fee for each extra account's method. +* **The shipped `TERMS_DIR` is empty.** It is `${TALER_DATA_HOME}terms/`, + which in a test home has nothing in it, so `/terms` answers "501 not + configured" and the wallet never asks anyone to accept anything. The + exchange serves *rendered* terms (one subdirectory per language), not the + `.rst` sources it ships, so `stack.sh` runs `taler-terms-generator` once + into `$SIM_ROOT/terms`. +* **Age restriction needs `AGE_RESTRICTION_ENABLED`** in `[exchange]` on top + of the age-restricted denominations, or `/keys` advertises an age mask of 0 + and the age picker never appears. + +## The three ways it drives the app + +**Scenarios** (`driver/suite.py`, 87 of them) walk one feature each, +deliberately: the transaction list and its per-transaction actions, suspend / +resume / abort / abandon, exchange management and terms of service, every +settings row, deposits in all three account formats, peer payments in both +directions, order templates, v1 contract choices and token issuance, the scan +screen's manual entry, and a batch of adversarial sequences (process death +mid-flow, airplane mode mid-withdrawal, two pay URIs at once, force-purging an +exchange that still holds coins). + +```bash +python3 suite.py --list +python3 suite.py history exchange_add_remove # a few +python3 campaign.py suite --workers 4 --tag iter5 # all of them, 4 emulators +``` + +A scenario that cannot reach its feature fails loudly (`Ctx.require`) instead +of reporting a green row for having done nothing. + +**Exploration** (`driver/explore.py`) takes over where scenarios end: it starts +from a funded, already-paid wallet and walks at random, biased towards screens +it has not seen, mixing in URIs from the corpus and environment faults. + +**QR codes through the camera** (`driver/qrsuite.py`) render a payload with +`qrencode`, hang it on the wall of the emulator's virtual scene and read it +with the camera, so the scan screen and `QrCameraAnalyzer` run for real. The +poster can only be set at launch, so there is one emulator boot per payload. + +## How the wallet is driven + +`device.py` works through the accessibility tree. The wallet is ~90 Compose +files with no `testTag`s anywhere, so widgets are addressed by the semantics the +app already publishes — `text` and `content-desc` — and tapped at the centre of +their bounds. A screen's "signature" (its set of labels, with numbers masked, +plus the count of interactive nodes) identifies a state well enough to detect +novelty during random exploration. + +Taler URIs reach the wallet as `ACTION_SEND` / `text/plain` rather than as a +`VIEW` deep link: the manifest's VIEW filter covers `taler://` and `payto://` +but not the `taler+http://` form a local http deployment produces. `view_uri()` +is kept for the schemes the filter does cover. + +### Destructive scenarios + +`revoke_denomination` takes a denomination key away from the exchange while the +wallet holds coins of it. That is stack-wide and lasts until the next stack +start, so it refuses to run unless `SIM_DESTRUCTIVE=1`, and it belongs in a +phase of its own. + +`wallet_lock_without_credential` is destructive to the *device* rather than the +stack: it sets a PIN with `locksettings` so that the wallet lock can be +switched on, and clears it again in a `finally`. If that scenario is ever +killed outright, clear it by hand before the emulator sees a keyguard: + +```bash +adb -s emulator-5562 shell locksettings clear --old 1234 +adb -s emulator-5562 shell locksettings set-disabled true +``` + + +```bash +SIM_DESTRUCTIVE=1 driver/phase.sh sim.conf revoke_denomination +``` + +### Failing a wallet-core call from the outside + +wallet-core takes two developer-mode URIs that are worth more than any proxy +for testing the app's own error handling: + +``` +taler+http://dev-experiment/api-error?operation=<op>&detail=<base64url JSON>&count=<n> +taler+http://dev-experiment/api-response?operation=<op>&response=<base64url JSON>&count=<n> +``` + +The first fails the named operation `n` times with the given error (the detail +must be an object with a numeric `code`); the second answers it with a canned +reply. `api_error_sweep` uses the first to make each screen's own call fail and +records which screens then say nothing; `api_response_hostile` uses the second +to feed the balance screen values this stack cannot produce. Both clear up +after themselves (`clear-api-errors`, `clear-api-responses`), and a fresh +profile resets the state anyway. + +Two things to know: the operation name must be one wallet-core knows (the app's +own list is in `coverage/app-operations.txt`), and applying an experiment ends +with a back navigation, which *closes the app* when the URI is what started +it — so a scenario has to put the app back in the foreground before it can +look at anything. + +## What counts as a finding + +`driver/oracles.py` is the contract. A refusal is not a bug — the wallet is +supposed to reject a stale order or a malformed URI and say so. A finding is a +crash, an ANR, a native abort, an error wallet-core itself calls unexpected or +an invariant failure (`TalerErrorCode` 2, 56, 60, 7001, 7007, 7047, 7048), an +error screen whose text reads like a defect, a blank screen, or a corrupt +database. Each one is written to the episode directory with a screenshot, the +logcat tail, the screen's labels and the full action list that produced it, and +fingerprinted so repeats collapse. + +## Tools + +| Tool | What it is for | +| --- | --- | +| `driver/probe.py` | one action, then a dump — how labels get discovered | +| `driver/report.py` | summarise episode directories and their findings | +| `driver/dbprobe.py` | copy the wallet's SQLite database off the device and query it | +| `driver/replay.py` | replay an episode, and shrink it with ddmin | +| `coverage/report.sh` | merge `.ec` files into an HTML/XML report | +| `coverage/gaps.py` | rank what is still uncovered, and diff two reports | +| `findings/new_finding.py` | scaffold a write-up from an episode's artifacts | + +## Findings + +`findings/` holds a write-up plus a standalone reproducer per confirmed defect. +So far: + +* `addglobalcurrencyexchange-null-masterpub.md` — "Treat as global" on an + exchange the wallet has never contacted sends a request with no + `exchangeMasterPub`, so wallet-core answers `WALLET_UNEXPECTED_EXCEPTION` + (7001) and the UI shows nothing at all. Four taps from a fresh profile. + +## Gotchas the harness learned the hard way + +* **Rotation outlives app data.** `user_rotation` is a system setting, so + `pm clear` does not undo a `rotate` action from an earlier episode, and a + landscape device invalidates every gesture computed for portrait. + `Device.portrait()` runs at the start of each episode, and `Device.scroll()` + derives its swipe from the scrollable node's own bounds rather than from + fixed coordinates. +* **`input text` cannot type non-ASCII.** It maps characters through a + KeyCharacterMap and throws `NullPointerException`. Non-ASCII text goes + through `SimHooks.SET_CLIPBOARD` plus `KEYCODE_PASTE` instead; the clipboard + may only be written by the foreground app, which is where the simulator is + pasting anyway. +* **Settings is longer than one screen**, and how much fits depends on how many + rows the wallet has to show, so callers wait for the screen and then scroll + to the row they want. +* **`uiautomator dump` fails while the UI is settling** ("could not get idle + state"); `Device.dump()` retries. +* **A label is often not the thing you can tap.** The main screen's action + buttons keep their text in a sibling node, so `Screen.tap_target()` resolves + a label to the clickable node that contains it *or sits next to it*. +* **A screen's title and its submit button often share a string.** "Add + account" is the app bar title, the list screen's add icon and the form's + submit button; a label search finds the title, which is not clickable, and + the neighbour search then lands on a tab or the back arrow. `Ctx.tap_button` + takes the lowest matching node that is clickable *and* contains the label. +* **An ad-hoc probe must name its serial.** `Device()` defaults to + `emulator-5554`, which is worker 0 -- a probe written without a serial + interferes with a running round. Worker 4 (`emulator-5562`) is the spare: + `SIM_WORKER=4`, or `Device("emulator-5562")`. +* **Reachable from the host is not reachable from the emulator.** Everything + goes through `adb reverse`, and a port that is not in `env.json`'s `ports` + is not mapped; the wallet then fails to add a payment service and says + nothing about it, which looks exactly like a scenario that worked. +* **`pgrep -f X` matches the shell whose command line contains X**, so a "wait + until the run finishes" loop waits forever on itself — and a bracket class + (`[f]orever.sh`) only helps when the *pattern* is bracketed and the waiting + command does not also mention the plain name later on its own command line. + Prefer matching on something the waiter cannot contain, or check a pid file. + The same trap kills an ssh session when `pkill -f` matches the ssh command + itself. diff --git a/simulator/backend/exchange2.sh b/simulator/backend/exchange2.sh @@ -0,0 +1,147 @@ +#!/bin/bash +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# A second exchange beside the stack, so the wallet has something to choose +# between. +# +# Usage: exchange2.sh start|stop|status +# +# The main stack has to be up already: this one has no bank of its own, it +# registers an account at the stack's libeufin bank and uses it. Everything +# else (port, database, offline key, secmod sockets) is its own; see +# sim-exchange2.conf. + +set -eu + +SIM_ROOT=${SIM_ROOT:-/opt/taler-sim} +RUN=${SIM_RUN:-$SIM_ROOT/run/stack} +RUN2=${SIM_RUN2:-$SIM_ROOT/run/exchange2} +HERE="$(cd "$(dirname "$0")" && pwd)" +CONF_NAME=sim-exchange2.conf +DB=${SIM_DB2:-talersim2} +ACCOUNT=exchange-account-sim2 +CURRENCY=${SIM_CURRENCY:-EUR} +PORT=8091 +BANK_PORT=8082 +BANK_ADMIN=${SIM_BANK_ADMIN:-admin} +BANK_ADMIN_PASS=${SIM_BANK_ADMIN_PASS:-secret-password} +READY_TIMEOUT=${SIM_READY_TIMEOUT:-300} +PIDFILE="$RUN2/exchange2.pid" + +die() { echo "exchange2.sh: $*" >&2; exit 1; } + +running_pid() { + [ -s "$PIDFILE" ] || return 1 + local pid + pid=$(cat "$PIDFILE") + kill -0 "$pid" 2>/dev/null || return 1 + echo "$pid" +} + +register_bank_account() { + # is_taler_exchange makes libeufin expose the wire gateway API on it, which + # is what wirewatch and the aggregator talk to. A second call comes back + # 409, which is fine. + local code + code=$(curl -s -o register-account.log -w '%{http_code}' \ + -u "$BANK_ADMIN:$BANK_ADMIN_PASS" \ + -H 'Content-Type: application/json' \ + -X POST "http://localhost:$BANK_PORT/accounts" \ + -d '{"username":"exchange2","password":"password2", + "name":"Second Exchange","is_taler_exchange":true, + "payto_uri":"payto://x-taler-bank/localhost/exchange2?receiver-name=Second+Exchange"}') + case "$code" in + 200|201|204|409) echo "bank account exchange2: HTTP $code" >&2 ;; + *) die "could not register the exchange2 bank account (HTTP $code): $(cat register-account.log)" ;; + esac +} + +start() { + if running_pid > /dev/null; then + echo "already running (pid $(running_pid))" >&2 + return 0 + fi + curl -s -m 5 -o /dev/null "http://localhost:$BANK_PORT/config" || + die "the stack's bank is not up; start the stack first" + rm -rf "$RUN2" + mkdir -p "$RUN2/home" + dropdb "$DB" 2>/dev/null || true + createdb "$DB" || die "could not create the database $DB" + cp "$HERE/$CONF_NAME" "$RUN2/$CONF_NAME" + cd "$RUN2" + register_bank_account + # Exchange, wirewatch, aggregator, transfer: enough to withdraw from it and + # to deposit into it, which is all the wallet needs from a second one. + setsid taler-unified-setup.sh -W -c "$CONF_NAME" -u "$ACCOUNT" -e -w -g -t \ + > setup.stdout 2> setup.stderr < /dev/null & + echo $! > "$PIDFILE" + local pid waited + pid=$(cat "$PIDFILE") + waited=0 + while [ "$waited" -lt "$READY_TIMEOUT" ]; do + if grep -q '^READY:' setup.stdout 2>/dev/null; then + echo "exchange2 up after ${waited}s on port $PORT" >&2 + echo "READY" + return 0 + fi + if ! kill -0 "$pid" 2>/dev/null; then + echo "--- setup.stderr (tail) ---" >&2 + tail -40 setup.stderr >&2 || true + die "taler-unified-setup.sh died before exchange2 became ready" + fi + sleep 1 + waited=$((waited + 1)) + done + echo "--- setup.stderr (tail) ---" >&2 + tail -40 setup.stderr >&2 || true + die "timed out after ${READY_TIMEOUT}s waiting for exchange2" +} + +stop() { + if pid=$(running_pid); then + kill -TERM "$pid" + local waited=0 + while kill -0 "$pid" 2>/dev/null && [ "$waited" -lt 60 ]; do + sleep 1 + waited=$((waited + 1)) + done + kill -KILL "$pid" 2>/dev/null || true + echo "stopped" >&2 + else + echo "not running" >&2 + fi + rm -f "$PIDFILE" +} + +status() { + if pid=$(running_pid); then + echo "running (pid $pid)" + else + echo "not running" + fi + printf ' port %s: ' "$PORT" + if curl -s -m 2 -o /dev/null "http://localhost:$PORT/config"; then + echo "ok" + else + echo "DOWN" + fi +} + +case "${1:-}" in + start) start ;; + stop) stop ;; + status) status ;; + *) die "usage: $0 start|stop|status" ;; +esac diff --git a/simulator/backend/services/README.md b/simulator/backend/services/README.md @@ -0,0 +1,97 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Services beside the stack + +`taler-unified-setup.sh` brings up the exchange, the merchant, the bank, donau +and the auditor. Two more services the wallet can use are not part of it, and +the wallet has screens for both: + +| service | repository | port | what it unlocks in the app | +| --- | --- | --- | --- | +| Taler mailbox | `git://git.taler.net/taler-mailbox` | 11000 | the Mailbox screen: register, list, refresh, delete | +| Taler directory | `git://git.taler.net/taldir` | 11001 | nothing, see below — but it makes the contacts operations testable through wallet-core | + +Both are Go services with vendored dependencies, so they build without network +access to a module proxy — but they need **Go 1.25**, which Debian does not +have yet; `GOTOOLCHAIN=auto` (the default) downloads it: + +```bash +git clone git://git.taler.net/taler-mailbox && cd taler-mailbox +GOFLAGS=-mod=vendor go build -ldflags "-X main.ltversion=1:1:0" -o /tmp/ ./cmd/... +``` + +The `ltversion` ldflag matters: without it the service advertises an empty +protocol version and the wallet refuses it (`carefullyParseConfig`). + +## Deploying them + +The simulator runs them on the emulator host, beside the stack: + +``` +/opt/taler-mailbox/{mailbox-server,mailbox-dbinit,sim.conf} +/opt/taldir/{taldir-server,taldir-dbinit,sim.conf,sim-validator.sh} +``` + +`services/mailbox-sim.conf` and `services/taldir-sim.conf` here are the +deployed configurations. Databases are Postgres, created once: + +```bash +createdb -h /var/run/postgresql talermailbox +createdb -h /var/run/postgresql talerdir +cd /opt/taler-mailbox && ./mailbox-dbinit -c sim.conf +cd /opt/taldir && ./taldir-dbinit -c sim.conf +cd /opt/taler-mailbox && ./mailbox-server -c sim.conf -L DEBUG > /tmp/mb.log 2>&1 & +cd /opt/taldir && ./taldir-server -c sim.conf -L DEBUG > server.log 2>&1 & +``` + +They keep their own databases, so unlike `exchange2` they survive a stack +restart and need starting only once. Their ports are in `stack.sh`'s port list, +so `emu.sh reverse` maps them into every emulator. + +## Things that cost an hour each + +* **`localhost` is not `127.0.0.1`.** Both services bind `127.0.0.1` only, and + wallet-core resolves `localhost` to `::1` first, so a `localhost` URL gets + ECONNREFUSED. Use the numeric address in anything handed to wallet-core. +* **Every `GetDuration`/`GetAmount` in the mailbox server errors out when its + key is missing**, default or no default, so `sim.conf` spells out every fee + and every duration. +* **`taldir-dbinit` reads `[taldir-pq]` while `taldir-server` reads + `[directory-pq]`.** The config carries both, saying the same thing. +* **The directory's protocol version is a literal `0:0:0`** in + `pkg/taldir/taldir.go`, which the wallet refuses; the deployment patches it + to `1:0:0`. See `findings/taldir-protocol-version-mismatch.md`. +* **The email validator is a command.** `[directory-validator-email] COMMAND` + is run as `COMMAND <alias> <challenge> <topic> <message>`, so + `sim-validator.sh` appends the alias and the challenge to + `/opt/taldir/challenges.log` — the simulator's stand-in for reading a + validation email, and the only way a scenario can complete a registration. + +## Why the directory unlocks nothing in the app + +The app hard-codes `https://taldir.gnunet.org` in two files, so no deployment +can be reached from it; the service is still worth having, because wallet-core +takes the base URL as a parameter and the three contact operations can be +driven through `taler-wallet-cli advanced api`. See +`findings/alias-registration-hardcodes-the-directory.md`. + +## Sync + +`git://git.taler.net/sync` is *not* deployed: the Android wallet has no backup +or sync feature at all — no screens, and none of the wallet-core backup +operations appear in `coverage/app-operations.txt`. Deploying it would add +nothing to drive. diff --git a/simulator/backend/services/mailbox-sim.conf b/simulator/backend/services/mailbox-sim.conf @@ -0,0 +1,34 @@ +# Taler mailbox for the Android wallet simulator. +# +# Plain HTTP on localhost: the wallet's mailbox URL is editable in its own UI +# ("Configure Mailbox URL"), so this needs no TLS and no DNS games -- unlike +# the directory, whose URL the app hard-codes. +# +# cd /opt/taler-mailbox && ./mailbox-server -c sim.conf -L DEBUG +[mailbox] +production = false +host = "http://localhost:11000" +base_url = "http://localhost:11000" +bind_to = "localhost:11000" +monthly_fee = EUR:0 +registration_update_fee = EUR:0 +message_fee = EUR:0 +free_message_quota = 1000 +message_body_bytes = 4096 +message_response_limit = 50 +# Every GetDuration/GetAmount in the server errors out when its key is absent, +# default or no default, so each one has to be spelled out. +pending_registration_expiration = 24h +delivery_period = 72h +default_doc_filetype = text/html +default_doc_lang = en +default_tos_path = terms/ +default_pp_path = privacy/ +supported_doc_filetypes = text/html application/pdf application/epub application/xml text/plain + +[mailbox-pq] +connection_string = "postgres:///talermailbox?host=/var/run/postgresql&sslmode=disable" +host = "localhost" +port = 5432 +user = "root" +db_name = "talermailbox" diff --git a/simulator/backend/services/taldir-sim.conf b/simulator/backend/services/taldir-sim.conf @@ -0,0 +1,49 @@ +# Taler directory for the Android wallet simulator. +[paths] +TALER_DATA_HOME = /opt/taldir/data/ + +[directory] +BASE_URL = https://taldir.gnunet.org/ +BIND_TO = localhost:11001 +FOOTER = /opt/taldir/web/templates/footer.html +CHALLENGE_BYTES = 16 +VALIDATION_INITIATION_MAX = 10 +SOLUTION_ATTEMPT_MAX = 10 +VALIDATION_TIMEFRAME = 60m +SOLUTION_ATTEMPT_TIMEFRAME = 24h +MONTHLY_FEE = EUR:0 +PURGE_MAPPINGS_ON_STARTUP_DANGEROUS = false +VALIDATION_EXPIRATION = 24h +VALIDATION_LANDING = /opt/taldir/web/templates/validation_landing.html +LANDING_PAGE = /opt/taldir/web/templates/landing.html +LOOKUP_RESULT_PAGE = /opt/taldir/web/templates/lookup_result.html +SALT = simulator +DEFAULT_DOC_FILETYPE = text/html +DEFAULT_DOC_LANG = en +DEFAULT_TOS_PATH = /opt/taldir/terms/ +DEFAULT_PP_PATH = /opt/taldir/privacy/ +SUPPORTED_DOC_FILETYPES = text/html application/pdf application/epub application/xml text/plain +MERCHANT_BASE_URL = http://localhost:8080/instances/sim +MERCHANT_TOKEN = sandbox +VALID_PAYMENT_SYSTEM_ADDRESS_REGEX = .* + +[directory-pq] +CONNECTION_STRING = postgres:///talerdir?host=/var/run/postgresql&sslmode=disable + +# taldir-dbinit reads this section; the server reads [directory-pq]. Both have +# to say the same thing. +[taldir-pq] +connection_string = postgres:///talerdir?host=/var/run/postgresql&sslmode=disable + +[directory-validator-email] +TYPE = command +ENABLED = true +COMMAND = /opt/taldir/sim-validator.sh +VALID_ALIAS_REGEX = ^\S+@\S+\.\S+$ +CHALLENGE_FEE = EUR:0 + +[directory-validator-phone] +TYPE = command +ENABLED = true +COMMAND = /opt/taldir/sim-validator.sh +CHALLENGE_FEE = EUR:0 diff --git a/simulator/backend/services/taldir-validator.sh b/simulator/backend/services/taldir-validator.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# The simulator's stand-in for sending a validation email: it records the +# challenge where the driver can read it, which is all the wallet needs to +# complete a registration. +printf '%s\t%s\t%s\n' "$(date -Is)" "$1" "$2" >> /opt/taldir/challenges.log +exit 0 diff --git a/simulator/backend/sim-exchange2.conf b/simulator/backend/sim-exchange2.conf @@ -0,0 +1,197 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# A second exchange, beside the one in sim.conf, in the same currency and at +# the same libeufin bank. +# +# One exchange leaves a whole class of screens unreachable: the exchange picker +# (`SelectExchangeDialogFragment`), the balance scopes that a second payment +# service creates, "treat as global", and every "which payment service?" step +# in withdraw, deposit and peer payments silently picks the only candidate. +# +# It is started by exchange2.sh as a separate taler-unified-setup.sh run +# (services: exchange, wirewatch, aggregator, transfer), so everything here is +# deliberately disjoint from sim.conf: its own port, database, bank account, +# runtime directory for the secmod sockets and TALER_TEST_HOME -- which is +# where its offline key lives, and therefore where its master key comes from. + +[PATHS] +TALER_TEST_HOME = home/ +# The secmod helpers listen on unix sockets under this directory; sharing it +# with the first exchange makes the two fight over the same socket names. +TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/taler-sim/exchange2-runtime/ + +[taler-helper-crypto-rsa] +LOOKAHEAD_SIGN = 10 days + +[taler-helper-crypto-cs] +LOOKAHEAD_SIGN = 10 days + +[taler-helper-crypto-eddsa] +LOOKAHEAD_SIGN = 24 days +DURATION = 14 days + +[exchange] +PURSE_EXPIRATION_LIMIT = 3 years +CURRENCY = EUR +CURRENCY_ROUND_UNIT = EUR:0.01 +TINY_AMOUNT = EUR:0.01 +PORT = 8091 +SERVE = tcp +BASE_URL = "http://localhost:8091/" +# Two exchanges advertising one shopping URL each is the only way to +# reach ExchangeShoppingScreen: the balance card that opens it is +# hidden when the list is empty, and a single URL opens the browser +# instead of the screen (balances/BalancesPagerComposable.kt:331, +# main/MainScreen.kt:186). +SHOPPING_URL = http://localhost:8080/config?shop=two +# Rewritten by taler-unified-setup.sh in the copy it is given. +MASTER_PUBLIC_KEY = KHA6YSPRQV1ZFCF144SY8KJNR588XA8DA0F6510FKJW30DJFJNAG +STEFAN_ABS = "EUR:5" +ENABLE_KYC = NO +AGE_RESTRICTION_ENABLED = YES +# Same reason as in sim.conf: without this /terms answers "not configured". +TERMS_DIR = /opt/taler-sim/terms/ +TERMS_ETAG = exchange-tos-tops-v0 +PRIVACY_DIR = /opt/taler-sim/terms/ +PRIVACY_ETAG = exchange-pp-v0 + +[exchangedb-postgres] +CONFIG = "postgres:///talersim2" + +# Its own account at the shared libeufin bank, registered by exchange2.sh. +[exchange-account-sim2] +PAYTO_URI = "payto://x-taler-bank/localhost/exchange2?receiver-name=Second+Exchange" +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-sim2] +WIRE_GATEWAY_AUTH_METHOD = basic +USERNAME = exchange2 +PASSWORD = password2 +WIRE_GATEWAY_URL = "http://localhost:8082/accounts/exchange2/taler-wire-gateway/" +CORE_BANK_URL = "http://localhost:8082/accounts/exchange2/" + +[admin-accountcredentials-sim2] +WIRE_GATEWAY_AUTH_METHOD = basic +USERNAME = exchange2 +PASSWORD = password2 +WIRE_GATEWAY_URL = "http://localhost:8082/accounts/exchange2/taler-wire-gateway/" + +# ----------------------------------------------------------- denominations --- + +[coin_eur_ct_1] +value = EUR:0.01 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.00 +fee_deposit = EUR:0.00 +fee_refresh = EUR:0.01 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_ct_10] +value = EUR:0.10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_1] +value = EUR:1 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_5] +value = EUR:5 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_10] +value = EUR:10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +# Age-restricted denominations, so the withdrawal screen offers "Restrict +# usage to age" and the age-restriction paths in the wallet are reachable. +# Taken from exchange/src/testing/coins-rsa.conf. + +[coin_eur_ct_10_age_restricted] +value = EUR:0.10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +age_restricted = YES +CIPHER = RSA + +[coin_eur_1_age_restricted] +value = EUR:1 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +age_restricted = YES +CIPHER = RSA + +[coin_eur_5_age_restricted] +value = EUR:5 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +age_restricted = YES +CIPHER = RSA + +# Sections starting with "doco_" are the donau's denominations. diff --git a/simulator/backend/sim-kyc.conf b/simulator/backend/sim-kyc.conf @@ -0,0 +1,84 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# The simulator stack with KYC turned on, so the wallet's "KYC required" and +# "Complete KYC" paths become reachable: withdrawing more than EUR:5 within a +# day trips a rule. +# +# The exchange's own test suite uses a form check backed by +# taler-exchange-helper-measure-test-form, which is built only in its test +# tree, so this uses the helpers the packaged exchange ships. + +@INLINE@ sim.conf + +[exchange] +ENABLE_KYC = YES + +# What the user has to do when a rule trips: fill in a form served by the +# exchange's KYC SPA. A FORM check (rather than INFO) is what gives the wallet +# a link to offer, and "none" accepts whatever the form returns — the test +# suite's validating program, taler-exchange-helper-measure-test-form, is not +# part of the packaged exchange. +[kyc-check-sim-form] +VOLUNTARY = NO +TYPE = FORM +DESCRIPTION = "The simulator requires identification for larger withdrawals" +DESCRIPTION_I18N = {} +REQUIRES = +FALLBACK = sim-freeze +FORM_NAME = full_name_and_birthdate +OUTPUTS = FULL_NAME DATE_OF_BIRTH + +[kyc-measure-sim-form] +CHECK_NAME = sim-form +PROGRAM = none +CONTEXT = {} + +# Shown once the check has been passed. +[kyc-check-sim-info] +VOLUNTARY = NO +TYPE = INFO +DESCRIPTION = "Your account is operating normally" +DESCRIPTION_I18N = {} +REQUIRES = +FALLBACK = sim-freeze + +[kyc-measure-sim-info] +CHECK_NAME = sim-info +CONTEXT = {} + +[kyc-measure-sim-freeze] +CHECK_NAME = skip +PROGRAM = freeze +CONTEXT = {} + +[aml-program-none] +DESCRIPTION = "Do nothing" +COMMAND = taler-exchange-helper-measure-none +FALLBACK = sim-freeze + +[aml-program-freeze] +DESCRIPTION = "Freeze the account pending investigation" +COMMAND = taler-exchange-helper-measure-freeze +FALLBACK = sim-freeze + +# Withdrawing more than EUR:5 in a day needs the check above. +[kyc-rule-sim-withdraw] +ENABLED = YES +EXPOSED = YES +IS_AND_COMBINATOR = YES +OPERATION_TYPE = WITHDRAW +THRESHOLD = EUR:5 +TIMEFRAME = 1d +NEXT_MEASURES = sim-form diff --git a/simulator/backend/sim-twister.conf b/simulator/backend/sim-twister.conf @@ -0,0 +1,49 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# The simulator stack with twister in front of the exchange, for fault +# injection: the wallet and the merchant both talk to port 8088, twister +# forwards to the real exchange on 8081 and can truncate, rewrite or fail what +# passes through. +# +# The exchange's own BASE_URL has to be the twister URL, because that is what +# it signs and what the wallet checks. + +@INLINE@ sim.conf + +[exchange] +BASE_URL = "http://localhost:8088/" + +[merchant-exchange-sim] +EXCHANGE_BASE_URL = http://localhost:8088/ + +# The bank hands the wallet this URL in every withdrawal it starts. Left +# pointing at the exchange directly, the wallet compares it with the URL the +# exchange signs (the proxy) and refuses with +# WALLET_EXCHANGE_BASE_URL_MISMATCH before any injected fault can matter. +[libeufin-bank] +SUGGESTED_WITHDRAWAL_EXCHANGE = http://localhost:8088/ + +[twister] +# What the wallet and the merchant treat as "the exchange". +HTTP_PORT = 8088 +SERVE = tcp +# The real exchange. No trailing slash, by twister's own convention. +DESTINATION_BASE_URL = "http://localhost:8081" +HOSTNAME = localhost +ACCEPT_FROM = 127.0.0.1; +ACCEPT_FROM6 = ::1; +UNIXPATH = /tmp/taler-sim-twister.sock +UNIX_MATCH_UID = NO +UNIX_MATCH_GID = YES diff --git a/simulator/backend/sim.conf b/simulator/backend/sim.conf @@ -0,0 +1,374 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# Stack configuration for the Android wallet simulator. Derived from +# merchant/src/testing/test_merchant_api.conf plus the libeufin-bank exchange +# account from exchange/src/testing/test_exchange_api.conf. +# +# Every BASE_URL is http://localhost:<port>/ on purpose: the driver maps the +# same ports into each emulator with "adb reverse", so one URL namespace is +# valid both on the host and inside the wallet. taler-unified-setup.sh is run +# with the run directory as CWD, so the relative TALER_TEST_HOME below lands +# there. Note that taler-unified-setup.sh *rewrites* MASTER_PUBLIC_KEY in the +# copy of this file it is given, so it is always run against a copy. + +[PATHS] +TALER_TEST_HOME = home/ +DONAU_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/taler-sim/donau-runtime/ + +[taler-helper-crypto-rsa] +LOOKAHEAD_SIGN = 10 days + +[taler-helper-crypto-cs] +LOOKAHEAD_SIGN = 10 days + +[taler-helper-crypto-eddsa] +LOOKAHEAD_SIGN = 24 days +DURATION = 14 days + +[donau-helper-crypto-rsa] +LOOKAHEAD_SIGN = 10 days + +# ---------------------------------------------------------------- exchange --- + +[exchange] +# A purse must not outlive the denominations of the coins in it. +PURSE_EXPIRATION_LIMIT = 3 years +CURRENCY = EUR +CURRENCY_ROUND_UNIT = EUR:0.01 +TINY_AMOUNT = EUR:0.01 +PORT = 8081 +SERVE = tcp +BASE_URL = "http://localhost:8081/" +# Two exchanges advertising one shopping URL each is the only way to +# reach ExchangeShoppingScreen: the balance card that opens it is +# hidden when the list is empty, and a single URL opens the browser +# instead of the screen (balances/BalancesPagerComposable.kt:331, +# main/MainScreen.kt:186). +SHOPPING_URL = http://localhost:8080/config?shop=one +MASTER_PUBLIC_KEY = KHA6YSPRQV1ZFCF144SY8KJNR588XA8DA0F6510FKJW30DJFJNAG +STEFAN_ABS = "EUR:5" +ENABLE_KYC = NO +# Without this the age-restricted denominations below are ignored and /keys +# advertises an age mask of 0. +AGE_RESTRICTION_ENABLED = YES +# The shipped TERMS_DIR is ${TALER_DATA_HOME}terms/, which in a test setup is +# an empty directory under TALER_TEST_HOME, so /terms answers "501 not +# configured" and the wallet never asks anyone to accept anything. Serving +# terms is what makes the terms-of-service screens -- and +# setExchangeTosAccepted -- reachable at all. +# +# The directory holds *rendered* terms, one subdirectory per language, not the +# .rst sources that ship with the exchange: stack.sh runs +# taler-terms-generator over them once. +TERMS_DIR = /opt/taler-sim/terms/ +TERMS_ETAG = exchange-tos-tops-v0 +PRIVACY_DIR = /opt/taler-sim/terms/ +PRIVACY_ETAG = exchange-pp-v0 + +[exchangedb-postgres] +CONFIG = "postgres:///talersim" + +# The account the exchange uses at the libeufin bank. Registered by +# taler-unified-setup.sh as user "exchange" with password "password". +[exchange-account-sim] +PAYTO_URI = "payto://x-taler-bank/localhost/exchange?receiver-name=Exchange" +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-sim] +WIRE_GATEWAY_AUTH_METHOD = basic +USERNAME = exchange +PASSWORD = password +WIRE_GATEWAY_URL = "http://localhost:8082/accounts/exchange/taler-wire-gateway/" +CORE_BANK_URL = "http://localhost:8082/accounts/exchange/" + +[admin-accountcredentials-sim] +WIRE_GATEWAY_AUTH_METHOD = basic +USERNAME = exchange +PASSWORD = password +WIRE_GATEWAY_URL = "http://localhost:8082/accounts/exchange/taler-wire-gateway/" + +# A second account for the same exchange, in IBAN form. The exchange then +# advertises two ways to be paid, which is what makes the wallet show its +# account picker and the IBAN transfer screens (EPC QR, Swiss QR bill) that the +# x-taler-bank form never reaches. Both point at the same libeufin account. +[exchange-account-iban] +PAYTO_URI = "payto://iban/SANDBOXX/DE89370400440532013000?receiver-name=Exchange+Company" +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-iban] +WIRE_GATEWAY_AUTH_METHOD = basic +USERNAME = exchange +PASSWORD = password +WIRE_GATEWAY_URL = "http://localhost:8082/accounts/exchange/taler-wire-gateway/" +CORE_BANK_URL = "http://localhost:8082/accounts/exchange/" + +# ------------------------------------------------------------ libeufin bank --- + +[libeufin-bank] +CURRENCY = EUR +WIRE_TYPE = x-taler-bank +X_TALER_BANK_PAYTO_HOSTNAME = localhost +# The simulator registers wallet-side customers itself, so registration and the +# registration bonus both have to be open. +ALLOW_REGISTRATION = YES +REGISTRATION_BONUS_ENABLED = yes +REGISTRATION_BONUS = EUR:100 +DEFAULT_CUSTOMER_DEBT_LIMIT = EUR:200 +DEFAULT_ADMIN_DEBT_LIMIT = EUR:2000 +IBAN_PAYTO_BIC = SANDBOXX +SUGGESTED_WITHDRAWAL_EXCHANGE = http://localhost:8081/ +SERVE = tcp +PORT = 8082 +# Cheap password hashing: the simulator creates throwaway accounts in bulk. +PWD_HASH_CONFIG = { "cost": 4 } +PWD_AUTH_COMPAT = yes +BASE_URL = http://localhost:8082/ + +[libeufin-bankdb-postgres] +CONFIG = postgresql:///talersim + +# ---------------------------------------------------------------- merchant --- + +[merchant] +CURRENCY = EUR +PORT = 8080 +SERVE = tcp +DB = postgres +BASE_URL = http://localhost:8080/ + +[merchantdb-postgres] +CONFIG = postgres:///talersim +SQL_DIR = ${DATADIR}sql/ + +[merchant-exchange-sim] +MASTER_KEY = KHA6YSPRQV1ZFCF144SY8KJNR588XA8DA0F6510FKJW30DJFJNAG +EXCHANGE_BASE_URL = http://localhost:8081/ +CURRENCY = EUR + +# Disable the exchanges the shipped merchant config.d pulls in, so the merchant +# only ever talks to the simulator's exchange. +[merchant-exchange-chf] +DISABLED = YES + +[merchant-exchange-kudos] +DISABLED = YES + +# ------------------------------------------------------------------- donau --- + +[donau] +TERMS_ETAG = tos +PRIVACY_ETAG = 0 +CURRENCY = EUR +PORT = 8079 +DB = postgres +LEGAL_DOMAIN = "Bern" +BASE_URL = "http://localhost:8079/" +SERVE = tcp +EXPIRE_IDLE_SLEEP_INTERVAL = "1 s" +EXPIRE_LEGAL_YEARS = 5 + +[donaudb-postgres] +CONFIG = "postgres:///talersim" + +# ----------------------------------------------------------------- auditor --- + +[auditor] +BASE_URL = "http://localhost:8083/" +PORT = 8083 +SERVE = tcp +DB = postgres +TINY_AMOUNT = EUR:0.01 + +[auditordb-postgres] +CONFIG = postgres:///talersim + +# ----------------------------------------------------------- denominations --- +# +# Taken from merchant/src/testing/test_merchant_api-rsa.conf: RSA with a 1024 +# bit key size, because the simulator values fast key setup over strength. The +# age-restricted variants from exchange/src/testing/coins-rsa.conf are left out +# for now; they belong in a separate config variant. + +[coin_eur_ct_1] +value = EUR:0.01 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.00 +fee_deposit = EUR:0.00 +fee_refresh = EUR:0.01 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_ct_10] +value = EUR:0.10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_1] +value = EUR:1 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_5] +value = EUR:5 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_10] +value = EUR:10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +# Age-restricted denominations, so the withdrawal screen offers "Restrict +# usage to age" and the age-restriction paths in the wallet are reachable. +# Taken from exchange/src/testing/coins-rsa.conf. + +[coin_eur_ct_10_age_restricted] +value = EUR:0.10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +age_restricted = YES +CIPHER = RSA + +[coin_eur_1_age_restricted] +value = EUR:1 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +age_restricted = YES +CIPHER = RSA + +[coin_eur_5_age_restricted] +value = EUR:5 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +age_restricted = YES +CIPHER = RSA + +# Sections starting with "doco_" are the donau's denominations. + +[doco_eur_ct_1] +value = EUR:0.01 +duration_withdraw = 1 year +anchor_round = 1 year +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.00 +fee_deposit = EUR:0.00 +fee_refresh = EUR:0.01 +fee_refund = EUR:0.01 +CIPHER = RSA +rsa_keysize = 1024 + +[doco_eur_ct_10] +value = EUR:0.10 +duration_withdraw = 1 year +anchor_round = 1 year +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = RSA +rsa_keysize = 1024 + +[doco_eur_1] +value = EUR:1 +duration_withdraw = 1 year +anchor_round = 1 year +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = RSA +rsa_keysize = 1024 + +[doco_eur_5] +value = EUR:5 +duration_withdraw = 1 year +anchor_round = 1 year +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = RSA +rsa_keysize = 1024 + +[doco_eur_10] +value = EUR:10 +duration_withdraw = 1 year +anchor_round = 1 year +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = RSA +rsa_keysize = 1024 diff --git a/simulator/backend/stack.sh b/simulator/backend/stack.sh @@ -0,0 +1,366 @@ +#!/bin/bash +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# Bring the Taler services for the wallet simulator up and down. +# +# Usage: stack.sh start|stop|status|urls +# +# "start" wipes the run directory and the database, so every run begins from a +# known state. taler-unified-setup.sh is started with -W (wait for signal) and +# detached, so it keeps running after this script returns; "stop" sends it +# SIGTERM, which makes it shut down every service it started. + +set -eu + +SIM_ROOT=${SIM_ROOT:-/opt/taler-sim} +RUN=${SIM_RUN:-$SIM_ROOT/run/stack} +HERE="$(cd "$(dirname "$0")" && pwd)" +# SIM_CONF picks the variant: sim.conf plain, sim-kyc.conf with KYC rules, or +# sim-twister.conf to put the fault injector in front of the exchange. +CONF_NAME=${SIM_CONF:-sim.conf} +CONF_SRC="$HERE/$CONF_NAME" +TWISTER_BIN=${SIM_TWISTER_BIN:-/opt/twister/bin/taler-twister-service} +DB=${SIM_DB:-talersim} +# Services: exchange, merchant, libeufin bank, wirewatch, aggregator, transfer, +# merchant depositcheck, merchant wirewatch, donau. +SERVICES=${SIM_SERVICES:="-e -m -b -w -g -t -M -z -D"} +ACCOUNT=${SIM_ACCOUNT:-exchange-account-sim} +# Without -r, taler-unified-setup.sh never patches the merchant's copy of the +# exchange master key, and the merchant then rejects every order with +# "exchange failed to provide a valid response to /keys". +MERCHANT_EXCHANGE=${SIM_MERCHANT_EXCHANGE:-merchant-exchange-sim} +READY_TIMEOUT=${SIM_READY_TIMEOUT:-300} +PIDFILE="$RUN/stack.pid" + +# Accounts to enable beyond the one taler-unified-setup.sh handles via -u. +# It enables exactly one, so a second wire method stays invisible in /keys +# until it is uploaded explicitly. +EXTRA_ACCOUNTS=${SIM_EXTRA_ACCOUNTS:-exchange-account-iban} +# Payto URIs to sign without a config section behind them. The wallet decides +# which deposit and transfer forms to offer purely from the wire methods in +# /keys, so signing an address is enough to reach those screens even when no +# service could ever settle on it. +# Bitcoin only, by default. A Cyclos address belongs here too -- the wallet +# has a Cyclos transfer screen -- but its WireType enum does not know the +# method, and one unknown method makes the whole getDepositWireTypes reply +# throw, which hangs the add-account form for ever (see +# findings/unknown-wire-method-hangs-the-deposit-form.md). Keeping it in the +# default stack would block every deposit scenario, so it is opt-in: +# +# SIM_EXTRA_PAYTOS='payto://cyclos/cyclos.example.com/exchange?receiver-name=X' \ +# ./stack.sh start +EXTRA_PAYTOS=${SIM_EXTRA_PAYTOS:-payto://bitcoin/bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq?receiver-name=Exchange+Bitcoin} +CURRENCY=${SIM_CURRENCY:-EUR} + +# Ports as configured in sim.conf; the emulator side maps exactly these. +PORT_MERCHANT=8080 +PORT_EXCHANGE=8081 +PORT_BANK=8082 +PORT_AUDITOR=8083 +PORT_DONAU=8079 +PORT_TWISTER=8088 +# A second exchange, started by exchange2.sh right after the stack is up; the +# port is mapped into the emulators either way, so turning it off needs no +# re-mapping. It shares the stack's bank, whose database this script wipes, so +# it has to be restarted together with the stack rather than left running. +PORT_EXCHANGE2=8091 +# Services deployed beside the stack (see services/README.md): the Taler +# mailbox and the Taler directory. They have their own databases and outlive a +# stack restart, but their ports have to be mapped into the emulators, so they +# belong in the list below. +PORT_MAILBOX=11000 +PORT_TALDIR=11001 +SIM_EXCHANGE2=${SIM_EXCHANGE2:-1} +EXCHANGE2_JSON=null +# Rendered terms of service, referenced by TERMS_DIR in the configs. +TERMS_OUT=${SIM_TERMS_DIR:-$SIM_ROOT/terms} + +die() { echo "stack.sh: $*" >&2; exit 1; } + +ensure_db() { + local me + me=$(id -un) + if ! sudo -u postgres psql -tAc \ + "SELECT 1 FROM pg_roles WHERE rolname='$me'" | grep -q 1; then + echo "creating postgres superuser role $me" >&2 + sudo -u postgres createuser -s "$me" + fi + # Drop and recreate so each run starts from an empty database; the service + # dbinit calls in taler-unified-setup.sh only reset the schemas they know. + dropdb --if-exists "$DB" + createdb "$DB" +} + +running_pid() { + [ -s "$PIDFILE" ] || return 1 + local pid + pid=$(cat "$PIDFILE") + kill -0 "$pid" 2>/dev/null || return 1 + echo "$pid" +} + +start_twister() { + # Only for the twister variant: taler-unified-setup.sh knows nothing about + # it, so the proxy is started here, once the exchange it forwards to is up. + case "$CONF_NAME" in + *twister*) ;; + *) return 0 ;; + esac + [ -x "$TWISTER_BIN" ] || { echo "WARNING: no twister at $TWISTER_BIN" >&2; return 0; } + setsid "$TWISTER_BIN" -c "$CONF_NAME" > twister.log 2>&1 < /dev/null & + echo $! > twister.pid + local waited=0 + while [ "$waited" -lt 20 ]; do + # Only that it is listening: the exchange it forwards to is not up yet. + if ss -ltn 2>/dev/null | grep -q ":$PORT_TWISTER "; then + echo "twister listening on $PORT_TWISTER -> 8081" >&2 + return 0 + fi + sleep 1 + waited=$((waited + 1)) + done + echo "WARNING: twister is not listening on $PORT_TWISTER; see $RUN/twister.log" >&2 +} + +# taler-unified-setup.sh only uploads a wire fee for the one wire method it was +# told about, and wallet-core hides every exchange account whose method has no +# fee -- so an extra account stays invisible to the wallet until we add one. +upload_wire_fee() { + local method=$1 next_year + next_year=$(( 1 + $(date +%Y) )) + if taler-exchange-offline -c "$CONF_NAME" \ + wire-fee now "$method" "$CURRENCY:0.01" "$CURRENCY:0.01" \ + wire-fee "$next_year" "$method" "$CURRENCY:0.01" "$CURRENCY:0.01" \ + upload >> enable-extra-accounts.log 2>&1; then + echo "uploaded $method wire fees" >&2 + else + echo "WARNING: no wire fee for $method; see enable-extra-accounts.log" >&2 + fi +} + +# The exchange serves rendered terms, one subdirectory per language; what ships +# with it are the .rst sources. Generating them once is the difference between +# /terms answering with the terms and answering "not configured". +# The wallet's terms screen only shows its language selector when the exchange +# offers more than one language (ReviewExchangeTosScreen.kt:183), and the +# shipped exchange-tos-v0 has an English source only -- so the terms used here +# are exchange-tos-tops-v0, which ships de and en. +TERMS_ID=${SIM_TERMS_ID:-exchange-tos-tops-v0} +TERMS_LANGS=${SIM_TERMS_LANGS:-"en de"} + +ensure_terms() { + [ -s "$TERMS_OUT/en/$TERMS_ID.txt" ] && return 0 + command -v taler-terms-generator > /dev/null || { + echo "WARNING: no taler-terms-generator; the exchange will serve no terms" >&2 + return 0 + } + mkdir -p "$TERMS_OUT" + local src=/usr/share/taler-exchange/terms lang + : > "$TERMS_OUT/generate.log" + for lang in $TERMS_LANGS; do + (cd "$src" && + taler-terms-generator -i "$TERMS_ID" -l "$lang" -o "$TERMS_OUT" && + taler-terms-generator -i exchange-pp-v0 -l "$lang" -o "$TERMS_OUT") \ + >> "$TERMS_OUT/generate.log" 2>&1 || + echo "WARNING: could not render the $lang terms; see $TERMS_OUT/generate.log" >&2 + done +} + +enable_payto() { + local payto=$1 what=$2 method + if taler-exchange-offline -c "$CONF_NAME" enable-account "$payto" upload \ + >> enable-extra-accounts.log 2>&1; then + echo "enabled $what ($payto)" >&2 + else + echo "WARNING: could not enable $what; see enable-extra-accounts.log" >&2 + return 0 + fi + method=$(echo "$payto" | sed -n 's|^payto://\([^/]*\)/.*|\1|p') + [ -n "$method" ] && upload_wire_fee "$method" +} + +enable_extra_accounts() { + local section payto + for section in $EXTRA_ACCOUNTS; do + payto=$(taler-exchange-config -c "$CONF_NAME" -s "$section" -o PAYTO_URI 2>/dev/null) + [ -n "$payto" ] || continue + enable_payto "$payto" "$section" + done + local IFS=' +' + for payto in $EXTRA_PAYTOS; do + [ -n "$payto" ] && enable_payto "$payto" "extra payto" + done +} + +start_exchange2() { + [ "$SIM_EXCHANGE2" = "1" ] || return 0 + if (cd "$HERE" && ./exchange2.sh start > "$RUN/exchange2.log" 2>&1); then + EXCHANGE2_JSON="\"http://localhost:$PORT_EXCHANGE2/\"" + echo "second exchange up on $PORT_EXCHANGE2" >&2 + else + echo "WARNING: the second exchange did not start; see exchange2.log" >&2 + tail -5 "$RUN/exchange2.log" >&2 || true + fi +} + +write_env() { + local EXCHANGE_URL="http://localhost:$PORT_EXCHANGE/" + local TWISTER_JSON=null + case "$CONF_NAME" in + *twister*) + EXCHANGE_URL="http://localhost:$PORT_TWISTER/" + TWISTER_JSON="{\"url\": \"http://localhost:$PORT_TWISTER/\", \"config\": \"$RUN/$CONF_NAME\"}" + ;; + esac + cat > "$RUN/env.json" <<JSON +{ + "host": "localhost", + "ports": [$PORT_DONAU, $PORT_MERCHANT, $PORT_EXCHANGE, $PORT_BANK, $PORT_AUDITOR, + $PORT_TWISTER, $PORT_EXCHANGE2, $PORT_MAILBOX, $PORT_TALDIR], + "exchange": "$EXCHANGE_URL", + "exchange_direct": "http://localhost:$PORT_EXCHANGE/", + "exchange2": $EXCHANGE2_JSON, + "mailbox": "http://localhost:$PORT_MAILBOX/", + "taldir": "http://localhost:$PORT_TALDIR/", + "twister": $TWISTER_JSON, + "merchant": "http://localhost:$PORT_MERCHANT/", + "bank": "http://localhost:$PORT_BANK/", + "donau": "http://localhost:$PORT_DONAU/", + "auditor": "http://localhost:$PORT_AUDITOR/", + "currency": "EUR", + "run_dir": "$RUN", + "bank_admin": {"username": "admin", "password": "secret-password"}, + "exchange_bank_account": {"username": "exchange", "password": "password"} +} +JSON +} + +start() { + if pid=$(running_pid); then + die "already running (pid $pid); run 'stack.sh stop' first" + fi + command -v taler-unified-setup.sh >/dev/null || die "taler-unified-setup.sh not in PATH" + ensure_db + rm -rf "$RUN" + mkdir -p "$RUN/home" + # taler-unified-setup.sh rewrites MASTER_PUBLIC_KEY in the config it is + # handed, so it always gets a copy. + # sim.conf is @INLINE@d by the variants, so both have to be in the run + # directory, and taler-unified-setup.sh rewrites the one it is given. + cp "$HERE/sim.conf" "$RUN/sim.conf" + [ "$CONF_NAME" = "sim.conf" ] || cp "$CONF_SRC" "$RUN/$CONF_NAME" + cd "$RUN" + ensure_terms + # Before the services, not after: with the twister variant the exchange's + # own BASE_URL is the proxy, and its key setup talks to that URL. If + # nothing is listening there yet, "Setting up exchange keys" fails and the + # whole stack dies. + start_twister + # shellcheck disable=SC2086 + setsid taler-unified-setup.sh -W -c "$CONF_NAME" -u "$ACCOUNT" \ + -r "$MERCHANT_EXCHANGE" $SERVICES \ + > setup.stdout 2> setup.stderr < /dev/null & + echo $! > "$PIDFILE" + local pid waited + pid=$(cat "$PIDFILE") + waited=0 + while [ "$waited" -lt "$READY_TIMEOUT" ]; do + if grep -q '^READY:' setup.stdout 2>/dev/null; then + enable_extra_accounts + start_exchange2 + write_env + echo "stack up after ${waited}s: $(cat "$RUN/env.json" | tr -d '\n')" >&2 + echo "READY" + return 0 + fi + if ! kill -0 "$pid" 2>/dev/null; then + echo "--- setup.stderr (tail) ---" >&2 + tail -40 setup.stderr >&2 || true + die "taler-unified-setup.sh died before becoming ready" + fi + sleep 1 + waited=$((waited + 1)) + done + echo "--- setup.stderr (tail) ---" >&2 + tail -40 setup.stderr >&2 || true + die "timed out after ${READY_TIMEOUT}s waiting for READY" +} + +stop() { + # The second exchange first: it has an account at the bank this stack is + # about to take down. + [ "$SIM_EXCHANGE2" = "1" ] && (cd "$HERE" && ./exchange2.sh stop >/dev/null 2>&1 || true) + if pid=$(running_pid); then + kill -TERM "$pid" + local waited=0 + while kill -0 "$pid" 2>/dev/null && [ "$waited" -lt 60 ]; do + sleep 1 + waited=$((waited + 1)) + done + kill -KILL "$pid" 2>/dev/null || true + if [ -s "$RUN/twister.pid" ]; then + kill "$(cat "$RUN/twister.pid")" 2>/dev/null || true + rm -f "$RUN/twister.pid" + fi + echo "stopped" >&2 + else + echo "not running" >&2 + fi + rm -f "$PIDFILE" + # The supervisor dying is not the same as its children letting go of the + # ports: starting again five seconds later made taler-unified-setup.sh die + # at the merchant, which cost a phase run. Wait for the ones this stack + # owns to be free. 11000 and 11001 (mailbox, taldir) are deliberately + # left out: they are run separately and outlive the stack. + local waited=0 busy + while [ "$waited" -lt 60 ]; do + busy="" + for p in "$PORT_DONAU" "$PORT_MERCHANT" "$PORT_EXCHANGE" "$PORT_BANK" \ + "$PORT_AUDITOR" "$PORT_EXCHANGE2"; do + if ss -ltn 2>/dev/null | grep -q ":$p\b"; then busy="$busy $p"; fi + done + [ -z "$busy" ] && break + sleep 2 + waited=$((waited + 2)) + done + [ -n "$busy" ] && echo "still listening after ${waited}s:$busy" >&2 + return 0 +} + +status() { + if pid=$(running_pid); then + echo "running (pid $pid)" + for p in $PORT_DONAU $PORT_MERCHANT $PORT_EXCHANGE $PORT_BANK; do + printf ' port %s: ' "$p" + if curl -s -m 2 -o /dev/null "http://localhost:$p/config"; then + echo "ok" + else + echo "NO /config" + fi + done + else + echo "not running" + return 1 + fi +} + +case "${1:-}" in + start) start ;; + stop) stop ;; + status) status ;; + urls) cat "$RUN/env.json" ;; + *) die "usage: stack.sh start|stop|status|urls" ;; +esac diff --git a/simulator/corpus/uris.py b/simulator/corpus/uris.py @@ -0,0 +1,150 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Corpus of URIs to feed the wallet, by QR code or shared text. + +Three kinds live here: + +* STRUCTURAL — well-formed URIs of every action the wallet claims to handle, + pointing at the local stack but at ids that do not exist. The + wallet must report a clean error, not an internal one. +* MALFORMED — syntactically broken or hostile input. Nothing here may crash + the app or reach an "internal error" screen. +* TEMPLATES — formats a scenario fills in with live ids, to test the + *semantically* wrong cases (already paid, aborted, expired). + +A value may legitimately be rejected; what matters is *how*. The oracle looks +for crashes, internal/unexpected error codes and hangs, not for success. +""" + +from __future__ import annotations + +# A 52-character Crockford base32 string, the shape of most Taler identifiers. +FAKE_ID = "A" * 52 +EXCHANGE = "localhost:8081" +MERCHANT = "localhost:8080" +BANK = "localhost:8082" + +STRUCTURAL: dict[str, str] = { + "pay": f"taler+http://pay/{MERCHANT}/instances/sim/{FAKE_ID}/", + "pay_with_token": f"taler+http://pay/{MERCHANT}/instances/sim/{FAKE_ID}/?c={FAKE_ID}", + "withdraw": f"taler+http://withdraw/{BANK}/taler-integration/{FAKE_ID}", + "withdraw_exchange": f"taler+http://withdraw-exchange/{EXCHANGE}/", + "add_exchange": f"taler+http://add-exchange/{EXCHANGE}/", + "pay_pull": f"taler+http://pay-pull/{EXCHANGE}/{FAKE_ID}", + "pay_push": f"taler+http://pay-push/{EXCHANGE}/{FAKE_ID}", + "refund": f"taler+http://refund/{MERCHANT}/instances/sim/{FAKE_ID}/", + "pay_template": f"taler+http://pay-template/{MERCHANT}/instances/sim/template1", + "reward": f"taler+http://reward/{MERCHANT}/instances/sim/{FAKE_ID}/", + "payto_iban": "payto://iban/SANDBOXX/DE89370400440532013000?receiver-name=Test", + "payto_x_taler_bank": f"payto://x-taler-bank/{BANK}/wallet1?receiver-name=Wallet", + # The https forms the production app would see; they must fail on the + # network, not in parsing. + "pay_https": f"taler://pay/{MERCHANT}/instances/sim/{FAKE_ID}/", + "withdraw_https": f"taler://withdraw/{BANK}/taler-integration/{FAKE_ID}", + # Developer-mode entry points. They are part of the app's URI surface and + # an unknown one already drops the user on the home screen (see + # dev-experiment-uri-exits-the-app.md), so the known ones belong here too. + # Only the harmless ones: the others change how the wallet behaves for the + # rest of the session, which a URI storm must not do to its own scenario. + "dev_experiment_clear_api_errors": "taler+http://dev-experiment/clear-api-errors", + "add_contact": f"taler+http://add-contact/email/friend@example.com/{EXCHANGE}/{FAKE_ID}", +} + +MALFORMED: dict[str, str] = { + "empty": "", + "whitespace": " \t ", + "scheme_only": "taler://", + "scheme_no_slash": "taler:", + "unknown_action": f"taler+http://frobnicate/{EXCHANGE}/{FAKE_ID}", + "wrong_scheme": f"gnunet://pay/{MERCHANT}/{FAKE_ID}/", + "http_url": f"http://{MERCHANT}/instances/sim/orders/{FAKE_ID}", + "javascript": "javascript:alert(1)", + "file_uri": "file:///etc/passwd", + "intent_uri": "intent://scan/#Intent;scheme=taler;package=net.taler.wallet;end", + "content_uri": "content://net.taler.wallet.fdroid.debug.fileprovider/db/wallet.sqlite3", + "uppercase": f"TALER+HTTP://PAY/{MERCHANT}/INSTANCES/SIM/{FAKE_ID}/", + "ext_prefix": f"ext+taler://pay/{MERCHANT}/instances/sim/{FAKE_ID}/", + "double_scheme": f"taler://taler://pay/{MERCHANT}/{FAKE_ID}/", + "no_host": f"taler+http://pay//instances/sim/{FAKE_ID}/", + "missing_id": f"taler+http://pay/{MERCHANT}/instances/sim/", + "truncated_id": f"taler+http://pay/{MERCHANT}/instances/sim/{'A' * 7}/", + # I, L, O and U are not in the Crockford alphabet Taler uses. + "bad_base32": f"taler+http://pay/{MERCHANT}/instances/sim/{'ILOU' * 13}/", + "id_too_long": f"taler+http://pay/{MERCHANT}/instances/sim/{'A' * 5000}/", + "path_traversal": f"taler+http://pay/{MERCHANT}/../../etc/passwd/{FAKE_ID}/", + "double_encoded": f"taler+http://pay/{MERCHANT}/instances/sim/%2541%2541/", + "percent_broken": f"taler+http://pay/{MERCHANT}/instances/sim/%ZZ/", + "null_byte": f"taler+http://pay/{MERCHANT}/instances/sim/{FAKE_ID}\x00/", + "newline": f"taler+http://pay/{MERCHANT}/instances/sim/{FAKE_ID}\n/", + "crlf_header": f"taler+http://pay/{MERCHANT}/\r\nX-Evil: 1/{FAKE_ID}/", + "unicode": f"taler+http://pay/{MERCHANT}/instances/sim/日本語テスト/", + "rtl_override": f"taler+http://pay/{MERCHANT}/instances/‮sim/{FAKE_ID}/", + "emoji": "taler+http://pay/localhost:8080/instances/🎉/🎉/", + "huge": "taler+http://pay/" + "a" * 10000, + "many_params": f"taler+http://pay/{MERCHANT}/instances/sim/{FAKE_ID}/?" + + "&".join(f"p{i}=1" for i in range(500)), + "port_overflow": f"taler+http://pay/localhost:99999/instances/sim/{FAKE_ID}/", + "port_negative": f"taler+http://pay/localhost:-1/instances/sim/{FAKE_ID}/", + "ipv6_host": f"taler+http://pay/[::1]:8080/instances/sim/{FAKE_ID}/", + "credentials_host": f"taler+http://pay/user:pw@{MERCHANT}/instances/sim/{FAKE_ID}/", + "private_host": f"taler+http://pay/169.254.169.254/instances/sim/{FAKE_ID}/", + "payto_no_target": "payto://iban/", + "payto_unknown_method": f"payto://frobnicate/{FAKE_ID}", + "payto_bad_amount": "payto://iban/SANDBOXX/DE89370400440532013000?amount=EUR:-1", + "payto_huge_amount": "payto://iban/SANDBOXX/DE89370400440532013000?amount=EUR:" + + "9" * 40, +} + +# Formats a scenario fills in once it has live identifiers; the interesting +# cases are the ones that are perfectly well-formed but semantically stale. +TEMPLATES: dict[str, str] = { + "pay": "taler+http://pay/{merchant}/instances/{instance}/{order_id}/?c={token}", + "withdraw": "taler+http://withdraw/{bank}/taler-integration/{withdrawal_id}", + "refund": "taler+http://refund/{merchant}/instances/{instance}/{order_id}/", + "pay_pull": "taler+http://pay-pull/{exchange}/{contract_id}", + "pay_push": "taler+http://pay-push/{exchange}/{contract_id}", +} + +# Text fed into amount and free-text fields; the amount parser and Amount's own +# overflow rules are the target. +TEXT_INPUTS: list[str] = [ + "", " ", "0", "0.00", "-1", "-0.01", "+5", + "1e10", "1E308", "0x10", "٠١٢", "1,50", "1.5.5", "1..5", + "999999999999999999999999", # beyond Amount's value range + "9007199254740993", # beyond 2^53 + "0.000000001", # below the smallest fraction + "10.123456789", # more fraction digits than allowed + "EUR:10", "10 EUR", "KUDOS:10", # currency where a number is expected + "NaN", "Infinity", "null", "undefined", + "'; DROP TABLE coins; --", + "<script>alert(1)</script>", + "${jndi:ldap://x/y}", + "%s%s%s%n", + "‮RTL", "🎉🎉🎉", "日本語", + "A" * 2000, +] + + +def all_uris() -> dict[str, str]: + """Everything that can be fired without live state.""" + return {**{f"structural/{k}": v for k, v in STRUCTURAL.items()}, + **{f"malformed/{k}": v for k, v in MALFORMED.items()}} + + +if __name__ == "__main__": + for name, uri in all_uris().items(): + shown = uri if len(uri) <= 90 else uri[:87] + "..." + print(f"{name:34} {shown!r}") + print(f"\n{len(all_uris())} URIs, {len(TEXT_INPUTS)} text inputs, " + f"{len(TEMPLATES)} templates") diff --git a/simulator/coverage/app-operations.txt b/simulator/coverage/app-operations.txt @@ -0,0 +1,71 @@ +abortTransaction +acceptBankIntegratedWithdrawal +acceptManualWithdrawal +addBankAccount +addContact +addExchange +addGlobalCurrencyExchange +addMailboxMessage +applyDevExperiment +cancelProgressToken +checkDeposit +checkPayForTemplate +checkPeerPullCredit +clearDb +completeRegisterAlias +confirmPay +confirmPeerPullDebit +confirmPeerPushCredit +createDepositGroup +deleteContact +deleteExchange +deleteMailboxMessage +deleteTransaction +exportDb +failTransaction +forgetBankAccount +getBalances +getBankAccountById +getChoicesForPayment +getContacts +getCurrencySpecification +getDepositWireTypes +getDonau +getDonauStatements +getExchangeEntryByUrl +getExchangeTos +getMailbox +getMailboxMessage +getMaxDepositAmount +getMaxPeerPushDebitAmount +getTransactionById +getWithdrawalDetailsForAmount +hintNetworkAvailability +importDb +init +initializeMailbox +initiatePeerPullCredit +initiatePeerPushDebit +initWallet +listBankAccounts +listDiscounts +listExchanges +listSubscriptions +lookupAlias +preparePeerPullDebit +preparePeerPushCredit +prepareWithdrawExchange +refreshMailbox +registerAlias +removeGlobalCurrencyExchange +resumeTransaction +retryTransaction +sendTalerUriMailboxMessage +setDonau +setExchangeTosAccepted +setExchangeTosForgotten +startRefundQueryForUri +suspendTransaction +updateExchangeEntry +validateIban +withdrawTestBalance diff --git a/simulator/coverage/gaps.py b/simulator/coverage/gaps.py @@ -0,0 +1,252 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Where the simulator has not been yet. + +Reads the JaCoCo XML report and ranks what is still untouched, so the next +iteration can aim at a feature rather than at random. Compose generates a lot +of synthetic classes, so lambdas and `*ComposableSingletons` are folded into +their owner and the ranking is by missed *lines* per package and per class. + + python3 gaps.py out/coverage/coverage.xml # ranking + python3 gaps.py out/coverage/coverage.xml --since old.xml # what moved +""" + +from __future__ import annotations + +import re +import sys +import xml.etree.ElementTree as ET +from pathlib import Path +from collections import defaultdict +from dataclasses import dataclass, field + +SYNTHETIC = re.compile(r"\$\$|ComposableSingletons|\$lambda|\$WhenMappings|Kt\$\d") + + +# Lines inside an @Preview body cannot be covered by an instrumented app run: +# the function exists for Android Studio's preview pane and nothing calls it. +# They are 27 % of everything this report calls "missed", so counting them +# makes every ranking point at work that cannot be done. +def preview_lines(repo: Path) -> dict[str, set[int]]: + """Line numbers belonging to @Preview functions, per source file name.""" + out: dict[str, set[int]] = {} + for tree in ("wallet/src/main/java", "taler-kotlin-android/src/main/java"): + base = repo / tree + if not base.is_dir(): + continue + for path in base.rglob("*.kt"): + lines = path.read_text(errors="replace").splitlines() + marked: set[int] = set() + i = 0 + while i < len(lines): + if "@Preview" in lines[i]: + depth, started, j = 0, False, i + while j < len(lines): + marked.add(j + 1) + depth += lines[j].count("{") - lines[j].count("}") + if "{" in lines[j]: + started = True + if started and depth <= 0: + break + j += 1 + i = j + i += 1 + if marked: + out[path.name] = marked + return out + + +def source_misses(path: str, skip: dict[str, set[int]]) -> tuple[int, int, int]: + """(missed, covered, missed-inside-previews) counted line by line.""" + root = ET.parse(path).getroot() + missed = covered = in_preview = 0 + for pkg in root.findall("package"): + for sf in pkg.findall("sourcefile"): + skipped = skip.get(sf.get("name") or "", ()) + for line in sf.findall("line"): + nr = int(line.get("nr", 0)) + mi, ci = int(line.get("mi", 0)), int(line.get("ci", 0)) + if ci: + covered += 1 + elif mi: + missed += 1 + if nr in skipped: + in_preview += 1 + return missed, covered, in_preview + + +def reachable_misses_by_package(path: str, skip: dict[str, set[int]]) -> dict[str, int]: + """Missed lines per package, not counting the ones inside @Preview bodies. + + Ranking packages by raw misses points at work that cannot be done: the + peer package looked like the third-biggest gap in the report and is mostly + four preview functions in one file. + """ + root = ET.parse(path).getroot() + out: dict[str, int] = defaultdict(int) + for pkg in root.findall("package"): + pname = (pkg.get("name") or "").replace("/", ".") + for sf in pkg.findall("sourcefile"): + skipped = skip.get(sf.get("name") or "", ()) + for line in sf.findall("line"): + if int(line.get("ci", 0)): + continue + if not int(line.get("mi", 0)): + continue + if int(line.get("nr", 0)) not in skipped: + out[pname] += 1 + return dict(out) + + +@dataclass +class Unit: + missed: int = 0 + covered: int = 0 + + @property + def total(self) -> int: + return self.missed + self.covered + + @property + def pct(self) -> float: + return 100.0 * self.covered / self.total if self.total else 100.0 + + +def counter(el: ET.Element, kind: str = "LINE") -> tuple[int, int]: + for c in el.findall("counter"): + if c.get("type") == kind: + return int(c.get("missed", 0)), int(c.get("covered", 0)) + return 0, 0 + + +def read(path: str) -> tuple[dict[str, Unit], dict[str, Unit], Unit]: + root = ET.parse(path).getroot() + packages: dict[str, Unit] = defaultdict(Unit) + classes: dict[str, Unit] = defaultdict(Unit) + overall = Unit() + m, c = counter(root) + overall.missed, overall.covered = m, c + for pkg in root.findall("package"): + pname = (pkg.get("name") or "").replace("/", ".") + pm, pc = counter(pkg) + packages[pname].missed += pm + packages[pname].covered += pc + for cls in pkg.findall("class"): + cname = (cls.get("name") or "").replace("/", ".") + # Fold Compose's synthetic classes into the file they came from. + owner = re.split(SYNTHETIC, cname)[0] or cname + cm, cc = counter(cls) + classes[owner].missed += cm + classes[owner].covered += cc + return dict(packages), dict(classes), overall + + +def main() -> int: + if len(sys.argv) < 2: + print(__doc__) + return 2 + packages, classes, overall = read(sys.argv[1]) + print(f"overall lines: {overall.covered}/{overall.total} ({overall.pct:.1f}%)") + # What of the shortfall is even reachable. + repo = Path(__file__).resolve().parent.parent.parent + try: + missed, covered, in_preview = source_misses(sys.argv[1], preview_lines(repo)) + except Exception: # noqa: BLE001 + in_preview = 0 + in_dead = 0 + if "--dead" in sys.argv: + # Opt-in: the dead-code search takes a few minutes, which is too slow + # for a report meant to be read while a round runs. + try: + sys.path.insert(0, str(Path(__file__).resolve().parent)) + import deadcode + found, _ = deadcode.dead(repo, deadcode.MODULES["wallet"]) + dead_by_file: dict[str, set[int]] = defaultdict(set) + for d in found: + dead_by_file[d.path.name].update(range(d.start, d.end + 1)) + root = ET.parse(sys.argv[1]).getroot() + previews = preview_lines(repo) + for pkg in root.findall("package"): + for sf in pkg.findall("sourcefile"): + name = sf.get("name") or "" + pv = previews.get(name, set()) + dd = dead_by_file.get(name, set()) + for line in sf.findall("line"): + nr = int(line.get("nr", 0)) + if int(line.get("ci", 0)) or not int(line.get("mi", 0)): + continue + if nr in dd and nr not in pv: + in_dead += 1 + except Exception as e: # noqa: BLE001 + print(f" (dead-code pass failed: {e})") + if in_preview: + reachable = covered + missed - in_preview - in_dead + print(f" of the {missed} missed lines, {in_preview} are inside @Preview " + f"bodies and cannot run at all") + if in_dead: + print(f" of the rest, {in_dead} are in declarations nothing " + f"refers to (deadcode.py)") + print(f" reachable lines covered: {covered}/{reachable} " + f"({100.0 * covered / reachable:.1f}%); the highest this report " + f"can ever read is {100.0 * reachable / (covered + missed):.1f}%") + if not in_dead: + print(" (pass --dead to discount unreachable declarations too)") + print() + + if "--since" in sys.argv: + before_path = sys.argv[sys.argv.index("--since") + 1] + bp, bc, bo = read(before_path) + print(f"since {before_path}: {bo.covered} -> {overall.covered} lines " + f"({bo.pct:.1f}% -> {overall.pct:.1f}%)\n") + moved = sorted( + ((name, u.covered - bc.get(name, Unit()).covered, u) + for name, u in classes.items()), + key=lambda row: -row[1], + ) + print("newly covered (top 15):") + for name, delta, u in moved[:15]: + if delta <= 0: + break + print(f" +{delta:5} {u.pct:5.1f}% {name.split('.')[-1]}") + print() + + try: + reachable_by_pkg = reachable_misses_by_package(sys.argv[1], preview_lines(repo)) + except Exception: # noqa: BLE001 + reachable_by_pkg = {} + + print("packages by missed lines that can actually be reached:") + ranked = sorted(packages.items(), + key=lambda kv: -reachable_by_pkg.get(kv[0], kv[1].missed)) + for name, u in ranked[:18]: + short = name.replace("net.taler.wallet", "~").replace("net.taler.common", "common") + reach = reachable_by_pkg.get(name) + extra = "" if reach is None else f" ({u.missed} counting previews)" + print(f" {reach if reach is not None else u.missed:6} missed " + f"{u.pct:5.1f}% {short}{extra}") + + print("\nuntouched classes with the most lines (0% covered):") + untouched = [(n, u) for n, u in classes.items() if u.covered == 0 and u.total >= 12] + for name, u in sorted(untouched, key=lambda kv: -kv[1].missed)[:25]: + print(f" {u.missed:6} lines {name}") + + print("\npartly covered, biggest remainder:") + partial = [(n, u) for n, u in classes.items() if u.covered > 0 and u.missed >= 25] + for name, u in sorted(partial, key=lambda kv: -kv[1].missed)[:20]: + print(f" {u.missed:6} missed {u.pct:5.1f}% {name.split('.')[-1]}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/simulator/coverage/operations.py b/simulator/coverage/operations.py @@ -0,0 +1,102 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Which wallet-core operations the simulator has actually exercised. + +JaCoCo measures the Kotlin shell; the logic that produces "internal error" +screens is TypeScript inside QuickJS and cannot be instrumented through qtart. +The boundary between them can be measured though: `BackendManager` logs every +request it sends and every reply it gets, so the operations exercised, and the +error codes each one produced, can be counted from the logcats the episodes +already keep. + +The denominator is the set of operations the app's own Kotlin code can issue +(`app-operations.txt`, extracted from the sources), not everything wallet-core +offers. + + python3 operations.py /opt/taler-sim/run/out + python3 operations.py /opt/taler-sim/run/out --ops app-operations.txt +""" + +from __future__ import annotations + +import argparse +import json +import re +from collections import Counter, defaultdict +from pathlib import Path + +SENT = re.compile(r'"operation"\s*:\s*"([a-zA-Z]+)"') +ERROR_REPLY = re.compile( + r'\{"type":"error","operation":"([a-zA-Z]+)","id":\d+,"error":\{"code":(\d+)') + + +def scan(root: Path) -> tuple[Counter, dict[str, Counter]]: + operations: Counter = Counter() + errors: dict[str, Counter] = defaultdict(Counter) + for log in root.rglob("*logcat*.txt"): + try: + text = log.read_text(errors="replace") + except OSError: + continue + for name in SENT.findall(text): + operations[name] += 1 + for name, code in ERROR_REPLY.findall(text): + errors[name][int(code)] += 1 + return operations, errors + + +def main() -> int: + ap = argparse.ArgumentParser(description=__doc__) + ap.add_argument("root", type=Path, nargs="?", + default=Path("/opt/taler-sim/run/out")) + ap.add_argument("--ops", type=Path, + default=Path(__file__).with_name("app-operations.txt")) + ap.add_argument("--json", action="store_true") + args = ap.parse_args() + + known = [line.strip() for line in args.ops.read_text().splitlines() + if line.strip()] if args.ops.is_file() else [] + seen, errors = scan(args.root) + + exercised = [op for op in known if seen.get(op)] + missing = [op for op in known if not seen.get(op)] + extra = sorted(set(seen) - set(known)) + + if args.json: + print(json.dumps({ + "exercised": exercised, "missing": missing, "undeclared": extra, + "counts": seen, "errors": {k: dict(v) for k, v in errors.items()}, + }, indent=2)) + return 0 + + total = len(known) or len(seen) + print(f"wallet-core operations exercised: {len(exercised)}/{total} " + f"({100 * len(exercised) / total:.0f}%)\n") + print("top operations by calls:") + for name, count in seen.most_common(15): + print(f" {count:6} {name}") + print(f"\nnever exercised ({len(missing)}):") + for name in missing: + print(f" {name}") + if extra: + print(f"\nseen but not in the app's list ({len(extra)}): " + f"{', '.join(extra[:20])}") + print("\noperations that returned an error, with codes:") + for name, codes in sorted(errors.items(), key=lambda kv: -sum(kv[1].values())): + print(f" {name}: {dict(codes)}") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/coverage/report.sh b/simulator/coverage/report.sh @@ -0,0 +1,102 @@ +#!/bin/bash +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# Turn collected .ec files into a coverage report. +# +# Runs on the *build* host, not on the emulator host: the report needs the +# uninstrumented class files and the sources, which only exist where the APK +# was built. Collect the .ec files first (driver/coverage.py on the emulator +# host, then rsync them here). +# +# Usage: report.sh <dir-with-.ec-files> [out-dir] +# +# One warning about the input: jacoco matches execution data to classes by a +# checksum of the class file, so data recorded by one APK is dropped (with +# "Execution data for class … does not match") when reported against a +# different build. Resources are enough to do it -- an added res/ file shifts +# the inlined R constants -- so rebuilding the APK starts a new coverage +# baseline, and .ec files from before it have to be reported separately or not +# at all. + +set -eu + +EC_DIR=${1:?usage: report.sh <dir-with-.ec-files> [out-dir]} +OUT_DIR=${2:-$(dirname "$0")/../out/coverage} +REPO=$(cd "$(dirname "$0")/../.." && pwd) +VARIANT=${SIM_VARIANT:-fdroidSim} +JACOCO_VERSION=${JACOCO_VERSION:-0.8.14} +CACHE=${SIM_TOOLS:-$HOME/.cache/taler-sim} +CLI="$CACHE/org.jacoco.cli-$JACOCO_VERSION-nodeps.jar" + +mkdir -p "$CACHE" "$OUT_DIR" +if [ ! -s "$CLI" ]; then + echo "fetching jacoco cli $JACOCO_VERSION" >&2 + curl -sSfL -o "$CLI" \ + "https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/$JACOCO_VERSION/org.jacoco.cli-$JACOCO_VERSION-nodeps.jar" +fi + +# One truncated .ec -- a dump whose app was killed mid-write -- makes jacoco's +# `merge` abort over every other file, so the files are checked first and only +# the complete ones go in. +mapfile -t EC_FILES < <(python3 "$(dirname "$0")/validate_ec.py" "$EC_DIR") +[ "${#EC_FILES[@]}" -gt 0 ] || { echo "no usable .ec files under $EC_DIR" >&2; exit 1; } +echo "merging ${#EC_FILES[@]} execution data file(s)" >&2 + +# JAVA_HOME when it points at a usable JVM, otherwise whatever is on PATH: +# this used to hard-code the workstation's JDK, so a run on the emulator host +# -- where JAVA_HOME is not set -- died with "no such file or directory" after +# validating all 2400 dumps. +if [ -n "${JAVA_HOME:-}" ] && [ -x "$JAVA_HOME/bin/java" ]; then + JAVA="$JAVA_HOME/bin/java" +else + JAVA=$(command -v java) || + { echo "no java on PATH and no usable JAVA_HOME" >&2; exit 1; } +fi +MERGED="$OUT_DIR/merged.exec" +# `merge` appends to an existing --destfile, which silently doubles everything +# on a second run. +rm -f "$MERGED" +"$JAVA" -jar "$CLI" merge "${EC_FILES[@]}" --destfile "$MERGED" + +# Kotlin and Java classes land in separate trees; both belong in the report, +# and both must be the uninstrumented ones. +CLASS_ARGS=() +for d in "$REPO/wallet/build/tmp/kotlin-classes/$VARIANT" \ + "$REPO/wallet/build/intermediates/javac/$VARIANT/classes"; do + [ -d "$d" ] && CLASS_ARGS+=(--classfiles "$d") +done +[ "${#CLASS_ARGS[@]}" -gt 0 ] || { echo "no class files for variant $VARIANT" >&2; exit 1; } + +"$JAVA" -jar "$CLI" report "$MERGED" \ + "${CLASS_ARGS[@]}" \ + --sourcefiles "$REPO/wallet/src/main/java" \ + --sourcefiles "$REPO/taler-kotlin-android/src/main/java" \ + --html "$OUT_DIR/html" \ + --xml "$OUT_DIR/coverage.xml" \ + --name "Taler wallet simulator ($VARIANT)" + +python3 - "$OUT_DIR/coverage.xml" <<'PY' +import sys, xml.etree.ElementTree as ET +root = ET.parse(sys.argv[1]).getroot() +print() +for counter in root.findall("counter"): + t = counter.get("type") + covered, missed = int(counter.get("covered")), int(counter.get("missed")) + total = covered + missed + if total: + print(f"{t.lower():12} {covered:7}/{total:<7} {100 * covered / total:5.1f}%") +PY +echo +echo "report: $OUT_DIR/html/index.html" >&2 diff --git a/simulator/coverage/validate_ec.py b/simulator/coverage/validate_ec.py @@ -0,0 +1,131 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Print the .ec files that are complete execution data, skip the rest. + +A dump whose app was killed while writing leaves a truncated file, and jacoco's +`merge` aborts on the first one it cannot read -- so one bad file out of a +thousand loses a whole campaign's coverage. Rather than merge in batches and +guess, this walks each file's block structure once and keeps only the files +that end on a block boundary. + + python3 validate_ec.py <dir> [--quiet] # one good path per line on stdout + +The format is org.jacoco.core.data.ExecutionDataWriter's: a header block, then +session-info and execution-data blocks, with Java DataOutput encodings and +jacoco's own var-int for array lengths. +""" + +from __future__ import annotations + +import sys +from pathlib import Path + +BLOCK_HEADER = 0x01 +BLOCK_SESSIONINFO = 0x10 +BLOCK_EXECUTIONDATA = 0x11 +MAGIC = 0xC0C0 + + +class Truncated(Exception): + pass + + +class Reader: + def __init__(self, data: bytes) -> None: + self.data = data + self.pos = 0 + + def take(self, n: int) -> bytes: + if self.pos + n > len(self.data): + raise Truncated(f"wanted {n} bytes at {self.pos} of {len(self.data)}") + out = self.data[self.pos:self.pos + n] + self.pos += n + return out + + def u8(self) -> int: + return self.take(1)[0] + + def u16(self) -> int: + return int.from_bytes(self.take(2), "big") + + def u64(self) -> int: + return int.from_bytes(self.take(8), "big") + + def utf(self) -> bytes: + return self.take(self.u16()) + + def var_int(self) -> int: + value, shift = 0, 0 + while True: + b = self.u8() + value |= (b & 0x7F) << shift + if not b & 0x80: + return value + shift += 7 + + def boolean_array(self) -> None: + bits = self.var_int() + self.take((bits + 7) // 8) + + +def complete(path: Path) -> bool: + """Whether this file is execution data all the way to its last byte.""" + r = Reader(path.read_bytes()) + if not r.data: + return False + try: + while r.pos < len(r.data): + block = r.u8() + if block == BLOCK_HEADER: + if r.u16() != MAGIC: + return False + r.u16() # format version + elif block == BLOCK_SESSIONINFO: + r.utf() + r.u64() # start + r.u64() # dump + elif block == BLOCK_EXECUTIONDATA: + r.u64() # class id + r.utf() # class name + r.boolean_array() + else: + return False + except Truncated: + return False + return True + + +def main() -> int: + if len(sys.argv) < 2: + print(__doc__, file=sys.stderr) + return 2 + quiet = "--quiet" in sys.argv + files = sorted(Path(sys.argv[1]).rglob("*.ec")) + good = [] + for f in files: + if complete(f): + good.append(f) + elif not quiet: + print(f"skipping incomplete {f} ({f.stat().st_size} bytes)", + file=sys.stderr) + if not quiet: + print(f"{len(good)} of {len(files)} execution data files are complete", + file=sys.stderr) + for f in good: + print(f) + return 0 if good else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/simulator/driver/campaign.py b/simulator/driver/campaign.py @@ -0,0 +1,192 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Run scenarios and explorations across several emulators at once. + +Each worker has its own emulator, its own bank customer and its own CLI peer +wallet, so they only share the Taler services. Work is split round-robin and +the per-worker summaries are merged into one report. + + python3 campaign.py suite # every scenario, 4 ways + python3 campaign.py suite --workers 2 + python3 campaign.py explore --steps 150 # one exploration per worker + python3 campaign.py both +""" + +from __future__ import annotations + +import argparse +import json +import os +import subprocess +import time +from collections.abc import Iterable +from pathlib import Path + +import oracles +import suite +from device import Device + +OUT = Path("/opt/taler-sim/run/out") +COVERAGE = Path("/opt/taler-sim/run/coverage") +HERE = Path(__file__).resolve().parent + + +def online_workers(limit: int) -> list[int]: + """Workers whose emulator is actually up.""" + listed = subprocess.run( + ["/opt/android-sdk/platform-tools/adb", "devices"], + capture_output=True, text=True, timeout=60, + ).stdout + found = [] + for worker in range(limit): + if f"emulator-{5554 + 2 * worker}\tdevice" in listed: + found.append(worker) + return found + + +def split(names: list[str], workers: list[int]) -> dict[int, list[str]]: + buckets: dict[int, list[str]] = {w: [] for w in workers} + for i, name in enumerate(names): + buckets[workers[i % len(workers)]].append(name) + return buckets + + +def launch(worker: int, args: list[str], tag: str) -> tuple[int, subprocess.Popen, Path]: + env = dict(os.environ, SIM_WORKER=str(worker)) + log = OUT / f"{tag}-w{worker}.log" + log.parent.mkdir(parents=True, exist_ok=True) + handle = log.open("w") + proc = subprocess.Popen(args, cwd=HERE, env=env, stdout=handle, + stderr=subprocess.STDOUT, text=True) + return worker, proc, log + + +def wait_all(jobs: list[tuple[int, subprocess.Popen, Path]], poll: int = 20) -> None: + pending = {w: (p, log) for w, p, log in jobs} + while pending: + for worker in list(pending): + proc, log = pending[worker] + if proc.poll() is not None: + print(f"worker {worker} finished with code {proc.returncode} ({log})") + del pending[worker] + if pending: + time.sleep(poll) + + +def collect(stamp_after: float, workers: Iterable[int] | None = None) -> dict: + """Merge the per-worker suite summaries this run produced. + + Filtered by worker as well as by time: a scenario run by hand on a spare + emulator writes a summary into the same directory, and round 20's tally + swallowed three such runs -- 147 "scenarios", and findings from a patched + APK reported against an unpatched round. + """ + wanted = None if workers is None else {f"suite-w{w}-" for w in workers} + merged: dict = {"scenarios": [], "findings": {}} + for path in sorted(OUT.glob("suite-w*-summary.json")): + if path.stat().st_mtime < stamp_after: + continue + if wanted is not None and not any(path.name.startswith(p) for p in wanted): + continue + data = json.loads(path.read_text()) + merged["scenarios"] += data.get("scenarios", []) + for f in data.get("findings", []): + merged["findings"][f["fingerprint"]] = f + return merged + + +def report(merged: dict) -> None: + rows = merged["scenarios"] + ok = [r for r in rows if r.get("status") == "ok"] + broken = [r for r in rows if r.get("status") != "ok"] + print(f"\n{len(rows)} scenarios: {len(ok)} ok, {len(broken)} driver errors") + for r in sorted(rows, key=lambda r: r.get("scenario") or ""): + flag = " " if r.get("status") == "ok" else "!" + print(f" {flag} {r.get('scenario'):26} {r.get('serious', 0)} serious, " + f"{len(r.get('findings', []))} findings, {r.get('seconds')}s") + if r.get("error"): + print(f" error: {r['error'][:200]}") + # oracles.INFORMATIONAL, the same rule the session and the suite use: a + # withdrawal the suite leaves pending on purpose is not a defect. + serious = [f for f in merged["findings"].values() + if f["kind"] not in oracles.INFORMATIONAL] + print(f"\nfindings: {len(merged['findings'])} distinct, {len(serious)} serious") + for f in merged["findings"].values(): + mark = "***" if f["kind"] not in oracles.INFORMATIONAL else " " + print(f" {mark} [{f['kind']}] {f['fingerprint']} {f['detail'][:170]}") + + +def dump_coverage(workers: list[int], tag: str) -> None: + import coverage as coverage_mod + for worker in workers: + dev = Device(f"emulator-{5554 + 2 * worker}") + try: + path = coverage_mod.dump(dev, COVERAGE / f"{tag}-w{worker}.ec", name=f"{tag}.ec") + print(f"coverage worker {worker}: {path} ({path.stat().st_size} bytes)") + except Exception as e: + print(f"coverage worker {worker} failed: {e}") + + +def main() -> int: + ap = argparse.ArgumentParser(description=__doc__) + ap.add_argument("mode", choices=["suite", "explore", "both"]) + ap.add_argument("--workers", type=int, default=4) + ap.add_argument("--steps", type=int, default=120, help="explore steps per worker") + ap.add_argument("--seed", type=int, default=100) + ap.add_argument("--only", nargs="*", help="scenario names (suite mode)") + ap.add_argument("--tag", default=None) + args = ap.parse_args() + + workers = online_workers(args.workers) + if not workers: + print("no emulators online") + return 1 + tag = args.tag or f"{args.mode}-{int(time.time())}" + started = time.time() + print(f"workers online: {workers} tag: {tag}") + + if args.mode in ("suite", "both"): + names = args.only or list(suite.REGISTRY) + buckets = split(names, workers) + jobs = [] + for worker, bucket in buckets.items(): + if not bucket: + continue + print(f"worker {worker}: {len(bucket)} scenarios -> {bucket}") + jobs.append(launch(worker, ["python3", "-u", "suite.py", *bucket], + f"{tag}-suite")) + wait_all(jobs) + dump_coverage(list(buckets), f"{tag}-suite") + report(collect(started, buckets)) + + if args.mode in ("explore", "both"): + started = time.time() + jobs = [] + for worker in workers: + seed = args.seed + worker + print(f"worker {worker}: explore {args.steps} steps, seed {seed}") + jobs.append(launch(worker, ["python3", "-u", "explore.py", + str(args.steps), str(seed)], f"{tag}-explore")) + wait_all(jobs) + dump_coverage(workers, f"{tag}-explore") + for worker in workers: + log = OUT / f"{tag}-explore-w{worker}.log" + if log.exists(): + print(f"\n--- worker {worker} ---") + print(log.read_text()[-1500:]) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/driver/cli.py b/simulator/driver/cli.py @@ -0,0 +1,254 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""taler-wallet-cli as the wallet's peer. + +Peer-to-peer payments need a second wallet. A command-line wallet on the host +is far cheaper than a second emulator and just as real from the app's point of +view: it holds its own coins at the same exchange and exchanges the same URIs. +""" + +from __future__ import annotations + +import json +import os +import re +import subprocess +import time +from pathlib import Path + +BINARY = "taler-wallet-cli" +URI_RE = re.compile(r"taler(?:\+http)?://[^\s'\"]+") + + +class CliWallet: + def __init__(self, db: str | Path | None = None, timeout: int = 300): + # One database per worker: the peer wallet is state, like the app's. + if db is None: + worker = os.environ.get("SIM_WORKER", "0") + # The extension picks the backend, and this build no longer has the + # JSON/in-memory one ("memory backend not supported"). + db = f"/opt/taler-sim/run/cli-wallet-{worker}.sqlite3" + self.db = str(db) + self.timeout = timeout + + def run(self, *args: str, check: bool = True) -> str: + proc = subprocess.run( + [BINARY, "--wallet-db", self.db, "--non-interactive", *args], + capture_output=True, text=True, timeout=self.timeout, + ) + if check and proc.returncode != 0: + raise RuntimeError( + f"{BINARY} {' '.join(args)} failed ({proc.returncode}): " + f"{(proc.stderr or proc.stdout)[-600:]}" + ) + return proc.stdout + proc.stderr + + def reset(self) -> None: + for suffix in ("", "-wal", "-shm"): + Path(self.db + suffix).unlink(missing_ok=True) + + def add_exchange(self, exchange: str) -> str: + """Teach the peer wallet about an exchange and accept its terms.""" + out = self.run("exchanges", "add", exchange, check=False) + return out + self.run("exchanges", "accept-tos", exchange, check=False) + + def fund_via_bank(self, bank, user: tuple[str, str], amount: str, + exchange: str, timeout: int = 150) -> str: + """Fund the peer wallet with a bank-integrated withdrawal. + + `withdraw --exchange --amount` would create a *manual* withdrawal that + waits for a wire transfer nobody is going to make, and `withdraw --uri` + does not always get as far as choosing an exchange, which leaves the + bank refusing to confirm ("Cannot confirm an unselected withdrawal"). + So the exchange is selected through the same wallet-core call the app + uses, and only then is the operation confirmed in the bank. + """ + self.add_exchange(exchange) + op = bank.create_withdrawal(*user, amount) + accepted = self.api("acceptBankIntegratedWithdrawal", { + "talerWithdrawUri": op["taler_withdraw_uri"], + "exchangeBaseUrl": exchange, + }) + if "master public key" in json.dumps(accepted): + # The stack was rebuilt since this wallet last ran, so its memory + # of the exchange is stale; start it over rather than carrying a + # wallet that refuses to talk to the only exchange there is. + self.reset() + self.add_exchange(exchange) + op = bank.create_withdrawal(*user, amount) + accepted = self.api("acceptBankIntegratedWithdrawal", { + "talerWithdrawUri": op["taler_withdraw_uri"], + "exchangeBaseUrl": exchange, + }) + result = accepted.get("result") or {} + transaction = result.get("transactionId") + if not transaction: + raise RuntimeError(f"the peer wallet could not accept the withdrawal: " + f"{str(accepted)[:400]}") + # The CLI is not a daemon: each invocation starts wallet-core, answers + # one request and exits, so the task that tells the bank which exchange + # was chosen only runs while something is waiting on the transaction. + # "--state pending" is useless for that -- the transaction is already + # pending, so the wait returns before any task has run. "pending/idle" + # is the state that means the wallet has done all it can and is now + # waiting on the bank. + self.pump(transaction, "pending/idle", 90) + deadline = time.time() + 90 + while time.time() < deadline: + if bank.withdrawal_status(op["withdrawal_id"])["status"] == "selected": + break + self.pump(transaction, "pending/idle", 30) + time.sleep(2) + else: + raise RuntimeError(f"the bank never saw an exchange selected for {amount}") + bank.confirm_withdrawal(*user, op["withdrawal_id"]) + # Pump the task loop again so the coins are actually withdrawn. + self.pump(transaction, "final", 120) + return self.balance() + + def pump(self, transaction: str, state: str = "pending/idle", + timeout: int = 60) -> str: + """Run wallet-core until `transaction` reaches `state`. + + This is the only way to make the CLI do background work: it processes + tasks while a wait is outstanding and exits as soon as it is over. + """ + return self.run("wait-tx", "--state", state, + "--timeout", f"{timeout}s", transaction, check=False) + + def balance(self) -> str: + return self.run("balance") + + def withdraw(self, exchange: str, amount: str) -> str: + """Fund the peer wallet straight from the exchange, no bank UI needed.""" + return self.run("withdraw", "--exchange", exchange, "--amount", amount, + "--wait", "--timeout", "120s") + + def accept_tos(self, exchange: str) -> str: + return self.run("exchanges", "accept-tos", exchange, check=False) + + def peer_send(self, amount: str, exchange: str, + summary: str = "from the simulator's peer") -> str: + """Push money to the app; returns the taler://pay-push URI.""" + out = self.run_fresh_on_key_change( + exchange, "peer-send", "--exchange", exchange, + "--summary", summary, amount) + return self._uri(out, "pay-push") + + def peer_request(self, amount: str, + summary: str = "invoice from the simulator's peer", + exchange: str | None = None) -> str: + """Invoice the app; returns the taler://pay-pull URI.""" + if exchange is None: + out = self.run("peer-request", "--summary", summary, amount) + else: + out = self.run_fresh_on_key_change( + exchange, "peer-request", "--summary", summary, amount) + return self._uri(out, "pay-pull") + + def send_mailbox_message(self, address: str, taler_uri: str, + mailbox_base: str = "http://127.0.0.1:11000/", + petname: str = "The app under test") -> dict: + """Put a real message in another wallet's mailbox. + + The app has no caller for `sendTalerUriMailboxMessage` -- the manager + method exists and nothing invokes it -- so the sender has to be this + wallet. The envelope is encrypted for the recipient's address, which + is why a hand-made POST to the service cannot stand in for it: the app + reads an unreadable message and discards it without a word. + """ + contact = { + "alias": "simulator@example.com", + "aliasType": "email", + "mailboxBaseUri": mailbox_base, + "mailboxAddress": address, + "source": "local", + "petname": petname, + "originMailboxBaseUrl": mailbox_base, + "downloadedAt": {"t_s": int(time.time())}, + "talerUri": "", + "transactionId": "", + } + return self.api("sendTalerUriMailboxMessage", + {"contact": contact, "talerUri": taler_uri}) + + def run_fresh_on_key_change(self, exchange: str, *args: str) -> str: + """Run a command, starting the wallet over if its exchange moved on. + + Every stack start gives the exchange a new master key, and a wallet + that remembers the old one refuses every operation with "the exchange + changed its master public key" (7066). Funding already coped with + this; the peer commands have to as well, because a scenario may be the + first thing to touch this wallet after a restart. + """ + try: + return self.run(*args) + except RuntimeError as e: + if "master public key" not in str(e): + raise + self.reset() + self.add_exchange(exchange) + return self.run(*args) + + def _uri(self, output: str, kind: str) -> str: + for match in URI_RE.finditer(output): + if kind in match.group(0): + return match.group(0).rstrip(".,)") + raise RuntimeError(f"no {kind} URI in output: {output[-600:]}") + + def api(self, operation: str, payload: dict | None = None) -> dict: + """Call wallet-core directly, bypassing the CLI's prompts. + + `handle-uri` asks whether to accept an incoming payment, and neither + `-y` nor the global `--non-interactive` answers that question off a + terminal, so the peer wallet drives the two-step API itself. + """ + out = self.run("advanced", "api", operation, + json.dumps(payload or {}), check=False) + start = out.find("{") + if start < 0: + raise RuntimeError(f"{operation}: no JSON in {out[-400:]}") + try: + # The CLI prints its own lines after the response, so only the + # first JSON value is ours. + parsed, _ = json.JSONDecoder().raw_decode(out[start:]) + return parsed + except json.JSONDecodeError as e: + raise RuntimeError(f"{operation}: {e}; output was {out[-400:]}") from None + + def accept_push(self, uri: str) -> dict: + """Accept an incoming push payment the app sent.""" + prepared = self.api("preparePeerPushCredit", {"talerUri": uri}) + result = prepared.get("result", {}) + transaction_id = result.get("transactionId") + if not transaction_id: + raise RuntimeError(f"preparePeerPushCredit gave no transaction: {prepared}") + return self.api("confirmPeerPushCredit", {"transactionId": transaction_id}) + + def pay_pull(self, uri: str) -> dict: + """Pay an invoice the app issued.""" + prepared = self.api("preparePeerPullDebit", {"talerUri": uri}) + result = prepared.get("result", {}) + transaction_id = result.get("transactionId") + if not transaction_id: + raise RuntimeError(f"preparePeerPullDebit gave no transaction: {prepared}") + return self.api("confirmPeerPullDebit", {"transactionId": transaction_id}) + + def handle_uri(self, uri: str) -> str: + """Hand a URI to the peer wallet, answering its questions. + + Prefer accept_push/pay_pull for peer payments; this stays for URIs that + need no confirmation. + """ + return self.run("handle-uri", "-y", uri) diff --git a/simulator/driver/coverage.py b/simulator/driver/coverage.py @@ -0,0 +1,83 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Pull JaCoCo execution data out of a running wallet. + +The simulator drives the app from outside, so AGP's own instrumented-test +coverage plumbing never runs. Instead the "sim" build type carries the JaCoCo +agent plus the SimHooks receiver, and this module asks the agent for what it +has collected so far. Data accumulates in the live process, so dumping is +cheap and can be done between episodes; the file only has to be collected +before the process dies. +""" + +from __future__ import annotations + +import subprocess +from pathlib import Path + +from device import ADB, PKG, Device + +RECEIVER = f"{PKG}/net.taler.wallet.sim.SimHooks" +ACTION = "net.taler.wallet.sim.DUMP_COVERAGE" + + +# Every jacoco .exec stream starts with a block header and this magic. +MAGIC = b"\x01\xc0\xc0" + + +def dump(dev: Device, out_path: str | Path, name: str = "coverage.ec") -> Path: + """Dump coverage from the app and copy it off the device. + + Raises if the agent is missing, which means the APK under test was not + built from the "sim" build type. + """ + out = Path(out_path) + out.parent.mkdir(parents=True, exist_ok=True) + res = dev.shell(f"am broadcast -a {ACTION} -n {RECEIVER} --es file {name}") + if "Broadcast completed" not in res: + raise RuntimeError(f"coverage broadcast not delivered: {res.strip()}") + # run-as is the only way into the app's private files; the sim build is + # debuggable, so it is allowed. + data = subprocess.run( + [ADB, "-s", dev.serial, "exec-out", "run-as", PKG, "cat", f"files/{name}"], + capture_output=True, timeout=120, + ) + if not data.stdout: + raise RuntimeError( + f"no coverage data (stderr: {data.stderr.decode(errors='replace').strip()}); " + "is this the fdroidSim APK?" + ) + # A dump whose process was killed while writing (the before-wipe one, as + # often as not) leaves a truncated file, and jacoco's `merge` aborts on the + # first one it cannot read -- losing every other file's data with it. So a + # dump that does not at least begin like execution data never gets the + # final name. + if not data.stdout.startswith(MAGIC): + raise RuntimeError( + f"coverage data for {name} is not jacoco execution data " + f"({len(data.stdout)} bytes, starts {data.stdout[:8]!r}); " + "the app was probably killed mid-dump" + ) + part = out.with_suffix(out.suffix + ".part") + part.write_bytes(data.stdout) + part.replace(out) + return out + + +if __name__ == "__main__": + import sys + d = Device(sys.argv[2] if len(sys.argv) > 2 else "emulator-5554") + target = sys.argv[1] if len(sys.argv) > 1 else "/opt/taler-sim/run/coverage/manual.ec" + p = dump(d, target) + print(f"{p} ({p.stat().st_size} bytes)") diff --git a/simulator/driver/dbprobe.py b/simulator/driver/dbprobe.py @@ -0,0 +1,106 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Read the wallet's SQLite database by copying it off the device. + +wallet-core runs with `useNativeDb`, so transaction state lives in a plain +SQLite file. The app's own SELinux domain may not exec /system/bin/sqlite3, +so the file (and its write-ahead log) are copied out with `run-as ... cat` and +queried on the host. The copy doubles as evidence for a finding. + + python3 dbprobe.py tables + python3 dbprobe.py emulator-5556 schema transactions + python3 dbprobe.py sql "select * from transactions limit 5" +""" + +from __future__ import annotations + +import sqlite3 +import subprocess +import sys +import tempfile +from pathlib import Path + +from device import ADB, PKG, Device + +DB_NAME = "talerwalletdb.sqlite3" + + +def pull(dev: Device, into: Path | None = None) -> Path: + """Copy the wallet database (plus its WAL) off the device.""" + target_dir = into or Path(tempfile.mkdtemp(prefix="walletdb-")) + target_dir.mkdir(parents=True, exist_ok=True) + db = target_dir / DB_NAME + for suffix in ("", "-wal", "-shm"): + data = subprocess.run( + [ADB, "-s", dev.serial, "exec-out", "run-as", PKG, "cat", + f"files/{DB_NAME}{suffix}"], + capture_output=True, timeout=180, + ).stdout + if data: + (target_dir / f"{DB_NAME}{suffix}").write_bytes(data) + elif suffix == "": + raise RuntimeError("could not read the wallet database off the device") + return db + + +def connect(db: Path) -> sqlite3.Connection: + conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True) + conn.row_factory = sqlite3.Row + return conn + + +def tables(db: Path) -> list[str]: + with connect(db) as conn: + return [r[0] for r in conn.execute( + "select name from sqlite_master where type='table' order by name")] + + +def columns(db: Path, table: str) -> list[str]: + with connect(db) as conn: + return [r[1] for r in conn.execute(f"pragma table_info({table})")] + + +def has_native_schema(db: Path) -> bool: + """Whether this database holds the native wallet schema. + + A wallet that has not been migrated keeps everything in the IndexedDB + emulation tables (`object_data` and friends), where none of the oracles' + queries apply. Asking first is cheaper than catching "no such table" on + every query, and it distinguishes "nothing to look at" from "the probe + broke". + """ + return "operation_retries" in set(tables(db)) + + +def rows(db: Path, sql: str, limit: int = 50) -> list[sqlite3.Row]: + with connect(db) as conn: + return list(conn.execute(sql))[:limit] + + +if __name__ == "__main__": + args = sys.argv[1:] + serial = "emulator-5554" + if args and args[0].startswith("emulator-"): + serial = args.pop(0) + database = pull(Device(serial)) + print(f"# {database}") + if not args or args[0] == "tables": + for name in tables(database): + print(name) + elif args[0] == "schema": + for name in args[1:] or tables(database): + print(f"{name}: {', '.join(columns(database, name))}") + elif args[0] == "sql": + for row in rows(database, args[1]): + print(dict(row)) diff --git a/simulator/driver/device.py b/simulator/driver/device.py @@ -0,0 +1,515 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Thin adb wrapper: one emulator, seen through the accessibility tree. + +The wallet is almost entirely Jetpack Compose and carries no testTags, so the +driver addresses widgets through the semantics the app already exposes: text, +content-description and bounds. Everything here is therefore black-box; the +only app-specific knowledge is the package name. +""" + +from __future__ import annotations + +import re +import shlex +import subprocess +import time +import xml.etree.ElementTree as ET +from dataclasses import dataclass, field +from typing import Iterable, Optional + +ADB = "/opt/android-sdk/platform-tools/adb" +PKG = "net.taler.wallet.fdroid.debug" +ACTIVITY = f"{PKG}/net.taler.wallet.main.MainActivity" + +BOUNDS_RE = re.compile(r"\[(-?\d+),(-?\d+)\]\[(-?\d+),(-?\d+)\]") + + +@dataclass(frozen=True) +class Node: + """One node of the accessibility tree, flattened.""" + + cls: str + text: str + desc: str + rid: str + clickable: bool + scrollable: bool + editable: bool + checkable: bool + checked: bool + enabled: bool + bounds: tuple[int, int, int, int] + + @property + def center(self) -> tuple[int, int]: + x1, y1, x2, y2 = self.bounds + return (x1 + x2) // 2, (y1 + y2) // 2 + + @property + def label(self) -> str: + return self.text or self.desc + + @property + def area(self) -> int: + x1, y1, x2, y2 = self.bounds + return max(0, x2 - x1) * max(0, y2 - y1) + + def __str__(self) -> str: + kind = self.cls.rsplit(".", 1)[-1] + flags = "".join( + f for f, on in (("C", self.clickable), ("S", self.scrollable), + ("E", self.editable), ("x", not self.enabled)) + if on + ) + return f"{kind}{'[' + flags + ']' if flags else ''} {self.label!r} @{self.center}" + + +@dataclass +class Screen: + """A parsed UI dump plus the cheap derived views the driver needs.""" + + nodes: list[Node] = field(default_factory=list) + activity: str = "" + + def labelled(self) -> list[Node]: + return [n for n in self.nodes if n.label.strip()] + + def tappable(self) -> list[Node]: + """Clickable nodes, plus labelled leaves (Compose often marks only an + ancestor clickable, so a text node's own box is the better tap target).""" + out = [n for n in self.nodes if n.clickable and n.enabled and n.area > 0] + seen = {n.bounds for n in out} + for n in self.labelled(): + if n.bounds not in seen and n.area > 0: + out.append(n) + seen.add(n.bounds) + return out + + def editable(self) -> list[Node]: + return [n for n in self.nodes if n.editable and n.enabled] + + def texts(self) -> list[str]: + return [n.label.strip() for n in self.labelled()] + + def tap_target(self, node: Node) -> Node: + """The node that actually reacts when the user aims at `node`. + + Three shapes occur in this app: the labelled node is itself clickable; + the label sits inside a clickable ancestor (ordinary Compose); or the + label is a separate TextView *underneath* an unlabelled Button, which + is how the main screen's Send/Request/Withdraw/Deposit buttons are + built. The last case needs a neighbour search, not a containment + search, or the tap lands on nothing at all. + """ + if node.clickable and node.enabled: + return node + cx, cy = node.center + clickables = [n for n in self.nodes if n.clickable and n.enabled and n.area > 0] + containing = [n for n in clickables + if n.bounds[0] <= cx <= n.bounds[2] + and n.bounds[1] <= cy <= n.bounds[3]] + if containing: + return min(containing, key=lambda n: n.area) + # A clickable node directly above or below, overlapping horizontally. + x1, y1, x2, y2 = node.bounds + + def neighbour_distance(n: Node) -> Optional[int]: + if n.bounds[2] < x1 or n.bounds[0] > x2: + return None + if n.bounds[3] <= y1: + return y1 - n.bounds[3] + if n.bounds[1] >= y2: + return n.bounds[1] - y2 + return 0 + + scored = [(d, n) for n in clickables + if (d := neighbour_distance(n)) is not None and d <= 120] + if scored: + return min(scored, key=lambda row: row[0])[1] + return node + + def unnamed_clickables(self) -> list[Node]: + """Clickable nodes a screen reader cannot announce. + + A clickable node with no text of its own is fine when the label sits + *inside* it: Compose merges the semantics and TalkBack reads the child. + What is not fine is a label that is only a neighbour, which is how the + main screen's action buttons are built. Only the latter are returned. + """ + labelled = [n for n in self.nodes if n.label.strip() and n.area > 0] + out = [] + for node in self.nodes: + if not (node.clickable and node.enabled and node.area > 0): + continue + if node.label.strip(): + continue + x1, y1, x2, y2 = node.bounds + if x2 - x1 >= 600 and y2 - y1 >= 600: + continue # a full-screen container, not a control + contains_label = any( + x1 <= n.bounds[0] and y1 <= n.bounds[1] + and n.bounds[2] <= x2 and n.bounds[3] <= y2 + for n in labelled + ) + if not contains_label: + out.append(node) + return out + + def find(self, pattern: str) -> Optional[Node]: + rx = re.compile(pattern, re.I) + for n in self.nodes: + if n.label and rx.search(n.label): + return n + return None + + def signature(self) -> str: + """Stable-ish identity of a screen, for novelty tracking and oracles. + + Only the set of labels and the shape of the interactive nodes go in, so + the same screen with a different balance still matches itself. + """ + labels = sorted({re.sub(r"\d+[.,]?\d*", "#", t) for t in self.texts()}) + shape = f"{len(self.tappable())}/{len(self.editable())}" + return f"{self.activity}|{shape}|{'|'.join(labels)}" + + def __str__(self) -> str: + return "\n".join(str(n) for n in self.labelled()) + + +class Device: + def __init__(self, serial: str = "emulator-5554", pkg: str = PKG): + self.serial = serial + self.pkg = pkg + self._sdk_int: Optional[int] = None + self._size: Optional[tuple[int, int]] = None + + # -- plumbing --------------------------------------------------------- + + def adb(self, *args: str, timeout: int = 60, check: bool = True) -> str: + proc = subprocess.run( + [ADB, "-s", self.serial, *args], + capture_output=True, text=True, timeout=timeout, + ) + if check and proc.returncode != 0: + raise RuntimeError(f"adb {' '.join(args)} failed: {proc.stderr.strip()}") + return proc.stdout + + def shell(self, cmd: str, timeout: int = 60, check: bool = True) -> str: + return self.adb("shell", cmd, timeout=timeout, check=check) + + # -- observation ------------------------------------------------------ + + @property + def sdk_int(self) -> int: + """The device's API level, read once. + + Scenarios need this because the *harness* has version floors of its + own: per-app language is API 33+, for instance, so a scenario that + changes it on an older device is testing adb, not the wallet. + """ + if self._sdk_int is None: + out = self.shell("getprop ro.build.version.sdk", check=False) + try: + self._sdk_int = int(out.strip() or 0) + except ValueError: + self._sdk_int = 0 + return self._sdk_int + + def current_activity(self) -> str: + out = self.shell("dumpsys activity activities | grep -m1 ResumedActivity", check=False) + m = re.search(r"([A-Za-z0-9_.]+/[A-Za-z0-9_.]+)", out) + return m.group(1) if m else "" + + def dump(self, retries: int = 3) -> Screen: + """Read the accessibility tree. + + uiautomator fails while the UI is still settling ("could not get idle + state"), which is routine right after a tap, so this retries. + """ + xml = "" + for attempt in range(retries): + out = self.shell("uiautomator dump /sdcard/ui.xml", check=False) + if "dumped" in out.lower(): + xml = self.adb("exec-out", "cat", "/sdcard/ui.xml", check=False) + if xml.lstrip().startswith("<?xml"): + break + time.sleep(1 + attempt) + if not xml.lstrip().startswith("<?xml"): + return Screen(activity=self.current_activity()) + return self._parse(xml) + + def _parse(self, xml: str) -> Screen: + screen = Screen(activity=self.current_activity()) + try: + root = ET.fromstring(xml) + except ET.ParseError: + return screen + for el in root.iter("node"): + m = BOUNDS_RE.match(el.get("bounds", "")) + if not m: + continue + cls = el.get("class", "") + screen.nodes.append(Node( + cls=cls, + text=el.get("text", ""), + desc=el.get("content-desc", ""), + rid=el.get("resource-id", ""), + clickable=el.get("clickable") == "true", + scrollable=el.get("scrollable") == "true", + editable=el.get("class", "").endswith("EditText") + or el.get("focusable") == "true" and "EditText" in cls, + checkable=el.get("checkable") == "true", + checked=el.get("checked") == "true", + enabled=el.get("enabled") == "true", + bounds=tuple(int(v) for v in m.groups()), # type: ignore[arg-type] + )) + return screen + + def screenshot(self, path: str) -> None: + png = subprocess.run([ADB, "-s", self.serial, "exec-out", "screencap", "-p"], + capture_output=True, timeout=60).stdout + with open(path, "wb") as f: + f.write(png) + + def logcat(self, clear: bool = False, lines: Optional[int] = None) -> str: + """Read the log, or clear it. + + `lines` bounds the read to the most recent entries. Reading the whole + buffer costs seconds once it has filled up, which is far too slow to + do after every action in an exploration. + """ + if clear: + self.adb("logcat", "-c", check=False) + return "" + args = ["logcat", "-d"] + if lines: + args += ["-t", str(lines)] + return self.adb(*args, timeout=120, check=False) + + # -- acting ----------------------------------------------------------- + + def tap(self, x: int, y: int) -> None: + self.shell(f"input tap {x} {y}") + + def tap_node(self, node: Node, screen: Optional[Screen] = None) -> None: + """Tap a node, or whatever clickable element really serves it.""" + target = screen.tap_target(node) if screen is not None else node + x, y = target.center + self.tap(x, y) + + def long_press(self, node: Node, ms: int = 800) -> None: + """Hold a finger on a node long enough for a long-press gesture. + + A zero-distance `input swipe` is what works: Compose's + `combinedClickable` sees it as a press that never moved. Moving even + two pixels turns it into a drag and the long press is cancelled, and + two separate `input motionevent` calls do not form one gesture at all + -- both were tried on a live transaction row, and only this registers. + """ + x, y = node.center + self.shell(f"input swipe {x} {y} {x} {y} {ms}") + + def type_text(self, s: str) -> None: + """Type into the focused field. + + "input text" maps each character through a KeyCharacterMap and throws + NullPointerException on anything it cannot map, so non-ASCII text goes + through the clipboard instead (which needs the sim build's SimHooks). + """ + if not s: + return + if not s.isascii() or len(s) > 200: + # Long strings are also pasted: "input text" sends them one + # keystroke at a time, which takes minutes for a few thousand + # characters and tests nothing extra. + self.paste_text(s) + return + # Shell-quote one chunk at a time; a space has to be a keyevent because + # "input text" splits its arguments on it. + for chunk in re.split(r"( )", s): + if not chunk: + continue + if chunk == " ": + self.shell("input keyevent 62") + else: + self.shell(f"input text {shlex.quote(chunk)}", check=False) + + def paste_text(self, s: str) -> None: + """Put text on the clipboard through SimHooks, then paste it.""" + res = self.shell( + f"am broadcast -a net.taler.wallet.sim.SET_CLIPBOARD " + f"-n {self.pkg}/net.taler.wallet.sim.SimHooks --es text {shlex.quote(s)}", + check=False, + ) + if "Broadcast completed" not in res: + raise RuntimeError( + f"clipboard hook unavailable (is this the fdroidSim APK?): {res.strip()[:200]}" + ) + self.shell("input keyevent KEYCODE_PASTE") + + def key(self, keycode: str) -> None: + self.shell(f"input keyevent {keycode}") + + def back(self) -> None: + self.key("KEYCODE_BACK") + + def size(self) -> tuple[int, int]: + """Current display size in pixels, cached per orientation.""" + if self._size is None: + out = self.shell("wm size") + m = re.search(r"Override size: (\d+)x(\d+)", out) or \ + re.search(r"Physical size: (\d+)x(\d+)", out) + w, h = (int(m.group(1)), int(m.group(2))) if m else (1080, 2400) + # wm size always reports the natural orientation, so swap when the + # device is rotated. + rotation = self.shell("settings get system user_rotation", + check=False).strip() + if rotation in ("1", "3"): + w, h = h, w + self._size = (w, h) + return self._size + + def scroll(self, down: bool = True, screen: Optional[Screen] = None) -> None: + """Swipe inside the scrollable area of the current screen. + + Fixed coordinates break as soon as the device is rotated or the layout + changes, so the gesture is derived from the scrollable node when there + is one and from the display size otherwise. + """ + width, height = self.size() + area = None + if screen is not None: + scrollables = [n for n in screen.nodes if n.scrollable and n.area > 0] + if scrollables: + area = max(scrollables, key=lambda n: n.area).bounds + if area is None: + area = (0, height // 8, width, height - height // 8) + x1, y1, x2, y2 = area + x = (x1 + x2) // 2 + near, far = y1 + (y2 - y1) // 6, y2 - (y2 - y1) // 6 + start, end = (far, near) if down else (near, far) + # 800 ms makes this a drag rather than a fling: a fling carries on + # under its own momentum and can scroll a whole row past the next dump. + self.shell(f"input swipe {x} {start} {x} {end} 800") + + def portrait(self) -> None: + """Undo any rotation left behind by an earlier episode. + + user_rotation is a system setting, so "pm clear" on the app does not + reset it and a landscape device silently invalidates every gesture + computed for portrait. + """ + self.shell("settings put system accelerometer_rotation 0") + self.shell("settings put system user_rotation 0") + self._size = None + + def rotate(self, landscape: bool) -> None: + self.shell("settings put system accelerometer_rotation 0") + self.shell(f"settings put system user_rotation {1 if landscape else 0}") + self._size = None + + # -- app lifecycle and entry points ----------------------------------- + + def launch(self) -> None: + self.shell(f"am start -W -n {ACTIVITY}", timeout=120) + + def stop(self) -> None: + self.shell(f"am force-stop {self.pkg}") + + def kill(self) -> None: + """Process death without a clean shutdown, to test state restoration.""" + self.shell(f"am kill {self.pkg}") + + def clear_data(self) -> None: + self.shell(f"pm clear {self.pkg}") + + def grant_camera(self) -> None: + """Re-grant the camera permission, which "pm clear" takes away.""" + self.shell(f"pm grant {self.pkg} android.permission.CAMERA", check=False) + + def send_uri(self, uri: str) -> None: + """Hand a Taler URI to the wallet. + + ACTION_SEND/text/plain is used rather than a VIEW intent because the + manifest's VIEW filter covers taler:// and payto:// but not the + taler+http:// form that a local http deployment hands out. + """ + self.shell( + "am start -a android.intent.action.SEND -t text/plain " + f"-n {ACTIVITY} --es android.intent.extra.TEXT {uri!r}", + timeout=120, + ) + + def send_ndef(self, uri: str) -> None: + """Deliver a URI the way a tapped NFC tag does. + + ACTION_NDEF_DISCOVERED carries its URI in a Parcelable NdefMessage, + which `am start` cannot build, so the sim build's SimHooks receiver + constructs it in-process. It deliberately leaves `intent.data` unset, + which is the branch MainActivity falls back to -- the one no scenario + had ever reached. + """ + self.shell( + f"am broadcast -a net.taler.wallet.sim.SEND_NDEF " + f"-n {self.pkg}/net.taler.wallet.sim.SimHooks --es uri {uri!r}", + timeout=120, + ) + + # -- waiting and convenience ------------------------------------------ + + def wait_for(self, pattern: str, timeout: int = 60, poll: float = 1.5) -> Screen: + """Poll the UI until some label matches, and return that screen. + + Raises TimeoutError with the last screen's labels attached, which is + what makes a failing scenario readable afterwards. + """ + deadline = time.monotonic() + timeout + last = Screen() + while time.monotonic() < deadline: + last = self.dump() + if last.find(pattern): + return last + time.sleep(poll) + raise TimeoutError( + f"no label matching {pattern!r} within {timeout}s; " + f"screen showed: {last.texts()}" + ) + + def tap_text(self, pattern: str, timeout: int = 30) -> Screen: + """Wait for a label, tap what serves it, and return that screen.""" + screen = self.wait_for(pattern, timeout=timeout) + node = screen.find(pattern) + if node is None: + # The screen changed between matching and tapping; say so plainly + # rather than failing with a bare assertion. + raise RuntimeError(f"{pattern!r} matched but was gone before the tap; " + f"screen now: {self.dump().texts()}") + self.tap_node(node, screen) + return screen + + def view_uri(self, uri: str) -> None: + """Deliver a URI the way a browser link or QR deep link would.""" + self.shell(f"am start -a android.intent.action.VIEW -d {uri!r}", timeout=120, check=False) + + +if __name__ == "__main__": + import sys + d = Device(sys.argv[1] if len(sys.argv) > 1 else "emulator-5554") + s = d.dump() + print(f"activity: {s.activity}") + print(f"nodes: {len(s.nodes)} labelled: {len(s.labelled())} " + f"tappable: {len(s.tappable())} editable: {len(s.editable())}") + print(s) + print("signature:", s.signature()[:200]) diff --git a/simulator/driver/episode.py b/simulator/driver/episode.py @@ -0,0 +1,255 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""One run of the simulator: actions in, artifacts and findings out. + +Every action is recorded in a form that can be replayed, which is what makes a +finding useful: the artifact directory holds the shortest sequence that still +reproduces it, not just a stack trace. Actions are addressed by label wherever +possible, because coordinates stop meaning anything as soon as a layout shifts. +""" + +from __future__ import annotations + +import json +import time +from dataclasses import asdict, dataclass, field +from pathlib import Path +from typing import Any, Optional + +import coverage as coverage_mod +import oracles +from device import Device, Screen +from wallet import Wallet + + +@dataclass +class Action: + """A replayable step.""" + + op: str + arg: Any = None + + def describe(self) -> str: + return f"{self.op}({self.arg!r})" if self.arg is not None else f"{self.op}()" + + +class Episode: + def __init__( + self, + dev: Device, + out_dir: str | Path, + name: str = "episode", + settle: float = 1.2, + coverage_dir: str | Path | None = None, + ): + self.dev = dev + self.app = Wallet(dev) + # Whatever has been exercised so far lives in the app process; a wipe + # takes it with it unless it is dumped first. + self.app.before_wipe = lambda: self.dump_coverage("before-wipe") + self.dir = Path(out_dir) / name + self.dir.mkdir(parents=True, exist_ok=True) + self.name = name + self.settle = settle + self.actions: list[Action] = [] + self.session = oracles.Session() + self.signatures: set[str] = set() + self.steps = 0 + self._shots = 0 + # JaCoCo data lives in the app process, so it has to be collected + # before anything kills it. + self.coverage_dir = Path(coverage_dir) if coverage_dir else None + self._dumps = 0 + self.dev.logcat(clear=True) + + # -- acting ----------------------------------------------------------- + + def perform(self, action: Action, screen: Optional[Screen] = None) -> None: + """Run one action, recording it first so a crash still leaves a trace.""" + self.actions.append(action) + self._write_actions() + op, arg = action.op, action.arg + if op == "tap_label": + current = screen or self.dev.dump() + target = current.find(f"^{_escape(arg)}$") or current.find(_escape(arg)) + if target is None: + return + before = current.signature() + # A random walk taps labels indiscriminately, and a label that is + # not a control legitimately changes nothing -- "Pending:", a + # timestamp, a section header. Only a tap that had something to + # hit can have failed silently. + resolved = current.tap_target(target) + interactive = resolved.clickable and resolved.enabled + self.dev.tap_node(target, current) + time.sleep(self.settle) + after = self.dev.dump() + if interactive: + fresh = self.session.add(oracles.silent_failure( + self.dev, str(arg), before, after.signature())) + for finding in fresh: + self._capture(finding, after, None) + elif op == "tap_xy": + self.dev.tap(arg[0], arg[1]) + elif op == "long_press_label": + target = (screen or self.dev.dump()).find(_escape(arg)) + if target is not None: + self.dev.long_press(target) + elif op == "type": + fields = (screen or self.dev.dump()).editable() + if fields: + self.dev.tap_node(fields[0], screen) + time.sleep(0.4) + self.dev.shell("input keyevent KEYCODE_MOVE_END") + for _ in range(24): + self.dev.shell("input keyevent KEYCODE_DEL") + self.dev.type_text(arg) + elif op == "scroll_down": + self.dev.scroll(down=True, screen=screen) + elif op == "scroll_up": + self.dev.scroll(down=False, screen=screen) + elif op == "back": + self.dev.back() + elif op == "rotate": + self.dev.rotate(landscape=bool(arg)) + elif op == "uri": + self.dev.send_uri(arg) + elif op == "view_uri": + self.dev.view_uri(arg) + elif op == "offline_blip": + self.dev.shell("cmd connectivity airplane-mode enable", check=False) + time.sleep(3) + self.dev.shell("cmd connectivity airplane-mode disable", check=False) + time.sleep(2) + elif op == "process_death": + self.dump_coverage("before-kill") + self.dev.kill() + time.sleep(1) + self.dev.launch() + elif op == "relaunch": + self.dump_coverage("before-relaunch") + self.dev.stop() + self.dev.launch() + elif op == "home_screen": + self.app.home() + else: + raise ValueError(f"unknown action {op}") + self.steps += 1 + time.sleep(self.settle) + + # -- observing -------------------------------------------------------- + + def observe(self, with_log: bool = True, + log_lines: int = 600) -> tuple[Screen, list[oracles.Finding]]: + """Read the screen, run the oracles, keep the evidence for anything new. + + Only the tail of the log is read: the whole buffer takes seconds once + it has filled, and the oracles are looking at what just happened. + """ + screen = self.dev.dump() + log = self.dev.logcat(lines=log_lines) if with_log else None + fresh = self.session.check(self.dev, screen=screen, log=log) + self.signatures.add(screen.signature()) + for finding in fresh: + self._capture(finding, screen, log) + return screen, fresh + + def _capture(self, finding: oracles.Finding, screen: Screen, log: Optional[str]) -> None: + stem = f"{finding.kind}-{finding.fingerprint}" + self._shots += 1 + try: + self.dev.screenshot(str(self.dir / f"{stem}.png")) + except Exception: + pass + payload = { + "finding": asdict(finding), + "fingerprint": finding.fingerprint, + "step": self.steps, + "screen": screen.texts(), + "signature": screen.signature(), + "actions": [asdict(a) for a in self.actions], + } + (self.dir / f"{stem}.json").write_text(json.dumps(payload, indent=2)) + if log: + (self.dir / f"{stem}.logcat.txt").write_text(log[-400_000:]) + + # -- finishing -------------------------------------------------------- + + def _write_actions(self) -> None: + (self.dir / "actions.json").write_text( + json.dumps([asdict(a) for a in self.actions], indent=2) + ) + + def dump_coverage(self, tag: str = "end") -> Optional[Path]: + """Collect execution data, if this is an instrumented build.""" + if self.coverage_dir is None: + return None + self._dumps += 1 + target = self.coverage_dir / f"{self.name}-{self._dumps:02d}-{tag}.ec" + try: + return coverage_mod.dump(self.dev, target, name=f"{tag}.ec") + except Exception as e: + print(f"coverage dump failed ({tag}): {e}") + return None + + def check_database(self) -> list[oracles.Finding]: + """Oracles that read the wallet database, not the screen. + + Done once per episode rather than per step: the database has to be + copied off the device, which is too slow for the action loop. + """ + found = oracles.background_failures(self.dev, keep_db_at=str(self.dir / "walletdb")) + found += oracles.unfinished_transactions(self.dev) + found += oracles.db_intact(self.dev) + fresh = self.session.add(found) + for finding in fresh: + self._capture(finding, self.dev.dump(), None) + return fresh + + def finish(self, extra: Optional[dict] = None) -> dict: + self.dump_coverage("end") + try: + self.check_database() + except Exception as e: + print(f"database oracle failed: {e}") + findings = list(self.session.findings.values()) + summary = { + "name": self.name, + "steps": self.steps, + "distinct_screens": len(self.signatures), + "findings": [asdict(f) | {"fingerprint": f.fingerprint} for f in findings], + "serious": len(self.session.serious()), + **(extra or {}), + } + (self.dir / "summary.json").write_text(json.dumps(summary, indent=2)) + # Keeping only the tail of the raw log loses the start of a chatty + # scenario, and with it whatever wallet-core operations ran early -- + # `coverage/operations.py` reads these files and reported + # updateExchangeEntry as never exercised although tapping "Reload + # information" calls it forty times. So the wallet's own lines are + # kept in full (they are what the oracles and the operation census + # read) and the rest of the system log keeps its tail. + log = self.dev.logcat() + mine = [l for l in log.splitlines() + if "taler-wallet" in l or "BackendManager" in l + or "SimHooks" in l] + (self.dir / "logcat.txt").write_text( + "\n".join(mine)[-4_000_000:] + "\n--- other tags, tail ---\n" + + log[-400_000:]) + return summary + + +def _escape(text: str) -> str: + import re + return re.escape(text) diff --git a/simulator/driver/explore.py b/simulator/driver/explore.py @@ -0,0 +1,213 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Random exploration of the wallet, biased towards screens not yet seen. + +A plain monkey spends its time on the main screen, so this keeps a count of +which labels it has already tapped in each screen signature and prefers the +untried ones. Environment actions — back, rotation, process death, a URI +arriving from outside — are mixed in at low rates, because they are where +state-restoration bugs live. + +The seed makes a run reproducible, but the authoritative record is still the +action log the episode writes: it replays even if the exploration policy +changes. +""" + +from __future__ import annotations + +import random +import sys +import time +from collections import Counter +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "corpus")) + +import oracles # noqa: E402 +import uris as corpus # noqa: E402 +from device import PKG, Device # noqa: E402 +from episode import Action, Episode # noqa: E402 +import scenarios # noqa: E402 +from stack import Env # noqa: E402 + +# Labels that end the session or throw away the wallet; reachable, but rarely, +# or exploration would spend its life on the first screen again. +DESTRUCTIVE = ( + "reset wallet", "delete wallet", "dangerously", "wipe", "logout", "log out", + "reset", "clear", +) +# Labels that lead out of the app entirely. +LEAVES_APP = ("authorize in bank", "export", "share", "save", "open in browser") + + +class Explorer: + def __init__(self, episode: Episode, seed: int = 0, allow_destructive: bool = False, + env=None): + self.ep = episode + self.rng = random.Random(seed) + self.allow_destructive = allow_destructive + self.tapped: dict[str, Counter] = {} + self.new_screens = 0 + self.uri_pool = list(corpus.all_uris().items()) + self.rng.shuffle(self.uri_pool) + self.env = env + # Steps since the walk last saw a screen it had not seen before. + self.stale = 0 + self.restarts = 0 + + def _pick_label(self, signature: str, labels: list[str]) -> str | None: + """Prefer a label never tapped on this screen before.""" + seen = self.tapped.setdefault(signature, Counter()) + usable = [ + label for label in labels + if (self.allow_destructive or not any(d in label.lower() for d in DESTRUCTIVE)) + and not any(x in label.lower() for x in LEAVES_APP) + ] + if not usable: + return None + fresh = [label for label in usable if seen[label] == 0] + choice = self.rng.choice(fresh or usable) + seen[choice] += 1 + return choice + + def refresh_state(self) -> None: + """Go back to a deep state when the walk stops finding anything new. + + A random walk settles into a few screens it can reach from wherever it + is; re-running a scenario setup puts it somewhere else entirely, which + is cheaper than waiting for chance to do it. + """ + import scenarios + if self.env is None: + return + choices = [scenarios.funded_and_paid, scenarios.fund_wallet, + lambda app, env: app.fresh_start(dev_mode=True)] + setup = self.rng.choice(choices) + self.restarts += 1 + self.ep.actions.append(Action("restart_state", setup.__name__ + if hasattr(setup, "__name__") else "fresh")) + try: + setup(self.ep.app, self.env) + except Exception as e: + print(f"could not refresh the state: {e}") + self.stale = 0 + + def step(self) -> None: + screen, _ = self.ep.observe() + # A tap can leave the app -- a KYC link opens Chrome, "Open in banking + # app" opens whatever handles payto -- and a random walk has no reason + # to find its way back, so a whole run can end up exploring a browser. + if screen.activity and not screen.activity.startswith(PKG): + self.ep.actions.append(Action("return_to_app", screen.activity[:60])) + self.ep.dev.launch() + time.sleep(4) + screen, _ = self.ep.observe() + signature = screen.signature() + if len(self.ep.signatures) > self.new_screens: + self.new_screens = len(self.ep.signatures) + self.stale = 0 + else: + self.stale += 1 + if self.stale >= 25: + self.refresh_state() + return + + roll = self.rng.random() + # An error sheet or a dead end: get out before doing anything else. + if screen.find(r"(?i)export error diagnostics") or not screen.labelled(): + self.ep.perform(Action("back"), screen) + return + if roll < 0.06: + self.ep.perform(Action("back"), screen) + return + if roll < 0.12: + self.ep.perform(Action("scroll_down" if self.rng.random() < 0.75 else "scroll_up"), + screen) + return + if roll < 0.14: + self.ep.perform(Action("rotate", self.rng.random() < 0.5), screen) + return + if roll < 0.16: + self.ep.perform(Action("process_death"), screen) + return + if roll < 0.175: + # Losing the network mid-operation is where retry logic shows its + # seams; it is turned back on immediately so the walk can continue. + self.ep.perform(Action("offline_blip"), screen) + return + if roll < 0.21 and self.uri_pool: + name, uri = self.uri_pool[self.ep.steps % len(self.uri_pool)] + self.ep.perform(Action("uri", uri), screen) + return + if roll < 0.33 and screen.editable(): + self.ep.perform(Action("type", self.rng.choice(corpus.TEXT_INPUTS)), screen) + return + + labels = [n.label.strip() for n in screen.tappable() if n.label.strip()] + label = self._pick_label(signature, labels) + if label is None: + self.ep.perform(Action("back"), screen) + return + self.ep.perform(Action("tap_label", label), screen) + + def run(self, steps: int) -> dict: + for i in range(steps): + try: + self.step() + except Exception as e: # keep exploring; the oracle records the state + self.ep.session.add([oracles.Finding("driver-error", f"{type(e).__name__}: {e}")]) + screen, _ = self.ep.observe() + return self.ep.finish({"new_screens": len(self.ep.signatures)}) + + +def main() -> int: + steps = int(sys.argv[1]) if len(sys.argv) > 1 else 60 + seed = int(sys.argv[2]) if len(sys.argv) > 2 else 1 + serial = sys.argv[3] if len(sys.argv) > 3 else "emulator-5554" + out = Path("/opt/taler-sim/run/out") + + dev = Device(serial) + ep = Episode(dev, out, name=f"explore-seed{seed}-{int(time.time())}", + coverage_dir=Path("/opt/taler-sim/run/coverage")) + # Start from a wallet that already holds coins and has paid once: most of + # the interesting screens do not exist in an empty wallet. + env = Env.load() + # Vary the starting point: a wallet with coins and a purchase behind it + # reaches different screens than an empty one, and both are worth walking. + setups = [ + ("funded_and_paid", scenarios.funded_and_paid), + ("fund_wallet", scenarios.fund_wallet), + ("fresh", lambda app, env: app.fresh_start(dev_mode=True)), + ] + name, setup = setups[seed % len(setups)] if seed % 4 else setups[0] + print(f"starting state: {name}") + try: + setup(ep.app, env) + except Exception as e: + print(f"warning: could not reach the {name} state ({e}); " + f"exploring from wherever the app is") + explorer = Explorer(ep, seed=seed, env=env) + summary = explorer.run(steps) + + print(f"steps: {summary['steps']} distinct screens: {summary['distinct_screens']}" + f" state refreshes: {explorer.restarts}") + print(f"findings: {len(summary['findings'])} ({summary['serious']} serious)") + for f in summary["findings"]: + print(f" [{f['kind']}] {f['detail'][:160]}") + print(f"artifacts: {ep.dir}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/simulator/driver/forever.sh b/simulator/driver/forever.sh @@ -0,0 +1,87 @@ +#!/bin/bash +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# Keep the campaign running without supervision. +# +# Each round: top the bank accounts up, run every scenario across the +# emulators, then explore at random with fresh seeds. Coverage is dumped after +# each phase and one line per round is appended to rounds.log, so progress can +# be read at a glance later. +# +# Usage: nohup ./forever.sh [first-round-number] > /opt/taler-sim/run/forever.log 2>&1 & +# Stop: touch /opt/taler-sim/run/STOP + +set -u + +HERE=$(cd "$(dirname "$0")" && pwd) +RUN=${SIM_RUN_DIR:-/opt/taler-sim/run} +ROUNDS_LOG="$RUN/rounds.log" +STOP="$RUN/STOP" +STEPS=${SIM_EXPLORE_STEPS:-120} +round=${1:-1} + +cd "$HERE" +mkdir -p "$RUN" + +log() { printf '%s round %s: %s\n' "$(date -Is)" "$round" "$*" | tee -a "$ROUNDS_LOG"; } + +while [ ! -e "$STOP" ]; do + log "starting" + + # Registration bonuses do not last; an empty bank account looks exactly + # like a wallet bug in the logs. + python3 stack.py > "$RUN/round$round-provision.log" 2>&1 || + log "provisioning failed, see round$round-provision.log" + + # Exploration first. It used to come after the suite, and a suite of 83 + # scenarios takes so long that a phase always set the STOP file first -- + # which breaks out of the loop here, so the random walks never ran at all. + # They are what found two of the findings, so they go before the queue. + seed=$((1000 + round * 10)) + python3 -u campaign.py explore --workers 4 --steps "$STEPS" --seed "$seed" \ + --tag "r${round}-explore" > "$RUN/round$round-explore.log" 2>&1 + found=$(grep -c '^ \[' "$RUN/round$round-explore.log" 2>/dev/null || echo 0) + log "explore: seed $seed, $STEPS steps/worker, $found finding lines" + + [ -e "$STOP" ] && break + + python3 -u campaign.py suite --workers 4 --tag "r${round}-suite" \ + > "$RUN/round$round-suite.log" 2>&1 + ok=$(grep -cE '^ [a-z_]+ ' "$RUN/round$round-suite.log" 2>/dev/null || echo 0) + bad=$(grep -cE '^ ! [a-z_]+ ' "$RUN/round$round-suite.log" 2>/dev/null || echo 0) + serious=$(grep -c '^ \*\*\*' "$RUN/round$round-suite.log" 2>/dev/null || echo 0) + log "suite: $ok ok, $bad driver errors, $serious serious findings" + + # Keep the on-device coverage from growing stale in case a later round + # restarts the app process. + python3 - <<'PY' >> "$RUN/round$round-coverage.log" 2>&1 +import coverage, time +from pathlib import Path +from device import Device +stamp = int(time.time()) +for worker in range(4): + try: + path = coverage.dump(Device(f"emulator-{5554 + 2 * worker}"), + Path(f"/opt/taler-sim/run/coverage/round-{stamp}-w{worker}.ec"), + name=f"round{stamp}w{worker}.ec") + print(f"worker {worker}: {path} ({path.stat().st_size} bytes)") + except Exception as e: + print(f"worker {worker}: {e}") +PY + log "coverage dumped" + round=$((round + 1)) +done + +log "stopped (STOP file present)" diff --git a/simulator/driver/matrix.py b/simulator/driver/matrix.py @@ -0,0 +1,182 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Run the platform-sensitive scenarios on every Android version the app supports. + +The campaign proper runs one image (the newest), which is the wrong shape for a +report like "scanning works on 15 but not on 14": a defect that depends on the +platform cannot be seen from a single platform. + +`wallet/build.gradle` says `minSdkVersion 24`, so the supported range is API +24 up to the compile target. Testing all thirteen is mostly waste -- what +matters are the levels where the app's own behaviour forks, and every entry in +API_LEVELS below names the code that makes it fork. + +One emulator at a time, because each wants 4 GB: + + python3 matrix.py # every level, the default subset + python3 matrix.py --apis 34 36 # just these two + python3 matrix.py --scenarios scan_manual_entry nfc_tap_to_pay + python3 matrix.py --keep # leave the last emulator running + +Results land in run/matrix-<stamp>.json and are printed as a table: one row per +scenario, one column per API level. +""" + +from __future__ import annotations + +import argparse +import json +import os +import subprocess +import sys +import time +from pathlib import Path + +HERE = Path(__file__).resolve().parent +SIM_ROOT = Path(os.environ.get("SIM_ROOT", "/opt/taler-sim")) +RUN = Path(os.environ.get("SIM_RUN_DIR", SIM_ROOT / "run")) +APK = Path(os.environ.get("SIM_APK", SIM_ROOT / "apk" / "wallet.apk")) +EMU = SIM_ROOT / "emu" / "emu.sh" + +# The worker index the matrix borrows. It is past the campaign's four and past +# the scratch worker, so a matrix run and a campaign round can coexist. +MATRIX_WORKER = int(os.environ.get("SIM_MATRIX_WORKER", "6")) + +# Why each level is in the list. Keep the reason with the number: without it +# the list grows by superstition. +API_LEVELS: dict[int, str] = { + 24: "minSdkVersion -- the oldest the app claims to run on", + 26: "TalerUtils.kt:29 branches below 26", + 28: "SettingsScreen.kt:562 branches at P", + 29: "Utils.kt:70 and AndroidUtils.kt:109 branch at 29 (scoped storage)", + 30: "MainActivity.kt:301 and SettingsScreen.kt:507,554 branch at R", + 31: "Theme.kt:158 takes dynamic colour from S", + 33: "MainActivity.kt:360 reads NDEF the TIRAMISU way; per-app language", + 34: "Amount.kt:256 formats with the monetary grouping separator from 34", + 36: "the compile target, and what the campaign runs", +} + +# The scenarios whose outcome can plausibly depend on the platform: anything +# touching the camera, NFC, storage, locale, biometrics or the window manager, +# plus enough of a money path to notice a wallet that cannot work at all. +DEFAULT_SCENARIOS = [ + "balances_screens", + "history", + "scan_manual_entry", + "nfc_tap_to_pay", + "settings_walk", + "settings_export", + "settings_import", + "config_changes", + "wallet_lock_without_credential", + "a11y_audit", + "lifecycle_kill", + "db_corruption", +] + + +def run(cmd: list[str], **kw) -> subprocess.CompletedProcess: + return subprocess.run(cmd, text=True, capture_output=True, **kw) + + +def emu(action: str, *args: str, api: int | None = None, timeout: int = 900): + env = dict(os.environ) + if api is not None: + env["SIM_SYSTEM_IMAGE"] = f"system-images;android-{api};google_apis;x86_64" + return subprocess.run( + [str(EMU), action, str(MATRIX_WORKER), *args], + text=True, capture_output=True, env=env, timeout=timeout, + ) + + +def boot(api: int) -> str: + """Create, boot and prepare one emulator on this API level.""" + serial = f"emulator-{5554 + 2 * MATRIX_WORKER}" + print(f" creating an API {api} emulator ...", flush=True) + made = emu("create", api=api) + if made.returncode != 0: + raise RuntimeError(f"could not create the AVD: {made.stderr.strip()[:300]}") + print(f" booting {serial} ...", flush=True) + booted = emu("boot", api=api, timeout=1200) + if booted.returncode != 0: + raise RuntimeError(f"could not boot: {booted.stderr.strip()[:300]}") + prepared = emu("prepare", str(APK), api=api, timeout=900) + if prepared.returncode != 0: + raise RuntimeError(f"could not prepare: {prepared.stderr.strip()[:300]}") + return serial + + +def scenarios_on(api: int, scenarios: list[str], timeout: int) -> dict: + """Run the subset and return each scenario's status.""" + env = dict(os.environ, SIM_WORKER=str(MATRIX_WORKER)) + log = RUN / f"matrix-api{api}.log" + with open(log, "w") as out: + proc = subprocess.run( + [sys.executable, "-u", str(HERE / "suite.py"), *scenarios], + text=True, stdout=out, stderr=subprocess.STDOUT, + env=env, cwd=HERE, timeout=timeout, + ) + results: dict[str, str] = {} + for line in log.read_text(errors="replace").splitlines(): + parts = line.split() + if len(parts) >= 2 and parts[0] in scenarios: + results[parts[0]] = parts[1] + return {"exit": proc.returncode, "log": str(log), "scenarios": results} + + +def main() -> int: + ap = argparse.ArgumentParser(description=__doc__) + ap.add_argument("--apis", nargs="*", type=int, default=sorted(API_LEVELS), + help="API levels to run (default: all of them)") + ap.add_argument("--scenarios", nargs="*", default=DEFAULT_SCENARIOS) + ap.add_argument("--timeout", type=int, default=5400, + help="seconds for one level's scenarios") + ap.add_argument("--keep", action="store_true", + help="leave the last emulator running") + args = ap.parse_args() + + stamp = int(time.time()) + out_path = RUN / f"matrix-{stamp}.json" + report: dict = {"stamp": stamp, "scenarios": args.scenarios, "levels": {}} + + for api in args.apis: + print(f"=== API {api}: {API_LEVELS.get(api, 'no reason recorded')}", flush=True) + try: + boot(api) + report["levels"][api] = scenarios_on(api, args.scenarios, args.timeout) + except Exception as e: # noqa: BLE001 + print(f" !! {e}", flush=True) + report["levels"][api] = {"error": str(e)[:400], "scenarios": {}} + finally: + if not (args.keep and api == args.apis[-1]): + emu("kill", api=api, timeout=120) + out_path.write_text(json.dumps(report, indent=2)) + + # One row per scenario, one column per level: a difference between columns + # is the thing this exists to find. + levels = [a for a in args.apis if a in report["levels"]] + width = max((len(s) for s in args.scenarios), default=10) + 2 + print("\n" + "scenario".ljust(width) + "".join(f"{a:>7}" for a in levels)) + for name in args.scenarios: + row = "".join( + f"{report['levels'][a]['scenarios'].get(name, '-')[:6]:>7}" + for a in levels + ) + print(name.ljust(width) + row) + print(f"\n{out_path}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/simulator/driver/oracles.py b/simulator/driver/oracles.py @@ -0,0 +1,488 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""What counts as a failure. + +An ordinary error is not a finding: the wallet is supposed to refuse a stale +order or a malformed URI, and say so. A finding is the app breaking its own +contract — a crash, an ANR, an error that wallet-core itself calls unexpected +or an invariant failure, a transaction that never leaves a pending state, or a +database that no longer opens. +""" + +from __future__ import annotations + +import hashlib +import json +import re +import time +from dataclasses import dataclass, field +from pathlib import Path +from typing import Iterable, Optional + +from device import PKG, Device, Screen + +# Error codes that mean "this should not have happened" rather than "your +# request was bad"; see wallet/src/main/java/net/taler/wallet/backend/ +# TalerErrorCode.kt. +INTERNAL_CODES = { + 2, # GENERIC_CLIENT_INTERNAL_ERROR + 56, # GENERIC_DB_INVARIANT_FAILURE + 60, # GENERIC_INTERNAL_INVARIANT_FAILURE + 7001, # WALLET_UNEXPECTED_EXCEPTION + 7007, # WALLET_CORE_API_OPERATION_UNKNOWN + 7047, # WALLET_TRANSACTION_PROTOCOL_VIOLATION + 7048, # WALLET_CORE_API_BAD_REQUEST +} + +CRASH_PATTERNS = ( + ("crash", re.compile(r"FATAL EXCEPTION")), + ("anr", re.compile(r"ANR in ")), + ("native-crash", re.compile(r"\*\*\* \*\*\* \*\*\*|signal \d+ \(SIG")), + ("core-internal", re.compile(r"(?i)unexpected exception|invariant (failure|violated)" + r"|unhandled (promise )?rejection|assertion failed")), + ("core-unreachable", re.compile(r"(?i)refusing to run a second wallet-core")), +) + +# The wallet's error bottom sheet always offers this; it is the cheapest marker +# that the screen on display is an error screen at all. +ERROR_SHEET_MARKER = re.compile(r"(?i)export error diagnostics") +# \bbug\b matters: without the word boundaries this matched the "debug" in +# the application id of every URI the wallet quoted back in an error message. +INTERNAL_TEXT = re.compile( + r"(?i)internal error|invariant|unexpected|assertion|\bbug\b" + r"|NullPointer|[A-Za-z]+Exception\b" +) + + +# Kinds that describe the wallet behaving reasonably (refusing bad input, +# waiting for a counterparty) rather than a defect. +INFORMATIONAL = {"error-screen", "unfinished-transaction", "harness-crash"} + + +@dataclass(frozen=True) +class Finding: + kind: str + detail: str + evidence: str = "" + + @property + def fingerprint(self) -> str: + """Dedup key: the same bug found twice should collapse to one entry.""" + # Strip ids, amounts, timestamps and addresses so that two instances of + # the same defect hash alike. + norm = re.sub(r"[0-9A-Z]{20,}", "<ID>", self.detail) + norm = re.sub(r"\b\d+\b", "#", norm) + norm = re.sub(r"0x[0-9a-f]+", "<ADDR>", norm) + return hashlib.sha256(f"{self.kind}|{norm}".encode()).hexdigest()[:16] + + def __str__(self) -> str: + return f"[{self.kind}] {self.detail}" + + +def from_logcat(log: str, pkg: str = PKG) -> list[Finding]: + """Crashes, ANRs and wallet-core's own internal errors. + + A crash is only the app's when the trace says so: `uiautomator dump` + itself dies with "UiAutomationService … already registered!" whenever two + dumps overlap, and that is the driver's problem, not the wallet's. + """ + out: list[Finding] = [] + lines = log.splitlines() + for kind, pattern in CRASH_PATTERNS: + for i, line in enumerate(lines): + if not pattern.search(line): + continue + # A stack trace's first frames identify the defect far better + # than the header line does. + context = "\n".join(lines[i:i + 12]) + if kind in ("crash", "native-crash") and pkg not in context: + out.append(Finding("harness-crash", + f"not the app: {line.strip()[:200]}", context)) + continue + out.append(Finding(kind, line.strip()[:400], context)) + for m in re.finditer(r'"code"\s*:\s*(\d+)', log): + code = int(m.group(1)) + if code in INTERNAL_CODES: + start = max(0, m.start() - 300) + out.append(Finding("internal-error-code", f"wallet-core returned code {code}", + log[start:m.end() + 300])) + return out + + +def from_screen(screen: Screen) -> list[Finding]: + """Error screens that look like a bug rather than a refusal.""" + texts = screen.texts() + joined = " | ".join(texts) + if not any(ERROR_SHEET_MARKER.search(t) for t in texts): + return [] + message = next((t for t in texts + if not ERROR_SHEET_MARKER.search(t) + and t.lower() not in ("error", "copy", "share", "close", + "drag handle", "close sheet")), "") + if INTERNAL_TEXT.search(joined): + return [Finding("internal-error-screen", message[:400] or joined[:400], joined)] + # A plain error sheet is recorded, but only as information: whether it is + # legitimate depends on what the scenario was trying to do. + return [Finding("error-screen", message[:400] or joined[:400], joined)] + + +# Text that should never reach a user. +SANITY_PATTERNS = ( + ("placeholder-leak", re.compile(r"%[0-9]+\$[sd]|%s\b|%d\b")), + ("null-leak", re.compile(r"(?<![A-Za-z])(null|undefined|NaN|Infinity)(?![A-Za-z])")), + ("exception-leak", re.compile(r"java\.lang\.|kotlin\.[A-Za-z]+Exception|" + r"[A-Za-z]+Exception:")), + # A word stuck to a number, like "UNKNOWN0.00" or "EUR1.00": a currency + # symbol that is a word, formatted as if it were a sign. + ("glued-currency", re.compile(r"(?:^|[\s:])[A-Z]{3,}\d+[.,]\d\d(?:$|\s)")), +) +# Labels that legitimately contain such words: the developer-mode error sheet +# and the JSON viewer render raw wallet-core payloads, nulls and all. +SANITY_EXEMPT = re.compile( + r"(?i)export error diagnostics|show json|internal event log" + r'|^\s*[\{\[]|"\s*:' +) + + +def screen_sanity(screen: Screen) -> list[Finding]: + """Rendering that is obviously wrong, whatever the screen is for. + + An unsubstituted format string, a stray "null", a stack-trace class name or + a currency word glued to a number are all defects no matter which flow + produced them, and they are cheap to notice on every dump. + """ + out: list[Finding] = [] + for text in screen.texts(): + label = text.strip() + if not label or SANITY_EXEMPT.search(label): + continue + for kind, pattern in SANITY_PATTERNS: + if pattern.search(label): + out.append(Finding(kind, f"{label[:160]!r} on {screen.activity}", + " | ".join(screen.texts())[:800])) + break + return out + + +# A transaction that never happened cannot have cost a fee. The fee row on +# every credit screen is the difference between the raw and the effective +# amount, and an aborted or failed transaction has an effective amount of +# zero, so the difference becomes the whole amount. +DEAD_STATE = re.compile(r"(?i)was aborted|has failed|has expired|been abandoned") + + +def fee_on_a_dead_transaction(screen: Screen) -> list[Finding]: + """A fee shown on a transaction that did not happen.""" + texts = screen.texts() + if not any(DEAD_STATE.search(t) for t in texts): + return [] + if not any(t.strip().lower() == "fee" for t in texts): + return [] + return [Finding( + "fee-on-dead-transaction", + f"a fee is shown on a transaction that did not happen, on {screen.activity}", + " | ".join(texts)[:800], + )] + + +# A screen that states an absence -- no accounts, no contacts, nothing to send +# -- while the log says the query behind it failed. Found by hand first (see +# findings/a-failed-query-is-shown-as-an-empty-wallet.md); this is the general +# shape of it. +ABSENCE_CLAIM = re.compile( + r"(?i)^No [a-z ]*(accounts|contacts|transactions|payment services|" + r"methods|statements)|^No [a-z ]+ (yet|saved)[.!]?$" +) +FAILED_QUERY = re.compile( + r'Error (?:retrieving )?(get|list)[A-Za-z]+' + r'|"operation"\s*:\s*"(get|list)[A-Za-z]+"' +) + + +def absence_after_error(screen: Screen, log: Optional[str]) -> list[Finding]: + """An empty state shown while the query behind it was failing.""" + if not log: + return [] + claims = [t for t in screen.texts() if ABSENCE_CLAIM.search(t.strip())] + if not claims: + return [] + failures = [l for l in log.splitlines() + if FAILED_QUERY.search(l) and ('"error"' in l or "Error " in l)] + if not failures: + return [] + return [Finding( + "absence-after-error", + f"{claims[0][:80]!r} while a query was failing, on {screen.activity}", + "\n".join(failures[-3:])[:600] + "\n--\n" + " | ".join(screen.texts())[:400], + )] + + +# Amounts rendered both with and without their currency specification on the +# same screen: "5.00 EUR" beside "€4.88" reads like two currencies. +AMOUNT_UNSPECCED = re.compile(r"(?:^|\s)\d+[.,]\d\d\s+[A-Z]{3,}(?:$|\s)") +AMOUNT_SPECCED = re.compile(r"[€$£¥₹]\s?\d+(?:[.,]\d+)?") + + +def mixed_amount_notation(screen: Screen) -> list[Finding]: + """Two notations for money on one screen.""" + texts = screen.texts() + plain = [m.group(0).strip() for t in texts + for m in [AMOUNT_UNSPECCED.search(t)] if m] + symbol = [m.group(0).strip() for t in texts + for m in [AMOUNT_SPECCED.search(t)] if m] + if not (plain and symbol): + return [] + # The two notations are often in the *same* sentence ("transfer 5.00 EUR + # ... to receive EUR4.88"), so name the amounts rather than their nodes: + # quoting whole nodes made the finding read as the same text twice. + return [Finding( + "mixed-amount-notation", + f"{plain[0]!r} beside {symbol[0]!r} on {screen.activity}", + " | ".join(texts)[:700], + )] + + +def blank_screen(screen: Screen) -> list[Finding]: + """A screen with nothing to read and nothing to tap is a dead end.""" + if not screen.nodes: + return [Finding("empty-hierarchy", "no view hierarchy returned")] + if not screen.labelled() and not screen.tappable(): + return [Finding("blank-screen", f"{len(screen.nodes)} nodes, none labelled or tappable")] + return [] + + +# Retry counters above this mean wallet-core has given up repeatedly on the +# same operation. +STUCK_RETRIES = 4 + + +def background_failures(dev: Device, keep_db_at: Optional[str] = None) -> list[Finding]: + """Operations failing where the UI never looks. + + wallet-core keeps one `operation_retries` row per retried operation, with + the last error and a retry counter. A row with an error is a failure the + user may never be shown; an error with an internal code is a defect, and a + high retry counter is an operation that is not getting anywhere. + """ + import dbprobe + + out: list[Finding] = [] + try: + db = dbprobe.pull(dev, Path(keep_db_at) if keep_db_at else None) + if not dbprobe.has_native_schema(db): + # A wallet on the legacy IndexedDB-emulation backend keeps its + # records in object_data, not in tables this oracle can read. + # That is a state the wallet can legitimately be in -- see + # db_migration_prompt -- so there is nothing to report rather than + # an oracle failure. + return [] + rows = dbprobe.rows(db, "select id, last_error, retry_info from operation_retries") + except Exception as e: + return [Finding("oracle-error", f"could not read the wallet database: {e}")] + for row in rows: + op = row["id"] + error = row["last_error"] + if error: + try: + info = json.loads(error) + except (json.JSONDecodeError, TypeError): + info = {} + code = info.get("code") + hint = str(info.get("hint") or info.get("message") or error)[:300] + kind = ("background-internal-error" if code in INTERNAL_CODES + else "background-error") + out.append(Finding(kind, f"{op}: code {code}: {hint}", error[:2000])) + try: + retries = json.loads(row["retry_info"] or "{}").get("retryCounter", 0) + except (json.JSONDecodeError, TypeError): + retries = 0 + if retries >= STUCK_RETRIES: + out.append(Finding("stuck-operation", + f"{op}: retried {retries} times", str(dict(row))[:1000])) + return out + + +# Tables that record one long-running operation each, with the column that +# says when it finished. +OPERATION_TABLES = { + "withdrawal_groups": ("withdrawal_group_id", "timestamp_start", "timestamp_finish"), + "refresh_groups": ("refresh_group_id", "timestamp_created", "timestamp_finished"), + "deposit_groups": ("deposit_group_id", "timestamp_created", "timestamp_finished"), +} + + +def unfinished_transactions(dev: Device, older_than: int = 240) -> list[Finding]: + """Operations that started a while ago and never finished. + + Advisory rather than damning: a suspended or aborted transaction is + legitimately unfinished, and so is one waiting for the bank. What makes it + worth printing is the pattern — the same operation unfinished across runs + that should have completed it. + """ + import dbprobe + + out: list[Finding] = [] + try: + db = dbprobe.pull(dev) + except Exception as e: + return [Finding("oracle-error", f"could not read the wallet database: {e}")] + if not dbprobe.has_native_schema(db): + return [] + now_us = time.time() * 1_000_000 + for table, (key, started, finished) in OPERATION_TABLES.items(): + try: + rows = dbprobe.rows( + db, f"select {key} as id, {started} as started, {finished} as finished, " + f"status from {table}") + except Exception: + continue + for row in rows: + if row["finished"]: + continue + start = row["started"] + if not isinstance(start, (int, float)): + continue + age = (now_us - float(start)) / 1_000_000 + if age > older_than: + out.append(Finding( + "unfinished-transaction", + f"{table} {str(row['id'])[:24]} unfinished after {age:.0f}s " + f"(status {row['status']})", + str(dict(row))[:500], + )) + return out + + +# Lines that mean wallet-core refused or failed an operation the UI asked for. +# Deliberately narrow: any "E taler-wallet" line also matches background +# chatter that has nothing to do with the tap being judged. +TAIL_ERROR = re.compile( + r'"type"\s*:\s*"error"\s*,\s*"operation"' + r"|got \w+ error" + r"|FATAL EXCEPTION" +) + + +LOGCAT_STAMP = re.compile(r"^(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)\.(\d+)") + + +def recent_lines(log: str, seconds: float = 6.0) -> list[str]: + """Log lines written within the last few seconds. + + logcat has no "since my last read" option, so the timestamps are compared + against the wall clock. The device and the host share it closely enough + for a window this wide. + """ + now = time.localtime() + cutoff = time.time() - seconds + out = [] + for line in log.splitlines(): + m = LOGCAT_STAMP.match(line) + if not m: + continue + month, day, hour, minute, second = (int(m.group(i)) for i in range(1, 6)) + stamp = time.mktime((now.tm_year, month, day, hour, minute, second, + 0, 0, now.tm_isdst)) + if stamp >= cutoff: + out.append(line) + return out + + +def silent_failure(dev: Device, label: str, before: str, after: str, + lines: int = 200) -> list[Finding]: + """A primary action that did nothing, while the log says it failed. + + This is the shape of the first defect the simulator found: tapping "Treat + as global" sent a malformed request, wallet-core rejected it, and the user + saw nothing at all. Comparing the screen before and after a tap catches + the whole class. + """ + if before != after: + return [] + # Only the app's own screens: a random walk taps around in Chrome too, and + # "tapping 'Sign in' changed nothing" is not a finding about the wallet. + activity = dev.dump().activity + if activity and not activity.startswith(PKG): + return [] + tail = dev.adb("logcat", "-d", "-t", str(lines), check=False) + fresh = "\n".join(recent_lines(tail)) + errors = [ln for ln in fresh.splitlines() if TAIL_ERROR.search(ln)] + if not errors: + return [] + codes = sorted({int(m.group(1)) for m in re.finditer(r'"code"\s*:\s*(\d+)', fresh)}) + internal = [c for c in codes if c in INTERNAL_CODES] + kind = "silent-internal-failure" if internal else "silent-failure" + return [Finding( + kind, + f"tapping {label!r} changed nothing on screen while the log reported " + f"an error (codes {codes or 'none'})", + "\n".join(errors[-8:])[:2000], + )] + + +def db_intact(dev: Device, pkg: Optional[str] = None) -> list[Finding]: + """Ask sqlite whether the wallet database still checks out.""" + from device import PKG + pkg = pkg or PKG + out = dev.shell( + f"run-as {pkg} sqlite3 files/talerwalletdb.sqlite3 'PRAGMA integrity_check;'", + check=False, + ).strip() + if not out: + # No sqlite3 on the image, or no database yet: not a finding. + return [] + if out.splitlines()[-1].strip() != "ok": + return [Finding("db-corrupt", out[:400])] + return [] + + +@dataclass +class Session: + """Collects findings over an episode, deduplicated.""" + + findings: dict[str, Finding] = field(default_factory=dict) + + def add(self, found: Iterable[Finding]) -> list[Finding]: + fresh = [] + for f in found: + if f.fingerprint not in self.findings: + self.findings[f.fingerprint] = f + fresh.append(f) + return fresh + + def check(self, dev: Device, screen: Optional[Screen] = None, + log: Optional[str] = None) -> list[Finding]: + found: list[Finding] = [] + # Screen oracles only apply to the app's own screens. A random walk + # leaves the wallet now and then -- a KYC link opens Chrome -- and + # Chrome's search suggestions are full of the words these oracles look + # for ("undefined behavior", "null"), which is 16 findings of pure + # noise in a 120-step walk. + if screen is not None and screen.activity and not screen.activity.startswith(PKG): + screen = None + if screen is not None: + found += from_screen(screen) + found += blank_screen(screen) + found += screen_sanity(screen) + found += fee_on_a_dead_transaction(screen) + found += mixed_amount_notation(screen) + if log is not None: + found += absence_after_error(screen, log) + if log is not None: + found += from_logcat(log) + return self.add(found) + + def serious(self) -> list[Finding]: + """Everything except what only describes the wallet refusing or waiting.""" + return [f for f in self.findings.values() if f.kind not in INFORMATIONAL] diff --git a/simulator/driver/phase.sh b/simulator/driver/phase.sh @@ -0,0 +1,105 @@ +#!/bin/bash +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# Run a set of scenarios against a different stack, then put the default stack +# back and resume the rounds. +# +# ./phase.sh sim-kyc.conf kyc_withdraw_trips_rule kyc_transaction_actions +# ./phase.sh sim-twister.conf twister_withdraw_faults twister_field_faults +# +# Only one stack can run at a time (the exchange's secmod sockets are shared), +# so this stops the unattended loop first and restarts it afterwards at the +# next round number. + +set -u + +HERE=$(cd "$(dirname "$0")" && pwd) +RUN=${SIM_RUN_DIR:-/opt/taler-sim/run} +BACKEND="$HERE/../backend" +CONF=${1:?usage: phase.sh <config> <scenario>...} +shift +SCENARIOS=("$@") +[ "${#SCENARIOS[@]}" -gt 0 ] || { echo "no scenarios given" >&2; exit 2; } +TAG=${SIM_PHASE_TAG:-phase-${CONF%.conf}-$(date +%s)} + +say() { printf '%s phase %s: %s\n' "$(date -Is)" "$TAG" "$*" | tee -a "$RUN/rounds.log"; } + +# 1. Pause the unattended loop and wait for the round in flight to end. +say "pausing the rounds" +touch "$RUN/STOP" +# A round is an exploration pass plus every scenario, which is well over an +# hour now; waiting only 40 minutes meant the stack was swapped *under* a +# running round, which corrupts both it and the phase. Three hours, and if a +# campaign is still running after that, do not swap the stack at all. +for _ in $(seq 1 1080); do + pgrep -f "python3 -u campaign.py" >/dev/null || break + sleep 10 +done +if pgrep -f "python3 -u campaign.py" >/dev/null; then + say "a campaign is STILL running after three hours; not swapping the stack" + rm -f "$RUN/STOP" + exit 1 +fi + +# 2. Swap the stack. +say "starting the stack from $CONF" +(cd "$BACKEND" && ./stack.sh stop >/dev/null 2>&1) +if ! (cd "$BACKEND" && SIM_CONF="$CONF" ./stack.sh start > "$RUN/$TAG-stack.log" 2>&1); then + say "the stack would not start from $CONF; see $TAG-stack.log" + tail -15 "$RUN/$TAG-stack.log" >&2 + (cd "$BACKEND" && ./stack.sh start >/dev/null 2>&1) && say "default stack restored" + python3 "$HERE/stack.py" > "$RUN/$TAG-provision.log" 2>&1 || true + for w in 0 1 2 3 4; do + "$HERE/../emu/emu.sh" reverse "$w" >> "$RUN/$TAG-reverse.log" 2>&1 || true + done + # The rounds must carry on even when a variant will not start, or a failed + # phase silently ends the campaign. + rm -f "$RUN/STOP" + NEXT=$(( $(grep -c 'round .*: starting' "$RUN/rounds.log" 2>/dev/null || echo 5) + 5 )) + say "resuming rounds at $NEXT after the failed phase" + nohup setsid "$HERE/forever.sh" "$NEXT" > "$RUN/forever-after-$TAG.log" 2>&1 < /dev/null & + exit 1 +fi +python3 "$HERE/stack.py" > "$RUN/$TAG-provision.log" 2>&1 || say "provisioning complained" + +# The variant may serve on a port the emulators have never had mapped (the +# twister proxy, for one), and adb reverse only knows what it was told. +for w in 0 1 2 3 4; do + "$HERE/../emu/emu.sh" reverse "$w" >> "$RUN/$TAG-reverse.log" 2>&1 || true +done +say "re-mapped the stack ports into the emulators" + +# 3. Run the scenarios across the workers. +say "running ${SCENARIOS[*]}" +python3 -u "$HERE/campaign.py" suite --workers 4 --tag "$TAG" \ + --only "${SCENARIOS[@]}" > "$RUN/$TAG.log" 2>&1 +ok=$(grep -cE '^ [a-z_]+ ' "$RUN/$TAG.log" 2>/dev/null || echo 0) +bad=$(grep -cE '^ ! [a-z_]+ ' "$RUN/$TAG.log" 2>/dev/null || echo 0) +serious=$(grep -c '^ \*\*\*' "$RUN/$TAG.log" 2>/dev/null || echo 0) +say "$ok ok, $bad driver errors, $serious serious findings (see $TAG.log)" + +# 4. Put the default stack back and let the rounds continue. +say "restoring the default stack" +(cd "$BACKEND" && ./stack.sh stop >/dev/null 2>&1) +(cd "$BACKEND" && ./stack.sh start > "$RUN/$TAG-restore.log" 2>&1) || + say "WARNING: the default stack did not come back; see $TAG-restore.log" +python3 "$HERE/stack.py" >> "$RUN/$TAG-provision.log" 2>&1 +for w in 0 1 2 3 4; do + "$HERE/../emu/emu.sh" reverse "$w" >> "$RUN/$TAG-reverse.log" 2>&1 || true +done +rm -f "$RUN/STOP" +NEXT=$(( $(grep -c 'round .*: starting' "$RUN/rounds.log" 2>/dev/null || echo 5) + 5 )) +say "resuming rounds at $NEXT" +nohup setsid "$HERE/forever.sh" "$NEXT" > "$RUN/forever-after-$TAG.log" 2>&1 < /dev/null & diff --git a/simulator/driver/probe.py b/simulator/driver/probe.py @@ -0,0 +1,98 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Poke at a running wallet one step at a time, printing what each step shows. + +Label discovery is most of the work in writing a scenario, and guessing from +source is slower than looking. Each invocation performs one action and dumps +the resulting screen. + + python3 probe.py dump + python3 probe.py tap Request + python3 probe.py fill 1 + python3 probe.py back + python3 probe.py uri 'taler+http://pay/...' + SIM_SERIAL=emulator-5556 python3 probe.py dump +""" + +from __future__ import annotations + +import os +import sys +import time + +from device import Device +from wallet import Wallet + + +def show(dev: Device) -> None: + screen = dev.dump() + print(f"activity: {screen.activity}") + for node in screen.labelled(): + print(f" {node}") + fields = screen.editable() + print(f"editable fields: {len(fields)}") + for node in fields: + print(f" FIELD {node}") + + +def main() -> int: + serial = os.environ.get("SIM_SERIAL", "emulator-5554") + dev = Device(serial) + app = Wallet(dev) + args = sys.argv[1:] or ["dump"] + op, rest = args[0], args[1:] + + if op == "dump": + pass + elif op == "home": + app.home() + elif op == "tap": + dev.tap_text(rest[0], timeout=20) + time.sleep(1.5) + elif op == "fill": + screen = dev.dump() + fields = screen.editable() + index = int(rest[1]) if len(rest) > 1 else 0 + if len(fields) <= index: + print(f"no editable field {index} (found {len(fields)})") + return 1 + dev.tap_node(fields[index]) + time.sleep(0.5) + dev.type_text(rest[0]) + time.sleep(1.5) + elif op == "back": + dev.back() + time.sleep(1.2) + elif op == "scroll": + dev.scroll(down=(not rest or rest[0] != "up"), screen=dev.dump()) + time.sleep(1.2) + elif op == "uri": + app.handle_uri(rest[0]) + time.sleep(2) + elif op == "settings": + app.open_settings() + elif op == "fresh": + app.fresh_start(dev_mode=True) + elif op == "enter": + dev.key("KEYCODE_ENTER") + time.sleep(1.5) + else: + print(__doc__) + return 2 + show(dev) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/driver/qrsuite.py b/simulator/driver/qrsuite.py @@ -0,0 +1,230 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Decode real QR images with the app, through its own scan screen. + +Everything else in the simulator hands URIs to the app as shared text, which +skips the decoder entirely. Here the payload is rendered to a PNG with +`qrencode`, pushed into the device's gallery and picked with the scan screen's +"Scan from gallery", so the image decoder and everything downstream of it run +for real. + +The live camera was tried first and does not work unattended: the emulator's +virtual scene hangs its poster on a wall that is rotated away from the default +camera pose (`Toren1BD.posters`: `rotation 0 -150 0`), and the pose cannot be +moved from outside. `--camera` keeps that path available for a human to watch. + + python3 qrsuite.py --worker 4 + python3 qrsuite.py --worker 4 --only valid_withdraw malformed_base32 +""" + +from __future__ import annotations + +import argparse +import json +import subprocess +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "corpus")) + +import oracles # noqa: E402 +import uris as corpus # noqa: E402 +from device import Device # noqa: E402 +from episode import Episode # noqa: E402 +from stack import Bank, Env, Merchant # noqa: E402 +from wallet import Wallet # noqa: E402 + +EMU = Path("/opt/taler-sim/emu/emu.sh") +POSTERS = Path("/opt/taler-sim/run/posters") +OUT = Path("/opt/taler-sim/run/out") +COVERAGE = Path("/opt/taler-sim/run/coverage") + + +def render(payload: str, name: str) -> Path: + """Make a QR poster. Large modules, because the camera sees it from afar.""" + POSTERS.mkdir(parents=True, exist_ok=True) + path = POSTERS / f"{name}.png" + subprocess.run( + ["qrencode", "-s", "20", "-m", "2", "-l", "L", "-o", str(path), payload], + check=True, timeout=60, + ) + return path + + +def payloads(env: Env) -> dict[str, str]: + """What to put on the wall. + + The valid entries point at live services but at identifiers that do not + exist, so no funds are needed: reaching the prompt (or a clean error) is + proof that the decode worked. + """ + merchant = Merchant(env.merchant) + bank = Bank(env.bank) + out = { + "valid_pay": corpus.STRUCTURAL["pay"], + "valid_withdraw": corpus.STRUCTURAL["withdraw"], + "valid_withdraw_exchange": corpus.STRUCTURAL["withdraw_exchange"], + "payto": corpus.STRUCTURAL["payto_iban"], + "malformed_base32": corpus.MALFORMED["bad_base32"], + "unknown_action": corpus.MALFORMED["unknown_action"], + "not_taler": "https://www.gnu.org/software/taler/", + "plain_text": "this is not a URI at all", + } + # One genuinely live pay URI, so a successful decode leads somewhere real. + try: + order = merchant.create_order("EUR:1", summary="QR scanned order") + out["live_pay"] = order["pay_uri"] + except Exception as e: + print(f"could not create a live order ({e}); skipping live_pay") + try: + op = bank.create_withdrawal("wallet1", "walletpass1", "EUR:5") + out["live_withdraw"] = op["taler_withdraw_uri"] + except Exception as e: + print(f"could not create a live withdrawal ({e}); skipping live_withdraw") + return out + + +def boot_with(worker: int, poster: Path) -> None: + subprocess.run([str(EMU), "kill", str(worker)], timeout=120, check=False) + time.sleep(3) + env = {"SIM_POSTER": str(poster), "PATH": "/usr/bin:/bin:/usr/sbin:/sbin"} + subprocess.run([str(EMU), "boot", str(worker)], timeout=600, check=True, + env={**env}) + subprocess.run([str(EMU), "prepare", str(worker)], timeout=600, check=True) + + +def push_to_gallery(dev: Device, poster: Path) -> None: + """Put the image where the system photo picker will offer it.""" + target = f"/sdcard/Pictures/{poster.name}" + dev.adb("push", str(poster), target, timeout=120) + # MediaStore has to learn about the file, or the picker shows nothing. + dev.shell(f"am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE " + f"-d file://{target}", check=False) + time.sleep(1.5) + + +def scan_from_gallery(dev: Device, app: Wallet, ep: Episode, name: str, + payload: str, poster: Path, settle: int = 20) -> dict: + """Pick the rendered QR image with the scan screen's gallery button.""" + app.fresh_start(dev_mode=True) + push_to_gallery(dev, poster) + dev.logcat(clear=True) + screen = app.open_scanner() + before = screen.signature() + dev.tap_text(r"(?i)Scan from gallery", timeout=30) + time.sleep(3) + picker = dev.dump() + photo = picker.find(r"(?i)^Photo taken on") or picker.find(r"(?i)photo") + if photo is None: + return {"payload": payload[:120], "error": "no photo in the picker", + "screen": picker.texts()[:12]} + dev.tap_node(photo, picker) + start = time.time() + reacted = None + while time.time() - start < settle: + current = dev.dump() + if current.signature() != before and "photopicker" not in current.activity: + reacted = current + break + time.sleep(2) + after = reacted or dev.dump() + ep.observe() + result = { + "payload": payload[:120], + "decoded_and_reacted": reacted is not None, + "screen": after.texts()[:14], + "seconds": round(time.time() - start, 1), + } + print(f" {name:24} reacted={result['decoded_and_reacted']} " + f"{result['screen'][:6]}") + return result + + +def scan_with_camera(dev: Device, app: Wallet, ep: Episode, name: str, + payload: str, settle: int = 25) -> dict: + """Open the scan screen and see what the camera makes of the wall.""" + app.fresh_start(dev_mode=True) + dev.logcat(clear=True) + screen = app.open_scanner() + start = time.time() + reacted = None + while time.time() - start < settle: + current = dev.dump() + if current.signature() != screen.signature(): + reacted = current + break + time.sleep(2) + after = reacted or dev.dump() + ep.observe() + result = { + "payload": payload[:120], + "decoded_and_reacted": reacted is not None, + "screen": after.texts()[:14], + "seconds": round(time.time() - start, 1), + } + print(f" {name:24} reacted={result['decoded_and_reacted']} " + f"{result['screen'][:6]}") + return result + + +def main() -> int: + ap = argparse.ArgumentParser(description=__doc__) + ap.add_argument("--worker", type=int, default=4) + ap.add_argument("--only", nargs="*") + ap.add_argument("--camera", action="store_true", + help="use the virtual scene's camera instead of the gallery " + "(needs a human to aim it; see the module docstring)") + args = ap.parse_args() + + env = Env.load() + cases = payloads(env) + if args.only: + cases = {k: v for k, v in cases.items() if k in args.only} + serial = f"emulator-{5554 + 2 * args.worker}" + stamp = int(time.time()) + results: dict[str, dict] = {} + + dev = Device(serial) + app = Wallet(dev) + for name, payload in cases.items(): + poster = render(payload, name) + print(f"{name}: {poster} ({poster.stat().st_size} bytes)") + if args.camera: + boot_with(args.worker, poster) + dev = Device(serial) + app = Wallet(dev) + ep = Episode(dev, OUT, name=f"qr-w{args.worker}-{stamp}-{name}", + coverage_dir=COVERAGE) + try: + if args.camera: + results[name] = scan_with_camera(dev, app, ep, name, payload) + else: + results[name] = scan_from_gallery(dev, app, ep, name, payload, poster) + except Exception as e: + results[name] = {"error": f"{type(e).__name__}: {e}"} + print(f" {name:24} ERROR {e}") + ep.finish({"qr_case": name, "result": results[name]}) + + summary = OUT / f"qr-w{args.worker}-{stamp}-summary.json" + summary.write_text(json.dumps(results, indent=2)) + decoded = [k for k, v in results.items() if v.get("decoded_and_reacted")] + print(f"\n{len(results)} QR codes scanned, {len(decoded)} produced a reaction: " + f"{decoded}") + print(f"summary: {summary}") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/driver/replay.py b/simulator/driver/replay.py @@ -0,0 +1,158 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Replay a recorded episode, and shrink it to the steps that matter. + +An 80-step random walk that ends in a crash is not a bug report. Delta +debugging over the action list turns it into one: each candidate subsequence is +replayed from the same starting state, and the shortest one that still produces +the same finding fingerprint is what gets written out. + +Replay is not perfectly deterministic — wallet-core retries on its own clock — +so a candidate is only discarded after it fails to reproduce `attempts` times. +""" + +from __future__ import annotations + +import argparse +import json +import sys +import time +from pathlib import Path +from typing import Callable, Optional, Sequence + +import scenarios +from device import Device +from episode import Action, Episode +from stack import Env + +SETUPS: dict[str, Callable] = { + "fresh": lambda app, env: app.fresh_start(dev_mode=True), + "fund_wallet": scenarios.fund_wallet, + "funded_and_paid": scenarios.funded_and_paid, +} + + +def load_actions(path: Path) -> list[Action]: + data = json.loads((path / "actions.json").read_text() + if path.is_dir() else path.read_text()) + return [Action(op=a["op"], arg=a.get("arg")) for a in data] + + +def replay( + dev: Device, + actions: Sequence[Action], + out_dir: Path, + setup: str = "funded_and_paid", + name: str = "replay", +) -> Episode: + env = Env.load() + ep = Episode(dev, out_dir, name=name) + SETUPS[setup](ep.app, env) + # The setup itself must not count as a finding of the sequence. + ep.session = type(ep.session)() + dev.logcat(clear=True) + for action in actions: + ep.perform(action) + ep.observe(with_log=False) + ep.observe(with_log=True) + ep.finish({"setup": setup, "replayed": len(actions)}) + return ep + + +def reproduces(ep: Episode, fingerprint: Optional[str]) -> bool: + if fingerprint: + return fingerprint in ep.session.findings + return bool(ep.session.serious()) + + +def minimize( + dev: Device, + actions: Sequence[Action], + out_dir: Path, + fingerprint: Optional[str], + setup: str = "funded_and_paid", + attempts: int = 2, +) -> list[Action]: + """Classic ddmin, with repeats to survive a flaky reproduction.""" + + def still_fails(candidate: Sequence[Action], tag: str) -> bool: + for attempt in range(attempts): + ep = replay(dev, candidate, out_dir, setup=setup, + name=f"min-{tag}-{attempt}") + if reproduces(ep, fingerprint): + return True + return False + + current = list(actions) + granularity = 2 + while len(current) >= 2: + chunk = max(1, len(current) // granularity) + reduced = False + for i in range(0, len(current), chunk): + candidate = current[:i] + current[i + chunk:] + if not candidate: + continue + if still_fails(candidate, f"{len(current)}-{i}"): + current = candidate + granularity = max(granularity - 1, 2) + reduced = True + break + if not reduced: + if granularity >= len(current): + break + granularity = min(len(current), granularity * 2) + return current + + +def main() -> int: + ap = argparse.ArgumentParser(description=__doc__) + ap.add_argument("episode", type=Path, help="episode directory or actions.json") + ap.add_argument("--fingerprint", help="the finding to preserve (default: any serious one)") + ap.add_argument("--setup", default="funded_and_paid", choices=sorted(SETUPS)) + ap.add_argument("--minimize", action="store_true") + ap.add_argument("--serial", default="emulator-5554") + ap.add_argument("--out", type=Path, default=Path("/opt/taler-sim/run/out/replays")) + args = ap.parse_args() + + dev = Device(args.serial) + actions = load_actions(args.episode) + print(f"{len(actions)} actions from {args.episode}") + + ep = replay(dev, actions, args.out, setup=args.setup, + name=f"replay-{int(time.time())}") + ok = reproduces(ep, args.fingerprint) + print(f"reproduced: {ok}") + for f in ep.session.findings.values(): + print(f" [{f.kind}] {f.fingerprint} {f.detail[:140]}") + if not ok: + print("nothing to minimize") + return 1 + + if args.minimize: + target = args.fingerprint or next(iter( + f.fingerprint for f in ep.session.serious())) + shortest = minimize(dev, actions, args.out, target, setup=args.setup) + print(f"\nminimized {len(actions)} -> {len(shortest)} actions:") + for a in shortest: + print(" ", a.describe()) + target_file = args.out / f"minimal-{target}.json" + target_file.write_text(json.dumps( + {"setup": args.setup, "fingerprint": target, + "actions": [{"op": a.op, "arg": a.arg} for a in shortest]}, indent=2)) + print(f"written: {target_file}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/simulator/driver/report.py b/simulator/driver/report.py @@ -0,0 +1,83 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Summarise episode directories. + + python3 report.py # everything, newest last + python3 report.py 'suite-w*-1792268945-*' + python3 report.py --notes 'suite-*' # with the scenario notes + python3 report.py --findings # only the findings, deduplicated +""" + +from __future__ import annotations + +import glob +import json +import os +import sys +from pathlib import Path + +OUT = Path("/opt/taler-sim/run/out") + + +def load(pattern: str) -> list[dict]: + rows = [] + for d in sorted(glob.glob(str(OUT / pattern)), key=os.path.getmtime): + path = Path(d) / "summary.json" + if path.is_file(): + try: + rows.append(json.loads(path.read_text()) | {"dir": d}) + except json.JSONDecodeError: + continue + return rows + + +def main() -> int: + args = [a for a in sys.argv[1:] if not a.startswith("--")] + pattern = args[0] if args else "*" + rows = load(pattern) + show_notes = "--notes" in sys.argv + only_findings = "--findings" in sys.argv + + findings: dict[str, dict] = {} + broken = 0 + for r in rows: + for f in r.get("findings", []): + findings.setdefault(f.get("fingerprint", f["detail"][:40]), f) + if r.get("status") not in (None, "ok"): + broken += 1 + if only_findings: + continue + name = r.get("scenario") or r.get("name", "?") + status = r.get("status", "-") + print(f"{name:28} {status:13} serious={r.get('serious', 0)} " + f"findings={len(r.get('findings', []))} steps={r.get('steps', 0)} " + f"{r.get('seconds', '?')}s") + if r.get("error"): + print(f" error: {r['error'][:200]}") + if show_notes: + for note in r.get("notes", []): + print(f" note: {note[:200]}") + + serious = [f for f in findings.values() if f["kind"] != "error-screen"] + print(f"\n{len(rows)} episodes, {broken} driver errors, " + f"{len(findings)} distinct findings ({len(serious)} serious)") + for f in findings.values(): + mark = "***" if f["kind"] != "error-screen" else " " + print(f" {mark} [{f['kind']:22}] {f.get('fingerprint', '')} " + f"{f['detail'][:150].replace(chr(10), ' ')}") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/driver/scenarios.py b/simulator/driver/scenarios.py @@ -0,0 +1,346 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Scripted flows that put the wallet into a deep, interesting state. + +Random exploration from the launcher almost never reaches "has coins and has +paid for something"; these do it in a handful of steps, so exploration can +start from there instead. Each one drives the real UI and uses the host-side +APIs only for the steps a counterparty would perform. +""" + +from __future__ import annotations + +import os +import time +from typing import Callable + +from cli import CliWallet +from device import Screen +from stack import Bank, Env, Merchant +from wallet import Wallet + +# Each parallel worker gets its own bank customer, so two emulators running +# scenarios at the same time cannot spend each other's money. +WORKER = int(os.environ.get("SIM_WORKER", "0")) +WALLET_USER = (f"wallet{WORKER + 1}", f"walletpass{WORKER + 1}") + + +def tap_if(app: Wallet, pattern: str, timeout: int = 8) -> bool: + """Tap a label if it is there; unlike Device.tap_text, do not raise.""" + try: + app.dev.tap_text(pattern, timeout=timeout) + return True + except TimeoutError: + return False + + +def tap_lowest_button(app: Wallet, pattern: str, timeout: int = 60) -> bool: + """Tap the lowest *clickable* node whose label matches. + + Several screens use one string for the heading and the submit button; the + heading comes first in the hierarchy and is not clickable, so a plain + tap_text hits nothing. Ctx.tap_button does this for scenarios; flows need + their own copy. + """ + import re as _re + rx = _re.compile(pattern, _re.I) + deadline = time.time() + timeout + while time.time() < deadline: + screen = app.dev.dump() + targets = [] + for node in screen.labelled(): + if not rx.search(node.label): + continue + target = screen.tap_target(node) + if target.clickable and target.enabled: + targets.append(target) + if targets: + app.dev.tap_node(max(targets, key=lambda n: n.bounds[1]), screen) + time.sleep(1.5) + return True + time.sleep(1.5) + return False + + +def accept_tos(app: Wallet, timeout: int = 20) -> bool: + """Get past the terms of service, if the exchange has any. + + An exchange that serves /terms turns the withdrawal prompt's own button + into "Terms of Service", which opens the review screen; nothing else can + be done until the terms are accepted. An exchange without terms (the + shipped TERMS_DIR points into an empty test home) never shows this, so + every caller has to cope with both. + """ + # Two orders of events: the button is already there, or the screen says the + # terms are required and the button arrives with the next recomposition + # (which is what happens after switching to a different payment service). + deadline = time.time() + 10 + while True: + screen = app.dev.dump() + if screen.find(r"(?i)^Terms of Service$") is not None: + break + if screen.find(r"(?i)terms of service before you can withdraw|" + r"must first accept") is None: + return False + if time.time() > deadline: + return False + time.sleep(1.5) + # Opening the review screen fetches the terms document, which on a loaded + # host takes longer than one tap's patience; and the accept button can sit + # below the fold. So: tap, look, scroll, and tap again rather than giving + # up on the first miss -- a flaky accept here fails the *setup* of whatever + # scenario asked for a funded wallet, which reads as that scenario being + # broken. + for attempt in range(3): + if not tap_if(app, r"(?i)^Terms of Service$", timeout=timeout): + break + time.sleep(2) + deadline = time.time() + timeout + while time.time() < deadline: + if app.dev.dump().find(r"(?i)^Accept Terms of Service$") is not None: + app.dev.tap_text(r"(?i)^Accept Terms of Service$", timeout=10) + time.sleep(2) + return True + app.dev.scroll(down=True) + time.sleep(1.5) + # Still on the prompt: go back up and try the button once more. + if app.dev.dump().find(r"(?i)^Terms of Service$") is None: + app.dev.back() + time.sleep(1.5) + return False + + +def pick_payment_service(app: Wallet, url: str) -> bool: + """Switch the withdrawal prompt to a particular payment service. + + The prompt shows the chosen service as a row labelled with its URL, and + that row is `clickable` but **disabled** until the terms of service have + been accepted -- so this only works after accept_tos, and tapping it + earlier does nothing (or lands on a neighbour and leaves the screen). + """ + import re as _re + screen = app.dev.dump() + row = next((n for n in screen.labelled() + if _re.match(r"(?i)^https?://", n.label.strip())), None) + if row is None: + return False + target = screen.tap_target(row) + if not target.enabled: + return False + app.dev.tap_node(target, screen) + time.sleep(2) + # The picker lists every service that can serve this currency. + return tap_lowest_button(app, _re.escape(url.rstrip("/")), timeout=15) + + +def withdraw(app: Wallet, bank: Bank, amount: str = "EUR:10", timeout: int = 180, + pick_exchange: str | None = None) -> Screen: + """Bank-initiated withdrawal, all the way to a completed transaction. + + The bank opens the operation, the wallet picks the exchange and confirms, + and the host plays the part of the human authorising it in the bank's own + UI. `pick_exchange` switches the service first, which is the only way to + get coins at a second exchange. + """ + op = bank.create_withdrawal(*WALLET_USER, amount) + app.handle_uri(op["taler_withdraw_uri"]) + accept_tos(app) + if pick_exchange and pick_payment_service(app, pick_exchange): + # A different service means its own terms. + accept_tos(app) + app.dev.tap_text(r"(?i)confirm withdrawal", timeout=60) + # The wallet has to have selected the exchange before the bank will let the + # operation be confirmed; confirming anyway answers "Cannot confirm an + # unselected withdrawal" (5130), which reads like a bank problem rather + # than a wallet that was still thinking. + deadline = time.monotonic() + 90 + while True: + status = bank.withdrawal_status(op["withdrawal_id"])["status"] + if status == "selected": + break + if time.monotonic() > deadline: + raise TimeoutError( + f"the wallet did not select an exchange for {amount} within 90s " + f"(bank says {status!r}; screen: {app.dev.dump().texts()[:12]})") + time.sleep(2) + bank.confirm_withdrawal(*WALLET_USER, op["withdrawal_id"]) + deadline = time.monotonic() + timeout + while time.monotonic() < deadline: + screen = app.dev.dump() + if screen.find(r"(?i)completed successfully"): + return screen + time.sleep(3) + raise TimeoutError(f"withdrawal {op['withdrawal_id']} did not complete") + + +def pay(app: Wallet, merchant: Merchant, amount: str = "EUR:2", + summary: str = "Simulator order") -> dict: + """Create an order and pay it from the wallet's balance.""" + order = merchant.create_order(amount, summary=summary) + app.handle_uri(order["pay_uri"]) + # The button carries the amount, e.g. "Pay €2.00". + app.dev.tap_text(r"(?i)^pay\b|confirm payment", timeout=60) + deadline = time.monotonic() + 90 + while time.monotonic() < deadline: + if merchant.order_status(order["order_id"], + order["token"]).get("order_status") == "paid": + return order + time.sleep(2) + raise TimeoutError(f"order {order['order_id']} was not paid") + + +def fund_wallet(app: Wallet, env: Env | None = None, amount: str = "EUR:10") -> Screen: + """Fresh profile in developer mode, with coins in it.""" + env = env or Env.load() + app.fresh_start(dev_mode=True) + screen = withdraw(app, Bank(env.bank), amount) + app.home() + return screen + + +def funded_and_paid(app: Wallet, env: Env | None = None) -> dict: + """The deepest cheap state: coins, one completed purchase, refundable.""" + env = env or Env.load() + fund_wallet(app, env) + order = pay(app, Merchant(env.merchant)) + app.home() + return order + + +def deposit_via_payto_link(app: Wallet, env: Env | None = None) -> Screen: + """Try to start a deposit from a payto link, which the wallet refuses. + + `DepositManager.isSupportedPayToUri` accepts `payto://iban/...` and nothing + else, so the `payto://x-taler-bank/...` URI the simulator's bank hands out + answers "Not a valid Taler link" -- see + findings/payto-link-only-accepts-iban.md. + """ + env = env or Env.load() + payto = Bank(env.bank).payto(*WALLET_USER) + app.handle_uri(payto) + app.dev.wait_for(r"(?i)Not a valid Taler link|deposit|amount|send", timeout=60) + return app.dev.dump() + + +def deposit_to_bank(app: Wallet, env: Env | None = None, + digits: str = "100", + before_submit: Callable[[], None] | None = None) -> Screen: + """Deposit from the app to a bank account, through the UI. + + Not through a payto link: the wallet refuses every target type but IBAN + (see `deposit_via_payto_link`), and the simulator's bank is x-taler-bank, + so the link path cannot deposit at all. The Deposit button can, and the + account is already known to the wallet from its withdrawals. + + `digits` is typed as an amount field takes them, from the right: "100" is + 1.00. + """ + env = env or Env.load() + app.home() + app.dev.tap_text(r"(?i)^Deposit$", timeout=30) + screen = app.dev.wait_for( + r"(?i)deposit to bank account|Manage bank accounts|x-taler-bank", + timeout=30) + account = screen.find(r"(?i)^wallet\d+$") or screen.find(r"(?i)x-taler-bank") + if account is not None: + app.dev.tap_node(account, screen) + time.sleep(2) + app.dev.wait_for(r"(?i)Amount to deposit|Make deposit", timeout=25) + fields = app.dev.dump().editable() + if fields: + app.dev.tap_node(fields[0]) + app.dev.type_text(digits) + time.sleep(1) + # The fees appear on their own once an amount is in; older builds had a + # "Check fees" button, so it is tapped when present and skipped otherwise. + tap_if(app, r"(?i)^Check fees$", timeout=6) + # A caller that wants the deposit to *stay* pending -- to reach the + # aborting state, say -- takes the network away here: against a healthy + # exchange the whole thing is over in under four seconds. + if before_submit is not None: + before_submit() + app.dev.tap_text(r"(?i)^Make deposit$|^Deposit$", timeout=20) + time.sleep(4) + return app.dev.dump() + + +# The peer wallet gets a bank customer of its own, so funding it never eats +# into the balance the app under test is spending. +PEER_USER = (f"peer{WORKER + 1}", f"peerpass{WORKER + 1}") + + +def fund_peer(peer: CliWallet, env: Env, amount: str = "EUR:5", + exchange: str | None = None) -> str: + """Give the CLI peer wallet coins, through the bank like any wallet. + + `exchange` picks which one they come from, which is how the app ends up + holding a second currency scope: a peer payment is spent at the sender's + exchange. + """ + from stack import Bank + return peer.fund_via_bank(Bank(env.bank), PEER_USER, amount, + exchange or env.exchange) + + +def peer_receive(app: Wallet, env: Env | None = None, amount: str = "EUR:1", + peer: CliWallet | None = None, + exchange: str | None = None) -> Screen: + """The CLI wallet pushes money; the app accepts it. + + `exchange` is where the peer's coins come from, and therefore which scope + the app ends up holding -- the cheapest way to give this wallet a balance + at a second exchange, since no withdrawal UI lets one be chosen. + """ + env = env or Env.load() + peer = peer or CliWallet() + exchange = exchange or env.exchange + if exchange != env.exchange: + peer.add_exchange(exchange) + fund_peer(peer, env, "EUR:5", exchange=exchange) + uri = peer.peer_send(amount, exchange) + app.handle_uri(uri) + # With terms the prompt's button is "Review terms of service" first, and + # the review screen has to be accepted before the payment can be. + if app.dev.wait_for(r"(?i)Review terms of service|Receive payment|accept", + timeout=60).find(r"(?i)Review terms of service") is not None: + app.dev.tap_text(r"(?i)Review terms of service", timeout=20) + time.sleep(2) + app.dev.tap_text(r"(?i)^Accept Terms of Service$", timeout=20) + time.sleep(3) + # "Receive payment" is both the screen's heading and its button, and + # tap_text takes the first match -- the heading, which is not clickable, so + # the payment was never accepted and the balance stayed at zero while the + # scenario reported success. Tap the lowest clickable match instead. + tap_lowest_button(app, r"(?i)^Receive payment$|accept|confirm") + return app.dev.dump() + + +def peer_pay_invoice(app: Wallet, env: Env | None = None, amount: str = "EUR:1", + peer: CliWallet | None = None) -> Screen: + """The CLI wallet invoices the app; the app pays it.""" + env = env or Env.load() + peer = peer or CliWallet() + peer.add_exchange(env.exchange) + uri = peer.peer_request(amount, exchange=env.exchange) + app.handle_uri(uri) + # Paying an invoice needs the exchange's terms accepted first, like any + # other first use of it. + if app.dev.wait_for(r"(?i)Review terms of service|^Pay\b|accept|confirm", + timeout=60).find(r"(?i)Review terms of service") is not None: + app.dev.tap_text(r"(?i)Review terms of service", timeout=20) + time.sleep(2) + app.dev.tap_text(r"(?i)^Accept Terms of Service$", timeout=20) + time.sleep(3) + app.dev.tap_text(r"(?i)^pay\b|accept|confirm", timeout=60) + return app.dev.dump() diff --git a/simulator/driver/smoke_pay.py b/simulator/driver/smoke_pay.py @@ -0,0 +1,92 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""P0 smoke test: pay a merchant order, then take a refund. + +Assumes the wallet already holds coins (run smoke_withdraw.py first); it keeps +the app's state rather than wiping it, because paying from an existing balance +is the state the explorer will spend most of its time in. +""" + +from __future__ import annotations + +import json +import sys +import time + +from device import Device +from stack import Env, Merchant +from wallet import Wallet + +PRICE = "EUR:2" +REFUND = "EUR:1" + + +def main() -> int: + env = Env.load() + merchant = Merchant(env.merchant) + + dev = Device(sys.argv[1] if len(sys.argv) > 1 else "emulator-5554") + app = Wallet(dev) + dev.logcat(clear=True) + app.home() + print("balances on screen:", app.balances()) + + order = merchant.create_order(PRICE, summary="Simulator test order") + print("order:", order["order_id"], "pay uri:", order["pay_uri"]) + + screen = app.handle_uri(order["pay_uri"]) + print("\n--- payment prompt ---") + print(screen) + + # The button carries the amount: "Pay €2.00". + dev.tap_text(r"(?i)^pay\b|confirm payment", timeout=60) + time.sleep(4) + print("\n--- after paying ---") + print(dev.dump()) + + paid = False + for _ in range(20): + status = merchant.order_status(order["order_id"], order["token"]) + if status.get("order_status") == "paid": + paid = True + break + time.sleep(2) + print("\nmerchant order status:", json.dumps( + {k: v for k, v in merchant.order_status(order['order_id'], order['token']).items() + if k in ("order_status", "refunded", "wired", "deposit_total")}, indent=2)) + if not paid: + print("ORDER NOT PAID") + + # Refund: the merchant grants it, the wallet picks it up from the URI the + # merchant hands back. + res = merchant.refund(order["order_id"], REFUND) + refund_uri = res.get("taler_refund_uri") + print("\nrefund uri:", refund_uri) + if refund_uri: + screen = app.handle_uri(refund_uri) + print("\n--- after refund uri ---") + print(screen) + + log = dev.logcat() + bad = [ln for ln in log.splitlines() + if "FATAL EXCEPTION" in ln or "ANR in" in ln + or "unexpected exception" in ln.lower() or "invariant" in ln.lower()] + print(f"\noracle hits in logcat: {len(bad)}") + for ln in bad[:10]: + print(" ", ln) + return 0 if paid else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/simulator/driver/smoke_withdraw.py b/simulator/driver/smoke_withdraw.py @@ -0,0 +1,106 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""P0 smoke test: withdraw from the local libeufin bank into the wallet app. + +Prints every screen it sees, because the labels it discovers are what the +scenario library will later be written against. +""" + +from __future__ import annotations + +import sys +import time + +from device import Device +from stack import Bank, Env, provision +from wallet import Wallet + +AMOUNT = "EUR:10" + + +def main() -> int: + env = Env.load() + bank = Bank(env.bank) + print("provisioning:", provision(env)) + + dev = Device(sys.argv[1] if len(sys.argv) > 1 else "emulator-5554") + app = Wallet(dev) + dev.logcat(clear=True) + dev.stop() + # A fresh profile in developer mode: taler+http:// URIs are rejected + # outright without it. + app.fresh_start(dev_mode=True) + print("\n--- home (developer mode on) ---") + print(dev.dump()) + + before = bank.balance("wallet1", "walletpass1") + op = bank.create_withdrawal("wallet1", "walletpass1", AMOUNT) + uri = op["taler_withdraw_uri"] + print(f"\nbank balance before: {before}\nwithdraw uri: {uri}") + + dev.send_uri(uri) + screen = dev.wait_for(r"(?i)withdraw|exchange|confirm|accept|terms", timeout=90) + print("\n--- withdrawal screen ---") + print(screen) + + # The exchange is unknown to a fresh wallet, so terms of service have to be + # accepted before the withdrawal can be confirmed. Both labels are tried, + # in the order they can appear. + for pattern in (r"(?i)^(accept|agree|i accept)", r"(?i)confirm|withdraw now|^withdraw$"): + try: + tapped = dev.tap_text(pattern, timeout=20) + print(f"\ntapped {pattern!r} on screen with {tapped.texts()}") + time.sleep(3) + except TimeoutError as e: + print(f"\n(no match for {pattern!r}: {e})") + + print("\n--- after confirm attempt ---") + print(dev.dump()) + + status = bank.withdrawal_status(op["withdrawal_id"]) + print("\nbank-side withdrawal status:", status) + + # The wallet has selected the exchange and registered the reserve; the + # human step left is confirming in the bank, which the host does here. + bank.confirm_withdrawal("wallet1", "walletpass1", op["withdrawal_id"]) + print("confirmed in bank") + + deadline = time.monotonic() + 120 + seen = None + while time.monotonic() < deadline: + screen = dev.dump() + seen = screen.texts() + if screen.find(r"EUR|€|\d+\.\d\d"): + break + time.sleep(3) + print("\n--- final wallet screen ---") + print("\n".join(str(t) for t in (seen or []))) + print("\nbank balance after:", bank.balance("wallet1", "walletpass1")) + + log = dev.logcat() + bad = [ln for ln in log.splitlines() + if "FATAL EXCEPTION" in ln or "ANR in" in ln + or "unexpected exception" in ln.lower() + or "invariant" in ln.lower()] + print(f"\noracle hits in logcat: {len(bad)}") + for ln in bad[:10]: + print(" ", ln) + with open("/opt/taler-sim/run/smoke-logcat.txt", "w") as f: + f.write(log) + print("full logcat: /opt/taler-sim/run/smoke-logcat.txt") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/simulator/driver/stack.py b/simulator/driver/stack.py @@ -0,0 +1,508 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Host-side clients for the simulator's Taler stack. + +Everything the wallet's counterparties do happens here over HTTP: the bank +(libeufin corebank) registers customers, opens and confirms withdrawals and +reports balances; the merchant creates instances, orders and refunds. Keeping +the counterparties on the host makes a scenario deterministic — the only thing +being explored is the wallet. +""" + +from __future__ import annotations + +import base64 +import json +import os +from pathlib import Path +from urllib.parse import quote +import uuid +import urllib.error +import urllib.request +from dataclasses import dataclass +from typing import Any, Optional + +DEFAULT_ENV = "/opt/taler-sim/run/stack/env.json" + + +class HttpError(RuntimeError): + def __init__(self, status: int, body: str, url: str): + super().__init__(f"HTTP {status} for {url}: {body[:300]}") + self.status = status + self.body = body + + +def _request( + url: str, + method: str = "GET", + payload: Any = None, + auth: Optional[tuple[str, str]] = None, + timeout: int = 30, +) -> Any: + data = None + headers = {"Accept": "application/json"} + if payload is not None: + data = json.dumps(payload).encode() + headers["Content-Type"] = "application/json" + if auth: + token = base64.b64encode(f"{auth[0]}:{auth[1]}".encode()).decode() + headers["Authorization"] = f"Basic {token}" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + try: + with urllib.request.urlopen(req, timeout=timeout) as resp: + body = resp.read().decode() + except urllib.error.HTTPError as e: + raise HttpError(e.code, e.read().decode(errors="replace"), url) from None + if not body.strip(): + return None + try: + return json.loads(body) + except json.JSONDecodeError: + return body + + +@dataclass +class Env: + """The URLs and credentials stack.sh wrote out.""" + + exchange: str + merchant: str + bank: str + donau: str + auditor: str + currency: str + # Only there when backend/exchange2.sh is running beside the stack. + exchange2: str | None = None + + @classmethod + def load(cls, path: str = DEFAULT_ENV) -> "Env": + with open(path) as f: + d = json.load(f) + return cls( + exchange=d["exchange"], merchant=d["merchant"], bank=d["bank"], + donau=d["donau"], auditor=d["auditor"], currency=d["currency"], + exchange2=d.get("exchange2"), + ) + + +class Bank: + """libeufin-bank corebank API.""" + + def __init__(self, base_url: str): + self.base = base_url.rstrip("/") + + def config(self) -> Any: + return _request(f"{self.base}/config") + + def register(self, username: str, password: str, name: str) -> Any: + # Passwords shorter than 8 characters are rejected by the bank. + return _request(f"{self.base}/accounts", "POST", + {"username": username, "password": password, "name": name}) + + def account(self, username: str, password: str) -> Any: + return _request(f"{self.base}/accounts/{username}", auth=(username, password)) + + def balance(self, username: str, password: str) -> str: + acc = self.account(username, password) + bal = acc["balance"] + sign = "-" if bal["credit_debit_indicator"] == "debit" else "" + return f"{sign}{bal['amount']}" + + def payto(self, username: str, password: str) -> str: + return self.account(username, password)["payto_uri"] + + def create_withdrawal(self, username: str, password: str, amount: str) -> Any: + """Open a withdrawal operation; returns withdrawal_id + taler_withdraw_uri. + + A round spends more than the registration bonus, so an exhausted + account is topped up and the request retried once rather than failing + the scenario with something that looks like a wallet bug. + """ + try: + return _request(f"{self.base}/accounts/{username}/withdrawals", "POST", + {"amount": amount}, auth=(username, password)) + except HttpError as e: + if e.status != 409 or "5102" not in e.body: + raise + self.top_up(username, "EUR:2000") + return _request(f"{self.base}/accounts/{username}/withdrawals", "POST", + {"amount": amount}, auth=(username, password)) + + def withdrawal_status(self, wid: str) -> Any: + return _request(f"{self.base}/withdrawals/{wid}") + + def confirm_withdrawal(self, username: str, password: str, wid: str) -> Any: + """The step a human would take in the bank's own UI.""" + return _request(f"{self.base}/accounts/{username}/withdrawals/{wid}/confirm", + "POST", {}, auth=(username, password)) + + def abort_withdrawal(self, username: str, password: str, wid: str) -> Any: + return _request(f"{self.base}/accounts/{username}/withdrawals/{wid}/abort", + "POST", {}, auth=(username, password)) + + ADMIN = ("admin", "secret-password") # set by taler-unified-setup.sh + + def top_up(self, username: str, amount: str = "EUR:200") -> Any: + """Credit a customer from the admin account. + + Scenario runs spend the registration bonus quickly, and an exhausted + bank account looks just like a wallet bug in the logs, so accounts get + topped up between iterations. Admin may read any account, so the + customer's own password is not needed. + """ + account = _request(f"{self.base}/accounts/{username}", auth=self.ADMIN) + payto = account["payto_uri"] + joiner = "&" if "?" in payto else "?" + return _request( + f"{self.base}/accounts/{self.ADMIN[0]}/transactions", "POST", + {"payto_uri": f"{payto}{joiner}amount={amount}&message=simulator top up"}, + auth=self.ADMIN, + ) + + def transfer(self, username: str, password: str, to_payto: str, + amount: str, subject: str) -> Any: + """Pay from one customer account to any payto URI, with a subject. + + This is how a manual (not bank-integrated) withdrawal is completed: the + wallet shows a subject -- the reserve public key -- and the user makes + the transfer in their own bank. The exchange's wirewatch then sees the + credit and the withdrawal goes through. + """ + joiner = "&" if "?" in to_payto else "?" + return _request( + f"{self.base}/accounts/{username}/transactions", "POST", + {"payto_uri": f"{to_payto}{joiner}amount={amount}" + f"&message={quote(subject)}"}, + auth=(username, password), + ) + + def transactions(self, username: str, password: str) -> Any: + return _request(f"{self.base}/accounts/{username}/transactions", + auth=(username, password)) + + +class Merchant: + """taler-merchant backend, private and management APIs.""" + + def __init__(self, base_url: str, instance: str = "sim"): + self.base = base_url.rstrip("/") + self.instance = instance + + @property + def private(self) -> str: + return f"{self.base}/instances/{self.instance}/private" + + def config(self) -> Any: + return _request(f"{self.base}/config") + + def exists(self) -> bool: + try: + _request(f"{self.base}/instances/{self.instance}/config") + return True + except HttpError: + return False + + def create_instance(self, name: str = "Simulator Shop") -> None: + """Idempotent. + + The management API is only open while the instance does not exist yet: + a second POST for the same id is an update and comes back 401 (or 409), + so an existing instance is probed for first and both codes tolerated. + """ + if self.exists(): + return + try: + _request(f"{self.base}/management/instances", "POST", { + "id": self.instance, + "name": name, + "auth": {"method": "external"}, + "address": {}, + "jurisdiction": {}, + "use_stefan": True, + "default_wire_transfer_delay": {"d_us": 3600 * 1000 * 1000}, + "default_pay_delay": {"d_us": 3600 * 1000 * 1000}, + }) + except HttpError as e: + if e.status not in (401, 409): + raise + + def add_account(self, payto_uri: str) -> Any: + """Idempotent: re-adding the same account comes back 409.""" + try: + return _request(f"{self.private}/accounts", "POST", {"payto_uri": payto_uri}) + except HttpError as e: + if e.status != 409: + raise + return None + + def create_otp_device(self, device_id: str = "simpos", + key: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", + algorithm: str = "TOTP_WITHOUT_PRICE") -> Any: + """A point-of-sale confirmation device. Idempotent. + + An order that names one gets a `pos_confirmation` in its pay reply, + which is the only thing that makes the wallet show its TOTP screen. + The key is RFC 3548 base32, not Crockford. + """ + body = { + "otp_device_id": device_id, + "otp_device_description": "Simulator point of sale", + "otp_algorithm": algorithm, + "otp_key": key, + "otp_ctr": 0, + } + try: + return _request(f"{self.private}/otp-devices", "POST", body) + except HttpError as e: + if e.status != 409: + raise + return None + + def create_order( + self, + amount: str, + summary: str = "Simulator order", + fulfillment_url: str | None = None, + otp_id: str | None = None, + **order_extra: Any, + ) -> dict: + """Create an order and return it with its taler://pay URI. + + Each order gets its own fulfillment URL unless one is given: the + wallet treats a second order with a fulfillment URL it has already + paid for as a repurchase and answers "You've already paid for this + purchase", which silently skips the payment a scenario was testing. + """ + if fulfillment_url is None: + fulfillment_url = ( + "https://example.com/fulfillment/" + f"{uuid.uuid4().hex[:16]}" + ) + order = { + "amount": amount, + "summary": summary, + "fulfillment_url": fulfillment_url, + **order_extra, + } + # otp_id is a sibling of "order", not a field of it. + body: dict = {"order": order} + if otp_id is not None: + body["otp_id"] = otp_id + res = _request(f"{self.private}/orders", "POST", body) + status = self.order_status(res["order_id"], res.get("token")) + return { + "order_id": res["order_id"], + "token": res.get("token"), + "pay_uri": status.get("taler_pay_uri"), + "status": status, + } + + def create_token_family(self, slug: str = "simdiscount", + kind: str = "discount", + name: str = "Simulator discount") -> Any: + """A token family, so orders can issue and demand tokens. + + Discount tokens are what the wallet shows under "Discounts"; nothing + reaches that screen until an order issues one. + """ + body = { + "slug": slug, + "name": name, + "description": f"{kind} tokens issued by the simulator", + "duration": {"d_us": 365 * 24 * 3600 * 1000 * 1000}, + "validity_granularity": {"d_us": 24 * 3600 * 1000 * 1000}, + "start_offset": {"d_us": 0}, + "kind": kind, + } + try: + return _request(f"{self.private}/tokenfamilies", "POST", body) + except HttpError as e: + if e.status != 409: + raise + return None + + def create_v1_order(self, choices: list[dict], summary: str = "Simulator v1 order", + fulfillment_url: str = "https://example.com/fulfillment", + **extra: Any) -> dict: + """A version 1 ("mumimo") order: several choices, with token inputs + and outputs.""" + order = { + "version": 1, + "summary": summary, + "fulfillment_url": fulfillment_url, + "choices": choices, + **extra, + } + res = _request(f"{self.private}/orders", "POST", {"order": order}) + status = self.order_status(res["order_id"], res.get("token")) + return { + "order_id": res["order_id"], + "token": res.get("token"), + "pay_uri": status.get("taler_pay_uri"), + "status": status, + } + + @staticmethod + def token_output(slug: str = "simdiscount", count: int = 1) -> dict: + return {"type": "token", "token_family_slug": slug, "count": count, + "key_index": 0} + + @staticmethod + def token_input(slug: str = "simdiscount", count: int = 1) -> dict: + return {"type": "token", "token_family_slug": slug, "count": count} + + def create_template(self, template_id: str = "simtemplate", + amount: str = "EUR:1") -> Any: + """A reusable order template, paid through a taler://pay-template URI.""" + body = { + "template_id": template_id, + "template_description": "Simulator template", + "template_contract": { + "amount": amount, + "minimum_age": 0, + "pay_duration": {"d_us": 3600 * 1000 * 1000}, + }, + } + try: + return _request(f"{self.private}/templates", "POST", body) + except HttpError as e: + if e.status != 409: + raise + return None + + def order_status(self, order_id: str, token: Optional[str] = None) -> Any: + url = f"{self.private}/orders/{order_id}" + if token: + url += f"?token={token}" + return _request(url) + + def refund(self, order_id: str, amount: str, reason: str = "simulator refund") -> Any: + return _request(f"{self.private}/orders/{order_id}/refund", "POST", + {"refund": amount, "reason": reason}) + + def delete_order(self, order_id: str) -> Any: + return _request(f"{self.private}/orders/{order_id}", "DELETE") + + +CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ" + + +def encode_crock(data: bytes) -> str: + """The base32 Taler uses for hashes and keys (GNUNET_STRINGS_data_to_string). + + Crockford's alphabet, big-endian bit order, no padding. Verified against + the exchange's own signing keys: the hex in `exchange.exchange_sign_keys` + encodes to exactly the strings /keys publishes. + """ + out = [] + bits = vbit = rpos = 0 + while rpos < len(data) or vbit > 0: + if rpos < len(data) and vbit < 5: + bits = (bits << 8) | data[rpos] + rpos += 1 + vbit += 8 + if vbit < 5: + bits <<= (5 - vbit) + vbit = 5 + out.append(CROCKFORD[(bits >> (vbit - 5)) & 31]) + vbit -= 5 + return "".join(out) + + +def revoke_denomination(denom_pub_hash: bytes | str, + conf: str = "sim.conf", + run_dir: str = "/opt/taler-sim/run/stack") -> str: + """Revoke a denomination key, as an exchange operator would. + + Destructive and stack-wide: the denomination stays revoked until the stack + is started again, and every wallet holding one of its coins has to recoup. + """ + import subprocess + crock = (denom_pub_hash if isinstance(denom_pub_hash, str) + else encode_crock(denom_pub_hash)) + proc = subprocess.run( + ["taler-exchange-offline", "-c", conf, + "revoke-denomination", crock, "upload"], + cwd=run_dir, capture_output=True, text=True, timeout=120, + ) + if proc.returncode != 0: + raise RuntimeError(f"revoking {crock} failed: " + f"{(proc.stderr or proc.stdout).strip()[:300]}") + return crock + + +def provision(env: Optional[Env] = None, + # Seven, not five: the harness has AVDs for workers 0..6 and + # worker 6 (the version matrix) banks as wallet7. A plain + # `python3 stack.py` used to leave that account out, and every + # scenario on that worker then died with + # `HTTP 401 ... accounts/wallet7 ... Unknown account` -- which + # looked exactly like a platform failure in the matrix. + workers: int = int(os.environ.get("SIM_WORKERS", "7"))) -> dict: + """Make the stack usable by a wallet: one merchant instance with a bank + account, and one bank customer per parallel worker.""" + env = env or Env.load() + bank, merchant = Bank(env.bank), Merchant(env.merchant) + out: dict[str, Any] = {"currency": env.currency} + # A stack start wipes the exchange database, so its master key is new while + # the peer wallets still remember the old one and refuse to talk to it + # ("the exchange changed its master public key", code 7066). Provisioning + # runs right after every stack start, which is exactly when they should be + # thrown away. + out["cli_wallets_removed"] = sorted( + p.name for p in Path("/opt/taler-sim/run").glob("cli-wallet-*.sqlite3*") + ) + for stale in Path("/opt/taler-sim/run").glob("cli-wallet-*.sqlite3*"): + stale.unlink(missing_ok=True) + accounts = [("merchant", "merchantpass1", "Simulator Shop")] + accounts += [(f"wallet{i + 1}", f"walletpass{i + 1}", f"Wallet {i + 1}") + for i in range(workers)] + # One more per worker for the taler-wallet-cli peer wallet. + accounts += [(f"peer{i + 1}", f"peerpass{i + 1}", f"Peer {i + 1}") + for i in range(workers)] + for user, password, name in accounts: + try: + bank.register(user, password, name) + out[f"{user}_registered"] = True + except HttpError as e: + # 409 means the account survived from an earlier run. + if e.status != 409: + raise + out[f"{user}_registered"] = False + # Keep every account well above what one round can spend: ~75 scenarios + # share these accounts, and a fresh one holds only the EUR:100 + # registration bonus. + for user, password, _ in accounts[1:]: + try: + balance = bank.balance(user, password) + value = float(balance.split(":")[1]) + if value < 1000: + bank.top_up(user, "EUR:2000") + out[f"{user}_topped_up"] = True + except (HttpError, ValueError, IndexError) as e: + out[f"{user}_top_up_error"] = str(e)[:120] + merchant.create_instance() + merchant.add_account(bank.payto("merchant", "merchantpass1")) + out["merchant_instance"] = merchant.instance + out["balances"] = { + f"wallet{i + 1}": bank.balance(f"wallet{i + 1}", f"walletpass{i + 1}") + for i in range(workers) + } + return out + + +if __name__ == "__main__": + import sys + e = Env.load(sys.argv[1] if len(sys.argv) > 1 else DEFAULT_ENV) + print(json.dumps(provision(e), indent=2)) diff --git a/simulator/driver/suite.py b/simulator/driver/suite.py @@ -0,0 +1,5755 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Feature scenarios, run as a suite. + +Each scenario walks one feature of the wallet deliberately, rather than at +random: the transaction list and its per-transaction actions, exchange +management, every settings row, the scan screen's manual entry, deposits and +peer payments. Random exploration finds the sequences nobody thought of; +these make sure the obvious ones are covered at all. + +A scenario failing because a label moved is *not* a finding — it is recorded +as a driver error so the two never get confused. Real findings come from the +oracles in oracles.py. + + python3 suite.py # every scenario + python3 suite.py history exchange_add_remove + python3 suite.py --list +""" + +from __future__ import annotations + +import json +import os +import re +import sys +import time +from pathlib import Path +import traceback +from dataclasses import dataclass, field +from typing import Callable, Optional + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "corpus")) + +import oracles # noqa: E402 +import scenarios as flows # noqa: E402 +import uris as corpus # noqa: E402 +from cli import CliWallet # noqa: E402 +from twister import FAULTS, Twister, TwisterUnavailable # noqa: E402 +from device import PKG, Device, Screen # noqa: E402 +from episode import Episode # noqa: E402 +import stack as stack_mod # noqa: E402 +from stack import Bank, Env, Merchant # noqa: E402 + +WORKER = int(os.environ.get("SIM_WORKER", "0")) +SERIAL = os.environ.get("SIM_SERIAL", f"emulator-{5554 + 2 * WORKER}") +OUT = Path("/opt/taler-sim/run/out") +# Where the JaCoCo dumps land. Settable so that a run against a *different* +# build -- a patched APK, say -- can keep its dumps out of the campaign's +# report: JaCoCo keys classes by a hash of their bytecode, so dumps from two +# builds cannot be merged. +COVERAGE = Path(os.environ.get("SIM_COVERAGE_DIR", + "/opt/taler-sim/run/coverage")) +LOCAL_EXCHANGE = "http://localhost:8081/" +# The second exchange, if backend/exchange2.sh has been started beside the +# stack. Scenarios that need a choice check for it rather than assume it. +SECOND_EXCHANGE = "http://localhost:8091/" +# Services deployed beside the stack, with their own databases: the Taler +# mailbox (whose URL the wallet lets you type in) and the Taler directory +# (whose URL the app hard-codes, so only wallet-core can be pointed at it). +LOCAL_MAILBOX = "http://localhost:11000/" +LOCAL_TALDIR = "http://localhost:11001/" + + +class Ctx: + """What a scenario gets to work with.""" + + def __init__(self, ep: Episode, env: Env): + self.ep = ep + self.dev = ep.dev + self.app = ep.app + self.env = env + self.bank = Bank(env.bank) + self.merchant = Merchant(env.merchant) + self.cli = CliWallet() + self.notes: list[str] = [] + + # Tolerant helpers: a scenario says what it wants to touch, and missing + # optional elements do not abort the walk. + + def tap(self, pattern: str, timeout: int = 12) -> bool: + try: + self._tap_watching(pattern, timeout) + return True + except TimeoutError: + return False + + def must_tap(self, pattern: str, timeout: int = 30) -> None: + self._tap_watching(pattern, timeout) + + def accept_tos(self) -> bool: + """Get past the exchange's terms of service, if it has any.""" + accepted = flows.accept_tos(self.app) + if accepted: + self.note("accepted the exchange's terms of service") + self.check() + return accepted + + def tap_exact(self, pattern: str, timeout: int = 12) -> bool: + """Tap the matching node's own centre, with no hunt for an ancestor. + + `tap` and `tap_button` look for a clickable ancestor or neighbour when + the matching node is not itself clickable, which is right for a label + inside a button and wrong in three places this campaign has now hit: + + * a document picker's rows, where the hunt lands somewhere that + dismisses the picker without selecting (`pick_file_in_picker`); + * a Compose `AlertDialog`'s text buttons, where it dismissed the + mailbox address dialog instead of pressing Copy; + * a dropdown item, whose clickable ancestor is the menu rather than + the item. + + In all three the node's own centre is inside the real touch target, so + tapping it directly is both simpler and correct. Use this when the + thing being tapped is a row, a dialog button or a menu item. + """ + deadline = time.time() + timeout + rx = re.compile(pattern, re.I) + while time.time() < deadline: + screen = self.dev.dump() + node = next((n for n in screen.labelled() + if rx.search(n.label.strip())), None) + if node is not None: + self.dev.tap(*node.center) + return True + time.sleep(1) + return False + + def tap_button(self, pattern: str, timeout: int = 12) -> bool: + """Tap a *button* whose label is used elsewhere on the same screen. + + Several screens give the title and the submit button the same string -- + "Add account" is the app bar title, the list screen's add icon and the + form's submit button -- and `find` returns the first match, which is + the title. A title is not clickable, so its tap goes nowhere (or, via + the neighbour search, to the back arrow). This picks the lowest + matching node that is clickable or sits inside something clickable. + """ + deadline = time.time() + timeout + rx = re.compile(pattern, re.I) + while time.time() < deadline: + screen = self.dev.dump() + matches = [n for n in screen.labelled() if rx.search(n.label)] + targets = [] + for n in matches: + target = screen.tap_target(n) + if not (target.clickable and target.enabled): + continue + # tap_target also looks at clickable *neighbours*, which on + # this screen means a tab beside the title: a disabled submit + # button would otherwise be "tapped" by switching tabs. Only + # a target that is the label itself, or contains it, counts. + x, y = n.center + x1, y1, x2, y2 = target.bounds + if target is n or (x1 <= x <= x2 and y1 <= y <= y2): + targets.append(target) + if targets: + lowest = max(targets, key=lambda t: t.center[1]) + before = screen.signature() + self.dev.tap(*lowest.center) + time.sleep(1.2) + after = self.dev.dump() + fresh = self.ep.session.add(oracles.silent_failure( + self.dev, pattern, before, after.signature())) + for finding in fresh: + self.ep._capture(finding, after, None) + return True + time.sleep(1) + return False + + def _tap_watching(self, pattern: str, timeout: int) -> None: + """Tap, and notice when the tap achieves nothing but an error.""" + before = self.dev.dump() + screen = self.dev.tap_text(pattern, timeout=timeout) + time.sleep(1.2) + after = self.dev.dump() + fresh = self.ep.session.add(oracles.silent_failure( + self.dev, pattern, before.signature(), after.signature())) + for finding in fresh: + self.ep._capture(finding, after, None) + + def see(self, pattern: str, timeout: int = 15) -> Optional[Screen]: + try: + return self.dev.wait_for(pattern, timeout=timeout) + except TimeoutError: + return None + + def set_amount(self, chip: str = "€5.00", digits: str = "500") -> bool: + """Choose an amount, by quick-amount chip if the screen offers one. + + The amount fields do not always take injected text — focus does not + always follow the tap — but every amount screen also offers preset + chips, which is what a user would reach for anyway. + """ + screen = self.dev.dump() + preset = screen.find(rf"(?i)^{re.escape(chip)}$") + if preset is not None: + self.dev.tap_node(preset, screen) + time.sleep(1.5) + if self.dev.dump().find(rf"(?i){re.escape(chip)}"): + return True + return self.fill(digits) + + def require(self, pattern: str, timeout: int = 30) -> Screen: + """Insist on reaching a screen. + + Without this a scenario whose entry point silently fails to open still + reports "ok" having exercised nothing, which is worse than a failure: + it hides a gap behind a green row. + """ + screen = self.see(pattern, timeout=timeout) + if screen is None: + raise RuntimeError( + f"expected a screen matching {pattern!r}; " + f"got {self.dev.dump().texts()}" + ) + return screen + + def note(self, text: str) -> None: + self.notes.append(text) + + def uri_from_logcat(self, kind: str, timeout: int = 30) -> str: + """Pull a URI the wallet just generated out of wallet-core's log. + + The Send/Request screens show the URI as a QR code and in a copy + button, neither of which can be read from the view hierarchy, but + wallet-core logs its own response. + """ + import re as _re + pattern = _re.compile(r"taler(?:\+http)?://" + kind + r"/[A-Za-z0-9:._/?=&%-]+") + deadline = time.time() + timeout + while time.time() < deadline: + for match in pattern.finditer(self.dev.logcat()): + return match.group(0).rstrip('\\"\',.)') + time.sleep(2) + raise RuntimeError(f"no taler://{kind}/ URI in the log") + + def fill(self, value: str, which: int = 0, clear: bool = False) -> bool: + """Type into the n-th editable field on the current screen. + + Amount fields append digits from the right, as a cash register does: + typing "5" yields 0.05 and "500" yields 5.00. Scenarios therefore pass + the digit sequence they want, not a decimal string. + + `clear` empties a pre-filled field first. Deleting backwards from the + tap position leaves whatever was to the right of it -- which is how + "https://mailbox.gnunet.org" became + "http://localhost:11000unet.org" -- so the cursor goes to the end + first. + """ + screen = self.dev.dump() + fields = screen.editable() + if len(fields) <= which: + return False + field = fields[which] + if clear: + # Tapping the node's centre puts the cursor in the middle of the + # text, and KEYCODE_MOVE_END does not move it in a Compose field, + # so deleting backwards left the tail behind: tap just inside the + # right-hand edge instead, where the cursor lands after the last + # character. + x1, y1, x2, y2 = field.bounds + self.dev.tap(max(x1 + 1, x2 - 12), (y1 + y2) // 2) + time.sleep(0.5) + self.dev.shell("input keyevent " + " ".join(["KEYCODE_DEL"] * 80), + check=False) + time.sleep(0.5) + else: + self.dev.tap_node(field, screen) + time.sleep(0.5) + self.dev.type_text(value) + time.sleep(0.5) + return True + + def check(self) -> None: + """Run the oracles against the current screen.""" + self.ep.observe() + + def back_to_home(self) -> None: + self.app.home() + + +@dataclass +class Scenario: + name: str + setup: str # fresh | funded | paid | keep + fn: Callable[[Ctx], None] + about: str = "" + # Finding kinds this scenario provokes on purpose: corrupting the database + # is supposed to produce an init error, and pointing the wallet at a dead + # host is supposed to produce connection failures. Reporting those as + # defects every round would bury the real ones. + expects: tuple[str, ...] = () + + +REGISTRY: dict[str, Scenario] = {} + + +def scenario(name: str, setup: str = "keep", about: str = "", + expects: tuple[str, ...] = ()) -> Callable: + def register(fn: Callable[[Ctx], None]) -> Callable[[Ctx], None]: + REGISTRY[name] = Scenario(name=name, setup=setup, fn=fn, + about=about or fn.__doc__ or "", expects=expects) + return fn + return register + + +# --------------------------------------------------------------- navigation --- + +# Section headers and chips that sit below "Recent transactions" but are not +# transactions themselves. +BELOW_BUT_NOT_A_TRANSACTION = ( + "all", "discounts", "passes", "donation statements", "other assets", + "settings", "internal event log", "scan qr code", "contacts", "pending", + "where to pay", "shopping", + # The dedicated transactions screen puts the balance card between its app + # bar and the list, and that card carries an unsigned amount and a + # relative time -- enough to be taken for a transaction, whose row then + # swallowed every long press aimed at the first "transaction". + "balance", +) +# A transaction row always carries a relative time and a signed amount; either +# is enough to tell it apart from a header or a chip. +TIME_LABEL = re.compile(r"(?i)\b(ago|yesterday|today)\b|\d{1,2}:\d\d|\d{4}") +AMOUNT_LABEL = re.compile(r"^[+\-\u2212]?\s*\d+[.,]\d\d$") +# Only a transaction's amount carries a sign; a balance is printed bare. +SIGNED_AMOUNT_LABEL = re.compile(r"^[+\-\u2212]\s*\d+[.,]\d\d$") + + +def open_transactions(c: Ctx) -> Screen: + """The main screen lists the recent transactions itself. + + There is no separate list screen: the balance pager shows a "Recent + transactions" header with the transactions under it, and tapping one opens + its detail screen. + """ + c.back_to_home() + screen = c.dev.dump() + if screen.find(r"(?i)^Recent transactions$") is None: + try: + screen = c.app.scroll_to_text(r"(?i)^Recent transactions$", max_scrolls=4) + except TimeoutError: + c.note("no transaction section on the main screen") + return screen + + +def open_exchange_list(c: Ctx) -> None: + """Settings -> Payment services, the exchange list.""" + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Payment services$") + c.must_tap(r"(?i)^Payment services$") + c.see(r"(?i)Add payment service|Currency:|No payment services") + + +def exchange_menu(c: Ctx, which: str = "localhost") -> bool: + """Open the per-exchange menu, whose label embeds the exchange URL.""" + return c.tap(rf"(?i)^Menu: .*{which}", timeout=25) + + +def transaction_rows(screen: Screen, + header: str = r"(?i)^Recent transactions$", + signed_only: bool = False) -> list: + """One tap target per transaction listed under the header. + + Nodes are grouped into horizontal bands, because a row is several nodes + (time, title, amount); a band counts as a transaction when something in it + looks like a time or a signed amount, which keeps the filter chips and the + "Discounts"/"Passes" sections out. + + The default header is the main screen's section title. The dedicated + transactions screen behind the "All" chip has no such header -- its rows + sit under the app bar -- so a caller there passes the screen's own title + instead, and the banding works the same way. + """ + header_node = screen.find(header) + if header_node is None: + return [] + top = header_node.center[1] + bands: dict[int, list] = {} + for node in screen.tappable(): + label = node.label.strip() + if not label or node.center[1] <= top: + continue + bands.setdefault(node.center[1] // 110, []).append(node) + rows = [] + for band in sorted(bands): + nodes = bands[band] + labels = [n.label.strip() for n in nodes] + if any(l.lower() in BELOW_BUT_NOT_A_TRANSACTION for l in labels): + continue + # With signed_only, a band needs an amount carrying a sign. The + # dedicated transactions screen shows a balance card above the list, + # and its parts -- the currency, the exchange URL, the bare amount -- + # band into something that looks exactly like a transaction; the first + # "row" there was the exchange URL, which swallowed every long press. + amount = SIGNED_AMOUNT_LABEL if signed_only else AMOUNT_LABEL + if signed_only: + if not any(amount.match(l) for l in labels): + continue + elif not any(TIME_LABEL.search(l) or amount.match(l) for l in labels): + continue + # Prefer the title over the time or the amount as the tap target. + target = next((n for n in nodes + if not TIME_LABEL.search(n.label.strip()) + and not AMOUNT_LABEL.match(n.label.strip()) + and "://" not in n.label), nodes[0]) + rows.append(target) + return rows + + +# ---------------------------------------------------------------- scenarios --- + +@scenario("history", setup="paid", about="transaction list, details, JSON view, filters") +def s_history(c: Ctx) -> None: + screen = open_transactions(c) + c.note(f"main screen: {screen.texts()[:14]}") + rows = transaction_rows(screen) + c.note(f"{len(rows)} transaction rows: {[n.label[:28] for n in rows]}") + opened = 0 + for index in range(min(len(rows), 4)): + screen = open_transactions(c) + rows = transaction_rows(screen) + if index >= len(rows): + break + c.dev.tap_node(rows[index], screen) + time.sleep(2) + detail = c.dev.dump() + if detail.find(r"(?i)^Show JSON$|completed successfully|^Delete$|^Transaction$"): + opened += 1 + c.note(f"detail {index}: {detail.texts()[:10]}") + c.check() + # The raw JSON view is dev-mode only and renders the whole + # transaction record. + if c.tap(r"(?i)^Show JSON$", timeout=10): + c.check() + c.dev.back() + time.sleep(1) + else: + c.note(f"row {index} did not open a detail screen: {detail.texts()[:8]}") + c.dev.back() + time.sleep(1) + c.note(f"opened {opened} transaction detail screens") + if opened == 0 and rows: + raise RuntimeError("transaction rows present but none opened a detail screen") + c.check() + + +@scenario("history_delete", setup="paid", about="delete a finished transaction") +def s_history_delete(c: Ctx) -> None: + screen = open_transactions(c) + rows = transaction_rows(screen) + before = len(rows) + if not rows: + raise RuntimeError(f"no transaction rows to delete; screen: {screen.texts()}") + c.dev.tap_node(rows[0], screen) + time.sleep(1.5) + c.must_tap(r"(?i)^Delete$") + # A confirmation dialog guards the deletion. + if c.see(r"(?i)Delete transaction|Are you sure"): + c.tap(r"(?i)^Delete$|^OK$|^Yes$") + time.sleep(2) + after = len(transaction_rows(open_transactions(c))) + c.note(f"transaction rows before={before} after={after}") + if after >= before: + c.note("WARNING: the row count did not drop after deleting") + c.check() + + +@scenario("withdraw_suspend_resume", setup="fresh", + about="suspend a pending withdrawal, then resume it") +def s_withdraw_suspend_resume(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + # The transaction now waits for the bank; its detail screen offers the + # lifecycle actions. + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + c.must_tap(r"(?i)^Suspend$") + if c.see(r"(?i)Are you sure|Suspend"): + c.tap(r"(?i)^Suspend$|^OK$|^Yes$", timeout=6) + time.sleep(2) + detail = c.dev.dump() + c.note("suspended, on its detail screen: " + str(detail.texts()[:12])) + c.check() + # What the *list* says about it: the detail screen says "This transaction + # is suspended", and the row is what a user scanning their history sees. + row_texts = [] + c.back_to_home() + listed = c.dev.dump() + rows = transaction_rows(listed) + if rows: + band = rows[0].bounds + row_texts = [n.label for n in listed.labelled() + if abs(n.bounds[1] - band[1]) < 120] + c.note(f"its row in the list: {row_texts}") + if row_texts and not any("suspend" in t.lower() for t in row_texts): + c.note("WARNING: nothing on the row says the transaction is suspended") + c.check() + rows = transaction_rows(c.dev.dump()) + if rows: + c.dev.tap_node(rows[0]) + time.sleep(2.5) + c.must_tap(r"(?i)^Resume$", timeout=30) + time.sleep(2) + c.note("resumed; screen: " + str(c.dev.dump().texts()[:8])) + c.check() + + +@scenario("withdraw_suspend_abort", setup="fresh", + about="suspend a pending withdrawal, then abort it") +def s_withdraw_suspend_abort(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + c.must_tap(r"(?i)^Suspend$") + time.sleep(2) + c.must_tap(r"(?i)^Abort$", timeout=30) + if c.see(r"(?i)Abort transaction|Are you sure"): + c.tap(r"(?i)^Abort$|^OK$|^Yes$") + time.sleep(3) + c.note("after abort: " + str(c.dev.dump().texts()[:10])) + c.check() + + +@scenario("withdraw_abort", setup="fresh", about="abort a withdrawal before the bank confirms") +def s_withdraw_abort(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + c.must_tap(r"(?i)^Abort$") + if c.see(r"(?i)Abort transaction|Are you sure"): + c.tap(r"(?i)^Abort$|^OK$|^Yes$") + time.sleep(3) + status = c.bank.withdrawal_status(op["withdrawal_id"]) + c.note(f"bank-side status after abort: {status.get('status')}") + # What the aborted transaction says about itself: nothing was withdrawn, so + # "Fee -<the whole amount>" would be a misstatement. Aborting navigates + # back to the list, so the detail screen has to be opened again. + aborted = c.dev.dump() + if aborted.find(r"(?i)was aborted|has failed") is None: + open_transactions(c) + rows = transaction_rows(c.dev.dump()) + if rows: + c.dev.tap_node(rows[0]) + time.sleep(2.5) + aborted = c.dev.dump() + c.note("aborted withdrawal: " + str(aborted.texts()[:14])) + labels = aborted.texts() + if "Fee" in labels: + fee_node = aborted.find(r"(?i)^Fee$") + amounts = [t for t in labels if re.match(r"^[-−]?[€$]?\d", t)] + c.note(f"amounts beside Fee: {amounts[:6]}") + if any(t.lstrip("-−").lstrip("€$") == "5.00" for t in amounts): + c.note("WARNING: the whole chosen amount is shown as a fee") + c.check() + + +@scenario("withdraw_abandon", setup="fresh", about="abandon (fail) a pending withdrawal") +def s_withdraw_abandon(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + if not c.tap(r"(?i)^Abandon$", timeout=20): + # Abandon is only offered in some states; suspend first and look again. + c.tap(r"(?i)^Suspend$") + if not c.tap(r"(?i)^Abandon$", timeout=20): + c.note("Abandon not offered for a withdrawal waiting on the bank") + return + if c.see(r"(?i)Abandon transaction|Are you sure"): + c.tap(r"(?i)^Abandon$|^OK$|^Yes$") + time.sleep(3) + c.check() + + +# "funded" rather than "fresh": the exchange menu only exists once the wallet +# knows the local exchange, which the first withdrawal is what teaches it. +@scenario("withdraw_manual", setup="funded", + about="manual withdrawal from the exchange menu: wire instructions and QR") +def s_withdraw_manual(c: Ctx) -> None: + open_exchange_list(c) + if not exchange_menu(c): + raise RuntimeError(f"no exchange menu; screen: {c.dev.dump().texts()}") + if not c.tap(r"(?i)^Withdraw$"): + c.note("no manual withdraw entry in the exchange menu") + return + screen = c.see(r"(?i)Withdraw|amount|Confirm", timeout=30) + fields = screen.editable() if screen else [] + if fields: + c.dev.tap_node(fields[0], screen) + c.dev.type_text("5") + c.accept_tos() + c.tap(r"(?i)^Withdraw$|Confirm withdrawal", timeout=20) + # Wire transfer instructions, with the QR variants below them. + if c.see(r"(?i)Wire transfer instructions|Subject|IBAN|Recipient", timeout=40): + c.note("reached manual withdrawal instructions") + c.app.scroll_to_text(r"(?i)Wire transfer QR codes|Open in banking app", max_scrolls=5) + c.check() + + +@scenario("payment_abort", setup="funded", about="decline a payment at the prompt") +def s_payment_abort(c: Ctx) -> None: + order = c.merchant.create_order("EUR:1", summary="Order the wallet will decline") + c.app.handle_uri(order["pay_uri"]) + c.see(r"(?i)Review order|Total:|^Pay", timeout=60) + c.must_tap(r"(?i)^Cancel$") + time.sleep(2) + status = c.merchant.order_status(order["order_id"], order["token"]) + c.note(f"order status after cancel: {status.get('order_status')}") + c.check() + + +@scenario("payment_insufficient", setup="funded", + about="an order larger than the balance, and what the Pay button does") +def s_payment_insufficient(c: Ctx) -> None: + order = c.merchant.create_order("EUR:99", summary="More than the wallet holds") + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)insufficient|not enough|balance|Review order", timeout=40) + c.note("screen: " + str(screen.texts()[:12])) + pay = screen.find(r"(?i)^Pay ") + if pay is not None: + button = screen.tap_target(pay) + c.note(f"Pay button present with an insufficient balance: " + f"label={pay.label!r} enabled={button.enabled} " + f"clickable={button.clickable}") + # Offering it is only a problem if it can actually be pressed. + if button.enabled and button.clickable: + c.dev.tap_node(pay, screen) + time.sleep(4) + after = c.dev.dump() + c.note("after pressing Pay anyway: " + str(after.texts()[:12])) + status = c.merchant.order_status(order["order_id"], order["token"]) + c.note(f"merchant says: {status.get('order_status')}") + c.check() + else: + c.note("no Pay button offered, which is the expected behaviour") + c.check() + c.ep.check_database() + + +@scenario("payment_twice", setup="funded", about="pay the same order twice") +def s_payment_twice(c: Ctx) -> None: + order = flows.pay(c.app, c.merchant, "EUR:1", summary="Paid once already") + c.app.home() + c.app.handle_uri(order["pay_uri"]) + c.see(r"(?i)already paid|paid|Error|Review order", timeout=40) + c.note("second attempt: " + str(c.dev.dump().texts()[:10])) + c.check() + + +@scenario("refund", setup="funded", about="take a refund for a paid order") +def s_refund(c: Ctx) -> None: + order = flows.pay(c.app, c.merchant, "EUR:2", summary="Order to be refunded") + c.app.home() + res = c.merchant.refund(order["order_id"], "EUR:1") + uri = res.get("taler_refund_uri") + if not uri: + raise RuntimeError(f"merchant returned no refund uri: {res}") + c.app.handle_uri(uri) + time.sleep(3) + c.note("after refund uri: " + str(c.dev.dump().texts()[:10])) + open_transactions(c) + c.check() + + +@scenario("exchange_add_remove", setup="fresh", about="add an exchange by URL, then delete it") +def s_exchange_add_remove(c: Ctx) -> None: + open_exchange_list(c) + c.must_tap(r"(?i)^Add payment service$") + screen = c.require(r"(?i)Enter address of payment service|address", timeout=30) + fields = screen.editable() if screen else [] + if not fields: + raise RuntimeError(f"no URL field on the add screen: {screen.texts() if screen else None}") + c.dev.tap_node(fields[0], screen) + c.dev.type_text(LOCAL_EXCHANGE) + c.tap(r"(?i)^Add$|^OK$|^Continue$|^Next$") + time.sleep(4) + c.check() + # Now remove it again. + open_exchange_list(c) + if exchange_menu(c): + if c.tap(r"(?i)^Delete payment service$"): + if c.see(r"(?i)Force deletion|Are you sure|Delete"): + c.tap(r"(?i)^Delete$|^OK$|^Yes$", timeout=8) + time.sleep(2) + c.note("deleted the local exchange") + c.check() + + +@scenario("exchange_tos", setup="fresh", about="view, reject and re-accept terms of service") +def s_exchange_tos(c: Ctx) -> None: + # Contact the exchange first so there are terms to look at. + flows.withdraw(c.app, c.bank, "EUR:5") + open_exchange_list(c) + if not exchange_menu(c): + raise RuntimeError(f"no exchange menu; screen: {c.dev.dump().texts()}") + if c.tap(r"(?i)^Review terms of service$"): + shown = c.see(r"(?i)Terms of Service|Accept|terms", timeout=30) + c.check() + # The language selector only exists when the exchange offers more than + # one language, which is why backend/stack.sh renders the terms in + # English *and* German (exchange-tos-tops-v0 ships both). + if shown is not None and shown.find(r"(?i)^Language$") is not None: + before = [x for x in shown.texts() if len(x) > 40][:1] + c.tap(r"(?i)^Language$", timeout=10) + time.sleep(2) + menu = c.dev.dump() + # The menu items are text nodes whose clickable ancestor is the + # row, so they do not appear in tappable() -- looking there found + # nothing and read as "the exchange offers one language". + known = ("English", "German", "Deutsch", "French", "Français") + offered = [n for n in menu.labelled() if n.label.strip() in known] + c.note(f"languages offered: {[n.label.strip() for n in offered]}") + other = next((n for n in offered + if n.label.strip() != "English"), None) + if other is not None and (c.dev.tap(*other.center) or True): + time.sleep(3) + after = c.dev.dump() + body = [x for x in after.texts() if len(x) > 40][:1] + c.note(f"after picking {other.label.strip()!r}: {str(body)[:160]}") + if before and body and before == body: + c.note("the terms text did not change with the language") + c.check() + else: + c.note("no language selector on the terms screen: " + + str(shown.texts()[:10] if shown else None)) + c.dev.back() + open_exchange_list(c) + exchange_menu(c) + if c.tap(r"(?i)^Reject terms of service$"): + time.sleep(2) + c.note("rejected the terms of service") + c.check() + open_exchange_list(c) + exchange_menu(c) + if c.tap(r"(?i)^Accept Terms of Service$|^Review terms of service$"): + c.tap(r"(?i)^Accept$|I accept|^Confirm$", timeout=20) + c.check() + + +@scenario("exchange_reload_global", setup="funded", + about="reload exchange info and toggle global-currency treatment") +def s_exchange_reload_global(c: Ctx) -> None: + open_exchange_list(c) + if not exchange_menu(c): + raise RuntimeError(f"no exchange menu; screen: {c.dev.dump().texts()}") + menu = c.dev.dump() + c.note("exchange menu: " + str(menu.texts()[:14])) + if c.tap(r"(?i)^Reload information$"): + time.sleep(3) + c.note("after reloading: " + str(c.dev.dump().texts()[:12])) + c.check() + else: + c.note("no 'Reload information' entry in the menu") + open_exchange_list(c) + exchange_menu(c) + if c.tap(r"(?i)^Treat as global$"): + time.sleep(3) + c.note("after treat-as-global: " + str(c.dev.dump().texts()[:12])) + c.check() + open_exchange_list(c) + exchange_menu(c) + after = c.dev.dump() + c.note("menu now offers: " + str(after.texts()[:14])) + if after.find(r"(?i)Stop treating as global") is None: + c.note("WARNING: the exchange was not marked global; the menu is " + "unchanged, which is what the null master key bug looks like") + c.tap(r"(?i)^Stop treating as global$") + time.sleep(2) + c.note("after stopping: " + str(c.dev.dump().texts()[:12])) + else: + c.note("no 'Treat as global' entry in the menu") + c.check() + + +@scenario("exchange_dev_add", setup="fresh", about="add the built-in development exchanges") +def s_exchange_dev_add(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Add development payment services$") + c.must_tap(r"(?i)^Add development payment services$") + time.sleep(4) + c.note("exchange list: " + str(c.dev.dump().texts()[:14])) + c.check() + + +@scenario("settings_walk", setup="funded", about="visit every settings row and toggle the switches") +def s_settings_walk(c: Ctx) -> None: + # Every row except the destructive ones and the two that talk to + # demo.taler.net; those have their own scenarios. + rows = [ + r"(?i)^Payment services$", + r"(?i)^Bank accounts$", + r"(?i)^Tax-deductible donations$", + r"(?i)^Performance stats$", + r"(?i)^Upgrade wallet database$", + r"(?i)^App version$", + r"(?i)^Wallet Core version$", + ] + for row in rows: + c.app.open_settings() + try: + c.app.scroll_to_text(row, max_scrolls=10) + except TimeoutError: + c.note(f"row not present: {row}") + continue + if c.tap(row): + time.sleep(1.5) + c.check() + c.note(f"visited {row}: {c.dev.dump().texts()[:6]}") + # The switches: flip each one off and on again. + for switch in (r"(?i)^Protect access to wallet$", r"(?i)^Developer mode$"): + c.app.open_settings() + try: + screen = c.app.scroll_to_text(switch, max_scrolls=10) + except TimeoutError: + continue + node = screen.find(switch) + if node is None: + continue + width, _ = c.dev.size() + _, y = node.center + c.dev.tap(width - 100, y) + time.sleep(2) + c.check() + c.dev.tap(width - 100, y) + time.sleep(2) + c.check() + # Developer mode must survive the round trip, or later scenarios break. + c.app.enable_dev_mode() + c.check() + + +def save_through_picker(c: Ctx, timeout: int = 30) -> bool: + """Carry a "save as" through the system document picker. + + The wallet hands off to DocumentsUI, which prefills a file name and offers + SAVE; without completing it the export never runs at all. + """ + screen = c.see(r"(?i)^SAVE$|Files in Downloads", timeout=timeout) + if screen is None: + return False + if not c.tap(r"(?i)^SAVE$", timeout=15): + return False + time.sleep(4) + return True + + +def pick_file_in_picker(c: Ctx, pattern: str = r"taler-wallet-db.*\.json", + timeout: int = 25) -> bool: + """Choose the newest matching file in DocumentsUI and wait for the hand-back. + + Three things here are easy to get wrong, and all three were: + + * the picker labels the row with the file name *and* the thumbnail with + "Preview the file <name>", so matching the name alone hits the preview; + * it lists newest first, so "the last row" is the *oldest* file -- which + for these exports is the one taken from an emptiest wallet, and + importing it looks exactly like an import that lost everything; + * `Screen.tap_target` hunts for a clickable ancestor or neighbour, and on + these rows that lands somewhere that dismisses the picker without + selecting, so the import never runs at all. + + So: skip the preview labels, pick the greatest *name* (they are + timestamps), and tap the label's own centre. + + Note also that `adb shell ls /sdcard/Download` and the picker disagree: + the shell sees its own scoped view, while the picker lists MediaStore, + which still holds everything the app wrote. Deleting old exports from the + shell therefore does not clear the picker. + """ + rx = re.compile(pattern, re.I) + preview = re.compile(r"(?i)^preview\b") + deadline = time.time() + timeout + while time.time() < deadline: + screen = c.dev.dump() + rows = [n for n in screen.labelled() + if rx.search(n.label) and not preview.match(n.label.strip())] + if rows: + newest = max(rows, key=lambda n: n.label.strip()) + c.note(f"picking {newest.label.strip()!r} of " + f"{len(rows)} offered") + c.dev.tap_node(newest, screen) + break + time.sleep(1.5) + else: + c.note(f"no file matching {pattern!r} in the picker: " + + str(c.dev.dump().texts()[:12])) + return False + # Some pickers need the selection confirmed. + for label in (r"(?i)^(OPEN|SELECT|DONE)$",): + c.tap(label, timeout=4) + # Handing back means the app is in the foreground again. + deadline = time.time() + 25 + while time.time() < deadline: + where = c.dev.dump().activity + if where.startswith(PKG): + return True + time.sleep(2) + c.note(f"the picker did not hand back to the wallet (now in {where}): " + + str(c.dev.dump().texts()[:10])) + return False + + +@scenario("settings_export", setup="funded", + about="database and log export, carried through the save dialog") +def s_settings_export(c: Ctx) -> None: + exported = [] + for row in (r"(?i)^Export database$", r"(?i)^Export raw database$", + r"(?i)^Debug log$"): + c.app.open_settings() + try: + c.app.scroll_to_text(row, max_scrolls=10) + except TimeoutError: + c.note(f"row not present: {row}") + continue + c.tap(row) + time.sleep(2) + # The database exports warn first, because the file holds the money. + if c.see(r"(?i)sensitive data|Export anyway", timeout=8): + c.note(f"{row}: warned before exporting") + c.tap(r"(?i)^Export anyway$", timeout=8) + if save_through_picker(c): + exported.append(row) + c.check() + else: + c.note(f"{row}: no save dialog appeared") + c.dev.back() + time.sleep(1.5) + c.check() + listing = c.dev.shell("ls -la /sdcard/Download/", check=False) + c.note(f"exported {len(exported)} file(s); Download now holds: " + f"{[l.split()[-1] for l in listing.splitlines()[1:] if l.strip()][:5]}") + c.app.home() + c.ep.check_database() + + +@scenario("settings_import", setup="funded", + about="export the database, then import it back") +def s_settings_import(c: Ctx) -> None: + # Export first, so there is something to import. + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Export database$", max_scrolls=10) + c.must_tap(r"(?i)^Export database$") + if c.see(r"(?i)sensitive data|Export anyway", timeout=8): + c.tap(r"(?i)^Export anyway$", timeout=8) + if not save_through_picker(c): + c.note("could not export, so there is nothing to import") + return + c.check() + + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Import database$", max_scrolls=10) + c.must_tap(r"(?i)^Import database$") + if c.see(r"(?i)overwrite|Do you want", timeout=15): + c.tap(r"(?i)^OK$|^Import$|^Yes$|^Continue$", timeout=10) + screen = c.see(r"(?i)taler-wallet-db|Files in Downloads|Downloads", timeout=25) + if screen is None: + c.note("no document picker for the import") + return + c.note("picker: " + str(screen.texts()[:10])) + if not pick_file_in_picker(c): + c.dev.back() + return + time.sleep(8) + c.note("after importing: " + str(c.dev.dump().texts()[:12])) + log = c.dev.logcat() + if "importDb" in log: + c.note("importDb reached wallet-core") + else: + c.note("WARNING: the file was picked but importDb never ran") + c.check() + # The wallet has to still work on the imported database. + c.back_to_home() + rows = transaction_rows(open_transactions(c)) + c.note(f"{len(rows)} transactions after the import") + c.check() + c.ep.check_database() + + +@scenario("settings_import_bad_file", setup="funded", + about="import a file that is not a wallet database") +def s_settings_import_bad_file(c: Ctx) -> None: + """The import's error path. + + `SettingsManager.importDb` reads the chosen file as text, parses it as + JSON, and hands the object to wallet-core; anything that is not JSON + throws before the request and lands in `onDbImportError`. The suite's + other import scenarios always pick a genuine export, so that branch -- and + the "Error importing database" it shows -- had never run. + + The file is written straight into Downloads and scanned into MediaStore, + because the picker lists MediaStore rather than the shell's view of the + directory. + """ + name = f"sim-not-a-db-{int(time.time())}.json" + path = f"/sdcard/Download/{name}" + c.dev.shell(f"echo 'this is not a wallet database' > {path}", check=False) + c.dev.shell("content call --uri content://media/external/file " + f"--method scan_file --arg {path}", check=False) + listed = c.dev.shell(f"ls -l {path}", check=False) + c.note(f"planted {name}: {listed.strip()[:100]}") + c.dev.logcat(clear=True) + + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Import database$", max_scrolls=10) + c.must_tap(r"(?i)^Import database$") + if c.see(r"(?i)overwrite|Do you want", timeout=15): + c.tap(r"(?i)^OK$|^Import$|^Yes$|^Continue$", timeout=10) + screen = c.see(r"(?i)Files in Downloads|Downloads|sim-not-a-db", timeout=25) + if screen is None: + c.note("no document picker for the import") + return + c.note("picker: " + str(screen.texts()[:10])) + if not pick_file_in_picker(c, pattern=r"sim-not-a-db.*\.json"): + c.note("could not pick the planted file; the picker showed " + + str(c.dev.dump().texts()[:12])) + c.dev.back() + return + # The error is a Toast (SettingsManager.onDbImportError), and LENGTH_LONG + # is about three and a half seconds: dumping at +6s missed it entirely and + # made it look as though nothing was reported. Look early and repeatedly. + shown = False + after = c.dev.dump() + for _ in range(6): + after = c.dev.dump() + if after.find(r"(?i)Error importing database") is not None: + shown = True + break + time.sleep(1) + c.note("after importing rubbish: " + str(after.texts()[:12])) + log = c.dev.logcat() + logged = "Error importing db" in log + # Not an assertion: the feedback is a Toast, and a Toast is a system + # window that a hierarchy dump does not reliably contain. "False" here + # means the harness could not see it, not that a user cannot. What can + # be asserted is that the failure was detected at all. + c.note(f"the error toast was visible to the dump: {shown}") + c.note(f"the failure reached the log: {logged}") + if not logged: + c.note("WARNING: importing a non-database was not reported anywhere " + "this harness can see") + c.check() + + # And the wallet has to be usable afterwards: a failed import must not + # have touched the database it was going to replace. + c.back_to_home() + home = c.dev.dump() + c.note("home after the failed import: " + str(home.texts()[:12])) + if home.find(r"€|EUR") is None: + c.note("WARNING: no balance on the main screen after a failed import") + c.check() + c.dev.shell(f"rm -f {path}", check=False) + c.ep.check_database() + + +@scenario("settings_import_cancel", setup="funded", about="start a database import and cancel it") +def s_settings_import_cancel(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Import database$", max_scrolls=10) + c.must_tap(r"(?i)^Import database$") + asked = c.see(r"(?i)overwrite|Do you want|Cancel", timeout=20) + c.note("import prompt: " + str((asked or c.dev.dump()).texts()[:12])) + if asked: + c.tap(r"(?i)^Cancel$|^No$") + else: + c.note("WARNING: importing a database asked nothing before proceeding") + time.sleep(1.5) + c.dev.back() + c.note("back in settings: " + str(c.dev.dump().texts()[:10])) + c.check() + + +@scenario("settings_reset_confirmed", setup="funded", + about="confirm the wallet reset, which is the only caller of clearDb") +def s_settings_reset_confirmed(c: Ctx) -> None: + """Reset Wallet, carried through. + + `settings_reset_cancel` backs out of this dialog; nothing confirmed it, so + `clearDb` was one of the last wallet-core operations no scenario reached. + + The dialog is also worth looking at: the destructive action is the + *negative* button and Cancel is the *positive* one + (`settings/SettingsScreen.kt:361`), so Android draws "Reset" where + convention puts "Cancel". + """ + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Reset Wallet", max_scrolls=12) + c.must_tap(r"(?i)^Reset Wallet") + dialog = c.require(r"(?i)really want to reset|lose all coins", timeout=20) + buttons = [(n.label.strip(), n.center[0]) for n in dialog.tappable() + if n.label.strip() in ("Reset", "Cancel")] + c.note(f"the reset dialog's buttons, left to right: " + + str(sorted(buttons, key=lambda b: b[1]))) + c.check() + if not c.tap_button(r"(?i)^Reset$", timeout=15): + c.note("no Reset button in the dialog: " + str(dialog.texts()[:10])) + return + time.sleep(8) + after = c.dev.dump() + c.note("after resetting: " + str(after.texts()[:12])) + c.check() + log = c.dev.logcat() + if "clearDb" not in log: + c.note("WARNING: the reset did not reach clearDb") + # A reset wallet is an empty wallet. + balances = c.app.balances() + c.note(f"balance after the reset: {balances}") + if any(re.search(r"[1-9]", b) for b in balances): + c.note("WARNING: coins survived a wallet reset") + c.check() + c.ep.check_database() + + +@scenario("settings_reset_cancel", setup="funded", about="open the wallet reset dialog and cancel") +def s_settings_reset_cancel(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Reset Wallet", max_scrolls=10) + c.must_tap(r"(?i)^Reset Wallet") + if c.see(r"(?i)really want to reset|lose all coins|Cancel", timeout=20): + c.tap(r"(?i)^Cancel$|^No$") + time.sleep(2) + c.note("after cancelling the reset: " + str(c.dev.dump().texts()[:8])) + c.check() + + +@scenario("scan_manual_entry", setup="funded", + about="the scan screen's manual link entry, fed hostile input") +def s_scan_manual_entry(c: Ctx) -> None: + hostile = ["", "taler://", "not a uri at all", + corpus.MALFORMED["bad_base32"], corpus.MALFORMED["id_too_long"], + corpus.MALFORMED["unicode"], corpus.STRUCTURAL["pay"]] + for value in hostile: + try: + screen = c.app.open_scanner() + except TimeoutError: + c.note("could not open the scan screen: " + + str(c.dev.dump().texts()[:10])) + return + fields = screen.editable() if screen else [] + if not fields: + c.note("scan screen has no text field: " + str(screen.texts() if screen else None)) + c.dev.back() + continue + c.dev.tap_node(fields[0], screen) + if value: + c.dev.type_text(value) + c.dev.key("KEYCODE_ENTER") + time.sleep(2.5) + c.check() + c.dev.back() + time.sleep(1) + c.check() + + +def tap_if_any(c: Ctx, patterns: tuple[str, ...], timeout: int = 6) -> bool: + """Tap the first of these labels that is present, if any.""" + for pattern in patterns: + if c.tap(pattern, timeout=timeout): + return True + return False + + +def fill_account_note(c: Ctx, label: str = "Simulator account") -> bool: + """Fill the add-account form's required "Note" field. + + The form is a LazyColumn, so the note is often below the fold and absent + from the view hierarchy altogether -- filling "the last editable field" + then types into Town instead, leaves the note empty, and the submit button + stays disabled with nothing to show for it + (findings/add-account-note-is-required-but-unmarked.md). + """ + try: + c.app.scroll_to_text(r"(?i)^Note$", max_scrolls=6) + except TimeoutError: + c.note("no Note field on this screen: " + str(c.dev.dump().texts()[:10])) + return False + fields = c.dev.dump().editable() + if not fields: + c.note("the add-account form has no editable fields") + return False + return c.fill(label, len(fields) - 1, clear=True) + + +def amount_value(amount: str) -> float: + """The numeric part of a "EUR:12.34" amount.""" + try: + return float(amount.split(":", 1)[1]) + except (IndexError, ValueError): + return float("nan") + + +@scenario("deposit", setup="funded", about="deposit coins back to a bank account") +def s_deposit(c: Ctx) -> None: + """A deposit that is checked, not just watched. + + This noted the bank balance before and after and passed either way, so it + reported "ok" for thirteen rounds while depositing nothing at all: the + balance was identical every time, because the payto link it used is one the + wallet refuses (findings/payto-link-only-accepts-iban.md). + """ + before = c.bank.balance(*flows.WALLET_USER) + screen = flows.deposit_to_bank(c.app, c.env, "100") + c.note("after the deposit: " + str(screen.texts()[:12])) + c.check() + # The exchange has to aggregate and wire it, which is not instant. + deadline = time.monotonic() + 120 + after = before + while time.monotonic() < deadline: + after = c.bank.balance(*flows.WALLET_USER) + if amount_value(after) > amount_value(before): + break + time.sleep(5) + c.note(f"bank balance {before} -> {after}") + if not amount_value(after) > amount_value(before): + raise RuntimeError( + f"the deposit did not reach the bank: balance stayed at {after} " + f"(screen: {c.dev.dump().texts()[:12]})") + c.check() + + +@scenario("deposit_payto_link", setup="funded", + about="a payto link for a non-IBAN account, which the wallet refuses") +def s_deposit_payto_link(c: Ctx) -> None: + """Pins the refusal, so a fix shows up here. + + `DepositManager.isSupportedPayToUri` accepts `payto://iban/...` only, so + the x-taler-bank account the wallet withdraws from -- and deposits to + perfectly well when it is picked from the account list -- cannot be reached + by a link. + """ + screen = flows.deposit_via_payto_link(c.app, c.env) + refused = screen.find(r"(?i)Not a valid Taler link") is not None + c.note(f"x-taler-bank payto link refused: {refused} -- " + + str(screen.texts()[:10])) + if not refused: + c.note("the wallet now accepts an x-taler-bank payto link; " + "payto-link-only-accepts-iban.md may be fixed") + c.check() + + +# Everyday configuration changes, each of which restarts the app. The wallet +# has to come back usable from all of them; one of them does not. +# Each change carries the API level the *driver* needs to make it: a per-app +# language is API 33+, so asking for one on an older device tests adb rather +# than the wallet, and reports a pass or a failure that means nothing. +CONFIG_CHANGES = ( + ("app language", 33, "cmd locale set-app-locales {pkg} --locales de-DE", + "cmd locale set-app-locales {pkg} --locales"), + ("dark mode", 29, "cmd uimode night yes", "cmd uimode night no"), + ("font size", 24, "settings put system font_scale 1.30", + "settings put system font_scale 1.0"), + ("display size", 24, "wm density 480", "wm density reset"), +) + + +def undo_of(name: str) -> str: + for n, _, _, undo in CONFIG_CHANGES: + if n == name: + return undo + raise KeyError(name) + + +INIT_ERROR = (r"(?i)Initialization error|Initialisierungsfehler" + r"|error occurred while starting|Fehler aufgetreten") + + +@scenario("config_changes", setup="funded", + about="change the language, theme, font and display size mid-flow", + expects=("error-screen", "internal-error-code")) +def s_config_changes(c: Ctx) -> None: + """Does the wallet survive what Android does to every app? + + Each of these recreates the activity -- and restarts the app -- while the + wallet is open. Changing the language loses the race for the SQLite + database and dead-ends on the Initialization error screen + (`config-change-locks-the-wallet-out-of-its-database.md`), so the others + are worth measuring in the same place. + """ + pkg = c.dev.pkg + broken: list[str] = [] + try: + for name, needs_api, apply_cmd, _ in CONFIG_CHANGES: + if c.dev.sdk_int < needs_api: + c.note(f"{name}: skipped, the driver needs API {needs_api} " + f"and this device is API {c.dev.sdk_int}") + continue + # A settings sub-screen keeps the wallet busy while the change + # lands, which is where this was first seen. + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Contacts$", max_scrolls=12) + c.tap(r"(?i)^Contacts$", timeout=20) + time.sleep(2) + c.dev.shell(apply_cmd.format(pkg=pkg), check=False) + time.sleep(9) + screen = c.dev.dump() + if screen.find(INIT_ERROR) is not None: + broken.append(name) + c.note(f"{name}: the wallet came back on its init error screen: " + + str(screen.texts()[:4])) + else: + c.note(f"{name}: survived -- " + str(screen.texts()[:8])) + c.check() + # Undo before the next one, so a failure is attributable. + c.dev.shell(undo_of(name).format(pkg=pkg), check=False) + time.sleep(6) + c.dev.stop() + time.sleep(2) + c.dev.launch() + time.sleep(8) + back = c.dev.dump() + if back.find(INIT_ERROR) is not None: + c.note(f"WARNING: still on the init error screen after undoing " + f"{name} and relaunching") + c.check() + c.note(f"configuration changes the wallet did not survive: {broken}") + finally: + for name, needs_api, _, undo in CONFIG_CHANGES: + if c.dev.sdk_int >= needs_api: + c.dev.shell(undo.format(pkg=pkg), check=False) + + +@scenario("abandon_aborting_deposit", setup="funded", + about="abort a deposit with no network, then abandon it", + # The abandoned deposit shows a fee on a transaction that failed, + # which is recorded under aborted-credit-shows-the-whole-amount-as-fee.md + # and may be correct, so it does not need flagging every round. + expects=("fee-on-dead-transaction", "unfinished-transaction")) +def s_abandon_aborting_deposit(c: Ctx) -> None: + """The only reachable "Abandon". + + wallet-core offers TransactionAction.Fail -- "Abandon", the one button + that calls failTransaction -- for a deposit or peer-push that is + *aborting*, and for little else: a withdrawal waiting on the bank never + offers it, which is what `withdraw_abandon` keeps recording. An abort + against a healthy exchange finishes in a blink, so the transaction only + sits in that state while the wallet is offline, and the dialog's own + warning ("Funds still in transit WILL GET LOST") is exactly what is being + tested. + """ + # The network goes away between entering the amount and submitting: a + # deposit against a reachable exchange completes in under four seconds, so + # taking the network afterwards only ever found a finished transaction. + def go_offline() -> None: + c.dev.shell("cmd connectivity airplane-mode enable", check=False) + time.sleep(3) + + screen = flows.deposit_to_bank(c.app, c.env, "100", before_submit=go_offline) + c.note("the deposit, submitted offline: " + str(screen.texts()[:12])) + c.check() + if not c.tap(r"(?i)^Abort$", timeout=20): + c.note("no Abort on the deposit: " + str(c.dev.dump().texts()[:14])) + c.dev.shell("cmd connectivity airplane-mode disable", check=False) + return + if c.see(r"(?i)Abort transaction|Are you sure", timeout=10): + c.tap(r"(?i)^Abort$|^OK$|^Yes$") + time.sleep(5) + # abortTransaction's onSuccess navigates back, so the detail screen -- and + # with it every action button -- is gone by now; the transaction has to be + # reopened to see what it offers. + rows = transaction_rows(open_transactions(c)) + if rows: + c.dev.tap_node(rows[0]) + time.sleep(3) + aborting = c.dev.dump() + c.note("the aborting deposit, reopened: " + str(aborting.texts()[:16])) + c.check() + if not c.tap(r"(?i)^Abandon$", timeout=20): + c.note("Abandon not offered on the aborting deposit; it offers " + + str([n.label for n in aborting.tappable() if n.label][:10])) + c.dev.shell("cmd connectivity airplane-mode disable", check=False) + return + dialog = c.dev.dump() + c.note("the abandon dialog: " + str(dialog.texts()[:10])) + c.tap(r"(?i)^Abandon$|^OK$|^Yes$") + time.sleep(4) + c.note("after abandoning: " + str(c.dev.dump().texts()[:14])) + c.check() + # Back online: an abandoned transaction must stay abandoned, and the + # balance must not count the coins twice. + c.dev.shell("cmd connectivity airplane-mode disable", check=False) + time.sleep(10) + c.note("after reconnecting: " + str(c.dev.dump().texts()[:14])) + c.check() + c.back_to_home() + c.note("balance afterwards: " + str(c.dev.dump().texts()[:10])) + c.check() + c.ep.check_database() + + +@scenario("peer_push_receive", setup="fresh", about="receive a peer push payment from the CLI wallet") +def s_peer_push(c: Ctx) -> None: + screen = flows.peer_receive(c.app, c.env, "EUR:1", c.cli) + c.note("the prompt: " + str(screen.texts()[:12])) + # The prompt is still on screen right after the tap; accepting is a + # round trip to the exchange, and only its completion reaches + # confirmPeerPushCredit and the credit transaction's own screen. + for _ in range(12): + time.sleep(3) + now = c.dev.dump() + if now.find(r"(?i)completed successfully|This transaction is pending|€") is not None \ + and now.find(r"(?i)Do you want to receive") is None: + break + c.note("after accepting: " + str(c.dev.dump().texts()[:14])) + c.check() + # The balance has to move, and this has to *fail* when it does not: the + # old check asked for a screen with no "€" on it, which a zero balance of + # "€0.00" never is, so a payment that never arrived read as success for + # every round of this campaign. + deadline = time.monotonic() + 90 + shown: list[str] = [] + while time.monotonic() < deadline: + shown = c.app.balances() + if any(re.search(r"[1-9]", s) for s in shown): + break + time.sleep(5) + c.note(f"balance after receiving: {shown}") + if not any(re.search(r"[1-9]", s) for s in shown): + raise RuntimeError( + f"the received push payment did not reach the balance: {shown} " + f"(screen: {c.dev.dump().texts()[:12]})") + c.check() + # The credit's own detail screen: nothing had opened it, so + # TransactionPeerPushCreditComposable had never rendered. + rows = transaction_rows(open_transactions(c)) + if rows: + c.dev.tap_node(rows[0]) + time.sleep(2.5) + detail = c.dev.dump() + c.note("the received push, in detail: " + str(detail.texts()[:16])) + c.check() + c.app.scroll_to_text(r"(?i)^Show JSON$|^Delete$", max_scrolls=4) + c.check() + c.ep.check_database() + + +@scenario("peer_pull_pay", setup="funded", about="pay an invoice the CLI wallet issued") +def s_peer_pull(c: Ctx) -> None: + flows.peer_pay_invoice(c.app, c.env, "EUR:1", c.cli) + time.sleep(3) + c.note("after paying the invoice: " + str(c.dev.dump().texts()[:10])) + c.check() + + +@scenario("balances_screens", setup="paid", about="balances, tokens and donation statements") +def s_balances(c: Ctx) -> None: + c.back_to_home() + for label in (r"(?i)^Balances$", r"(?i)^Other assets$", r"(?i)^Donation statements$", + r"(?i)^Contacts$"): + c.back_to_home() + if c.tap(label, timeout=10): + time.sleep(1.5) + c.note(f"{label}: {c.dev.dump().texts()[:8]}") + c.check() + c.check() + + +@scenario("peer_send", setup="funded", about="wallet sends money to the CLI wallet (OutgoingPush)") +def s_peer_send(c: Ctx) -> None: + c.back_to_home() + c.must_tap(r"(?i)^Send$", timeout=30) + c.require(r"(?i)Send money|Amount to send|Purpose", timeout=30) + c.set_amount("€5.00", "500") + c.check() + # Purpose and expiry are optional; touch them so their code runs. + c.tap(r"(?i)^Purpose$", timeout=6) + c.tap(r"(?i)Expires in|1 week|30 days", timeout=6) + c.must_tap(r"(?i)^Send ", timeout=30) + c.see(r"(?i)Scan this QR code to receive|copy and send this URI", timeout=60) + uri = c.uri_from_logcat("pay-push") + c.note(f"push uri: {uri[:70]}") + # The app's side of the flow is what is under test; whether the CLI peer + # can accept depends on its wallet-core being compatible with this + # exchange, so a failure there is recorded rather than raised. + try: + flows.fund_peer(c.cli, c.env, "EUR:5") + result = c.cli.accept_push(uri) + c.note(f"peer accepted: {str(result)[:200]}") + except Exception as e: + c.note(f"peer could not accept (counterparty problem): {str(e)[:220]}") + time.sleep(4) + c.back_to_home() + rows = transaction_rows(open_transactions(c)) + c.note(f"transactions after sending: {[n.label[:24] for n in rows]}") + c.check() + c.ep.check_database() + + +@scenario("peer_request", setup="funded", about="wallet invoices the CLI wallet (OutgoingPull)") +def s_peer_request(c: Ctx) -> None: + c.back_to_home() + c.must_tap(r"(?i)^Request$", timeout=30) + c.require(r"(?i)Request money|Amount to receive|Amount requested", timeout=30) + c.set_amount("€5.00", "500") + c.check() + c.must_tap(r"(?i)^Request ", timeout=30) + c.see(r"(?i)Scan this QR code to pay|copy and send this URI", timeout=60) + uri = c.uri_from_logcat("pay-pull") + c.note(f"pull uri: {uri[:70]}") + try: + flows.fund_peer(c.cli, c.env, "EUR:5") + result = c.cli.pay_pull(uri) + c.note(f"peer paid the invoice: {str(result)[:160]}") + except Exception as e: + c.note(f"peer could not pay (counterparty problem): {str(e)[:200]}") + time.sleep(4) + c.check() + + +@scenario("deposit_flow", setup="funded", + about="the Deposit button: amount, account selection, IBAN entry") +def s_deposit_flow(c: Ctx) -> None: + c.back_to_home() + c.must_tap(r"(?i)^Deposit$", timeout=30) + # The account comes first: the amount field only appears once a target + # account has been picked. + screen = c.require(r"(?i)deposit to bank account|Manage bank accounts|x-taler-bank", + timeout=30) + c.note("account step: " + str(screen.texts()[:10])) + account = screen.find(r"(?i)^wallet\d+$") or screen.find(r"(?i)x-taler-bank") + if account is not None: + c.dev.tap_node(account, screen) + time.sleep(2) + c.require(r"(?i)Amount to deposit|Make deposit", timeout=25) + c.set_amount("€5.00", "500") + c.check() + c.tap(r"(?i)^Check fees$", timeout=8) + c.tap(r"(?i)^Make deposit$|^Deposit$|^Next$|^Continue$", timeout=15) + # The account manager, with the IBAN form behind "Add account". + if c.see(r"(?i)Select bank account|Known bank accounts|Add account|Manage bank accounts", + timeout=20): + c.tap(r"(?i)^Manage bank accounts$", timeout=8) + if c.tap(r"(?i)^Add account$", timeout=15): + c.see(r"(?i)IBAN|Account holder|x-taler-bank", timeout=20) + c.check() + c.fill("Wallet One", 0) + c.fill("DE89370400440532013000", 1) + c.tap(r"(?i)^Save$|^Add$|^OK$|^Continue$", timeout=15) + time.sleep(2) + c.check() + c.tap(r"(?i)^Make deposit$|^Deposit$", timeout=20) + time.sleep(4) + c.note("after deposit attempt: " + str(c.dev.dump().texts()[:10])) + c.check() + + +@scenario("bank_accounts", setup="funded", about="Settings - Bank accounts: add, edit, forget") +def s_bank_accounts(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Bank accounts$") + c.must_tap(r"(?i)^Bank accounts$") + c.require(r"(?i)Known bank accounts|No bank accounts saved|Add account", timeout=25) + c.check() + if c.tap(r"(?i)^Add account$", timeout=20): + c.see(r"(?i)IBAN|Account holder", timeout=20) + # The form opens on the x-taler-bank tab, whose fields are a host + # dropdown, holder, account and note -- so filling "field 1" with an + # IBAN typed it into the account name. Pick the tab first. + c.tap(r"(?i)^IBAN$", timeout=10) + time.sleep(1.5) + # Wrong IBAN first: the form should say so rather than accept it. + c.fill("Test Holder", 0, clear=True) + c.fill("NOT-AN-IBAN", 1, clear=True) + # "Note" carries no "(optional)" but the submit button is disabled + # without it (findings/add-account-note-is-required-but-unmarked.md), + # so it has to be filled or nothing can ever be added. + fill_account_note(c, "Test account") + # The submit button carries the same string as the title and the add + # icon, so it has to be picked as a button, not as a label. + submitted = c.tap_button(r"(?i)^Add account$|^Save$|^OK$", timeout=10) + time.sleep(1.5) + c.note(f"invalid IBAN (submit tappable: {submitted}): " + + str(c.dev.dump().texts()[:10])) + c.check() + # Without clear=True this appends, leaving "NOT-AN-IBANDE89370…", + # which keeps the submit button disabled: no account was ever added. + c.fill("DE89370400440532013000", 1, clear=True) + c.tap_button(r"(?i)^Add account$|^Save$|^OK$", timeout=10) + time.sleep(3) + listed = c.dev.dump() + c.note("after adding: " + str(listed.texts()[:12])) + if listed.find(r"DE89|370400440532013000|Test Holder") is None: + c.note("WARNING: the account does not appear in the list") + c.check() + # Edit whatever is listed now. There is no "Edit" label to tap: the row + # itself is clickable and opens the add screen with the account's id, + # which is the only thing that ever calls getBankAccountById. + if c.tap(r"(?i)Test Holder|DE89|370400440532013000", timeout=10): + if c.see(r"(?i)^Edit account$", timeout=20): + edit = c.dev.dump() + c.note("the edit form: " + str(edit.texts()[:14])) + if edit.find(r"(?i)Test Holder") is None: + c.note("WARNING: the edit form did not load the account") + # Change the holder and save, then check the list shows the change. + c.fill("Edited Holder", 0, clear=True) + c.tap_button(r"(?i)^Save$|^Edit account$|^OK$", timeout=10) + time.sleep(3) + c.note("after saving: " + str(c.dev.dump().texts()[:12])) + else: + c.note("tapping the account row did not open the edit form: " + + str(c.dev.dump().texts()[:12])) + c.check() + c.back_to_home() + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Bank accounts$") + c.must_tap(r"(?i)^Bank accounts$") + c.require(r"(?i)Known bank accounts|No bank accounts saved|Add account", timeout=25) + if c.tap(r"(?i)^Delete$|^Forget", timeout=10): + if c.see(r"(?i)Forget account|really wish to forget", timeout=10): + c.tap(r"(?i)^Forget$|^OK$|^Yes$|^Delete$") + time.sleep(2) + c.check() + + +@scenario("manual_withdraw_transfer", setup="funded", + about="the Withdraw button: manual wire transfer details and QR codes") +def s_manual_withdraw_transfer(c: Ctx) -> None: + c.back_to_home() + c.must_tap(r"(?i)^Withdraw$", timeout=30) + c.require(r"(?i)Amount to withdraw|Select target bank account|Payment service", + timeout=30) + c.fill("5") + c.check() + c.tap(r"(?i)Restrict usage to age|Unrestricted", timeout=6) + c.accept_tos() + c.must_tap(r"(?i)^Withdraw$|Confirm withdrawal", timeout=30) + if c.see(r"(?i)Wire transfer instructions|Subject|IBAN|Recipient|Account", timeout=60): + c.note("manual withdrawal instructions reached") + c.check() + # Each of these used to be tried and dropped on the floor, so a button + # that stopped working looked exactly like one that is not offered for + # this account type. Say which happened. + reached = [] + for label in (r"(?i)Wire transfer QR codes", r"(?i)EPC QR", r"(?i)Swiss QR bill", + r"(?i)Open in banking app"): + try: + c.app.scroll_to_text(label, max_scrolls=6) + except TimeoutError: + c.note(f"{label}: not offered on this screen") + continue + if not c.tap(label, timeout=8): + c.note(f"{label}: on screen but the tap did not take") + continue + time.sleep(1.5) + reached.append(label) + c.note(f"{label}: " + str(c.dev.dump().texts()[:10])) + c.check() + # "Wire transfer QR codes" is the one that navigates away, to the + # transfer screen with showQrCodes set -- the only way that branch + # of ScreenTransfer runs. + if "QR codes" in label: + if c.see(r"(?i)you can scan one of these QR codes|share this QR code", + timeout=15) is None: + c.note("the QR code screen did not show its own text: " + + str(c.dev.dump().texts()[:12])) + else: + c.note("the QR variant of the transfer screen rendered") + c.check() + c.dev.back() + time.sleep(1.5) + c.note(f"transfer actions reached: {reached}") + c.note("screen: " + str(c.dev.dump().texts()[:12])) + c.check() + + +@scenario("tokens_screen", setup="paid", about="the Other assets / token list screen") +def s_tokens(c: Ctx) -> None: + c.back_to_home() + # The main screen's own labels: "Discounts" and "Passes" are the token + # views, "Donation statements" the donau receipts. + for label in (r"(?i)^Discounts$", r"(?i)^Passes$", r"(?i)^Donation statements$"): + c.back_to_home() + try: + c.app.scroll_to_text(label, max_scrolls=5) + except TimeoutError: + c.note(f"{label} not on the main screen") + continue + c.tap(label, timeout=10) + time.sleep(2) + c.note(f"{label}: {c.dev.dump().texts()[:10]}") + c.check() + for tab in (r"(?i)^Available$", r"(?i)^Expired$"): + c.tap(tab, timeout=6) + c.check() + c.check() + + +@scenario("donau_setup", setup="funded", about="configure the donation tax authority") +def s_donau(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Tax-deductible donations$") + c.must_tap(r"(?i)^Tax-deductible donations$") + c.require(r"(?i)tax authority|Donor tax payer ID|donation", timeout=25) + c.check() + if c.tap(r"(?i)^Select tax authority$", timeout=15): + time.sleep(2) + c.check() + c.tap(r"(?i)localhost:8079|Bern", timeout=10) + c.tap_button(r"(?i)^Setup tax payer ID$", timeout=10) + time.sleep(2) + # The form has two fields in this order: the authority's URL, then the tax + # payer ID. Save stays disabled until both are filled, which is why + # filling only the first one made the tap do nothing at all. + c.fill(c.env.donau, 0) + c.fill("TAXID-12345", 1) + time.sleep(1) + saved = c.tap_button(r"(?i)^Save$", timeout=15) + time.sleep(4) + screen = c.dev.dump() + c.note(f"after donau setup (save tappable: {saved}): " + str(screen.texts()[:12])) + if screen.find(r"(?i)configured successfully|Tax-deductible donations") is None: + c.note("WARNING: the tax authority was not accepted") + c.check() + + +@scenario("contacts_alias", setup="funded", about="contacts and alias registration") +def s_contacts(c: Ctx) -> None: + c.back_to_home() + if not c.tap(r"(?i)^Contacts$", timeout=15): + c.app.open_settings() + try: + c.app.scroll_to_text(r"(?i)^Contacts$|Alias Registration", max_scrolls=10) + c.tap(r"(?i)^Contacts$|Alias Registration", timeout=10) + except TimeoutError: + c.note("no way into contacts from home or settings") + return + screen = c.see(r"(?i)Contacts|Alias", timeout=20) + c.note("contacts screen: " + str((screen or c.dev.dump()).texts()[:14])) + c.check() + if c.tap(r"(?i)Alias Registration|^Register", timeout=15): + c.see(r"(?i)Alias Type|Alias|Duration", timeout=20) + c.fill("simulator@example.com") + c.tap(r"(?i)^Register Alias$", timeout=15) + time.sleep(3) + c.note("after alias registration: " + str(c.dev.dump().texts()[:10])) + c.check() + + +@scenario("transactions_bulk_delete", setup="paid", + about="selection mode: long-press, Select All, delete the lot") +def s_bulk_delete(c: Ctx) -> None: + """The main screen's rows do not select, and that is deliberate. + + This scenario used to long-press a row here, look for "Select All", and + return with "long press did not open selection mode" -- every round, while + counting as a pass. It never could: `BalancesPagerComposable`'s + `BalanceRecentTransactions` builds each `TransactionRow` with + `selectionMode = false` and `onTransactionSelect = {}`, so a long press on + the main screen is a no-op by construction. Selection and bulk deletion + live on the dedicated screen behind the "All" chip, which is what + `transactions_screen_selection` drives. + + What is left here is worth pinning: a long press must do *nothing* -- not + open a detail screen, not select, not crash. + """ + screen = open_transactions(c) + rows = transaction_rows(screen) + if not rows: + raise RuntimeError(f"no transaction rows; screen: {screen.texts()}") + before = screen.signature() + c.dev.long_press(rows[0]) + time.sleep(2) + after = c.dev.dump() + c.note("after a long press on the main screen: " + str(after.texts()[:12])) + if after.find(r"(?i)^Select All$") is not None: + c.note("selection mode opened on the main screen, which it is not " + "built to do -- the list's arguments must have changed") + elif after.signature() != before: + c.note("the long press changed the screen: " + str(after.texts()[:12])) + else: + c.note("the long press did nothing, as the main screen's rows intend") + c.check() + c.ep.check_database() + + +@scenario("transactions_screen_selection", setup="paid", + about="selection mode on the dedicated transactions screen") +def s_transactions_screen_selection(c: Ctx) -> None: + """The other transaction list. + + `transactions_bulk_delete` works on the main screen's "Recent + transactions" section. The **dedicated** screen behind the "All" chip is + `TransactionsScreen.kt`, and its selection mode -- select all, leave + selection mode, and the delete-selected dialog -- is the uncovered half of + that file. + """ + c.back_to_home() + try: + c.app.scroll_to_text(r"(?i)^All$", max_scrolls=6) + except TimeoutError: + c.note("no All chip on the main screen: " + str(c.dev.dump().texts()[:14])) + return + c.must_tap(r"(?i)^All$", timeout=15) + time.sleep(2) + screen = c.dev.dump() + c.note("after the All chip: " + str(screen.texts()[:14])) + if screen.find(r"(?i)^Transactions$") is None: + c.note("the All chip did not open the transactions screen") + c.check() + return + c.check() + + rows = transaction_rows(screen, header=r"(?i)^Transactions$", + signed_only=True) + if not rows: + c.note("no rows on the transactions screen: " + str(screen.texts()[:14])) + c.check() + return + c.dev.long_press(rows[0]) + time.sleep(2) + screen = c.dev.dump() + c.note("selection mode: " + str(screen.texts()[:14])) + if screen.find(r"(?i)^Select All$") is None: + c.note("long press did not open selection mode here either") + c.check() + return + c.must_tap(r"(?i)^Select All$", timeout=15) + time.sleep(1.5) + c.note("after select all: " + str(c.dev.dump().texts()[:14])) + c.check() + + # Leaving selection mode is an unnamed icon button in the app bar + # (TransactionsScreen.kt:112 passes contentDescription = null), so it can + # only be found by position: the top-left clickable. + screen = c.dev.dump() + unnamed = [n for n in screen.unnamed_clickables() if n.bounds[1] < 400] + c.note(f"{len(unnamed)} unnamed clickable(s) in the app bar: " + + str([n.bounds for n in unnamed][:4])) + if unnamed: + leftmost = min(unnamed, key=lambda n: n.bounds[0]) + c.dev.tap(*leftmost.center) + time.sleep(1.5) + back = c.dev.dump() + c.note("after closing selection mode: " + str(back.texts()[:12])) + if back.find(r"(?i)^Select All$") is not None: + c.note("WARNING: still in selection mode") + c.check() + + # Round two: select all and delete, through the confirmation dialog. + screen = c.dev.dump() + rows = transaction_rows(screen, header=r"(?i)^Transactions$", + signed_only=True) + if not rows: + c.note("no rows left to select") + c.check() + return + c.dev.long_press(rows[0]) + time.sleep(2) + if not c.tap(r"(?i)^Select All$", timeout=10): + c.note("could not re-enter selection mode") + c.check() + return + time.sleep(1) + if not c.tap(r"(?i)^Delete$", timeout=15): + c.note("no Delete in the selection app bar: " + + str(c.dev.dump().texts()[:12])) + c.check() + return + dialog = c.see(r"(?i)Delete transactions|Are you sure you want to remove", + timeout=15) + c.note("the delete dialog: " + + (str(dialog.texts()[:10]) if dialog else "did not appear")) + if dialog is not None: + c.must_tap(r"(?i)^Delete$|^OK$|^Yes$", timeout=10) + time.sleep(3) + left = transaction_rows(c.dev.dump(), header=r"(?i)^Transactions$", + signed_only=True) + c.note(f"rows after deleting the selection: {len(left)}") + c.check() + c.ep.check_database() + + +@scenario("transactions_filter", setup="paid", about="the transaction list filter chip") +def s_tx_filter(c: Ctx) -> None: + open_transactions(c) + for _ in range(3): + if not c.tap(r"(?i)^All$", timeout=10): + break + time.sleep(1.5) + screen = c.dev.dump() + c.note("filter menu: " + str(screen.texts()[:12])) + c.check() + # Pick whatever option the menu offers, then come back to All. + if not c.tap(r"(?i)pending|final|complete|incoming|outgoing", timeout=8): + c.dev.back() + break + time.sleep(1.5) + c.check() + c.check() + + +def open_mailbox(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Mailbox$", max_scrolls=10) + c.must_tap(r"(?i)^Mailbox$") + c.require(r"(?i)mailbox|message|P2P|empty|Loading", timeout=25) + + +@scenario("mailbox", setup="funded", about="the P2P messaging mailbox screen") +def s_mailbox(c: Ctx) -> None: + """The mailbox screen and both of its dialogs. + + The screen has three actions in its app bar -- the address, the URL + configuration and a refresh -- and this used to tap for "Add"/"New"/"+" + and "refresh", which matched only the last of them. The two dialogs are + half of `MailboxScreen.kt`'s uncovered lines, and the address one is the + only caller of its clipboard copy. + """ + open_mailbox(c) + screen = c.dev.dump() + c.note("mailbox: " + str(screen.texts()[:14])) + c.check() + + # "Show Mailbox Address" exists only once the mailbox has registered. + if c.tap(r"(?i)^Show Mailbox Address$", timeout=10): + dialog = c.see(r"(?i)Your Mailbox Address", timeout=15) + c.note("the address dialog: " + + (str(dialog.texts()[:8]) if dialog else "did not open")) + if dialog is not None: + address = next((t for t in dialog.texts() + if "/" in t and "mailbox" in t.lower()), None) + c.note(f"the address it shows: {address}") + # The confirm button copies it to the clipboard and says so in a + # snackbar. Polled tightly on purpose: `c.see` took long enough + # over its first dump to miss it, and reported "no confirmation" + # for a message that a probe found 0.4 s after the tap. + # tap_exact, not tap: on a dialog's text buttons the ancestor + # hunt lands somewhere that dismisses the dialog instead. + if c.tap_exact(r"(?i)^Copy$", timeout=8): + snack = None + for _ in range(10): + dump = c.dev.dump() + if dump.find(r"(?i)copied to clipboard") is not None: + snack = dump + break + time.sleep(0.4) + c.note("after copying: " + + (str([t for t in snack.texts() if "clipboard" in t.lower()]) + if snack else "no confirmation seen")) + c.check() + else: + c.note("no address action; the mailbox has not registered: " + + str(c.dev.dump().texts()[:12])) + + # The URL dialog is always there, and cancelling it must change nothing. + if c.tap(r"(?i)^Configure Mailbox$", timeout=10): + dialog = c.see(r"(?i)Configure Mailbox URL|Mailbox Base URL", timeout=15) + c.note("the URL dialog: " + + (str(dialog.texts()[:8]) if dialog else "did not open")) + if dialog is not None: + c.fill("https://mailbox.example.org", 0, clear=True) + c.note("after typing a URL: " + str(c.dev.dump().texts()[:10])) + c.must_tap(r"(?i)^Cancel$", timeout=10) + time.sleep(1.5) + c.note("after cancelling: " + str(c.dev.dump().texts()[:12])) + c.check() + + if c.tap(r"(?i)^Refresh$", timeout=8): + time.sleep(3) + c.note("after refreshing: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + + +@scenario("forward_payment_to_contact", setup="funded", + about="forward a peer-push URI to a contact through the mailbox", + expects=("error-screen", "internal-error-code", "core-internal")) +def s_forward_payment_to_contact(c: Ctx) -> None: + """The app's sending side of the mailbox, which looks unreachable. + + `sendTalerUriMailboxMessage` hangs off a button that only exists in + developer mode, only on a pay-push/pay-pull QR screen, and is labelled + "Contacts" rather than anything about sending + (`compose/QrCodeUriComposable.kt:183`). Tapping it opens the contacts + screen as "Send to Contact"; confirming a contact there is the call. + + The contact is the wallet's own mailbox address, so the message has + somewhere real to go and comes back to the sender -- which also checks that + a wallet can read what it sent itself. + """ + # The wallet's own address, which it registers on first use against the + # default mailbox (now answered locally through the TLS front end). + open_mailbox(c) + if not c.tap(r"(?i)^Show Mailbox Address$", timeout=20): + c.note("no address dialog; the mailbox did not register: " + + str(c.dev.dump().texts()[:12])) + return + dialog = c.require(r"(?i)Your Mailbox Address", timeout=15) + address = next((t for t in dialog.texts() + if "mailbox" in t.lower() and "/" in t), None) + c.note(f"the wallet's own mailbox address: {address}") + c.tap(r"(?i)^Cancel$|^OK$", timeout=8) + if not address: + return + c.check() + + # A peer-push payment, which is what the forward button appears on. + c.back_to_home() + c.must_tap(r"(?i)^Send$", timeout=30) + c.require(r"(?i)Send money|Amount to send|Purpose", timeout=30) + c.set_amount("€5.00", "500") + c.must_tap(r"(?i)^Send ", timeout=30) + if not c.see(r"(?i)Scan this QR code to receive|copy and send this URI", + timeout=60): + c.note("the push never reached its QR screen: " + + str(c.dev.dump().texts()[:14])) + return + c.check() + + # "Contacts" here means "forward this payment to one". + if not c.tap_button(r"(?i)^Contacts$", timeout=20): + c.note("no forward button on the push screen (developer mode off?): " + + str(c.dev.dump().texts()[:14])) + return + picker = c.require(r"(?i)Send to Contact|No contacts yet|Add Contact", + timeout=20) + c.note("the picker: " + str(picker.texts()[:12])) + c.check() + + # Add the wallet itself as a contact, if it is not already one. + if picker.find(r"(?i)^self$") is None: + if not c.tap(r"(?i)^Add Contact$", timeout=15): + c.note("no way to add a contact from the picker") + return + c.require(r"(?i)Petname|Alias Type", timeout=15) + fields = c.dev.dump().editable() + # petname, alias, (alias type is a read-only dropdown), mailbox + c.fill("self", 0, clear=True) + c.fill(f"self-w{WORKER}@example.com", 1, clear=True) + if len(fields) >= 4: + c.fill(address, len(fields) - 1, clear=True) + else: + c.note(f"the add-contact form has {len(fields)} fields, not 4") + c.tap_button(r"(?i)^OK$|^Add$|^Save$", timeout=10) + time.sleep(3) + c.note("after adding the contact: " + str(c.dev.dump().texts()[:12])) + c.check() + + if not c.tap(r"(?i)^self$", timeout=15): + c.note("the contact is not in the list: " + + str(c.dev.dump().texts()[:14])) + return + if c.see(r"(?i)Are you sure you want to send", timeout=15): + c.tap_button(r"(?i)^OK$", timeout=10) + time.sleep(8) + c.note("after sending: " + str(c.dev.dump().texts()[:14])) + c.check() + + # The message should arrive back in this very wallet. + open_mailbox(c) + for _ in range(8): + time.sleep(5) + c.tap(r"(?i)^Refresh$", timeout=5) + inbox = c.dev.dump() + if inbox.find(r"(?i)Accept payment|Pay invoice|From:") is not None: + c.note("the forwarded payment came back: " + str(inbox.texts()[:14])) + break + else: + c.note("the forwarded message did not arrive within 40s: " + + str(c.dev.dump().texts()[:14])) + c.check() + c.ep.check_database() + + +@scenario("mailbox_roundtrip", setup="funded", + about="register with a real mailbox service, receive and delete a message", + expects=("error-screen", "internal-error-code", "core-internal")) +def s_mailbox_roundtrip(c: Ctx) -> None: + """The mailbox screen against a deployed taler-mailbox. + + Its URL is the one service address the app lets the user type in, so no + DNS or TLS games are needed: point it at the local service, let the wallet + register itself, deliver a message to its address the way another wallet + would, and read and delete it. + """ + url = service_or_skip(c, LOCAL_MAILBOX, "mailbox") + if url is None: + return + open_mailbox(c) + c.check() + # "Configure Mailbox" is an icon; its content description is the only name. + if not c.tap(r"(?i)^Configure Mailbox$", timeout=15): + c.note("no way to configure the mailbox URL: " + + str(c.dev.dump().texts()[:12])) + return + screen = c.require(r"(?i)Configure Mailbox URL|Mailbox Base URL", timeout=15) + if not screen.editable(): + c.note("no URL field in the dialog") + return + # The field comes pre-filled with the production URL. + if not c.fill(url.rstrip("/"), 0, clear=True): + c.note("could not type the mailbox URL") + return + c.tap_button(r"(?i)^OK$", timeout=10) + time.sleep(6) + c.note("after configuring: " + str(c.dev.dump().texts()[:14])) + c.check() + # The wallet registers itself on first use; its address is behind the info + # icon. + if not c.tap(r"(?i)^Show Mailbox Address$", timeout=15): + c.note("no address dialog; the mailbox may not have registered") + return + dialog = c.require(r"(?i)Your Mailbox Address", timeout=15) + address = next((t for t in dialog.texts() if "localhost:11000" in t), None) + c.note(f"the wallet's mailbox address: {address}") + c.tap(r"(?i)^Cancel$", timeout=8) + if not address: + c.note("WARNING: the address dialog showed no address") + return + h_address = address.rstrip("/").rsplit("/", 1)[-1] + c.check() + + # Deliver a real message: the CLI wallet encrypts a taler:// URI for this + # address, which is what another wallet would do. (The app itself has no + # caller for sendTalerUriMailboxMessage, so it can only receive.) + # Two messages, differing only in the scheme of the URI they carry: the + # row offers "Accept payment" only for a literal taler:// prefix, so the + # developer-mode scheme the rest of the app accepts everywhere else falls + # through to a bare string. + for scheme in ("taler://", "taler+http://"): + try: + sent = c.cli.send_mailbox_message( + h_address.upper(), + f"{scheme}pay-push/localhost:8081/" + "A" * 52, + mailbox_base=url.replace("localhost", "127.0.0.1")) + c.note(f"another wallet sent a {scheme} message: {str(sent)[:120]}") + except Exception as e: # noqa: BLE001 + c.note(f"the peer wallet could not send {scheme}: {str(e)[:160]}") + time.sleep(2) + c.tap(r"(?i)^Refresh$", timeout=10) + time.sleep(8) + listed = c.dev.dump() + c.note("after two real messages: " + str(listed.texts()[:20])) + if listed.find(r"(?i)No messages yet") is not None: + c.note("WARNING: a message another wallet sent does not appear") + actions = [t for t in listed.texts() + if t.strip() in ("Accept payment", "Pay invoice")] + raw = [t for t in listed.texts() if t.startswith(("taler://", "taler+http://"))] + c.note(f"rows offering an action: {len(actions)}; rows showing a raw URI: {raw}") + if raw: + c.note("WARNING: a received payment with no way to accept it") + c.check() + + # And one the wallet cannot read: anyone may POST to a mailbox address, so + # what the app does with junk is worth knowing. It turns out to fetch it, + # fail to make sense of it, delete it from the server and say nothing -- + # which is the right instinct for a public drop box. + import urllib.request + # The service insists on exactly message_body_bytes, so ask it how long a + # message is rather than guessing (43 bytes earns a flat 400). + size = 256 + try: + with urllib.request.urlopen(url + "config", timeout=5) as r: + size = int(json.loads(r.read()).get("message_body_bytes", 256)) + except Exception as e: # noqa: BLE001 + c.note(f"could not read the mailbox config: {str(e)[:80]}") + c.note(f"a message is {size} bytes here") + # Not a valid envelope: what the app does with a message it cannot make + # sense of is worth knowing too. + body = (b"simulator test message, not a valid envelope. " + * (size // 46 + 1))[:size] + req = urllib.request.Request(url + h_address.upper(), data=body, + method="POST") + try: + with urllib.request.urlopen(req, timeout=10) as r: + c.note(f"delivered a message: HTTP {r.status}") + except Exception as e: # noqa: BLE001 + c.note(f"could not deliver a message: {str(e)[:160]}") + time.sleep(2) + c.tap(r"(?i)^Refresh$", timeout=10) + time.sleep(6) + after = c.dev.dump() + c.note("after refreshing: " + str(after.texts()[:16])) + c.check() + # A message row offers a delete button; that is the only path to + # deleteMailboxMessage. + if c.tap(r"(?i)^Delete$|delete message", timeout=10): + time.sleep(3) + c.note("after deleting: " + str(c.dev.dump().texts()[:14])) + c.check() + c.ep.check_database() + + +@scenario("contacts_list", setup="funded", about="the contacts screen from settings") +def s_contacts_list(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Contacts$", max_scrolls=10) + c.must_tap(r"(?i)^Contacts$") + c.require(r"(?i)contact|alias|empty", timeout=25) + c.note("contacts: " + str(c.dev.dump().texts()[:14])) + c.check() + c.tap(r"(?i)^Add$|^New$|Add contact", timeout=8) + c.check() + + +@scenario("uri_add_contact", setup="funded", about="a taler://add-contact/ URI") +def s_uri_add_contact(c: Ctx) -> None: + for uri in (f"taler+http://add-contact/{corpus.EXCHANGE}/{corpus.FAKE_ID}", + "taler+http://add-contact/"): + c.app.handle_uri(uri) + time.sleep(2.5) + c.note(f"{uri[:48]}: {c.dev.dump().texts()[:8]}") + c.check() + c.back_to_home() + + +@scenario("uri_dev_experiment", setup="funded", about="a taler://dev-experiment/ URI") +def s_uri_dev_experiment(c: Ctx) -> None: + for uri in ("taler+http://dev-experiment/nonexistent", + "taler+http://dev-experiment/", + "taler+http://dev-experiment/" + "x" * 300): + c.app.handle_uri(uri) + time.sleep(2.5) + c.note(f"{uri[:42]}: {c.dev.dump().texts()[:8]}") + c.check() + c.back_to_home() + + +@scenario("payment_insufficient_reason", setup="funded", + about="a payment refused for a named reason, not just 'insufficient'", + expects=("error-screen", "internal-error-code", "core-internal")) +def s_payment_insufficient_reason(c: Ctx) -> None: + """The typed half of `PaymentResponses.kt`. + + `payment_insufficient` reaches the plain "not enough money" case. The + insufficient-balance *details* -- `PaymentInsufficientBalanceDetails`, + `PerExchange`, and the mapping from each reason to its own hint string at + `PaymentResponses.kt:186` -- need a refusal with a reason attached, and the + wallet cannot manufacture one. wallet-core can: the + `merchant-deposit-insufficient` dev experiment + (`dev-experiments.ts:269`) makes the next payment fail as though the + merchant's account could not take the deposit. + """ + c.app.handle_uri("taler+http://dev-experiment/merchant-deposit-insufficient") + time.sleep(3) + c.note("after arming the experiment: " + str(c.dev.dump().texts()[:10])) + c.back_to_home() + c.check() + + # A neutral summary on purpose: the first version called the order + # "Order the merchant cannot take", and every pattern below then matched + # the summary instead of the wallet's own text. + order = c.merchant.create_order("EUR:1", summary="Simulator order") + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)Review order|Total|^Pay\b|Insufficient balance", + timeout=60) + c.note("the prompt: " + str(screen.texts()[:16])) + c.check() + # "Insufficient balance" is the state; the hint beside it is the reason, + # and the reason is what PaymentResponses.kt:186 maps. + state = screen.find(r"(?i)^Insufficient balance$") + if state is None and c.tap_button(r"(?i)^Pay\b", timeout=20): + time.sleep(6) + screen = c.dev.dump() + c.note("after confirming: " + str(screen.texts()[:16])) + state = screen.find(r"(?i)^Insufficient balance$") + c.note(f"the wallet says the balance is insufficient: {state is not None}") + # One of the seven hint strings, matched on wording the order summary + # cannot contain. + hint = screen.find( + r"(?i)wire method of the payment service" + r"|doesn't accept money from one or more" + r"|due to age restriction" + r"|missing the global fee configuration" + r"|fees not covered by the merchant" + r"|coins needed for this purchase are currently unavailable") + c.note(f"a reason-specific hint: {hint is not None}" + + (f" -- {hint.label[:140]}" if hint is not None else "")) + if state is not None and hint is None: + c.note("WARNING: insufficient balance with no reason shown, though " + "the experiment armed a specific one") + c.check() + c.ep.check_database() + + +@scenario("payment_template", setup="funded", about="pay through an order template") +def s_payment_template(c: Ctx) -> None: + c.merchant.create_template("simtemplate", "EUR:1") + uri = (f"taler+http://pay-template/localhost:8080/instances/" + f"{c.merchant.instance}/simtemplate") + c.app.handle_uri(uri) + screen = c.see(r"(?i)amount|summary|Pay|Order|template", timeout=40) + c.note("template prompt: " + str(screen.texts()[:12] if screen else None)) + c.check() + # Templates can ask for the amount and the subject. + if screen and screen.editable(): + c.fill("1") + c.tap(r"(?i)^Pay|^Continue$|^Next$|^Order$", timeout=20) + time.sleep(4) + c.note("after template pay: " + str(c.dev.dump().texts()[:10])) + c.check() + + +@scenario("payment_expired", setup="funded", about="pay an order whose deadline has passed") +def s_payment_expired(c: Ctx) -> None: + import time as _t + deadline = int(_t.time()) + 5 + order = c.merchant.create_order( + "EUR:1", summary="Order that expires at once", + pay_deadline={"t_s": deadline}, + ) + _t.sleep(10) + c.app.handle_uri(order["pay_uri"]) + time.sleep(3) + c.note("expired order: " + str(c.dev.dump().texts()[:12])) + c.check() + + +@scenario("payment_deleted_order", setup="funded", + about="pay an order the merchant deleted in the meantime") +def s_payment_deleted(c: Ctx) -> None: + order = c.merchant.create_order("EUR:1", summary="Order about to vanish") + try: + c.merchant.delete_order(order["order_id"]) + c.note("merchant deleted the order") + except Exception as e: + c.note(f"merchant refused to delete the order: {e}") + c.app.handle_uri(order["pay_uri"]) + time.sleep(3) + c.note("after paying a deleted order: " + str(c.dev.dump().texts()[:12])) + c.check() + + +@scenario("refresh_history", setup="paid", + about="the refresh transaction left behind by paying") +def s_refresh_history(c: Ctx) -> None: + screen = open_transactions(c) + rows = transaction_rows(screen) + c.note(f"rows: {[n.label[:24] for n in rows]}") + # Change ("refresh") transactions appear after spending part of a coin. + for index, node in enumerate(rows): + screen = open_transactions(c) + rows_now = transaction_rows(screen) + if index >= len(rows_now): + break + c.dev.tap_node(rows_now[index], screen) + time.sleep(2) + detail = c.dev.dump() + if detail.find(r"(?i)change|refresh"): + c.note(f"change transaction detail: {detail.texts()[:10]}") + c.check() + c.dev.back() + time.sleep(1) + c.check() + + +@scenario("lifecycle_kill", setup="fresh", + about="suspend, kill the app, relaunch, resume: does the state survive?") +def s_lifecycle_kill(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + c.must_tap(r"(?i)^Suspend$") + time.sleep(2) + suspended = c.dev.dump().texts() + c.note(f"suspended: {suspended[:8]}") + # Process death without a clean shutdown, the way the system would do it. + c.dev.kill() + time.sleep(2) + c.dev.launch() + time.sleep(6) + c.check() + screen = open_transactions(c) + rows = transaction_rows(screen) + c.note(f"after relaunch, {len(rows)} rows: {[n.label[:24] for n in rows]}") + if rows: + c.dev.tap_node(rows[0], screen) + time.sleep(2) + detail = c.dev.dump() + c.note(f"detail after relaunch: {detail.texts()[:10]}") + # A suspended transaction must still offer Resume. + if detail.find(r"(?i)^Resume$") is None: + c.note("WARNING: no Resume on a suspended transaction after process death") + c.tap(r"(?i)^Resume$", timeout=15) + time.sleep(3) + c.check() + c.ep.check_database() + + +@scenario("abort_then_retry", setup="fresh", + about="abort a withdrawal, then hand the same URI in again") +def s_abort_then_retry(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + uri = op["taler_withdraw_uri"] + c.app.handle_uri(uri) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + c.must_tap(r"(?i)^Abort$") + if c.see(r"(?i)Abort transaction|Are you sure", timeout=10): + c.tap(r"(?i)^Abort$|^OK$|^Yes$") + time.sleep(3) + c.check() + # The same URI again: the operation is dead at the bank, so the wallet has + # to say so rather than start over. + c.app.handle_uri(uri) + time.sleep(4) + c.note("re-handled an aborted withdraw URI: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + + +@scenario("amount_edges_deposit", setup="funded", + about="hostile amounts in the deposit amount field") +def s_amount_edges_deposit(c: Ctx) -> None: + values = ["0", "0.00", "-1", "999999999", "1.999", "0.001", "1e5", "abc", "9.87"] + for value in values: + c.back_to_home() + if not c.tap(r"(?i)^Deposit$", timeout=20): + c.note("no Deposit button on the balance card") + return + screen = c.see(r"(?i)deposit to bank account|x-taler-bank|Amount to deposit", + timeout=20) + if screen is not None and screen.find(r"(?i)Amount to deposit") is None: + # Pick a target account to reach the amount field. + account = (screen.find(r"(?i)^wallet\d+$") + or screen.find(r"(?i)x-taler-bank")) + if account is not None: + c.dev.tap_node(account, screen) + time.sleep(2) + if not c.fill(value): + c.note(f"no amount field for {value!r}") + c.dev.back() + continue + time.sleep(1) + screen = c.dev.dump() + c.note(f"{value!r}: {[t for t in screen.texts() if 'nvalid' in t or 'xceed' in t or 'rror' in t][:3]}") + # Try to proceed; a bad amount must not get past the form. + c.tap(r"(?i)^Make deposit$|^Check fees$|^Deposit$|^Next$", timeout=8) + time.sleep(1.5) + c.check() + c.back_to_home() + c.ep.check_database() + + +@scenario("amount_edges_peer", setup="funded", + about="hostile amounts in the peer send amount field") +def s_amount_edges_peer(c: Ctx) -> None: + values = ["0", "-5", "100000", "1.999", "0.001", "9.87", "1,5"] + for value in values: + c.back_to_home() + if not c.tap(r"(?i)^Send$", timeout=20): + c.note("no Send button on the balance card") + return + c.see(r"(?i)Amount to send|Purpose|Send money", timeout=20) + if not c.fill(value): + c.note(f"no amount field for {value!r}") + c.dev.back() + continue + time.sleep(1) + screen = c.dev.dump() + c.note(f"{value!r}: {[t for t in screen.texts() if 'nvalid' in t or 'xceed' in t or 'rror' in t][:3]}") + c.tap(r"(?i)^Send ", timeout=8) + time.sleep(1.5) + c.check() + c.back_to_home() + c.ep.check_database() + + +@scenario("offline_withdraw", setup="fresh", + about="lose the network in the middle of a withdrawal, then get it back") +def s_offline_withdraw(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + # Airplane mode: the emulator keeps the adb connection, so the driver can + # still watch what the app does without a network. + c.dev.shell("cmd connectivity airplane-mode enable", check=False) + time.sleep(3) + c.bank.confirm_withdrawal(*flows.WALLET_USER, op["withdrawal_id"]) + time.sleep(6) + c.note("offline: " + str(c.dev.dump().texts()[:10])) + c.check() + c.tap(r"(?i)^Retry$", timeout=10) + time.sleep(3) + c.check() + c.dev.shell("cmd connectivity airplane-mode disable", check=False) + time.sleep(8) + # Once the network is back the withdrawal should finish on its own. + done = False + for _ in range(12): + if c.dev.dump().find(r"(?i)completed successfully"): + done = True + break + c.tap(r"(?i)^Retry$", timeout=4) + time.sleep(5) + c.note(f"recovered after reconnect: {done}") + if not done: + c.note("WARNING: withdrawal did not complete after the network came back") + c.check() + c.ep.check_database() + + +@scenario("concurrent_uris", setup="funded", about="two pay URIs delivered back to back") +def s_concurrent_uris(c: Ctx) -> None: + first = c.merchant.create_order("EUR:1", summary="First of two") + second = c.merchant.create_order("EUR:1", summary="Second of two") + c.dev.send_uri(first["pay_uri"]) + time.sleep(0.8) + c.dev.send_uri(second["pay_uri"]) + time.sleep(4) + screen = c.dev.dump() + c.note("after two URIs: " + str(screen.texts()[:12])) + c.check() + c.tap(r"(?i)^Pay", timeout=20) + time.sleep(4) + for order in (first, second): + status = c.merchant.order_status(order["order_id"], order["token"]) + c.note(f"{order['order_id']}: {status.get('order_status')}") + c.check() + c.ep.check_database() + + +@scenario("exchange_delete_with_coins", setup="funded", + about="delete (and purge) an exchange the wallet holds coins at") +def s_exchange_delete_with_coins(c: Ctx) -> None: + open_exchange_list(c) + if not exchange_menu(c): + raise RuntimeError(f"no exchange menu; screen: {c.dev.dump().texts()}") + c.must_tap(r"(?i)^Delete payment service$") + screen = c.see(r"(?i)Force deletion|Are you sure|purge|Delete", timeout=20) + c.note("delete dialog: " + str(screen.texts()[:10] if screen else None)) + c.check() + # Refusing to delete while coins remain is correct; forcing it is the + # interesting path. + c.tap(r"(?i)Force deletion", timeout=10) + c.tap(r"(?i)^Delete$|^OK$|^Yes$", timeout=10) + time.sleep(4) + c.note("after forced deletion: " + str(c.dev.dump().texts()[:12])) + c.check() + c.back_to_home() + c.note("home after purge: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + + +@scenario("tos_reject_midflow", setup="fresh", + about="reject the terms of service while a withdrawal is pending") +def s_tos_reject_midflow(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + open_exchange_list(c) + if exchange_menu(c): + if c.tap(r"(?i)^Reject terms of service$"): + time.sleep(3) + c.note("rejected the terms of service mid-withdrawal") + c.check() + c.bank.confirm_withdrawal(*flows.WALLET_USER, op["withdrawal_id"]) + time.sleep(8) + c.back_to_home() + c.note("after the bank confirmed: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + + +@scenario("tokens_issue_and_view", setup="funded", + about="pay a v1 order that issues a discount token, then view it") +def s_tokens_issue(c: Ctx) -> None: + c.merchant.create_token_family("simdiscount", "discount") + order = c.merchant.create_v1_order( + [{"amount": "EUR:1", "description": "Buy one, get a discount token", + "inputs": [], "outputs": [c.merchant.token_output("simdiscount")], + "max_fee": "EUR:0.5"}], + summary="Issues a discount token", + ) + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)Review order|Total:|^Pay", timeout=60) + c.note("v1 prompt: " + str(screen.texts()[:14])) + c.check() + c.must_tap(r"(?i)^Pay\b|confirm payment", timeout=40) + paid = False + for _ in range(20): + if c.merchant.order_status(order["order_id"], + order["token"]).get("order_status") == "paid": + paid = True + break + time.sleep(2) + c.note(f"order paid: {paid}") + # The issued token should now show up under Discounts. + c.back_to_home() + try: + c.app.scroll_to_text(r"(?i)^Discounts$", max_scrolls=5) + except TimeoutError: + c.note("no Discounts section on the main screen") + c.check() + return + c.must_tap(r"(?i)^Discounts$") + screen = c.require(r"(?i)discount|available|expired|empty", timeout=25) + c.note("discounts screen: " + str(screen.texts()[:14])) + for tab in (r"(?i)^Available$", r"(?i)^Expired$"): + c.tap(tab, timeout=8) + c.check() + c.check() + c.ep.check_database() + + +# An 8x8 red PNG, which is enough for the wallet to decode and draw. The +# wallet accepts exactly `data:image/(jpeg|png);base64,<b64>` +# (AndroidUtils.kt:278), so the prefix matters. +PRODUCT_IMAGE = ( + "data:image/png;base64," + "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAEUlEQVR4nGM4ISeHFTEMLQkA" + "kL9BAbKfPiIAAAAASUVORK5CYII=" +) + + +@scenario("payment_product_image", setup="funded", + about="an order whose product carries an image, and the image dialog") +def s_payment_product_image(c: Ctx) -> None: + """`ProductImageDialog` has exactly one caller: tapping a product's image + on the payment prompt. No order any scenario made carried an image, so + neither the image nor the dialog had ever been drawn. + """ + order = c.merchant.create_order( + "EUR:2", summary="Order with a pictured product", + products=[{"description": "A red square", "price": "EUR:2", + "image": PRODUCT_IMAGE, "quantity": 1}], + ) + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)A red square|Review order|^Pay\b", timeout=60) + c.note("prompt with a product: " + str(screen.texts()[:14])) + if screen.find(r"(?i)A red square") is None: + c.note("WARNING: the product is not on the prompt at all") + c.check() + + # The image carries no content description (PromptPaymentComposable.kt:372 + # passes null), so it can only be found as an unnamed clickable -- which + # is also what a11y_audit would say about it, if any order it saw had an + # image. + unnamed = screen.unnamed_clickables() + c.note(f"{len(unnamed)} unnamed clickable(s): " + + str([n.bounds for n in unnamed][:6])) + if not unnamed: + c.note("no unnamed clickable, so the image did not render") + c.check() + return + target = min(unnamed, key=lambda n: n.area) + c.dev.tap(*target.center) + time.sleep(2) + after = c.dev.dump() + c.note("after tapping the image: " + str(after.texts()[:12])) + # The dialog is its own window with no text in it, so what says it opened + # is that the prompt behind it is no longer in the dump. + if after.find(r"(?i)^Pay\b|Review order") is None: + c.note("the image dialog is up: the prompt is no longer dumped") + c.check() + # It dismisses by being tapped. + c.dev.tap(*target.center) + time.sleep(2) + back = c.dev.dump() + c.note("after dismissing: " + str(back.texts()[:12])) + if back.find(r"(?i)^Pay\b|Review order") is None: + c.note("WARNING: the prompt did not come back") + else: + c.note("tapping the smallest unnamed clickable changed nothing; " + "the image may be elsewhere in the row") + c.check() + # Leave nothing pending behind. + c.tap(r"(?i)^Cancel$|^Abort$", timeout=8) + c.ep.check_database() + + +@scenario("payment_choices", setup="funded", + about="a v1 order with several choices to pick from") +def s_payment_choices(c: Ctx) -> None: + c.merchant.create_token_family("simdiscount", "discount") + order = c.merchant.create_v1_order( + [ + {"amount": "EUR:2", "description": "Full price", "inputs": [], + "outputs": [], "max_fee": "EUR:0.5"}, + {"amount": "EUR:1", "description": "Discounted, needs a token", + "inputs": [c.merchant.token_input("simdiscount")], "outputs": [], + "max_fee": "EUR:0.5"}, + {"amount": "EUR:3", "description": "Full price plus a token", + "inputs": [], "outputs": [c.merchant.token_output("simdiscount")], + "max_fee": "EUR:0.5"}, + ], + summary="Three ways to pay", + ) + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)Review order|choice|Full price|Total:|^Pay", timeout=60) + c.note("choices prompt: " + str(screen.texts()[:18])) + c.check() + # Pick the choice that needs no token, then pay it. + c.tap(r"(?i)Full price$", timeout=15) + c.check() + c.tap(r"(?i)^Pay\b|confirm payment", timeout=30) + time.sleep(4) + status = c.merchant.order_status(order["order_id"], order["token"]) + c.note(f"order status: {status.get('order_status')}") + c.check() + c.ep.check_database() + + +@scenario("subscription_issued_and_viewed", setup="funded", + about="buy a subscription token and open it under Passes") +def s_subscription_issued_and_viewed(c: Ctx) -> None: + """A subscription the wallet actually holds. + + `payment_needs_token` creates a subscription family and *demands* the + token, so the wallet never holds one and `PassList`'s rows never render -- + the pass list item and `SubscriptionListDetail` are the uncovered half of + `TokenListScreen`. This buys one instead: an order whose output is a + subscription token. + """ + c.merchant.create_token_family("simsub", "subscription", "Simulator pass") + order = c.merchant.create_v1_order( + [{"amount": "EUR:2", "description": "A month of something", + "inputs": [], "outputs": [c.merchant.token_output("simsub")], + "max_fee": "EUR:0.5"}], + summary="Subscription purchase", + ) + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)Review order|Total:|^Pay\b|subscription", timeout=60) + c.note("subscription prompt: " + str(screen.texts()[:14])) + c.check() + c.must_tap(r"(?i)^Pay\b|confirm payment", timeout=30) + deadline = time.time() + 60 + paid = False + while time.time() < deadline: + if c.merchant.order_status(order["order_id"], + order["token"]).get("order_status") == "paid": + paid = True + break + time.sleep(2) + c.note(f"the merchant says the order was paid: {paid}") + c.check() + + # "Passes" is the subscription view; "Discounts" is the other one. + c.back_to_home() + try: + c.app.scroll_to_text(r"(?i)^Passes$", max_scrolls=6) + except TimeoutError: + c.note("no Passes entry on the main screen: " + + str(c.dev.dump().texts()[:16])) + c.check() + c.ep.check_database() + return + c.must_tap(r"(?i)^Passes$", timeout=10) + time.sleep(2.5) + screen = c.dev.dump() + c.note("passes: " + str(screen.texts()[:16])) + # Not matched on the family's name: `create_token_family` returns 409 when + # the slug exists and leaves the old name in place, so "simsub" is called + # whatever the scenario that created it first called it. What says a pass + # is listed is a row with a validity. + if screen.find(r"(?i)^Active$|Valid until") is None: + c.note("WARNING: the pass the wallet just bought is not listed") + c.check() + # Tapping a row opens its detail, which is its own composable. + rows = [n for n in screen.labelled() + if re.search(r"(?i)Valid until|^Active$|tokens issued", n.label)] + if rows: + c.dev.tap(*rows[0].center) + time.sleep(2) + c.note("pass detail: " + str(c.dev.dump().texts()[:14])) + c.check() + for tab in (r"(?i)^Available$", r"(?i)^Expired$"): + if c.tap(tab, timeout=6): + time.sleep(1.5) + c.note(f"{tab}: " + str(c.dev.dump().texts()[:10])) + c.check() + c.ep.check_database() + + +@scenario("payment_needs_token", setup="funded", + about="an order that can only be paid with a token the wallet lacks") +def s_payment_needs_token(c: Ctx) -> None: + c.merchant.create_token_family("simsub", "subscription") + order = c.merchant.create_v1_order( + [{"amount": "EUR:0", "description": "Subscribers only", + "inputs": [c.merchant.token_input("simsub")], "outputs": [], + "max_fee": "EUR:0.5"}], + summary="Requires a subscription token", + ) + c.app.handle_uri(order["pay_uri"]) + time.sleep(4) + screen = c.dev.dump() + c.note("prompt without the token: " + str(screen.texts()[:16])) + # The wallet should explain that it cannot satisfy the contract. + if screen.find(r"(?i)token|subscription|cannot|unavailable|missing|insufficient") is None: + c.note("WARNING: nothing on screen explains the missing token") + c.check() + c.ep.check_database() + + +@scenario("payment_pos_confirmation", setup="funded", + about="an order tied to a point-of-sale device shows its TOTP code") +def s_payment_pos_confirmation(c: Ctx) -> None: + """`PayTotpComposable` is only reachable through a pos_confirmation. + + The merchant puts one in the pay reply when the order names an OTP + device, and the wallet then renders the code (and an NDEF message) on the + payment's detail screen. + """ + c.merchant.create_otp_device("simpos") + order = c.merchant.create_order("EUR:1", summary="Point of sale order", + otp_id="simpos") + c.app.handle_uri(order["pay_uri"]) + c.app.dev.tap_text(r"(?i)^pay\b|confirm payment", timeout=60) + deadline = time.time() + 90 + while time.time() < deadline: + if c.merchant.order_status(order["order_id"], + order["token"]).get("order_status") == "paid": + break + time.sleep(2) + else: + raise RuntimeError(f"order {order['order_id']} was not paid") + screen = c.require(r"(?i)Payment|Completed|paid", timeout=45) + c.note("after paying a pos order: " + str(screen.texts()[:16])) + # The merchant returns every T-OTP code in the valid time range, newline + # separated, and the wallet prints the lot in one Text node. + codes = [line.strip() for t in screen.texts() for line in t.splitlines() + if re.fullmatch(r"\d{6,}", line.strip())] + c.note(f"confirmation codes on the detail screen: {codes}") + if not codes: + c.note("WARNING: no pos_confirmation shown for an order with an OTP device") + elif len(codes) > 1: + c.note(f"WARNING: {len(codes)} codes shown under a singular label") + c.check() + # A TOTP code is valid for 30 s, and the composable has a timer that + # recomputes it -- so staying on the screen for one period is the only way + # to run that half of PayTotpComposable. + time.sleep(35) + later = c.dev.dump() + codes_later = [line.strip() for x in later.texts() for line in x.splitlines() + if re.fullmatch(r"\d{6,}", line.strip())] + c.note(f"codes after one TOTP period: {codes_later}") + if codes and codes_later and codes == codes_later: + c.note("the codes did not change across a TOTP period") + c.check() + c.ep.check_database() + + +@scenario("a11y_audit", setup="paid", + about="walk the main screens and list clickable elements with no name") +def s_a11y_audit(c: Ctx) -> None: + """Every unnamed clickable node is a control a screen reader cannot announce. + + Layout containers show up too, so this records rather than judges; what + makes it useful is the per-screen count and the neighbouring labels, which + is how the Send/Request/Withdraw/Deposit defect was spotted. + """ + visited: dict[str, int] = {} + + def audit(where: str) -> None: + screen = c.dev.dump() + unnamed = screen.unnamed_clickables() + visited[where] = len(unnamed) + if unnamed: + near = [] + for node in unnamed[:6]: + label = min( + (n for n in screen.labelled()), + key=lambda n: abs(n.center[1] - node.center[1]) + + abs(n.center[0] - node.center[0]) // 4, + default=None, + ) + near.append(f"{node.cls.rsplit('.', 1)[-1]}@{node.center}" + f"~{label.label[:18] if label else '?'}") + c.note(f"{where}: {len(unnamed)} unnamed clickables: {near}") + else: + c.note(f"{where}: all clickable elements are named") + c.check() + + c.back_to_home() + audit("main") + c.app.open_settings() + audit("settings") + for label, where in ((r"(?i)^Payment services$", "exchange list"), + (r"(?i)^Bank accounts$", "bank accounts")): + c.app.open_settings() + try: + c.app.scroll_to_text(label, max_scrolls=10) + except TimeoutError: + continue + if c.tap(label): + audit(where) + c.back_to_home() + for label, where in ((r"(?i)^Send$", "peer send"), (r"(?i)^Request$", "peer request"), + (r"(?i)^Deposit$", "deposit"), (r"(?i)^Withdraw$", "withdraw")): + c.back_to_home() + if c.tap(label, timeout=15): + audit(where) + screen = open_transactions(c) + rows = transaction_rows(screen) + if rows: + c.dev.tap_node(rows[0], screen) + time.sleep(2) + audit("transaction detail") + c.note(f"summary: {visited}") + c.check() + + +@scenario("exchange_url_fuzz", setup="fresh", + about="hostile payment-service URLs in the add-exchange field") +def s_exchange_url_fuzz(c: Ctx) -> None: + urls = [ + "", + "not a url", + "http://", + "http://localhost:9/", # nothing listening + "http://localhost:8082/", # a bank, not an exchange + "https://localhost:8081/", # right host, wrong scheme + "http://localhost:8081/../../etc/passwd", + "http://127.0.0.1:8081/", # same exchange, other spelling + "http://localhost:8081/" + "a" * 500, + "http://日本語.example/", + "javascript:alert(1)", + "file:///etc/passwd", + ] + # The dialog closes back onto the exchange list, so the list is opened + # once and every address goes through from there. + open_exchange_list(c) + for url in urls: + if not c.tap(r"(?i)^Add payment service$", timeout=20): + c.note("no add-payment-service entry; " + + str(c.dev.dump().texts()[:8])) + break + screen = c.see(r"(?i)Enter address of payment service|address", timeout=20) + fields = screen.editable() if screen else [] + if not fields: + c.note("no URL field") + c.dev.back() + continue + c.dev.tap_node(fields[0], screen) + if url: + c.dev.type_text(url) + c.tap(r"(?i)^OK$|^Add$|^Continue$|^Next$", timeout=10) + time.sleep(2) + after = c.dev.dump() + c.note(f"{url[:46]!r} -> {after.texts()[:8]}") + c.check() + if after.find(r"(?i)Enter address of payment service") is not None: + # The dialog stayed open (it should, with an error); close it. + c.tap(r"(?i)^Cancel$", timeout=6) + c.ep.check_database() + + +@scenario("peer_expiry_custom", setup="funded", + about="the peer-send expiry picker, including a custom period") +def s_peer_expiry(c: Ctx) -> None: + c.back_to_home() + c.must_tap(r"(?i)^Send$", timeout=30) + c.require(r"(?i)Send money|Amount to send|Purpose", timeout=30) + c.set_amount("€5.00", "500") + for option in (r"(?i)^1 day$", r"(?i)^1 week$", r"(?i)^30 days$", r"(?i)^Custom$"): + if not c.tap(r"(?i)Expires in|^1 week$|^1 day$|^30 days$|^Custom$", timeout=8): + break + if c.tap(option, timeout=8): + c.note(f"picked {option}") + c.check() + # Custom opens day and hour fields. + screen = c.dev.dump() + if screen.find(r"(?i)^Days$|^Hours$"): + c.note("custom expiry fields: " + str(screen.texts()[:10])) + c.fill("3", 1) + c.check() + c.tap(r"(?i)^Send ", timeout=20) + time.sleep(4) + c.note("after send: " + str(c.dev.dump().texts()[:10])) + c.check() + c.ep.check_database() + + +@scenario("deposit_methods", setup="funded", + about="all three deposit account types and their validation") +def s_deposit_methods(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Bank accounts$") + c.must_tap(r"(?i)^Bank accounts$") + c.require(r"(?i)Known bank accounts|No bank accounts saved|Add account", timeout=25) + if not c.tap(r"(?i)^Add account$", timeout=20): + c.note("no add-account entry") + return + c.require(r"(?i)IBAN|x-taler-bank|Bitcoin|Account holder", timeout=25) + cases = [ + (r"(?i)^IBAN$", [("Holder One", 0), ("DE89370400440532013000", 1)]), + (r"(?i)^x-taler-bank$", [("Holder Two", 0), ("http://localhost:8082/wallet1", 1)]), + # The Bitcoin tab has no holder field: its first field is the address + # and the second is the note. Filling them the other way round sent + # `payto://bitcoin/Holder%20Three` and read as a wallet defect. + (r"(?i)^Bitcoin$", [("bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh", 0), + ("Holder Three", 1)]), + ] + for tab, fields in cases: + # A successful submit closes the form and goes back to the account + # list, so every case has to open it again -- without this the first + # case to succeed left the later tabs with no form to tap, and the + # Bitcoin one was never tried ("no Bitcoin tab"). + if c.dev.dump().find(r"(?i)^Note$") is None: + if not c.tap_button(r"(?i)^Add account$", timeout=15): + c.note("could not reopen the add-account form") + break + # "IBAN" is also the wire method printed on an account *row*, so + # requiring it matches the list we just came from; the note field + # exists only on the form. + if c.see(r"(?i)^Note$", timeout=20) is None: + c.note("the add-account form did not reopen: " + + str(c.dev.dump().texts()[:10])) + break + if not c.tap(tab, timeout=10): + c.note(f"no {tab} tab: " + str(c.dev.dump().texts()[:10])) + continue + c.check() + for value, index in fields: + c.fill(value, index, clear=True) + # Every type needs the unmarked "Note" field, or the submit button + # stays disabled and the account is never added -- which is how this + # scenario reported "ok" while adding nothing. + name = re.sub(r"[^A-Za-z-]", "", tab.replace("(?i)", "")) + fill_account_note(c, f"Simulator {name}") + time.sleep(1) + screen = c.dev.dump() + complaints = [t for t in screen.texts() + if "invalid" in t.lower() or "error" in t.lower()] + c.note(f"{tab}: complaints={complaints[:2]} labels={screen.texts()[:8]}") + c.tap_button(r"(?i)^Add account$|^Save$|^OK$", timeout=8) + time.sleep(3) + c.note(f"{tab} after submitting: {c.dev.dump().texts()[:10]}") + c.check() + c.ep.check_database() + + +@scenario("deposit_bad_payto", setup="funded", + about="deposit to an account the exchange will reject, then read the " + "failed transaction") +def s_deposit_bad_payto(c: Ctx) -> None: + # A syntactically fine IBAN that belongs to nobody: the deposit should be + # accepted by the wallet and then fail, which is the only cheap way to + # reach the failed-transaction screens. + bad = "payto://iban/SANDBOXX/DE02100100109307118603?receiver-name=Nobody" + c.app.handle_uri(bad) + time.sleep(3) + screen = c.dev.dump() + c.note("payto prompt: " + str(screen.texts()[:12])) + c.check() + if screen.editable(): + # Amount fields take digits from the right: "100" is 1.00, and "1" + # made a one-cent deposit. No clear=True: on this field the 80 + # KEYCODE_DELs leave it at 0.00 and the typed digits do not land, so + # the submit button stays disabled. + c.fill("100") + # The button on this screen is "Send", not "Deposit": tapping for the + # latter did nothing at all, and the scenario then read the funding + # withdrawal's detail and called it a failed deposit. + tap_if_any(c, (r"(?i)^Check fees$",)) + if not c.tap_button(r"(?i)^Send$|^Make deposit$|^Deposit$", timeout=20): + c.note("nothing to submit the deposit with: " + + str(c.dev.dump().texts()[:12])) + time.sleep(8) + c.note("after depositing: " + str(c.dev.dump().texts()[:12])) + c.check() + # Whatever state it reached, look at the transaction and its actions. + screen = open_transactions(c) + rows = transaction_rows(screen) + if rows: + c.dev.tap_node(rows[0], screen) + time.sleep(2) + detail = c.dev.dump() + c.note("deposit detail: " + str(detail.texts()[:12])) + # A transaction that carries an error shows an "Error" button in + # developer mode, and it is the only way into + # ErrorTransactionComposable's dialog -- the error object as JSON, with + # a copy button. + if c.tap(r"(?i)^Error$", timeout=10): + dialog = c.dev.dump() + c.note("the error dialog: " + str(dialog.texts()[:10])) + c.check() + c.tap(r"(?i)^OK$|^Close$|^Cancel$|^Copy$", timeout=8) + time.sleep(1.5) + else: + c.note("no Error button on the failed deposit: " + + str([n.label for n in detail.tappable() if n.label][:10])) + for action in (r"(?i)^Retry$", r"(?i)^Abandon$", r"(?i)^Abort$"): + if c.tap(action, timeout=8): + c.tap(r"(?i)^Abandon$|^Abort$|^OK$|^Yes$", timeout=6) + time.sleep(2) + c.check() + break + c.check() + c.ep.check_database() + + +@scenario("withdraw_to_dead_exchange", setup="fresh", + about="withdraw from an exchange that is not listening", + expects=("background-error", "stuck-operation", "error-screen")) +def s_withdraw_dead_exchange(c: Ctx) -> None: + c.app.handle_uri("taler+http://withdraw-exchange/localhost:9/") + time.sleep(5) + screen = c.dev.dump() + c.note("dead exchange: " + str(screen.texts()[:12])) + c.check() + c.tap(r"(?i)^Retry$", timeout=10) + time.sleep(4) + c.check() + c.back_to_home() + rows = transaction_rows(open_transactions(c)) + c.note(f"{len(rows)} transactions after the failed attempt") + if rows: + screen = open_transactions(c) + c.dev.tap_node(transaction_rows(screen)[0], screen) + time.sleep(2) + c.note("failed withdrawal detail: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + + +@scenario("withdraw_account_details", setup="funded", + about="the manual withdrawal's account picker and wire details") +def s_withdraw_account_details(c: Ctx) -> None: + c.back_to_home() + c.must_tap(r"(?i)^Withdraw$", timeout=30) + c.require(r"(?i)Amount to withdraw|Select target bank account|Payment service", + timeout=30) + c.set_amount("€5.00", "500") + c.check() + # Tapping the age row opens the picker, which covers the confirm button, so + # an age has to be chosen before confirming; the age path itself is + # withdraw_age_restricted's job. + if c.tap(r"(?i)Restrict usage to age|Unrestricted", timeout=6): + if not c.tap(r"(?i)^Unrestricted$|^18$", timeout=8): + c.dev.back() + time.sleep(1) + c.accept_tos() + c.must_tap(r"(?i)Confirm withdrawal|^Withdraw$", timeout=25) + # A manual withdrawal waits for a wire transfer, and its detail screen + # links to the instructions. + screen = c.require(r"(?i)Wire transfer instructions|transaction is pending", + timeout=45) + c.note("pending withdrawal: " + str(screen.texts()[:12])) + c.check() + c.must_tap(r"(?i)Wire transfer instructions", timeout=25) + screen = c.require(r"(?i)Subject|Recipient|IBAN|Account", timeout=30) + c.note("transfer instructions: " + str(screen.texts()[:16])) + c.check() + # Copy buttons, the QR variants and the hand-off to a banking app. + copies = [n for n in screen.tappable() if n.label.strip().lower() == "copy"] + c.note(f"{len(copies)} copy buttons") + if copies: + c.dev.tap_node(copies[0], screen) + time.sleep(1) + c.check() + for label in (r"(?i)Wire transfer QR codes", r"(?i)EPC QR", r"(?i)Swiss QR bill", + r"(?i)Unknown payment QR", r"(?i)Open in banking app", + r"(?i)^Share$"): + try: + c.app.scroll_to_text(label, max_scrolls=4) + except TimeoutError: + continue + c.note(f"saw {label}") + if "Share" not in label and "banking app" not in label: + c.tap(label, timeout=6) + c.check() + c.ep.check_database() + + +@scenario("withdraw_account_tabs", setup="funded", + about="every wire account the exchange offers for a manual withdrawal") +def s_withdraw_account_tabs(c: Ctx) -> None: + """One transfer screen per wire method. + + `TransferAccountChooser` only appears once the exchange advertises more + than one account, and the IBAN and Bitcoin transfer screens are only + reachable through it. + """ + c.back_to_home() + c.must_tap(r"(?i)^Withdraw$", timeout=30) + c.require(r"(?i)Amount to withdraw|Select target bank account|Payment service", + timeout=30) + c.set_amount("€5.00", "500") + # Deliberately leave the age chooser alone: tapping it opens the age picker + # and hides the confirm button, and the age path has its own scenario. + c.accept_tos() + c.must_tap(r"(?i)Confirm withdrawal|^Withdraw$", timeout=25) + screen = c.require(r"(?i)Wire transfer instructions|transaction is pending", + timeout=45) + c.note("pending withdrawal screen: " + str(screen.texts())) + tabs = [t for t in screen.texts() if re.match(r"(?i)^Account #\d", t.strip())] + c.note(f"account tabs: {tabs}") + if not tabs: + c.note("the exchange advertises a single wire account; nothing to choose") + for tab in tabs or [None]: + if tab is not None: + # Tap the tab by its node: the label carries parentheses and the + # account index, which is awkward to match as a pattern. + screen = c.dev.dump() + node = next((n for n in screen.labelled() + if n.label.strip() == tab.strip()), None) + if node is None: + c.note(f"could not find the tab {tab!r} again") + continue + # Tap the tab's own centre: the neighbour search in tap_target + # would reach the app bar's back arrow, which is within its reach. + c.dev.tap(*node.center) + time.sleep(2) + c.check() + try: + c.app.scroll_to_text(r"(?i)Wire transfer instructions", max_scrolls=4) + except TimeoutError: + c.note(f"{tab}: no instructions link; screen " + + str(c.dev.dump().texts())) + continue + if not c.tap(r"(?i)Wire transfer instructions", timeout=20): + c.note(f"{tab}: the instructions link would not tap") + continue + # Each method has its own labels: a subject and a recipient for + # x-taler-bank, an IBAN block for IBAN, and a split transaction with + # segwit outputs for Bitcoin. + screen = c.require(r"(?i)Subject|Recipient|IBAN|Account|Address|" + r"split transaction|BTC", timeout=30) + c.note(f"{tab} instructions: {screen.texts()[:14]}") + if screen.find(r"(?i)BTC") is not None: + amounts = [t for t in screen.texts() if "BTC" in t] + c.note(f"{tab}: amounts labelled BTC: {amounts[:4]}") + c.check() + # Each method renders its own transfer screen; the QR variants hang off + # it and differ per method (EPC for IBAN, none for Bitcoin). + for label in (r"(?i)Wire transfer QR codes", r"(?i)EPC QR", + r"(?i)Swiss QR bill", r"(?i)Unknown payment QR"): + try: + c.app.scroll_to_text(label, max_scrolls=3) + except TimeoutError: + continue + c.note(f"{tab}: saw {label}") + c.tap(label, timeout=6) + c.check() + c.dev.back() + c.require(r"(?i)Wire transfer instructions|transaction is pending", timeout=25) + c.ep.check_database() + + +def second_exchange_or_skip(c: Ctx) -> Optional[str]: + """The second exchange's URL, or None with a note saying why not. + + exchange2.sh runs it beside the stack; it is not part of the stack itself, + so a scenario that needs two payment services has to cope without one. + """ + url = getattr(c.env, "exchange2", None) or SECOND_EXCHANGE + try: + import urllib.request + with urllib.request.urlopen(url + "config", timeout=5) as r: + if r.status != 200: + raise RuntimeError(f"HTTP {r.status}") + except Exception as e: # noqa: BLE001 - absence is a skip, not a failure + c.note(f"no second exchange at {url} ({str(e)[:60]}); nothing to choose") + return None + # Reachable from here is not reachable from the emulator: without the + # reverse mapping the wallet adds nothing and says nothing about it, which + # looks exactly like a scenario that worked. + port = url.rstrip("/").rsplit(":", 1)[-1] + if f"tcp:{port}" not in c.dev.adb("reverse", "--list", check=False): + c.note(f"port {port} is not mapped into {c.dev.serial}; " + f"the wallet cannot reach the second exchange") + return None + return url + + +def service_or_skip(c: Ctx, url: str, what: str) -> Optional[str]: + """A service beside the stack, if it is up and the emulator can reach it.""" + try: + import urllib.request + with urllib.request.urlopen(url + "config", timeout=5) as r: + if r.status != 200: + raise RuntimeError(f"HTTP {r.status}") + except Exception as e: # noqa: BLE001 - absence is a skip, not a failure + c.note(f"no {what} at {url} ({str(e)[:60]})") + return None + port = url.rstrip("/").rsplit(":", 1)[-1] + if f"tcp:{port}" not in c.dev.adb("reverse", "--list", check=False): + c.note(f"port {port} is not mapped into {c.dev.serial}; " + f"the wallet cannot reach the {what}") + return None + return url + + +def add_exchange_by_url(c: Ctx, url: str) -> None: + """Settings -> Payment services -> Add, typing a URL.""" + open_exchange_list(c) + c.must_tap(r"(?i)^Add payment service$") + screen = c.require(r"(?i)Enter address of payment service|address", timeout=30) + fields = screen.editable() + if not fields: + raise RuntimeError(f"no URL field on the add screen: {screen.texts()}") + c.dev.tap_node(fields[0], screen) + c.dev.type_text(url) + c.tap(r"(?i)^Add$|^OK$|^Continue$|^Next$") + time.sleep(4) + # Adding one may ask for its terms of service. + c.tap(r"(?i)^Accept Terms of Service$|^Accept$|I accept", timeout=8) + time.sleep(2) + c.check() + + +@scenario("exchange_two_services", setup="fresh", + about="two payment services in the same currency, side by side") +def s_exchange_two_services(c: Ctx) -> None: + second = second_exchange_or_skip(c) + if second is None: + return + add_exchange_by_url(c, LOCAL_EXCHANGE) + add_exchange_by_url(c, second) + open_exchange_list(c) + screen = c.require(r"(?i)Currency:|localhost", timeout=25) + listed = [t for t in screen.texts() if "localhost" in t] + c.note(f"payment services listed: {listed}") + if len(listed) < 2: + c.note("WARNING: the second payment service is not listed") + c.check() + # The per-exchange menu, which is how the app exposes anything about one: + # tapping the URL itself does not navigate. + for which in ("8081", "8091"): + open_exchange_list(c) + if not exchange_menu(c, f"localhost:{which}"): + c.note(f"no menu for localhost:{which}") + continue + time.sleep(1.5) + c.note(f"{which} menu: {c.dev.dump().texts()[:14]}") + c.check() + c.dev.back() + c.ep.check_database() + + +@scenario("withdraw_pick_exchange", setup="funded", + about="the manual withdrawal's payment-service dropdown") +def s_withdraw_pick_exchange(c: Ctx) -> None: + """Choosing which payment service to withdraw from. + + This was written for `SelectExchangeDialogFragment`, on the assumption that + a withdrawal with two candidates would raise it. It does not: + **that fragment has no caller anywhere in the app** (the last + DialogFragment left, and dead), and the bank-integrated prompt has no + service row at all -- its exchange is fixed, and the prompt shows only the + amount, the age restriction and "Confirm withdrawal". + + The real control is on the *manual* withdraw screen: an + `AmountScopeField` whose "via <service>" row is an exposed dropdown over + the known scopes. It is `clickable` but **disabled** until the service's + terms are accepted, which is what made every earlier attempt tap a + neighbour and leave the screen. + """ + second = second_exchange_or_skip(c) + if second is None: + return + add_exchange_by_url(c, second) + c.back_to_home() + c.must_tap(r"(?i)^Withdraw$", timeout=30) + screen = c.require(r"(?i)Amount to withdraw|Select target|Payment service|via", + timeout=30) + c.note("the manual withdraw screen: " + str(screen.texts()[:18])) + c.check() + # Terms first: the dropdown is disabled until they are accepted. + c.accept_tos() + row = next((n for n in c.dev.dump().labelled() + if re.match(r"(?i)^https?://", n.label.strip())), None) + if row is None: + c.note("no payment-service row on the withdraw screen") + return + target = c.dev.dump().tap_target(row) + c.note(f"the service row {row.label!r}: clickable={target.clickable} " + f"enabled={target.enabled}") + if not target.enabled: + c.note("the service row is still disabled after accepting the terms") + c.check() + return + c.dev.tap_node(target) + time.sleep(2) + opened = c.dev.dump() + c.note("after opening the dropdown: " + str(opened.texts()[:18])) + c.check() + # The menu lists one entry per known scope. + if c.tap(r"(?i)localhost:8091|8091", timeout=10): + time.sleep(2) + c.note("picked the second service: " + str(c.dev.dump().texts()[:14])) + else: + c.note("the second service is not among the scopes offered") + c.check() + c.set_amount("€5.00", "500") + c.accept_tos() + c.tap_button(r"(?i)Confirm withdrawal|^Withdraw", timeout=25) + time.sleep(5) + c.note("after confirming: " + str(c.dev.dump().texts()[:16])) + c.check() + c.ep.check_database() + + +@scenario("balances_two_exchanges", setup="fresh", + about="coins from two payment services in one currency") +def s_balances_two_exchanges(c: Ctx) -> None: + """Two services in one currency is what creates a second balance scope, + and what "treat as global" is for.""" + second = second_exchange_or_skip(c) + if second is None: + return + # Coins from the stack's exchange, through the bank as usual. + flows.withdraw(c.app, c.bank, "EUR:10") + c.app.home() + add_exchange_by_url(c, second) + c.back_to_home() + screen = c.dev.dump() + c.note("home with two services: " + str(screen.texts()[:18])) + c.check() + # The balance detail and its transaction list, per scope. + if c.tap(r"(?i)^€|EUR", timeout=10): + time.sleep(2) + c.note("balance detail: " + str(c.dev.dump().texts()[:16])) + c.check() + c.back_to_home() + # "Treat as global" lives in the per-exchange menu and is where a null + # master key used to come from. + open_exchange_list(c) + # Contact each service before treating it as global: "treat as global" + # sends the master public key, which is null until the exchange's /keys + # has been fetched, and a null one is dropped from the request -- + # findings/addglobalcurrencyexchange-null-masterpub.md. The second + # service is the one that arrives un-contacted, with its terms + # unaccepted. + for which in ("8081", "8091"): + if not exchange_menu(c, f"localhost:{which}"): + continue + time.sleep(1) + if c.tap(r"(?i)^Accept Terms of Service$", timeout=6): + time.sleep(2) + c.accept_tos() + open_exchange_list(c) + exchange_menu(c, f"localhost:{which}") + time.sleep(1) + if c.tap(r"(?i)^Reload information$", timeout=8): + time.sleep(4) + c.note(f"{which}: reloaded") + open_exchange_list(c) + for which in ("8081", "8091"): + if not exchange_menu(c, f"localhost:{which}"): + c.note(f"no menu for localhost:{which}") + continue + time.sleep(1) + c.note(f"{which} menu: {c.dev.dump().texts()[:12]}") + if c.tap(r"(?i)Treat as global|global currency", timeout=8): + time.sleep(3) + c.note(f"{which} after treat-as-global: {c.dev.dump().texts()[:12]}") + c.check() + open_exchange_list(c) + + # With both services global, the currency scope carries both their shopping + # URLs, and the card goes to ExchangeShoppingScreen rather than straight + # out to a browser -- MainScreen.kt:188 opens the browser when there is + # exactly one URL, so one service can never reach that screen. + c.back_to_home() + try: + c.app.scroll_to_text(r"(?i)^Where to pay with ", max_scrolls=6) + except TimeoutError: + c.note("no shopping card on the main screen: " + + str(c.dev.dump().texts()[:16])) + c.check() + c.ep.check_database() + return + if not c.tap(r"(?i)^Where to pay with ", timeout=10): + c.note("the shopping card would not tap") + else: + time.sleep(3) + screen = c.dev.dump() + # Recognised by the screen's own message rather than its title: the + # title reads "Where to pay with EUR", which is also what the card on + # the main screen says, so matching the title cannot tell the two + # apart. + if screen.find(r"(?i)offers the following website") is not None: + c.note("the shopping screen: " + str(screen.texts()[:12])) + # Each row is one exchange's shopping URL; opening one leaves the + # app, so the list itself is what is checked here. + rows = [n for n in screen.labelled() if "http" in n.label.lower()] + c.note(f"{len(rows)} shopping URLs listed: " + + str([n.label[:40] for n in rows])) + else: + # MainScreen.kt:188 only navigates when the scope carries more than + # one shopping URL; with one it opens the URL instead, which is + # what this means. + c.note("the card did not open the shopping screen, so the scope " + "still carries one shopping URL: " + + str(screen.texts()[:12])) + c.check() + c.ep.check_database() + + +@scenario("revoke_denomination", setup="funded", + about="revoke a denomination the wallet holds and watch the recoup", + # Revocation is supposed to make the wallet give the coins back to + # the exchange and get new ones; errors along the way are the point. + expects=("background-error", "stuck-operation", "internal-error-code", + "error-screen", "core-internal")) +def s_revoke_denomination(c: Ctx) -> None: + """What happens when the exchange withdraws a denomination under the wallet. + + Destructive and stack-wide -- the denomination stays revoked until the + stack is started again -- so this only runs when a phase says so with + SIM_DESTRUCTIVE=1. + """ + if os.environ.get("SIM_DESTRUCTIVE") != "1": + c.note("destructive scenarios are off; set SIM_DESTRUCTIVE=1 in a phase") + return + import dbprobe + c.back_to_home() + before = c.dev.dump() + c.note("balance before: " + str(before.texts()[:8])) + + db = dbprobe.pull(c.dev) + held = dbprobe.rows(db, "select denom_pub_hash, count(*) c from coins " + "where status = 'fresh' group by denom_pub_hash " + "order by c asc", limit=10) + if not held: + c.note("the wallet holds no fresh coins; nothing to revoke") + return + c.note(f"the wallet holds {len(held)} denominations: " + + str([r["c"] for r in held])) + # The one it holds fewest of: enough to force a recoup without taking the + # whole balance away. + target = held[0]["denom_pub_hash"] + try: + crock = stack_mod.revoke_denomination(target) + except Exception as e: # noqa: BLE001 - reported as a note, not a crash + c.note(f"could not revoke: {str(e)[:200]}") + return + c.note(f"revoked {crock} ({held[0]['c']} coin(s) held)") + + # The wallet learns about it from /keys, which it re-reads on its own + # schedule. Opening the exchange list is not enough; the menu has a + # "Reload information" entry, which is the user's way of asking. + open_exchange_list(c) + if exchange_menu(c): + time.sleep(1) + if c.tap(r"(?i)^Reload information$", timeout=10): + c.note("asked the wallet to reload the exchange") + time.sleep(8) + c.back_to_home() + for _ in range(20): + time.sleep(6) + screen = c.dev.dump() + if screen.find(r"(?i)recoup|loss of funds") is not None: + c.note("something about a recoup or a loss appeared") + break + c.note("home after revocation: " + str(c.dev.dump().texts()[:12])) + c.check() + open_transactions(c) + c.note("transactions after revocation: " + + str(c.dev.dump().texts()[:16])) + c.check() + # The database knows about losses and recoups even when the screens say + # nothing. A revocation the wallet has seen leaves a trace in one of + # these; nothing in any of them means it never noticed. + db = dbprobe.pull(c.dev) + for table in ("denom_loss_events", "recoup_groups", "coins"): + try: + rows = dbprobe.rows(db, f"select * from {table}", limit=3) + c.note(f"{table}: {len(rows)} rows") + except Exception as e: # noqa: BLE001 + c.note(f"{table}: {str(e)[:80]}") + try: + rows = dbprobe.rows(db, "select status, count(*) c from coins " + "group by status", limit=8) + c.note("coins by status: " + str([dict(r) for r in rows])) + except Exception as e: # noqa: BLE001 + c.note(f"coin status: {str(e)[:80]}") + log = c.dev.logcat(lines=600) + hits = [l for l in log.splitlines() + if "recoup" in l.lower() or "revok" in l.lower()][:3] + c.note("the log on recoup/revocation: " + (" / ".join(hits)[:300] or "nothing")) + + # Recoup is how the money comes back, and it is a background task: the + # first measurement above catches the coin marked `denom-loss` and the + # balance down by its value, which is the *start* of the story. Whether + # the wallet ends up whole is the question worth answering, so wait for + # the recoup group to finish and say what the balance did. + def shown_balance() -> str: + """The first euro amount on the main screen, as text.""" + c.back_to_home() + for t in c.dev.dump().texts(): + m = re.search(r"€\s*([0-9]+[.,][0-9]{2})", t) + if m: + return m.group(1) + return "?" + + before = shown_balance() + settled = False + for _ in range(20): + time.sleep(15) + db = dbprobe.pull(c.dev) + try: + pending = dbprobe.rows( + db, "select recoup_group_id, operation_status, timestamp_finished " + "from recoup_groups where timestamp_finished is null", limit=5) + except Exception as e: # noqa: BLE001 + c.note(f"recoup_groups: {str(e)[:80]}") + break + if not pending: + settled = True + break + c.note(f"the recoup group finished within five minutes: {settled}") + after = shown_balance() + c.note(f"balance before the wait: {before}, after: {after}") + db = dbprobe.pull(c.dev) + try: + rows = dbprobe.rows(db, "select status, count(*) c from coins " + "group by status", limit=8) + c.note("coins by status once settled: " + str([dict(r) for r in rows])) + except Exception as e: # noqa: BLE001 + c.note(f"coin status: {str(e)[:80]}") + screen = open_transactions(c) + c.note("history once settled: " + str(screen.texts()[:16])) + c.check() + + # A revocation is the one thing in this stack that makes a *EUR* loss + # event, and therefore the only way to the loss transaction and its detail + # screen: the dev experiment's injected loss is hard-coded to TESTKUDOS + # (dev-experiments.ts:243), which a euro wallet has no scope to show it + # under. `TransactionDenomLoss` and `TransitionLossComposable` have never + # rendered for that reason. + row = screen.find(r"(?i)^Loss of funds$") + if row is None: + try: + screen = c.app.scroll_to_text(r"(?i)^Loss of funds$", max_scrolls=6) + row = screen.find(r"(?i)^Loss of funds$") + except TimeoutError: + row = None + if row is None: + c.note("no loss transaction in the history, though the database has " + "a loss event: " + str(screen.texts()[:16])) + c.check() + c.ep.check_database() + return + c.dev.tap_node(row, screen) + time.sleep(2.5) + detail = c.dev.dump() + c.note("the loss detail screen: " + str(detail.texts()[:16])) + # Its own labels: the reason, and one of the three explanations. + if detail.find(r"(?i)^Reason$") is None: + c.note("WARNING: the loss detail shows no reason") + reason = detail.find(r"(?i)not renewed|stopped offering|lost the record") + c.note(f"the loss reason is spelled out: {reason is not None}") + c.check() + c.ep.check_database() + + +@scenario("wallet_lock_without_credential", setup="funded", + about="turn the wallet lock on, then take the device credential away", + expects=("error-screen",)) +def s_wallet_lock(c: Ctx) -> None: + """What happens to a locked wallet when the screen lock goes away. + + "Protect access to wallet" can only be switched on while the device can + authenticate (`enableBiometrics` checks `canAuthenticate`), but nothing + re-checks afterwards, and `BiometricOverlay` covers the whole app with a + single "Tap to unlock" button. Removing the credential afterwards is an + ordinary thing to do. + + Touches the device's lock settings, so it only runs under + SIM_DESTRUCTIVE=1, and it clears the credential again whatever happens. + """ + if os.environ.get("SIM_DESTRUCTIVE") != "1": + c.note("destructive scenarios are off; set SIM_DESTRUCTIVE=1 in a phase") + return + try: + out = c.dev.shell("locksettings set-pin 1234", check=False) + c.note(f"set a device PIN: {out.strip()[:80]}") + if "set" not in out.lower(): + c.note("could not set a device credential; nothing to test") + return + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Protect access to wallet$") + c.must_tap(r"(?i)^Protect access to wallet$", timeout=20) + time.sleep(3) + c.note("after switching the lock on: " + str(c.dev.dump().texts()[:10])) + c.check() + # Locked now: a restart has to ask before showing anything. + c.dev.stop() + time.sleep(2) + c.dev.launch() + time.sleep(6) + locked = c.dev.dump() + # The overlay covers the app, but uiautomator still reports the nodes + # underneath it, so presence has to be asked about rather than read off + # the first few labels. + c.note(f"after a restart with a credential: locked=" + f"{locked.find(r'(?i)Tap to unlock') is not None}; " + + str(locked.texts()[:8])) + if locked.find(r"(?i)Tap to unlock") is None: + c.note("the wallet is not locked; the switch did not take") + return + c.check() + # Now the credential goes away, as it does when a user turns their + # screen lock off. + out = c.dev.shell("locksettings clear --old 1234", check=False) + c.note(f"cleared the device credential: {out.strip()[:80]}") + c.dev.stop() + time.sleep(2) + c.dev.launch() + time.sleep(6) + screen = c.dev.dump() + c.note(f"after a restart with no credential: locked=" + f"{screen.find(r'(?i)Tap to unlock') is not None}; " + + str(screen.texts()[:8])) + c.check() + if screen.find(r"(?i)Tap to unlock") is not None: + c.dev.logcat(clear=True) + c.must_tap(r"(?i)Tap to unlock", timeout=20) + time.sleep(5) + after = c.dev.dump() + still = after.find(r"(?i)Tap to unlock") is not None + c.note(f"after tapping unlock: still locked={still}; " + + str(after.texts()[:8])) + # The prompt reports its refusal through a toast, which is not in + # the hierarchy; the log has it. + log = c.dev.logcat(lines=400) + lines = [l for l in log.splitlines() + if "iometric" in l or "uthenticat" in l] + c.note("authentication log: " + " / ".join(lines[-3:])[:300]) + c.check() + if still: + c.note("WARNING: the wallet cannot be unlocked at all; the only " + "way back in is clearing the app's data, which destroys " + "the coins") + finally: + c.dev.shell("locksettings clear --old 1234", check=False) + c.dev.shell("locksettings set-disabled true", check=False) + + +# wallet-core can be told to fail a named operation from the outside, which is +# the only way to see what each screen does with an error it cannot otherwise +# be made to produce. The detail is base64url JSON with a numeric code. +def api_error_uri(operation: str, code: int = 7001, + hint: str = "injected by the simulator", + count: int = 4) -> str: + import base64 + detail_obj: dict = {"code": code} + if hint: + detail_obj["hint"] = hint + detail = base64.urlsafe_b64encode( + json.dumps(detail_obj).encode()).decode().rstrip("=") + return (f"taler+http://dev-experiment/api-error?operation={operation}" + f"&detail={detail}&count={count}") + + +@scenario("api_error_sweep", setup="funded", + about="make each screen's wallet-core call fail and see what it says", + expects=("error-screen", "internal-error-code", "core-internal", + "silent-failure", "blank-screen")) +def s_api_error_sweep(c: Ctx) -> None: + """One injected failure per screen. + + Every one of these is a reply the app can get in the field -- a request + that times out, an exchange that is down, a database that is busy -- and + each screen either says so or says nothing. The oracles decide; this + scenario only has to get each screen to make its call while the error is + queued. + """ + cases = [ + ("getBalances", lambda: c.back_to_home()), + ("getTransactionsV2", lambda: open_transactions(c)), + ("listExchanges", lambda: open_exchange_list(c)), + ("getContacts", lambda: (c.app.open_settings(), + c.app.scroll_to_text(r"(?i)^Contacts$"), + c.must_tap(r"(?i)^Contacts$"))), + ("listBankAccounts", lambda: (c.app.open_settings(), + c.app.scroll_to_text(r"(?i)^Bank accounts$"), + c.must_tap(r"(?i)^Bank accounts$"))), + ("getDepositWireTypes", lambda: (c.back_to_home(), + c.must_tap(r"(?i)^Deposit$", timeout=20))), + ("getWithdrawalDetailsForAmount", + lambda: (c.back_to_home(), c.must_tap(r"(?i)^Withdraw$", timeout=20))), + ("getMaxPeerPushDebitAmount", + lambda: (c.back_to_home(), c.must_tap(r"(?i)^Send$", timeout=20))), + ("listDiscounts", lambda: (c.back_to_home(), + c.app.scroll_to_text(r"(?i)^Discounts$"), + c.must_tap(r"(?i)^Discounts$"))), + ("getDonau", lambda: (c.app.open_settings(), + c.app.scroll_to_text(r"(?i)^Tax-deductible donations$"), + c.must_tap(r"(?i)^Tax-deductible donations$"))), + ("getCurrencySpecification", lambda: c.back_to_home()), + ("getExchangeTos", lambda: (open_exchange_list(c), + exchange_menu(c), + c.must_tap(r"(?i)terms of service", timeout=15))), + ("getMaxDepositAmount", lambda: (c.back_to_home(), + c.must_tap(r"(?i)^Deposit$", timeout=20))), + ("listSubscriptions", lambda: (c.back_to_home(), + c.app.scroll_to_text(r"(?i)^Passes$"), + c.must_tap(r"(?i)^Passes$"))), + ] + # The shipped wallet-core may be older than the experiment: a wallet-core + # that does not know "api-error" treats the URI as an unknown experiment + # and the whole sweep would measure nothing. + c.dev.logcat(clear=True) + c.app.handle_uri(api_error_uri("getBalances", count=1)) + time.sleep(3) + log = c.dev.logcat(lines=400) + if "unknown" in log.lower() and "experiment" in log.lower(): + bad = [l for l in log.splitlines() if "experiment" in l.lower()][:2] + c.note("this wallet-core does not support api-error: " + " / ".join(bad)[:240]) + return + c.note("api-error is accepted by this wallet-core") + + for operation, visit in cases: + c.back_to_home() + c.dev.logcat(clear=True) + c.app.handle_uri(api_error_uri(operation)) + time.sleep(2) + # Applying an experiment ends with a back navigation, which closes the + # app when the URI is what started it; without this the next case + # measures the launcher instead of a wallet screen. + for attempt in range(3): + if c.dev.dump().activity.startswith(PKG): + break + c.note(f"{operation}: the app left the foreground; relaunching") + c.dev.launch() + time.sleep(6) + else: + c.note(f"{operation}: could not get the app back; skipping") + continue + try: + c.app.home() + visit() + except (TimeoutError, RuntimeError) as e: + c.note(f"{operation}: could not reach its screen ({str(e)[:120]})") + continue + time.sleep(4) + screen = c.dev.dump() + said = screen.find(r"(?i)error|failed|could not|unavailable|try again|" + r"something went wrong") is not None + c.note(f"{operation}: shows an error: {said}; " + + str(screen.texts()[:12])) + if not said: + c.note(f"WARNING: {operation} failed and the screen says nothing") + c.check() + # Leave no injected errors behind for the next scenario. + c.app.handle_uri("taler+http://dev-experiment/clear-api-errors") + c.ep.check_database() + + +@scenario("contacts_add_and_forget", setup="funded", + about="add a contact by hand, then delete it") +def s_contacts_add(c: Ctx) -> None: + """`addContact` and `deleteContact` have never run. + + The contact list's own dialog is the only way to them that does not go + through the directory service, and its OK button stays disabled until the + petname, the alias and the mailbox are all filled. + """ + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Contacts$") + c.must_tap(r"(?i)^Contacts$", timeout=20) + c.require(r"(?i)Contacts|No contacts yet|Add Contact", timeout=25) + c.check() + if not c.tap(r"(?i)^Add Contact$", timeout=20): + c.note("no way to add a contact") + return + screen = c.require(r"(?i)Petname|Alias|Mailbox", timeout=20) + c.note("add-contact dialog: " + str(screen.texts()[:12])) + fields = screen.editable() + c.note(f"{len(fields)} fields in the dialog") + if len(fields) < 3: + c.note("the dialog does not have the fields it is supposed to") + return + c.fill("Simulator Friend", 0) + c.fill("friend@example.com", 1) + c.fill("http://localhost:8081/mailbox/ABCD1234", len(fields) - 1) + time.sleep(1) + added = c.tap_button(r"(?i)^OK$|^Add$", timeout=15) + time.sleep(3) + listed = c.dev.dump() + c.note(f"after adding (OK tappable: {added}): " + str(listed.texts()[:12])) + if listed.find(r"(?i)Simulator Friend|friend@example.com") is None: + c.note("WARNING: the contact does not appear in the list") + c.check() + # And away again: long-press or a menu, whichever the list offers. + row = listed.find(r"(?i)Simulator Friend") + if row is not None: + c.dev.long_press(row) + time.sleep(2) + c.note("after a long press: " + str(c.dev.dump().texts()[:12])) + c.tap(r"(?i)^Delete$|^Forget$|^Remove$", timeout=8) + time.sleep(2) + c.tap(r"(?i)^OK$|^Yes$|^Delete$", timeout=8) + time.sleep(2) + c.note("after deleting: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + + +def api_response_uri(operation: str, response: dict, count: int = 5) -> str: + """A canned reply for a wallet-core operation, base64url JSON.""" + import base64 + blob = base64.urlsafe_b64encode( + json.dumps(response).encode()).decode().rstrip("=") + return (f"taler+http://dev-experiment/api-response?operation={operation}" + f"&response={blob}&count={count}") + + +def _balance(currency: str, url: str, available: str) -> dict: + return { + "scopeInfo": {"type": "exchange", "currency": currency, "url": url}, + "available": available, + "pendingIncoming": f"{currency}:0", + "pendingOutgoing": f"{currency}:0", + "disablePeerPayments": False, + } + + +@scenario("api_response_hostile", setup="funded", + about="feed the balance screen replies it would never see in a test", + expects=("error-screen", "internal-error-screen", "internal-error-code", + "core-internal", "glued-currency", "blank-screen", + "mixed-amount-notation")) +def s_api_response_hostile(c: Ctx) -> None: + """Well-formed replies with hostile *values*. + + An amount larger than the wallet's own maximum, a currency name longer + than any symbol, and a dozen scopes at once are all things a real + deployment can produce, and none of them can be produced by this stack. + """ + cases = { + "huge amount": {"balances": [ + _balance("EUR", LOCAL_EXCHANGE, "EUR:999999999999.99")]}, + "long currency name": {"balances": [ + _balance("VERYLONGCURRENCY", LOCAL_EXCHANGE, "VERYLONGCURRENCY:1.00")]}, + "twelve scopes": {"balances": [ + _balance("EUR", f"http://localhost:80{80 + i}/", f"EUR:{i + 1}.00") + for i in range(12)]}, + "zero everywhere": {"balances": [ + _balance("EUR", LOCAL_EXCHANGE, "EUR:0")]}, + } + for name, response in cases.items(): + c.back_to_home() + c.dev.logcat(clear=True) + # The queue is FIFO and holds `count` copies, so leftovers from the + # previous case would be what the next one measures. + c.app.handle_uri("taler+http://dev-experiment/clear-api-responses") + time.sleep(1.5) + if not c.dev.dump().activity.startswith(PKG): + c.dev.launch() + time.sleep(5) + c.app.handle_uri(api_response_uri("getBalances", response, count=2)) + time.sleep(2) + if not c.dev.dump().activity.startswith(PKG): + c.dev.launch() + time.sleep(5) + # The main screen asks for balances whenever it is shown. + c.back_to_home() + time.sleep(4) + screen = c.dev.dump() + c.note(f"{name}: " + str(screen.texts()[:16])) + c.check() + # More than one scope gives the pager a list page as well, which is + # the only thing that renders BalancesListComposable. + if name == "twelve scopes": + w, h = c.dev.size() + for _ in range(3): + c.dev.shell(f"input swipe {int(w * 0.85)} {int(h * 0.45)} " + f"{int(w * 0.15)} {int(h * 0.45)} 400") + time.sleep(1.5) + c.note("after paging: " + str(c.dev.dump().texts()[:16])) + c.check() + c.app.handle_uri("taler+http://dev-experiment/clear-api-responses") + c.ep.check_database() + + +@scenario("error_screen_without_dev_mode", setup="funded", + about="what a release build shows for an error with no hint", + expects=("error-screen", "internal-error-code", "core-internal", + "blank-screen")) +def s_error_screen_release(c: Ctx) -> None: + """The error screen the campaign never sees. + + Everything here runs in developer mode, because `taler+http://` needs it, + and the error screen shows the raw JSON in that mode. Without it the whole + explanation is `TalerErrorInfo.userFacingMsg`, which is the hint and the + message concatenated -- and nothing at all when the reply carries neither. + """ + # Queue the failure first: the URI needs developer mode to be delivered. + # An error with neither hint nor message is what makes the release screen + # empty, so api_error_uri is asked for one without a hint. + c.back_to_home() + c.app.handle_uri(api_error_uri("getBalances", hint="", count=20)) + time.sleep(2) + if not c.dev.dump().activity.startswith(PKG): + c.dev.launch() + time.sleep(5) + with_dev = c.dev.dump() + c.note("with developer mode: " + str(with_dev.texts()[:10])) + c.check() + + # Now turn developer mode off, which is what a release build is. + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Developer mode$") + screen = c.dev.dump() + row = screen.find(r"(?i)^Developer mode$") + if row is None: + c.note("no developer mode row") + return + _, y = row.center + width = max(n.bounds[2] for n in screen.nodes) + c.dev.tap(width - 100, y) + time.sleep(2) + c.note(f"developer mode now on: {c.app.dev_mode_on()}") + c.back_to_home() + time.sleep(4) + without_dev = c.dev.dump() + c.note("without developer mode: " + str(without_dev.texts()[:12])) + # "Error" and an export affordance, and nothing that says what happened. + explained = [t for t in without_dev.texts() + if t.strip() not in ("Error", "Copy", "Share", "Settings", + "Internal event log", "Scan QR code", + "Wallet") + and "Export error" not in t] + c.note(f"anything explaining the error: {explained[:6]}") + if not explained: + c.note("WARNING: the error screen explains nothing without developer mode") + c.check() + # taler+http:// is refused while developer mode is off, so the clearing URI + # needs it back first. + c.app.enable_dev_mode() + c.app.handle_uri("taler+http://dev-experiment/clear-api-errors") + c.ep.check_database() + + +@scenario("denom_loss_transaction", setup="funded", + about="a loss-of-funds transaction and its detail screen", + expects=("error-screen",)) +def s_denom_loss(c: Ctx) -> None: + """`TransactionDenomLoss` has never been rendered. + + It appears when an exchange's denomination expires or is revoked while the + wallet still holds coins of it -- which no stack can produce on demand, but + wallet-core will insert one on request. + """ + import dbprobe + c.back_to_home() + c.dev.logcat(clear=True) + c.app.handle_uri("taler+http://dev-experiment/insert-denom-loss") + time.sleep(3) + for _ in range(3): + if c.dev.dump().activity.startswith(PKG): + break + c.dev.launch() + time.sleep(6) + # Did wallet-core accept the experiment at all? The shipped qtart may be + # older than it. + log = c.dev.logcat(lines=400) + complaints = [l for l in log.splitlines() + if "experiment" in l.lower() and ("error" in l.lower() + or "unknown" in l.lower())] + c.note("wallet-core on the experiment: " + (" / ".join(complaints[-2:])[:240] + or "no complaint")) + db = dbprobe.pull(c.dev) + rows: list = [] + try: + rows = dbprobe.rows(db, "select * from denom_loss_events", limit=5) + c.note(f"denom_loss_events rows: {len(rows)}") + for r in rows: + c.note(" " + str({k: str(v)[:40] for k, v in dict(r).items()})[:240]) + except Exception as e: # noqa: BLE001 + c.note(f"could not read denom_loss_events: {str(e)[:120]}") + c.app.home() + time.sleep(3) + c.note("home after the loss event: " + str(c.dev.dump().texts()[:14])) + c.check() + screen = open_transactions(c) + c.note("recent transactions: " + str(screen.texts()[:18])) + loss = screen.find(r"(?i)Loss of funds") + if loss is None: + # The main screen's list belongs to the selected scope, and the event + # is in a currency of its own; "All" is the unscoped list. + if c.tap(r"(?i)^All$", timeout=10): + time.sleep(3) + screen = c.dev.dump() + c.note("all transactions: " + str(screen.texts()[:18])) + loss = screen.find(r"(?i)Loss of funds") + if loss is None: + # Not a defect, and worth saying so rather than leaving a WARNING that + # reads like one: the dev experiment inserts the event for TESTKUDOS + # (the row's own `currency` column says so), and a wallet holding only + # EUR has no TESTKUDOS scope for it to appear under. Rendering + # TransactionDenomLoss would need a loss in a currency the wallet + # actually holds, which means a denomination expiring under it -- + # not something this stack can arrange. + currencies = {dict(row).get("currency") for row in rows} + c.note(f"the loss event does not appear in any list, as expected: it is " + f"in {currencies or '(unknown)'} and this wallet holds EUR") + c.check() + return + c.dev.tap_node(loss, screen) + time.sleep(3) + detail = c.dev.dump() + c.note("loss detail: " + str(detail.texts()[:16])) + if detail.find(r"(?i)Amount lost|Reason|expired|revoked") is None: + c.note("WARNING: the loss detail screen shows none of its own labels") + c.check() + c.ep.check_database() + + +@scenario("exchange_turns_hostile", setup="funded", + about="the exchange's protocol version and master key change under the wallet", + expects=("error-screen", "internal-error-code", "core-internal", + "background-error", "stuck-operation", "blank-screen")) +def s_exchange_turns_hostile(c: Ctx) -> None: + """Two events a wallet must survive and explain. + + An exchange that answers with a protocol version this wallet cannot speak + is unusable; an exchange whose master public key has changed is either + compromised or has been replaced, and the wallet holds coins signed by the + old one. Neither can be produced by configuration -- wallet-core will + pretend, per exchange base URL, on request. + """ + url = LOCAL_EXCHANGE + quoted = url.replace(":", "%3A").replace("/", "%2F") + cases = [ + ("protocol version 999", + f"taler+http://dev-experiment/start-fakeprotover" + f"?base_url={quoted}&fake_ver=999%3A0%3A0&fup=1"), + ("a different master key", + f"taler+http://dev-experiment/start-fakemasterpub" + f"?base_url={quoted}" + f"&fake_pub=0000000000000000000000000000000000000000000000000000&fup=1"), + ] + for name, uri in cases: + c.back_to_home() + c.dev.logcat(clear=True) + c.app.handle_uri(uri) + time.sleep(4) + for _ in range(3): + if c.dev.dump().activity.startswith(PKG): + break + c.dev.launch() + time.sleep(6) + c.app.home() + time.sleep(4) + c.note(f"{name}: home shows " + str(c.dev.dump().texts()[:14])) + c.check() + # The payment services screen is where the wallet would say so. + open_exchange_list(c) + time.sleep(3) + listed = c.dev.dump() + c.note(f"{name}: payment services show " + str(listed.texts()[:16])) + if listed.find(r"(?i)error|not supported|incompatible|too old|too new|" + r"changed|unavailable") is None: + c.note(f"WARNING: nothing on the exchange list mentions {name}") + c.check() + # And a withdrawal, which is what the user would try next. + c.back_to_home() + if c.tap(r"(?i)^Withdraw$", timeout=20): + time.sleep(5) + prompt = c.dev.dump() + c.note(f"{name}: the withdraw screen shows " + str(prompt.texts()[:14])) + c.check() + log = c.dev.logcat(lines=500) + codes = sorted({m for m in re.findall(r'"code":\s*(\d{4})', log)}) + c.note(f"{name}: error codes in the log: {codes[:8]}") + + # And the case that puts an error *on a transaction*: a withdrawal that is + # already pending when the exchange becomes unusable. Nothing else in the + # suite has ever rendered `ErrorTransactionButton`. + c.app.fresh_start(dev_mode=True) + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + if not c.tap(r"(?i)confirm withdrawal", timeout=40): + c.note("could not start a withdrawal to break") + return + c.see(r"(?i)Waiting for authorization|Authorize in bank|transaction is pending", + timeout=60) + c.app.handle_uri( + f"taler+http://dev-experiment/start-fakemasterpub?base_url={quoted}" + f"&fake_pub=0000000000000000000000000000000000000000000000000000&fup=1") + time.sleep(3) + for _ in range(3): + if c.dev.dump().activity.startswith(PKG): + break + c.dev.launch() + time.sleep(6) + # Push the withdrawal along, so its next step fails. + c.bank.confirm_withdrawal(*flows.WALLET_USER, op["withdrawal_id"]) + for _ in range(8): + time.sleep(5) + screen = c.dev.dump() + if screen.find(r"(?i)has failed|error|Show error") is not None: + break + c.note("the pending withdrawal now: " + str(c.dev.dump().texts()[:16])) + c.check() + open_transactions(c) + rows = transaction_rows(c.dev.dump()) + if rows: + c.dev.tap_node(rows[0]) + time.sleep(3) + detail = c.dev.dump() + c.note("its detail screen: " + str(detail.texts()[:16])) + if c.tap(r"(?i)Show error|^Error$", timeout=8): + time.sleep(2) + c.note("error block: " + str(c.dev.dump().texts()[:14])) + c.check() + c.ep.check_database() + + +@scenario("peer_push_abandon", setup="funded", + about="look for Abandon on an outgoing peer payment and on a deposit") +def s_peer_push_abandon(c: Ctx) -> None: + """Where `failTransaction` can be reached from, if anywhere. + + wallet-core puts `TransactionAction.Fail` in the action list for deposits + and for outgoing peer payments, so the withdrawal scenarios could never + reach it -- but an outgoing peer payment turns out to offer Retry, Abort + and Suspend while it is live, and Resume and Abort once suspended, with no + Abandon in sight. This scenario records both, and then tries a deposit. + """ + c.back_to_home() + before = c.app.balances() + c.note(f"balance before: {before}") + c.must_tap(r"(?i)^Send$", timeout=30) + c.require(r"(?i)Send money|Amount to send|Purpose", timeout=30) + c.set_amount("€5.00", "500") + c.must_tap(r"(?i)^Send ", timeout=30) + c.see(r"(?i)Scan this QR code to receive|copy and send this URI", timeout=60) + c.check() + # Nobody accepts it; the wallet's own way out is Abandon. wallet-core + # offers it on an outgoing peer payment only once the transaction is + # suspended -- while it is live the choices are Suspend and Abort. + # The QR code is the top of the screen; the actions are below it. + try: + c.app.scroll_to_text(r"(?i)^Suspend$|^Abandon$|^Abort$", max_scrolls=5) + except TimeoutError: + c.note("no actions on the outgoing payment: " + + str(c.dev.dump().texts()[:16])) + return + c.note("live actions: " + str(c.dev.dump().texts()[:18])) + if not c.tap(r"(?i)^Abandon$", timeout=10): + if not c.tap(r"(?i)^Suspend$", timeout=15): + c.note("neither Abandon nor Suspend is offered") + return + time.sleep(4) + try: + c.app.scroll_to_text(r"(?i)^Abandon$|^Resume$", max_scrolls=5) + except TimeoutError: + pass + c.note("after suspending: " + str(c.dev.dump().texts()[:18])) + c.check() + if not c.tap(r"(?i)^Abandon$", timeout=15): + c.note("Abandon is not offered even once suspended: " + + str(c.dev.dump().texts()[:18])) + # A deposit is the other place wallet-core offers it. + c.back_to_home() + if not c.tap(r"(?i)^Deposit$", timeout=20): + return + screen = c.require(r"(?i)Deposit|bank account|Amount", timeout=25) + account = screen.find(r"(?i)^wallet\d+$") or screen.find(r"(?i)x-taler-bank") + if account is not None: + c.dev.tap_node(account, screen) + time.sleep(3) + if not c.set_amount("€1.00", "100"): + c.note("could not set a deposit amount") + return + if not c.tap(r"(?i)^Make deposit$|^Deposit$", timeout=20): + c.note("could not make the deposit") + return + time.sleep(4) + try: + c.app.scroll_to_text(r"(?i)^Abandon$|^Suspend$|^Abort$", + max_scrolls=5) + except TimeoutError: + pass + c.note("a deposit's actions: " + str(c.dev.dump().texts()[:18])) + if not c.tap(r"(?i)^Abandon$", timeout=10): + # wallet-core offers Fail on a deposit that is *aborting* + # (deposits.ts: Aborting, SuspendedAborting, + # PendingAggregateKyc, …), so aborting one is the way in -- if + # the aggregator has not already finalised it. + if c.tap(r"(?i)^Abort$", timeout=10): + time.sleep(4) + c.note("after aborting the deposit: " + + str(c.dev.dump().texts()[:18])) + c.check() + if c.tap(r"(?i)^Abandon$", timeout=10): + time.sleep(4) + c.note("abandoned the deposit: " + str(c.dev.dump().texts()[:14])) + c.check() + else: + c.note("Abandon is offered in none of the deposit states this " + "stack produces") + return + if c.see(r"(?i)Abandon transaction|Are you sure", timeout=10): + c.tap(r"(?i)^Abandon$|^OK$|^Yes$") + time.sleep(5) + after_screen = c.dev.dump() + c.note("after abandoning: " + str(after_screen.texts()[:14])) + c.check() + # The coins are refreshed back into the balance; that takes a moment. + for _ in range(10): + time.sleep(4) + c.back_to_home() + now = c.app.balances() + if now and now != before: + break + c.note(f"balance after: {c.app.balances()} (was {before})") + c.check() + c.ep.check_database() + + +@scenario("history_after_forgetting_exchange", setup="funded", + about="forget the payment service and look for the transactions again") +def s_history_after_forget(c: Ctx) -> None: + """Every transaction list is scope-filtered. + + `TransactionManager.getTransactions` always passes a `scopeInfo`, and the + scopes come from the balances, so a currency with no balance scope has no + list to appear in. Forgetting the only payment service is the ordinary way + to reach that state. + """ + c.back_to_home() + before = transaction_rows(open_transactions(c)) + c.note(f"transactions before: {[n.label[:24] for n in before]}") + c.check() + open_exchange_list(c) + if not exchange_menu(c): + c.note("no exchange menu") + return + c.note("menu: " + str(c.dev.dump().texts()[:14])) + if not c.tap(r"(?i)^Delete payment service$|^Forget payment service$|" + r"^Forget$|^Delete$", timeout=15): + c.note("no way to forget the payment service") + return + time.sleep(2) + dialog = c.dev.dump() + c.note("the delete dialog: " + str(dialog.texts()[:10])) + # The wallet holds coins on this exchange, so a plain delete is refused; + # the dialog's own checkbox is what forces it. + if dialog.find(r"(?i)Force deletion") is not None: + c.tap(r"(?i)Force deletion") + time.sleep(1) + c.tap_button(r"(?i)^Delete$|^Forget$|^OK$|^Yes$", timeout=10) + time.sleep(6) + c.note("after forgetting: " + str(c.dev.dump().texts()[:14])) + c.check() + c.back_to_home() + time.sleep(3) + home = c.dev.dump() + c.note("home afterwards: " + str(home.texts()[:16])) + after = transaction_rows(c.dev.dump()) + c.note(f"transactions after: {[n.label[:24] for n in after]}") + if before and not after: + c.note("WARNING: forgetting the payment service took the history with " + "it; the record of what was done with the money is gone") + c.check() + c.ep.check_database() + + +def _fake_withdrawal(txid: str, major: str, minor: str | None, + actions: list[str], error: dict | None = None) -> dict: + """A withdrawal transaction as wallet-core would report it.""" + tx: dict = { + "type": "withdrawal", + "transactionId": f"txn:withdrawal:{txid}", + "timestamp": {"t_s": int(time.time())}, + "txState": {"major": major, **({"minor": minor} if minor else {})}, + "txActions": actions, + "amountRaw": "EUR:10", + "amountEffective": "EUR:9.87", + "scopes": [{"type": "exchange", "currency": "EUR", + "url": LOCAL_EXCHANGE}], + "exchangeBaseUrl": LOCAL_EXCHANGE, + "withdrawalDetails": {"type": "manual-transfer", + "reserveClosingDelay": {"d_us": 3600000000}}, + } + if error is not None: + tx["error"] = error + return tx + + +@scenario("nfc_tap_to_pay", setup="funded", + about="a payment arriving over NFC, as a tapped tag delivers it", + expects=("error-screen", "background-error", "stuck-operation")) +def s_nfc_tap_to_pay(c: Ctx) -> None: + """The tap-to-pay entry point, which nothing had ever used. + + `MainActivity` has three external entry points -- a VIEW intent, shared + text, and `NfcAdapter.ACTION_NDEF_DISCOVERED` -- and only the first two had + ever been driven, although the sim build ships a `SEND_NDEF` hook built for + exactly this (the URI travels in a Parcelable `NdefMessage`, which `am + start` cannot construct). The handler's own comment calls the NDEF-record + path a fallback for when the system leaves `intent.data` unset, and that is + the branch the hook exercises. + """ + order = c.merchant.create_order("EUR:1", summary="Tapped order") + c.dev.send_ndef(order["pay_uri"]) + screen = c.see(r"(?i)^Pay\b|Review order|Total:|Purchase", timeout=60) + if screen is None: + c.note("an NDEF tap did not open the payment prompt: " + + str(c.dev.dump().texts()[:14])) + c.check() + return + c.note("the tapped payment prompt: " + str(screen.texts()[:14])) + c.check() + c.tap_button(r"(?i)^Pay\b|confirm payment", timeout=30) + deadline = time.monotonic() + 90 + paid = False + while time.monotonic() < deadline: + if c.merchant.order_status(order["order_id"], + order["token"]).get("order_status") == "paid": + paid = True + break + time.sleep(2) + c.note(f"the tapped order was paid: {paid}") + if not paid: + raise RuntimeError("a payment delivered over NFC was never paid") + c.check() + + # And the hostile taps: a tag carrying something that is not a Taler URI at + # all, and one carrying a Taler URI for an order that does not exist. + for label, uri in ( + ("a plain website", "https://example.org/not-taler"), + ("a nonsense scheme", "taler+http://pay/"), + ("an order that does not exist", + f"taler+http://pay/{corpus.EXCHANGE}/{corpus.FAKE_ID}/"), + ): + c.back_to_home() + c.dev.send_ndef(uri) + time.sleep(4) + c.note(f"tapped {label}: " + str(c.dev.dump().texts()[:10])) + c.check() + c.ep.check_database() + + +@scenario("transaction_details_by_type", setup="funded", + about="open the detail screen of every transaction type the stack " + "can produce", + expects=("error-screen", "unfinished-transaction", + "mixed-amount-notation", "glued-currency")) +def s_transaction_details_by_type(c: Ctx) -> None: + """One detail screen per transaction kind. + + `TransactionDetailScreen` branches on the transaction's type -- withdrawal, + payment, refund, deposit, peer push/pull debit/credit, denomination loss -- + and each branch has its own composable. Scenarios create those + transactions all the time but almost never open them, which is why the + detail screen sits at 56 % and several per-type composables at 0 %. + + Each counterparty step is allowed to fail on its own: what matters is that + whatever did end up in the list gets opened. + """ + made: list[str] = [] + steps = ( + ("payment", lambda: flows.pay(c.app, c.merchant, "EUR:2", + "Detail-screen order")), + ("deposit", lambda: flows.deposit_to_bank(c.app, c.env, "100")), + ("peer push credit", lambda: flows.peer_receive(c.app, c.env, "EUR:1", + c.cli)), + ("peer pull debit", lambda: flows.peer_pay_invoice(c.app, c.env, + "EUR:1", c.cli)), + ) + for name, step in steps: + try: + step() + made.append(name) + except Exception as e: # noqa: BLE001 + c.note(f"could not make a {name}: {str(e)[:140]}") + c.back_to_home() + c.note(f"transaction types created: {made}") + c.check() + + # Now the point of the scenario: open every row there is. The list lives + # on the main screen under "Recent transactions", which is what + # transaction_rows understands; tapping the "All" chip navigates to the + # dedicated screen instead, where that header does not exist and every row + # went missing. + screen = open_transactions(c) + rows = transaction_rows(screen) + c.note(f"{len(rows)} transactions listed: " + + str([n.label[:26] for n in rows])) + opened = 0 + for index in range(len(rows)): + # Re-read the list each time: going back recomposes it, and holding a + # node from an older dump taps whatever is at those coordinates now. + listing = open_transactions(c) + rows_now = transaction_rows(listing) + if index >= len(rows_now): + break + c.dev.tap_node(rows_now[index], listing) + time.sleep(2.5) + detail = c.dev.dump() + title = next((t for t in detail.texts() + if re.search(r"(?i)transaction (is|was)|Received|Sent", t)), + None) + c.note(f"detail {index}: {title!r} | " + + str([x for x in detail.texts()[:10]])) + c.check() + # The JSON dump and the error button are both developer-mode only and + # both on this screen. + if c.tap(r"(?i)^Show JSON$", timeout=6): + time.sleep(1.5) + c.check() + c.dev.back() + time.sleep(1) + if c.tap(r"(?i)^Error$", timeout=5): + time.sleep(1.5) + c.note(f"detail {index} carries an error: " + + str(c.dev.dump().texts()[:8])) + c.check() + c.tap(r"(?i)^OK$|^Close$|^Cancel$", timeout=5) + # The overflow menu exists only for a transaction with a payto target + # -- a deposit or a manual withdrawal -- and holds one item, which is + # the only caller of copyToClipBoard on this screen. + if c.tap(r"(?i)^Menu$", timeout=4): + time.sleep(1) + menu = c.dev.dump() + c.note(f"detail {index} overflow menu: " + str(menu.texts()[:8])) + if c.tap(r"(?i)^Copy payto URI$", timeout=5): + time.sleep(1) + c.note(f"detail {index}: copied the payto URI") + else: + c.dev.back() + c.check() + opened += 1 + c.dev.back() + time.sleep(1.5) + c.note(f"opened {opened} detail screens") + c.check() + c.ep.check_database() + + +@scenario("transaction_states_rendered", setup="funded", + about="transaction states this stack cannot produce", + expects=("error-screen", "internal-error-screen", "internal-error-code", + "core-internal", "blank-screen", "fee-on-dead-transaction")) +def s_transaction_states(c: Ctx) -> None: + """Every state the list has a branch for. + + `TransactionsComposable` renders differently for pending, aborting, + suspended, failed and unknown states, and for a transaction that carries + its own error; a stack produces two or three of those on a good day. A + canned `getTransactionsV2` reply produces all of them, including a state + from the future -- the app keeps the unrecognised name on purpose, so what + it does with it is worth seeing. + """ + transactions = [ + _fake_withdrawal("AAAA1", "pending", "kyc", ["suspend", "abort"]), + _fake_withdrawal("AAAA2", "aborting", "bank", ["fail"]), + _fake_withdrawal("AAAA3", "suspended", "exchange-wait-reserve", + ["resume", "fail"]), + _fake_withdrawal("AAAA4", "failed", None, ["delete"], + error={"code": 7003, + "hint": "the exchange could not be reached"}), + _fake_withdrawal("AAAA5", "done", None, ["delete"]), + # A state this version of the app has never heard of. + _fake_withdrawal("AAAA6", "transmogrified", "inside-out", ["delete"]), + # And two the app cannot *parse* at all, which is the only way to reach + # TransactionSerializer's catch branch and the DummyTransaction it + # falls back to: a type that does not exist, and a known type missing + # a field it needs. + { + "type": "interpretive-dance", + "transactionId": "txn:interpretive-dance:AAAA7", + "timestamp": {"t_s": int(time.time())}, + "txState": {"major": "done"}, + "txActions": ["delete"], + }, + { + "type": "withdrawal", + "transactionId": "txn:withdrawal:AAAA8", + "timestamp": {"t_s": int(time.time())}, + "txState": {"major": "done"}, + "txActions": ["delete"], + # no amountRaw/amountEffective/scopes: required, so this throws + }, + ] + c.back_to_home() + c.app.handle_uri("taler+http://dev-experiment/clear-api-responses") + time.sleep(1.5) + if not c.dev.dump().activity.startswith(PKG): + c.dev.launch() + time.sleep(5) + c.app.handle_uri(api_response_uri("getTransactionsV2", + {"transactions": transactions}, count=8)) + time.sleep(2) + for _ in range(3): + if c.dev.dump().activity.startswith(PKG): + break + c.dev.launch() + time.sleep(6) + c.app.home() + time.sleep(4) + screen = open_transactions(c) + c.note("the list: " + str(screen.texts()[:24])) + c.check() + if c.tap(r"(?i)^All$", timeout=10): + time.sleep(3) + full = c.dev.dump() + c.note("the full list: " + str(full.texts()[:28])) + c.check() + rows = transaction_rows(full) + c.note(f"{len(rows)} rows: {[n.label[:20] for n in rows][:8]}") + # The two unparseable transactions become DummyTransactions, which + # carry an error and no amount; the list should still render, and + # whatever it shows for them is worth reading. + if full.find(r"(?i)interpretive|UNKNOWN|Error") is not None: + c.note("the unparseable transactions show as: " + + str([x for x in full.texts() + if re.search(r"(?i)unknown|error|interpretive", x)][:4])) + else: + c.note("nothing on screen marks the two unparseable transactions") + # The failed one carries an error, which is the only way to render + # ErrorTransactionButton; its detail screen needs its own canned reply. + c.app.handle_uri(api_response_uri( + "getTransactionById", + _fake_withdrawal("AAAA4", "failed", None, ["delete"], + error={"code": 7003, + "hint": "the exchange could not be reached"}), + count=4)) + time.sleep(2) + for _ in range(3): + if c.dev.dump().activity.startswith(PKG): + break + c.dev.launch() + time.sleep(6) + c.app.home() + rows = transaction_rows(open_transactions(c)) + if rows: + c.dev.tap_node(rows[0]) + time.sleep(4) + detail = c.dev.dump() + c.note("a detail screen: " + str(detail.texts()[:20])) + if c.tap(r"(?i)Show error|^Error$", timeout=8): + time.sleep(2) + c.note("the error block: " + str(c.dev.dump().texts()[:16])) + c.check() + c.app.handle_uri("taler+http://dev-experiment/clear-api-responses") + c.ep.check_database() + + +TALDIR_CHALLENGES = "/opt/taldir/challenges.log" + + +def taldir_ready(c: Ctx) -> bool: + """Whether this worker can reach the directory the app hard-codes. + + The app always talks to https://taldir.gnunet.org, so the device has to + answer for that name: emu/tls-names.sh adds the hosts entry and forwards + the device's port 443 to the TLS front end, whose CA the sim build type + trusts. Without that the scenario would only measure the refusal. + """ + if "tcp:443" not in c.dev.adb("reverse", "--list", check=False): + c.note("port 443 is not mapped on this worker; run emu/tls-names.sh") + return False + try: + import socket + import ssl + # The front end's certificate is for the two hostnames and nothing + # else, so the probe has to validate the name the *device* validates + # while connecting to the address the device's port 443 forwards to. + # Asking for https://127.0.0.1:8443 instead fails with "IP address + # mismatch" and says nothing about whether the front end works. + ctx = ssl.create_default_context(cafile="/opt/taler-sim/tls/ca.crt") + with socket.create_connection(("127.0.0.1", 8443), timeout=5) as raw: + with ctx.wrap_socket(raw, server_hostname="taldir.gnunet.org") as tls: + tls.sendall(b"GET /config HTTP/1.1\r\n" + b"Host: taldir.gnunet.org\r\n" + b"Connection: close\r\n\r\n") + head = tls.recv(64) + if b" 200 " not in head: + raise RuntimeError(f"answered {head[:40]!r}") + except Exception as e: # noqa: BLE001 + c.note(f"the TLS front end is not answering: {str(e)[:120]}") + return False + return True + + +def latest_challenge(alias: str) -> Optional[str]: + """The challenge the directory's validator recorded for this alias.""" + try: + with open(TALDIR_CHALLENGES) as f: + lines = [l.strip().split("\t") for l in f if alias in l] + except OSError: + return None + return lines[-1][2] if lines and len(lines[-1]) >= 3 else None + + +@scenario("alias_registration_real", setup="funded", + about="register an alias with a real directory, challenge and all", + expects=("error-screen", "internal-error-code", "core-internal")) +def s_alias_registration_real(c: Ctx) -> None: + """The whole alias registration, against a deployed taldir. + + Everything past the "Register Alias" button has never run: the app's URL + is a literal, so without the device answering for that name there is + nothing behind it. With the directory deployed and the name resolved, the + flow is register -> challenge -> complete -> look up, and the challenge + comes from the validator's log the way it would come from an email. + """ + if not taldir_ready(c): + return + alias = f"sim-w{WORKER}-{int(time.time())}@example.com" + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Alias Registration$", max_scrolls=12) + c.must_tap(r"(?i)^Alias Registration$") + screen = c.require(r"(?i)Alias|Duration|Register", timeout=25) + c.note("the form: " + str(screen.texts()[:12])) + c.check() + # Field 0 is the alias *type*, a read-only dropdown: tapping it opens the + # menu, typing goes nowhere, the alias stays empty -- which disables the + # register button -- and the open menu covers it. The alias is field 1. + if not c.fill(alias, 1, clear=True): + c.note("no alias field") + return + time.sleep(1) + if not c.tap_button(r"(?i)^Register Alias$", timeout=15): + c.note("the register button would not tap; the form reads " + + str(c.dev.dump().texts()[:12])) + return + # The directory has to answer, and the validator has to run, before the + # challenge exists. + challenge = None + for _ in range(12): + time.sleep(3) + challenge = latest_challenge(alias) + if challenge: + break + after = c.dev.dump() + c.note(f"after registering (challenge: {challenge}): " + str(after.texts()[:14])) + c.check() + if challenge is None: + c.note("WARNING: the directory recorded no challenge for this alias") + return + # The screen should now be asking for it, in a field labelled "Challenge + # Solution", with an OK button under it. + waiting = c.dev.dump() + if waiting.find(r"(?i)Challenge Solution") is None: + c.note("the screen is not asking for the challenge: " + + str(waiting.texts()[:16])) + return + fields = [n for n in waiting.editable()] + if not fields: + c.note("no field to type the challenge into") + return + # The alias and duration fields are still above it; the solution field is + # the last one. + if not c.fill(challenge, len(fields) - 1, clear=True): + c.note("could not type the challenge") + return + time.sleep(1) + c.tap_button(r"(?i)^OK$", timeout=15) + time.sleep(6) + done = c.dev.dump() + c.note("after completing: " + str(done.texts()[:16])) + c.check() + # And the other half: look the alias up from the contacts screen. + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Contacts$", max_scrolls=12) + c.must_tap(r"(?i)^Contacts$") + if c.tap(r"(?i)^Add Contact$", timeout=20): + screen = c.require(r"(?i)Petname|Alias|Mailbox", timeout=20) + c.fill("Looked up", 0) + c.fill(alias, 1) + time.sleep(1) + if c.tap_button(r"(?i)Lookup with Taldir", timeout=15): + time.sleep(8) + c.note("after the lookup: " + str(c.dev.dump().texts()[:16])) + c.check() + c.ep.check_database() + + +@scenario("db_corruption", setup="funded", + about="scribble on the wallet database and restart the app", + # A corrupt database is supposed to fail to open; what is being + # checked is that the app explains it instead of crashing. + expects=("internal-error-screen", "core-internal", "internal-error-code")) +def s_db_corruption(c: Ctx) -> None: + """A corrupt database must produce an explained failure, not a crash. + + `WalletInitErrorScreen` exists for exactly this and has never been reached + by any other scenario. + """ + from device import PKG + before = c.dev.shell(f"run-as {PKG} ls -l files/talerwalletdb.sqlite3", check=False) + c.note(f"database before: {before.strip()[:120]}") + c.dev.stop() + time.sleep(2) + # Overwrite the SQLite header in place; the file keeps its size, so this is + # corruption rather than truncation. + cmd = ("dd if=/dev/urandom of=files/talerwalletdb.sqlite3 " + "bs=512 count=2 conv=notrunc") + out = c.dev.shell(f"run-as {PKG} {cmd}", check=False) + c.note(f"corrupting: {out.strip()[:160]}") + c.dev.launch() + time.sleep(8) + screen = c.dev.dump() + c.note("after relaunch: " + str(screen.texts()[:14])) + c.check() + log = c.dev.logcat() + crashed = "FATAL EXCEPTION" in log + c.note(f"crashed: {crashed}") + if crashed: + c.ep.session.add([oracles.Finding( + "crash", "the app crashed after its database was corrupted", + "\n".join(l for l in log.splitlines() if "FATAL" in l)[:1000])]) + # Whatever it shows, the wallet has to be usable again afterwards. + c.app.fresh_start(dev_mode=True) + c.note("after a wipe: " + str(c.dev.dump().texts()[:8])) + c.check() + + +@scenario("db_migration_prompt", setup="fresh", + about="plant a wallet database in the old format and migrate it") +def s_db_migration_prompt(c: Ctx) -> None: + """The database migration, which needs a database in the legacy format. + + wallet-core picks its backend from what the file already holds + (`host-impl.qtart.ts`: `inspectWalletDbFile`), so a file carrying + IndexedDB-emulation records is opened with the bridge and `init` reports + `IndexedDB`. That is the only way to reach the "Upgrade wallet database" + row in the settings, `MainActivity`'s migration prompt and progress + dialog, `migrateDatabase`, and -- if the migration can be caught while it + runs -- `cancelProgressToken`, the last wallet-core operation no scenario + had exercised. + + The fixture in `corpus/legacy-indexeddb-wallet.db` has to come from the + *app's own* wallet-core, because IndexedDB refuses to open a database + newer than the schema version the opener asks for. `taler-wallet-cli` + with `TALER_WALLET_DB_BACKEND=indexeddb` does write a legacy database, but + the checkout beside this one is 1.6.48, whose schema is version 36, while + the qtart the app embeds is 1.6.42 and asks for 34: + + VersionError: requested version 34, existing version is 36 + + So the fixture is made by the app itself: build it with + `useNativeDb = false` in `MainViewModel`, launch it once, and copy + `files/talerwalletdb.sqlite3` back out. That file carries + `taler-wallet-main-v10` at version 34, and has to be remade whenever the + bundled qtart moves its schema version. + """ + from device import PKG + # The committed fixture is deliberately small. A bigger one -- made the + # same way, by driving the useNativeDb=false build through a scenario + # first -- migrates slowly enough that the Cancel below can be caught, and + # is passed in with SIM_LEGACY_DB rather than carried in the repository. + legacy = Path(os.environ.get( + "SIM_LEGACY_DB", + Path(__file__).resolve().parent.parent / "corpus" + / "legacy-indexeddb-wallet.db")) + if not legacy.exists(): + c.note(f"no legacy database at {legacy}; nothing to plant") + return + + c.dev.stop() + time.sleep(2) + c.dev.adb("push", str(legacy), "/data/local/tmp/legacy-wallet.db") + c.dev.shell("chmod 644 /data/local/tmp/legacy-wallet.db", check=False) + # The write-ahead log belongs to the database being replaced. + for leftover in ("talerwalletdb.sqlite3-wal", "talerwalletdb.sqlite3-shm"): + c.dev.shell(f"run-as {PKG} rm -f files/{leftover}", check=False) + # dd rather than a redirection: run-as execs its argument without a shell. + out = c.dev.shell( + f"run-as {PKG} dd if=/data/local/tmp/legacy-wallet.db " + "of=files/talerwalletdb.sqlite3", check=False) + c.note("planting the legacy database: " + out.strip()[:160]) + planted = c.dev.shell(f"run-as {PKG} ls -l files/talerwalletdb.sqlite3", + check=False) + c.note("database now: " + planted.strip()[:120]) + + c.dev.launch() + time.sleep(10) + c.note("after relaunch: " + str(c.dev.dump().texts()[:14])) + c.check() + + # The row only exists when wallet-core reports the IndexedDB backend, so + # finding it is the proof that the planted file was accepted. + c.app.open_settings() + try: + c.app.scroll_to_text(r"(?i)^Upgrade wallet database$", max_scrolls=8) + except TimeoutError: + c.note("no migration row in the settings: wallet-core did not report " + "the IndexedDB backend for the planted database; " + + str(c.dev.dump().texts()[:16])) + c.check() + return + c.must_tap(r"(?i)^Upgrade wallet database$") + prompt = c.see(r"(?i)Upgrade wallet database\?", timeout=15) + if prompt is None: + c.note("the migration prompt did not open: " + + str(c.dev.dump().texts()[:14])) + c.check() + return + c.note("the prompt: " + str(prompt.texts()[:8])) + c.check() + + # "Later" first, so the deferral path is exercised too, then ask again. + if c.tap(r"(?i)^Later$", timeout=8): + time.sleep(2) + c.note("after Later: " + str(c.dev.dump().texts()[:10])) + c.check() + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Upgrade wallet database$", max_scrolls=8) + c.must_tap(r"(?i)^Upgrade wallet database$") + c.require(r"(?i)Upgrade wallet database\?", timeout=15) + + # Where the prompt's buttons are, so the progress dialog's Cancel can be + # tapped without a dump first: a dump costs about a second, which is + # longer than the whole migration on a database this size. + prompt_screen = c.dev.dump() + slots = [n.center for n in prompt_screen.labelled() + if re.match(r"(?i)^(Migrate now|Later)$", n.label.strip())] + # The Cancel on the progress dialog is the only caller of + # cancelProgressToken, and this harness cannot reach it. Four attempts, + # all recorded in CAMPAIGN.md: + # + # * a 57 KB legacy fixture -- migrates in well under a second; + # * a 1.7 MB fixture with 512 records and 112 progress notifications -- + # the same; + # * blind taps at the prompt's button coordinates, with no screen dump + # in between (a dump alone costs about a second); + # * freezing the process with SIGSTOP so the taps queue in the input + # dispatcher, both before and after starting the migration. + # + # The taps below are the third of those, kept because they cost nothing + # and would start working the moment a fixture is large enough. What + # would actually settle it is a legacy database of some thousands of + # records, or a debug hook that pauses the migration. + c.must_tap(r"(?i)^Migrate now$", timeout=15) + for x, y in slots: + c.dev.tap(x, y) + + # No separate dump before each attempt: every dump costs about a second, + # which is most of the window on a small database. + cancelled = False + for _ in range(15): + if c.tap(r"(?i)^Cancel$", timeout=1): + cancelled = True + c.note("cancelled the migration while it was running") + break + if cancelled: + # Cancelling is itself a state with its own dialog, and the operation + # it cancels is the only caller of cancelProgressToken. + if c.see(r"(?i)Cancelling", timeout=6) is not None: + c.note("the cancelling dialog was shown") + c.note(f"caught the migration in progress: {cancelled}") + time.sleep(8) + c.note("after the migration: " + str(c.dev.dump().texts()[:14])) + c.check() + + # Whichever way it went, the wallet has to be usable, and the backend it + # ends on has to be one of the two -- not a half-migrated database. + c.app.open_settings() + row = c.dev.dump().find(r"(?i)^Upgrade wallet database$") + c.note("the migration row is still offered: " + str(row is not None)) + c.back_to_home() + c.check() + c.ep.check_database() + + +@scenario("donau_receipt", setup="funded", + about="pay for a tax receipt, then read the donation statement") +def s_donau_receipt(c: Ctx) -> None: + # The donau output type makes the merchant issue a tax receipt for the + # payment, which is what the statements screen lists. + order = c.merchant.create_v1_order( + [{"amount": "EUR:2", "description": "Donation with a receipt", + "inputs": [], "outputs": [{"type": "tax-receipt"}], + "max_fee": "EUR:0.5"}], + summary="Donation with a tax receipt", + ) + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)Review order|Total:|^Pay|donation|receipt", timeout=60) + c.note("donation prompt: " + str(screen.texts()[:14])) + c.check() + c.tap(r"(?i)^Pay\b|confirm payment", timeout=30) + time.sleep(6) + c.note("after paying: " + str(c.dev.dump().texts()[:12])) + c.back_to_home() + try: + c.app.scroll_to_text(r"(?i)^Donation statements$", max_scrolls=5) + except TimeoutError: + c.note("no donation statements section") + c.check() + return + c.must_tap(r"(?i)^Donation statements$") + # "Donation statements" is also the section header on the main screen, so + # the arrival has to be recognised by something only the statements screen + # has: its per-year list ("Donations 2026") or its own title. + screen = c.see(r"(?i)^Donations \d{4}$|^Donation statement$", timeout=25) + if screen is None: + # Expected, and now explained: the button is wired to + # onBalanceSelected(null) rather than to WalletDestination.DonauStatement, + # which has no caller at all -- see + # findings/donation-statements-button-is-wired-to-nothing.md. + c.note("the donation statements screen did not open (the button is a " + "no-op; donation-statements-button-is-wired-to-nothing.md): " + + str(c.dev.dump().texts()[:14])) + c.check() + return + c.note("statements: " + str(screen.texts()[:14])) + c.check() + rows = [n for n in screen.labelled() + if re.match(r"(?i)^Donations \d{4}$", n.label.strip())] + if rows: + c.dev.tap(*rows[0].center) + time.sleep(2) + detail = c.dev.dump() + c.note("statement detail: " + str(detail.texts()[:14])) + if detail.find(r"(?i)Show this QR code|Tax authority|Legal domain") is None: + c.note("WARNING: the statement detail shows none of its own labels") + c.check() + c.ep.check_database() + + +@scenario("refund_detail", setup="funded", + about="take a refund and open the refund transaction") +def s_refund_detail(c: Ctx) -> None: + order = flows.pay(c.app, c.merchant, "EUR:2", summary="Order to refund fully") + c.app.home() + res = c.merchant.refund(order["order_id"], "EUR:2", reason="simulator full refund") + uri = res.get("taler_refund_uri") + if not uri: + raise RuntimeError(f"merchant returned no refund uri: {res}") + c.app.handle_uri(uri) + time.sleep(5) + c.note("after the refund uri: " + str(c.dev.dump().texts()[:12])) + screen = open_transactions(c) + rows = transaction_rows(screen) + c.note(f"{len(rows)} transactions: {[n.label[:22] for n in rows]}") + for index in range(min(3, len(rows))): + screen = open_transactions(c) + rows_now = transaction_rows(screen) + if index >= len(rows_now): + break + c.dev.tap_node(rows_now[index], screen) + time.sleep(2) + detail = c.dev.dump() + if detail.find(r"(?i)refund"): + c.note("refund detail: " + str(detail.texts()[:12])) + c.check() + c.tap(r"(?i)^Show JSON$", timeout=8) + c.check() + c.dev.back() + c.dev.back() + time.sleep(1) + c.check() + + +@scenario("exchange_shopping", setup="funded", + about="the exchange's \"where to pay\" screen") +def s_exchange_shopping(c: Ctx) -> None: + """The "Where to pay" screen, which needs two exchanges to exist at all. + + The balance card that opens it is hidden while `shoppingUrls` is empty, and + with exactly one URL the button opens that site in a browser instead of the + screen -- so the screen is reachable only when the wallet holds a currency + from **two** exchanges that both advertise one (`SHOPPING_URL` in each + exchange's config). The second exchange has to be in the balance, so this + withdraws from it first. + """ + second = second_exchange_or_skip(c) + if second is not None: + # One URL is not enough: with a single entry the button opens that site + # in a browser. Two take a *balance* at each exchange, so the second + # one has to be picked during a withdrawal rather than merely added. + # Coins at the second exchange, without touching any exchange-picking + # UI: the bank-integrated prompt has no service row (its exchange is + # fixed), and a manual withdrawal would need a real wire transfer. A + # peer payment lands at the *sender's* exchange, so a peer funded at + # the second one gives this wallet a second EUR scope. + try: + # peer_receive knows both shapes of the terms prompt on this + # screen -- "Terms of Service" and "Review terms of service" -- + # which is why this does not drive the accept by hand. + screen = flows.peer_receive(c.app, c.env, "EUR:2", c.cli, + exchange=second) + c.note("after receiving from the second service: " + + str(screen.texts()[:12])) + time.sleep(8) + except Exception as e: # noqa: BLE001 + c.note(f"the second service did not reach the balance: {str(e)[:160]}") + c.check() + # What is left, for whoever picks this up: two services give two + # balance *scopes*, one pager page each, and the card on a page carries + # only that service's URL -- so each card still has one URL and the + # button opens a browser. Merging them with "treat as global" (per the + # exchange menu) should put both on one card; driving that menu from + # here kept landing back on the home screen, and the screen is 62 + # lines, so it was not worth more rounds of guessing. + c.back_to_home() + card = c.dev.dump() + c.note("the balance screen: " + str(card.texts()[:14])) + for label in (r"(?i)Where to pay", r"(?i)^Shopping$"): + if c.tap(label, timeout=10): + screen = c.see(r"(?i)where to pay|website|shopping", timeout=20) + c.note("shopping: " + str(screen.texts()[:12] if screen else None)) + c.check() + return + c.note("the card is there but the screen is not: with one URL the button " + "opens that site in a browser, and reaching ExchangeShoppingScreen " + "needs one scope carrying two") + c.check() + + +@scenario("cancel_in_flight", setup="funded", + about="back out of prompts while they are still loading") +def s_cancel_in_flight(c: Ctx) -> None: + """Leaving a prompt before it has loaded, which is where a half-finished + request would show up as a stuck transaction. + + It does *not* reach `cancelProgressToken`, whatever this docstring used to + claim: that operation has exactly one caller, + `WalletBackendApi.cancelDatabaseMigration`, and the only thing that offers + a database migration is a wallet whose database is still in the IndexedDB + emulation. `MainViewModel` hard-codes `useNativeDb = true`, so a new + install never has one, and `taler-wallet-cli`'s database is native too -- + so nothing in this environment can produce the legacy format, and + `cancelProgressToken`, `migrateDatabase` and the migration UI stay out of + reach without a database written by an older wallet. + """ + order = c.merchant.create_order("EUR:1", summary="Cancelled while loading") + for delay in (0.3, 1.0, 2.0): + c.dev.send_uri(order["pay_uri"]) + time.sleep(delay) + c.dev.back() + time.sleep(1.5) + c.note(f"after backing out {delay}s in: {c.dev.dump().texts()[:8]}") + c.check() + c.back_to_home() + # The same for a withdrawal, which takes longer to prepare. + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + for delay in (0.3, 1.5): + c.dev.send_uri(op["taler_withdraw_uri"]) + time.sleep(delay) + c.dev.back() + time.sleep(1.5) + c.note(f"withdrawal, backed out {delay}s in: {c.dev.dump().texts()[:8]}") + c.check() + c.back_to_home() + # Nothing should be left half-done. + c.ep.check_database() + rows = transaction_rows(open_transactions(c)) + c.note(f"{len(rows)} transactions after cancelling: " + f"{[n.label[:22] for n in rows]}") + c.check() + + +@scenario("alias_registration", setup="funded", + about="the Taldir alias registration form") +def s_alias_registration(c: Ctx) -> None: + """Fill and submit the alias form. + + No Taldir service runs in this stack, so registration is expected to fail; + the point is the screen itself, which nothing else reaches, and that the + failure is reported rather than swallowed. + """ + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Alias Registration$", max_scrolls=12) + c.must_tap(r"(?i)^Alias Registration$") + screen = c.require(r"(?i)Alias|Duration|Register", timeout=25) + c.note("alias screen: " + str(screen.texts()[:14])) + c.check() + # The type picker is a dropdown: choosing from it leaves the menu open, and + # a "Register Alias" tap underneath it does nothing at all, which is how + # this scenario used to report a submission it never made. + for kind, value in ((r"(?i)^email$", "simulator@example.com"), + (r"(?i)^phone$", "+10000000000")): + if c.tap(r"(?i)Alias Type", timeout=8): + c.tap(kind, timeout=8) + time.sleep(1) + c.check() + if not c.fill(value): + c.note(f"no alias field for {value!r}") + break + time.sleep(1) + if not c.tap(r"(?i)^Register Alias$", timeout=12): + c.note("the register button is not tappable") + break + # Registration goes to the hard-coded https://taldir.gnunet.org, which + # is not reachable from here, so what matters is whether the screen + # says so. + time.sleep(8) + after = c.dev.dump() + c.note(f"{value!r} -> {after.texts()[:14]}") + if after.find(r"(?i)error|failed|could not|unreachable|retry") is None: + c.note("WARNING: no sign on screen that the registration failed") + c.check() + c.ep.check_database() + + +@scenario("uri_storm", setup="funded", + about="many URIs in rapid succession, valid and malformed") +def s_uri_storm(c: Ctx) -> None: + """Fire URIs faster than the app can finish handling them. + + Each one starts an asynchronous request; overlapping them is where a + half-initialised screen or a lost cancellation would show up. + """ + order = c.merchant.create_order("EUR:1", summary="Storm order") + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + storm = [ + order["pay_uri"], + op["taler_withdraw_uri"], + corpus.MALFORMED["bad_base32"], + corpus.STRUCTURAL["pay"], + corpus.MALFORMED["huge"], + order["pay_uri"], + corpus.STRUCTURAL["withdraw_exchange"], + corpus.MALFORMED["unknown_action"], + ] + for round_number in range(3): + for uri in storm: + c.dev.send_uri(uri) + time.sleep(0.35) + time.sleep(3) + screen = c.dev.dump() + c.note(f"after burst {round_number + 1}: {screen.texts()[:10]}") + c.check() + c.back_to_home() + # Everything should still work afterwards. + c.app.home() + rows = transaction_rows(open_transactions(c)) + c.note(f"{len(rows)} transactions after the storm") + c.check() + c.ep.check_database() + + +@scenario("long_text_fields", setup="funded", + about="very long input in every text field that will take it") +def s_long_text(c: Ctx) -> None: + blob = "A" * 4000 + places = [ + (r"(?i)^Send$", r"(?i)Send money|Amount to send|Purpose"), + (r"(?i)^Request$", r"(?i)Request money|Amount to receive"), + ] + for entry, marker in places: + c.back_to_home() + if not c.tap(entry, timeout=20): + continue + screen = c.see(marker, timeout=25) + if screen is None: + continue + # The purpose/summary field takes free text; the amount field does not. + fields = screen.editable() + c.note(f"{entry}: {len(fields)} editable fields") + for index in range(len(fields)): + if not c.fill(blob, index): + continue + time.sleep(1.5) + after = c.dev.dump() + c.note(f" field {index} after 4000 chars: {after.texts()[:6]}") + c.check() + c.back_to_home() + c.ep.check_database() + + +@scenario("withdraw_age_restricted", setup="fresh", + about="withdraw coins restricted to an age group") +def s_withdraw_age(c: Ctx) -> None: + """The age picker only appears when the exchange offers age-restricted + denominations, which the simulator's exchange now does.""" + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:10") + c.app.handle_uri(op["taler_withdraw_uri"]) + screen = c.require(r"(?i)Confirm withdrawal|Total amount", timeout=60) + c.note("withdrawal prompt: " + str(screen.texts()[:14])) + if not c.tap(r"(?i)Restrict usage to age|^Unrestricted$", timeout=15): + c.note("no age restriction offered") + return + picker = c.dev.dump() + c.note("age options: " + str(picker.texts()[:14])) + c.check() + chosen = None + for age in (r"(?i)^12$", r"(?i)^13$", r"(?i)^16$", r"(?i)^18$"): + if c.tap(age, timeout=6): + chosen = age + break + c.note(f"chose {chosen}") + c.check() + c.accept_tos() + c.must_tap(r"(?i)Confirm withdrawal", timeout=30) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + deadline = time.time() + 60 + while time.time() < deadline: + if c.bank.withdrawal_status(op["withdrawal_id"])["status"] == "selected": + break + time.sleep(2) + c.bank.confirm_withdrawal(*flows.WALLET_USER, op["withdrawal_id"]) + for _ in range(20): + if c.dev.dump().find(r"(?i)completed successfully"): + break + time.sleep(3) + detail = c.dev.dump() + c.note("after the age-restricted withdrawal: " + str(detail.texts()[:14])) + c.tap(r"(?i)^Show JSON$", timeout=8) + c.check() + c.ep.check_database() + + +def kyc_enabled(c: Ctx) -> bool: + """Whether the stack was started from the KYC variant. + + The exchange says so itself, which is more reliable than guessing from the + config file the stack happens to have been given. + """ + import urllib.request + try: + with urllib.request.urlopen(f"{c.env.exchange}keys", timeout=15) as resp: + keys = json.loads(resp.read().decode()) + except Exception as e: + c.note(f"could not read the exchange's keys: {e}") + return False + if not keys.get("kyc_enabled"): + c.note("this stack has KYC switched off; start it with " + "SIM_CONF=sim-kyc.conf to exercise these paths") + return False + return True + + +@scenario("kyc_withdraw_trips_rule", setup="fresh", + about="withdraw past the KYC threshold and follow what the wallet offers", + expects=("error-screen", "unfinished-transaction", "background-error")) +def s_kyc_withdraw(c: Ctx) -> None: + """The KYC stack trips a rule above EUR:5 within a day. + + What matters here is the wallet's half: that it says identification is + needed, offers a way to start it, and does not leave the transaction + looking finished when it is not. + """ + if not kyc_enabled(c): + return + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:10") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + deadline = time.time() + 60 + while time.time() < deadline: + if c.bank.withdrawal_status(op["withdrawal_id"])["status"] == "selected": + break + time.sleep(2) + c.bank.confirm_withdrawal(*flows.WALLET_USER, op["withdrawal_id"]) + + # Now the exchange should ask for identification rather than paying out. + kyc_screen = None + deadline = time.time() + 120 + while time.time() < deadline: + screen = c.dev.dump() + if screen.find(r"(?i)KYC|identification|verify|Complete"): + kyc_screen = screen + break + if screen.find(r"(?i)completed successfully"): + c.note("the withdrawal completed without any KYC step") + break + time.sleep(4) + if kyc_screen is None: + c.note("no KYC prompt appeared: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + return + c.note("KYC prompt: " + str(kyc_screen.texts()[:14])) + c.check() + # Follow the call to action; it hands off to a browser, so coming back is + # part of the test. + if c.tap(r"(?i)Complete KYC|KYC required|verify|identification", timeout=20): + time.sleep(6) + after = c.dev.dump() + c.note(f"after tapping the KYC action: activity={after.activity} " + f"{after.texts()[:10]}") + c.check() + c.dev.launch() + time.sleep(4) + c.note("back in the wallet: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + + +@scenario("kyc_transaction_actions", setup="fresh", + about="what a KYC-blocked transaction offers in its detail screen", + expects=("error-screen", "unfinished-transaction", "background-error")) +def s_kyc_actions(c: Ctx) -> None: + if not kyc_enabled(c): + return + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:10") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + deadline = time.time() + 60 + while time.time() < deadline: + if c.bank.withdrawal_status(op["withdrawal_id"])["status"] == "selected": + break + time.sleep(2) + c.bank.confirm_withdrawal(*flows.WALLET_USER, op["withdrawal_id"]) + time.sleep(25) + screen = open_transactions(c) + rows = transaction_rows(screen) + c.note(f"{len(rows)} transactions: {[n.label[:24] for n in rows]}") + if rows: + c.dev.tap_node(rows[0], screen) + time.sleep(3) + detail = c.dev.dump() + c.note("KYC-blocked transaction: " + str(detail.texts()[:16])) + c.check() + for action in (r"(?i)^Show JSON$", r"(?i)^Retry$", r"(?i)^Suspend$", + r"(?i)^Resume$"): + if c.tap(action, timeout=8): + c.check() + c.dev.back() + time.sleep(1) + c.ep.check_database() + + +def twister_or_skip(c: Ctx) -> Twister | None: + """The fault injector, or None when the stack was not started with it. + + Only the sim-twister.conf variant puts a proxy in front of the exchange; + on an ordinary stack these scenarios have nothing to break and say so + rather than failing. + """ + env_file = Path("/opt/taler-sim/run/stack/env.json") + try: + if not json.loads(env_file.read_text()).get("twister"): + c.note("the stack is not running twister; nothing to inject") + return None + except (OSError, json.JSONDecodeError): + c.note("no stack env.json; cannot tell whether twister is running") + return None + try: + twister = Twister() + if not twister.alive(): + c.note("twister is configured but not answering") + return None + return twister + except TwisterUnavailable as e: + c.note(f"twister unavailable: {e}") + return None + + +@scenario("twister_withdraw_faults", setup="fresh", + about="damage the exchange's replies during a withdrawal", + expects=("error-screen", "background-error", "stuck-operation", + "unfinished-transaction")) +def s_twister_withdraw(c: Ctx) -> None: + """Each fault is armed, then a withdrawal is attempted. + + What is being checked is the shape of the failure: a refusal the user can + read, or a retry, rather than an internal error, a blank screen or a + transaction that sits there for ever. + """ + twister = twister_or_skip(c) + if twister is None: + return + for name, arm in FAULTS.items(): + c.app.fresh_start(dev_mode=True) + c.dev.logcat(clear=True) + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + # The fault stays armed for the whole withdrawal: one arming would be + # spent on whichever poll happened to come first. + with twister.armed(arm) as a: + c.app.handle_uri(op["taler_withdraw_uri"]) + time.sleep(6) + screen = c.dev.dump() + c.note(f"{name}: {screen.texts()[:10]}") + c.check() + # Try to carry on: the wallet should either recover or explain itself. + c.accept_tos() + c.tap(r"(?i)confirm withdrawal|^Retry$", timeout=15) + time.sleep(6) + c.note(f"{name} after retry: {c.dev.dump().texts()[:10]}") + c.check() + if a.errors: + c.note(f"{name}: arming complained: {a.errors}") + c.note(f"{name}: armed {a.fired} times") + # ... and recover with the fault gone, so a permanent failure is + # distinguishable from one the wallet retries out of. + time.sleep(8) + c.note(f"{name} once the fault stops: {c.dev.dump().texts()[:10]}") + c.check() + c.ep.check_database() + + +@scenario("twister_payment_faults", setup="funded", + about="damage the exchange's replies during a payment", + expects=("error-screen", "background-error", "stuck-operation", + "unfinished-transaction")) +def s_twister_payment(c: Ctx) -> None: + twister = twister_or_skip(c) + if twister is None: + return + # Seven payments of EUR:1, each of which may strand coins on a purchase + # that cannot finish, exhaust the EUR:10 the fixture withdraws: the last + # faults then measure "Insufficient balance" rather than the fault. + flows.withdraw(c.app, c.bank, "EUR:20") + c.back_to_home() + recovered = {} + for name, arm in FAULTS.items(): + order = c.merchant.create_order("EUR:1", summary=f"Order during {name}") + # Only the exchange sits behind the proxy, so the prompt itself comes + # through intact and the fault has to survive until the coins are + # deposited -- which only happens once "Pay" is tapped. + with twister.armed(arm) as a: + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)^Pay\b|Review order|Total", timeout=40) + c.note(f"{name} prompt: {screen.texts()[:10]}") + c.must_tap(r"(?i)^Pay\b", timeout=30) + time.sleep(8) + c.note(f"{name} after paying: {c.dev.dump().texts()[:12]}") + c.check() + status = c.merchant.order_status(order["order_id"], order["token"]) + c.note(f"{name}: merchant says {status.get('order_status')}") + c.note(f"{name}: armed {a.fired} times") + # With the fault gone the payment should either complete or fail for + # good. Retries have a backoff, so this has to wait properly: the + # finding would be a purchase that never resolves either way. + # Five minutes, not ninety seconds: the first fault-injection phase + # reported every payment still "claimed" after 90s, which says nothing + # -- wallet-core retries with a backoff, and a deposit that has not + # been retried yet looks exactly like one that never will. Long + # enough to tell those apart, and the elapsed time is recorded so a + # slow recovery can be told from none. + started = time.time() + deadline = started + 300 + final = None + while time.time() < deadline: + final = c.merchant.order_status(order["order_id"], + order["token"]).get("order_status") + if final == "paid": + break + time.sleep(10) + recovered[name] = final + c.note(f"{name}: {int(time.time() - started)}s after the fault " + f"stopped the merchant says {final}; screen " + f"{c.dev.dump().texts()[:10]}") + c.check() + c.back_to_home() + c.note("recovery per fault: " + str(recovered)) + stuck = [k for k, v in recovered.items() if v != "paid"] + if stuck: + c.note(f"WARNING: these payments never completed: {stuck}") + c.ep.check_database() + + +@scenario("twister_field_faults", setup="fresh", + about="delete and rewrite fields of the exchange's replies", + expects=("error-screen", "background-error", "stuck-operation", + "unfinished-transaction")) +def s_twister_fields(c: Ctx) -> None: + """Structural damage rather than transport damage: a reply that parses but + is missing a field, or carries a wrong one.""" + twister = twister_or_skip(c) + if twister is None: + return + # Twister walks dot paths and takes a numeric token as an array index, so + # a nested field can be named exactly: "denoms" alone is not a key of + # /keys and silently matched nothing. + cases = [ + ("delete-denominations", lambda t: t.delete("denominations")), + ("delete-denom-list", lambda t: t.delete("denominations.0.denoms")), + ("delete-signature", lambda t: t.delete("exchange_sig")), + ("flip-master-pub", lambda t: t.flip("master_public_key")), + ("flip-denom-sig", lambda t: t.flip("denominations.0.denoms.0.master_sig")), + ("delete-wire-fees", lambda t: t.delete("wire_fees")), + ("rewrite-version", lambda t: t.modify("version", "999:0:0")), + ("rewrite-currency", lambda t: t.modify("currency", "XXX")), + ("rewrite-base-url", lambda t: t.modify("base_url", "http://elsewhere.invalid/")), + ] + for name, arm in cases: + c.app.fresh_start(dev_mode=True) + c.dev.logcat(clear=True) + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + with twister.armed(arm) as a: + c.app.handle_uri(op["taler_withdraw_uri"]) + time.sleep(7) + c.note(f"{name}: {c.dev.dump().texts()[:12]}") + c.check() + c.accept_tos() + c.accept_tos() + c.tap(r"(?i)confirm withdrawal", timeout=10) + time.sleep(6) + c.note(f"{name} after confirming: {c.dev.dump().texts()[:12]}") + c.check() + if a.errors: + c.note(f"{name}: arming complained: {a.errors}") + c.note(f"{name}: armed {a.fired} times") + c.ep.check_database() + + +@scenario("memory_pressure", setup="paid", + about="trim memory and background the app mid-flow") +def s_memory_pressure(c: Ctx) -> None: + """What Android does to an app it wants memory back from. + + TRIM_MEMORY_RUNNING_CRITICAL while a prompt is open, then a trip through + the background, is where a screen that kept state outside the saved + instance falls over. + """ + from device import PKG + order = c.merchant.create_order("EUR:1", summary="Order under memory pressure") + c.app.handle_uri(order["pay_uri"]) + c.require(r"(?i)Review order|Total:|^Pay", timeout=60) + pid = c.dev.shell(f"pidof {PKG}", check=False).strip().split()[0:1] + c.note(f"pid: {pid}") + for level in ("RUNNING_MODERATE", "RUNNING_LOW", "RUNNING_CRITICAL"): + c.dev.shell(f"am send-trim-memory {PKG} {level}", check=False) + time.sleep(1.5) + c.note("after trimming: " + str(c.dev.dump().texts()[:10])) + c.check() + # Background the app, trim again, come back. + c.dev.key("KEYCODE_HOME") + time.sleep(2) + c.dev.shell(f"am send-trim-memory {PKG} COMPLETE", check=False) + time.sleep(2) + c.dev.launch() + time.sleep(4) + restored = c.dev.dump() + c.note("after returning: " + str(restored.texts()[:12])) + c.check() + # The prompt should either still be there or be gone cleanly; either way + # the wallet has to work afterwards. + c.back_to_home() + rows = transaction_rows(open_transactions(c)) + c.note(f"{len(rows)} transactions afterwards") + c.check() + c.ep.check_database() + + +@scenario("rapid_taps", setup="funded", + about="hammer confirm buttons faster than the app can respond") +def s_rapid_taps(c: Ctx) -> None: + """Double-submission is the classic way to pay twice or abort twice.""" + order = c.merchant.create_order("EUR:1", summary="Hammered order") + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)Review order|^Pay", timeout=60) + pay = screen.find(r"(?i)^Pay\b") + if pay is None: + c.note("no pay button: " + str(screen.texts()[:10])) + return + target = screen.tap_target(pay) + x, y = target.center + for _ in range(6): + c.dev.tap(x, y) + time.sleep(0.15) + time.sleep(6) + c.note("after hammering pay: " + str(c.dev.dump().texts()[:12])) + c.check() + status = c.merchant.order_status(order["order_id"], order["token"]) + c.note(f"order status: {status.get('order_status')}, refunded: {status.get('refunded')}") + # One payment, not six. + rows = transaction_rows(open_transactions(c)) + purchases = [n.label for n in rows] + c.note(f"transactions: {purchases}") + c.check() + c.ep.check_database() + + +# -------------------------------------------------------------------- runner --- + +SETUPS: dict[str, Callable] = { + "fresh": lambda app, env: app.fresh_start(dev_mode=True), + "funded": flows.fund_wallet, + "paid": flows.funded_and_paid, + "keep": lambda app, env: app.home(), +} + + +def run(names: list[str], serial: str = SERIAL) -> dict: + env = Env.load() + dev = Device(serial) + stamp = int(time.time()) + results = [] + all_findings: dict[str, oracles.Finding] = {} + + for name in names: + sc = REGISTRY[name] + ep = Episode(dev, OUT, name=f"suite-w{WORKER}-{stamp}-{name}", + coverage_dir=COVERAGE) + c = Ctx(ep, env) + status, error = "ok", None + started = time.time() + try: + SETUPS[sc.setup](ep.app, env) + # Only what the scenario itself provokes should count. + ep.session = oracles.Session() + dev.logcat(clear=True) + sc.fn(c) + ep.observe() + except Exception as e: + status = "driver-error" + error = f"{type(e).__name__}: {e}" + traceback.print_exc(limit=3) + expected = [f for f in ep.session.findings.values() if f.kind in sc.expects] + summary = ep.finish({"scenario": name, "setup": sc.setup, "status": status, + "error": error, "notes": c.notes, + "expected_findings": [f.fingerprint for f in expected], + "seconds": round(time.time() - started, 1)}) + summary["serious"] = len([f for f in ep.session.serious() + if f.kind not in sc.expects]) + all_findings.update({k: v for k, v in ep.session.findings.items() + if v.kind not in sc.expects}) + results.append(summary) + print(f" {name:26} {status:13} {summary['serious']} serious, " + f"{len(summary['findings'])} total, {summary['seconds']}s") + for f in ep.session.findings.values(): + print(f" [{f.kind}] {f.detail[:150]}") + + out = { + "stamp": stamp, + "scenarios": results, + "findings": [f.__dict__ | {"fingerprint": f.fingerprint} + for f in all_findings.values()], + } + (OUT / f"suite-w{WORKER}-{stamp}-summary.json").write_text(json.dumps(out, indent=2)) + # oracles.INFORMATIONAL, not just "error-screen": this tally used its own + # narrower rule, so a withdrawal left pending on purpose -- every manual + # withdrawal the suite starts and never wires money to sits in + # PendingQueryingStatus forever, by design -- was counted as a serious + # finding twice a round and triaged again every time. + serious = [f for f in all_findings.values() + if f.kind not in oracles.INFORMATIONAL] + print(f"\n{len(results)} scenarios, " + f"{sum(1 for r in results if r['status'] == 'ok')} ok, " + f"{len(all_findings)} findings ({len(serious)} serious)") + print(f"summary: {OUT}/suite-w{WORKER}-{stamp}-summary.json") + return out + + +def main() -> int: + args = [a for a in sys.argv[1:] if not a.startswith("-")] + if "--list" in sys.argv: + for name, sc in REGISTRY.items(): + print(f"{name:26} [{sc.setup}] {sc.about.strip().splitlines()[0][:70]}") + return 0 + names = args or list(REGISTRY) + unknown = [n for n in names if n not in REGISTRY] + if unknown: + print(f"unknown scenarios: {unknown}\nknown: {list(REGISTRY)}") + return 2 + out = run(names) + return 0 if all(r["status"] == "ok" for r in out["scenarios"]) else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/simulator/driver/twister.py b/simulator/driver/twister.py @@ -0,0 +1,186 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Fault injection between the wallet and the exchange. + +`taler-twister` is an HTTP proxy that forwards to the real exchange and can +damage what passes through: truncate a response, force a status code, delete +or rewrite a field of the JSON. The stack has to be started from +`sim-twister.conf` for any of this to have something to talk to, and the +wallet's exchange base URL is then the twister port. + +Each command affects the *next* response (or upload) the proxy handles and is +then forgotten, so arming once and then starting a wallet operation usually +damages some unrelated poll instead of the request under test. `armed` keeps a +fault re-armed for as long as the step runs, which is what a scenario wants. + + t = Twister() + t.response_code(500) # the next exchange reply becomes a 500 + t.malform() # ... or is truncated at a random point + t.delete("denominations") # ... or loses a field + + with t.armed(lambda x: x.response_code(500)): + ... # every exchange reply in here is a 500 + +Dot paths address nested fields, and a numeric token is an array index, so +`denominations.0.denoms.0.master_sig` names one denomination signature. +""" + +from __future__ import annotations + +import json +import subprocess +import threading +import time +from pathlib import Path +from typing import Callable + +BINARY = "/opt/twister/bin/taler-twister" +DEFAULT_CONFIG = "/opt/taler-sim/run/stack/sim-twister.conf" +ENV_FILE = Path("/opt/taler-sim/run/stack/env.json") + + +class TwisterUnavailable(RuntimeError): + pass + + +class Twister: + def __init__(self, config: str | None = None, timeout: int = 30): + self.config = config or self._config_from_env() or DEFAULT_CONFIG + self.timeout = timeout + + @staticmethod + def _config_from_env() -> str | None: + try: + info = json.loads(ENV_FILE.read_text()).get("twister") + except (OSError, json.JSONDecodeError): + return None + return (info or {}).get("config") + + def _run(self, *args: str) -> str: + if not Path(BINARY).is_file(): + raise TwisterUnavailable(f"no twister binary at {BINARY}") + proc = subprocess.run([BINARY, "-c", self.config, *args], + capture_output=True, text=True, timeout=self.timeout) + if proc.returncode != 0: + raise TwisterUnavailable( + f"taler-twister {' '.join(args)} failed: " + f"{(proc.stderr or proc.stdout).strip()[:300]}" + ) + return proc.stdout + + # -- state ------------------------------------------------------------ + + def alive(self) -> bool: + try: + self._run("--checkalive") + return True + except TwisterUnavailable: + return False + + # -- faults ----------------------------------------------------------- + + def malform(self) -> None: + """Truncate the next response at a random point.""" + self._run("--malform") + + def malform_upload(self) -> None: + """Truncate the next request the wallet sends.""" + self._run("--malformupload") + + def response_code(self, status: int) -> None: + """Answer the next request with this status code.""" + self._run(f"--responsecode={status}") + + def delete(self, path: str) -> None: + """Remove a field from the next response body.""" + self._run(f"--deleteobject={path}") + + def modify(self, path: str, value: str) -> None: + """Replace a field in the next response body (always as a string).""" + self._run(f"--modify-dl={path}", f"--value={value}") + + def flip(self, path: str) -> None: + """Flip one character of a string field in the next response.""" + self._run(f"--flip-dl={path}") + + def flip_upload(self, path: str) -> None: + self._run(f"--flip-ul={path}") + + def header(self, name: str, value: str) -> None: + """Rewrite a header of the next response.""" + self._run(f"--modify-header-dl={name}", f"--value={value}") + + + # -- keeping a fault armed -------------------------------------------- + + def armed(self, arm: "Callable[[Twister], None]", period: float = 0.4): + """Context manager that re-arms `arm` until the block exits. + + A fault is one-shot, and the wallet talks to the exchange constantly + (/config, /keys, /reserves/...), so a single arming lands on an + arbitrary request. Re-arming in the background makes the fault apply + to the whole step; the number of times it actually fired is reported + as `fired` on the handle. + """ + twister = self + + class _Armed: + fired = 0 + errors: list[str] = [] + + def __init__(self) -> None: + self._stop = threading.Event() + self._thread = threading.Thread(target=self._loop, daemon=True) + + def _loop(self) -> None: + while not self._stop.is_set(): + try: + arm(twister) + self.fired += 1 + except Exception as e: # noqa: BLE001 - reported, not raised + if len(self.errors) < 3: + self.errors.append(str(e)[:120]) + self._stop.wait(period) + + def __enter__(self) -> "_Armed": + self._thread.start() + return self + + def __exit__(self, *exc: object) -> None: + self._stop.set() + self._thread.join(timeout=5) + + return _Armed() + + +# The faults a scenario can arm, with names that read in a report. +FAULTS = { + "truncated-response": lambda t: t.malform(), + "truncated-request": lambda t: t.malform_upload(), + "http-500": lambda t: t.response_code(500), + "http-404": lambda t: t.response_code(404), + "http-403": lambda t: t.response_code(403), + "http-502": lambda t: t.response_code(502), + "wrong-content-type": lambda t: t.header("Content-Type", "text/plain"), +} + + +if __name__ == "__main__": + import sys + t = Twister() + print(f"config: {t.config}") + print(f"alive: {t.alive()}") + if len(sys.argv) > 1: + FAULTS[sys.argv[1]](t) + print(f"armed {sys.argv[1]}") diff --git a/simulator/driver/wallet.py b/simulator/driver/wallet.py @@ -0,0 +1,200 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Wallet-app operations on top of the raw device driver. + +Only app-level knowledge lives here: the labels of the screens the simulator +has to pass through to reach a feature, and the one setting the whole simulator +depends on — developer mode, without which HandleUriScreen refuses every +taler+http:// URI that a local http deployment produces. +""" + +from __future__ import annotations + +import re +import time + +from device import Device, Screen + +DEV_MODE_LABEL = "Developer mode" +# Only shown while developer mode is on, so it doubles as the check that the +# toggle took effect. +DEV_MODE_MARKER = "Withdraw demo KUDOS" + + +class Wallet: + def __init__(self, dev: Device): + self.dev = dev + # Set by Episode: dump coverage before the process is wiped. + self.before_wipe = None + + # -- navigation ------------------------------------------------------- + + def fresh_start(self, dev_mode: bool = True) -> None: + """Wipe app data and come back up, optionally in developer mode.""" + # Coverage lives in the app process, so whatever ran before this point + # is lost when the process goes. The Episode sets this hook; without + # it, every scenario that restarts mid-run threw its measurement away + # (WalletInitErrorScreen reads 0% although db_corruption renders it). + if self.before_wipe is not None: + try: + self.before_wipe() + except Exception as e: # noqa: BLE001 - never fail a wipe over this + print(f"pre-wipe coverage dump failed: {e}") + # Rotation outlives the app's data, so reset it before anything else. + self.dev.portrait() + self.dev.clear_data() + # "pm clear" also revokes runtime permissions, so the camera has to be + # granted again or the scan screen opens on a system dialog instead. + self.dev.grant_camera() + self.dev.launch() + self.dev.wait_for(r"(?i)wallet|balance|withdraw", timeout=90) + if dev_mode: + self.enable_dev_mode() + + def home(self, tries: int = 6) -> Screen: + """Back out to the main screen.""" + for _ in range(tries): + screen = self.dev.dump() + if screen.find(r"(?i)^Scan QR code$") and not screen.find(r"(?i)^Close sheet$"): + return screen + self.dev.back() + time.sleep(1) + return self.dev.dump() + + def scroll_to_text(self, pattern: str, max_scrolls: int = 8) -> Screen: + """Scroll until a label shows up, downwards and then back up. + + Scrolling only one way misses a row that was already above the fold, + and a list that has reached its end stops moving, so the upward sweep + is where a missed row is usually found. + """ + seen: list[str] = [] + for direction in (True, False): + for _ in range(max_scrolls): + screen = self.dev.dump() + if screen.find(pattern): + return screen + signature = screen.signature() + if seen and seen[-1] == signature and not direction: + break # the list is not moving any more + seen.append(signature) + self.dev.scroll(down=direction, screen=screen) + time.sleep(0.8) + screen = self.dev.dump() + if screen.find(pattern): + return screen + raise TimeoutError(f"{pattern!r} not reachable by scrolling; " + f"last screen: {screen.texts()}") + + def open_settings(self, tries: int = 3) -> Screen: + """Open the Settings root and wait for it. + + How much of the list is on screen depends on how many rows the wallet + has to show, so waiting for "Developer mode" here fails as soon as the + list grows; callers scroll to the row they want. Landing in one of + Settings' own sub-screens (Payment services, Bank accounts) is treated + as not having arrived, and backed out of. + """ + sub_screen = re.compile( + r"(?i)^(Add payment service|Known bank accounts|No bank accounts saved" + r"|Select tax authority|Alias Type)$" + ) + for _ in range(tries): + self.home() + self.dev.tap_text(r"(?i)^Settings$", timeout=30) + screen = self.dev.wait_for( + r"(?i)Payment services|Developer mode|About|Version|Protect access", + timeout=30, + ) + if not any(sub_screen.match(t.strip()) for t in screen.texts()): + return screen + self.dev.back() + time.sleep(1.5) + return self.dev.dump() + + # -- the one setting the simulator cannot do without ------------------ + + def dev_mode_on(self) -> bool: + screen = self.dev.dump() + return screen.find(DEV_MODE_MARKER) is not None + + def enable_dev_mode(self) -> None: + """Turn developer mode on through the UI. + + MainActivity pushes the persisted flag into MainViewModel on every + start, so a debug build does *not* come up in developer mode however + BuildConfig.DEBUG is set; it has to be switched on here. + """ + self.open_settings() + self.scroll_to_text(DEV_MODE_LABEL) + if self.dev_mode_on(): + self.home() + return + screen = self.dev.dump() + row = screen.find(DEV_MODE_LABEL) + if row is None: + # Scrolling settled differently between the search and the dump. + screen = self.scroll_to_text(DEV_MODE_LABEL) + row = screen.find(DEV_MODE_LABEL) + if row is None: + raise RuntimeError(f"the developer mode row went away; " + f"settings showed: {screen.texts()}") + # Hit the switch at the right-hand end of the row rather than the label, + # which is not itself the clickable node. + _, y = row.center + width = max(n.bounds[2] for n in screen.nodes) + self.dev.tap(width - 100, y) + time.sleep(1.5) + if not self.dev_mode_on(): + # Fall back to the row itself, in case the switch moved. + self.dev.tap_node(row) + time.sleep(1.5) + if not self.dev_mode_on(): + raise RuntimeError(f"could not enable developer mode; " + f"settings showed: {self.dev.dump().texts()}") + self.home() + + # -- entry points ----------------------------------------------------- + + def dismiss_permission_dialog(self) -> bool: + """Answer a runtime-permission dialog if one is in the way.""" + screen = self.dev.dump() + if screen.find(r"(?i)allow .* to take pictures|While using the app") is None: + return False + node = screen.find(r"(?i)While using the app") or screen.find(r"(?i)^Allow$") + if node is None: + return False + self.dev.tap_node(node, screen) + time.sleep(1.5) + return True + + def open_scanner(self) -> Screen: + """Open the QR scan screen, past any permission prompt.""" + self.home() + self.dev.tap_text(r"(?i)^Scan QR code$", timeout=30) + time.sleep(1.5) + self.dismiss_permission_dialog() + return self.dev.wait_for(r"(?i)Scan or enter link|Scan QR", timeout=30) + + def handle_uri(self, uri: str) -> Screen: + """Share a URI into the wallet and return the screen it produced.""" + self.dev.send_uri(uri) + time.sleep(2) + return self.dev.dump() + + def balances(self) -> list[str]: + """Amounts visible on the main screen.""" + import re + screen = self.home() + return [t for t in screen.texts() if re.search(r"\d+[.,]\d\d", t)] diff --git a/simulator/emu/emu.sh b/simulator/emu/emu.sh @@ -0,0 +1,208 @@ +#!/bin/bash +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# Emulator lifecycle for the wallet simulator. One AVD per worker; the worker +# index picks both the AVD name and the (even) console port, so several workers +# can run side by side against the same Taler stack. +# +# Usage: +# emu.sh create <worker> create/replace the AVD +# emu.sh boot <worker> boot headless and wait for boot_completed +# emu.sh prepare <worker> <apk> install the wallet, grant permissions, +# kill animations, map the stack ports +# emu.sh reverse <worker> (re)map the stack ports into the emulator +# emu.sh snapshot <worker> <name> save a snapshot +# emu.sh restore <worker> <name> load a snapshot (fast episode reset) +# emu.sh serial <worker> print the adb serial +# emu.sh kill <worker> shut the emulator down + +set -eu + +SIM_ROOT=${SIM_ROOT:-/opt/taler-sim} +export ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT:-/opt/android-sdk} +export ANDROID_HOME=$ANDROID_SDK_ROOT +export ANDROID_AVD_HOME=${ANDROID_AVD_HOME:-$SIM_ROOT/avd} +ADB=$ANDROID_SDK_ROOT/platform-tools/adb +EMULATOR=$ANDROID_SDK_ROOT/emulator/emulator +AVDMANAGER=$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager +IMAGE=${SIM_SYSTEM_IMAGE:-"system-images;android-36;google_apis;x86_64"} +# A PNG to hang on the wall of the emulator's virtual scene, so the camera has +# something real to decode. Only settable at launch, hence one boot per image. +POSTER=${SIM_POSTER:-} +PKG=${SIM_PKG:-net.taler.wallet.fdroid.debug} +BOOT_TIMEOUT=${SIM_BOOT_TIMEOUT:-300} + +die() { echo "emu.sh: $*" >&2; exit 1; } + +worker=${2:-0} +avd_name() { echo "taler-sim-$worker"; } +# The API level the image carries, so the AVD can be tuned per platform. +api_level() { echo "$IMAGE" | sed -n 's/.*android-\([0-9][0-9]*\).*/\1/p'; } +# The virtual scene camera, which is what lets a QR code be shown to the +# device, needs an image that can deliver NV21 frames: below API 26 the camera +# service rejects the format ("Unsupported camera format for virtual scene +# views 825382478" -- that number is the NV21 fourcc) and retries until the +# boot times out. Those levels get the old emulated camera instead, which no +# scenario in the version matrix needs to decode from. +camera_back() { [ "$(api_level)" -ge 26 ] 2>/dev/null && echo virtualscene || echo emulated; } +# An old system image will not boot on a new image's budget. API 24 never +# finished booting with 4 GB of RAM and a 6 GB data partition -- 1200 seconds, +# twice, from a clean start and with the emulated camera, so neither the +# teardown nor the camera was the cause -- and boots in 35 seconds with 2 GB +# and 2 GB. The device profile is not the problem: pixel_6 boots fine at that +# size. Levels below 29 therefore get the smaller budget. +old_image() { [ "$(api_level)" -lt 29 ] 2>/dev/null; } +ram_size() { old_image && echo 2048 || echo 4096; } +heap_size() { old_image && echo 256 || echo 512; } +data_partition() { old_image && echo 2048M || echo 6144M; } +console_port() { echo $((5554 + 2 * worker)); } +serial() { echo "emulator-$(console_port)"; } + +create() { + mkdir -p "$ANDROID_AVD_HOME" + echo no | "$AVDMANAGER" create avd -n "$(avd_name)" -k "$IMAGE" \ + -d pixel_6 --force >/dev/null + local cfg="$ANDROID_AVD_HOME/$(avd_name).avd/config.ini" + python3 - "$cfg" "$(camera_back)" "$(ram_size)" "$(heap_size)" "$(data_partition)" <<'PY' +import sys +path = sys.argv[1] +cfg = {} +for line in open(path): + if '=' in line: + k, v = line.rstrip('\n').split('=', 1) + cfg[k] = v +# A temp data partition would throw away everything on shutdown, which breaks +# snapshots; the rest is headless tuning. +cfg.pop('disk.dataPartition.path', None) +cfg.update({ + 'hw.ramSize': sys.argv[3], + 'vm.heapSize': sys.argv[4], + 'disk.dataPartition.size': sys.argv[5], + 'hw.audioInput': 'no', + 'hw.audioOutput': 'no', + 'hw.camera.back': sys.argv[2], + 'hw.camera.front': 'emulated', + 'hw.keyboard': 'yes', + 'hw.gpu.enabled': 'yes', + 'hw.gpu.mode': 'swiftshader_indirect', + 'hw.lcd.width': '1080', + 'hw.lcd.height': '2400', + 'hw.lcd.density': '420', + 'showDeviceFrame': 'no', +}) +with open(path, 'w') as f: + f.writelines(f'{k}={v}\n' for k, v in sorted(cfg.items())) +PY + echo "created $(avd_name)" +} + +kill_emu() { + local s waited=0 port pid + s=$(serial) + port=$(console_port) + "$ADB" -s "$s" emu kill >/dev/null 2>&1 || true + # Waiting matters: `emu kill` returns as soon as the console accepts it, + # and the next AVD is created with the same name. A process still holding + # that AVD's lock files is why every second level of the version matrix + # failed to boot -- 26 ok, 28 failed, 29 ok, 30 failed, and so on. + while [ "$waited" -lt 90 ]; do + "$ADB" devices 2>/dev/null | grep -q "^$s" || break + sleep 2 + waited=$((waited + 2)) + done + for _ in $(seq 1 30); do + pid=$(pgrep -f -- "-port $port" | head -1) + [ -n "$pid" ] || break + kill "$pid" 2>/dev/null || true + sleep 2 + done + rm -f "$ANDROID_AVD_HOME/$(avd_name).avd"/*.lock 2>/dev/null || true + echo "killed $s after ${waited}s" +} + +boot() { + local log="$SIM_ROOT/run/emu-$worker.log" + mkdir -p "$SIM_ROOT/run" + "$ADB" start-server >/dev/null 2>&1 || true + local camera="$(camera_back)" + local poster_args=() + if [ -n "$POSTER" ] && [ "$camera" = virtualscene ]; then + [ -r "$POSTER" ] || die "no poster image at $POSTER" + poster_args=(-virtualscene-poster "wall=$POSTER") + fi + local wipe_args=() + [ "${SIM_KEEP_DATA:-0}" = "1" ] || wipe_args=(-wipe-data) + setsid "$EMULATOR" -avd "$(avd_name)" -port "$(console_port)" \ + -no-window -no-audio -no-boot-anim -gpu swiftshader_indirect \ + -no-snapshot-load -no-snapshot-save "${wipe_args[@]}" \ + -camera-back "$camera" "${poster_args[@]}" \ + > "$log" 2>&1 < /dev/null & + echo "booting $(avd_name) on $(serial), log $log" >&2 + local waited=0 + while [ "$waited" -lt "$BOOT_TIMEOUT" ]; do + if [ "$("$ADB" -s "$(serial)" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r\n')" = "1" ]; then + echo "booted after ${waited}s" + return 0 + fi + sleep 2 + waited=$((waited + 2)) + done + tail -20 "$log" >&2 || true + die "emulator did not finish booting within ${BOOT_TIMEOUT}s" +} + +reverse() { + local s env_json p + s=$(serial) + env_json=${SIM_RUN:-$SIM_ROOT/run/stack}/env.json + [ -r "$env_json" ] || die "no $env_json; start the stack first" + for p in $(python3 -c 'import json,sys; print(" ".join(str(p) for p in json.load(open(sys.argv[1]))["ports"]))' "$env_json"); do + "$ADB" -s "$s" reverse "tcp:$p" "tcp:$p" >/dev/null + done + echo "mapped stack ports into $s" +} + +prepare() { + local s apk + s=$(serial) + apk=${3:-$SIM_ROOT/apk/wallet.apk} + [ -r "$apk" ] || die "no APK at $apk" + # Deterministic, animation-free UI: the driver reads the view hierarchy and + # animations make it race. + "$ADB" -s "$s" shell settings put global window_animation_scale 0 + "$ADB" -s "$s" shell settings put global transition_animation_scale 0 + "$ADB" -s "$s" shell settings put global animator_duration_scale 0 + "$ADB" -s "$s" shell settings put secure long_press_timeout 250 + "$ADB" -s "$s" shell svc power stayon true + # Leave the device in portrait: user_rotation survives app data wipes. + "$ADB" -s "$s" shell settings put system accelerometer_rotation 0 + "$ADB" -s "$s" shell settings put system user_rotation 0 + "$ADB" -s "$s" install -r -g "$apk" + "$ADB" -s "$s" shell pm grant "$PKG" android.permission.CAMERA 2>/dev/null || true + reverse + echo "prepared $s with $apk" +} + +case "${1:-}" in + create) create ;; + boot) boot ;; + prepare) prepare "$@" ;; + reverse) reverse ;; + snapshot) "$ADB" -s "$(serial)" emu avd snapshot save "${3:-clean}" ;; + restore) "$ADB" -s "$(serial)" emu avd snapshot load "${3:-clean}" ;; + serial) serial ;; + kill) kill_emu ;; + *) die "usage: emu.sh create|boot|prepare|reverse|snapshot|restore|serial|kill <worker> [arg]" ;; +esac diff --git a/simulator/emu/tls-names.sh b/simulator/emu/tls-names.sh @@ -0,0 +1,89 @@ +#!/bin/bash +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# Make one emulator resolve the hostnames the wallet hard-codes to the TLS +# front end on the host. +# +# The wallet hard-codes https://taldir.gnunet.org (see +# findings/alias-registration-hardcodes-the-directory.md) and defaults to +# https://mailbox.gnunet.org, so the only way to exercise those code paths as +# they ship is to answer for the names. The URLs under test are not touched. +# +# The simulator's CA is trusted because the "sim" build type bundles it as a +# trust anchor (wallet/src/sim/res/xml/network_security_config.xml), not by +# anything done here. Installing it into the device's own store instead is a +# dead end worth recording: both system stores have to be replaced by a tmpfs +# from inside init's mount namespace (an APEX mount made from adbd is invisible +# to apps, which shows up as "tls: unknown certificate" in the proxy log while +# everything else looks right), and the framework restart that is then needed +# to make zygote see them leaves the network at PARTIAL_CONNECTIVITY for a +# while -- during which the wallet refuses to do anything with "This action +# requires internet connection". +# +# Usage: tls-names.sh <worker> +# +# Needs the TLS front end running on the host (tls/tlsproxy, port 8443) and is +# undone by a `wipe`/reboot of the emulator, so it has to be re-run after one. + +set -eu + +SIM_ROOT=${SIM_ROOT:-/opt/taler-sim} +export ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT:-/opt/android-sdk} +ADB=$ANDROID_SDK_ROOT/platform-tools/adb +WORKER=${1:?usage: tls-names.sh <worker>} +SERIAL=emulator-$((5554 + 2 * WORKER)) +HOSTS_ENTRY="127.0.0.1 taldir.gnunet.org mailbox.gnunet.org" +PROXY_PORT=${SIM_TLS_PORT:-8443} + +say() { printf 'tls-names %s: %s\n' "$SERIAL" "$*" >&2; } + +# 1. A privileged listening port on the device needs a root adbd. Restarting +# adbd takes every `adb reverse` mapping with it, so the stack's ports have +# to be put back afterwards or the wallet loses the exchange -- and a wallet +# that cannot reach the exchange reproduces unrelated findings very +# convincingly. +if [ "$("$ADB" -s "$SERIAL" shell id -u | tr -d '\r\n')" = 0 ]; then + say "adbd is already root" +else + "$ADB" -s "$SERIAL" root >/dev/null 2>&1 || true + sleep 4 + "$ADB" -s "$SERIAL" wait-for-device + "$(dirname "$0")/emu.sh" reverse "$WORKER" >/dev/null 2>&1 || + say "WARNING: could not restore the stack's port mappings" + say "rooted, stack ports restored" +fi + +# 2. The name has to resolve to the device's own loopback, where the reverse +# mapping is listening. /system is read-only on these images and `adb +# remount` does not help (no overlay), so the file is replaced by a bind +# mount rather than edited -- a mount needs no write access to /system. +if "$ADB" -s "$SERIAL" shell "grep -q taldir.gnunet.org /system/etc/hosts" 2>/dev/null; then + say "hosts entry already there" +else + "$ADB" -s "$SERIAL" shell " +set -e +cp /system/etc/hosts /data/local/tmp/hosts +echo '$HOSTS_ENTRY' >> /data/local/tmp/hosts +chmod 644 /data/local/tmp/hosts +chcon u:object_r:system_file:s0 /data/local/tmp/hosts 2>/dev/null || true +mount --bind /data/local/tmp/hosts /system/etc/hosts +grep taldir /system/etc/hosts +" >/dev/null || { say "could not bind a hosts file over /system/etc/hosts"; exit 1; } + say "hosts entry bind-mounted" +fi + +# 3. Port 443 on the device forwards to the host's TLS front end. +"$ADB" -s "$SERIAL" reverse "tcp:443" "tcp:$PROXY_PORT" >/dev/null +say "device port 443 -> host $PROXY_PORT; done" diff --git a/simulator/findings/CAMPAIGN.md b/simulator/findings/CAMPAIGN.md @@ -0,0 +1,2007 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Simulator campaign log + +Every finding here has three things: what happens, how to reproduce it by hand +on a device, and a `repro_*.py` beside it that reproduces it against the +simulator. To run one: + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_zero_deposit.py # worker 0 by default +python3 ../findings/repro_zero_deposit.py emulator-5562 +``` + +Each exits 0 when the defect is present and prints the evidence it checked, so +they double as regression tests once a fix lands. + +## Findings so far + +| Finding | Severity | How it was found | +| --- | --- | --- | +| [`addglobalcurrencyexchange-null-masterpub.md`](addglobalcurrencyexchange-null-masterpub.md) — "Treat as global" sends a request with no `exchangeMasterPub`, so wallet-core answers `WALLET_UNEXPECTED_EXCEPTION` and nothing happens | low-moderate (developer mode only) | random exploration, seed 11 | +| [`action-buttons-have-no-accessible-name.md`](action-buttons-have-no-accessible-name.md) — none of the main screen's seven action buttons has an accessible name; TalkBack cannot announce them | moderate (release builds) | the driver could not tap them | +| [`mailbox-private-keys-written-to-log.md`](mailbox-private-keys-written-to-log.md) — both mailbox private keys are logged every 30 s, where the app's own log export picks them up | moderate | an oracle false positive led to the line | +| [`word-currency-symbol-glued-to-amount.md`](word-currency-symbol-glued-to-amount.md) — amounts render as `UNKNOWN0.00` and `Total: EUR1.00` when the currency symbol is a word | low (cosmetic) | QR scan of an order that does not exist | +| [`delete-transaction-requeries-deleted-id.md`](delete-transaction-requeries-deleted-id.md) — deleting a transaction makes the app ask wallet-core for it again | low | the `history_delete` scenario, twice | +| [`error-code-registry-behind-wallet-core.md`](error-code-registry-behind-wallet-core.md) — the app's registry is 26 wallet codes behind the wallet-core it ships; two were hit in normal runs | low | tallying error replies across all logs | +| [`dev-experiment-uri-exits-the-app.md`](dev-experiment-uri-exits-the-app.md) — an unknown `dev-experiment` URI logs an internal error and drops the user on the home screen | low (developer mode only) | the `uri_dev_experiment` scenario | +| [`add-payment-service-fails-silently.md`](add-payment-service-fails-silently.md) — every payment-service failure is silent: `ExchangeManager` publishes four error channels and nothing reads any of them | moderate | the `exchange_url_fuzz` scenario | +| [`deposit-does-not-guard-zero-amounts.md`](deposit-does-not-guard-zero-amounts.md) — clearing the deposit amount raises `WALLET_UNEXPECTED_EXCEPTION`, and depositing at or below the fee stores a zero-value deposit | low-moderate | the `deposit_flow` scenario | +| [`unreachable-host-leaves-blank-retrying-purchase.md`](unreachable-host-leaves-blank-retrying-purchase.md) — a prompt the app cannot prepare is an empty screen: eleven different exchange faults produce the same blank "Withdraw UNKNOWN", and it does not recover when the fault stops | moderate | random exploration, then fault injection | +| [`refresh-fails-on-mixed-age-denominations.md`](refresh-fails-on-mixed-age-denominations.md) — on an exchange offering age-restricted and ordinary denominations, the exchange rejects the melt and the change is never recovered; fixed upstream after the shipped wallet-core was built | high where it applies | the `refund` scenario, once age restriction was enabled | +| [`bitcoin-transfer-relabels-the-amount-as-btc.md`](bitcoin-transfer-relabels-the-amount-as-btc.md) — the Bitcoin wire instructions say "5.00 BTC" for a withdrawal of EUR 5.00, in the screen and on the clipboard | low | the `withdraw_account_tabs` scenario, once a Bitcoin account was signed | +| [`mailbox-payment-only-actionable-for-one-scheme.md`](mailbox-payment-only-actionable-for-one-scheme.md) — a payment received by mailbox shows an "Accept payment" button only for a literal `taler://` prefix; the developer-mode and extension schemes become a bare string | low-moderate | the `mailbox_roundtrip` scenario | +| [`taldir-protocol-version-mismatch.md`](taldir-protocol-version-mismatch.md) — the directory advertises protocol `0:0:0`, wallet-core's client requires `1:0:0` and refuses, and the precise reason is replaced by "could not read the configuration" | low-moderate | deploying a real taldir | +| [`alias-registration-hardcodes-the-directory.md`](alias-registration-hardcodes-the-directory.md) — the Taler directory URL is a literal in two files, so alias registration and contact lookup can only ever talk to `taldir.gnunet.org` | low | trying to cover the `contacts` package | +| [`amounts-without-currency-specification.md`](amounts-without-currency-specification.md) — the wire transfer instructions read "transfer 5.00 EUR … to receive €4.88", and the incoming peer-payment prompt shows "Total: 1.00 EUR" | low | the `withdraw_account_tabs` and `peer_push_receive` scenarios | +| [`release-error-screen-explains-nothing.md`](release-error-screen-explains-nothing.md) — with developer mode off, an error whose explanation is in `detail` rather than `hint` shows only the word "Error" | moderate (release builds) | the `error_screen_without_dev_mode` scenario | +| [`a-failed-query-is-shown-as-an-empty-wallet.md`](a-failed-query-is-shown-as-an-empty-wallet.md) — a failed `getDepositWireTypes` is shown as "No bank accounts saved", a failed `getMaxPeerPushDebitAmount` as "€0.00" to send; four of ten screens report nothing | moderate | the `api_error_sweep` scenario | +| [`wallet-lock-opens-when-the-credential-is-gone.md`](wallet-lock-opens-when-the-credential-is-gone.md) — once the device credential is removed, "Protect access to wallet" still shows its lock screen but opens on one tap with no authentication | moderate (security, release builds) | the `wallet_lock_without_credential` scenario | +| [`unknown-wire-method-hangs-the-deposit-form.md`](unknown-wire-method-hangs-the-deposit-form.md) — an exchange advertising a wire method the app does not know makes the whole reply undecodable and the add-account form spin for ever; three enums carry an `Unknown` member that can never be used | moderate | the `deposit_methods` scenario, once a Cyclos address was signed | +| [`purge-destroys-coins-and-history-without-saying-so.md`](purge-destroys-coins-and-history-without-saying-so.md) — "Force deletion (purge)" removes the balance and every transaction with the payment service, from a dialog that is a title, a checkbox and two buttons | moderate | the `history_after_forgetting_exchange` scenario | +| [`suspended-looks-like-completed-in-the-list.md`](suspended-looks-like-completed-in-the-list.md) — the transaction list has no branch for `Suspended`, so a suspended withdrawal's row says "Waiting for confirmation" instead | low-moderate | the `transaction_states_rendered` and `withdraw_suspend_resume` scenarios | +| [`aborted-credit-shows-the-whole-amount-as-fee.md`](aborted-credit-shows-the-whole-amount-as-fee.md) — an aborted withdrawal reads "Chosen amount €5.00 / Fee −€5.00 / Total amount €0.00"; the same arithmetic is on three further credit screens | low-moderate | a note of the `abort_then_retry` scenario | +| [`pos-confirmation-shows-five-codes.md`](pos-confirmation-shows-five-codes.md) — "Confirmation code" prints every T-OTP code in the valid time range, with nothing to say which one to read out | low | the `payment_pos_confirmation` scenario | + +Each one has a manual reproduction and, where there is something to run, a +`repro_*.py` script beside it. Three are established by reading rather than +running — the hard-coded directory URL, the error-code registry and the +fault-injection half of the blank-prompt finding — and each says which command +shows it. + +One entry per iteration: what was run, what the coverage was afterwards, what +it found, and what the next iteration aims at. Coverage is JaCoCo line coverage +of the `wallet` module (the Kotlin shell only — wallet-core is TypeScript inside +QuickJS and is not instrumentable through qtart). + +## Iteration 1 — baseline (random exploration only) + +Ran `smoke_withdraw`, `smoke_pay` and two `explore.py` runs (80 and 100 steps). + +* **Coverage: 33.9 %** line (5855/17247), 22.3 % branch, 35.8 % class. +* Findings: one confirmed defect, `addglobalcurrencyexchange-null-masterpub.md` + (`WALLET_UNEXPECTED_EXCEPTION` from "Treat as global"). Everything else the + oracles flagged was a correct refusal. +* Gaps, by missed lines: `peer` 0.9 % covered, `deposit` 0.8 %, `accounts` + 1.3 %, `transfer` 0.0 %, `tokens` 1.1 %, `donau` 3.4 %, `mailbox` 20.2 %, + `payment` 27.4 %, `exchanges` 27.8 %, `transactions` 45.4 %. + +Random exploration reaches the screens that are one tap from the main screen and +stops there: everything behind an amount field or a multi-step form stayed +untouched. Hence the scenario suite. + +## Iteration 2 — feature scenarios + +`suite.py` with 33 scenarios covering the flows named in the campaign brief: +transaction history and detail views, deleting transactions, aborting, +suspending and resuming, suspending and aborting, abandoning, adding and +removing exchanges, terms-of-service accept/reject, every settings row and +switch, the scan screen's manual entry, deposits, peer send/request in both +directions, manual withdrawal with wire-transfer details, tokens, donau and +contacts. + +Ran 33 scenarios across 4 emulators on tripwire (one bank customer and one +CLI peer wallet per worker, all against one Taler stack). + +* **Coverage: 40.8 %** line (7043/17247), up from 33.9 %; class 44.7 %, + branch 27.5 %. +* 23 of 33 scenarios passed. The 10 failures were all harness faults, not + wallet faults, and each one taught the driver something: + * a helper lost in an edit (`open_exchange_list`) — restored; + * `taler-wallet-cli` needs a `.sqlite3` database ("memory backend not + supported") and cannot fund itself with `withdraw --exchange`, which + creates a *manual* withdrawal nobody completes — the peer wallet now goes + through the bank like the app, with a bank customer of its own; + * bank accounts ran out of money mid-run ("Insufficient funds to withdraw + with Taler") — provisioning now tops every account up past EUR:100; + * **tapping a label did nothing** for the main screen's Send / Request / + Withdraw / Deposit buttons, because the clickable element is an unnamed + `Button` *above* the text. `Screen.tap_target()` now resolves a label to + the clickable node that contains it or sits next to it. +* Findings: the tap problem turned out to be a defect in the app, not just in + the driver — see `action-buttons-have-no-accessible-name.md`. The oracles + flagged nothing else: no crash, no internal error, no stuck operation, and + the new database oracles (`operation_retries`, unfinished operations) were + quiet throughout. +* New oracles this iteration: background failures and stuck operations read + out of the wallet's own SQLite database (`dbprobe.py`), which sees errors the + UI never shows. + +## Iteration 3 — the same scenarios with a working driver, plus 17 new ones + +50 scenarios: everything from iteration 2 (10 of which never really ran), plus +selection-mode bulk delete, transaction filters, mailbox, contacts, the +`add-contact` and `dev-experiment` URIs, order templates, expired and deleted +orders, change (refresh) transactions, and a batch of adversarial sequences — +suspend/kill/relaunch/resume, abort-then-reuse-the-URI, hostile amounts in the +deposit and peer fields, airplane mode mid-withdrawal, two pay URIs at once, +force-purging an exchange that still holds coins, and rejecting the terms of +service mid-withdrawal. + +Ran 60 scenarios across 4 emulators; 55 passed, and the 5 that did not were +harness faults (all since fixed: the CLI peer could not fund itself, the +Mailbox row needed scrolling in both directions, and `withdraw_manual` needs a +wallet that already knows the exchange). + +* **Coverage: 56.5 %** line (9743/17247), up from 40.8 %; class 60.9 %, branch + 44.8 %. +* **wallet-core operations exercised: 44/71 (62 %)**, up from 26/71. What is + left is mostly features that need services this stack does not run (Taldir + alias registration, the GNUnet mailbox) plus the database export/import + pickers. +* Newly reached, from 0 %: token issuance and the Discounts screen (a v1 + contract with a token output), contract choices, the deposit account forms, + the donau setup screen, performance stats, and the bank-account manager. +* Findings: the two written up above, plus repeats of the known ones. Two + `silent-failure` reports were false positives from background log chatter, + which is why that oracle now only counts wallet-core error replies. + +## Verified good behaviour + +Negative results worth recording, because each was a plausible place for a +crash and is not one: + +* **A corrupted wallet database is handled.** Overwriting the SQLite header and + restarting shows "An error occurred while starting the wallet … Please retry, + and if the problem persists, export the …" — no crash, and the wallet works + again after a wipe (`db_corruption`). +* **Suspend survives process death.** Suspending a withdrawal, killing the app + and reopening it leaves the transaction suspended and still offering *Resume* + (`lifecycle_kill`). +* **A withdrawal survives losing the network.** Turning on airplane mode + mid-withdrawal and turning it off again lets the transaction finish without + intervention (`offline_withdraw`). +* **Invalid QR codes are refused cleanly.** All ten payloads in the QR suite — + malformed base32, unknown actions, a plain https URL, free text — produce an + explained refusal rather than silence or a crash. +* **Paying the same order twice** shows the completed transaction rather than + charging again (`payment_twice`). +* **A transaction the app cannot parse is handled.** `TransactionSerializer` + falls back to a `DummyTransaction` when deserialization throws, and nothing + had ever given it one. Fed a type that does not exist + (`interpretive-dance`) and a withdrawal with no amounts, the list renders + both as "Unknown transaction" with a zero amount and stays usable -- no + crash, no blank row (`transaction_states_rendered`). +* **A database export can be restored.** The export/import round trip brings a + wiped wallet back to its balance and its transactions + (`settings_import`). This one took three attempts to establish, all of + them harness error; see the near-miss above. +* **Tap-to-pay works, and refuses what it should.** An order delivered as an + NDEF record is paid like any other, and a tag carrying a plain website, a + bare `taler+http://pay/` or a non-existent order each produce their own + explained error (`nfc_tap_to_pay`). +* **KYC works end to end.** On the KYC stack a withdrawal above the threshold + shows "KYC required, preparing challenge", then "This transaction would + exceed a limit set by the payment service. To increase the limit, follow the + instructions linked below."; the call to action hands off to the exchange's + KYC page in Chrome, and coming back to the wallet shows the explanation + again. No internal errors anywhere in that path. +* **The app has not crashed once.** Across every round, scenario and + exploration step, no `FATAL EXCEPTION` belongs to `net.taler.wallet`. The + ones in the logs are `uiautomator dump` colliding with itself, which is the + driver's problem — the oracle now says so rather than reporting a wallet + crash. + +## Iteration 4 and onward — unattended rounds + +`driver/forever.sh` runs continuously: provision (topping up the bank), all 65 +scenarios across 4 emulators, then a random-exploration pass with a fresh seed +each round, dumping coverage after each phase and appending one line per round +to `run/rounds.log`. Round 4 started at 23:24. + +### Where the numbers stand + +| After | Line coverage | wallet-core operations | +| --- | --- | --- | +| random exploration only | 33.9 % | 26/71 (37 %) | +| iteration 2 (first scenario pass) | 40.8 % | — | +| iteration 3 (working driver) | 56.5 % | 44/71 (62 %) | +| round 4 | 61.2 % | 48/71 (68 %) | + +The 23 operations still unexercised are mostly features with no service behind +them here: Taldir alias registration (`registerAlias`, `lookupAlias`, +`completeRegisterAlias`, `addContact`, `deleteContact`) and GNUnet mailbox +messaging (`addMailboxMessage`, `sendTalerUriMailboxMessage`, +`deleteMailboxMessage`). The rest — the database import/reset pickers, +`failTransaction`, `cancelProgressToken`, the donau statements and the +incoming-peer-payment pair — are covered by scenarios added for round 5. + +### What the stack gained + +Round 4 ended with a config swap that unlocked two feature areas the wallet +could not reach before: + +* a **second exchange account in IBAN form**, so the manual withdrawal offers + an account picker and the IBAN transfer screens; +* **age-restricted denominations**, so the withdrawal screen offers "Restrict + usage to age" (8, 10, 12, 14, 16, 18) — exercised end to end. + +Neither happens by itself: `taler-unified-setup.sh` enables only the account +given with `-u`, and age restriction needs `AGE_RESTRICTION_ENABLED` in the +`[exchange]` section on top of the age-restricted denominations. + +### Round 5 + +75 scenarios; 49 ran, and 26 failed on one shared cause: the bank accounts ran +dry. A fresh account holds exactly the EUR:100 registration bonus, the +provisioning top-up only triggered *below* EUR:100, and a round of 75 +scenarios spends far more. Accounts are now kept at EUR:2000 and a refused +withdrawal tops up and retries, so the whole class is gone. + +No new defects. What the round did show is that the oracles now catch by +themselves what used to take noticing by hand: the screen-sanity oracle +flagged `UNKNOWN0.00` on the main screen without anyone looking for it, and the +`expects` declarations kept the deliberate failures (a corrupted database, a +dead exchange) out of the serious column. + +### Rounds 6 to 10, the KYC pass, and two fault-injection phases + +Rounds kept running unattended; `phase.sh` can now pause them, swap the stack +for a variant, run a named set of scenarios and put everything back. + +* **KYC pass** (`sim-kyc.conf`, a FORM check with a EUR:5 withdraw threshold): + the hand-off works — the withdrawal reports "KYC required, preparing + challenge", the action opens the KYC page in Chrome, and coming back shows + "This transaction would exceed a limit set by the payment service". The one + serious finding of that phase was a withdrawal "retried 4 times", which is + the ordinary scenarios doing a plain EUR:10 withdrawal on a stack that + demands identification above EUR:5 — correct behaviour, not a defect. +* **Fault injection**, twice, and both runs measured nothing: + 1. the first because the bank still suggested the direct exchange URL while + the wallet was configured for the proxy, so every withdrawal was refused + with `WALLET_EXCHANGE_BASE_URL_MISMATCH` before a fault could matter + (`SUGGESTED_WITHDRAWAL_EXCHANGE` now points at the proxy); + 2. the second because **a twister fault is one-shot**. Arming it and then + starting a withdrawal spends it on whichever poll happens to come first, + which is why all seven fault types produced an untouched withdrawal + prompt and a withdrawal that then completed normally. `Twister.armed()` + re-arms in the background for as long as the step runs, and the field + faults now name real paths (`denominations.0.denoms.0.master_sig`, not + `denoms`, which matched nothing and said so in twister's log). + +### Iteration 5 — what one exchange and one wire method were hiding + +Two configuration facts, not scenarios, were holding coverage down: + +* `taler-unified-setup.sh` uploads a wire fee only for the method it was told + about, and **wallet-core hides every exchange account whose method has no + fee**. The IBAN account had been enabled since round 4 and was still + invisible: `/keys` listed it under `accounts` but `wire_fees` had only + `x-taler-bank`. One `taler-exchange-offline wire-fee now iban …` made the + account picker, the IBAN transfer screen (0 % → 61 %), the IBAN deposit form + (0 % → 95 %) and the EPC QR card appear. +* With **one** payment service every "which one?" step picks the only + candidate, so the exchange picker, "treat as global" and the balance scopes a + second service creates were unreachable. `backend/exchange2.sh` now starts a + second, independent exchange (own port, database, offline key, secmod + sockets, bank account at the shared libeufin) beside the stack in 11 s. + +Also fixed: the peer wallet could not be funded at all — +`taler-wallet-cli wait-tx --state pending` returns immediately, because the +transaction is already pending, so no task ever ran. Waiting for +`pending/idle` is the pump; all four peer scenarios pass now where they used +to be driver errors. + +* **Coverage: 66.0 %** line (11390/17247), up from 61.2 %; branch 53.8 %, + class 70.2 %. +* New scenarios: `withdraw_account_tabs` (one transfer screen per wire + method), `payment_pos_confirmation` (an order tied to a merchant OTP + device — the only way to reach the TOTP screen), `exchange_two_services`, + `withdraw_pick_exchange`, `balances_two_exchanges`. +* New findings: the hard-coded directory URL, the two amount notations in one + sentence, and the five confirmation codes. + +## Iteration 6 — fault injection that lands, and three more defects + +### Fault injection, third attempt + +With `Twister.armed()` re-arming in the background, every fault finally hit +the request it was aimed at (the notes record 64 to 116 re-arms per step): + +* **Payments survive transport faults.** A truncated reply, 500, 404, 403, + 502 or the wrong content type leaves the purchase pending and the merchant + saying "claimed"; when the fault stops, the wallet retries and the merchant + says "paid". Two of three faulted payments recovered on their own within the + measurement window, and the third had run the wallet out of coins — the + scenario now withdraws EUR:20 first and waits 90 s for the recovery, so the + distinction is recorded rather than guessed. +* **Withdrawals do not.** Eleven ways of breaking `/keys` — truncation, five + status codes, the wrong content type, a deleted denomination list, a flipped + master public key, a forged denomination signature, missing wire fees, an + impossible protocol version — all produce the *same* screen, + `['Go back', 'Withdraw UNKNOWN', 'Internal event log']`, and it stays that + way after the fault is removed. That went into + `unreachable-host-leaves-blank-retrying-purchase.md`, which is no longer + about unreachable hosts: it is about a prompt with no error state. + +### Three defects, from three different directions + +* **An aborted withdrawal says the whole amount went to fees** — found by + reading a scenario's notes, now caught by an oracle + (`fee-on-dead-transaction`), and shared by all four credit screens. +* **The wallet lock opens with no credential** — found by asking what happens + when the thing a security feature depends on goes away. The overlay still + appears and a single tap opens the wallet. +* **The point-of-sale confirmation shows five codes** — found by reaching + `PayTotpComposable` for the first time, which needed a merchant OTP device. + +### What the operation counter kept pointing at + +Measuring which wallet-core operations the campaign had *never* reached found +three driver bugs that each hid a feature: + +* `addBankAccount`, `forgetBankAccount` and `getBankAccountById` had never + run, because the form's submit button carries the same string as the app bar + title ("Add account"), the label search found the title, and the neighbour + search then switched tabs instead. `Ctx.tap_button` takes the lowest + matching node that is clickable and contains the label. +* `setDonau` had never run, because the tax payer ID was being typed into the + authority URL field and Save stays disabled until both are filled. +* `addContact` and `deleteContact` had no scenario at all. + +Still out of reach: the directory operations (`registerAlias`, +`completeRegisterAlias`, `lookupAlias`) behind the hard-coded URL, the mailbox +operations with no mailbox service in this stack, and `importDb` / `clearDb`. + +### New: failing a wallet-core call from the outside + +wallet-core takes `taler://dev-experiment/api-error?operation=…&detail=…`, +where the detail is base64url JSON with an error code, and fails that +operation that many times. `api_error_sweep` uses it to make each screen's own +call fail — balances, transactions, exchanges, contacts, bank accounts, +deposit wire types, withdrawal details, peer limits, discounts, donau — and +reports which screens then say nothing. It needs no proxy and no stack +variant, which makes it the cheapest way to hunt for the silent-failure class +that `add-payment-service-fails-silently.md` is one instance of. + +## Iteration 7 — failing wallet-core from the outside + +The sharpest tool so far turned out not to be a proxy at all. wallet-core +accepts two developer-mode URIs: + +``` +dev-experiment/api-error?operation=<op>&detail=<base64url JSON>&count=<n> +dev-experiment/api-response?operation=<op>&response=<base64url JSON>&count=<n> +``` + +the first failing a named operation `n` times with a given error, the second +answering it with a canned reply. No stack variant, no proxy, no restart. + +`api_error_sweep` makes one operation fail per screen and reads what the screen +then says. Thirteen operations in, the split is clean: **six screens report the +failure** (balances, transactions, bank accounts, discounts, passes, terms of +service — an `ErrorComposable` with the code and an export affordance) and +**seven say nothing**. Three of the seven state the failure as a fact about the +user: "No bank accounts saved in the wallet", "No contacts yet.", and a Send +screen offering "€0.00" on a wallet holding €9.87. That is +`a-failed-query-is-shown-as-an-empty-wallet.md`, and it also reproduced the +blank withdrawal prompt from a single injected error — no twister needed. + +`error_screen_without_dev_mode` then asked what a *release* build shows, by +turning developer mode off after queueing the error. Everything in this +campaign runs in developer mode, where the error screen prints the whole error +as JSON; without it the explanation is `userFacingMsg`, the hint and the +message concatenated, and an error carrying neither renders as the word +"Error" and two export buttons. wallet-core puts a bad request's reason in +`detail`, which the app keeps but never shows: +`release-error-screen-explains-nothing.md`. + +Both defects are now oracles — `absence-after-error` (an empty state claimed +while the query behind it was failing) and `mixed-amount-notation` — so the +next round catches the class rather than the instance. + +### Two more screens reached by signing an address + +The wallet picks a transfer screen purely from the payto method, so signing an +address at the exchange is enough to render it. A `payto://bitcoin/…` address +brought up the segwit instructions — and with them a defect: the amount is +relabelled, not converted, so a EUR 5.00 withdrawal reads "5.00 BTC" on the +screen and on the clipboard (`bitcoin-transfer-relabels-the-amount-as-btc.md`). +A `payto://cyclos/…` address covers the fourth and last transfer screen. + +### Scenarios added this iteration + +`api_error_sweep`, `api_response_hostile` (a balance of €999,999,999,999.99 +renders correctly, with grouping separators), `error_screen_without_dev_mode`, +`denom_loss_transaction` (the loss-of-funds transaction, which no stack can +produce), `exchange_turns_hostile` (the exchange's protocol version and master +key change under the wallet), `peer_push_abandon` (the only reachable path to +`failTransaction`: "Abandon" is offered on deposits and outgoing peer +payments, never on withdrawals), `contacts_add_and_forget`, +`wallet_lock_without_credential`, `revoke_denomination`. Ninety-one in total. + +Three scenarios had been passing every round without recording a single +observation, which is indistinguishable from doing nothing; they now say what +they saw. And the random exploration had **never run in any round** — the +STOP file a queued phase sets breaks the loop before it, so it now runs first. + +## Iteration 8 — 69.7 %, and what a config change found + +* **Coverage: 69.7 %** line (12018/17247), up from 66.0 %; branch 57.6 %, + class 73.9 %. The start of the campaign was 33.9 %. +* What is left is mostly out of reach rather than untried: about 190 lines have + **no caller at all** (`PromptAddContactScreen`, `GridMenu`, + `DemandAttention`, `SelectExchangeDialogFragment`, and + `SelectionModeTopAppBar` — the transaction list implements selection mode + inline instead), and another ~350 need a + service this stack has not got (the GNUnet mailbox, donau statements, the + Taler directory). +* The app's *sending* side of the mailbox (`sendTalerUriMailboxMessage`) looked + dead and is not — see iteration 10. It hangs off a developer-mode-only button + labelled "Contacts" on a peer-push QR screen, which is why no scenario had + found it. +* The measurement itself was losing data: coverage accumulates in the app + process, so every scenario that wiped the app mid-run threw away what it had + exercised — `WalletInitErrorScreen` read 0 % although `db_corruption` + renders it, word for word. `fresh_start` now dumps first. + +### A signed address found a real defect + +Signing a `payto://cyclos/…` account — done to reach the last transfer screen +— broke the **deposit** form in the next round: + +``` +E taler-wallet: Error getDepositWireTypes TalerErrorInfo(code=NONE, hint=, + message=kotlinx.serialization.SerializationException: + net.taler.wallet.deposit.WireType does not contain element with name 'cyclos') +``` + +One unrecognised wire method makes the whole reply undecodable, so the +add-account form sits on its spinner for ever with no message. `WireType` has +an `Unknown` member for exactly this case and it can never fire, because the +property that decodes into it has no default value and `coerceInputValues` +only coerces to a declared default. Two more enums have the same shape +(`WithdrawalOperationStatusFlag`, `ExchangeTosStatus`). + +The Cyclos address is therefore opt-in: leaving it signed blocks every deposit +scenario. `findings/unknown-wire-method-hangs-the-deposit-form.md` has the +one-line reproduction. + +### Random exploration, now that it runs in a round + +48 finding lines on its first in-round run, and **19 of them were about +Chrome**: a tap had opened a browser (a KYC link, "Open in banking app") and a +random walk has no reason to come back, so the oracles spent the run reading +Chrome's search suggestions ("undefined behavior", "undefined label") and +tapping its settings. The screen oracles now only apply to the app's own +screens, `silent_failure` likewise, and the explorer notices it has left and +relaunches. + +### Three more defects + +* **`purge-destroys-coins-and-history-without-saying-so.md`** — "Force + deletion (purge)" destroyed €9.87, the payment service and every transaction + made with it, leaving the first-run welcome screen. The dialog is a title, a + checkbox and two buttons, with no body text at all. +* **`suspended-looks-like-completed-in-the-list.md`** — the transaction list + has no branch for `Suspended`, so a suspended withdrawal's row reads + "Waiting for confirmation" — the opposite of what is happening. +* **`unknown-wire-method-hangs-the-deposit-form.md`**, above. + +And `failTransaction` is now pinned down rather than guessed at: wallet-core +offers "Abandon" only for deposits that are aborting, suspended-aborting or +waiting on aggregate KYC (`deposits.ts:955-1000`), none of which this stack +produces, because the aggregator finalises a deposit at once. A withdrawal +never offers it; an outgoing peer payment offers Retry/Abort/Suspend while +live and Resume/Abort once suspended. + +## Iteration 9 — the two services the stack was missing + +`taler-unified-setup.sh` brings up the exchange, merchant, bank, donau and +auditor. The wallet has screens for two more services, and both are now +deployed beside the stack (`backend/services/README.md`): the **Taler +mailbox** (`git://git.taler.net/taler-mailbox`, port 11000) and the **Taler +directory** (`git://git.taler.net/taldir`, port 11001), each Go, each with its +own Postgres database, both outliving a stack restart. + +`sync` was deliberately *not* deployed: the Android wallet has no backup or +sync feature — no screens, and no backup operation in +`coverage/app-operations.txt` — so there would be nothing to drive. + +### The mailbox pays off directly + +Its URL is the one service address the app lets the user type in, so no DNS or +TLS work was needed. The wallet registers itself on first use and shows its own +address: + +``` +http://localhost:11000/V8K0FT9X8DP44T4SW7VK40XVNJPGTMNFQB24GC34DFP7VNNBG70… +``` + +`mailbox_roundtrip` does the whole thing: configure the URL, let the wallet +register, have the **CLI wallet** encrypt a `taler://pay-push` URI for that +address and post it, refresh, read and delete. The sender has to be another +wallet: the app's own `sendTalerUriMailboxMessage` has no caller in the UI, and +a hand-made POST cannot stand in for it, because the app fetches a message it +cannot decrypt, deletes it from the server and says nothing — the right +instinct for a public drop box, and the reason the first two attempts showed +"No messages yet.". + +Three facts that cost an hour each are in `backend/services/README.md`: +wallet-core resolves `localhost` to `::1` while both services bind +`127.0.0.1`; every `GetDuration`/`GetAmount` in the mailbox server errors out +when its key is absent, default or not; and `taldir-dbinit` reads +`[taldir-pq]` while `taldir-server` reads `[directory-pq]`. + +### The directory proves a point instead + +Deployed, with a validator script that records each challenge where the driver +can read it — the simulator's stand-in for a validation email — the three +operations the app can never reach round-trip through wallet-core on the first +attempt: + +``` +registerAlias -> {} (202, challenge recorded) +completeRegisterAlias -> {} +lookupAlias -> {"targetUri": "http://127.0.0.1:11000/SIMADDRESS"} +``` + +So the feature is finished and the protocol is fine; the app is the only thing +that cannot be pointed at a directory. That is now in +`alias-registration-hardcodes-the-directory.md` as evidence rather than +conjecture. + +Getting there needed one character changed in the service: +`taldir-protocol-version-mismatch.md` — its `/config` hard-codes protocol +`0:0:0`, wallet-core's client declares `1:0:0` and refuses anything +incompatible, and `taldir.ts` replaces the precise reason with "could not read +the configuration of the directory service". + +### Answering for a hard-coded name, without touching the app + +`simulator/tls/` is a TLS front end that routes by `Host` and serves a +certificate for `taldir.gnunet.org` and `mailbox.gnunet.org` from the +simulator's own CA; `emu/tls-names.sh` roots one emulator, bind-mounts a hosts +entry over `/system/etc/hosts` and forwards the device's port 443 to the front +end. The CA is trusted because the `sim` build type — the simulator's own, +never published — bundles it as an extra trust anchor. No URL the app uses +changes, so `alias_registration_real` drives the shipped code path: register, +read the challenge from the validator's log, complete, look up. + +Installing the CA into the *device's* store was tried first and abandoned after +two measurements, both written up in `tls/README.md`: a mount made from `adbd` +is invisible to app processes (APEX paths have their own mount namespace, so it +has to be made under `nsenter --mount=/proc/1/ns/mnt`), there are two system +stores and the app reads the one that is not the APEX — and the framework +restart needed to make zygote see either leaves the network at +`PARTIAL_CONNECTIVITY`, where the wallet refuses everything with "This action +requires internet connection". A trust anchor in a test-only build type costs +none of that. + +### Two more harness defects, both of which hid behaviour + +* **Clearing a pre-filled field needs the caret at the end.** Tapping a + Compose field puts it in the middle and `KEYCODE_MOVE_END` does not move it, + so deleting backwards left the tail: `https://mailbox.gnunet.org` became + `http://localhost:11000unet.org`. That mistake is how the mailbox screen was + caught printing a QuickJS stack trace to the user + (`release-error-screen-explains-nothing.md`). +* The **silent-failure oracle** was reporting taps on plain text — "Pending:", + a timestamp, a section header — as findings: 24 lines in round 13. It now + requires the tapped label to resolve to something clickable. + +The exploration fixes from iteration 8 held: round 13's random walks produced +**no findings about Chrome at all**, where round 12 produced 19, and +`return_to_app` fired six to ten times per worker. + +## Iteration 10 — the app reaches the directory, and a crash nobody had to look for + +### The shipped code path, against a real directory + +Iteration 9 proved the directory's three operations work by calling wallet-core +directly. This time the **app** did it, with no URL changed: the emulator +resolves `taldir.gnunet.org` to a TLS front end, and the `sim` build type — the +simulator's own, never published — carries that front end's CA as an extra +trust anchor. The proxy log is the witness: + +``` +POST taldir.gnunet.org/register/email <- the "Register Alias" button +POST taldir.gnunet.org/FAVWP84VPPY4… <- the challenge, typed in +GET taldir.gnunet.org/FAVWP84VPPY4… <- "Lookup with Taldir" +``` + +and the screens followed: `Challenge Solution` → `Registration successful!` → +an `Add Contact` form filled in with the alias and the mailbox address behind +it. **No findings.** The feature works; the hard-coded URL is the entire +defect, which is now written into +`alias-registration-hardcodes-the-directory.md` with the evidence. + +Two blind alleys were worth the time it took to rule them out, both now in +`tls/README.md`: a trust store mounted from `adbd` is invisible to app +processes (APEX paths have their own mount namespace), and there are *two* +system stores of which the app reads the one that is not the APEX. The +framework restart needed to make either visible leaves the network at +`PARTIAL_CONNECTIVITY`, where the wallet refuses everything with "This action +requires internet connection" — which looks exactly like a wallet bug and was +briefly mistaken for one. + +### Changing the language locks the wallet out of its own database + +Found by accident, setting up a translation test: +`config-change-locks-the-wallet-out-of-its-database.md`. Changing the app's +language, the system font size or the display size while the wallet is open +lands it on the **Initialization error** screen, under + +``` +code 7001 "could not acquire exclusive ownership of the wallet database; + another wallet process may still be using it" +``` + +The screen replaces the whole app and says "Please retry" while offering only +*Export logs* and *Export database*; the only way back is to kill the app. Two +of the three triggers are accessibility settings. + +The cause is two lines of lifecycle that disagree. `onDestroy` deliberately +keeps wallet-core alive across a configuration change — + +```kotlin +// wallet-core belongs to the retained MainViewModel, not to this activity +if (!isChangingConfigurations) model.stopWallet() +``` + +— while `onCreate` calls `model.startWallet()` unconditionally, which sends a +second `init`. The pid is unchanged across the whole thing (measured), so the +error's "another wallet process" is this very process. Dark mode and rotation +are safe only because `uiMode` and `orientation` are already in the activity's +`configChanges`. + +This is the first defect in the campaign that a user can hit by changing a +system setting, and the first one found while building a test for something +else entirely. + +### Two whole features cannot be translated + +`contacts-and-mailbox-cannot-be-translated.md`: 34 user-visible strings in +`contacts/`, `mailbox/`, the two settings entries that open them, the +transaction list's selection counter and a couple of error messages are string +literals in the Compose sources, not entries in `strings.xml`. The wallet ships +19 translations; none of them can reach these. Neither defence in the repo can +see it — `./check-translations.py` reads only `values*/strings.xml`, and +lint's `HardcodedText` check only looks at layout XML, of which Compose has +none. `AliasRegistrationScreen.kt`, in the same package, uses `stringResource` +for all of its labels, so this is drift rather than convention. + +The reproducer's own navigation is the demonstration: it needs +`Settings|Einstellungen` to get around a German wallet, and plain English for +`Contacts`, `Mailbox` and everything behind them. + +### Three operations that no scenario could reach + +`registerAlias` and `lookupAlias` now run (above). Two more needed the right +state rather than a service: + +* **`failTransaction`** is the "Abandon" button, and wallet-core offers it only + while an abort is *in progress* — never for a withdrawal waiting on the bank, + which is what `withdraw_abandon` kept recording. An abort against a healthy + exchange finishes too fast to catch, so `abandon_aborting_deposit` takes the + wallet offline first. +* **`getBankAccountById`** is only called when the add-account screen is opened + with an existing id, and nothing is labelled "Edit": the account *row* is the + button. `bank_accounts` now taps it, checks the form came back filled, and + saves a change. + +`sendTalerUriMailboxMessage` is reachable too, by a path worth writing down +because it is easy to conclude it is not: a peer-push transaction's QR screen +shows a *forward* button **in developer mode only**, and only for a +`pay-push`/`pay-pull` URI +(`compose/QrCodeUriComposable.kt:183`); it navigates to the contacts screen +with the URI, and confirming a contact there calls +`mailboxManager.sendMessage` (`contacts/ContactScreen.kt:203`). The button is +labelled "Contacts", which is why it does not read like a send button. +`forward_payment_to_contact` now drives it. + +### Five scenarios were passing without doing anything + +The worst defect of this iteration was in the harness, and it had been hiding +behaviour for thirteen rounds. Five scenarios drove their flow, *noted* what +they saw, and reported "ok" whether or not anything happened: + +| Scenario | What it never did | Why | +| --- | --- | --- | +| `deposit` | deposited | the payto link it used is one the wallet refuses (`payto-link-only-accepts-iban.md`) | +| `deposit_bad_payto` | deposited | the submit button on that screen is **Send**, not Deposit, so the tap went nowhere | +| `peer_push_receive` | received | "Receive payment" is both the heading and the button, and the heading came first | +| `bank_accounts` | added an account | the unmarked required "Note" field left the submit disabled (`add-account-note-is-required-but-unmarked.md`) | +| `deposit_methods` | added any of its three | the same, plus the Bitcoin tab's fields filled in the wrong order | + +Three of the five were hiding a genuine app defect behind the green row. Two +were purely my own mistakes. Either way the lesson is the same one iteration 7 +already wrote down and did not apply widely enough: **a scenario that only +notes what it sees cannot fail.** + +`peer_push_receive` is the sharpest case, because it *had* a check: + +```python +if home.find(r"(?i)0\.00|Welcome") is not None and home.find(r"€") is None: + c.note("WARNING: the received payment did not reach the balance") +``` + +It asks for a screen with no `€` anywhere — which a zero balance, rendered +"€0.00", never is. The condition could not fire, and the note it guarded was a +warning rather than a failure in any case. It now polls the balance and raises. + +Each of the five now asserts: a bank balance that must increase, a wallet +balance that must become non-zero, an account that must appear in the list. + +### The measurement was quietly broken, twice + +* **One truncated `.ec` file lost a whole campaign's coverage.** A dump whose + app was killed mid-write leaves a partial file, and jacoco's `merge` aborts + on the first one it cannot read — taking the other 1099 files' data with it. + `coverage/validate_ec.py` now walks each file's block structure and keeps + only the complete ones (it found exactly the one bad file), and + `driver/coverage.py` refuses to write a dump that is not execution data. +* **`merge` appends to an existing `--destfile`.** A first attempt to merge in + batches reused two scratch files and so doubled the data every other batch: + 4 MB of execution data became 11 GB before it was noticed. Each destination + is now removed first. +* **Rebuilding the APK starts a new coverage baseline.** Jacoco matches data to + classes by a checksum of the class file, and adding the two `src/sim/res` + files shifted the inlined `R` constants, so data from the old APK is dropped + with "Execution data for class … does not match". Reporting rounds 1–13 + against the new build reads 49.7 % where the same data read 69.7 % against + the build that produced it. The figure to compare from here on is the one + measured over rounds 14 and later; the caveat is recorded in `report.sh` so + the next person does not chase it. + +## Iteration 11 — what the remaining 30 % actually is + +**Coverage: 69.8 % line** (12041/17247) on the new APK, measured twice over two +independent rounds with the same figure, so the measurement is now stable +enough that a real gain is distinguishable from noise. + +The more useful number is what is left. Of the 5206 missed lines, **1404 are +inside `@Preview` bodies** — functions that exist for Android Studio's preview +pane, which nothing calls and which no instrumented run can ever execute: + +``` +overall lines: 12041/17247 (69.8%) + of the 5206 missed lines, 1404 are inside @Preview bodies and cannot run at all + reachable lines covered: 12041/15843 (76.0%); the highest this report can ever read is 91.9% +``` + +So the campaign has covered **76 % of the code that can run**, and 91.9 % is the +ceiling of the figure everyone quotes. `coverage/gaps.py` now says this on every +run, because a ranking that counts preview bodies points at work nobody can do: +`ScreenTransfer.kt` leads the "missed" table with 135 lines, and 106 of them are +its five previews. + +A further ~300 lines are unreachable for a second reason — they have no caller. +That list keeps growing as scenarios reach further: +`PromptAddContactScreen`, `GridMenu`, `DemandAttention`, +`SelectionModeTopAppBar`, `SelectExchangeDialogFragment` (the last +DialogFragment in the app, and the premise `withdraw_pick_exchange` was built +on), and `DonauStatementScreen` + `DonauStatementComposable`, which are dead +because the button that should open them is wired to a no-op +(`donation-statements-button-is-wired-to-nothing.md`). + +### What the de-vacuumed scenarios bought + +Round 16 ran with most of iteration 10's fixes and moved the headline by six +lines, which looks like nothing until the per-class diff is read: + +| | before | after | +| --- | --- | --- | +| `TransactionPeerPushCreditKt` | 0 % | 44.7 % | +| `PeerManager$confirmPeerPushCredit$1` | — | 100 % | +| `TransactionPeerPullDebit` | — | 78.3 % | +| `WithdrawalShowInfoKt` | — | 63.3 % | +| `peer` package, missed lines | 482 | 448 | +| `transactions` package, missed lines | 751 | 719 | + +`confirmPeerPushCredit` at 100 % is the proof that the peer payment is now +accepted rather than merely prompted, and `bank_accounts` reached the edit form +and saved a change — which is `getBankAccountById`, one of the operations no +scenario could reach before. + +139 lines moved the other way across 28 classes. Most is run-to-run variance, +but one was a real defect in the fix: `deposit_methods` reported "no Bitcoin +tab", because a successful submit closes the form and returns to the account +list, so the first case that worked left the later tabs with nothing to tap. +Each wire method now reopens the form. + +### Two features that had never been driven at all + +* **Tap-to-pay.** `MainActivity` has three external entry points -- a VIEW + intent, shared text, and `NfcAdapter.ACTION_NDEF_DISCOVERED` -- and the third + had never been used, although the sim build has shipped a `SEND_NDEF` hook + for exactly it since the harness was written (the URI travels in a Parcelable + `NdefMessage`, which `am start` cannot build). `nfc_tap_to_pay` now delivers + a real order over NDEF and requires it to be *paid*, then taps three hostile + tags. All four behave: the order is paid, and a plain website, a bare + `taler+http://pay/` and a non-existent order each produce their own error + (`Unsupported URI`, 7008, 21). + +* **Database import.** `settings_import` had been reaching the document picker + and tapping a label matching the file name -- which DocumentsUI also uses for + the thumbnail ("Preview the file <name>") -- so nothing was selected, + `importDb` never ran, and the scenario noted "after importing" while still + sitting in the picker. Fixed, the export/import round trip **works**: a wiped + wallet comes back with its €9.87 and its transaction. + +### Nearly a serious finding, and why it was not + +The import work is worth recording as a discipline lesson, because for about +twenty minutes the evidence looked like the worst defect of the campaign: a +funded wallet exported 526 KB, was wiped, imported that file, and stayed +empty -- across a relaunch -- while `importDb` returned `result: {}`. + +It was not a defect. Three separate mistakes in the driving produced it: + +| assumed | actually | +| --- | --- | +| `adb shell rm` clears old exports from the picker | the shell sees its own scoped view; the picker lists MediaStore, which keeps everything the app wrote | +| the picker lists oldest first, so `rows[-1]` is the newest | it lists **newest** first -- `rows[-1]` was the oldest export, taken from an empty wallet | +| `Screen.tap_target` selects the row | it resolves to a neighbour that dismisses the picker to the launcher, so no import happened at all | + +The second one is the trap: the app faithfully imported an export of an empty +wallet, which is indistinguishable from an import that lost everything. The +check that caught it was reading the `importDb` *request* -- `"tables": +{"bank_accounts": [], …}` -- rather than trusting the screen. Every step of +that probe is now asserted separately (which file, which activity, which call, +which reply), and `pick_file_in_picker` carries all three findings in its +docstring. + +### The operation census was lying, in both directions + +`coverage/operations.py` counts wallet-core operations from the logcats the +episodes save, and it read **66 of 71** exercised with five never reached. Two +of those five were wrong: + +* `updateExchangeEntry` fires **forty times** when the exchange menu's "Reload + information" is tapped -- which `exchange_reload_global` has been tapping + every round. It read as unexercised because `episode.py` kept only the last + 2 MB of logcat, and in a chatty scenario that cuts the start. The wallet's + own lines (`taler-wallet`, `BackendManager`, `SimHooks`) are now kept in + full to 4 MB, with the rest of the system log keeping its tail. +* `clearDb` was genuinely unreached, because `settings_reset_cancel` only ever + cancelled. `settings_reset_confirmed` now carries the dialog through -- and + found that both of the app's `MaterialAlertDialogBuilder` dialogs put the + destructive action in the *negative* slot, which Material draws on the left + where Cancel belongs + (`reset-dialog-puts-the-wipe-where-cancel-belongs.md`). + +Of the three that remain, two are blocked by defects already written up +(`getDonauStatements` by the no-op button, `sendTalerUriMailboxMessage` by the +`taler://`-only prefix test), and one is out of reach of this environment +altogether: `cancelProgressToken` has a single caller, +`cancelDatabaseMigration`, and a migration is only offered to a wallet whose +database is still the IndexedDB emulation. `MainViewModel` hard-codes +`useNativeDb = true` so a new install never has one, and `taler-wallet-cli` +writes the native schema as well -- nothing here can manufacture the legacy +format. That also keeps the migration UI in `MainViewModel` and +`MainActivity` unreachable, which is a fair slice of their missed lines. + +### Measurement notes worth keeping + +* **Two jobs on one emulator look exactly like app defects.** Twice a scenario + landed on the welcome screen and a probe timed out inside `flows.withdraw`, + and both times the cause was a second run driving the same device. One job + per worker. +* `Wallet.dev_mode_on()` reads the marker on the *current* screen, so it + returns False on the home screen whatever the setting is. It is only + meaningful inside Settings. +* The transaction list is **on the main screen** under "Recent transactions", + which is what `transaction_rows` keys on; the "All" chip navigates to a + different screen where that header does not exist and every row goes missing. + +## Iteration 12 — the last few operations, and three features nothing had driven + +**Coverage: 70.0 % line** (12075/17247) after round 17, **76.2 % of the +reachable lines**. Each of the iteration's fixes shows up on its own in the +per-class diff, which is the useful way to read a +34-line round: + +| | | +| --- | --- | +| `TransactionManager$failTransaction$1` | **100 %** — "Abandon" finally reachable | +| `SettingsManager$importDb$1` | 60 % — the database import runs | +| `SettingsManager$clearDb$1` | the wallet reset, confirmed rather than cancelled | +| `SimHooks` | 81.6 % — the NDEF hook, used for the first time | +| `QrCodeUriComposableKt` | 98.4 % | +| `HandleUriScreenKt$getTalerAction$2` | the hostile-tag URIs | +| `MainActivity` | 76.0 % | + +**Wallet-core operations: 69 of 71.** The three that were outstanding are +settled: `clearDb` and `failTransaction` are exercised, and +`updateExchangeEntry` turned out to have been exercised all along (see below). +What remains is `getDonauStatements` and `sendTalerUriMailboxMessage`, both +blocked by defects already written up, and `cancelProgressToken`, which no +wallet in this environment can reach. + +### Where the Abandon button actually lives + +`failTransaction` took three attempts because the state it belongs to is +narrow. A deposit against a reachable exchange finishes in under four seconds, +so the network has to go away *between entering the amount and submitting*; +and `abortTransaction`'s success handler navigates back, so the transaction has +to be reopened afterwards to see what it now offers: + +``` +pending -> Retry, Suspend, Abort +aborting -> Retry, Abandon, Suspend <- the only state that offers it +abandoned -> "This transaction has failed or been abandoned" +``` + +The money is really gone afterwards (€9.87 -> €8.87), which is what the +dialog promises. That raised a question rather than a finding, recorded under +`aborted-credit-shows-the-whole-amount-as-fee.md`: the amount is honest, but +the exchange never completed the deposit, so the €0.02 "Fee" row is doubtful. + +### Three features the stack could not present + +Twice more the "uncovered" code turned out to be unreachable by configuration +rather than untested, which is the same lesson as the wire fees and the terms +in earlier iterations: + +* **The terms language selector** only renders when the exchange offers more + than one language, and the shipped `exchange-tos-v0` has an English source + only. `exchange-tos-tops-v0` ships de and en, so `stack.sh` now renders both + (`SIM_TERMS_ID`, `SIM_TERMS_LANGS`) and `exchange_tos` picks the other + language and checks the body text changes. +* **`ExchangeShoppingScreen`** needs a *scope* carrying two shopping URLs; one + URL opens a browser instead. Both exchanges now advertise one, which is why + the card appears at all, and what is still missing is written in the + scenario. +* **`DummyTransaction`** is what `TransactionSerializer` falls back to when a + transaction will not deserialize, so it needed a transaction the app cannot + parse: `transaction_states_rendered` now injects an unknown type and a + withdrawal missing its amounts. + +### A warning that was not a defect + +`denom_loss_transaction` had been reporting "WARNING: the loss event appears in +no transaction list" every round. It is not a defect: the dev experiment +inserts the event for **TESTKUDOS** -- the database row's own `currency` column +says so -- and a wallet holding EUR has no scope to show it under. The scenario +now says that, with the currency it found. Rendering `TransactionDenomLoss` +needs a loss in a currency the wallet holds, which means a denomination +expiring under it. + +### Still to do, in order + +1. Keep rounds running and triage what they surface. +2. `alias_registration_real` against the TLS front end, and the coverage the + contacts package then reaches. +3. The revocation phase, with the wallet asked to reload the exchange: a + revoked denomination left no trace in the first minute. +3. A destructive phase for `revoke_denomination`: an exchange that withdraws a + denomination under a wallet holding its coins, which is the only way to + reach the recoup path. +4. The remaining untouched screens are mostly things no service in this stack + can produce: Cyclos transfers, the GNUnet mailbox, and the database + migration prompt (which needs a wallet database in the old IndexedDB + format). + +## The camera path, taken apart without a camera + +A report arrived that scanning works on Android 15 but not on Android 14. The +campaign cannot answer that directly: the emulator's virtual scene camera +cannot be aimed at a code, so the live-camera route behind `qrsuite.py +--camera` has never run unattended, and the QR suite's default route decodes a +*bitmap* through the gallery — a different decoder that never touches the +camera arithmetic. Pointing the gallery route at API 34 and API 36 gave 10 of +10 on both with identical screens, which says nothing about the report and +everything about why it had to be approached another way. + +So the pipeline was rebuilt instead. A camera frame is a luminance plane plus +`rowStride` and `pixelStride`, and nothing in `QrCameraAnalyzer` after that +point is Android-specific — the conversion, the rotation and zxing are all +plain JVM code. `findings/repro_qr_plane_strides.java` builds a frame with a +real QR code in it, lays it out the way hardware is free to, and runs the +app's own arithmetic over it. That turned a code-reading suspicion into +measurements, and it surfaced more than the suspicion: + +* **Padding kills it outright.** Row padding of 16, 32, 64 or 128 bytes: + not one frame decodes. The same frame decodes the moment the stride is + honoured. Interleaved samples likewise. +* **A padded frame held upside down throws.** `rotateNV21`'s 180° branch walks + the chroma tail out to the padded `data.size` and runs off the end of an + array it sized from `width * height`. Because `proxy.close()` sits in the + *decode* `try`'s `finally`, that throw leaks the frame, and with + `STRATEGY_KEEP_ONLY_LATEST` CameraX then never delivers another one — the + scanner is dead for the life of the screen while the preview keeps running. + Nothing in the wallet's manifest locks the orientation, so it is reachable. +* **The rotation was never needed.** zxing finds a QR code by its finder + patterns and takes the orientation from them: all four orientations decode + untouched. The rotation that caused the crash bought nothing, which makes + deleting it the fix rather than repairing it. +* **And the obvious repair would have been worse.** The tempting replacement, + `PlanarYUVLuminanceSource.rotateCounterClockwise()`, throws + `UnsupportedOperationException` — zxing does not implement rotation for that + source, in 3.5.3 or 3.5.4. + +That last one was worth checking because the **merchant terminal already does +it.** `ConfigFragment` keeps its own copy of the pipeline, with the same +stride-blind conversion plus a `rotateCounterClockwise()` call sitting outside +the `try`. On a device whose back camera sensor is oriented 0° — common on +tablets, which is what a terminal usually is — the first frame throws, the +proxy leaks, and scanning the configuration QR code, the normal way to +provision a terminal, has never worked. Two findings, two patches, both +verified to compile and lint: `qr-camera-ignores-the-plane-strides` (now with +nine unit tests, five of which encode a real code into a synthetic frame) and +`pos-config-scanner-asks-for-a-rotation-zxing-refuses`. + +What this still does not establish is that either is *the* reported bug. The +two numbers that would settle it — `rowStride` and `width`, on the two +platforms — can only be read on the devices in the report, so both findings end +with the attended tests a developer should run, ordered to separate causes +rather than to confirm the guess. + +### The version matrix, and what API 24 showed + +`driver/matrix.py` runs the platform-sensitive scenarios on one emulator per +API level, the levels being the ones where the app's own code forks (24, 26, +28, 29, 30, 31, 33, 34, 36, each justified in `API_LEVELS` by the branch that +needs it). Its first run never got past the first level: the API 24 emulator +spent 1200 seconds booting and never finished, with its log full of + +``` +ERROR | Unsupported camera format for virtual scene views 825382478 +``` + +825382478 is the NV21 fourcc, so the virtual scene camera — configured so that +a QR code *can* be shown to the device — is asking the image's camera service +for a format it will not produce. That is **not** established as the cause of +the timeout: the API 26 emulator logs the same error eight times and boots +fine. So the error is at most a suspect. `emu.sh` now picks the camera backend +from the image's API level anyway, virtualscene from 26 up and the old emulated +camera below, because no scenario in the matrix needs to decode from it and it +removes one difference between a level that boots and one that does not. The +API 24 level is queued for a retry on that configuration, which is what will +actually say whether the camera was involved. + +## Iteration 19 — a number that was counting the wrong thing + +101 scenarios, 0 driver errors, and the round reported **7 serious findings**, +up from 5. Every one turned out to be a kind already written up: +`fee-on-dead-transaction` (`aborted-credit-shows-the-whole-amount-as-fee`), +`mixed-amount-notation` (`amounts-without-currency-specification`), +`glued-currency` (`word-currency-symbol-glued-to-amount`), and a refresh +failing with 7029 `WALLET_REFRESH_GROUP_INCOMPLETE` plus its retry +(`refresh-fails-on-mixed-age-denominations`, which is wallet-core's). + +The two remaining ones were the harness's fault, and not in an interesting way: + +``` + *** [unfinished-transaction] withdrawal_groups WQWFW8YK… unfinished after 255s (status 16777219) + *** [unfinished-transaction] withdrawal_groups WQWFW8YK… unfinished after 260s (status 16777219) +``` + +16777219 is `0x0100_0003`, `WithdrawalGroupStatus.PendingQueryingStatus` — +"querying reserve status with the exchange". The scenarios that produced it, +`withdraw_account_details` and `withdraw_account_tabs`, create a **manual** +withdrawal and deliberately never wire the money: their subject is the transfer +instructions screen. A withdrawal waiting for a transfer that is never made +stays pending by design, which is exactly why `unfinished-transaction` is +listed in `oracles.INFORMATIONAL`. + +The round tally did not use that list. `oracles.Session.serious` filters on +`INFORMATIONAL`, while the suite's own summary line filtered on +`kind != "error-screen"` — two rules for one word, and the narrower one made +every deliberately-pending withdrawal a serious finding, twice a round, to be +re-triaged each time. The suite now uses `oracles.INFORMATIONAL` as well. + +Worth stating plainly: this inflated every "serious findings" count this +campaign has reported for scenarios that leave a manual withdrawal pending. +Nothing was *missed* — `stuck-operation` and `background-error`, the kinds that +catch a genuine stall, are untouched — but the number was larger than the +defects behind it. + +### A patched build, on a device + +`PATCHES.md` had to admit that none of the seventeen patches had run anywhere +but a compiler. So the whole set was built into a `sim` APK +(`:wallet:assembleFdroidSim` on a tree with every `.diff` applied) and run on +worker 4 against the same stack, with `SIM_COVERAGE_DIR` pointing somewhere +else — JaCoCo keys classes by a hash of their bytecode, so dumps from two +builds cannot be merged into one report. + +That pass has a second purpose. Two wallet-core operations had no caller the +simulator could reach *because of* defects that are now patched: +`getDonauStatements` sits behind the donation-statements button that was wired +to nothing, and `sendTalerUriMailboxMessage` behind a forward button that only +recognised one URI scheme. On the patched build both are reachable, which is +also the only end-to-end check those two patches can get. + +### The last operation, and the database that unlocks it + +`cancelProgressToken` had been written off as unreachable: it is only called +when a database migration is cancelled, a migration only exists for a wallet +database in the legacy IndexedDB-emulation format, and the note in iteration 12 +said `taler-wallet-cli` writes the native schema. That note was wrong — or +rather, incomplete. wallet-core picks its backend from what the file already +contains, and for *empty* storage the node host reads an environment variable: + +```bash +TALER_WALLET_DB_BACKEND=indexeddb taler-wallet-cli \ + --wallet-db legacy.db api getVersion '{}' +``` + +produces a 53 KB SQLite file holding `object_data`, `object_stores`, `indexes` +and 29 records — the legacy format, confirmed by its tables. + +Planting that file made the wallet **refuse to start**, with the init error +screen. The reason is not a defect, and it is the useful part of this: + +``` +"hint": "unexpected exception (message: requested version 34, existing version is 36)" +VersionError: requested version 34, existing version is 36 +``` + +The checkout beside this one is wallet-core 1.6.48, whose IndexedDB schema is +version 36; the qtart the app embeds is 1.6.42 and asks for 34. IndexedDB does +not open a database newer than the version requested, and refusing is right. +A fixture therefore has to come from *the app's own core*, which is easy enough +to arrange: build the app with `useNativeDb = false` in `MainViewModel`, launch +it once, and copy `files/talerwalletdb.sqlite3` back out. That file carries +`taler-wallet-main-v10` at version 34 — and the fixture has to be remade +whenever the bundled qtart moves its schema version, which the scenario's +docstring now says. + +With that fixture, `db_migration_prompt` works end to end: + +``` +- database now: -rw------- 1 u0_a216 u0_a216 57344 files/talerwalletdb.sqlite3 +- after relaunch: ['Upgrade wallet database?', 'The wallet can use a faster + database. …', 'Migrate now', 'Later'] +- after Later: [settings] +- caught the migration in progress: False +- the migration row is still offered: False +``` + +So the prompt, the "Later" deferral, `migrateDatabase` and the switch to the +native backend are all covered now, and the migration dialog in `MainActivity` +— the last of the "screens nothing had driven" — is reached. + +`cancelProgressToken` is still not. The `Cancel` that calls it lives on the +progress dialog, and the migration finishes faster than the harness can tap: +driving the `useNativeDb = false` build through a scenario first gave a 1.7 MB +fixture with 512 records, the migration emitted 102 progress notifications, and +even tapping blind at the button's coordinates — no screen dump, since a dump +alone costs about a second — never landed while the dialog was up. That leaves +**70 of 71 wallet-core operations exercised**, with the last one behind a race +rather than behind a defect. A fixture of some thousands of records would +probably win it; the big one is passed in with `SIM_LEGACY_DB` rather than +carried in the repository. + +One harness defect fell out of this. Both database oracles query the native +schema, so against a wallet still on the legacy backend they reported +`oracle-error: no such table: operation_retries` — a serious finding for a +state the wallet can legitimately be in. `dbprobe.has_native_schema` now +answers that question and both oracles return nothing instead. + +### Coverage after rounds 18 and 19 + +The report had not been regenerated since the morning, and the stale one was +misleading in a way worth recording: run on the emulator host it printed 49.7 %, +because `report.sh` resolves the checkout two directories above itself, which is +the repository on a workstation and `/opt` on the emulator host — so it merged +2400 dumps and then failed to find any class files. It also hard-coded the +workstation's JDK path, which is why it died with "no such file or directory" +after half an hour of validation. Both are fixed: Java comes from `JAVA_HOME` +when that points at a real JVM and from `PATH` otherwise, and the merge can be +done on the host while the report step runs where the build output is. + +Merged over every dump from rounds 1–19: + +``` +instruction 109639/150580 72.8% +branch 3095/4923 62.9% +line 12585/17247 73.0% +method 2988/4530 66.0% +class 743/942 78.9% +``` + +73.0 % of lines, up from 70.0 %, and **79.4 % of the lines that can run at all** +(1403 of the 4662 missed lines are `@Preview` bodies; the ceiling is 91.9 %). + +Ranked by what is left: + +``` + 636 missed 69.0% ~.transactions + 526 missed 64.8% ~.payment + 432 missed 70.9% ~.peer + 369 missed 73.7% ~.compose + 289 missed 54.3% ~.transfer + 256 missed 38.2% ~.donau +``` + +`~.donau` at 38.2 % is the lowest of any package, and most of what is missing +there is behind the statements button that is wired to nothing. `~.transfer` at +54.3 % is largely the Cyclos path, which no service in this stack can present. +And checking the "untouched classes" list before writing scenarios for it turned +up `ui-with-no-callers.md`: 189 lines of UI that nothing in the app refers to, +including a second, unreachable implementation of the add-contact screen. + +### Still to do, as of round 20 + +Replacing the list at the end of iteration 12, two items of which are done: + +* **`alias_registration_real` — done.** It has been passing since the TLS front + end went in, end to end: register, challenge, complete, look up. + + ``` + - the form: ['email', 'Alias Type', 'Alias', '12', 'Duration (months)', 'Register Alias'] + - after registering (challenge: WJY4TVQQ2D6TCJVBBXBN9R5974): ['Challenge Solution', 'OK'] + - after completing: ['Registration successful!', 'OK'] + - after the lookup: ['Add Contact', 'Looked up', 'Petname', 'sim-w1-…@example.com', 'Alias', …] + ``` + +* **The database migration prompt — done**, see above, with the fixture caveat. + +* **The revocation phase and fault injection — queued as one job.** + `run/phases.sh` waits for the round the loop is in to finish, waits for the + version matrix to clear worker 6, then restarts the stack and runs + `revoke_denomination` alone (it is stack-wide and lasts until the next + restart), restarts it again from `sim-twister.conf` and runs the three + twister scenarios, and finally restores the ordinary stack and puts the loop + back at round 21. + + The twister scenarios are worth saying something about: they have been in the + suite for several rounds and **have been skipping every time**, because + `twister_or_skip` looks for a `twister` entry in the stack's `env.json` and + an ordinary stack has none. They were costing 30–60 seconds a round to + report "the stack is not running twister; nothing to inject". That is the + right behaviour — faults were to be the last avenue, after everything else — + but it does mean no fault has been injected yet, and the phase above is the + first time one will be. + +* **What is left uncovered is now mostly explained rather than pending.** Three + findings written this round account for a good part of it: + `ui-with-no-callers` (189 lines nothing refers to), + `refresh-transactions-are-never-listed` (a whole detail screen for a + transaction type the app never asks wallet-core for), and + `multi-qr-transfer-screen-cannot-be-reached` (a button gated on two QR codes + where there can only ever be one). Cyclos transfers and the GNUnet mailbox + remain genuinely absent from this stack, and `ExchangeShoppingScreen` still + needs an exchange advertising two shopping URLs in one scope. + +### Round 20 — three scenarios written from the gap list + +Reading the fresh report class by class rather than package by package paid off +better than designing scenarios from the feature list did. + +* **The overflow menu on a transaction detail screen.** It only exists when the + transaction has a payto target, and its single item is the only caller of + `copyToClipBoard` there. `transaction_details_by_type` now opens it on every + detail screen it visits. + +* **`manual_withdraw_transfer` stopped swallowing its own failures.** It tried + four buttons -- "Wire transfer QR codes", "EPC QR", "Swiss QR bill", "Open in + banking app" -- inside a `try: … except TimeoutError: continue`, so a button + that had stopped working was indistinguishable from one that is not offered. + It now says which, and the answer turned out to be the finding + `multi-qr-transfer-screen-cannot-be-reached`. + +* **`subscription_issued_and_viewed`, a new scenario.** The uncovered half of + `TokenListScreen` is the pass (subscription) list, and nothing was buying a + subscription: `payment_needs_token` creates a subscription family and + *demands* the token, so the wallet never holds one. An order with a + subscription token as its **output** does: + + ``` + - the merchant says the order was paid: True + - passes: ['Simulator discount', 'subscription tokens issued by the simulator', + 'Provided by Simulator Shop', 'Active', + 'Valid until October 18, 2027 at 2:43 PM', …] + ``` + + One trap worth recording: the first version asserted the pass was called + "Simulator pass", and it is called "Simulator discount". `create_token_family` + answers 409 when the slug already exists and leaves the existing name alone, + so the family that `payment_needs_token` created first keeps its name + whatever a later scenario asks for. The assertion is now on a row having a + validity, which is what actually says a pass is listed. + +* **`balances_two_exchanges` now goes on to the shopping screen.** Same shape + as the QR button: `MainScreen.kt:188` opens a browser when the scope has + exactly one shopping URL and only navigates to `ExchangeShoppingScreen` when + it has more, which needs both exchanges treated as global currency in one + scope. The scenario does the treating already; now it taps the card and says + which of the two happened. + +#### The shopping screen, and what it says about the global-currency defect + +`ExchangeShoppingScreen` (62 lines, untouched since the campaign began) is now +covered, and getting there answered a question the findings had left open. + +The card on the main screen only navigates to that screen when the scope +carries more than one shopping URL, which needs both services in one currency +scope — that is what "treat as global" is for. `balances_two_exchanges` was +already treating both as global and getting nowhere, and the reason is the +defect in `addglobalcurrencyexchange-null-masterpub.md`: the call sends +`masterPub`, which is null until the exchange's `/keys` has been fetched, and +`JSONObject.put` drops a null key, so wallet-core rejects the request. The +second service had just been added by URL and never contacted, so its key was +null every time. + +With the scenario accepting the second service's terms and tapping "Reload +information" first, it works: + +``` +- 8081: reloaded +- 8091: reloaded +- the shopping screen: ['Your payment service offers the following website(s) …', + 'http://localhost:8080/config?shop=one', + 'http://localhost:8080/config?shop=two'] +- 2 shopping URLs listed +``` + +Which sharpens the finding: "treat as global" is not broken, it is broken for +an exchange that has been added and not yet talked to — the state an exchange +is in immediately after being added by URL, and therefore the state a user is +most likely to try it in. + +Two detection mistakes worth recording, both mine, both of the same kind. The +first check for the screen looked for a node reading exactly "Where to pay", +but the title is "Where to pay with EUR" — which is also what the card on the +main screen says, so the title cannot distinguish the two screens at all. The +screen is now recognised by its own message ("offers the following +website(s)"). Before that, the note said the tap "left the app", which was +wrong: the activity was still the wallet's, and the screen text in the very +same note was the shopping screen's. A note that prints what it saw is worth +more than a note that reports a conclusion. + +#### The round tally counted work that was not the round's + +Round 20 reported "147 ok, 1 driver errors, 8 serious findings", and three of +those eight were things this session had done by hand on the spare emulator: +the error screen of a *patched* APK, the oracle error from the deliberately +too-new migration fixture, and the `history` run that built the big legacy +database. `campaign.py`'s `collect()` merged **every** `suite-w*-summary.json` +newer than the round's start, and a scenario run by hand writes one of those +into the same directory. + +It now filters by worker as well as by time — the round knows which emulators +it launched. Recomputed over workers 0–3 only, round 20 is: + +``` +205 scenarios, 205 ok, 9 findings, 5 serious + *** background-error refresh 7029 WALLET_REFRESH_GROUP_INCOMPLETE + *** stuck-operation the same refresh, retried 5 times + *** fee-on-dead-transaction + *** mixed-amount-notation + *** glued-currency +``` + +Five, all of kinds already written up, three of them already patched. That is +the third measurement bug this campaign has found in itself — after the +truncated logcat and the double-counting merge — and all three had the same +shape: a number that was easy to read and quietly measuring something else. + +### The version matrix: three levels clean, four never booted + +`matrix.py`'s first full pass over the nine API levels where the app's own code +branches gave: + +``` +API 24: ERROR boot timed out after 1200s +API 26: 12 scenarios, 12 ok +API 28: ERROR could not boot +API 29: 12 scenarios, 12 ok +API 30: ERROR could not boot +API 31: 12 scenarios, 12 ok +API 33: ERROR could not boot +``` + +The pattern is the finding: **every second level** failed. That is not how +platform incompatibility behaves; it is how a teardown that does not wait +behaves. `emu.sh kill` ran `adb emu kill`, which returns as soon as the +emulator's console accepts the request, and the matrix then immediately +created the next AVD **under the same name** — with the previous process still +holding its lock files. The level after a failure then found nothing running +and booted fine, which is what produced the alternation. + +`kill` now waits for the device to leave `adb devices`, then for the process on +that console port to exit, and clears any `*.lock` left in the AVD directory. +The four failed levels are queued for a retry behind the phase job +(`run/matrix-retry.sh`), which is also where it will become clear whether the +API 24 timeout was ever about the camera format at all. + +One data point in the fix's favour arrived immediately: API 34 passed 12/12, +and under the old alternation the level after a success was the one that +failed — but API 36, the first level whose predecessor was torn down with the +waiting `kill`, booted. One observation is not proof; the retry of the four +failed levels is the test. + +What the three levels that did run say: the twelve platform-sensitive +scenarios — the balances and history screens, manual QR entry, NFC tap to pay, +the settings walk, export and import, the config changes, the lock screen +without a credential, the accessibility audit, the lifecycle kill and the +database corruption — behave on API 26, 29 and 31 exactly as they do on 36. +**No version-specific defect has been found yet**, which is worth saying +plainly given that the whole matrix exists because of a report that scanning +works on one Android version and not another: the matrix cannot speak to that +report, because the camera path is the one thing it cannot drive. + +#### What the last big gap in the detail screen actually is + +`TransactionDetailScreenKt` is the single largest partially-covered class (164 +missed lines, 59 %), and reading it line by line leaves three things, none of +them a scenario anyone can write today: + +* **Its preview** (lines 638–657) — counted correctly as unreachable; checked, + because `gaps.py`'s preview accounting is what the "79.4 % of reachable + lines" figure rests on. `preview_lines()` does find them: 1831 preview lines + across 43 files, of which 1403 are lines the report also calls missed. The + same check cleared the `~.peer` package, whose 432 missed lines are mostly + the four previews in `OutgoingPushComposable.kt` (105 lines) — so no + scenario was worth writing there either. +* **The refresh branch** (320–329) — unreachable by design, see + `refresh-transactions-are-never-listed.md`. +* **The denomination-loss branch** (354–364, 497–531) — needs a loss event in a + currency the wallet holds, and it cannot have one here. + `dev-experiments.ts:243` hard-codes the injected event: + + ```ts + const newRg: WalletDenomLossEvent = { + amount: "TESTKUDOS:42", + currency: "TESTKUDOS", + exchangeBaseUrl: "https://exchange.test.taler.net/", + ``` + + No parameters, so the injected loss is always TESTKUDOS, and a EUR wallet has + no scope to show it under — which is what `denom_loss_transaction` has been + reporting all along. + + **Corrected the same evening:** the revocation phase makes a *EUR* loss + event, because revoking a denomination the wallet holds is a real loss in the + wallet's own currency. The clean revocation run left `denom_loss_events: 1` + and one coin marked `denom-loss`, so the loss transaction and its detail + screen are reachable after all — through the destructive phase rather than + through the dev experiment. `revoke_denomination` now looks for the "Loss of + funds" row, opens it, and checks that the screen names a reason (one of + `loss_reason_expired`, `_unoffered`, `_vanished`). That is + `TransactionDenomLoss`, the loss branch of the detail screen and + `TransitionLossComposable` — around ninety lines that had never rendered — + and it makes the detail screen's remaining gap the refresh branch alone. + +### The phase job's first attempt, and a third teardown that did not wait + +The revocation-and-twister job waited correctly for the campaign loop and the +version matrix, then died: + +``` +=== 17:49:15 restarting the stack with sim.conf +=== 17:49:35 stack did not come up; stopping +``` + +`phases-stack.log` shows `taler-unified-setup.sh` terminating at the merchant. +The cause is the same shape as the emulator one, two sections above: +`stack.sh stop` kills the supervisor and waits for *it*, then returns — while +its children are still holding the ports. The job started the stack again five +seconds later, and the merchant could not bind. + +Both halves are fixed. `stack.sh stop` now waits, after the supervisor is +gone, for the six ports this stack owns to be released (not 11000 and 11001: +the mailbox and taldir are run separately and outlive it), and says so if they +are still held after a minute. `run/phases2.sh` additionally retries the start +once, because losing a phase to a transient failure costs an hour of waiting +for the next round boundary. + +Worth noticing how similar the three are: + +| what | what it waited for | what it should have waited for | +| --- | --- | --- | +| `emu.sh kill` | the console accepting `emu kill` | the process to exit and release the AVD | +| `stack.sh stop` | the supervisor to exit | the children to release the ports | +| the first phase job | a line in `rounds.log` | the loop's process to be gone | + +In all three, something answered "done" before the thing that mattered was +done, and the failure landed on whatever ran next rather than on the component +at fault. In the meantime the stack is back up (18 s, clean), the loop is +running again at round 21, and the phases are queued behind the matrix retry. + +### The revocation phase ran, in the worst possible conditions + +A `pkill` of the first phase script had not actually killed it — the pattern +matched the `bash -c` wrapper of the very command doing the killing, which +ended that ssh session before `pkill` ran. So two phase jobs were alive, and at +17:49 they both stopped and started the stack. One of them won, ran the +revocation phase from 17:50 to 17:59, restarted the stack and started a +*second* campaign loop; the other saw its own start fail at the merchant and +gave up. For about fifteen minutes there were two loops exploring with the same +seeds on the same four emulators, a scenario of mine running on a fifth, and +the stack being restarted underneath all of it. + +Everything is back to one loop and one phase job. The point of recording it is +what it does to the result: `revoke_denomination` completed and reported + +``` +- the wallet holds 4 denominations: [1, 4, 7, 8] +- revoked 1E1SBDFT7V6KX9… (1 coin(s) held) +- asked the wallet to reload the exchange +- home after revocation: [] +- denom_loss_events: 0 rows +- recoup_groups: 0 rows +- coins: 0 rows +``` + +A wallet that held twenty coins has none, with no recoup group and no loss +event to account for them — which would be a serious finding if anything about +that run could be trusted. It cannot: the same episode carries a +`[harness-crash] FATAL EXCEPTION: main` from a process that is not the app and +an `[empty-hierarchy] no view hierarchy returned`, the two scenarios after it +died with `could not enable developer mode; settings showed: []`, and the +exchange it was talking to was restarted twice while it ran. Any of those could +produce an empty wallet. + +So it is **not** filed as a finding. `run/phases2.sh` re-runs the same phase +with the stack to itself, and the question to put to that run is precisely: +after revoking one denomination of four, does the wallet still hold the coins +of the other three, and does the revoked one leave a recoup group or a loss +event behind? Whatever that says is worth a finding; this run is not. + +### Ranking the gaps by what can be reached + +`gaps.py` ranked packages by raw missed lines, and that ranking was misleading +in a way that cost scenario-design time: `~.peer` looked like the third-biggest +gap in the module and is mostly four `@Preview` functions in one file. The +ranking now subtracts preview lines per package — the same data the headline +"reachable" figure already used, applied one level down: + +``` +packages by missed lines that can actually be reached: + 493 missed 69.0% ~.transactions (636 counting previews) + 376 missed 64.8% ~.payment (526 counting previews) + 271 missed 73.7% ~.compose (369 counting previews) + 222 missed 67.8% ~.exchanges (242 counting previews) + 204 missed 38.2% ~.donau (256 counting previews) + … + 122 missed 70.9% ~.peer (432 counting previews) + 97 missed 74.6% ~.balances (233 counting previews) +``` + +`~.peer` moves from third to tenth and `~.balances` from tenth to fourteenth. +`~.donau` keeps the lowest percentage of any package at 38.2 %, and most of +what is missing there is behind the statements button that is wired to nothing +— which the patched build reaches, so that number should move on its own once +the patch lands. + +### Why API 24 never booted: not the camera, not the teardown, the AVD's size + +The retry settled two of the three hypotheses at once. **API 28 booted** this +time, where it had failed in the first pass — so the teardown fix is real. +**API 24 failed again**, from a clean start and with the emulated camera, so +neither the lingering-process theory nor the NV21 virtual-scene error was its +cause. The camera error is therefore cleared: it is noise that API 26 logs +eight times while booting fine. + +What is left is the AVD itself. `emu.sh create` builds every AVD the same way: +`-d pixel_6`, 4 GB of RAM, a 6 GB data partition, 1080×2400 at 420 dpi. Three +probes on a spare emulator, each a fresh AVD from the same API 24 image: + +| profile | RAM | data partition | result | +| --- | --- | --- | --- | +| `pixel_2` | 2 GB | 2 GB | **booted in 35 s** | +| `pixel_6` | 2 GB | 2 GB | **booted in 35 s** | +| `pixel_6` | 4 GB | 6 GB | never booted (the campaign's own configuration) | + +So the device profile is not the problem — a Pixel 6 profile on Android 7 boots +fine. The size is. Which of the two sizes is still open; a fourth probe +(`pixel_6`, 4 GB RAM, 2 GB partition) is running to say whether it is the RAM +or the partition, and `emu.sh` will then pick that one value by API level +rather than giving a 2016 system image the same budget as a 2025 one. + +A note on how the probes were run, since two of them had to be thrown away: the +first attempt printed a hard-coded "booted with -d pixel_2 and 2 GB" while +actually running with `pixel_6`, which nearly produced the wrong conclusion — +the message now interpolates the parameters it was given. And two copies ended +up racing on the same AVD name and console port, because the ssh session +carrying one timed out while the remote script kept going. Probes get +`setsid nohup` and their own log now, like everything else here. + +#### The retried levels booted and had no money + +API 28, 30 and 33 all booted on the second pass — the teardown fix works — and +then every one of their twelve scenarios failed: + +``` +API 28: 0/12 ok + all twelve: driver-error + stack.HttpError: HTTP 401 for http://localhost:8082/accounts/wallet7/withdrawals: + {"code":40,"hint":"Unknown account"} +``` + +Worker 6 — the one the matrix drives — banks as `wallet7`, and +`stack.py`'s `provision()` defaulted to `SIM_WORKERS=5`, so a plain +`python3 stack.py` created `wallet1`…`wallet5` and stopped. The campaign's own +four workers were fine, which is why nobody noticed; the matrix's worker had an +account until the bank database was rebuilt, and after that it did not. + +The failure mode is the thing to watch for: a level that boots and then reports +twelve driver errors looks exactly like a platform that cannot run the app. +Only the exception text says otherwise. The default is now seven, which covers +every AVD the harness has, and the three levels are queued to run again behind +the phase job. + +## Fault injection, at last + +The twister phase ran: three scenarios, all of them actually doing something +for the first time (`twister_withdraw_faults` took 638 s against the 30 s it +used to take while reporting "nothing to inject"). Seven faults, armed one at a +time in front of the exchange: a truncated response, a truncated upload, 500, +404, 403, 502, and a wrong `Content-Type`. + +**One finding.** Five of the seven faults leave a withdrawal on a screen with a +title, a back arrow and nothing else — and it stays that way after the fault is +removed and the exchange is healthy again: + +``` +- http-500: ['Go back', 'Withdraw UNKNOWN', 'Internal event log'] +- http-500 after retry: ['Go back', 'Withdraw UNKNOWN', 'Internal event log'] +- http-500: armed 115 times +- http-500 once the fault stops: ['Go back', 'Withdraw UNKNOWN', 'Internal event log'] +``` + +Written up as `withdrawal-screen-never-recovers-from-an-exchange-outage.md`: +`PromptWithdrawScreen` has a loading state and a success state and nothing in +between, so a preparation that failed looks like one still in flight, and +nothing re-runs it. A user meets this without any proxy whenever an exchange +answers 5xx or truncates a body at the moment a withdrawal starts. + +The two faults that are *survived* are the useful contrast: a damaged **upload** +(`truncated-request`) and a wrong `Content-Type` both carry on to the terms of +service and then to "Waiting for authorization in the bank". So the wallet is +not simply fragile under damage; it is specifically missing an error state on +one screen. + +**One observation held back.** Under every fault, a payment ends with the +wallet showing "This transaction is pending" and "Paid -€1.00" while the +merchant still says `claimed` ninety seconds after the fault stopped. That +could be a purchase that never resolves, or a retry that had not come round +yet — ninety seconds cannot tell them apart, and wallet-core's retry backoff is +measured in minutes. The scenario now waits five minutes and records how long +recovery took, so the next phase will answer it instead of hinting at it. + +**And one thing the faults did not find:** no crash, no internal error screen, +no stuck database, in 21 fault-armed flows. The oracles that have caught real +defects all round — `fee-on-dead-transaction`, `mixed-amount-notation`, +`glued-currency` — reported nothing here either. Fault injection was the last +avenue by design, and on this evidence the wallet's transport-level error +handling is in better shape than its screens are. + +### Two more scenarios from the reachable ranking, and a finding from one of them + +With the ranking subtracting previews, `~.payment` is second (376 reachable +missed) and `PaymentResponses.kt` the worst file in it at 42 %. What is missing +there is the *typed* half: `PaymentInsufficientBalanceDetails`, its +`PerExchange` breakdown, and the mapping from each of seven refusal reasons to +its own string. `payment_insufficient` only ever reaches the plain +"not enough money" case, and the wallet cannot manufacture the others — but +wallet-core can, with the `merchant-deposit-insufficient` dev experiment. + +The new `payment_insufficient_reason` scenario arms it and pays for something +the wallet can easily afford. The answer is +`payment-prompt-says-insufficient-without-the-reason.md`: with €9.87 in the +wallet and a €1.00 order, the prompt says **"Insufficient balance"** and nothing +else. The reason is in the reply, the string for it exists, the mapping from +hint to string exists, and exactly one screen in the app uses that mapping — +the peer-push one. The payment prompt reads `choice.details` and ignores +`choice.details.balanceDetails.causeHint` sitting beside it. Patched with the +same expression the peer screen already uses. + +Two mistakes of mine in writing that scenario, both worth the same warning: +the first version named the order "Order the merchant cannot take", so every +pattern looking for the word "cannot" matched the order summary and the +scenario cheerfully reported a reason-specific hint that was not there. The +summary is neutral now and the patterns match wording only the wallet's own +strings contain. **An assertion that can be satisfied by the test's own input +is not an assertion.** + +The other new scenario comes from the revocation: `revoke_denomination` now +follows the recoup group to completion, reports what the balance did, and then +looks for the "Loss of funds" row and opens it — `TransactionDenomLoss`, the +loss branch of the detail screen and `TransitionLossComposable`, about ninety +lines that had never rendered because the only loss event anyone could make was +TESTKUDOS. A revocation makes one in euros. That phase is queued. + +### A seventh vacuous scenario, and the long press that could not work + +`TransactionsScreen.kt` sat at 49 % with its whole selection mode uncovered — +select all, leaving selection mode, and the delete-selected dialog. There was +already a scenario for that, `transactions_bulk_delete`, and it had been +reporting the same line every round while counting as a pass: + +``` +- after long press: ['http://localhost:8081', '€7.87', 'Pending:', …] +- long press did not open selection mode +``` + +Checked across the last forty summaries: **every** run of it, in every round, +ended on that note. It never could do otherwise. The main screen's list is +built with selection switched off: + +```kotlin +// wallet/src/main/java/net/taler/wallet/balances/BalancesPagerComposable.kt +TransactionRow( + tx = tx, + isSelected = false, + selectionMode = false, + onTransactionClick = { onTransactionClicked(tx) }, + onTransactionSelect = {}, // a no-op, by construction +) +``` + +Selection exists only on the dedicated screen behind the "All" chip. So the +scenario was waiting for a feature that is deliberately absent, and saying so +in a way that read like a flaky gesture. + +Finding the real cause took three wrong turns worth recording, because each was +a plausible theory that the evidence refuted: + +1. **"The gesture is wrong."** `long_press` sends `input swipe x y x y 800`, a + zero-distance swipe, which looks like something Compose might reject. It was + replaced with two `input motionevent` calls — which silently do nothing, + because each `input` invocation is its own input session and the DOWN is + cancelled when it exits. Probing four techniques against a live row settled + it: the original zero-distance swipe is the only one that works, and moving + even two pixels turns it into a drag that cancels the long press. The change + was reverted and the reason written into the function. +2. **"The balance card is being counted as a row."** It is, on the dedicated + screen — the card sits between the app bar and the list — but adding + "balance" to the stop-list did not help, because the card's parts land in + different bands and the offending one holds the exchange URL, not the word + "Balance". +3. **The actual fix.** A transaction's amount carries a sign and a balance's + does not, so `transaction_rows` grew a `signed_only` mode for callers on + that screen, plus a rule that a URL is never a row's title. + +With that, the dedicated screen's selection mode runs end to end: + +``` +- selection mode: [… '1 selected', 'Select All', …] +- after select all: [… '2 selected', …] +- 1 unnamed clickable(s) in the app bar: [(12, 150, 138, 276)] +- after closing selection mode: [… 'Go back', …] +- the delete dialog: ['Delete transactions', 'Are you sure you want to remove + the selected transactions from your wallet?', 'Delete', 'Cancel'] +- rows after deleting the selection: 0 +``` + +`transactions_bulk_delete` now pins what the main screen actually does — a long +press there must do *nothing*, not open a detail screen and not crash — and +says so, and `transactions_screen_selection` owns the deletion flow. Note the +close button in that app bar is an unnamed clickable, which is why the scenario +has to find it by position: `TransactionsScreen.kt:112` passes +`contentDescription = null`, the same omission as +`action-buttons-have-no-accessible-name.md`. + +### The matrix, third pass: five levels clean, and two kinds of infrastructure noise + +With `wallet7` funded, the retried levels do what they should: + +``` +API 30: 12/12 ok +API 28: 0/0 ok -- aborted: adb logcat timed out after 120s +``` + +API 30 joins 26, 29, 31, 34 and 36 at 12 of 12. API 28 did not fail a +scenario; it never finished one, because `adb logcat` stopped answering: + +``` +subprocess.TimeoutExpired: Command '[… 'logcat', '-d', '-t', '600']' + timed out after 120 seconds +``` + +That is the machine, not the app — at the time it was carrying six emulators, +the campaign's four workers, a matrix level, two Gradle builds and a scenario +of mine on a spare worker. The lesson is about discipline rather than code: ad +hoc runs on a spare emulator are cheap individually and not free in aggregate, +and the version matrix is the thing that suffers first because it boots a fresh +emulator for every level. + +Tally so far, across three passes: + +| level | result | +| --- | --- | +| 24 | never booted; the AVD-sizing fix is queued for validation | +| 26, 29, 30, 31, 34, 36 | 12/12 ok | +| 28 | booted twice, aborted twice — provisioning once, an adb timeout once | +| 33 | pending in the current pass | + +So **no version-specific defect has turned up in any level that completed**, +and every failure so far has been the harness or the host. + +## Dead code, enumerated, and coverage without it + +The "untouched classes" list in a coverage report shows the dead code that +happens to be big; `ui-with-no-callers.md` was assembled by reading it and +chasing suspects by hand. `simulator/coverage/deadcode.py` now does it +systematically: every top-level declaration and every direct member of a type, +asked whether its name appears anywhere else in the app. + +**19 declarations, 383 lines in the wallet module; 10 and 56 in the library.** +The full list, with what each one is, is in +`dead-declarations-complete-list.md`. Beyond the five pieces of UI already +written up, it turned up the older generation of a menu component sitting in +the same file as its replacement (`NewMenuItem`, `NewMenuSectionHeader`, +`NewMenuContent`, beside the `Material3MenuGroup` four screens use), two lists +of wallet-core notification type strings superseded by `@SerialName` matching +in `backend/Notifications.kt`, a constructor property nothing passes or reads, +and `fun MerchantInfoSheet() {}` — an empty composable. + +### What it does to the numbers + +``` +lines covered 12585/17247 (73.0%) +missed inside @Preview 1403 +missed in dead code 277 +reachable lines covered 12585/15567 (80.8%) +the ceiling this report can read: 90.3% +``` + +Three figures that have to be kept apart: **73.0 %** of all lines, **79.4 %** +of lines outside `@Preview` bodies, **80.8 %** of lines that are both outside a +preview and reachable at all. Only the last says anything about how well the +app is tested. `gaps.py --dead` prints it; the pass is opt-in because it takes +a few minutes. + +Only *missed* dead lines are subtracted. Some dead lines count as covered — a +file-level `private val` is initialised when its class loads whether anything +reads it or not — and subtracting those would flatter the numerator. + +### Getting the detector to tell the truth took three tries + +Worth recording, because the first two versions produced confident nonsense: + +1. **Indentation is not nesting.** The first version accepted declarations at + indent 0 or 4, which admitted every `val` local to a composable — 43 + "dead declarations" of which most were locals, including `pagerPosition` + and `biometricManager`. It now tracks brace depth and the kind of the + enclosing construct, so a member of a class counts and a local inside a + function does not. +2. **Spans ran away.** Brace-matching from a `val` declaration consumed the + rest of the enclosing block, so a one-line property was reported as 121 + lines — and worse, spans overlapped, which would have double-counted lines + subtracted from the coverage denominator. Each body shape is now handled + separately, and the spans were checked against the source line by line. +3. **Deadness is transitive.** `connectToWifi29` and + `connectToWifiDeprecated` are referenced only from `connectToWifi`, which + is referenced from nowhere. The search now repeats, ignoring references + that come from inside already-dead spans, until a round adds nothing. + +The remaining limits are in the finding: a common name can collide with an +unrelated use and look alive (which under-reports, the safe direction — the +library's `showError` hides the wallet's two), mutually-referencing overloads +keep each other alive (`GridMenu.kt` is dead as a unit but only `GridMenu` is +listed), and anything reached by reflection would be reported wrongly. Which +is why the finding is a list to read, not a deletion to apply. + +### cancelProgressToken: four attempts, and why it stays at 70 of 71 + +The last unexercised wallet-core operation sits behind one button: the Cancel +on the database-migration progress dialog. `MainActivity.kt`'s largest +remaining gap is that dialog (lines 445–482) and the `onCancel` that calls +`cancelDatabaseMigration` (223–227), so this is worth something beyond the +operation count — but it is also the hardest thing in the campaign to reach, +and four attempts did not. + +1. **The committed 57 KB fixture.** Migrates in well under a second. The + fifteen-attempt tap loop never saw the dialog. +2. **A 1.7 MB fixture, 512 records.** Built by driving the + `useNativeDb = false` build through a scenario first. The migration emitted + 112 progress notifications and still finished before a screen dump came + back; a dump costs about a second, which is most of the window. +3. **Blind taps.** Read the prompt's button coordinates first, then tap + "Migrate now" and the same slot again with no dump in between — the + progress dialog's single button sits where the prompt's confirm button was. + No call. +4. **Freezing the process.** `kill -STOP` on the app so the taps queue in the + system input dispatcher, then `kill -CONT`: once after starting the + migration, once with the start *and* the cancel queued together before it. + The freeze itself worked both times (`froze the app: True`); the migration + still finished first. + +What would reach it: a legacy database of some thousands of records, which +means driving the `useNativeDb = false` build through enough withdrawals to +make one, or a debug hook that pauses the migration between steps. Neither is +a scenario, so the operation count stands at **70 of 71**, and the reason is +recorded in the scenario itself rather than left as a mystery for the next +person. + +Worth noting what the attempts *did* buy: the prompt, the "Later" deferral, +`migrateDatabase`, the progress notifications and the switch to the native +backend are all covered, and the migration dialog in `MainActivity` is no +longer a screen nothing had ever driven. + +## Iteration 22 — 106 scenarios, three serious findings, all of them patched kinds + +``` +2026-10-18T20:52:13 round 22: suite: 106 ok, 0 driver errors, 3 serious findings + *** [fee-on-dead-transaction] a fee is shown on a transaction that did not happen + *** [mixed-amount-notation] '5.00 EUR' beside '€4.88' + *** [glued-currency] 'UNKNOWN0.00' +``` + +Three, down from five, and the drop is not luck: two of the five were the +`unfinished-transaction` false positives that the tally fix reclassified. All +three that remain have patches sitting beside them. + +### The mailbox screen's two dialogs, and the same tap trap for the third time + +`MailboxScreen.kt` sat at 61 %, and half of what was missing was its two +dialogs. The scenario had been tapping for `^Add$|^New$|^\+$` and +`refresh|reload`, of which only the last matches anything on that screen — the +app bar offers "Show Mailbox Address", "Configure Mailbox" and "Refresh". + +Both dialogs now run: the address one shows the wallet's real mailbox URI and +copies it, and the URL one accepts a typed URL and is cancelled, which must +leave the screen as it was. + +Getting the copy confirmation to appear took the same mistake twice more: + +* **Too slow.** `c.see(r"copied to clipboard", timeout=10)` reported "no + confirmation" for a snackbar that a probe found **0.4 s** after the tap. The + scenario now polls tightly, as the Toast lesson in the import scenario + already said it should. +* **The wrong control.** Even then it saw nothing, because `c.tap` hunts for a + clickable ancestor and on these dialog buttons lands somewhere that dismisses + the dialog instead of pressing the button — exactly the trap documented in + `pick_file_in_picker`'s docstring for the document picker's rows, and in the + transactions screen's row long-press. Tapping the node's own centre works: + + ``` + - after copying: ['Mailbox address URI copied to clipboard'] + ``` + +Three different screens have now needed that same correction. It is written in +three docstrings; it would be better as one helper, and that is worth doing +before a fourth screen finds it. + +### API 24 boots, and the matrix is eight levels of nine + +The AVD-sizing fix is confirmed end to end. The level that spent 1200 seconds +twice without finishing a boot now boots and runs everything: + +``` +scenario 24 +balances_screens ok +history ok +scan_manual_entry ok +nfc_tap_to_pay ok +settings_walk ok +settings_export ok +settings_import ok +config_changes ok +wallet_lock_without_credential ok +a11y_audit ok +lifecycle_kill ok +db_corruption ok + +API 24: 12/12 ok +``` + +So the cause was never the app, the camera format or the teardown: a 2016 +system image cannot boot on 4 GB of RAM with a 6 GB data partition, and boots +in 35 seconds on 2 GB of each. `emu.sh` picks the smaller budget below API 29. + +The matrix now reads: + +| level | result | +| --- | --- | +| 24, 26, 29, 30, 31, 33, 34, 36 | **12/12 ok** | +| 28 | aborted twice, both times on the harness — provisioning once, an `adb logcat` timeout under load once | + +**Eight of the nine levels the app's own code branches on now pass every +platform-sensitive scenario, identically.** The report that started this — +scanning works on Android 15 but not 14 — is still unanswered, and the matrix +cannot answer it: the camera is the one path no emulator here can drive. What +the matrix *can* say is that nothing else about the app differs across eight +platform generations, which narrows where to look. diff --git a/simulator/findings/PATCHES.md b/simulator/findings/PATCHES.md @@ -0,0 +1,148 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Patches for the findings + +Where a finding has a fix that is clear from the code rather than a product +decision, the patch sits beside it as `<finding>.diff`. Each one applies to a +clean checkout with + +```bash +git apply simulator/findings/<finding>.diff +``` + +All nineteen apply together, and with all of them applied +`./gradlew :wallet:compileFdroidDebugKotlin :wallet:lintFdroidDebug +:taler-kotlin-android:testDebugUnitTest` succeeds (lint matters here: it runs +with `abortOnError true` and `ignoreWarnings false`). The terminal patch was +checked on its own module, `:merchant-terminal:compileDebugKotlin` and +`:merchant-terminal:lintDebug`. No two patches touch the same file, with +one exception: `release-error-screen-explains-nothing` and +`product-image-dialog-has-nothing-to-announce` both add strings to +`wallet/src/main/res/values/strings.xml`, in different places, so they apply in +either order. + +Fifteen of the nineteen have also **run on a device**. The four that have not +are the ones written since that run — the terminal's config scanner, the +product-picture labels, the payment prompt's refusal reason, and the second +half of the accessible-names patch — which are built and linted but not +driven. The set that did run was built into a +`sim` APK and put through the sixteen scenarios that touch patched code on one +emulator, with its coverage dumps kept apart (JaCoCo keys classes by a hash of +their bytecode, so two builds' dumps cannot be merged): + +``` +16 scenarios, 16 ok, 1 findings (1 serious) +``` + +Fifteen of the sixteen reported nothing at all, including the scenarios that +produce `fee-on-dead-transaction`, `mixed-amount-notation` and +`glued-currency` on an unpatched build. Two wallet-core operations that no +scenario could reach before — `getDonauStatements` and +`sendTalerUriMailboxMessage`, each behind one of the defects — are exercised by +that run. + +The one finding was the patch set's own fault and is now fixed: see "What +running it changed" in `release-error-screen-explains-nothing.md`, where the +first version of that patch put a wallet-core error-code *name* in front of a +release user. The rebuilt patch was re-run on the same scenario and is clean. + +The exceptions are the two camera patches. `qr-camera-ignores-the-plane-strides` +carries nine JVM unit tests, including five that encode a real QR code into a +synthetic camera frame and decode it back, so the pipeline is verified as far +as arithmetic goes — though still not against a real Android 14 camera. +`pos-config-scanner-asks-for-a-rotation-zxing-refuses` removes a call that +throws unconditionally, which `repro_pos_rotate_unsupported.java` shows in +three lines. Both findings list the attended tests that only a human with a +phone can run. + +| patch | what it changes | +| --- | --- | +| `config-change-locks-the-wallet-out-of-its-database` | `MainActivity` starts wallet-core only when it is not already running, which is the asymmetry that caused the 7001 "exclusive ownership" error screen | +| `reset-dialog-puts-the-wipe-where-cancel-belongs` | swaps the positive and negative buttons in the reset *and* import dialogs, so the destructive action is drawn on the right | +| `payto-link-only-accepts-iban` | `isSupportedPayToUri` delegates to `PaytoUri.parse`, so every target type the app models is accepted | +| `mailbox-payment-only-actionable-for-one-scheme` | one `talerUriAction`/`talerUriIsAction` helper in `Utils.kt`, used by the mailbox rows and the forward button instead of two hand-written prefix tests | +| `donation-statements-button-is-wired-to-nothing` | threads the donau host through `BalancesPagerComposable` and navigates to `DonauStatement`, with the setup screen as the fallback | +| `contacts-and-mailbox-cannot-be-translated` | moves 42 literals into `strings.xml` and references them with `stringResource` | +| `amounts-without-currency-specification` | passes the currency specification into the three transfer screens so `transferAmount` is formatted like every other amount | +| `aborted-credit-shows-the-whole-amount-as-fee` | adds `Transaction.feeIsMeaningful` and gates the inferred fee row on it in all four credit screens | +| `suspended-looks-like-completed-in-the-list` | shows the suspended and expired states in the transaction list, which said nothing for them | +| `release-error-screen-explains-nothing` | `userFacingMsg` falls back to the error code when there is neither a hint nor a message | +| `action-buttons-have-no-accessible-name` | merges `ActionButton`'s semantics, naming all seven action buttons at once, and names the button that leaves selection mode on the transactions screen | +| `mailbox-private-keys-written-to-log` | redacts the keys in `MailboxConfiguration.toString()` and downgrades two `Log.e` traces | +| `add-account-note-is-required-but-unmarked` | labels the field "Note (required)", beside the two that say "(optional)" | +| `unreachable-host-leaves-blank-retrying-purchase` | permits cleartext to `127.0.0.1` and `::1`, which are the same machine as `localhost` | +| `delete-transaction-requeries-deleted-id` | `TransactionManager` remembers the ids it deleted and skips their transition notifications, which is where the three 7052 requests came from | +| `payment-prompt-says-insufficient-without-the-reason` | the payment prompt reads `causeHint` like the peer screen already does, so a refusal the merchant caused stops being reported as the user's balance | +| `product-image-dialog-has-nothing-to-announce` | names the product thumbnail and the picture dialog, whose window had nothing in its accessibility tree at all | +| `qr-camera-ignores-the-plane-strides` | extracts the camera's luminance plane with `rowStride` and `pixelStride` honoured, deletes the hand-rolled rotation zxing never needed, closes the frame whatever happens to it, and moves the analysis off the UI thread — **with nine unit tests** | +| `pos-config-scanner-asks-for-a-rotation-zxing-refuses` | the terminal's own copy of that pipeline: drops a `rotateCounterClockwise()` that `PlanarYUVLuminanceSource` answers with `UnsupportedOperationException`, takes the row stride as zxing's `dataWidth`, and closes the frame in a `finally` | + +## Deliberately not patched + +* **`database-import-reports-only-in-a-toast`** — a snackbar, a dialog or a + "last imported" line in the settings would all work; which one fits the app's + voice is a product decision, and it should cover export and clear too. +* **`withdrawal-screen-never-recovers-from-an-exchange-outage`** — the screen + needs an error state and a way to re-prepare; both are design decisions about + what a failed withdrawal preparation should look like. +* **`multi-qr-transfer-screen-cannot-be-reached`** — the button, the navigation + flag and the screen variant are all gated on a transfer option with two QR + codes, and wallet-core's two encoders exclude each other by IBAN country. + Leaving it for a future encoder, routing the single-QR case through the same + screen, or deleting the variant are all defensible. +* **`refresh-transactions-are-never-listed`** — the app has the whole detail + screen for change transactions but never passes `includeRefreshes`, so + wallet-core withholds them. Showing them always, only in developer mode, or + only when one has failed is a product decision; the finding lays out the + three. +* **`dead-declarations-complete-list`** — the systematic list (19 declarations + and 383 lines in the wallet, 10 and 56 in the library) and coverage + recomputed without them: 80.8 % of reachable lines rather than 79.4 %. + Deletion is a decision about intent, per item. +* **`ui-with-no-callers`** — about 320 lines that nothing refers to: five + pieces of UI (one a second implementation of the add-contact screen) and + four helpers in `Utils.kt`, one of which is the only user of the app's two + WiFi permissions. Whether each is wired up or deleted is a decision about + intent; the unused `CHANGE_WIFI_STATE` is the part worth deciding first. +* **`alias-registration-hardcodes-the-directory`** — the fix is a new setting + (a `taldirBaseUrl` beside the donau one), which is a product decision about + where it belongs and what the default should be, not a mechanical change. +* **`a-failed-query-is-shown-as-an-empty-wallet`** and the empty-prompt half of + `unreachable-host-leaves-blank-retrying-purchase` — both need a loading and + an error state designed into several screens. +* **`refresh-fails-on-mixed-age-denominations`**, + `deposit-does-not-guard-zero-amounts`, `addglobalcurrencyexchange-null-masterpub` + — these are wallet-core (taler-typescript-core), not this repository. +* **`taldir-protocol-version-mismatch`** — one character in the taldir service, + in its own repository. +* **`error-code-registry-behind-wallet-core`** — `TalerErrorCode.kt` is + generated from the upstream registry; it wants a regeneration, not an edit. +* **`pos-confirmation-shows-five-codes`**, `purge-destroys-coins-and-history-without-saying-so`, + `wallet-lock-opens-when-the-credential-is-gone`, + `unknown-wire-method-hangs-the-deposit-form`, + `bitcoin-transfer-relabels-the-amount-as-btc`, + `dev-experiment-uri-exits-the-app`, + `add-payment-service-fails-silently`, + `word-currency-symbol-glued-to-amount` — each needs a decision I would be + guessing at: which TOTP code is the right one to show, what a purge should + warn, whether an absent credential should lock or open, and so on. The + findings say what is wrong and where; the choice is the maintainer's. +* **`contacts-and-mailbox-cannot-be-translated`** covers 42 of the 43 strings. + The last one, `ContactManager.kt:169`'s "Alias not found", is built into a + `TalerErrorInfo.message` by a class that has no `Context`; localising it + means mapping the code at the display site instead, which is a small design + choice rather than a substitution. diff --git a/simulator/findings/__pycache__/repro_untranslated_contacts_mailbox.cpython-313.pyc b/simulator/findings/__pycache__/repro_untranslated_contacts_mailbox.cpython-313.pyc Binary files differ. diff --git a/simulator/findings/a-failed-query-is-shown-as-an-empty-wallet.md b/simulator/findings/a-failed-query-is-shown-as-an-empty-wallet.md @@ -0,0 +1,139 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# A failed query is shown as an empty wallet + +Found by the `api_error_sweep` scenario, which makes one wallet-core call fail +per screen and reads what the screen then says. Four of the ten screens it +sweeps report nothing at all, and two of those four state the failure as a fact +about the user's money. + +**Severity: moderate.** No money is at risk, but the wallet tells the user +something untrue about their own wallet, and the only trace is in the log. + +## What happens + +The sweep injects `WALLET_UNEXPECTED_EXCEPTION` into one operation and then +opens the screen that calls it: + +| operation | screen | what it shows | +| --- | --- | --- | +| `getBalances` | main screen | the error, with "Export error diagnostics" | +| `getTransactionsV2` | transaction list | the error | +| `listBankAccounts` | Settings → Bank accounts | the error | +| `listDiscounts` | Discounts | the error | +| `listSubscriptions` | Passes | the error | +| `getExchangeTos` | PSP's terms of service | the error, with its own heading | +| `listExchanges` | Settings → Payment services | **nothing** — the list renders | +| `getContacts` | Contacts | **"No contacts yet."** | +| `getDepositWireTypes` | Deposit | **"No bank accounts saved in the wallet"** | +| `getMaxDepositAmount` | Deposit | **nothing** — the account list renders | +| `getMaxPeerPushDebitAmount` | Send | **"€0.00"**, and a "Send €0.00" button | +| `getWithdrawalDetailsForAmount` | Withdraw | **an empty screen** | +| `getCurrencySpecification` | main screen | **nothing** — amounts lose their symbol | + +Six of the thirteen are right: an `ErrorComposable` with the code, the hint and +a way to export diagnostics. The rest are the defect, and three of them are +worse than silence, because they state the failure as a fact about the user: + +* **Deposit** says the user has *no bank accounts*. They may well have + several; the wallet simply could not ask. +* **Contacts** says *"No contacts yet."*, the same way. +* **Send** says the user can send *nothing*, with a disabled-looking + "Send €0.00", on a wallet holding €9.87. + +## Why + +Both are the same shape — a nullable result, an error that only reaches the +log, and a caller that reads `null` as "nothing there": + +```kotlin +// wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt:166 +suspend fun getDepositWireTypes(…): GetDepositWireTypesResponse? { + var result: GetDepositWireTypesResponse? = null + api.request("getDepositWireTypes", …) + .onError { Log.e(TAG, "Error getDepositWireTypes $it") } + .onSuccess { result = it } + return result +} +``` + +```kotlin +// wallet/src/main/java/net/taler/wallet/peer/PeerManager.kt:215 +private suspend fun getMaxPeerPushDebitAmount(…): GetMaxPeerPushDebitAmountResponse? { + var response: GetMaxPeerPushDebitAmountResponse? = null + api.request("getMaxPeerPushDebitAmount", …) + .onError { error -> Log.e(TAG, "got getMaxPeerPushDebitAmount error result $error") } + .onSuccess { response = it } + return response +} +``` + +`PeerManager` alone has nine error handlers whose whole body is a `Log` call; +`grep -n 'onError' wallet/src/main/java/net/taler/wallet/*/*Manager.kt` shows +the shape across the rest. + +The `listExchanges` silence is the same defect as +[`add-payment-service-fails-silently.md`](add-payment-service-fails-silently.md) +seen from the other side: that finding is about `ExchangeManager` publishing +error channels nobody reads, and this is what the user sees when one of them +fires. The empty withdrawal prompt is +[`unreachable-host-leaves-blank-retrying-purchase.md`](unreachable-host-leaves-blank-retrying-purchase.md), +reached without a proxy — one injected error is enough. + +## Reproduce by hand + +Needs a debug build with **Developer mode** on, and a balance. + +1. Share this URI into the wallet (it fails the next four `getDepositWireTypes` + calls with code 7001): + + ```bash + adb shell am start -a android.intent.action.VIEW -d \ + 'taler+http://dev-experiment/api-error?operation=getDepositWireTypes&detail=eyJjb2RlIjogNzAwMSwgImhpbnQiOiAiaW5qZWN0ZWQifQ&count=4' + ``` + + (`detail` is base64url JSON: `{"code": 7001, "hint": "injected"}`.) + +2. On the main screen tap **Deposit**. The screen says "No bank accounts saved + in the wallet". +3. `adb logcat | grep getDepositWireTypes` shows the real reason. +4. The same with `operation=getMaxPeerPushDebitAmount` and the **Send** + button: the screen offers €0.00. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_failed_query_empty_state.py +SIM_WORKER=4 python3 suite.py api_error_sweep +``` + +The notes of the resulting `suite-w4-*-summary.json` list every screen with +"shows an error: True/False" and what was on it. + +## Suggested fix + +Distinguish "no data" from "could not ask". The managers already have the +`TalerErrorInfo`; the cheapest change that fixes all four is to give each of +these screens the same `state` treatment the balance list has — `Loading`, +`Success`, `Error` — rather than a nullable payload, so an error renders as +`ErrorComposable` instead of as an empty list or a zero amount. + +Where that is too much, the minimum is: do not claim a fact the wallet does +not have. "No bank accounts saved" and "€0.00" are both assertions; a failed +query should produce neither. diff --git a/simulator/findings/aborted-credit-shows-the-whole-amount-as-fee.diff b/simulator/findings/aborted-credit-shows-the-whole-amount-as-fee.diff @@ -0,0 +1,113 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullCredit.kt b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullCredit.kt +index a329a533..3478a6aa 100644 +--- a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullCredit.kt ++++ b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullCredit.kt +@@ -29,6 +29,7 @@ import net.taler.wallet.R + import net.taler.wallet.backend.TalerErrorCode.EXCHANGE_GENERIC_KYC_REQUIRED + import net.taler.wallet.backend.TalerErrorInfo + import net.taler.wallet.balances.ScopeInfo ++import net.taler.wallet.transactions.feeIsMeaningful + import net.taler.wallet.transactions.AmountType + import net.taler.wallet.transactions.PeerActions + import net.taler.wallet.transactions.PeerInfoShort +@@ -70,7 +71,7 @@ fun ColumnScope.TransactionPeerPullCreditComposable( + amountType = AmountType.Neutral, + ) + +- if (t.amountRaw > t.amountEffective) { ++ if (t.amountRaw > t.amountEffective && t.feeIsMeaningful) { + val fee = t.amountRaw - t.amountEffective + TransactionAmountComposable( + label = stringResource(id = R.string.amount_fee), +diff --git a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushCredit.kt b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushCredit.kt +index 34ab5606..3a8162aa 100644 +--- a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushCredit.kt ++++ b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushCredit.kt +@@ -28,6 +28,7 @@ import net.taler.wallet.R + import net.taler.wallet.backend.TalerErrorCode.EXCHANGE_GENERIC_KYC_REQUIRED + import net.taler.wallet.backend.TalerErrorInfo + import net.taler.wallet.balances.ScopeInfo ++import net.taler.wallet.transactions.feeIsMeaningful + import net.taler.wallet.transactions.AmountType + import net.taler.wallet.transactions.PeerActions + import net.taler.wallet.transactions.PeerInfoShort +@@ -55,7 +56,7 @@ fun ColumnScope.TransactionPeerPushCreditComposable( + amountType = AmountType.Neutral, + ) + +- if (t.amountRaw > t.amountEffective) { ++ if (t.amountRaw > t.amountEffective && t.feeIsMeaningful) { + val fee = t.amountRaw - t.amountEffective + TransactionAmountComposable( + label = stringResource(id = R.string.amount_fee), +diff --git a/wallet/src/main/java/net/taler/wallet/refund/TransactionRefundComposable.kt b/wallet/src/main/java/net/taler/wallet/refund/TransactionRefundComposable.kt +index f2f408cb..743bf4f2 100644 +--- a/wallet/src/main/java/net/taler/wallet/refund/TransactionRefundComposable.kt ++++ b/wallet/src/main/java/net/taler/wallet/refund/TransactionRefundComposable.kt +@@ -40,6 +40,7 @@ import net.taler.wallet.backend.TalerErrorCode + import net.taler.wallet.backend.TalerErrorInfo + import net.taler.wallet.balances.ScopeInfo + import net.taler.wallet.compose.TalerSurface ++import net.taler.wallet.transactions.feeIsMeaningful + import net.taler.wallet.transactions.AmountType + import net.taler.wallet.transactions.ErrorTransactionButton + import net.taler.wallet.transactions.TransactionAction +@@ -89,7 +90,7 @@ fun TransactionRefundComposable( + amountType = AmountType.Neutral, + ) + +- if (t.amountRaw > t.amountEffective) { ++ if (t.amountRaw > t.amountEffective && t.feeIsMeaningful) { + val fee = t.amountRaw - t.amountEffective + TransactionAmountComposable( + label = stringResource(id = R.string.amount_fee), +diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionState.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionState.kt +index 906bfbd7..c55cc54f 100644 +--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionState.kt ++++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionState.kt +@@ -185,3 +185,24 @@ object TransactionStateSerializer : KSerializer<TransactionState> { + }) + } + } ++ ++/** ++ * Whether the difference between a credit's raw and effective amounts is ++ * really a fee. ++ * ++ * The credit screens infer the fee as `amountRaw - amountEffective`, and for a ++ * transaction that never completed wallet-core reports an effective amount of ++ * zero -- so the inference claims the entire amount went to fees. An aborted ++ * €5.00 withdrawal read "Fee -€5.00 / Total €0.00" although nothing was ++ * withdrawn and no fee was charged. ++ */ ++val Transaction.feeIsMeaningful: Boolean ++ get() = when (txState.major) { ++ TransactionMajorState.Aborted, ++ TransactionMajorState.Aborting, ++ TransactionMajorState.SuspendedAborting, ++ TransactionMajorState.Failed, ++ TransactionMajorState.Expired, ++ TransactionMajorState.Deleted -> false ++ else -> true ++ } +diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/TransactionWithdrawalComposable.kt b/wallet/src/main/java/net/taler/wallet/withdraw/TransactionWithdrawalComposable.kt +index bc8bf4a4..73168e97 100644 +--- a/wallet/src/main/java/net/taler/wallet/withdraw/TransactionWithdrawalComposable.kt ++++ b/wallet/src/main/java/net/taler/wallet/withdraw/TransactionWithdrawalComposable.kt +@@ -52,6 +52,7 @@ import net.taler.wallet.backend.TalerErrorCode + import net.taler.wallet.backend.TalerErrorInfo + import net.taler.wallet.balances.ScopeInfo + import net.taler.wallet.cleanExchange ++import net.taler.wallet.transactions.feeIsMeaningful + import net.taler.wallet.transactions.AmountType + import net.taler.wallet.transactions.ErrorTransactionButton + import net.taler.wallet.transactions.TransactionAction +@@ -168,7 +169,7 @@ fun TransactionWithdrawalComposable( + ) + } + +- if (t.amountRaw > t.amountEffective) { ++ if (t.amountRaw > t.amountEffective && t.feeIsMeaningful) { + val fee = t.amountRaw - t.amountEffective + TransactionAmountComposable( + label = stringResource(id = R.string.amount_fee), diff --git a/simulator/findings/aborted-credit-shows-the-whole-amount-as-fee.md b/simulator/findings/aborted-credit-shows-the-whole-amount-as-fee.md @@ -0,0 +1,120 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# An aborted withdrawal says the whole amount went to fees + +Found in the notes of the `abort_then_retry` scenario: a withdrawal that was +aborted before the bank confirmed it reads + +``` +This transaction was aborted +Chosen amount €5.00 +Fee -€5.00 +Total amount €0.00 +``` + +Nothing was withdrawn and no fee was charged — the exchange never saw the +money — but the screen says the whole €5.00 was consumed by fees. + +**Severity: low-moderate.** Cosmetic in the sense that no money moved, but it +is alarming in exactly the situation where a user is already unsure what +happened, it is reachable in a release build by anyone who aborts a +withdrawal, and the same arithmetic is used on three further screens. + +## What happens + +The fee row is derived from the difference between the two amounts: + +```kotlin +// wallet/src/main/java/net/taler/wallet/withdraw/TransactionWithdrawalComposable.kt:171 +if (t.amountRaw > t.amountEffective) { + val fee = t.amountRaw - t.amountEffective + TransactionAmountComposable( + label = stringResource(id = R.string.amount_fee), + amount = fee.withSpec(spec), + amountType = AmountType.Negative, + ) +} +``` + +For a successful withdrawal that is right: `amountRaw` is what the bank sends, +`amountEffective` what lands in the wallet, and the difference is the +withdrawal fee. For an aborted one wallet-core reports `amountEffective` of +zero, and the difference becomes the entire amount. + +The same expression appears on every *credit* screen, so each of them makes +the same claim once its transaction is aborted or fails: + +- `withdraw/TransactionWithdrawalComposable.kt:171` +- `peer/TransactionPeerPushCredit.kt` +- `peer/TransactionPeerPullCredit.kt` +- `refund/TransactionRefundComposable.kt` + +The debit screens (payment, deposit, peer-push-debit, peer-pull-debit) use the +difference the other way round (`amountEffective > amountRaw`), which goes to +zero instead of to the full amount — an expired purchase correctly shows +"Total €1.00 / Paid €0.00" with no fee row at all. + +### An abandoned deposit: the same oracle, but probably not the same defect + +`abandon_aborting_deposit` trips the oracle on a *debit*, and it is recorded +here rather than as its own finding because it may well be correct. A deposit +submitted while offline, then aborted, then abandoned reads + +``` +This transaction has failed or been abandoned +Chosen amount €0.98 +Fee -€0.02 +Amount sent -€1.00 +``` + +and the money is genuinely gone — the balance went from €9.87 to €8.87 across +the abandon, which is what the confirmation dialog promises ("Funds still in +transit WILL GET LOST"). So "Amount sent −€1.00" is true. + +What is doubtful is the **fee row**: the exchange never completed the deposit, +so it earned no €0.02 deposit fee; the whole €1.00 was lost in transit, not +split between a fee and a transfer. If that reading is right the screen should +show the loss as a loss rather than as a fee and a payment. A maintainer can +judge that faster than this campaign can — it is recorded, with the balances +either side, rather than asserted. + +## Reproduce by hand + +1. On the main screen tap **Withdraw**, or follow a bank's withdrawal URI. +2. Confirm the withdrawal, so the wallet is waiting for the bank. +3. Tap **Abort**, and confirm. +4. The transaction now reads "This transaction was aborted", with + "Fee −€5.00" and "Total amount €0.00" under a "Chosen amount" of €5.00. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_aborted_fee.py # worker 0 by default +SIM_WORKER=4 python3 suite.py withdraw_abort # the scenario notes it too +``` + +## Suggested fix + +Show the fee row only when the difference is a fee: either gate it on the +transaction's state (`txState.major` of `Pending` or `Done`, not `Aborted`, +`Failed` or `Expired`), or, better, take the fee from the withdrawal's own +details rather than inferring it — wallet-core reports the fee structure, and +inferring it from two amounts means every state where one of them is zeroed +produces a wrong number. The same change applies to the three other credit +screens. diff --git a/simulator/findings/action-buttons-have-no-accessible-name.diff b/simulator/findings/action-buttons-have-no-accessible-name.diff @@ -0,0 +1,61 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/compose/ActionButton.kt b/wallet/src/main/java/net/taler/wallet/compose/ActionButton.kt +index 86f3786e..3c0db806 100644 +--- a/wallet/src/main/java/net/taler/wallet/compose/ActionButton.kt ++++ b/wallet/src/main/java/net/taler/wallet/compose/ActionButton.kt +@@ -29,6 +29,7 @@ import androidx.compose.ui.Alignment + import androidx.compose.ui.Modifier + import androidx.compose.ui.graphics.Color + import androidx.compose.ui.graphics.Shape ++import androidx.compose.ui.semantics.semantics + import androidx.compose.ui.text.style.TextAlign + import androidx.compose.ui.unit.dp + +@@ -44,7 +45,15 @@ fun ActionButton( + labelColor: Color = MaterialTheme.colorScheme.onPrimaryContainer, + enabled: Boolean = true, + ) { +- Column(modifier, horizontalAlignment = Alignment.CenterHorizontally) { ++ // One accessibility node for the icon and its label together: the icon ++ // carries no description (right for decoration, but it is the only thing ++ // inside the button), so without this the control is announced as ++ // "Button" with no name, and the label is a separate focus stop. Merging ++ // here fixes every caller at once, and makes the whole column the target. ++ Column( ++ modifier.semantics(mergeDescendants = true) {}, ++ horizontalAlignment = Alignment.CenterHorizontally, ++ ) { + FloatingActionButton( + onClick = if (enabled) onClick else {{}}, + shape = shape, +diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionsScreen.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionsScreen.kt +index a08133df..ff9e4d8d 100644 +--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionsScreen.kt ++++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionsScreen.kt +@@ -116,7 +116,14 @@ fun TransactionsScreen( + }) { + Icon( + imageVector = Icons.Rounded.Close, +- contentDescription = null, ++ // The only way out of selection mode, and the only ++ // thing in the button: without a description it is ++ // announced as an unnamed button, and a screen reader ++ // user has no way to tell it from the back arrow it ++ // replaces. ++ contentDescription = stringResource( ++ R.string.transactions_leave_selection, ++ ), + ) + } + } +diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml +index 905e4390..219246b9 100644 +--- a/wallet/src/main/res/values/strings.xml ++++ b/wallet/src/main/res/values/strings.xml +@@ -227,6 +227,7 @@ GNU Taler is immune to many types of fraud such as credit card data theft, phish + <string name="transactions_retry">Retry</string> + <string name="transactions_required_kyc">KYC required to proceed</string> + <string name="transactions_select_all">Select All</string> ++ <string name="transactions_leave_selection">Leave selection mode</string> + <string name="transactions_send_funds">Send</string> + <string name="transactions_suspend">Suspend</string> + <string name="transactions_title">Transactions</string> diff --git a/simulator/findings/action-buttons-have-no-accessible-name.md b/simulator/findings/action-buttons-have-no-accessible-name.md @@ -0,0 +1,162 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Unnamed controls: the seven action buttons, and the way out of selection mode + +Found while teaching the simulator to tap them: the taps did nothing, because +the label a sighted user reads is not part of the button at all. A screen +reader has the same problem. + +**Severity: moderate, and it affects release builds** — these are the wallet's +primary actions, and they are unusable with TalkBack. + +All seven buttons on the main screen are the same `ActionButton`: Send, +Request, Withdraw, Deposit, and -- further down -- Discounts, Passes and +Donation statements (`balances/BalancesPagerComposable.kt`, seven call sites). +Every other floating action button in the app does set a +`contentDescription`, so this one composable is the whole defect. + +## What happens + +On the main screen the balance card shows four buttons. Each one is a +`FloatingActionButton` holding only an icon, with the text in a *sibling* +`Text` below it: + +``` +Button clickable=true text='' content-desc='' bounds=[332,887][479,1034] +TextView clickable=false text='Request' bounds=[338,1050][473,1103] +``` + +So the clickable element has no name and the name is not clickable. TalkBack +announces the button as just "Button, double tap to activate"; the label is +read separately as static text, with nothing tying the two together. + +Seven clickable nodes on the main screen have no accessible name of their own +*and* no labelled descendant to inherit one from — these four among them. (A +clickable wrapper whose label is a child is fine: Compose merges the semantics +and TalkBack reads the child. Only a label that is merely a *neighbour*, as +here, is lost.) + +## The same omission on the transactions screen + +Found later, while driving the dedicated transactions screen's selection mode: +the button that leaves selection mode is unnamed too. + +```kotlin +// wallet/src/main/java/net/taler/wallet/transactions/TransactionsScreen.kt:111 +navigationIcon = if (selectionMode) { + { + IconButton(onClick = { selectionMode = false; selectedItems.clear() }) { + Icon(imageVector = Icons.Rounded.Close, contentDescription = null) + } + } +} else null, +``` + +It is the only way out of selection mode and the only thing inside the button, +and it sits where the back arrow normally is — so a screen reader user is told +there is a button, not what it does or that it has replaced the back arrow. +"Select All" beside it *is* described, which is what makes the omission look +like an oversight rather than a decision. + +The simulator had to find it by position for the same reason: + +``` +- 1 unnamed clickable(s) in the app bar: [(12, 150, 138, 276)] +``` + +The patch gives it `R.string.transactions_leave_selection` +("Leave selection mode"), beside the existing `transactions_select_all`. + +## Reproduce by hand + +With TalkBack, as a user would hit it: + +1. Install the wallet and get a balance into it (withdraw once — against the + local stack, or `Settings → Withdraw demo KUDOS` on a debug build). +2. Enable TalkBack (Settings → Accessibility → TalkBack on the device). +3. Go to the wallet's main screen and swipe right repeatedly to move the + accessibility focus along the balance card. +4. Focus lands on four buttons in a row. Each is announced as an unnamed + button; the words "Send", "Request", "Withdraw", "Deposit" are announced as + separate text, after or before the button they belong to. + +Without TalkBack, from a shell — the same thing, in the accessibility tree: + +```bash +adb shell uiautomator dump /sdcard/ui.xml +adb exec-out cat /sdcard/ui.xml | tr '>' '>\n' | grep -E 'Button|Request' +``` + +The `android.widget.Button` nodes carry `text=""` and `content-desc=""`, while +the `Request` text sits in a non-clickable `TextView` underneath. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_action_buttons_no_a11y_name.py --fund +``` + +Prints each label, the button it really belongs to and that button's +accessible name, then `reproduced: True`. + +## Why + +`compose/ActionButton.kt:47` builds a `Column` of a `FloatingActionButton` and +a label, and every caller passes an icon with no description +(`BalancesPagerComposable.kt:651` and the three below it): + +```kotlin +ActionButton( + icon = { Icon(Icons.AutoMirrored.Default.ArrowForward, contentDescription = null) }, + label = { Text(stringResource(R.string.transactions_send_funds)) }, + ... +) +``` + +`contentDescription = null` is right for a decorative icon *inside* a named +control, but here it is the only thing in the control, so the control ends up +nameless. + +## Suggested fix + +Merge the column's semantics so the label names the button, in `ActionButton` +itself rather than in each of the four call sites: + +```kotlin +Column( + modifier.semantics(mergeDescendants = true) {}, + horizontalAlignment = Alignment.CenterHorizontally, +) { +``` + +That gives the whole column one accessibility node named after the label, which +also makes the much larger column the touch target. Passing the label string as +the icon's `contentDescription` would fix the announcement too, but leaves the +label as a second, redundant focus stop. + +One change covers all seven, which is why it belongs in `ActionButton`: the +Discounts / Passes / Donation statements row is built from the same composable, +and the main screen's QR scanner FAB, the exchange list's, the contact list's +and the bank account list's all set a `contentDescription` already. + +The second half of the patch is the one-line omission on the transactions +screen, with `transactions_leave_selection` ("Leave selection mode") added +beside `transactions_select_all` in `strings.xml`. Verified together: +`:wallet:compileFdroidDebugKotlin` and `:wallet:lintFdroidDebug` clean, and all +nineteen patches still apply together and build. diff --git a/simulator/findings/add-account-note-is-required-but-unmarked.diff b/simulator/findings/add-account-note-is-required-but-unmarked.diff @@ -0,0 +1,13 @@ +diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml +index 905e4390..bcb01841 100644 +--- a/wallet/src/main/res/values/strings.xml ++++ b/wallet/src/main/res/values/strings.xml +@@ -348,7 +348,7 @@ GNU Taler is immune to many types of fraud such as credit card data theft, phish + <string name="send_deposit_account_edit">Edit account</string> + <string name="send_deposit_account_forget_dialog_message">Do you really wish to forget this account in the wallet?</string> + <string name="send_deposit_account_forget_dialog_title">Forget account</string> +- <string name="send_deposit_account_note">Note</string> ++ <string name="send_deposit_account_note">Note (required)</string> + <string name="send_deposit_account_manage">Manage bank accounts</string> + <string name="send_deposit_account_warning">You must enter an account that you control, otherwise you will not be able to fulfill the regulatory requirements.</string> + <string name="send_deposit_bitcoin">Bitcoin</string> diff --git a/simulator/findings/add-account-note-is-required-but-unmarked.md b/simulator/findings/add-account-note-is-required-but-unmarked.md @@ -0,0 +1,116 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# "Add account" is disabled until you fill a field called "Note" + +Found the slow way: two of this campaign's scenarios had been filling the +add-account form correctly, submitting, and reporting success for rounds on end +without ever adding an account. The button was disabled the whole time and +nothing on the screen said why. + +**Severity: low**, but it costs the user the whole feature until they guess. + +## What happens + +Open **Settings → Bank accounts → Add account**, pick **IBAN**, and fill in the +two fields that look like the form: + +``` +Account holder Test Holder +IBAN DE89370400440532013000 +Postal code (optional) +Town (optional) +Note +``` + +**Add account** stays greyed out. There is no message, and the two fields that +*are* optional say so in their labels — which is exactly what makes "Note" read +as optional too. Typing anything into it enables the button. + +## Why + +The submit button requires the note, which the form calls an alias internally: + +```kotlin +// wallet/src/main/java/net/taler/wallet/accounts/AddAccountComposable.kt:245 +enabled = !formError && formAlias.isNotBlank(), +``` + +```kotlin +// wallet/src/main/java/net/taler/wallet/accounts/AddAccountComposable.kt:229 +OutlinedTextField( + value = formAlias, + … + label = { Text(stringResource(R.string.send_deposit_account_note)) }, + isError = formAlias.isBlank(), +) +``` + +and the label is the bare word: + +```xml +<!-- res/values/strings.xml:351 --> +<string name="send_deposit_account_note">Note</string> +``` + +while the genuinely optional fields are explicit: + +```xml +<!-- res/values/strings.xml:373,377 --> +<string name="send_deposit_postal_code">Postal code (optional)</string> +<string name="send_deposit_town">Town (optional)</string> +``` + +The field does get an error outline (`isError = formAlias.isBlank()`), but it +has that outline from the moment the form opens, before the user has done +anything wrong, so it reads as decoration rather than as a complaint. + +It applies to every account type: `formAlias` is in the parent composable, so +IBAN, x-taler-bank and Bitcoin accounts all need it. + +## Reproduce by hand + +1. **Settings → Bank accounts → Add account**. +2. Choose **IBAN**, type a holder name and `DE89370400440532013000`. +3. **Add account** is disabled. Nothing explains it. +4. Type one character into **Note** — the button enables. + +Expected: the label says the field is required (or the button explains what is +missing), consistently with the "(optional)" labels beside it. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=0 python3 -u suite.py bank_accounts deposit_methods +``` + +Both scenarios now fill the note and check that the account appears in the +list; before they did not, and both passed while adding nothing — which is the +same vacuous-pass pattern as +[`payto-link-only-accepts-iban.md`](payto-link-only-accepts-iban.md). + +## Suggested fix + +Either label it `Note (required)` / `Account name`, or drop the requirement and +fall back to something derived from the account (the IBAN, the Bitcoin address, +the x-taler-bank account name) when the user leaves it blank — the label is +stored as `KnownBankAccountInfo.label` and only used for display, so a +sensible default costs nothing. + +Whichever way, a disabled button with no explanation is the part to remove: if +the form cannot be submitted, it should say what is missing. diff --git a/simulator/findings/add-payment-service-fails-silently.md b/simulator/findings/add-payment-service-fails-silently.md @@ -0,0 +1,147 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Payment-service failures are never shown: four error channels have no observer + +Found by the `exchange_url_fuzz` scenario, which fed twelve hostile addresses +to Settings → Payment services → **Add payment service**. Every rejection +looked identical to the user: the dialog closes and the list comes back +unchanged. + +**Severity: moderate.** This is not developer-mode gated — "Payment services" +is in the ordinary settings list. A mistyped address is indistinguishable from +one that is still being added, since a *successful* add also takes several +seconds to appear in the list. + +The same gap covers the whole screen, not just adding: `ExchangeManager` +publishes four error channels and **none of them has a reader**, so failures to +add, list, delete or reload a payment service are all silent. + +## What happens + +Entering `file:///etc/passwd` and tapping OK: the dialog closes, nothing is +shown at +0.6 s, +1.5 s or +3 s, and no payment service is added. wallet-core +did reject it, in the log only: + +``` +{"type":"error","operation":"addExchange","id":109, + "error":{"code":7048,"detail":"scheme \"file:\" is not supported, expected \"https:\""}} +{"type":"error","operation":"addExchange","id":100, + "error":{"code":7048,"detail":"URL cannot be parsed"}} +``` + +For contrast, a good address does work — `http://localhost:8081/` appears in +the list as "Currency: EUR" — but only after a few seconds, which is why the +silence is misleading rather than merely untidy. + +Injecting a failure into the operation behind the *list* shows the same thing +from the other side: with `listExchanges` made to fail +(`taler://dev-experiment/api-error?operation=listExchanges&…`), Settings → +Payment services renders its list as if nothing had happened. Whatever it +shows is whatever it had before; the user is given no reason to doubt it. + +The same silence covers the case that matters most in practice: a *well-formed* +address that simply cannot be reached. Adding `http://localhost:8091/` on a +device where nothing answers on that port behaves exactly like adding nothing +at all — the screen returns to the list, the service is absent, and the user is +given no reason to suspect a network problem rather than a typo. This was +noticed the other way round: a simulator scenario that adds a second payment +service "passed" while silently achieving nothing, because the port had not +been routed into the emulator. + +## Reproduce by hand + +1. Open the wallet, go to **Settings → Payment services**. +2. Tap **Add payment service**. +3. Type `file:///etc/passwd` (or `not a url`, or `http://`) and tap **OK**. +4. The dialog closes. Nothing else happens — no message, no entry in the list. + `adb logcat | grep addExchange` shows the rejection. + +Expected: the dialog stays open with the reason, or an error is shown — the +string for it already exists. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_add_exchange_fails_silently.py +``` + +## Why + +`ExchangeManager.add()` does publish the error +(`exchanges/ExchangeManager.kt:97-112`): + +```kotlin +}.onError { + Log.e(TAG, "Error adding exchange: $it") + mProgress.value = false + mAddError.value = it.toEvent() +} +``` + +but `addError` has no observer anywhere in the app — and neither do its three +siblings: + +| Channel | Set when | Readers | +| --- | --- | --- | +| `addError` (`ExchangeManager.kt:58`) | `addExchange` fails | none | +| `listError` (`:61`) | listing exchanges fails | none | +| `deleteError` (`:64`) | deleting one fails | none | +| `reloadError` (`:67`) | reloading one fails | none | + +```console +$ grep -rn "addError\|deleteError\|listError\|reloadError" \ + --include=*.kt wallet/src/main/java | grep -v "private val m" +wallet/.../ExchangeManager.kt:58: val addError: LiveData<Event<TalerErrorInfo>> = mAddError +wallet/.../ExchangeManager.kt:61: val listError: LiveData<Event<TalerErrorInfo>> = mListError +wallet/.../ExchangeManager.kt:64: val deleteError: LiveData<Event<TalerErrorInfo>> = mDeleteError +wallet/.../ExchangeManager.kt:67: val reloadError: LiveData<Event<TalerErrorInfo>> = mReloadError +``` + +Four declarations, no readers. Two matching string resources exist and are +never referenced either — `R.string.exchange_add_error` ("Could not add +payment service") and `R.string.exchange_list_error` ("Could not list payment +services") — so the error path was designed and then left unwired. There are no +strings at all for the delete and reload cases. + +`ExchangeListScreen.kt:136` also closes the dialog immediately +(`exchangeManager.add(url); showAddDialog = false`), before the asynchronous +call has any result to report. + +## Suggested fix + +Observe all four channels on the exchange list and show them — the screen +already has a snackbar host, and two of the strings are waiting (the delete and +reload cases need new ones). Keeping the add dialog open while `progress` is +true, and closing it only on success, would also tell the user that something +is happening during the seconds a good address takes. + +A lint rule or a small test asserting that every `*Error` channel a manager +exposes is collected somewhere would stop this class of defect coming back. +A sweep of every manager in `wallet/src/main/java` found no others: + +```console +$ for f in wallet/src/main/java/net/taler/wallet/*/[A-Z]*Manager.kt; do … +ExchangeManager.addError has no readers +ExchangeManager.deleteError has no readers +ExchangeManager.listError has no readers +ExchangeManager.reloadError has no readers +``` + +so this is a local lapse rather than a habit, and fixing the exchange list +closes the class. diff --git a/simulator/findings/addglobalcurrencyexchange-null-masterpub.md b/simulator/findings/addglobalcurrencyexchange-null-masterpub.md @@ -0,0 +1,154 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# "Treat as global" raises WALLET_UNEXPECTED_EXCEPTION on an un-contacted exchange + +Found by `simulator/driver/explore.py` (seed 11, step 34); reproducer in +`repro_global_currency_null_masterpub.py` (4 taps from a fresh profile). + +**Severity: low-moderate.** The menu entry sits inside `if (devMode)` in +`ExchangeListScreen.kt:231`, so only developer mode shows it. What it costs is a +feature that silently does not work plus a spurious +`WALLET_UNEXPECTED_EXCEPTION` in the logs, which is noise when triaging real +problems. + +## Reproduce by hand + +No local Taler deployment is needed: any payment service the wallet has not +contacted yet will do, and the wallet ships several as built-ins. + +1. Install a debug build of the wallet (`./gradlew :wallet:installFdroidDebug`) + on a device or emulator, or use a release build and skip to step 2 with + developer mode already on. +2. Open the app, go to **Settings** and switch **Developer mode** on. (A fresh + profile always starts with it off, whatever `BuildConfig.DEBUG` is: the + persisted value is pushed into the view model at every start.) +3. Settings → **Payment services**. The list contains built-ins the wallet has + never talked to, for example `exchange.taler-ops.ch`. Do not tap the entry + itself — contacting it would fetch its keys and fill in the missing field. +4. Tap the **⋮ menu** next to `exchange.taler-ops.ch`. +5. Tap **Treat as global**. + +Nothing happens on screen. With `adb logcat | grep addGlobalCurrencyExchange` +running, the request and its error are visible: + +``` +E taler-wallet: got addGlobalCurrencyExchange error: + TalerErrorInfo(code=WALLET_UNEXPECTED_EXCEPTION, + hint=unexpected exception (message: expected string at + (AddGlobalCurrencyExchangeRequest).exchangeMasterPub but got undefined), ...) +``` + +Expected instead: either the entry is not offered for an exchange whose keys +have not been fetched, or tapping it reports a plain, explained failure. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver && python3 ../findings/repro_global_currency_null_masterpub.py +``` + +Exits 0 and prints `reproduced: True` when the internal error appears. + +## What happens + +Settings → Payment services → ⋮ on an exchange the wallet has never contacted +→ **Treat as global**. wallet-core rejects the request: + +``` +code 7001 (WALLET_UNEXPECTED_EXCEPTION) +hint unexpected exception (message: expected string at + (AddGlobalCurrencyExchangeRequest).exchangeMasterPub but got undefined) +stack at _DecodingError … at decode … at dispatchRequestInternal +``` + +Nothing is shown to the user: the action silently does nothing, and the only +trace is the error in logcat. + +## Why + +`ExchangeItem.masterPub` is nullable and starts out null — it is only filled in +once the exchange's `/keys` has been fetched (`Exchanges.kt:33`): + +```kotlin +val masterPub: String? = null, +``` + +`BalanceManager.addGlobalCurrencyExchange` puts it into the request +unconditionally (`BalanceManager.kt:137`): + +```kotlin +api.request<Unit>("addGlobalCurrencyExchange") { + put("currency", currency) + put("exchangeBaseUrl", exchange.exchangeBaseUrl) + put("exchangeMasterPub", exchange.masterPub) // null -> key removed +} +``` + +`org.json.JSONObject.put(String, String?)` *removes* the key when the value is +null rather than storing JSON null, so wallet-core receives a request with no +`exchangeMasterPub` at all and fails to decode it. The failure is reported as +an unexpected exception because a missing required field is, from core's point +of view, a client bug. + +Confirmed from the other side, which pins the precondition exactly: with the +exchange **contacted first** -- its terms accepted and "Reload information" +tapped, so `/keys` has been fetched and `masterPub` is set -- the same menu +entry works. The currency scope then forms across both services, and the +"Where to pay" screen that only exists for a scope with more than one shopping +URL renders: + +``` +- the shopping screen: ['Your payment service offers the following website(s) …', + 'http://localhost:8080/config?shop=one', + 'http://localhost:8080/config?shop=two'] +- 2 shopping URLs listed +``` + +So this is not "treat as global is broken"; it is "treat as global is broken +for an exchange that has been added but not yet talked to", which is exactly +the state an exchange is in right after being added by URL. That is also why +`balances_two_exchanges` reached nothing for several rounds: it treated both +services as global straight after adding the second one. + +Two further places make it invisible rather than merely broken: + +* `removeGlobalCurrencyExchange` (`BalanceManager.kt:154`) has the identical + null-`masterPub` problem. +* `ExchangeListScreen.kt:356` discards both callbacks + (`onSuccess = {}, onError = {}`), so neither outcome reaches the UI. + +## Suggested fix + +Treat a null `masterPub` as "not possible yet" rather than passing it on: have +`ExchangeAction.GlobalAdd`/`GlobalDelete` bail out (or reload the exchange +first) when `exchange.masterPub == null`, and hide or disable the menu entry in +that state. Surfacing the error through `onError` would at least make it +visible, but the request should not be sent in the first place. + +A fix in the UI only is enough for the user-visible symptom; the underlying +sharp edge — `JSONObject.put` dropping null-valued keys, turning a nullable +Kotlin field into a missing required field — is worth checking across the other +`api.request { put(...) }` call sites. A sweep of all of them found every other +nullable argument guarded (`restrictAge?.let { put(…) }`, +`status.exchangeBaseUrl ?: error("no exchangeBaseUrl")`), so +`addGlobalCurrencyExchange` and `removeGlobalCurrencyExchange` are the only two +that pass a nullable straight through. + +The same sweep found `ExchangeListScreen.kt:361` and `:369` to be the only two +places in the app that discard an error callback with `onError = {}` — both of +them this feature. diff --git a/simulator/findings/alias-registration-hardcodes-the-directory.md b/simulator/findings/alias-registration-hardcodes-the-directory.md @@ -0,0 +1,143 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Alias registration and contact lookup hard-code a production directory + +Found while trying to cover the `net.taler.wallet.contacts` package: its forms +render and can be filled in (`AliasRegistrationScreen` is 60 % covered), but +nothing past the "Register Alias" button can work against a test or +self-hosted deployment, because the directory it talks to is a literal. + +**Severity: low** as a defect. The consequences are that a self-hosted Taler +deployment cannot have its own directory, and that three wallet-core +operations — `registerAlias`, `completeRegisterAlias`, `lookupAlias` — have no +reachable success path, which is why `contacts` is the least covered package in +the app (442 of its 827 instrumented lines missed). + +## What happens + +The Taler directory (taldir) base URL is a literal in two places: + +```kotlin +// wallet/src/main/java/net/taler/wallet/contacts/AliasRegistrationScreen.kt:100 +val taldirBaseUri = "https://taldir.gnunet.org" +``` + +```kotlin +// wallet/src/main/java/net/taler/wallet/contacts/ContactManager.kt:155,196,222 +taldirBaseUri: String = "https://taldir.gnunet.org", +``` + +`ContactScreen.kt:244` calls `taldirLookupAlias(alias, aliasType)` without the +parameter, so the default applies there too. Nothing in the app — not +developer mode, not the settings screen, not a `taler://` URI — can change it: +`grep -rn taldir wallet/src taler-kotlin-android/src` finds matches only inside +`contacts/`, and there is no `BuildConfig` field, resource or preference for it. + +Every other service the wallet talks to is chosen at runtime: exchanges are +added by URL in Settings, the merchant comes from the pay URI, the bank from +the withdrawal URI, donau from its own settings screen. + +## Why it matters + +1. **Nothing can exercise the second half of these screens.** The form renders + and validates locally, but registering an alias or looking one up always + goes to `taldir.gnunet.org`, so the simulator (and any CI, and any hand test + on a device) either talks to a production service or gets an error. The + challenge step, the completion step and every success state behind them stay + unreachable, as do the operations that drive them. +2. **A self-hosted Taler deployment cannot use it.** An operator who runs their + own exchange, bank and directory still has their users' wallets registering + aliases in GNUnet's directory. +3. **In developer mode it is the one URL that stays remote.** Dev mode exists + to point the wallet at a local stack; this screen ignores that. + +## How it was established + +The two literals are the whole story on the app side: + +```bash +cd taler-android +grep -rn 'taldir' --include=*.kt --include=*.xml wallet/src taler-kotlin-android/src +``` + +### And everything behind them works + +A real directory was then deployed beside the simulator's stack +(`git://git.taler.net/taldir`, a Go service; see +`simulator/backend/services/README.md`) and driven through wallet-core +directly, which *does* take the base URL as a parameter: + +``` +registerAlias -> {} (202 Accepted) + the validator recorded the challenge: J34V6DZG18X6EV0DFHQGDDGNJC +completeRegisterAlias -> {} +lookupAlias -> {"targetUri": "http://127.0.0.1:11000/SIMADDRESS"} +``` + +All three operations — the ones this campaign could never reach from the app — +round-trip on the first attempt. So the feature is not unfinished and the +protocol is not the problem: the app simply cannot be pointed at a directory. +Everything from the "Register Alias" button onwards is unreachable for want of +a URL field. + +### And then through the app itself, with the URL untouched + +To be sure the operations were not just working *beside* the app, the emulator +was made to answer for the hard-coded name — a hosts entry, the device's port +443 forwarded to a TLS front end, and the front end's CA trusted by the +simulator's own build type (`simulator/tls/README.md`). No URL in the app was +changed. The shipped code path then ran end to end: + +``` +POST taldir.gnunet.org/register/email <- the "Register Alias" button + the directory recorded: 285JEWK0894595KHSQSVYZW5E4 +POST taldir.gnunet.org/FAVWP84VPPY4… <- the challenge, typed in +GET taldir.gnunet.org/FAVWP84VPPY4… <- "Lookup with Taldir" +``` + +and the screens followed it exactly as designed: + +``` +the form: ['email', 'Alias Type', 'Alias', '12', 'Duration (months)', 'Register Alias'] +after registering: ['Challenge Solution', 'OK', 'Alias Registration'] +after completing: ['Registration successful!', 'OK', 'Alias Registration'] +after the lookup: ['Add Contact', 'Looked up', 'Petname', 'sim-w4-…@example.com', + 'https://mailbox.gnunet.org/CFEF11D10YTNNM6G…', 'Mailbox', 'OK'] +``` + +Not one finding came out of it: register, challenge, complete and look up all +work, and the lookup even fills the new contact's mailbox address in for the +user. **The hard-coded URL is the only thing wrong with this feature**, and it +is what keeps all of that out of reach of any test and any self-hosted +deployment. + +(Two caveats from doing it: the deployed taldir's `/config` hard-codes +protocol `0:0:0` while wallet-core's client declares `1:0:0` and refuses an +incompatible server, so the version had to be patched locally before anything +worked — see +[`taldir-protocol-version-mismatch.md`](taldir-protocol-version-mismatch.md). +And wallet-core resolved `localhost` to `::1` while the service listened on +`127.0.0.1`, so the URL has to be numeric.) + +## Suggested fix + +Give the directory the same treatment as donau: a `taldirBaseUrl` setting with +`https://taldir.gnunet.org` as its default, read by `ContactManager` and passed +down to `AliasRegistrationScreen`, and settable from the settings screen (or at +least from developer mode). A `BuildConfig` field with the same default would +already be enough to make the screens testable; a setting is what makes +self-hosting work. diff --git a/simulator/findings/amounts-without-currency-specification.diff b/simulator/findings/amounts-without-currency-specification.diff @@ -0,0 +1,182 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/transfer/ScreenTransfer.kt b/wallet/src/main/java/net/taler/wallet/transfer/ScreenTransfer.kt +index 940fc43a..5ba1db28 100644 +--- a/wallet/src/main/java/net/taler/wallet/transfer/ScreenTransfer.kt ++++ b/wallet/src/main/java/net/taler/wallet/transfer/ScreenTransfer.kt +@@ -135,17 +135,20 @@ fun ScreenTransfer( + transfer = transfer, + transactionAmountEffective = transfer.amountEffective.withSpec(spec), + transferContext = transferContext, ++ spec = spec, + ) + + is TransferData.IBAN -> TransferIBAN( + transfer = transfer, + transactionAmountEffective = transfer.amountEffective.withSpec(spec), + transferContext = transferContext, ++ spec = spec, + ) + + is TransferData.Cyclos -> TransferCyclos( + transfer = transfer, + transactionAmountEffective = transfer.amountEffective.withSpec(spec), ++ spec = spec, + ) + + is TransferData.Bitcoin -> TransferBitcoin( +diff --git a/wallet/src/main/java/net/taler/wallet/transfer/TransferCyclos.kt b/wallet/src/main/java/net/taler/wallet/transfer/TransferCyclos.kt +index 159fa43c..e1c72909 100644 +--- a/wallet/src/main/java/net/taler/wallet/transfer/TransferCyclos.kt ++++ b/wallet/src/main/java/net/taler/wallet/transfer/TransferCyclos.kt +@@ -27,6 +27,7 @@ import androidx.compose.ui.Modifier + import androidx.compose.ui.res.stringResource + import androidx.compose.ui.unit.dp + import net.taler.common.Amount ++import net.taler.common.CurrencySpecification + import net.taler.wallet.R + import net.taler.wallet.compose.WarningLabel + import net.taler.wallet.withdraw.TransferData +@@ -36,6 +37,7 @@ fun TransferCyclos( + transfer: TransferData.Cyclos, + transactionAmountEffective: Amount, + // TODO: transferContext? ++ spec: CurrencySpecification?, + ) { + Column( + modifier = Modifier.padding(all = 16.dp), +@@ -44,7 +46,7 @@ fun TransferCyclos( + Text( + stringResource( + R.string.withdraw_manual_ready_intro, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + transactionAmountEffective, + ), + style = MaterialTheme.typography.bodyLarge, +@@ -72,7 +74,7 @@ fun TransferCyclos( + ) + + WithdrawalAmountTransfer( +- conversionAmountRaw = transfer.transferAmount, ++ conversionAmountRaw = transfer.transferAmount.withSpec(spec), + ) + + TransferStep(2, stringResource(R.string.withdraw_manual_step_subject)) +@@ -94,7 +96,7 @@ fun TransferCyclos( + TransferStep(3, + stringResource( + R.string.withdraw_manual_step_finish, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + ), + ) + } +diff --git a/wallet/src/main/java/net/taler/wallet/transfer/TransferIBAN.kt b/wallet/src/main/java/net/taler/wallet/transfer/TransferIBAN.kt +index dc9ad5c8..dfc11ea6 100644 +--- a/wallet/src/main/java/net/taler/wallet/transfer/TransferIBAN.kt ++++ b/wallet/src/main/java/net/taler/wallet/transfer/TransferIBAN.kt +@@ -29,6 +29,7 @@ import androidx.compose.ui.Modifier + import androidx.compose.ui.res.stringResource + import androidx.compose.ui.unit.dp + import net.taler.common.Amount ++import net.taler.common.CurrencySpecification + import net.taler.common.TalerUtils + import net.taler.wallet.R + import net.taler.wallet.accounts.PaytoUri +@@ -44,6 +45,7 @@ fun TransferIBAN( + transfer: TransferData.IBAN, + transactionAmountEffective: Amount, + transferContext: TransferContext, ++ spec: CurrencySpecification?, + ) { + Column( + modifier = Modifier.padding(all = 16.dp), +@@ -53,7 +55,7 @@ fun TransferIBAN( + text = when(transferContext) { + ManualWithdrawal -> stringResource( + R.string.withdraw_manual_ready_intro, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + transactionAmountEffective, + ) + +@@ -62,7 +64,7 @@ fun TransferIBAN( + if (paytoIban !is PaytoUriIban) return@Column // TODO: render error + stringResource( + R.string.send_deposit_kyc_auth_intro_bank, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + paytoIban.iban, + ) + } +@@ -123,7 +125,7 @@ fun TransferIBAN( + } + + WithdrawalAmountTransfer( +- conversionAmountRaw = transfer.transferAmount, ++ conversionAmountRaw = transfer.transferAmount.withSpec(spec), + ) + + TransferStep(2, stringResource(R.string.withdraw_manual_step_subject)) +@@ -149,12 +151,12 @@ fun TransferIBAN( + when (transferContext) { + ManualWithdrawal -> stringResource( + R.string.withdraw_manual_step_finish, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + ) + + is DepositKycAuth -> stringResource( + R.string.send_deposit_kyc_auth_step_finish, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + transfer.iban, + ) + } +diff --git a/wallet/src/main/java/net/taler/wallet/transfer/TransferTaler.kt b/wallet/src/main/java/net/taler/wallet/transfer/TransferTaler.kt +index 6bcfaf98..5a36cb9d 100644 +--- a/wallet/src/main/java/net/taler/wallet/transfer/TransferTaler.kt ++++ b/wallet/src/main/java/net/taler/wallet/transfer/TransferTaler.kt +@@ -27,6 +27,7 @@ import androidx.compose.ui.Modifier + import androidx.compose.ui.res.stringResource + import androidx.compose.ui.unit.dp + import net.taler.common.Amount ++import net.taler.common.CurrencySpecification + import net.taler.wallet.R + import net.taler.wallet.accounts.PaytoUri + import net.taler.wallet.accounts.PaytoUriTalerBank +@@ -40,6 +41,7 @@ fun TransferTaler( + transfer: TransferData.Taler, + transactionAmountEffective: Amount, + transferContext: TransferContext, ++ spec: CurrencySpecification?, + ) { + Column( + modifier = Modifier.padding(all = 16.dp), +@@ -49,7 +51,7 @@ fun TransferTaler( + text = when (transferContext) { + ManualWithdrawal -> stringResource( + R.string.withdraw_manual_ready_intro, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + transactionAmountEffective, + ) + +@@ -58,7 +60,7 @@ fun TransferTaler( + if (paytoTaler !is PaytoUriTalerBank) return@Column // TODO: render error + stringResource( + R.string.send_deposit_kyc_auth_intro_bank, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + paytoTaler.account, + ) + } +@@ -108,7 +110,7 @@ fun TransferTaler( + DetailRow(stringResource(R.string.withdraw_exchange), cleanExchange(transfer.exchangeBaseUrl)) + + WithdrawalAmountTransfer( +- conversionAmountRaw = transfer.transferAmount, ++ conversionAmountRaw = transfer.transferAmount.withSpec(spec), + ) + } + } +\ No newline at end of file diff --git a/simulator/findings/amounts-without-currency-specification.md b/simulator/findings/amounts-without-currency-specification.md @@ -0,0 +1,140 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Amounts reach two screens without their currency specification + +Found by the `withdraw_account_tabs` and `peer_push_receive` scenarios: the +wire transfer instructions and the incoming peer-payment prompt print amounts +in the wallet's fallback notation ("5.00 EUR") while the rest of the app shows +"€5.00". On the transfer screen the two notations appear in the same sentence. + +**Severity: low.** Cosmetic, but both are screens the user acts on: one carries +the amount to copy into a banking app, the other is where a payment is +accepted. + +## What happens + +The manual-withdrawal instructions say: + +``` +You need to transfer 5.00 EUR from your regular bank account to the payment +service to receive €4.88 as digital cash in this wallet. +``` + +Both amounts are EUR. The first is rendered "5.00 EUR", the second "€4.88". + +The sentence is `R.string.withdraw_manual_ready_intro` and takes two +arguments: + +```kotlin +// wallet/src/main/java/net/taler/wallet/transfer/TransferIBAN.kt:55 +stringResource( + R.string.withdraw_manual_ready_intro, + transfer.transferAmount, // no currency specification + transactionAmountEffective, // .withSpec(spec) by the caller +) +``` + +`ScreenTransfer` applies the currency specification to the effective amount +before passing it down (`transfer.amountEffective.withSpec(spec)`), but +`transfer.transferAmount` is handed over as it came from wallet-core. With +`spec == null`, `Amount.toString()` takes its no-specification branch and +prints "5.00 EUR"; with a specification it prints "€5.00". + +The same pairing appears in every transfer screen: + +- `transfer/TransferTaler.kt:52,61` +- `transfer/TransferIBAN.kt:56,65,152,157` +- `transfer/TransferCyclos.kt:47,97` + +and in the deposit KYC variant of the sentence +(`send_deposit_kyc_auth_intro_bank`). + +## The same thing on the incoming peer-payment prompt + +Accepting money from another wallet shows: + +``` +Do you want to receive this payment? +from the simulator's peer +Total: 1.00 EUR + −0.09 EUR +Receive payment +``` + +`IncomingComposable` takes no `CurrencySpecification` parameter at all, so both +the total and the fee are rendered with `Amount.toString()` on an amount that +never had one: + +```kotlin +// wallet/src/main/java/net/taler/wallet/peer/IncomingComposable.kt:145 +text = terms.contractTerms.amount.toString(), +// ...:159 +stringResource(R.string.amount_negative, fee) +``` + +The same composable serves `IncomingPushPaymentScreen` and +`IncomingPullPaymentScreen`, so this is the prompt for both receiving a push +payment and paying an invoice. Its sibling screens get this right — +`TransactionAmountInfo` and `PeerQrCode` are both passed `withSpec(spec)`. + +## Reproduce by hand — the transfer instructions + +Needs an exchange that offers a manual (not bank-integrated) withdrawal; any +deployment does, including a plain `taler-unified-setup.sh` stack. + +1. Install a debug build, enable **Developer mode**, add the exchange. +2. On the main screen tap **Withdraw**, enter an amount, tap + **Confirm withdrawal** — do not use the bank's own "withdraw" button, as + that is the bank-integrated flow. +3. On the pending transaction tap **Wire transfer instructions**. +4. The first sentence reads "You need to transfer 5.00 EUR … to receive €4.88 + …". + +## Reproduce by hand — the peer prompt + +Needs a second wallet (`taler-wallet-cli` will do) with a balance: + +1. `taler-wallet-cli peer-send --exchange <url> --summary test EUR:1` +2. Hand the `taler://pay-push/…` URI it prints to the wallet under test. +3. The prompt reads "Total: 1.00 EUR" and "−0.09 EUR". + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_unspecced_amounts.py # both screens +SIM_WORKER=4 python3 suite.py withdraw_account_tabs peer_push_receive +``` + +The reproducer prints the offending lines from each screen; the scenarios' +`suite-w4-*-summary.json` quotes them in its notes. + +## Suggested fix + +Give `IncomingComposable` a `spec: CurrencySpecification?` parameter — both its +screens have the exchange base URL in hand and so can use +`rememberCurrencySpec` as the transaction screens do — and apply it to the +total and the fee. + +On the transfer screens, pass `transfer.transferAmount.withSpec(spec)` the way +the effective amount already is — the specification is in scope in `ScreenTransfer`, which is where +`transactionAmountEffective` is computed, so the simplest fix is to compute +both there and hand both down formatted. Note the spec belongs to the +*transfer* currency, which for a currency-converting account is not the +wallet's currency, so the right specification is the account's +`currencySpecification` where it has one. diff --git a/simulator/findings/bitcoin-transfer-relabels-the-amount-as-btc.md b/simulator/findings/bitcoin-transfer-relabels-the-amount-as-btc.md @@ -0,0 +1,112 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# The Bitcoin transfer screen relabels the amount as BTC + +Found by the `withdraw_account_tabs` scenario once the exchange advertised a +`payto://bitcoin/…` account: the wire transfer instructions tell the user to +send **5.00 BTC** for a withdrawal of **EUR 5.00**. + +**Severity: low**, with a caveat about the configuration — see below. + +## What happens + +A manual withdrawal of EUR:5.00 from an exchange whose account for this +withdrawal is a Bitcoin address shows: + +``` +Now make a split transaction with the following three outputs. +bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq 5.00 BTC +bc1qwtsq3knjuqyd4uqlh9ma373s4445j77m57zs6l 0.00000294 BTC +bc1q7tsq3kketks3deyfjqd43t20zy3r3rlcx2y8sf 0.00000294 BTC +``` + +The two dust outputs are right — 294 satoshi each, which is how the reserve +public key is encoded into the transaction. The first line is not: the amount +is EUR 5.00 and the screen says BTC. + +The app is told the currency and overwrites it: + +```kotlin +// wallet/src/main/java/net/taler/wallet/transfer/TransferBitcoin.kt:82 +text = if (segwitAddress == address) + amount.withCurrency("BTC").toString() +``` + +and again in the text the "Copy" button puts on the clipboard: + +```kotlin +// …:107 +return "$addr ${amount.withCurrency("BTC")}\n$sr" +``` + +`withCurrency` relabels; it does not convert. Whatever the exchange said the +transfer amount was, this screen calls it BTC. + +## The caveat + +For this to be visible, an exchange has to offer a Bitcoin account for a +currency that is not BTC, which is what the simulator does deliberately +(`SIM_EXTRA_PAYTOS` in `backend/stack.sh` signs a `payto://bitcoin/…` address +on a EUR exchange, so that the Bitcoin screens can be reached at all). Whether +that configuration is meaningful is an exchange-operator question. + +What does not depend on the caveat: the wallet has the transfer amount's real +currency in hand and prints a different one. On a genuinely Bitcoin-wired +exchange the relabelling is invisible because the two agree; the moment they +do not, the screen states a confident wrong unit for an amount the user is +about to transfer, and so does the clipboard. + +## Reproduce by hand + +Needs an exchange with a signed Bitcoin account; against the simulator's stack +that is the default (see `backend/stack.sh`, `EXTRA_PAYTOS`). On another +deployment: + +```bash +taler-exchange-offline -c <conf> \ + enable-account 'payto://bitcoin/bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq' upload +taler-exchange-offline -c <conf> \ + wire-fee now bitcoin EUR:0.01 EUR:0.01 upload +``` + +(the wire fee matters: wallet-core hides an account whose method has none). +Then, in the wallet: + +1. **Withdraw**, enter 5, **Confirm withdrawal** — the manual flow, not the + bank's own button. +2. On the pending withdrawal tap **Wire transfer instructions**. +3. Select the account tab for the Bitcoin account ("Account #3"). +4. The first output reads "5.00 BTC". + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=4 python3 suite.py withdraw_account_tabs +``` + +The notes quote each wire account's instructions, the Bitcoin one included. + +## Suggested fix + +Print the amount in the currency it came in — `amount.toString()`, with the +currency specification applied the way the other transfer screens do (see +[`amounts-without-currency-specification.md`](amounts-without-currency-specification.md)) — +and keep `withCurrency("BTC")` for the segwit dust, which really is satoshi. +If an exchange offering a Bitcoin account for a non-BTC currency is to be +treated as a misconfiguration, the screen should say so rather than render it. diff --git a/simulator/findings/config-change-locks-the-wallet-out-of-its-database.diff b/simulator/findings/config-change-locks-the-wallet-out-of-its-database.diff @@ -0,0 +1,66 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/backend/BackendManager.kt b/wallet/src/main/java/net/taler/wallet/backend/BackendManager.kt +index b9ef17b5..f667e414 100644 +--- a/wallet/src/main/java/net/taler/wallet/backend/BackendManager.kt ++++ b/wallet/src/main/java/net/taler/wallet/backend/BackendManager.kt +@@ -70,6 +70,10 @@ class BackendManager( + + private var running = false + ++ /** Whether wallet-core is up in this process. */ ++ val isRunning: Boolean ++ @Synchronized get() = running ++ + private fun newScope() = CoroutineScope(Dispatchers.Default + SupervisorJob()) + + @Synchronized +diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt +index 26a8ed89..2a3c8925 100644 +--- a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt ++++ b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt +@@ -41,6 +41,9 @@ class WalletBackendApi( + + private val backendManager = BackendManager(notificationReceiver) + ++ /** Whether wallet-core is already up, and so must not be initialised again. */ ++ val isRunning: Boolean get() = backendManager.isRunning ++ + fun startWallet() { + backendManager.run() + GlobalScope.launch(Dispatchers.IO) { +diff --git a/wallet/src/main/java/net/taler/wallet/main/MainActivity.kt b/wallet/src/main/java/net/taler/wallet/main/MainActivity.kt +index 4868fbca..367faa68 100644 +--- a/wallet/src/main/java/net/taler/wallet/main/MainActivity.kt ++++ b/wallet/src/main/java/net/taler/wallet/main/MainActivity.kt +@@ -238,7 +238,14 @@ class MainActivity : FragmentActivity() { + } + } + +- model.startWallet() ++ // wallet-core belongs to the retained MainViewModel, and onDestroy ++ // deliberately leaves it running across a configuration change -- so ++ // starting it again here sends a second "init", whose fresh wallet ++ // cannot take the SQLite database from the instance still holding it ++ // ("could not acquire exclusive ownership of the wallet database"). ++ // Changing the language, the font size or the display size recreates ++ // this activity, which is how a user met that error screen. ++ if (!model.walletRunning) model.startWallet() + + handleIntents(intent) + +diff --git a/wallet/src/main/java/net/taler/wallet/main/MainViewModel.kt b/wallet/src/main/java/net/taler/wallet/main/MainViewModel.kt +index 9c2bf023..cd0e2c81 100644 +--- a/wallet/src/main/java/net/taler/wallet/main/MainViewModel.kt ++++ b/wallet/src/main/java/net/taler/wallet/main/MainViewModel.kt +@@ -165,6 +165,12 @@ class MainViewModel( + MutableStateFlow<DatabaseMigrationState>(DatabaseMigrationState.None) + val databaseMigrationState: StateFlow<DatabaseMigrationState> = mDatabaseMigrationState + ++ /** ++ * Whether wallet-core is already running, so that an activity being ++ * recreated does not start it a second time. ++ */ ++ val walletRunning: Boolean get() = api.isRunning ++ + fun startWallet() { + api.startWallet() + } diff --git a/simulator/findings/config-change-locks-the-wallet-out-of-its-database.md b/simulator/findings/config-change-locks-the-wallet-out-of-its-database.md @@ -0,0 +1,225 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# A configuration change locks the wallet out of its own database + +Found while setting up a different test — switching the app's language to +German to read the contacts screen — which is as ordinary a thing as a user +does. Enlarging the system font or the display size does it too. + +**Severity: high.** The wallet lands on its "Initialization error" screen, +which replaces the entire app, and the screen tells the user to retry while +offering no way to do so; the only way out is to swipe the app away and reopen +it. The error underneath is `WALLET_UNEXPECTED_EXCEPTION` (7001), not a handled +condition. Two of the three triggers are **accessibility** settings, so the +users most likely to meet it are the ones who changed their font size to be +able to read the screen at all. + +## What happens + +With the wallet open, set its language: + +```bash +adb shell cmd locale set-app-locales net.taler.wallet.fdroid.debug --locales de-DE +``` + +The app comes back in German — on this screen: + +``` +Fehler +Beim Starten der Wallet ist ein Fehler aufgetreten. Dies kann nach einem +App-Update oder bei inkompatiblen Wallet-Daten passieren. Bitte versuche es +erneut, … +{ + "code": 7001, + "hint": "unexpected exception (message: could not acquire exclusive ownership + of the wallet database; another wallet process may still be using it)", + "message": null, + "stack": " at acquireSqliteWalletDbOwnership (<compiled_js>:34739:20)" +} +[Fehlerdiagnose exportieren] [Kopieren] [Teilen] +``` + +The configuration change restarts the app, the new instance asks wallet-core to +`init`, and wallet-core cannot take the SQLite database because the instance it +replaced has not let go of it yet. + +## Which changes do it + +Four everyday configuration changes, each applied while the wallet was open on +a settings sub-screen, then undone and the app relaunched: + +| Change | Init error | Still broken after relaunching | +| --- | --- | --- | +| app language (`cmd locale set-app-locales … de-DE`) | **yes** | no | +| system font size (`settings put system font_scale 1.30`) | **yes** | no | +| display size (`wm density 480`) | **yes** | no | +| dark mode (`cmd uimode night yes`) | no | — | + +Nothing is lost: killing the app and reopening it recovers, and undoing the +change is not necessary. But nothing *in* the app recovers. + +Dark mode is the exception for a reason — the manifest already handles it: + +```xml +<!-- wallet/src/main/AndroidManifest.xml:65 --> +android:configChanges="keyboardHidden|orientation|screenSize|uiMode" +``` + +`uiMode` and `orientation` are in that list, so dark mode and rotation never +recreate the activity. Locale, `fontScale` and `density` are not, so they do — +and that is the whole trigger. + +## Why it happens + +It is the same process throughout — measured, not assumed: + +``` +pid before: 13611 +pid after: 13611 +same process: True +init error: True +``` + +so the message's "another wallet process" is itself misleading: the lock is +held by the previous wallet instance *inside this process*, which was never +shut down. The activity's two lifecycle halves do not agree about that: + +```kotlin +// wallet/src/main/java/net/taler/wallet/main/MainActivity.kt:241 +model.startWallet() // in onCreate, unconditionally + +// wallet/src/main/java/net/taler/wallet/main/MainActivity.kt:414 +// wallet-core belongs to the retained MainViewModel, not to this activity +if (!isChangingConfigurations) model.stopWallet() +``` + +The `onDestroy` side is right, and its comment says why: wallet-core belongs to +the retained `MainViewModel`, so a configuration change must not shut it down. +The `onCreate` side then starts it again anyway. `startWallet()` is not +idempotent in the way that needs: + +```kotlin +// wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt:44 +fun startWallet() { + backendManager.run() // a no-op, it is already running + GlobalScope.launch(Dispatchers.IO) { sendInitMessage() } // a *second* init +} +``` + +`backendManager.run()` does nothing the second time — its `running` flag and +the static `coreRunning` guard both hold, and indeed "refusing to run a second +wallet-core in this process" never appears in the log. The second `init` +message is the problem: wallet-core logs it as a "repeat initialization" and +builds a fresh wallet on the same core, which then cannot take the SQLite +database from the instance still holding it. + +Whether it fails at all is a race with the old instance letting go — the same +change applied while the wallet sits on its home screen sometimes survives, and +wallet-core logs `request-finish-success` for the repeat init. That is why this +reproduces reliably from a settings sub-screen and only sometimes from the +balance screen. + +## Why the screen is a dead end + +`MainActivity` swaps the whole navigation graph for the error screen: + +```kotlin +// wallet/src/main/java/net/taler/wallet/main/MainActivity.kt:155 +initError?.let { error -> + WalletInitErrorScreen(model = model, error = error, …) +} ?: run { + WalletNavHost(…) +} +``` + +and `WalletInitErrorScreen` offers exactly two buttons — **Export logs** and +**Export database**. Meanwhile the message it shows says: + +```xml +<!-- res/values/strings.xml:70 --> +<string name="wallet_init_error_message">An error occurred while starting the +wallet. … Please retry, and if the problem persists, export the logs and report +this issue to the developers.</string> +``` + +There is nothing to retry *with*. `initError` is a `StateFlow` that is only +cleared by a later successful init: + +```kotlin +// wallet/src/main/java/net/taler/wallet/main/MainViewModel.kt:177,192 +override fun onInitErrorReceived(error: TalerErrorInfo) { mInitError.value = error } +override fun onInitReceived(init: InitResponse) { … mInitError.value = null … } +``` + +and nothing asks for another init. So for the life of that process the wallet is +a single screen with two export buttons. + +## Reproduce by hand + +1. Open the wallet and leave it on a settings sub-screen (Settings → Contacts + is where this was first seen). +2. Make one of the three changes: + * *App info → Language* for this app, or + `adb shell cmd locale set-app-locales <pkg> --locales de-DE`; + * *Settings → Display → Font size*, or + `adb shell settings put system font_scale 1.30`; + * *Settings → Display → Display size*, or `adb shell wm density 480`. +3. The wallet comes back on the Initialization error screen. With developer + mode on, the `7001` object quoted above is on screen; without it, the hint + alone. +4. Nothing on the screen gets the wallet back. Swiping the app away from the + task switcher and reopening it does. + +Undo with `--locales` (no value), `font_scale 1.0`, `wm density reset`. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_config_change_db_ownership.py emulator-5554 +``` + +It is also measured every round now, over all four changes at once: + +```bash +cd /opt/taler-sim/driver && SIM_WORKER=0 python3 -u suite.py config_changes +``` + +## Suggested fix + +The one-line version: **do not start the wallet again when it is already +running.** `MainActivity.onCreate` calls `startWallet()` on every activity +creation, while `onDestroy` deliberately does not stop it across a +configuration change; making the start side agree with the stop side — +`if (!model.walletRunning) model.startWallet()`, or moving the call into +`MainViewModel`'s initialiser, where the retained lifetime already lives — ends +it. + +Three smaller things are worth doing anyway, because each one would have turned +this into a non-event: + +1. **Make `init` idempotent, or wait briefly for the lock.** A repeat `init` + whose predecessor is still letting go of the database could reuse it or + retry for a few hundred milliseconds instead of failing. +2. **Retry init from the error screen.** The message already promises it: + "Please retry". A button calling `model.startWallet()` would honour the + promise, and would cover every other transient init failure as well. +3. **Say "the database is busy", not "unexpected exception".** 7001 with a + compiled-JavaScript stack trace is what the user is shown for a condition + the wallet understands perfectly well — and the text blames "another wallet + process", which measurement shows is this very process. diff --git a/simulator/findings/contacts-and-mailbox-cannot-be-translated.diff b/simulator/findings/contacts-and-mailbox-cannot-be-translated.diff @@ -0,0 +1,354 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/contacts/ContactScreen.kt b/wallet/src/main/java/net/taler/wallet/contacts/ContactScreen.kt +index d59b0b00..9bc840ec 100644 +--- a/wallet/src/main/java/net/taler/wallet/contacts/ContactScreen.kt ++++ b/wallet/src/main/java/net/taler/wallet/contacts/ContactScreen.kt +@@ -139,7 +139,12 @@ fun ContactScreen( + Scaffold( + topBar = { + TopAppBar( +- title = { Text(if (sendUri != null) "Send to Contact" else "Contacts") }, ++ title = { ++ Text(stringResource( ++ if (sendUri != null) R.string.contacts_send_title ++ else R.string.contacts_title ++ )) ++ }, + navigationIcon = { + IconButton(onClick = onNavigateBack) { + Icon( +@@ -152,7 +157,7 @@ fun ContactScreen( + }, + floatingActionButton = { + FloatingActionButton(onClick = { showAddDialog = true }) { +- Icon(Icons.Default.Add, contentDescription = "Add Contact") ++ Icon(Icons.Default.Add, contentDescription = stringResource(R.string.contacts_add)) + } + } + ) { innerPadding -> +@@ -167,14 +172,20 @@ fun ContactScreen( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp, vertical = 8.dp), +- placeholder = { Text("Search contacts...") }, ++ placeholder = { Text(stringResource(R.string.contacts_search)) }, + leadingIcon = { Icon(Icons.Default.Search, contentDescription = null) }, + singleLine = true, + ) + + when (val res = contactResult) { +- is ContactResult.Loading -> Text("Loading...", modifier = Modifier.padding(16.dp)) +- is ContactResult.Error -> Text("Error: ${res.error}", modifier = Modifier.padding(16.dp)) ++ is ContactResult.Loading -> Text( ++ stringResource(R.string.loading), ++ modifier = Modifier.padding(16.dp), ++ ) ++ is ContactResult.Error -> Text( ++ stringResource(R.string.contacts_error, res.error.toString()), ++ modifier = Modifier.padding(16.dp), ++ ) + is ContactResult.Success -> { + val filteredContacts = res.contacts.filter { contact -> + contact.petname.fuzzyMatches(searchQuery) || +@@ -196,8 +207,12 @@ fun ContactScreen( + contactToConfirm?.let { contact -> + AlertDialog( + onDismissRequest = { contactToConfirm = null }, +- title = { Text("Send to ${contact.petname}") }, +- text = { Text("Are you sure you want to send this to ${contact.petname}?") }, ++ title = { Text(stringResource(R.string.contacts_send_confirm_title, contact.petname)) }, ++ text = { ++ Text(stringResource( ++ R.string.contacts_send_confirm_message, contact.petname, ++ )) ++ }, + confirmButton = { + TextButton(onClick = { + model.mailboxManager.sendMessage(contact, sendUri!!) +@@ -290,19 +305,19 @@ fun AddContactDialog( + + AlertDialog( + onDismissRequest = onDismiss, +- title = { Text("Add Contact") }, ++ title = { Text(stringResource(R.string.contacts_add)) }, + text = { + Column(modifier = Modifier.verticalScroll(rememberScrollState())) { + OutlinedTextField( + value = petname, + onValueChange = { petname = it }, +- label = { Text("Petname") }, ++ label = { Text(stringResource(R.string.contacts_petname)) }, + modifier = Modifier.fillMaxWidth().padding(bottom = 8.dp) + ) + OutlinedTextField( + value = alias, + onValueChange = { alias = it }, +- label = { Text("Alias") }, ++ label = { Text(stringResource(R.string.contacts_alias)) }, + placeholder = { + Text( + if (aliasType == stringResource(R.string.alias_registration_alias_email)) { +@@ -327,7 +342,7 @@ fun AddContactDialog( + value = aliasType, + onValueChange = {}, + readOnly = true, +- label = { Text("Alias Type") }, ++ label = { Text(stringResource(R.string.contacts_alias_type)) }, + trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = aliasTypeExpanded) }, + colors = ExposedDropdownMenuDefaults.outlinedTextFieldColors(), + modifier = Modifier +@@ -354,7 +369,7 @@ fun AddContactDialog( + + if (isDuplicate) { + Text( +- text = "A contact with this alias and type already exists.", ++ text = stringResource(R.string.contacts_duplicate), + color = MaterialTheme.colorScheme.error, + style = MaterialTheme.typography.bodySmall, + modifier = Modifier.padding(bottom = 8.dp) +@@ -373,13 +388,13 @@ fun AddContactDialog( + enabled = alias.isNotBlank() && aliasType.isNotBlank(), + modifier = Modifier.fillMaxWidth().padding(bottom = 8.dp) + ) { +- Text("Lookup with Taldir") ++ Text(stringResource(R.string.contacts_lookup_taldir)) + } + } + + if (lookupResult is LookupResult.Error) { + Text( +- text = "Lookup failed: ${lookupResult.error.userFacingMsg}", ++ text = stringResource(R.string.contacts_lookup_failed, lookupResult.error.userFacingMsg), + color = MaterialTheme.colorScheme.error, + style = MaterialTheme.typography.bodySmall, + modifier = Modifier.padding(bottom = 8.dp) +@@ -389,7 +404,7 @@ fun AddContactDialog( + OutlinedTextField( + value = mailbox, + onValueChange = { mailbox = it }, +- label = { Text("Mailbox") }, ++ label = { Text(stringResource(R.string.contacts_mailbox)) }, + modifier = Modifier.fillMaxWidth().padding(bottom = 8.dp) + ) + } +@@ -425,7 +440,7 @@ fun ContactList( + onSelect: ((ContactEntry) -> Unit)? = null, + ) { + if (contacts.isEmpty()) { +- Text("No contacts yet.", modifier = Modifier.padding(16.dp)) ++ Text(stringResource(R.string.contacts_empty), modifier = Modifier.padding(16.dp)) + } else { + LazyColumn { + items(contacts) { contact -> +@@ -470,7 +485,7 @@ fun ContactItem( + Text(contact.mailboxBaseUri, style = MaterialTheme.typography.bodySmall) + } + IconButton(onClick = { onDelete(contact) }) { +- Icon(Icons.Default.Delete, contentDescription = "Delete") ++ Icon(Icons.Default.Delete, contentDescription = stringResource(R.string.transactions_delete)) + } + } + } +diff --git a/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt b/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt +index 01073ef5..053b8c3f 100644 +--- a/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt ++++ b/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt +@@ -111,7 +111,7 @@ fun MailboxScreen( + Scaffold( + topBar = { + TopAppBar( +- title = { Text("Mailbox") }, ++ title = { Text(stringResource(R.string.mailbox_title)) }, + navigationIcon = { + IconButton(onClick = onNavigateBack) { + Icon( +@@ -124,15 +124,15 @@ fun MailboxScreen( + val state = mailboxState + if (state is MailboxResult.Success) { + IconButton(onClick = { showAddressDialog = true }) { +- Icon(Icons.Default.Info, contentDescription = "Show Mailbox Address") ++ Icon(Icons.Default.Info, contentDescription = stringResource(R.string.mailbox_show_address)) + } + } + IconButton(onClick = { showUrlDialog = true }) { +- Icon(Icons.Default.Settings, contentDescription = "Configure Mailbox") ++ Icon(Icons.Default.Settings, contentDescription = stringResource(R.string.mailbox_configure)) + } + if (state is MailboxResult.Success) { + IconButton(onClick = { mailboxManager.refreshMailbox(state.config) }) { +- Icon(Icons.Default.Refresh, contentDescription = "Refresh") ++ Icon(Icons.Default.Refresh, contentDescription = stringResource(R.string.mailbox_refresh)) + } + } + } +@@ -146,8 +146,14 @@ fun MailboxScreen( + .padding(innerPadding) + ) { + when (val res = mailboxState) { +- is MailboxResult.Loading -> Text("Loading...", modifier = Modifier.padding(16.dp)) +- is MailboxResult.Error -> Text("Error: ${res.error}", modifier = Modifier.padding(16.dp)) ++ is MailboxResult.Loading -> Text( ++ stringResource(R.string.loading), ++ modifier = Modifier.padding(16.dp), ++ ) ++ is MailboxResult.Error -> Text( ++ stringResource(R.string.mailbox_error, res.error.toString()), ++ modifier = Modifier.padding(16.dp), ++ ) + is MailboxResult.Success -> { + MessageList(res.messages, onNavigate) { message -> + mailboxManager.deleteMessage(res.config, message) +@@ -161,9 +167,10 @@ fun MailboxScreen( + val state = mailboxState + if (state is MailboxResult.Success) { + val mailboxAddressURI = "${state.config.mailboxBaseUrl}/${state.config.hAddress}" ++ val addressCopiedMessage = stringResource(R.string.mailbox_address_copied) + AlertDialog( + onDismissRequest = { showAddressDialog = false }, +- title = { Text("Your Mailbox Address") }, ++ title = { Text(stringResource(R.string.mailbox_your_address)) }, + text = { + Text(mailboxAddressURI) + }, +@@ -171,7 +178,7 @@ fun MailboxScreen( + TextButton(onClick = { + clipboardManager.setText(AnnotatedString(mailboxAddressURI)) + scope.launch { +- snackbarHostState.showSnackbar("Mailbox address URI copied to clipboard") ++ snackbarHostState.showSnackbar(addressCopiedMessage) + } + showAddressDialog = false + }) { +@@ -191,12 +198,12 @@ fun MailboxScreen( + var url by remember { mutableStateOf("https://mailbox.gnunet.org") } + AlertDialog( + onDismissRequest = { showUrlDialog = false }, +- title = { Text("Configure Mailbox URL") }, ++ title = { Text(stringResource(R.string.mailbox_configure_url)) }, + text = { + OutlinedTextField( + value = url, + onValueChange = { url = it }, +- label = { Text("Mailbox Base URL") }, ++ label = { Text(stringResource(R.string.mailbox_base_url)) }, + modifier = Modifier.fillMaxWidth() + ) + }, +@@ -224,7 +231,7 @@ fun MessageList( + onDelete: (MailboxMessageRecord) -> Unit, + ) { + if (messages.isEmpty()) { +- Text("No messages yet.", modifier = Modifier.padding(16.dp)) ++ Text(stringResource(R.string.mailbox_empty), modifier = Modifier.padding(16.dp)) + } else { + LazyColumn { + items(messages) { message -> +@@ -255,22 +262,28 @@ fun MessageItem( + Button( + onClick = { onNavigate(WalletDestination.HandleUri(message.talerUri), false) } + ) { +- Text(if (isPayPush) "Accept payment" else "Pay invoice") ++ Text(stringResource( ++ if (isPayPush) R.string.mailbox_accept_payment ++ else R.string.mailbox_pay_invoice ++ )) + } + } else { + Text(message.talerUri, style = MaterialTheme.typography.bodyMedium) + } + Text( +- "From: ${message.originMailboxBaseUrl}", ++ stringResource(R.string.mailbox_from, message.originMailboxBaseUrl), + style = MaterialTheme.typography.bodySmall + ) + Text( +- "Received: ${message.downloadedAt.ms.toAbsoluteTime(context)}", ++ stringResource( ++ R.string.mailbox_received, ++ message.downloadedAt.ms.toAbsoluteTime(context), ++ ), + style = MaterialTheme.typography.bodySmall + ) + } + IconButton(onClick = { onDelete(message) }) { +- Icon(Icons.Default.Delete, contentDescription = "Delete") ++ Icon(Icons.Default.Delete, contentDescription = stringResource(R.string.transactions_delete)) + } + } + } +diff --git a/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt b/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt +index 5d904900..afadd1e7 100644 +--- a/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt ++++ b/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt +@@ -254,22 +254,22 @@ fun SettingsScreen( + ) + + SettingsItem( +- title = "Contacts", +- summary = "Contacts", ++ title = stringResource(R.string.contacts_title), ++ summary = stringResource(R.string.settings_contacts_summary), + icon = Icons.Default.Person, + onClick = { onNavigate(WalletDestination.Contacts(), false) } + ) + + SettingsItem( +- title = "Mailbox", +- summary = "P2P Messaging", ++ title = stringResource(R.string.mailbox_title), ++ summary = stringResource(R.string.mailbox_summary), + icon = ImageVector.vectorResource(R.drawable.ic_adjust), + onClick = { onNavigate(WalletDestination.Mailbox, false) } + ) + + SettingsItem( + title = stringResource(R.string.alias_registration_title), +- summary = "Taldir Registration", ++ summary = stringResource(R.string.settings_taldir_summary), + icon = Icons.Default.Person, + onClick = { onNavigate(WalletDestination.AliasRegistration, false) } + ) +diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml +index 905e4390..eb80f552 100644 +--- a/wallet/src/main/res/values/strings.xml ++++ b/wallet/src/main/res/values/strings.xml +@@ -519,6 +519,40 @@ GNU Taler is immune to many types of fraud such as credit card data theft, phish + <string name="contact_mailbox_base_uri">Mailbox Base URI</string> + <string name="contact_petname">Petname</string> + <string name="contacts_title">Contacts</string> ++ <!-- Contacts --> ++ <string name="contacts_send_title">Send to Contact</string> ++ <string name="contacts_add">Add Contact</string> ++ <string name="contacts_search">Search contacts…</string> ++ <string name="contacts_empty">No contacts yet.</string> ++ <string name="contacts_error">Error: %1$s</string> ++ <string name="contacts_send_confirm_title">Send to %1$s</string> ++ <string name="contacts_send_confirm_message">Are you sure you want to send this to %1$s?</string> ++ <string name="contacts_petname">Petname</string> ++ <string name="contacts_alias">Alias</string> ++ <string name="contacts_alias_type">Alias Type</string> ++ <string name="contacts_mailbox">Mailbox</string> ++ <string name="contacts_lookup_taldir">Lookup with Taldir</string> ++ <string name="contacts_lookup_failed">Lookup failed: %1$s</string> ++ <string name="contacts_duplicate">A contact with this alias and type already exists.</string> ++ <!-- Mailbox --> ++ <string name="mailbox_title">Mailbox</string> ++ <string name="mailbox_summary">P2P Messaging</string> ++ <string name="mailbox_show_address">Show Mailbox Address</string> ++ <string name="mailbox_configure">Configure Mailbox</string> ++ <string name="mailbox_refresh">Refresh</string> ++ <string name="mailbox_error">Error: %1$s</string> ++ <string name="mailbox_your_address">Your Mailbox Address</string> ++ <string name="mailbox_address_copied">Mailbox address URI copied to clipboard</string> ++ <string name="mailbox_configure_url">Configure Mailbox URL</string> ++ <string name="mailbox_base_url">Mailbox Base URL</string> ++ <string name="mailbox_empty">No messages yet.</string> ++ <string name="mailbox_accept_payment">Accept payment</string> ++ <string name="mailbox_pay_invoice">Pay invoice</string> ++ <string name="mailbox_from">From: %1$s</string> ++ <string name="mailbox_received">Received: %1$s</string> ++ <!-- Settings entries for the two above --> ++ <string name="settings_contacts_summary">Manage the people you send to</string> ++ <string name="settings_taldir_summary">Taldir Registration</string> + + <!-- Settings --> + diff --git a/simulator/findings/contacts-and-mailbox-cannot-be-translated.md b/simulator/findings/contacts-and-mailbox-cannot-be-translated.md @@ -0,0 +1,177 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Two whole features are untranslatable, and nothing in the repo can tell + +Found while reading the contacts screens for the alias-registration work: every +label on them is an English string literal in the Compose source rather than an +entry in `strings.xml`. + +**Severity: moderate.** The wallet ships 19 translations and the project keeps a +135-term glossary in 27 languages (`dictionary.md`), but the contacts and +mailbox features will be English in all of them, and no amount of translation +work can change that. Two strings on the *payment prompt* — a screen every user +sees — are in the same state, as is the transaction list's selection counter. + +## What happens + +`res/values/strings.xml` is the source of truth for translations, and +`./check-translations.py` compares every `values-<lang>/strings.xml` against +it. A literal passed to a Composable is in neither file, so it is invisible to +both the translators and the checker: coverage reads 100 % while the screen is +half English. + +Set the wallet's language to German and the whole UI follows — except these: + +| Where | Untranslatable, user-visible strings | +| --- | --- | +| `contacts/ContactScreen.kt` | 18 — the screen title (`Contacts`, or `Send to Contact` when forwarding a payment), `Add Contact`, `Petname`, `Alias`, `Alias Type`, `Mailbox`, `Lookup with Taldir`, `Search contacts...`, `No contacts yet.`, `Loading...`, `Error: …`, `Lookup failed: …`, `A contact with this alias and type already exists.`, `Send to <petname>`, `Are you sure you want to send this to <petname>?`, and the `Add Contact`/`Delete` content descriptions | +| `mailbox/MailboxScreen.kt` | 16 — `Mailbox`, `Your Mailbox Address`, `Configure Mailbox URL`, `Mailbox Base URL`, `No messages yet.`, `Loading...`, `Error: …`, the `Accept payment` and `Pay invoice` buttons on a message, its `From: …` and `Received: …` lines, the `Mailbox address URI copied to clipboard` toast, and the `Show Mailbox Address`/`Configure Mailbox`/`Refresh`/`Delete` content descriptions | +| `settings/SettingsScreen.kt:257-272` | 5 — the `Contacts` and `Mailbox` entries with their summaries (`Contacts`, `P2P Messaging`), and the `Taldir Registration` summary | +| `contacts/ContactManager.kt:169` | `Alias not found` | +| `payment/PaymentManager.kt:395` | `The order could not be found. Maybe the merchant deleted it.` | +| `main/MainViewModel.kt:503` | `Database migration completed without switching to SQLite` | +| `compose/ExpandableCard.kt:96` | the `Drop Down Arrow` content description | + +**43 strings in all.** Three more (`Error`, `Event`, `Bitcoin`) are `ClipData` +labels on copy buttons, which some Android versions show in the "copied" toast. +Everything else a literal scan turns up is `@Preview` fixture data, commented +out, a `@Deprecated` message, a log line, a wallet-core operation name, or a +token that should not be translated (`payto://`, `https://`, `Cy` for Cyclos). + +The drift is visible inside a single call. The third settings entry in that +block takes its title from a resource and hard-codes its summary: + +```kotlin +// wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt:271 +SettingsItem( + title = stringResource(R.string.alias_registration_title), + summary = "Taldir Registration", +``` + +Two details sharpen it: + +* **`contacts_title` already exists** in `strings.xml` (`<string + name="contacts_title">Contacts</string>`) and is translated in the shipped + languages — but it is used for the *forward* button on a peer transaction + (`compose/QrCodeUriComposable.kt:199`), while the settings entry that opens + the contacts screen hard-codes the same word. One of the two spellings of + "Contacts" in this app is translatable and the other is not. +* **The neighbouring file gets it right.** + `contacts/AliasRegistrationScreen.kt`, in the same package, uses + `stringResource` for all 14 of its labels. So this is drift, not a + convention. + +One literal that a scan flags is *not* a live defect, and is worth naming so +nobody re-files it: `compose/SelectionModeTopAppBar.kt:48` renders +`"${selectedItems.size} selected"`, but that composable has no caller — +`TransactionsScreen` implements selection mode inline and uses +`stringResource(R.string.selection_count, …)` for the same text. The dead copy +is the hard-coded one. + +That live resource has a smaller problem of its own: + +```xml +<!-- res/values/strings.xml:93 --> +<string name="selection_count">%1$d selected</string> +``` + +A count belongs in a `<plurals>` resource; as a single string it cannot be +declined in languages that need it, and "1 selected" is wrong in several of the +19 the wallet ships. + +## Why the tooling misses it + +The repo's defences are both aimed at `strings.xml`: + +* `./check-translations.py` reads `values*/strings.xml` and reports missing or + extra keys, format-argument mismatches and string-array lengths. A string + that was never a resource cannot be missing from a translation. +* Android lint's `HardcodedText` check only looks at layout XML. These screens + are Compose, so there is no layout file and nothing is flagged — `wallet` + builds with `abortOnError true` and `ignoreWarnings false` and still passes. + +## Reproduce by hand + +The per-app language setting needs no root (Android 13+): + +```bash +adb shell cmd locale set-app-locales net.taler.wallet.fdroid.debug --locales de-DE +adb shell am force-stop net.taler.wallet.fdroid.debug # see the note below +# open the wallet: it reads "Willkommen bei Taler Wallet!", "QR-Code scannen", +# "Einstellungen" … +# and Settings, in German, lists "Contacts" and "Mailbox" +adb shell cmd locale set-app-locales net.taler.wallet.fdroid.debug --locales # undo +``` + +Expected: the two entries, and everything behind them, in the device's +language. + +The `force-stop` is not politeness: changing the language *without* restarting +the wallet drops it on its initialization error screen, which is a separate +defect — [`config-change-locks-the-wallet-out-of-its-database.md`](config-change-locks-the-wallet-out-of-its-database.md). + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_untranslated_contacts_mailbox.py emulator-5554 +``` + +It sets the language, restarts the wallet, and then walks to both screens — +needing `Settings|Einstellungen` to find its way and plain English for +everything after that: + +``` +the wallet is in German: ['Einstellungen', 'QR-Code scannen', + 'Willkommen bei Taler Wallet', 'abheben'] + home screen: Wallet | Willkommen bei Taler Wallet! | Um Ihre erste Zahlung + zu tätigen, heben Sie digitales Bargeld ab | CHF abheben | … | + Einstellungen | Internes Ereignisprotokoll | QR-Code scannen + +=== Contacts (reached by its English name) + Search contacts... | No contacts yet. | Contacts | Add Contact + 3 untranslatable labels: ['Add Contact', 'No contacts yet', 'Search contacts'] + +=== Mailbox (reached by its English name) + No messages yet. | Mailbox | Show Mailbox Address | Configure Mailbox | Refresh + 2 untranslatable labels: ['No messages yet', 'Mailbox'] + +reproduced: True (5 English labels in a German wallet, plus the two settings +entries that opened them) +``` + +Five is all an empty wallet shows; the other 39 need a contact, a message, a +lookup or an error to be on screen. The table above is from the sources, not +from this run. + +## Suggested fix + +Move the literals into `res/values/strings.xml` and reference them with +`stringResource`, as `AliasRegistrationScreen.kt` already does, and give the +settings entry a resource of its own rather than hard-coding the word that +`contacts_title` already holds. Separately, make `selection_count` a +`<plurals>`. The content descriptions matter twice over, since they are what a +screen reader announces — see +[`action-buttons-have-no-accessible-name.md`](action-buttons-have-no-accessible-name.md). + +To stop it coming back, something has to look at Kotlin rather than at XML. The +scan that produced the table above is three lines of Python over +`wallet/src/main/java`, matching string literals passed to `Text(…)` and to the +`title`/`label`/`placeholder`/`contentDescription` parameters, and skipping +`@Preview` bodies; as a check in `./check-translations.py` it would have caught +each of these the day it was written. diff --git a/simulator/findings/delete-transaction-requeries-deleted-id.diff b/simulator/findings/delete-transaction-requeries-deleted-id.diff @@ -0,0 +1,71 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt +index d7e95ce6..d6ed35d4 100644 +--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt ++++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt +@@ -37,6 +37,9 @@ import net.taler.wallet.balances.ScopeInfo + import net.taler.wallet.transactions.TransactionAction.Delete + import org.json.JSONObject + ++/** How many deleted transaction ids to remember, to recognise their transitions. */ ++private const val DELETED_IDS_REMEMBERED = 32 ++ + sealed class TransactionsResult { + data object None : TransactionsResult() + data class Error(val error: TalerErrorInfo) : TransactionsResult() +@@ -93,6 +96,30 @@ class TransactionManager( + val selectedTransaction = mSelectedTransaction.asStateFlow() + val selectedTransferOption = mSelectedTransferOption.asStateFlow() + ++ /** ++ * Ids this wallet has deleted, so their transition notifications can be ++ * ignored. ++ * ++ * Deleting a transaction makes wallet-core emit transitions for it, and ++ * [onTransactionStateTransition] asks for the transaction before it can ++ * know what the transition was -- which after a deletion is a request for ++ * something that no longer exists: 7052, logged at error level, three ++ * times per deletion. An id never comes back, so a bounded set is enough. ++ */ ++ private val deletedIds = LinkedHashSet<String>() ++ ++ @Synchronized ++ private fun rememberDeleted(transactionId: String) { ++ deletedIds.add(transactionId) ++ while (deletedIds.size > DELETED_IDS_REMEMBERED) { ++ val oldest = deletedIds.first() ++ deletedIds.remove(oldest) ++ } ++ } ++ ++ @Synchronized ++ private fun wasDeleted(transactionId: String) = transactionId in deletedIds ++ + /** + * Streams the [RECENT_LIMIT] most recent transactions for [scopeInfo], as + * shown on the balances screen. +@@ -168,6 +195,9 @@ class TransactionManager( + * not been requested yet are left untouched. + */ + fun onTransactionStateTransition(transactionId: String) = scope.launch { ++ // Nothing to refresh and no scope to reload for a transaction we ++ // deleted; asking is what filled the log with 7052 errors. ++ if (wasDeleted(transactionId)) return@launch + val transaction = getTransactionById(transactionId) + + if (transaction != null && mSelectedTransactionId.value == transactionId) { +@@ -282,6 +312,7 @@ class TransactionManager( + + fun deleteTransaction(transactionId: String, onError: (it: TalerErrorInfo) -> Unit) = + scope.launch { ++ rememberDeleted(transactionId) + api.request<Unit>("deleteTransaction") { + put("transactionId", transactionId) + }.onError { +@@ -357,6 +388,7 @@ class TransactionManager( + fullTransactions.values.flatten().filter { transaction -> + transaction.transactionId in transactionIds && Delete in transaction.txActions + }.forEach { toBeDeletedTx -> ++ rememberDeleted(toBeDeletedTx.transactionId) + api.request<Unit>("deleteTransaction") { + put("transactionId", toBeDeletedTx.transactionId) + }.onError { diff --git a/simulator/findings/delete-transaction-requeries-deleted-id.md b/simulator/findings/delete-transaction-requeries-deleted-id.md @@ -0,0 +1,117 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Deleting a transaction makes the app immediately ask wallet-core for it again + +Found by the `history_delete` scenario, which reproduces it on **every run** — +five rounds so far, three stray requests each. + +**Severity: low.** Nothing visible goes wrong — the row disappears and the user +is returned to the list — but every deletion leaves an error in the log, which +is noise in exactly the place one looks when triaging a real problem. + +## What happens + +Deleting a transaction from its detail screen deletes it, and then the screen +asks for it once more: + +``` +{"type":"error","operation":"getTransactionById","id":78, + "error":{"code":7052, + "hint":"transaction txn:payment:7W5B3DR0…X5Z0 not found", + "transactionId":"txn:payment:7W5B3DR0…X5Z0"}} +``` + +wallet-core also records it as a failed database query +(`db-query-finish-error` at `handleTxRetries/runWalletDbTx`). Three such +requests go out per deletion, consistently: + +```console +$ for d in /opt/taler-sim/run/out/*history_delete; do + echo "$(basename $d): $(grep -c '"code":7052' $d/logcat.txt)"; done +suite-w1-1792268945-history_delete: 3 +suite-w1-1792270256-history_delete: 3 +suite-w1-1792272286-history_delete: 3 +suite-w1-1792274698-history_delete: 3 +suite-w1-1792277245-history_delete: 3 +``` + +The error code makes it worse: 7052 (`WALLET_TRANSACTION_NOT_FOUND`) is not in +the app's `TalerErrorCode.kt`, so even if the app wanted to recognise this case +it could not — see `error-code-registry-behind-wallet-core.md`. + +## Reproduce by hand + +1. Install a debug build, enable **Developer mode** in Settings. +2. Get a transaction into the wallet: withdraw once, or pay for something + (against the local stack from `simulator/README.md`, or any deployment). +3. Start `adb logcat | grep -E 'getTransactionById|7052'` in a terminal. +4. On the main screen, under **Recent transactions**, tap the transaction. +5. On the detail screen tap **Delete**, then confirm **Delete** in the dialog. + +The list comes back without the row, and the log shows the +`getTransactionById` request for the id that was just deleted, answered with +"transaction … not found". + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_delete_requeries_transaction.py +``` + +Prints the stray error lines and `reproduced: True`. + +## Why + +Not the detail screen's observer, which is what this finding first said — the +requests come from the notification handler, and clearing the selection would +not stop one of them. + +Deleting a transaction makes wallet-core emit transaction-state-transition +notifications for it, and the handler asks for the transaction *before* it can +know what the transition was: + +```kotlin +// wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt:170 +fun onTransactionStateTransition(transactionId: String) = scope.launch { + val transaction = getTransactionById(transactionId) // 7052 after a delete + … + if (transaction == null) return@launch +``` + +It needs the transaction for two things — refreshing the copy the detail screen +is showing, and learning which scopes' lists to reload — and after a deletion +neither applies, but the query has already gone out. A deletion emits several +transitions, which is why exactly three requests appear rather than one. + +`getTransactionById` then logs every failure at error level +(`Log.e(TAG, "Error getting transaction $it")`), so each one lands in the log +as an error. + +## Suggested fix + +Remember the ids this wallet has just deleted and let the handler skip them: +the transaction is gone, so there is nothing to refresh and no scope to +reload. A small bounded set is enough — an id cannot come back, and only the +transitions that follow the deletion matter. + +Treating 7052 as an expected outcome instead would also work, but the app +cannot currently recognise it: `WALLET_TRANSACTION_NOT_FOUND` is not in +`TalerErrorCode.kt`, so the code does not survive deserialization (see +`error-code-registry-behind-wallet-core.md`). That makes the id-based fix the +one that can be written today. diff --git a/simulator/findings/deposit-does-not-guard-zero-amounts.md b/simulator/findings/deposit-does-not-guard-zero-amounts.md @@ -0,0 +1,102 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# The deposit screen does not guard zero or below-fee amounts + +Found by the `deposit_flow` scenario; the oracles flagged the internal error +and the transaction that came out of it looked wrong, which led to the second +half. + +**Severity: low-moderate.** Both halves are reachable by any user with a +balance, in a release build, from Settings-free navigation (the balance card's +**Deposit** button). + +## Half one: clearing the amount raises an internal error + +Type an amount, then tap **Reset**. The screen goes back to €0.00 and the app +prices the empty deposit: + +``` +{"type":"error","operation":"checkDeposit","id":50,"error":{"code":7001, + "hint":"unexpected exception (message: can't sum zero amounts)", + "stack":" at sum (<compiled_js>:5729:18) + at getCounterpartyEffectiveDepositAmount (<compiled_js>:70346:38)"}} +``` + +`WALLET_UNEXPECTED_EXCEPTION` — wallet-core treating it as a bug rather than as +a request it can decline. Nothing is shown; it repeats as the debounce fires. + +## Half two: an amount at or below the fee produces a zero deposit + +With a deposit fee of EUR:0.01, entering **0.01** and tapping **Make deposit** +creates a transaction that reads: + +``` +This transaction is finalizing +Chosen amount €0.00 +Fee -€0.01 +Amount sent -€0.01 +``` + +"Show JSON" confirms the wallet stored exactly that: + +```json +"amountRaw": "EUR:0", +"amountEffective": "EUR:0.01" +``` + +So the user asked to deposit one cent, the wallet deposited nothing, charged a +cent, and displays a negative "Amount sent" — while the deposit itself goes +through to the exchange. + +## Reproduce by hand + +Needs a wallet with a balance (withdraw once first). + +1. On the main screen tap **Deposit**. +2. Pick the bank account offered (e.g. `wallet1`). +3. Type `500` — the field fills from the right, so this is €5.00 — then tap + **Reset**. With `adb logcat | grep -i "sum zero"` running, the internal + error appears within a second or two. +4. Now type `1` (€0.01) and tap **Make deposit**. +5. The transaction screen shows "Chosen amount €0.00", "Fee −€0.01", + "Amount sent −€0.01". + +Expected: an amount of zero is not worth pricing, and an amount that cannot +cover the fee should be refused with a message — the screen already has +`R.string.amount_invalid` ("Amount invalid") and `amount_excess` for the +opposite bound. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_zero_deposit.py +``` + +## Suggested fix + +In `deposit/DepositAmountComposable.kt`, skip the `checkDeposit` call while the +amount is zero (the debounce already has the amount in hand), and disable +**Make deposit** until the amount is strictly greater than the fee reported by +`checkDeposit`, showing `amount_invalid` otherwise. Mirroring the +"Insufficient balance" treatment at the upper bound would make the two +boundaries consistent. + +Worth raising with wallet-core as well: `checkDeposit` of a zero amount is a +client asking a reasonable question, so a declined request would be a better +answer than an unexpected exception. diff --git a/simulator/findings/dev-experiment-uri-exits-the-app.md b/simulator/findings/dev-experiment-uri-exits-the-app.md @@ -0,0 +1,112 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# An unknown `dev-experiment` URI closes the wallet, and its error is never shown + +Found by the `uri_dev_experiment` scenario. + +**Severity: low** — `taler://dev-experiment/` is only accepted in developer +mode. What makes it worth fixing is the shape of the failure: the error is +collected into a variable that nothing will ever display, and the user is +dropped onto the Android home screen. + +## What happens + +Sharing `taler+http://dev-experiment/nonexistent` into the wallet: + +* wallet-core answers with `WALLET_UNEXPECTED_EXCEPTION` (7001): + `unexpected exception (message: dev-experiment id not understood nonexistent)` +* the wallet **leaves the foreground**: the next screen is the launcher, not + the wallet. This happens when the URI arrives while the wallet is closed — + scanning a QR code or following a link, which is the ordinary case. With the + wallet already open the screen pops back to the main screen instead, so the + error is merely invisible rather than disruptive. + +The simulator recorded the screen after the URI as +`['At a glance', 'Sat, Oct 17', 'Gmail', 'Photos', 'YouTube', …]` — the +emulator's home screen. + +An empty id (`taler+http://dev-experiment/`) behaves differently and correctly: +the wallet stays open on the main screen. + +## Reproduce by hand + +1. Install a debug build and enable **Developer mode**. +2. Close the wallet (swipe it away, or + `adb shell am force-stop net.taler.wallet.fdroid.debug`) — the URI has to + arrive while it is not running. +3. Run `adb logcat | grep applyDevExperiment` in a terminal. +4. Share the URI into the wallet, e.g. + + ```bash + adb shell am start -a android.intent.action.SEND -t text/plain \ + -n net.taler.wallet.fdroid.debug/net.taler.wallet.main.MainActivity \ + --es android.intent.extra.TEXT 'taler+http://dev-experiment/nonexistent' + ``` + + (A QR code with the same text, scanned from the wallet, does the same.) +5. The wallet opens, closes again and the home screen appears. The log shows + the 7001 error; nothing is shown in the app. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_dev_experiment_uri_exits_app.py +``` + +## Why + +`wallet/src/main/java/net/taler/wallet/HandleUriScreen.kt:128`: + +```kotlin +action.startsWith("dev-experiment/", ignoreCase = true) -> { + model.applyDevExperiment(u2) { error -> + errorInfo = error + } + onNavigateBack() +} +``` + +`applyDevExperiment` is asynchronous, and `onNavigateBack()` runs immediately, +without waiting for it. Two consequences: + +* the error callback assigns to `errorInfo` after the screen that would render + it has already been popped, so the message is lost; +* when the URI arrived from outside (a share or a scan), there is nothing + behind this screen, so popping it finishes the activity and the user lands + on the home screen. + +Every other branch in the same `when` navigates *forward* to a screen that +reports its own outcome; this is the only one that pops first. + +## Suggested fix + +Navigate back only on success, and let the error render: + +```kotlin +action.startsWith("dev-experiment/", ignoreCase = true) -> { + model.applyDevExperiment(u2) { error -> + errorInfo = error // stays on screen, shows the sheet + } + // onNavigateBack() only once applyDevExperiment reports success +} +``` + +Separately, "dev-experiment id not understood" is a user-supplied value being +rejected, so wallet-core returning `WALLET_UNEXPECTED_EXCEPTION` for it is +arguably wrong as well; a dedicated code would let the app say what happened. diff --git a/simulator/findings/donation-statements-button-is-wired-to-nothing.diff b/simulator/findings/donation-statements-button-is-wired-to-nothing.diff @@ -0,0 +1,80 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/balances/BalancesPagerComposable.kt b/wallet/src/main/java/net/taler/wallet/balances/BalancesPagerComposable.kt +index c2a8b928..0a09738c 100644 +--- a/wallet/src/main/java/net/taler/wallet/balances/BalancesPagerComposable.kt ++++ b/wallet/src/main/java/net/taler/wallet/balances/BalancesPagerComposable.kt +@@ -193,6 +193,7 @@ fun BalancesPagerComposable( + onShowPendingOutgoing: (ScopeInfo) -> Unit, + onShowDiscounts: (ScopeInfo?) -> Unit, + onShowPasses: (ScopeInfo?) -> Unit, ++ onShowStatements: (host: String?) -> Unit, + ) { + if (state.showWelcome()) { + return EmptyBalancesComposable( +@@ -254,7 +255,7 @@ fun BalancesPagerComposable( + onWithdrawMoneyClicked = onWithdrawMoney, + onGetDemoMoneyClicked = onGetDemoMoney, + onBalanceClicked = onBalanceSelected, +- onStatementClicked = { onBalanceSelected(null) } ++ onStatementClicked = { host -> onShowStatements(host) } + ) + } else { + val scope = balance.scopeInfo +@@ -280,7 +281,7 @@ fun BalancesPagerComposable( + onShowAllTransactions = { onShowAllTransactions(scope) }, + onShowPendingIncoming = { onShowPendingIncoming(scope) }, + onShowPendingOutgoing = { onShowPendingOutgoing(scope) }, +- onShowStatements = { onBalanceSelected(null) }, ++ onShowStatements = { onShowStatements(null) }, + onShowDiscounts = { onShowDiscounts(scope) }, + onShowPasses = { onShowPasses(scope) }, + ) +@@ -801,6 +802,7 @@ fun BalancesPagerComposablePreview() { + onShowPendingOutgoing = {}, + onShowDiscounts = {}, + onShowPasses = {}, ++ onShowStatements = {}, + ) + } + } +\ No newline at end of file +diff --git a/wallet/src/main/java/net/taler/wallet/main/MainScreen.kt b/wallet/src/main/java/net/taler/wallet/main/MainScreen.kt +index bd913dd9..4d22253d 100644 +--- a/wallet/src/main/java/net/taler/wallet/main/MainScreen.kt ++++ b/wallet/src/main/java/net/taler/wallet/main/MainScreen.kt +@@ -59,6 +59,7 @@ import net.taler.wallet.balances.BalanceState + import net.taler.wallet.balances.BalancesPagerComposable + import net.taler.wallet.compose.GlobalScaffold + import net.taler.wallet.compose.collectAsStateLifecycleAware ++import net.taler.wallet.donau.GetDonauStatus + import net.taler.wallet.scan.ScanTab + import net.taler.wallet.transactions.TransactionStateFilter + import net.taler.wallet.transactions.onTransactionClicked +@@ -81,6 +82,7 @@ fun MainScreen( + val balanceState by model.balanceManager.state.observeAsState(BalanceState.None) + val viewMode by model.viewMode.collectAsStateLifecycleAware() + val devMode by model.devMode.observeAsState(false) ++ val donauStatus by model.donauManager.donauStatus.collectAsStateLifecycleAware() + val txResults = remember(balanceState) { + (balanceState as? BalanceState.Success)?.let { state -> + state.balances.associate { balance -> +@@ -214,6 +216,20 @@ fun MainScreen( + onShowPasses = { + onNavigate(WalletDestination.PassList, false) + }, ++ onShowStatements = { host -> ++ // A statement row knows which donau it belongs to; the action ++ // button on a balance does not, so it falls back to the one ++ // the wallet is configured with -- and sends the user to the ++ // setup screen when there is none, rather than doing nothing. ++ val configured = (donauStatus as? GetDonauStatus.Success) ++ ?.donauInfo?.donauBaseUrl ++ val donau = host ?: configured ++ if (donau != null) { ++ onNavigate(WalletDestination.DonauStatement(donau), false) ++ } else { ++ onNavigate(WalletDestination.SetDonau(), false) ++ } ++ }, + ) + } + } diff --git a/simulator/findings/donation-statements-button-is-wired-to-nothing.md b/simulator/findings/donation-statements-button-is-wired-to-nothing.md @@ -0,0 +1,132 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# "Donation statements" does nothing, and its whole screen is unreachable + +The random exploration kept reporting this and it kept being filed as noise: + +``` +[silent-failure] tapping 'Donation statements' changed nothing on screen +``` + +It is not noise. The button is wired to a no-op, and behind it sits a complete +feature that nothing in the app can open. + +**Severity: moderate.** A labelled button on the main balance screen does +nothing when tapped — no navigation, no message, no change. Two composables +(~90 lines), a registered navigation destination and a wallet-core operation +are dead because of it. + +## What happens + +On the balance screen, the row under the recent transactions has three action +buttons: **Discounts**, **Passes**, **Donation statements**. The first two +open their screens. The third does nothing at all. + +If the wallet holds donau receipts, the balances list also shows a +**Donation statements** section whose rows look tappable. They do nothing +either. + +## Why + +The three buttons sit in one row, and two of them are wired to navigation +while the third is wired to clearing the balance selection: + +```kotlin +// wallet/src/main/java/net/taler/wallet/balances/BalancesPagerComposable.kt:283 +onShowStatements = { onBalanceSelected(null) }, +onShowDiscounts = { onShowDiscounts(scope) }, +onShowPasses = { onShowPasses(scope) }, +``` + +and `onBalanceSelected` only changes which balance is displayed: + +```kotlin +// wallet/src/main/java/net/taler/wallet/main/MainScreen.kt:171 +onBalanceSelected = { model.displayScope(it?.scopeInfo) }, +``` + +With `null` that is a no-op from the user's point of view. The statement rows +in the list have the same handler: + +```kotlin +// wallet/src/main/java/net/taler/wallet/balances/BalancesPagerComposable.kt:257 +onStatementClicked = { onBalanceSelected(null) } +``` + +even though `BalancesListComposable` passes a real argument for it — +`onStatementClicked(statement.donauBaseUrl)` — which is exactly the `host` the +statement screen wants. + +## What is unreachable as a result + +* `WalletDestination.DonauStatement(host)` is declared + (`WalletNavigation.kt:70`) and registered in the nav host + (`WalletNavHost.kt:291`), and **nothing navigates to it**: + + ```bash + $ grep -rn 'WalletDestination.DonauStatement' --include=*.kt wallet/src/main/java + WalletNavHost.kt:291: composable<WalletDestination.DonauStatement> { backStackEntry -> + WalletNavHost.kt:292: val dest = backStackEntry.toRoute<WalletDestination.DonauStatement>() + ``` + +* `DonauStatementScreen` (35 lines) and `DonauStatementComposable` (55 lines) + therefore never render — they read 0 % in every coverage report of this + campaign. +* `getDonauStatements` is called from exactly one place, + `DonauStatementScreen.kt:51`, so that wallet-core operation has no reachable + caller either. It is one of the operations this campaign could never + exercise from the app. + +The donau *package* sits at 38 % line coverage, the lowest of any feature +package, and this button is why. + +## Reproduce by hand + +1. Install a debug build and withdraw once, so there is a balance to show. +2. On the balance screen, scroll to the row with **Discounts**, **Passes** and + **Donation statements**. +3. Tap **Discounts** — a screen opens. Go back. Tap **Passes** — a screen + opens. Go back. +4. Tap **Donation statements** — nothing happens. `adb logcat` shows no + navigation and no error. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=0 python3 -u suite.py donau_receipt +``` + +The scenario taps the button and records the screen before and after; the +silent-failure oracle flags it, which is how it first showed up. + +## Suggested fix + +Wire it the way its two neighbours are wired: + +```kotlin +onShowStatements = { onShowStatements(scope) }, // in the pager +onStatementClicked = { host -> onStatementClicked(host) }, // in the list +``` + +with `MainScreen` navigating to `WalletDestination.DonauStatement(host)` — the +screen already fetches its own statements from the host it is given, so nothing +else is needed. The list's rows carry the right `donauBaseUrl` already. + +If the feature is meant to be unfinished, the button should not be on the +balance screen: a control that does nothing is worse than one that is absent. diff --git a/simulator/findings/error-code-registry-behind-wallet-core.md b/simulator/findings/error-code-registry-behind-wallet-core.md @@ -0,0 +1,106 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# The app's error-code registry is behind the wallet-core it ships + +Found by tallying every error reply in the simulator's logs +(`simulator/coverage/operations.py`): two of the four codes the wallet-core in +`net.taler:qtart:1.6.42` returned during normal scenarios are not in +`wallet/src/main/java/net/taler/wallet/backend/TalerErrorCode.kt`. + +**Severity: low, but it grows.** `TalerErrorInfo.rawCode` keeps the number, so +nothing crashes and the hint text still reaches the user; what is lost is the +ability to recognise the error. Any `code == TalerErrorCode.X` branch added for +one of these cases would silently never match, and triage reads "UNKNOWN". + +## What was observed + +| Operation | Code returned | Name upstream | +| --- | --- | --- | +| `getTransactionById` | 7052 | `WALLET_TRANSACTION_NOT_FOUND` | +| `startRefundQueryForUri` | 7051 | `WALLET_PURCHASE_NOT_FOUND` | + +Neither number appears in `TalerErrorCode.kt`, so both arrive as +`TalerErrorCode.UNKNOWN` with `rawCode` set. + +## The size of the gap + +Against the registry in the `taler-typescript-core` checkout (the source the +bundled wallet-core is built from), the app is missing **141 codes** +in total, of which **26** are in the wallet's own 7xxx range +and therefore reachable from the app: + +| Code | Name | +| --- | --- | +| 7050 | `WALLET_PAY_MERCHANT_INSUFFICIENT_BALANCE` | +| 7051 | `WALLET_PURCHASE_NOT_FOUND` | +| 7052 | `WALLET_TRANSACTION_NOT_FOUND` | +| 7053 | `WALLET_TRANSACTION_ACTION_UNSUPPORTED` | +| 7054 | `WALLET_KYC_LIMIT_EXCEEDED` | +| 7055 | `WALLET_NO_SUITABLE_EXCHANGE` | +| 7056 | `WALLET_BANK_ACCOUNT_NOT_FOUND` | +| 7057 | `WALLET_PEER_CONTRACT_NOT_FOUND` | +| 7058 | `WALLET_PEER_PUSH_CREDIT_PURSE_GONE` | +| 7059 | `WALLET_PEER_PULL_DEBIT_ALREADY_PAID` | +| 7060 | `WALLET_TOKENS_IN_USE` | +| 7061 | `WALLET_DB_BACKEND_UNSUPPORTED` | +| 7062 | `WALLET_MAILBOX_UNAVAILABLE` | +| 7063 | `WALLET_ALIAS_REGISTRATION_FAILED` | +| 7064 | `WALLET_CONTRACT_TERMS_UNSUPPORTED` | +| 7065 | `WALLET_EXCHANGE_SIGNATURE_INVALID` | +| 7066 | `WALLET_EXCHANGE_KEYS_NOT_ACCEPTED` | +| 7067 | `WALLET_EXCHANGE_NO_KEY_CHANGE_PENDING` | +| 7068 | `WALLET_EXCHANGE_KEY_CHANGE_MISMATCH` | +| 7069 | `WALLET_PEER_PUSH_PAYMENT_QUOTE_CHANGED` | +| 7070 | `WALLET_TRANSACTION_COMPLETED_BY_OTHER_WALLET` | +| 7071 | `WALLET_REFRESH_GROUP_FAILED` | +| 7072 | `WALLET_RECOUP_GROUP_FAILED` | +| 7073 | `WALLET_REFUND_GROUP_FAILED` | +| 7074 | `WALLET_TRANSACTION_RECOVERY_FAILED` | +| 7075 | `WALLET_TRANSACTION_DEPENDENCY_FAILED` | + +## Reproduce by hand + +```bash +# Codes the app knows nothing about, yet wallet-core can return: +grep -c 'WALLET_TRANSACTION_NOT_FOUND' \ + wallet/src/main/java/net/taler/wallet/backend/TalerErrorCode.kt # 0 +grep -c '7052' \ + wallet/src/main/java/net/taler/wallet/backend/TalerErrorCode.kt # 0 +``` + +To see one arrive, follow `delete-transaction-requeries-deleted-id.md`: deleting +a transaction logs an error with `"code":7052`. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/coverage && python3 operations.py /opt/taler-sim/run/out +``` + +The "operations that returned an error, with codes" section lists each code +observed, by operation. + +## Suggested fix + +`TalerErrorCode.kt` carries an LGPL header and is a transcription of the GANA +`gnu-taler-error-codes` registry, so it should be regenerated from that registry +rather than extended by hand — ideally pinned to the same release as the +`qtart` version in `wallet/build.gradle`, since that is what decides which +codes can actually arrive. A check that fails the build when the bundled +wallet-core knows a code the registry does not would keep the two from drifting +again. diff --git a/simulator/findings/mailbox-payment-only-actionable-for-one-scheme.diff b/simulator/findings/mailbox-payment-only-actionable-for-one-scheme.diff @@ -0,0 +1,93 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/Utils.kt b/wallet/src/main/java/net/taler/wallet/Utils.kt +index 6e0ecdc0..2c2762fe 100644 +--- a/wallet/src/main/java/net/taler/wallet/Utils.kt ++++ b/wallet/src/main/java/net/taler/wallet/Utils.kt +@@ -63,6 +63,7 @@ import net.taler.common.AmountParserException + import net.taler.lib.android.showError + import net.taler.lib.android.startActivitySafe + import net.taler.wallet.backend.TalerErrorInfo ++import java.util.Locale + + const val CURRENCY_BTC = "BITCOINBTC" + +@@ -117,6 +118,31 @@ private fun connectToWifiDeprecated(context: Context, ssid: String) { + } + } + ++/** ++ * The action part of a Taler URI, whatever scheme it arrived under. ++ * ++ * `taler://`, `ext+taler://` and `taler+http://` all carry the same actions, ++ * and schemes are case-insensitive per RFC 3986. Testing for one spelling by ++ * hand is how a payment that arrived by mailbox became unactionable and how ++ * the forward-to-contact button stopped appearing in the one mode that offers ++ * it -- so anything deciding *which* action a URI names should ask here. ++ * ++ * Returns null for a URI that is not a Taler URI at all. ++ */ ++fun talerUriAction(uri: String): String? { ++ val lower = uri.lowercase(Locale.ROOT) ++ for (scheme in listOf("taler://", "ext+taler://", "taler+http://")) { ++ if (lower.startsWith(scheme)) return lower.substring(scheme.length) ++ } ++ return null ++} ++ ++/** Whether a Taler URI names one of these actions, under any scheme. */ ++fun talerUriIsAction(uri: String, vararg actions: String): Boolean { ++ val action = talerUriAction(uri) ?: return false ++ return actions.any { action.startsWith(it) } ++} ++ + fun cleanExchange(exchange: String) = exchange.let { + if (it.startsWith("https://", ignoreCase = true)) it.substring(8) else it + }.trimEnd('/') +diff --git a/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt b/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt +index dd378132..57da5de0 100644 +--- a/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt ++++ b/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt +@@ -61,6 +61,7 @@ import net.taler.lib.android.QrCodeManager + import net.taler.lib.android.QrLogoSize + import net.taler.lib.android.copyToClipBoard + import net.taler.wallet.R ++import net.taler.wallet.talerUriIsAction + + sealed class QrCodeParams { + data object Taler: QrCodeParams() +@@ -179,7 +180,12 @@ fun ColumnScope.QrCodeUriComposable( + ), + ) + +- if (devMode && onForward != null && (qrData.startsWith("taler://pay-push") || qrData.startsWith("taler://pay-pull"))) { ++ // In developer mode the wallet's own URIs are taler+http://, so ++ // testing for taler:// here meant this button never appeared in ++ // the only mode that offers it. ++ if (devMode && onForward != null && ++ talerUriIsAction(qrData, "pay-push", "pay-pull") ++ ) { + ForwardButton( + onClick = { onForward(qrData) }, + colors = ButtonDefaults.buttonColors( +diff --git a/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt b/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt +index 01073ef5..58eee7b1 100644 +--- a/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt ++++ b/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt +@@ -68,6 +68,7 @@ import net.taler.common.Timestamp + import net.taler.lib.android.toAbsoluteTime + import net.taler.wallet.NavigateCallback + import net.taler.wallet.R ++import net.taler.wallet.talerUriIsAction + import net.taler.wallet.WalletDestination + import net.taler.wallet.compose.TalerSurface + import net.taler.wallet.main.MainViewModel +@@ -242,8 +243,8 @@ fun MessageItem( + onDelete: (MailboxMessageRecord) -> Unit, + ) { + val context = LocalContext.current +- val isPayPush = message.talerUri.startsWith("taler://pay-push") +- val isPayPull = message.talerUri.startsWith("taler://pay-pull") ++ val isPayPush = talerUriIsAction(message.talerUri, "pay-push") ++ val isPayPull = talerUriIsAction(message.talerUri, "pay-pull") + Row( + modifier = Modifier + .fillMaxWidth() diff --git a/simulator/findings/mailbox-payment-only-actionable-for-one-scheme.md b/simulator/findings/mailbox-payment-only-actionable-for-one-scheme.md @@ -0,0 +1,198 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Mailbox payments work only if the URI says "taler://" — in and out + +Found by the `mailbox_roundtrip` scenario, the first thing in this campaign to +put a real message in the wallet's mailbox: the message arrived, the row showed +the URI as plain text, and there was no way to act on it. The same test, +written later for the *sending* side, found the identical mistake there. + +**Severity: low-moderate.** The scheme that fails is `taler+http://`, which is +what every development and test deployment uses — exactly where someone would +first try the feature. The same rows also fail for the `ext+taler://` form the +app accepts everywhere else. + +On the sending side it is worse than a scheme mismatch: the button that +forwards a payment to a contact is shown **only in developer mode**, and the +scheme it insists on is the one developer mode does not produce, so the feature +cancels itself out (below). + +## What happens + +Another wallet sends a push payment to this wallet's mailbox address. The +message is received and listed: + +``` +taler+http://pay-push/localhost:8081/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +From: http://localhost:11000 +Received: October 18, 2026 at 6:38 AM +[Delete] +``` + +The URI is printed as text and the only button is **Delete**. With a +`taler://` URI, the same row shows an **"Accept payment"** button that opens +the payment. + +Both at once, from one run — two messages sent to the same mailbox differing +only in the scheme: + +``` +after two real messages: ['Accept payment', + 'From: http://localhost:11000', + 'Received: October 18, 2026 at 6:42 AM', + 'Delete', + 'taler+http://pay-push/localhost:8081/AAAA…', + 'From: http://localhost:11000', + 'Received: October 18, 2026 at 6:42 AM', …] +rows offering an action: 1 +rows showing a raw URI: ['taler+http://pay-push/localhost:8081/AAAA…'] +``` + +## Why + +The row decides by exact prefix: + +```kotlin +// wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt:245 +val isPayPush = message.talerUri.startsWith("taler://pay-push") +val isPayPull = message.talerUri.startsWith("taler://pay-pull") +… +if (isPayPush || isPayPull) { + Button(onClick = { onNavigate(WalletDestination.HandleUri(message.talerUri), false) }) { + Text(if (isPayPush) "Accept payment" else "Pay invoice") + } +} else { + Text(message.talerUri, style = MaterialTheme.typography.bodyMedium) +} +``` + +Three URIs the app handles elsewhere fall into the `else`: + +* `taler+http://pay-push/…` — the developer-mode scheme, which is the only one + that works against a local deployment; +* `ext+taler://pay-push/…` — the browser-extension form; +* `TALER://PAY-PUSH/…` — schemes are case-insensitive per RFC 3986. + +Everywhere else the app is careful about this. `HandleUriScreen` lowercases +the whole URI and strips `taler://`, `ext+taler://` or `taler+http://` before +matching the action: + +```kotlin +// wallet/src/main/java/net/taler/wallet/HandleUriScreen.kt:60 +val normalizedURL = u.lowercase(Locale.ROOT) +… +if (normalizedURL.startsWith("taler://", ignoreCase = true)) … +else if (normalizedURL.startsWith("ext+taler://", ignoreCase = true)) … +else if (normalizedURL.startsWith("taler+http://", ignoreCase = true) && devMode) … +``` + +so the mailbox row is *not* the only place that knows about one of the three. + +### The same prefix test hides the forward button + +The way *out* of the wallet has it too. A peer-push transaction's QR screen +offers a button that forwards the payment to a contact's mailbox — the only +caller of `sendTalerUriMailboxMessage` — and it is gated the same way: + +```kotlin +// wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt:183 +if (devMode && onForward != null && + (qrData.startsWith("taler://pay-push") || qrData.startsWith("taler://pay-pull"))) { + ForwardButton(onClick = { onForward(qrData) }, …) +} +``` + +Note the first condition: the button exists **only in developer mode**. But in +developer mode against a local deployment the wallet's own push URI is +`taler+http://pay-push/…`, so the prefix test fails and the button is never +drawn. Measured, with developer mode on: + +``` +forward_payment_to_contact: + Scan this QR code to receive €5.00 + Alternatively, copy and send this URI: + taler+http://pay-push/localhost:8081/3ZTJWX7HJ0G1J8R64Z6VFXGG35SX9R9XFMK4BPF79WMV5CNCYDH0 + -> no forward button on the push screen +``` + +The two conditions contradict each other: one restricts the feature to +developer mode, the other to the scheme developer mode does not produce. It +survives only when a dev-mode wallet talks to an `https://` exchange. + +## Reproduce by hand + +Needs a mailbox service and a second wallet; against the simulator's stack +(`simulator/backend/services/README.md` has the deployment): + +1. In the wallet, Settings → **Mailbox** → the gear icon → type + `http://localhost:11000` → OK. The wallet registers itself; the info icon + shows its address. +2. From another wallet, send a push payment URI to that address. With + `taler-wallet-cli`: + + ```bash + taler-wallet-cli --wallet-db /tmp/sender.sqlite3 advanced api \ + sendTalerUriMailboxMessage '{"contact":{"alias":"x@example.com","aliasType":"email", + "mailboxBaseUri":"http://127.0.0.1:11000/","mailboxAddress":"<THE ADDRESS>", + "source":"local","petname":"test","originMailboxBaseUrl":"http://127.0.0.1:11000/", + "downloadedAt":{"t_s":0},"talerUri":"","transactionId":""}, + "talerUri":"taler+http://pay-push/localhost:8081/AAAA…"}' + ``` + +3. Tap **Refresh** in the mailbox screen. The message appears with its URI as + text and no action. +4. Send the same thing again with `taler://` instead of `taler+http://`: that + row has an "Accept payment" button. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=4 python3 suite.py mailbox_roundtrip +``` + +The scenario sends one message of each scheme and reports how many rows offer +an action and which ones show a bare URI. + +For the forward button, which fails for the same reason: + +```bash +SIM_WORKER=4 python3 suite.py forward_payment_to_contact +``` + +It makes a push payment with developer mode on and looks for the button on the +QR screen; its note says what the screen offered instead. + +## Suggested fix + +Decide the action the way `HandleUriScreen` does — normalise the scheme first, +and match the action case-insensitively: + +```kotlin +val action = message.talerUri.lowercase(Locale.ROOT) + .removePrefix("ext+taler://").removePrefix("taler+http://").removePrefix("taler://") +val isPayPush = action.startsWith("pay-push") +val isPayPull = action.startsWith("pay-pull") +``` + +and the same in `QrCodeUriComposable`'s forward-button condition. + +A shared helper would be better than a fourth copy of that logic: the +normalisation is already written out in `HandleUriScreen` and partly again in +`ContactScreen`'s `fillFromUri`. One `talerUriAction(uri): String?` used by all +four would have made both of these impossible. diff --git a/simulator/findings/mailbox-private-keys-written-to-log.diff b/simulator/findings/mailbox-private-keys-written-to-log.diff @@ -0,0 +1,49 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/mailbox/MailboxManager.kt b/wallet/src/main/java/net/taler/wallet/mailbox/MailboxManager.kt +index dac720c5..809a6bae 100644 +--- a/wallet/src/main/java/net/taler/wallet/mailbox/MailboxManager.kt ++++ b/wallet/src/main/java/net/taler/wallet/mailbox/MailboxManager.kt +@@ -40,7 +40,17 @@ data class MailboxConfiguration( + val hAddress: String, + val expiration: Timestamp, + val payUri: String? = null, +-) ++) { ++ /** ++ * Without this the generated toString() puts both private keys in any log ++ * line this object is interpolated into -- and it was interpolated into ++ * two. ++ */ ++ override fun toString(): String = ++ "MailboxConfiguration(mailboxBaseUrl=$mailboxBaseUrl, hAddress=$hAddress, " + ++ "expiration=$expiration, payUri=$payUri, " + ++ "privateKey=<redacted>, privateEncryptionKey=<redacted>)" ++} + + @Serializable + data class MailboxMessageRecord( +@@ -100,14 +110,14 @@ class MailboxManager( + fun loadMailbox(baseUrl: String = "https://mailbox.gnunet.org") { + _mailbox.value = MailboxResult.Loading + scope.launch { +- Log.e(TAG, "Loading mailbox") ++ Log.d(TAG, "loading mailbox at $baseUrl") + api.request("getMailbox", GetMailboxResponse.serializer()) { + put("mailboxBaseUrl", baseUrl) + }.onSuccess { resp -> + if (null == resp.mailboxConfiguration) { + initializeMailbox(baseUrl) + } else { +- Log.e(TAG, "Got mailbox ${resp.mailboxConfiguration}") ++ Log.d(TAG, "got mailbox at ${resp.mailboxConfiguration.mailboxBaseUrl}") + getMessages(resp.mailboxConfiguration) + } + }.onError { +@@ -143,7 +153,7 @@ class MailboxManager( + + fun refreshMailbox(config: MailboxConfiguration) { + +- Log.e(TAG, "Rereshing mailbox ${config}") ++ Log.d(TAG, "refreshing mailbox at ${config.mailboxBaseUrl}") + scope.launch { + api.request("refreshMailbox", MailboxMessagesResponse.serializer()) { + JSONObject(BackendManager.json.encodeToString(config)) diff --git a/simulator/findings/mailbox-private-keys-written-to-log.md b/simulator/findings/mailbox-private-keys-written-to-log.md @@ -0,0 +1,93 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# The mailbox's private keys are written to the log every 30 seconds + +Noticed in a simulator log while investigating something else: with developer +mode on, the wallet logs its whole mailbox configuration — including both +private keys — at **error** level, every 30 seconds. + +**Severity: moderate.** It is developer-mode only, but developer mode is also +where "Debug log → Save internal log" lives, and that export is exactly what a +user is asked for when reporting a problem. Sending that file hands over the +keys to the wallet's mailbox. + +## What happens + +``` +E taler-wallet: Rereshing mailbox MailboxConfiguration( + mailboxBaseUrl=https://mailbox.gnunet.org, + privateKey=K5ZN6AW2WQVE4T7G22EXPNR1HCBZZAVKMP3JXEXTGF5X1TV2B0CG, + privateEncryptionKey=9Q59Z0H38JB4N4F40VXAB33Q799KN6XTAW1ARN2H7DTMM9Q2H5H0, + hAddress=E4RBDRX49F7M2V3H1JJVQ0MN0QVVJHTRMEG4300ZCWMXEPQMQWXMHZ7C80VBHVM69HX7Y59X05F70KNGR1K94DK87TT8BGA11TX5X2G, + expiration=Timestamp(s=1823806854), payUri=null) +``` + +`MailboxConfiguration` is a data class, so string interpolation prints every +field. + +## Reproduce by hand + +1. Install the wallet and enable **Developer mode** in Settings. +2. Run `adb logcat | grep -i "Rereshing mailbox"` (the typo is in the source). +3. Wait up to 30 seconds. The line appears, with `privateKey=` and + `privateEncryptionKey=` in full, and repeats every 30 seconds. + +The same content reaches a file through Settings → **Debug log**, which runs +`logcat -d *:V`. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_mailbox_private_keys_in_log.py +``` + +## Why + +`wallet/src/main/java/net/taler/wallet/mailbox/MailboxManager.kt:146`: + +```kotlin +fun refreshMailbox(config: MailboxConfiguration) { + + Log.e(TAG, "Rereshing mailbox ${config}") +``` + +Left-over debug output: error level, no `BuildConfig.DEBUG` guard, and a typo +in the message. `MailboxManager.start()` schedules `refreshMailbox` every 30 +seconds while `isDevMode()` is true (`MailboxManager.kt:82-98`). + +## Suggested fix + +Delete the line. If a trace is wanted, log the base URL alone and at debug +level: + +```kotlin +Log.d(TAG, "refreshing mailbox at ${config.mailboxBaseUrl}") +``` + +Worth considering alongside it: give `MailboxConfiguration` a `toString()` that +redacts the two key fields, so no future interpolation can leak them. + +## Also worth deciding + +`MainViewModel.onInitReceived` calls `mailboxManager.start()` unconditionally, +and `start()` calls `loadMailbox()` with a hardcoded +`https://mailbox.gnunet.org`. Every wallet start therefore contacts that host, +in release builds too, before the user has asked for anything to do with +messaging. Whether that is intended is a product decision, but it is worth +being deliberate about. diff --git a/simulator/findings/new_finding.py b/simulator/findings/new_finding.py @@ -0,0 +1,149 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Scaffold a finding write-up from an episode's artifacts. + +Turns the recorded action log into numbered steps a person can follow on a +device, and gathers the evidence paths, so the write-up only needs the analysis +and the suggested fix filled in. + + python3 new_finding.py <episode-dir> [fingerprint] > my-finding.md +""" + +from __future__ import annotations + +import json +import sys +from pathlib import Path + +# How each recorded action reads as an instruction to a person. +HUMAN = { + "tap_label": 'Tap **{arg}**.', + "tap_xy": "Tap the screen at {arg}.", + "long_press_label": 'Long-press **{arg}**.', + "type": 'Type `{arg}` into the text field.', + "scroll_down": "Scroll down.", + "scroll_up": "Scroll up.", + "back": "Press the back button.", + "rotate": "Rotate the device ({arg} = landscape).", + "uri": "Send the wallet this URI (share it into the app, or scan it as a QR code):\n `{arg}`", + "view_uri": "Open this link so the system hands it to the wallet:\n `{arg}`", + "process_death": "Kill the app's process (`adb shell am kill net.taler.wallet.fdroid.debug`) and reopen it.", + "relaunch": "Close the app and reopen it.", + "home_screen": "Go back to the main screen.", +} + +SETUP_TEXT = { + "fresh": "a wallet with no data, developer mode on", + "funded": "a wallet with no data, developer mode on, then one completed " + "withdrawal of EUR:10 from the local bank", + "paid": "a wallet with one completed EUR:10 withdrawal and one completed " + "EUR:2 purchase", + "keep": "whatever state the previous scenario left behind", +} + + +def steps(actions: list[dict]) -> list[str]: + out = [] + for action in actions: + template = HUMAN.get(action["op"]) + if template is None: + out.append(f"Perform `{action['op']}` ({action.get('arg')!r}).") + else: + out.append(template.format(arg=action.get("arg"))) + return out + + +def main() -> int: + if len(sys.argv) < 2: + print(__doc__) + return 2 + episode = Path(sys.argv[1]) + wanted = sys.argv[2] if len(sys.argv) > 2 else None + summary = json.loads((episode / "summary.json").read_text()) + findings = summary.get("findings", []) + if wanted: + findings = [f for f in findings if f.get("fingerprint") == wanted] + if not findings: + print(f"no findings in {episode}", file=sys.stderr) + return 1 + finding = findings[0] + detail_files = sorted(episode.glob(f"*{finding['fingerprint']}*")) + actions = json.loads((episode / "actions.json").read_text()) \ + if (episode / "actions.json").is_file() else [] + scenario = summary.get("scenario") or summary.get("name", "") + setup = summary.get("setup", "keep") + + print(f"""<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# TITLE ME + +Found by the simulator in `{scenario}` ({finding['kind']}, fingerprint +`{finding['fingerprint']}`). + +**Severity: TODO.** + +## What happens + +``` +{finding['detail'][:1200]} +``` + +Screen at the time: {summary.get('findings', [{}])[0].get('screen', '')} + +## Reproduce by hand + +Starting point: {SETUP_TEXT.get(setup, setup)}. The local stack is the one +described in `simulator/README.md`; where a step mentions a URI, the bank or +the merchant produced it. +""") + for index, step in enumerate(steps(actions), start=1): + print(f"{index}. {step}") + print(f""" +Watch the app's log while doing this: + +```bash +adb logcat | grep -E 'taler-wallet|BackendManager|FATAL' +``` + +## Why TODO + +## Suggested fix TODO + +## Evidence + +Episode directory: `{episode}` (on tripwire). +""") + for path in detail_files: + print(f"* `{path.name}`") + print("* `actions.json` — the full recorded sequence, replayable with " + "`driver/replay.py`") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/payto-link-only-accepts-iban.diff b/simulator/findings/payto-link-only-accepts-iban.diff @@ -0,0 +1,44 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt b/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt +index 821bf471..0b19306a 100644 +--- a/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt ++++ b/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt +@@ -29,6 +29,7 @@ import kotlinx.serialization.json.jsonPrimitive + import net.taler.common.Amount + import net.taler.wallet.main.TAG + import net.taler.wallet.accounts.KnownBankAccountInfo ++import net.taler.wallet.accounts.PaytoUri + import net.taler.wallet.accounts.PaytoUriBitcoin + import net.taler.wallet.accounts.PaytoUriIban + import net.taler.wallet.accounts.PaytoUriTalerBank +@@ -39,7 +40,6 @@ import net.taler.wallet.backend.WalletResponse + import net.taler.wallet.balances.BalanceManager + import net.taler.wallet.balances.ScopeInfo + import org.json.JSONObject +-import androidx.core.net.toUri + + class DepositManager( + private val api: WalletBackendApi, +@@ -50,12 +50,17 @@ class DepositManager( + private val mDepositState = MutableStateFlow<DepositState>(DepositState.Start) + internal val depositState = mDepositState.asStateFlow() + +- fun isSupportedPayToUri(uriString: String): Boolean { +- if (!uriString.startsWith("payto://")) return false +- val u = uriString.toUri() +- if (!u.authority.equals("iban", ignoreCase = true)) return false +- return u.pathSegments.isNotEmpty() +- } ++ /** ++ * Whether a payto URI names an account this wallet can deposit to. ++ * ++ * Every target type the app models counts, not just IBAN: the ++ * add-account form offers x-taler-bank, IBAN and Bitcoin, the transfer ++ * screens render all four, and a deposit to an x-taler-bank account ++ * chosen from the account list succeeds -- so refusing the same account ++ * as a *link* told the user their link was invalid when it was not. ++ */ ++ fun isSupportedPayToUri(uriString: String): Boolean = ++ PaytoUri.parse(uriString) != null + + @UiThread + fun selectAccount(account: KnownBankAccountInfo) = scope.launch { diff --git a/simulator/findings/payto-link-only-accepts-iban.md b/simulator/findings/payto-link-only-accepts-iban.md @@ -0,0 +1,134 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# A payto link is "not a valid Taler link" unless it is an IBAN + +Found by a harness defect of its own: the `deposit` scenario had been passing +for thirteen rounds while depositing nothing, because it started the deposit +from a payto link the wallet refuses. + +**Severity: moderate.** The wallet deposits to `x-taler-bank` accounts +perfectly well when one is picked from its own account list — that is how every +deposit in this campaign's local stack works — but the same account as a +`payto://` link is rejected, and the message says the *link* is invalid rather +than that the account type is unsupported. + +## What happens + +The bank in the simulator's stack hands out + +``` +payto://x-taler-bank/localhost/wallet5?receiver-name=Wallet%205 +``` + +Sharing that into the wallet opens the "Send funds" screen with one line of red +text: + +``` +['Not a valid Taler link', 'Go back', 'Send', 'Internal event log'] +``` + +Picking the very same account from *Deposit → account list* works and the money +arrives: + +``` +deposit_flow: ['This transaction was completed successfully', + 'Chosen amount', '€0.44', 'Fee', '-€0.06', 'Amount sent', '-€0.50'] +``` + +## Why + +`PayToUriScreen` asks one question before it will show the amount form, and the +answer for anything but an IBAN is no: + +```kotlin +// wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt:53 +fun isSupportedPayToUri(uriString: String): Boolean { + if (!uriString.startsWith("payto://")) return false + val u = uriString.toUri() + if (!u.authority.equals("iban", ignoreCase = true)) return false + return u.pathSegments.isNotEmpty() +} +``` + +```kotlin +// wallet/src/main/java/net/taler/wallet/deposit/PayToUriScreen.kt:81 +} else if (model.depositManager.isSupportedPayToUri(uri)) { + PayToComposable(…) +} else { + Text(text = stringResource(id = R.string.uri_invalid), …) +} +``` + +Everything else in the app disagrees with that restriction: + +* the add-account form offers **x-taler-bank**, **IBAN** and **Bitcoin** tabs, + and `AddAccountComposable` builds a payto for each; +* `Accounts.kt` models `PaytoUriIban`, `PaytoUriTaler`, `PaytoUriBitcoin` and + `PaytoUriCyclos`, and the transfer screens render all four; +* wallet-core's own payto parser accepts `iban`, `x-taler-bank`, `bitcoin`, + `upi` and more (`packages/taler-util/src/payto.ts`); +* and the deposit itself succeeds for an x-taler-bank account chosen from the + list, so nothing downstream needs the restriction. + +So the check is narrower than the feature behind it, and `uri_invalid` — +"Not a valid Taler link" — is the wrong thing to say about a well-formed payto +URI for an account the wallet can use. + +## Reproduce by hand + +1. Install a debug build, enable **Developer mode**, and withdraw once from the + local bank so the wallet has coins and knows the account. +2. Share a payto URI for a non-IBAN account into the wallet: + + ```bash + adb shell am start -a android.intent.action.VIEW \ + -d 'payto://x-taler-bank/localhost/wallet1?receiver-name=Wallet%201' + ``` + +3. The screen shows "Not a valid Taler link". +4. For the contrast: **Deposit** on the home screen, pick the `wallet1` + account, enter an amount, **Make deposit** — the same account, and it works. + +An IBAN link, for comparison, opens the amount form: + +```bash +adb shell am start -a android.intent.action.VIEW \ + -d 'payto://iban/DE89370400440532013000?receiver-name=Wallet%20One' +``` + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=0 python3 -u suite.py deposit_payto_link deposit +``` + +`deposit_payto_link` records the refusal and says so if it ever stops +happening; `deposit` now drives the account list instead and **fails** if the +bank balance does not move, which is what should have been checked all along. + +## Suggested fix + +Accept the target types the wallet already models. `isSupportedPayToUri` can +delegate to the same parsing the account forms use — `PaytoUri.parse`, which +returns `PaytoUriIban`/`PaytoUriTaler`/`PaytoUriBitcoin`/`PaytoUriCyclos` — +and treat "parsed to something we can deposit to" as supported. + +For whatever genuinely stays unsupported, say that instead of `uri_invalid`: +"this wallet cannot deposit to a <type> account" tells the user something, +where "not a valid Taler link" is both unhelpful and untrue. diff --git a/simulator/findings/pos-confirmation-shows-five-codes.md b/simulator/findings/pos-confirmation-shows-five-codes.md @@ -0,0 +1,107 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# "Confirmation code" shows five codes with no hint which one to read out + +Found by the new `payment_pos_confirmation` scenario, the first thing in this +campaign to reach `PayTotpComposable` at all. + +**Severity: low.** It only shows up at merchants that use a point-of-sale +confirmation device, and only for the human-readable half of that feature; the +NFC half is correct. + +## What happens + +Paying an order that names an OTP device, the completed purchase reads: + +``` +This transaction was completed successfully +Total €1.00 +Paid -€1.00 +Confirmation code +10179494 +80755471 +56332107 +94603659 +92288808 +``` + +Five eight-digit numbers under a singular label, in a monospace block, with +nothing to say what to do with them. + +That is not a bug in the merchant: `TALER_build_pos_confirmation` deliberately +returns *every* T-OTP code in the valid time range, newline-separated, so that +a device whose clock is off by a step or two still matches +(`exchange/src/util/crypto_confirmation.c:254`, "Return all T-OTP codes in +range separated by new lines"). `formatTotpPayload` in the wallet splits them +and writes all of them into the NDEF record, which is exactly right for a +device reading over NFC. + +The display path then prints the same string verbatim: + +```kotlin +// wallet/src/main/java/net/taler/wallet/payment/PayTotpComposable.kt:123 +Text( + text = totpString, + fontFamily = FontFamily.Monospace, + ... +) +``` + +So where NFC is not available — which is the case `enableNfc == false` exists +for — a cashier is shown five candidate codes and has to guess. The middle one +is the current time step, but nothing says so. + +## Reproduce by hand + +Needs a merchant backend you can configure; against the simulator's stack: + +1. Create an OTP device: + ```bash + curl -X POST http://localhost:8080/instances/sim/private/otp-devices \ + -H 'Content-Type: application/json' \ + -d '{"otp_device_id":"simpos","otp_device_description":"Till", + "otp_algorithm":"TOTP_WITHOUT_PRICE", + "otp_key":"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567","otp_ctr":0}' + ``` + (`otp_key` is RFC 3548 base32, not Crockford.) +2. Create an order naming it — `otp_id` is a sibling of `order`, not a field + of it: + ```bash + curl -X POST http://localhost:8080/instances/sim/private/orders \ + -H 'Content-Type: application/json' \ + -d '{"order":{"amount":"EUR:1","summary":"Till order", + "fulfillment_url":"https://example.com/f/1"},"otp_id":"simpos"}' + ``` +3. Hand the resulting `taler_pay_uri` to the wallet and pay it. +4. The completed purchase shows the block above. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_pos_confirmation_codes.py # worker 0 by default +SIM_WORKER=4 python3 suite.py payment_pos_confirmation # or the scenario +``` + +## Suggested fix + +Show the code for the current time step and keep the rest for the NFC payload: +`totpString.split("\n")` is already computed in `formatTotpPayload`, so the +display can take the middle entry (the list is centred on now) and show the +others only in developer mode. If showing all of them is deliberate, the label +should be plural and say why there are several. diff --git a/simulator/findings/purge-destroys-coins-and-history-without-saying-so.md b/simulator/findings/purge-destroys-coins-and-history-without-saying-so.md @@ -0,0 +1,115 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# "Force deletion (purge)" destroys the coins and the history, and says neither + +Found by the `history_after_forgetting_exchange` scenario, written to ask +whether the transaction history survives removing the payment service it +belongs to. It does not, and nothing warns about it. + +**Severity: moderate.** Irreversible, reachable in a release build from +Settings → Payment services, and it destroys money: the wallet went from +€9.87 and a transaction history to the first-run welcome screen. + +## What happens + +A wallet with €9.87 withdrawn from one payment service, Settings → Payment +services → the service's menu → **Delete payment service**. The dialog is: + +``` +Delete payment service +[ ] Force deletion (purge) + Delete Cancel +``` + +That is the whole dialog — a title, a checkbox, two buttons. There is no body +text, no mention of the balance held at that service, and no statement of what +"purge" additionally destroys. + +Ticking the box and pressing **Delete**: + +``` +transactions before: ['Withdraw'] +after forgetting: the payment services list, with the service gone +home afterwards: ['Wallet', 'Welcome to Taler Wallet!', + 'To make your first payment, withdraw digital cash.', …] +transactions after: [] +``` + +The €9.87 is gone, the withdrawal that produced it is gone, and the wallet +looks like a fresh install. + +Without the checkbox the app does protect the user — a plain delete of a +service that still holds coins is refused, which is what the +`exchange_delete_with_coins` scenario covers. The checkbox is the override, +and it is the override that carries no warning. + +## Why + +The dialog has no text beyond the checkbox label: + +```kotlin +// wallet/src/main/java/net/taler/wallet/exchanges/ExchangeListScreen.kt:297 +AlertDialog( + onDismissRequest = onDismiss, + title = { Text(stringResource(R.string.exchange_delete)) }, + text = { + Row(verticalAlignment = Alignment.CenterVertically) { + Checkbox(checked = purge, onCheckedChange = { purge = it }) + Text(stringResource(R.string.exchange_delete_force)) + } + }, + confirmButton = { TextButton(onClick = { onConfirm(purge) }) { … } }, + … +) +``` + +`R.string.exchange_delete_force` is the five words "Force deletion (purge)". +There is no string in the file that explains the consequence, so there is +nothing to show even if the dialog wanted to. + +For contrast, the wallet's own reset dialog *does* explain itself, and +forgetting a bank account asks "Do you really wish to forget…". + +## Reproduce by hand + +1. Withdraw some money, so the wallet has a balance and a transaction. +2. Settings → **Payment services** → the service's **Menu** → **Delete + payment service**. +3. Tick **Force deletion (purge)** and press **Delete**. +4. The service disappears. Go back to the main screen: it is the first-run + welcome screen, the balance is gone, and the transaction list is empty. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=4 python3 suite.py history_after_forgetting_exchange +``` + +The notes record the transactions before, the dialog, and the empty list +afterwards. + +## Suggested fix + +Give the dialog a body that says what will happen, and name the amount at +risk: the balance for that scope is already in `BalanceManager`, so "This +payment service holds €9.87. Deleting it will destroy that balance and the +record of every transaction made with it." is available to write. Requiring +the checkbox *and* a typed confirmation would not be excessive for an action +that cannot be undone; at the very least the consequence should be stated +before the money is gone. diff --git a/simulator/findings/qr-camera-ignores-the-plane-strides.diff b/simulator/findings/qr-camera-ignores-the-plane-strides.diff @@ -0,0 +1,538 @@ +diff --git a/taler-kotlin-android/src/main/java/net/taler/lib/android/qr/QrCameraAnalyzer.kt b/taler-kotlin-android/src/main/java/net/taler/lib/android/qr/QrCameraAnalyzer.kt +index de9d94ca..5fb26e3f 100644 +--- a/taler-kotlin-android/src/main/java/net/taler/lib/android/qr/QrCameraAnalyzer.kt ++++ b/taler-kotlin-android/src/main/java/net/taler/lib/android/qr/QrCameraAnalyzer.kt +@@ -19,6 +19,7 @@ package net.taler.lib.android.qr + import android.content.Context + import android.graphics.Bitmap + import android.media.Image ++import android.util.Log + import androidx.camera.core.Camera + import androidx.camera.core.CameraSelector + import androidx.camera.core.ExperimentalGetImage +@@ -38,7 +39,62 @@ import com.google.zxing.RGBLuminanceSource + import com.google.zxing.BarcodeFormat + import com.google.zxing.common.HybridBinarizer + import com.google.zxing.PlanarYUVLuminanceSource ++import java.nio.ByteBuffer ++import java.util.concurrent.ExecutorService + import java.util.concurrent.Executor ++import java.util.concurrent.Executors ++ ++/** ++ * The luminance plane of a YUV_420_888 frame, with its padding removed. ++ * ++ * A camera plane is not a tightly packed image: `rowStride` may exceed the ++ * width (the hardware pads each row) and `pixelStride` may exceed one (the ++ * samples are interleaved). Copying the buffer in one `get()` is only correct ++ * when neither is true, and when a row is padded every row after the first ++ * lands shifted, so the image skews and nothing decodes. Whether a given ++ * camera pads depends on the device *and* the platform version, which is how ++ * scanning can work on one Android release and fail on another. ++ * ++ * zxing's [PlanarYUVLuminanceSource] reads only this plane, so the chroma ++ * layout does not matter -- this is the whole of what the decoder needs. ++ */ ++internal fun extractLuma( ++ buffer: ByteBuffer, ++ rowStride: Int, ++ pixelStride: Int, ++ width: Int, ++ height: Int, ++): ByteArray { ++ val luma = ByteArray(width * height) ++ if (rowStride == width && pixelStride == 1) { ++ // The common case: already tightly packed. ++ buffer.position(0) ++ buffer.get(luma, 0, minOf(luma.size, buffer.remaining())) ++ return luma ++ } ++ val row = ByteArray(rowStride) ++ var out = 0 ++ for (y in 0 until height) { ++ val start = y * rowStride ++ if (start >= buffer.limit()) break ++ buffer.position(start) ++ // The last row is often short: the plane need not include its padding. ++ val len = minOf(rowStride, buffer.remaining()) ++ buffer.get(row, 0, len) ++ if (pixelStride == 1) { ++ System.arraycopy(row, 0, luma, out, minOf(width, len)) ++ } else { ++ var x = 0 ++ while (x < width && x * pixelStride < len) { ++ luma[out + x] = row[x * pixelStride] ++ x++ ++ } ++ } ++ out += width ++ } ++ return luma ++} ++ + + @androidx.annotation.OptIn(ExperimentalGetImage::class) + class QrCameraAnalyzer( +@@ -49,6 +105,14 @@ class QrCameraAnalyzer( + private val onCameraReady: ((initialLinearZoom: Float) -> Unit)? = null, + ) { + private val mainExecutor: Executor = ContextCompat.getMainExecutor(context) ++ ++ /** ++ * Frames are analysed here, not on the main thread: a frame costs a ++ * copy of the luminance plane plus a zxing decode, which is work the UI ++ * thread should not be doing thirty times a second. One thread, so the ++ * reader below needs no locking. ++ */ ++ private val analysisExecutor: ExecutorService = Executors.newSingleThreadExecutor() + private var camera: Camera? = null + + private val qrReader = MultiFormatReader().apply { +@@ -72,34 +136,21 @@ class QrCameraAnalyzer( + val analysis = ImageAnalysis.Builder() + .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) + .build().also { useCase -> +- useCase.setAnalyzer(mainExecutor) { proxy -> +- val mediaImage = proxy.image +- if (mediaImage != null) { +- val nv21 = yuv420888ToNv21(mediaImage) +- val width = mediaImage.width +- val height = mediaImage.height +- val rotation = proxy.imageInfo.rotationDegrees +- +- val (rotatedNv21, rotatedWidth, rotatedHeight) = when (rotation) { +- 90 -> rotateNV21(nv21, width, height, 90) +- 180 -> rotateNV21(nv21, width, height, 180) +- 270 -> rotateNV21(nv21, width, height, 270) +- else -> Triple(nv21, width, height) ++ useCase.setAnalyzer(analysisExecutor) { proxy -> ++ // Whatever happens to this frame, the proxy has to be ++ // closed: with STRATEGY_KEEP_ONLY_LATEST an unclosed ++ // one stops frame delivery for good, so a single ++ // unexpected frame would end scanning for the rest of ++ // the session while the viewfinder kept running. ++ try { ++ proxy.image?.let { image -> ++ decodeQr(image)?.let { text -> ++ mainExecutor.execute { onQrDetected(text) } ++ } + } +- +- val source = PlanarYUVLuminanceSource( +- rotatedNv21, rotatedWidth, rotatedHeight, 0, 0, rotatedWidth, rotatedHeight, false, +- ) +- +- val bitmap = BinaryBitmap(HybridBinarizer(source)) +- try { +- val result = qrReader.decodeWithState(bitmap) +- onQrDetected(result.text) +- } catch (_: NotFoundException) { +- } finally { +- proxy.close() +- } +- } else { ++ } catch (e: Exception) { ++ Log.w(TAG, "could not analyse a camera frame", e) ++ } finally { + proxy.close() + } + } +@@ -124,6 +175,7 @@ class QrCameraAnalyzer( + camera = null + } catch (_: Exception) { + } ++ analysisExecutor.shutdown() + } + + fun enableTorch(enabled: Boolean) { +@@ -147,84 +199,37 @@ class QrCameraAnalyzer( + cam.cameraControl.startFocusAndMetering(action) + } + +- private fun yuv420888ToNv21(image: Image): ByteArray { +- val yPlane = image.planes[0].buffer +- val uPlane = image.planes[1].buffer +- val vPlane = image.planes[2].buffer +- val ySize = yPlane.remaining() +- val uSize = uPlane.remaining() +- val vSize = vPlane.remaining() +- val nv21 = ByteArray(ySize + uSize + vSize) +- yPlane.get(nv21, 0, ySize) +- vPlane.get(nv21, ySize, vSize) +- uPlane.get(nv21, ySize + vSize, uSize) +- return nv21 +- } +- +- private fun rotateNV21(data: ByteArray, width: Int, height: Int, rotation: Int): Triple<ByteArray, Int, Int> { +- if (rotation == 0) return Triple(data, width, height) +- +- val ySize = width * height +- val uvSize = ySize / 2 +- val rotated = ByteArray(ySize + uvSize) +- +- when (rotation) { +- 90 -> { +- var i = 0 +- for (x in 0 until width) { +- for (y in height - 1 downTo 0) { +- rotated[i++] = data[y * width + x] +- } +- } +- var uvIndex = ySize +- for (x in 0 until width step 2) { +- for (y in height - 1 downTo 0 step 2) { +- val uvPos = ySize + (y * width + x) +- if (uvPos + 1 < data.size) { +- rotated[uvIndex++] = data[uvPos] +- rotated[uvIndex++] = data[uvPos + 1] +- } +- } +- } +- return Triple(rotated, height, width) +- } +- 180 -> { +- var i = ySize - 1 +- for (j in 0 until ySize) { +- rotated[j] = data[i--] +- } +- i = data.size - 1 +- for (j in ySize until data.size step 2) { +- rotated[j] = data[i - 1] +- rotated[j + 1] = data[i] +- i -= 2 +- } +- return Triple(rotated, width, height) +- } +- 270 -> { +- var i = 0 +- for (x in width - 1 downTo 0) { +- for (y in 0 until height) { +- rotated[i++] = data[y * width + x] +- } +- } +- var uvIndex = ySize +- for (x in width - 1 downTo 0 step 2) { +- for (y in 0 until height step 2) { +- val uvPos = ySize + (y * width + x - 1) +- if (uvPos + 1 < data.size) { +- rotated[uvIndex++] = data[uvPos] +- rotated[uvIndex++] = data[uvPos + 1] +- } +- } +- } +- return Triple(rotated, height, width) +- } ++ /** ++ * The `taler://` URI in [image], or null if there is no QR code in it. ++ * ++ * The frame is not rotated first. zxing locates a QR code by its three ++ * finder patterns and derives the orientation from them, so it reads a ++ * code the same whichever way up the phone is held -- rotating the plane ++ * by hand only cost a second pass over every pixel. ++ */ ++ private fun decodeQr(image: Image): String? { ++ val plane = image.planes[0] ++ val luma = extractLuma( ++ plane.buffer, ++ plane.rowStride, ++ plane.pixelStride, ++ image.width, ++ image.height, ++ ) ++ val source = PlanarYUVLuminanceSource( ++ luma, image.width, image.height, 0, 0, image.width, image.height, false, ++ ) ++ return try { ++ qrReader.decodeWithState(BinaryBitmap(HybridBinarizer(source))).text ++ } catch (_: NotFoundException) { ++ // Most frames hold no code at all; this is the ordinary case. ++ null + } +- return Triple(data, width, height) + } + + companion object { ++ private const val TAG = "QrCameraAnalyzer" ++ + fun decodeQrFromBitmap(bitmap: Bitmap): String? { + val width = bitmap.width + val height = bitmap.height +diff --git a/taler-kotlin-android/src/test/java/net/taler/lib/android/qr/ExtractLumaTest.kt b/taler-kotlin-android/src/test/java/net/taler/lib/android/qr/ExtractLumaTest.kt +new file mode 100644 +index 00000000..63f84f7f +--- /dev/null ++++ b/taler-kotlin-android/src/test/java/net/taler/lib/android/qr/ExtractLumaTest.kt +@@ -0,0 +1,104 @@ ++/* ++ * This file is part of GNU Taler ++ * (C) 2026 Taler Systems S.A. ++ * ++ * GNU Taler is free software; you can redistribute it and/or modify it under the ++ * terms of the GNU General Public License as published by the Free Software ++ * Foundation; either version 3, or (at your option) any later version. ++ * ++ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY ++ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR ++ * A PARTICULAR PURPOSE. See the GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License along with ++ * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> ++ */ ++ ++package net.taler.lib.android.qr ++ ++import org.junit.Assert.assertArrayEquals ++import org.junit.Test ++import java.nio.ByteBuffer ++ ++/** ++ * A camera's luminance plane is not a tightly packed image, and the QR decoder ++ * only works if the padding is taken out. How a plane is laid out depends on ++ * the device and the platform version, which is why this is worth pinning: ++ * reading it wrong shows up as "scanning works on one Android release and not ++ * on another" rather than as an obvious failure. ++ */ ++class ExtractLumaTest { ++ ++ /** Row y, column x of a test image, as a recognisable byte. */ ++ private fun pixel(x: Int, y: Int) = (y * 16 + x).toByte() ++ ++ private fun expected(width: Int, height: Int) = ByteArray(width * height) { ++ pixel(it % width, it / width) ++ } ++ ++ @Test ++ fun tightlyPackedPlaneIsCopiedAsIs() { ++ val width = 4 ++ val height = 3 ++ val buffer = ByteBuffer.wrap(expected(width, height)) ++ assertArrayEquals( ++ expected(width, height), ++ extractLuma(buffer, rowStride = width, pixelStride = 1, width, height), ++ ) ++ } ++ ++ @Test ++ fun paddedRowsDoNotShiftTheImage() { ++ val width = 4 ++ val height = 3 ++ val rowStride = 7 // the hardware pads each row by three bytes ++ val padded = ByteArray(rowStride * height) { 0x7F } ++ for (y in 0 until height) { ++ for (x in 0 until width) padded[y * rowStride + x] = pixel(x, y) ++ } ++ assertArrayEquals( ++ expected(width, height), ++ extractLuma(ByteBuffer.wrap(padded), rowStride, pixelStride = 1, width, height), ++ ) ++ } ++ ++ @Test ++ fun interleavedSamplesAreTakenEveryPixelStride() { ++ val width = 4 ++ val height = 2 ++ val pixelStride = 2 ++ val rowStride = width * pixelStride ++ val interleaved = ByteArray(rowStride * height) { 0x7F } ++ for (y in 0 until height) { ++ for (x in 0 until width) { ++ interleaved[y * rowStride + x * pixelStride] = pixel(x, y) ++ } ++ } ++ assertArrayEquals( ++ expected(width, height), ++ extractLuma(ByteBuffer.wrap(interleaved), rowStride, pixelStride, width, height), ++ ) ++ } ++ ++ @Test ++ fun aPlaneWithoutTrailingPaddingIsStillRead() { ++ // Some cameras stop the plane after the last row's pixels, so the ++ // buffer is rowStride * (height - 1) + width bytes, not rowStride * ++ // height. Reading past that must not throw. ++ val width = 4 ++ val height = 3 ++ val rowStride = 6 ++ val size = rowStride * (height - 1) + width ++ val plane = ByteArray(size) { 0x7F } ++ for (y in 0 until height) { ++ for (x in 0 until width) { ++ val at = y * rowStride + x ++ if (at < size) plane[at] = pixel(x, y) ++ } ++ } ++ assertArrayEquals( ++ expected(width, height), ++ extractLuma(ByteBuffer.wrap(plane), rowStride, pixelStride = 1, width, height), ++ ) ++ } ++} +diff --git a/taler-kotlin-android/src/test/java/net/taler/lib/android/qr/QrFrameDecodeTest.kt b/taler-kotlin-android/src/test/java/net/taler/lib/android/qr/QrFrameDecodeTest.kt +new file mode 100644 +index 00000000..9bdc6ba8 +--- /dev/null ++++ b/taler-kotlin-android/src/test/java/net/taler/lib/android/qr/QrFrameDecodeTest.kt +@@ -0,0 +1,163 @@ ++/* ++ * This file is part of GNU Taler ++ * (C) 2026 Taler Systems S.A. ++ * ++ * GNU Taler is free software; you can redistribute it and/or modify it under the ++ * terms of the GNU General Public License as published by the Free Software ++ * Foundation; either version 3, or (at your option) any later version. ++ * ++ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY ++ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR ++ * A PARTICULAR PURPOSE. See the GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License along with ++ * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> ++ */ ++ ++package net.taler.lib.android.qr ++ ++import com.google.zxing.BarcodeFormat ++import com.google.zxing.BinaryBitmap ++import com.google.zxing.DecodeHintType ++import com.google.zxing.EncodeHintType ++import com.google.zxing.MultiFormatReader ++import com.google.zxing.NotFoundException ++import com.google.zxing.PlanarYUVLuminanceSource ++import com.google.zxing.common.HybridBinarizer ++import com.google.zxing.qrcode.QRCodeWriter ++import org.junit.Assert.assertEquals ++import org.junit.Assert.assertNull ++import org.junit.Test ++import java.nio.ByteBuffer ++ ++/** ++ * The camera half of QR scanning, end to end, without a camera. ++ * ++ * A camera frame is only a luminance plane plus the two numbers that say how ++ * it is laid out, so a frame can be built here and put through the same ++ * decoder the analyzer uses. That covers the part of scanning that no ++ * emulator can test -- the virtual camera cannot be pointed at a code -- and ++ * it covers it on every device layout at once rather than on whichever one the ++ * test phone happens to use. ++ */ ++class QrFrameDecodeTest { ++ ++ private val payload = "taler://pay/backend.demo.taler.net/2026.123-02B5CYNPRHXRC/" ++ ++ private val width = 640 ++ private val height = 480 ++ private val codeSize = 400 ++ ++ /** ++ * The luminance plane of a frame with the code centred on white, laid out ++ * with [rowStride] bytes per row and [pixelStride] bytes per sample. ++ * [rowStride] counts bytes, so an interleaved plane needs at least ++ * `width * pixelStride` of them. ++ */ ++ private fun frame(rowStride: Int = width, pixelStride: Int = 1): ByteArray { ++ val matrix = QRCodeWriter().encode( ++ payload, BarcodeFormat.QR_CODE, codeSize, codeSize, ++ mapOf(EncodeHintType.MARGIN to 1), ++ ) ++ val plane = ByteArray(rowStride * height) { -1 } // white ++ val left = (width - codeSize) / 2 ++ val top = (height - codeSize) / 2 ++ for (y in 0 until codeSize) { ++ for (x in 0 until codeSize) { ++ if (matrix.get(x, y)) { ++ val at = (y + top) * rowStride + (x + left) * pixelStride ++ plane[at] = 0 // ink ++ } ++ } ++ } ++ return plane ++ } ++ ++ /** The analyzer's decoder: zxing over a luminance plane. */ ++ private fun decode(luma: ByteArray, width: Int, height: Int): String? { ++ val reader = MultiFormatReader().apply { ++ setHints( ++ mapOf( ++ DecodeHintType.POSSIBLE_FORMATS to listOf(BarcodeFormat.QR_CODE), ++ DecodeHintType.CHARACTER_SET to "UTF-8", ++ ), ++ ) ++ } ++ val source = PlanarYUVLuminanceSource( ++ luma, width, height, 0, 0, width, height, false, ++ ) ++ return try { ++ reader.decodeWithState(BinaryBitmap(HybridBinarizer(source))).text ++ } catch (_: NotFoundException) { ++ null ++ } ++ } ++ ++ private fun lumaOf(rowStride: Int, pixelStride: Int = 1) = extractLuma( ++ ByteBuffer.wrap(frame(rowStride, pixelStride)), ++ rowStride, pixelStride, width, height, ++ ) ++ ++ @Test ++ fun aTightlyPackedFrameDecodes() { ++ assertEquals(payload, decode(lumaOf(width), width, height)) ++ } ++ ++ @Test ++ fun aFrameWithPaddedRowsDecodes() { ++ // Whether the camera pads, and by how much, is the camera's choice. ++ for (padding in listOf(16, 32, 64, 128)) { ++ val rowStride = width + padding ++ assertEquals( ++ "padding of $padding bytes", ++ payload, ++ decode(lumaOf(rowStride), width, height), ++ ) ++ } ++ } ++ ++ @Test ++ fun aFrameWithInterleavedSamplesDecodes() { ++ assertEquals(payload, decode(lumaOf(width * 2, pixelStride = 2), width, height)) ++ } ++ ++ @Test ++ fun copyingAPaddedPlaneWholesaleDoesNotDecode() { ++ // What the analyzer used to do, kept as the reason the code above ++ // exists: one bulk copy of a padded plane shifts every row after the ++ // first, and the decoder then never finds anything at all. ++ val rowStride = width + 32 ++ assertNull(decode(frame(rowStride), width, height)) ++ } ++ ++ @Test ++ fun theCodeIsReadWhicheverWayUpThePhoneIsHeld() { ++ // zxing finds a QR code by its finder patterns and takes the ++ // orientation from them, so the analyzer does not have to rotate the ++ // frame to the upright position first. ++ val upright = lumaOf(width) ++ for (degrees in listOf(0, 90, 180, 270)) { ++ val turned = rotate(upright, width, height, degrees) ++ val w = if (degrees == 90 || degrees == 270) height else width ++ val h = if (degrees == 90 || degrees == 270) width else height ++ assertEquals("rotated by $degrees", payload, decode(turned, w, h)) ++ } ++ } ++ ++ /** Clockwise rotation of a tightly packed plane, as the sensor would give it. */ ++ private fun rotate(plane: ByteArray, width: Int, height: Int, degrees: Int): ByteArray { ++ val out = ByteArray(width * height) ++ for (y in 0 until height) { ++ for (x in 0 until width) { ++ val v = plane[y * width + x] ++ when (degrees) { ++ 90 -> out[x * height + (height - 1 - y)] = v ++ 180 -> out[(height - 1 - y) * width + (width - 1 - x)] = v ++ 270 -> out[(width - 1 - x) * height + y] = v ++ else -> out[y * width + x] = v ++ } ++ } ++ } ++ return out ++ } ++} diff --git a/simulator/findings/qr-camera-ignores-the-plane-strides.md b/simulator/findings/qr-camera-ignores-the-plane-strides.md @@ -0,0 +1,297 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Scanning a QR code reads the camera frame wrong, and one bad frame ends scanning + +Investigated after a report that scanning works on Android 15 but not on +Android 14. The camera cannot be driven from an emulator — the virtual scene's +camera pose cannot be aimed at a code — so the pipeline was taken apart +instead: a camera frame is a luminance plane plus two numbers saying how it is +laid out, which can be built on a workstation and put through the app's own +arithmetic. Everything below is reproducible with a JDK and the zxing jar the +app already depends on; no device, no emulator, no camera. + +**Severity: high.** Two independent defects, each of which stops scanning +outright rather than degrading it. Neither produces an error message: the +viewfinder keeps running, the user waves the phone at a valid code, and the +wallet never reacts. + +## Defect 1 — the frame's layout is ignored, so nothing decodes + +`QrCameraAnalyzer` converts each frame by hand and never looks at how it is +laid out: + +```kotlin +// taler-kotlin-android/src/main/java/net/taler/lib/android/qr/QrCameraAnalyzer.kt:150 +private fun yuv420888ToNv21(image: Image): ByteArray { + val yPlane = image.planes[0].buffer + … + val ySize = yPlane.remaining() + yPlane.get(nv21, 0, ySize) // one bulk copy + … +} +``` + +```console +$ grep -c 'rowStride\|pixelStride' QrCameraAnalyzer.kt +0 +``` + +A `YUV_420_888` plane is not a tightly packed image. `rowStride` is the +distance between the starts of two rows and the hardware is free to pad, so +`rowStride >= width`; `pixelStride` is the distance between two samples. +(`ImageFormat.YUV_420_888` documents the Y plane's pixel stride as always one, +so row padding is the part that varies in practice — the patch handles both +because handling both costs nothing.) A single `get()` is correct only when the +plane happens to be tight. With padded rows every row after the first lands +shifted by the padding, the image shears a little further on each line, the +finder patterns stop being squares, and zxing returns `NotFoundException` for +every frame — which the analyzer swallows, so a systematically broken decoder +looks exactly like an empty viewfinder. + +Run against the current code, `repro_qr_plane_strides.java`: + +``` +== 1. control: tightly packed plane, rotation 0 +app pipeline, rowStride == width decoded + +== 2. the same frame with padded rows (rowStride > width) +app pipeline, rowStride = 656 (pad 16) FAIL: NotFoundException + patched extractLuma, same frame decoded + zxing dataWidth = rowStride, no copy at all decoded +app pipeline, rowStride = 672 (pad 32) FAIL: NotFoundException + … (same for 64, 128) + +== 3. interleaved luma (pixelStride 2) +app pipeline FAIL: NotFoundException + patched extractLuma decoded +``` + +Not "degraded": no padding value decodes a single frame, and the same frame +decodes the moment the stride is honoured. The code is in the frame, unchanged; +only the arithmetic differs. + +## Defect 2 — a frame that throws stops the camera for good + +`proxy.close()` sits in the `finally` of the *decode* `try`, which is entered +after the conversion and rotation have already run: + +```kotlin +val nv21 = yuv420888ToNv21(mediaImage) // throws here … +val (rotatedNv21, …) = rotateNV21(nv21, …) // … or here +… +try { + onQrDetected(qrReader.decodeWithState(bitmap).text) +} catch (_: NotFoundException) { +} finally { + proxy.close() // … and this never runs +} +``` + +The analysis use case is built with `STRATEGY_KEEP_ONLY_LATEST`, under which +CameraX holds one frame and acquires the next only once the current proxy is +closed. So an exception anywhere above that `try` does not cost one frame: it +ends frame delivery for the rest of the screen's life, while the preview — a +separate use case — carries on looking perfectly healthy. + +That is not hypothetical, because the two defects meet. `rotateNV21` sizes its +output from `width * height` while the array it was handed was sized from the +*padded* `remaining()`, and its 180° branch copies the chroma tail out to +`data.size`: + +``` +== 4. the app's rotation on a padded plane +rotation 90 degrees, rowStride = 672 FAIL: NotFoundException +rotation 180 degrees, rowStride = 672 THREW ArrayIndexOutOfBoundsException: Index 460800 out of bounds for length 460800 +rotation 270 degrees, rowStride = 672 FAIL: NotFoundException +``` + +`rotationDegrees == 180` is reached when the device is held in the orientation +opposite to the sensor's, and nothing in the wallet constrains that: + +```console +$ grep -rn screenOrientation wallet/src/main/AndroidManifest.xml +$ # no output -- the scan screen rotates freely +``` + +So on a device whose camera pads its rows, turning the phone around during a +scan kills scanning until the screen is left and re-entered — with no error, +no log line, and a live preview. + +## Defect 3 — the analysis runs on the UI thread + +```kotlin +useCase.setAnalyzer(mainExecutor) { proxy -> … } +``` + +Every frame costs a copy of the luminance plane plus a zxing decode, and both +happen on the main thread, at frame rate. It is not why scanning fails, but it +is why the scan screen janks, and it makes a slow decode cost dropped frames. + +## What is *not* wrong + +Worth recording, because each of these is a plausible place to go looking: + +* **The rotation arithmetic is correct.** On a tightly packed plane all three + branches produce a decodable image (section 6 of the reproducer). The 270° + branch's odd-looking indexing is in the chroma half, which nothing reads. +* **The rotation is not needed at all.** zxing locates a QR code by its three + finder patterns and derives the orientation from them: + + ``` + == 5. is the rotation needed at all? (tight plane, kept as it arrives) + frame arrives rotated 0, decoded as-is decoded + frame arrives rotated 90, decoded as-is decoded + frame arrives rotated 180, decoded as-is decoded + frame arrives rotated 270, decoded as-is decoded + ``` + + So `rotateNV21` buys nothing, and it is where the crash lives. Deleting it is + the fix, not repairing it. +* **Asking zxing to rotate instead would be worse.** The obvious replacement, + `PlanarYUVLuminanceSource.rotateCounterClockwise()`, is not implemented: + zxing 3.5.3 *and* 3.5.4 inherit the base class, where + `isRotateSupported()` returns false and the method throws + `UnsupportedOperationException`. The merchant terminal's copy of this + pipeline does exactly that — see + `pos-config-scanner-asks-for-a-rotation-zxing-refuses.md`. +* **The decoder and the hints are fine**, and so is the gallery path. Importing + a photo of a code decodes 10 of 10 on API 34 and on API 36, with identical + screens; that route goes through `decodeQrFromBitmap`, which builds an + `RGBLuminanceSource` from `Bitmap.getPixels` and so never touches any of the + arithmetic above. A working gallery import is therefore not evidence that the + camera path works — it is the control that isolates it. + +## Why this can differ between Android versions + +The layout is the camera's choice, not the app's: it comes from the HAL, +together with the resolution CameraX selects from the device's advertised +stream configurations. Both can change when a device is upgraded — the same +hardware with a new vendor camera stack may pad where it did not before, or +offer a different analysis resolution — and both differ between devices. +"Works on 15, not on 14" is precisely the shape of a stride assumption, which +is why the report points here. It is *not* proof: the two numbers that decide +it can be printed in one log line, which is the first manual test below. + +## Reproduce + +Without a device, against an unpatched checkout: + +```bash +ZX=$(find ~/.gradle ~/.m2 -name 'core-3.5.*.jar' | head -1) +javac -cp "$ZX" -d /tmp/qrrepro simulator/findings/repro_qr_plane_strides.java +java -cp "$ZX:/tmp/qrrepro" repro_qr_plane_strides +``` + +With the patch applied, the same ground is covered by unit tests that stay in +the tree: + +```bash +./gradlew :taler-kotlin-android:testDebugUnitTest \ + --tests 'net.taler.lib.android.qr.*' +``` + +`ExtractLumaTest` (4 cases) pins the layout arithmetic; +`QrFrameDecodeTest` (5 cases) encodes a real QR code, lays it out tight, +padded by 16/32/64/128 bytes and interleaved, and asserts it decodes — plus +one case asserting that the *old* bulk copy does not decode, and one that the +code reads at all four orientations. All nine pass with the patch; the four +`ExtractLumaTest` cases were written first and three of them failed against the +original arithmetic. + +By hand on an affected device: open **Scan QR code**, point it at any valid +`taler://` code, and nothing happens — no error, no reaction, and `adb logcat` +shows nothing, because the per-frame `NotFoundException` is caught and dropped. + +## Fix + +`qr-camera-ignores-the-plane-strides.diff` does all of it in one file: + +* `extractLuma(buffer, rowStride, pixelStride, width, height)` — a pure + function, so it is testable without an emulator — copies the luminance plane + row by row, skips the padding, steps by `pixelStride`, keeps the single + `get()` fast path for the tight case, and drops the chroma copy that zxing + never read. +* `rotateNV21` is deleted (see above). +* The whole frame body is wrapped in `try { … } catch (e: Exception) { Log.w } + finally { proxy.close() }`, so no frame can stop the camera. +* Analysis moves to a single-thread executor, with `onQrDetected` posted back + to the main thread. + +Verified: `:taler-kotlin-android:compileDebugKotlin`, `:taler-kotlin-android:lintDebug` +(0 errors) and the nine unit tests above all pass. Not verified on a real +camera — that is what the manual tests are for. + +### Reference implementations, none of them Google Play + +The arithmetic above is the minimal change. Two alternatives are worth knowing, +because both move the problem out of the app entirely, and neither needs Play +Services (no ML Kit anywhere): + +1. **Let zxing take the stride.** `PlanarYUVLuminanceSource`'s constructor + already separates the buffer's layout from the image: + `(yuvData, dataWidth, dataHeight, left, top, width, height, reverseHoriz)`. + Passing `rowStride` as `dataWidth` and `width`/`height` as the crop decodes + a padded frame with no stride arithmetic in the app at all — the + "no copy at all" line in section 2 of the reproducer. This is what the + merchant terminal's patch uses, being a four-line change there. +2. **Let CameraX do the conversion.** `camera-core` 1.5.3 (already a + dependency) carries, verified by `javap` on the resolved artifact: + `ImageAnalysis.Builder.setOutputImageFormat(OUTPUT_IMAGE_FORMAT_NV21)`, + `setOutputImageRotationEnabled(boolean)`, and internally + `ImageProcessingUtil.rotateYUVAndConvertToNV21` over a libyuv + `nativeRotateYUV`. That delivers a tightly packed, already-rotated NV21 + buffer from native code, which is exactly what `PlanarYUVLuminanceSource` + wants, and deletes both hand-written functions. CameraX's own stride-aware + conversion, `androidx.camera.core.internal.utils.ImageUtil.yuv_420_888toNv21`, + is worth reading as the reference arithmetic but is a restricted API — read + it, do not call it. + `OUTPUT_IMAGE_FORMAT_RGBA_8888` plus `ImageProxy.toBitmap()` would go + further and let the camera and gallery paths share the one + `decodeQrFromBitmap` decoder, at the cost of an RGBA conversion per frame + where zxing only ever reads luminance. + +Worth doing alongside, in any variant: count consecutive failed decodes and log +one debug line when the count crosses a threshold. Both defects above were +silent, and that single counter would have named either of them in a minute. + +## Attended tests the developer should run + +These need a human holding a phone; each one is chosen to separate a cause +rather than to confirm a guess. + +1. **Print the layout, once per session.** `rowStride`, `pixelStride`, + `width`, `height` of `planes[0]`, plus `rotationDegrees` and the resolution + CameraX chose, on every device and OS version in the report. This is the + decisive test: if `rowStride == width` on Android 15 and `rowStride > width` + on Android 14 for the same hardware, defect 1 is the report, and nothing + else needs proving. Ideally on the same device before and after the upgrade. +2. **Scan in all four orientations**, portrait, both landscapes and upside + down, on a device whose rows are padded. Reverse orientation is where + `rotationDegrees == 180`, the branch that throws. +3. **After a failed scan, check whether frames still arrive** — a temporary + per-frame counter in the analyzer is enough. "No frames" means defect 2; + "frames but no decode" means defect 1. Then leave the screen and come back: + if scanning works again until the next failure, that is defect 2 confirmed. +4. **Import a photo of the same code from the gallery.** It goes through a + different decoder. Gallery decodes, camera does not ⇒ the fault is in the + frame handling, not in the code, the decoder or the lighting. +5. **Vary the code's size in the frame and the light**: filling the frame, + then small and at arm's length, then dim. A layout fault fails all of them + identically; focus and resolution problems do not. +6. **Scan a non-Taler QR code** (any URL). It exercises the same pipeline + without the app's URI handling, so a decode that the wallet ignores + separates "could not read the code" from "read it and did nothing with it". diff --git a/simulator/findings/refresh-fails-on-mixed-age-denominations.md b/simulator/findings/refresh-fails-on-mixed-age-denominations.md @@ -0,0 +1,117 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Change is lost when a denomination family mixes age-restricted and ordinary coins + +Found by the `refund` scenario in round 7, once the simulator's exchange was +given age-restricted denominations alongside the ordinary ones. + +**Severity: moderate, and it applies to the shipped app.** What is certain is +that the exchange refuses the melt and wallet-core retries the refresh group +indefinitely — a permanent background failure on an ordinary spend. What is +*not* established is money loss: in the run measured here the displayed balance +after withdraw / pay / refund was exactly what the arithmetic predicts +(EUR:8.75), with nothing shown as pending, so the user may see nothing wrong +while a refresh churns underneath. Whether the affected coins remain spendable +over a longer horizon was not determined. + +It only shows on an exchange that offers both kinds of denomination for the +same value — which is exactly what an exchange supporting age restriction +looks like. + +**Already fixed upstream**: wallet-core commit `efb714f76`, "wallet-core: +preserve denomination age masks during refresh" (2026-09-14). The app ships +`net.taler:qtart:1.6.42`, which is wallet-core `c2e11ad42` of 2026-09-01 — +thirteen days older. Bumping `qtart_version` in `wallet/build.gradle` to a +build that contains that commit is the fix here. + +## What happens + +Withdraw, spend part of a coin, take a refund. The exchange rejects the melt +that the refresh needs: + +```json +{"code":1365, + "hint":"The client provided invalid age commitment data: missing, not an + array, or array of invalid size.", + "detail":"old_age_commitment_h"} +``` + +`EXCHANGE_REFRESHES_REVEAL_AGE_RESTRICTION_COMMITMENT_INVALID`. wallet-core +then reports the group as incomplete and keeps retrying: + +``` +refresh:54W1D6A47J8PPS8EE681YRWCD5S2QACVM5GEK1MEGEQTGFFJ70CG: + code 7029: Error (WALLET_REFRESH_GROUP_INCOMPLETE) +refresh:54W1D6A47J8PPS8EE681YRWCD5S2QACVM5GEK1MEGEQTGFFJ70CG: retried 5 times +``` + +In that one episode: 8 rejections from the exchange, 22 refresh-incomplete +errors. The retry counter keeps climbing (5, then 8, …) for as long as the +wallet is watched. + +Which member of the denomination family the wallet picks for the new coins +decides whether the age mask matches, so it is not certain on every spend — +but it is common: the reproducer below hit it on its **first** withdraw / +spend / refund cycle (six rejections), while one earlier run of the `refund` +scenario on the same stack produced none. + +## Reproduce by hand + +1. Run an exchange that offers age-restricted *and* ordinary denominations for + the same values. In the simulator's `backend/sim.conf` that is + `AGE_RESTRICTION_ENABLED = YES` in `[exchange]` plus the `coin_eur_*` and + `coin_eur_*_age_restricted` sections; `/keys` then advertises group age + masks of both `0` and `2446593`. +2. Install the wallet, enable **Developer mode**, and withdraw from that + exchange (no age restriction needed). +3. Pay for something that costs less than one coin — the remainder has to be + refreshed into change. +4. Take a refund for part of it. +5. Watch `adb logcat | grep -E '"code":1365|REFRESH_GROUP_INCOMPLETE'`. When + the wallet picks an incompatible family member, the rejection appears and + repeats as the refresh is retried. + +Nothing is shown in the UI — no error, nothing pending — which is what makes +this worth fixing even where the balance ends up right: a user has no way to +know their wallet is retrying a request the exchange will always refuse. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_age_restricted_refresh_fails.py # three cycles +python3 ../findings/repro_age_restricted_refresh_fails.py emulator-5562 5 +``` + +## Why + +`refresh.ts` sends `old_age_commitment_h` with the melt, and the new coins +have to be chosen with an age mask compatible with the old one. Before +`efb714f76`, the denomination selected for the new coins could come from a +different member of the same family — one with a different age mask — and the +exchange rejects the reveal as inconsistent. The commit's own words: "Select a +compatible member of each denomination family and use the same age-mask +constraint for refresh cost estimates. Families can contain both restricted +and unrestricted denominations." + +## Suggested fix + +Bump `qtart_version` in `wallet/build.gradle` past wallet-core `efb714f76`, +and keep an age-restriction-enabled exchange in whatever integration testing +the app does — the defect is invisible without one, which is why it survived +to a release. diff --git a/simulator/findings/release-error-screen-explains-nothing.diff b/simulator/findings/release-error-screen-explains-nothing.diff @@ -0,0 +1,61 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt +index a73e286c..dc719377 100644 +--- a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt ++++ b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt +@@ -78,6 +78,14 @@ data class TalerErrorInfo( + // so they are not re-encoded as -1. + val rawCode: Int = code.code, + ) { ++ /** ++ * What to show a user, which is often nothing: plenty of errors carry ++ * neither a hint nor a message -- 7001 and 7048 among them -- and this is ++ * then empty. A display site that has a [android.content.Context] should ++ * fall back to the error code; this class has none, and the code's own ++ * name ("WALLET_UNEXPECTED_EXCEPTION") is not something to put in front ++ * of a user. ++ */ + val userFacingMsg: String + get() { + return StringBuilder().apply { +@@ -93,7 +101,7 @@ data class TalerErrorInfo( + hint?.let { append(it) } + message?.let { append(" ").append(it) } + } +- }.toString() ++ }.toString().trim() + } + + fun getStringExtra(key: String): String? = +diff --git a/wallet/src/main/java/net/taler/wallet/compose/ErrorComposable.kt b/wallet/src/main/java/net/taler/wallet/compose/ErrorComposable.kt +index d3a8165f..ddd2d0ed 100644 +--- a/wallet/src/main/java/net/taler/wallet/compose/ErrorComposable.kt ++++ b/wallet/src/main/java/net/taler/wallet/compose/ErrorComposable.kt +@@ -116,7 +116,15 @@ fun ErrorComposable( + } + } else { + Text( +- text = error.userFacingMsg, ++ // Without developer mode this is the whole explanation, and ++ // for an error with neither a hint nor a message it is empty, ++ // which leaves the sheet saying only "Error". The code is ++ // not an explanation either, but it is something the user can ++ // report. rawCode rather than code.code: a code newer than ++ // this app's registry is preserved there. ++ text = error.userFacingMsg.ifEmpty { ++ stringResource(R.string.error_code_only, error.rawCode) ++ }, + fontFamily = FontFamily.Default, + textAlign = TextAlign.Center, + ) +diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml +index 905e4390..b3a63920 100644 +--- a/wallet/src/main/res/values/strings.xml ++++ b/wallet/src/main/res/values/strings.xml +@@ -65,6 +65,7 @@ GNU Taler is immune to many types of fraud such as credit card data theft, phish + <string name="enter_uri_label">Taler link</string> + <string name="enter_uri_prefix" translatable="false">taler://</string> + <string name="error">Error</string> ++ <string name="error_code_only">Error code %1$d</string> + <string name="error_export">Export error diagnostics</string> + <string name="wallet_init_error_title">Initialization error</string> + <string name="wallet_init_error_message">An error occurred while starting the wallet. This can happen after an app update or if the wallet data is incompatible. Please retry, and if the problem persists, export the logs and report this issue to the developers.</string> diff --git a/simulator/findings/release-error-screen-explains-nothing.md b/simulator/findings/release-error-screen-explains-nothing.md @@ -0,0 +1,225 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# In a release build, an error screen can explain nothing at all + +Found by the `error_screen_without_dev_mode` scenario, written because +everything else in this campaign runs with developer mode on — where the error +screen prints the whole error as JSON and the defect is invisible. + +**Severity: moderate, release builds only.** It applies to every error whose +explanation wallet-core puts somewhere other than `hint` or `message`, which +includes `WALLET_CORE_API_BAD_REQUEST` (7048) — one of the codes this campaign +hit in ordinary runs. + +## What happens + +With developer mode **on**, an error with no hint and no message shows the raw +object, which at least names the code: + +``` +Error +{ + "code": 7001, + "hint": null, + "message": null +} +Export error diagnostics [Copy] [Share] +``` + +With developer mode **off** — which is what a release build is — the same error +shows: + +``` +Error +Export error diagnostics [Copy] [Share] +``` + +An icon, the word "Error", and an invitation to export diagnostics. Nothing +about what failed, what to do, or which operation it was. + +## Why + +`ErrorComposable` has two branches, and the release one prints a single string: + +```kotlin +// wallet/src/main/java/net/taler/wallet/compose/ErrorComposable.kt:105 +if (devMode) { + … Text(text = jsonError, fontFamily = FontFamily.Monospace) … +} else { + Text(text = error.userFacingMsg, …) +} +``` + +and that string is the hint and the message concatenated, with no fallback: + +```kotlin +// wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt:81 +val userFacingMsg: String + get() = StringBuilder().apply { + if (extra.containsKey("errorResponse")) { … } + else { + hint?.let { append(it) } + message?.let { append(" ").append(it) } + } + }.toString() +``` + +Both null gives the empty string, and `Text("")` is nothing. + +This is not hypothetical. wallet-core puts the explanation of a bad request in +`detail`, which this very campaign has logged: + +``` +{"type":"error","operation":"addExchange","id":100, + "error":{"code":7048,"detail":"URL cannot be parsed"}} +``` + +`detail` is not lost — the custom `TalerErrorInfoSerializer` keeps every +unknown key in `extra`, and the "Copy"/"Share" buttons export the complete +object including it. It is simply never *shown*: `userFacingMsg` looks at +`hint`, at `message`, and at one special case (`extra["errorResponse"].hint`), +and at nothing else. + +The other end of the same problem: whatever *is* in `message` goes to the user +verbatim, exception class names included. Feeding the balance screen a reply +with an out-of-spec currency (`api_response_hostile`) produced + +``` +{"code": 0, "hint": "", + "message": "net.taler.common.AmountParserException: Invalid currency: VERYLONGCURRENCY"} +``` + +so a release build would show the user a Java class name — and the whole +balance screen becomes an error page, which for a *rejected* value is the right +severity but the wrong words. + +The mailbox screen does not even go through `ErrorComposable`; it interpolates +the error object into a string: + +```kotlin +// wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt:150 +is MailboxResult.Error -> Text("Error: ${res.error}", modifier = Modifier.padding(16.dp)) +``` + +which is a Kotlin data-class dump. Typing a malformed mailbox URL puts this on +the screen, in any build: + +``` +Error: TalerErrorInfo(code=WALLET_UNEXPECTED_EXCEPTION, hint=unexpected +exception (message: Invalid base URL: http://localhost:11000unet.org), +message=null, extra={when={"t_ms":…}, stack=" at URLImpl (<compiled_js>:4523:28) + at registerMailbox (<compiled_js>:… +``` + +— a QuickJS stack trace, shown to the user, on a screen that is not +developer-mode gated. + +## Reproduce by hand + +Needs a debug build (to deliver the URI) and one trip through the developer +mode switch: + +1. Enable **Developer mode** in Settings. +2. Queue an error with neither hint nor message — `{"code": 7001}`, base64url + encoded: + + ```bash + adb shell am start -a android.intent.action.VIEW -d \ + 'taler+http://dev-experiment/api-error?operation=getBalances&detail=eyJjb2RlIjogNzAwMX0&count=20' + ``` + +3. Go to the main screen: the error screen appears with the JSON. +4. Turn **Developer mode** off and go back to the main screen. +5. The error screen now shows only "Error" and the export buttons. + +A release build reaches the same state without step 1 or 4, with any error of +that shape — for example by adding `file:///etc/passwd` as a payment service, +whose refusal is a 7048 with only a `detail` (that one is also never shown at +all; see +[`add-payment-service-fails-silently.md`](add-payment-service-fails-silently.md)). + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_release_error_screen.py +SIM_WORKER=4 python3 suite.py error_screen_without_dev_mode +``` + +The notes record the screen with developer mode on, then off, and list +everything on the second one that could explain the error — which is nothing. + +## Fix + +`release-error-screen-explains-nothing.diff` makes the error sheet fall back to +the code when there is no text to show: + +```kotlin +// wallet/src/main/java/net/taler/wallet/compose/ErrorComposable.kt +text = error.userFacingMsg.ifEmpty { + stringResource(R.string.error_code_only, error.rawCode) +}, +``` + +with `<string name="error_code_only">Error code %1$d</string>` beside it, and +`userFacingMsg` left honest — trimmed, and empty when the error carries nothing +— with a doc comment saying where the fallback belongs. `rawCode` rather than +`code.code`, because a code newer than this app's registry is preserved there +while `code` has become `-1`. + +The screen then reads: + +``` +Error +Error code 7001 +Export error diagnostics [Copy] [Share] +``` + +### What running it changed + +The first version of this patch put the fallback inside `userFacingMsg` itself +and rendered `"Error code ${code.code} (${code.name})"`. It compiled, it +lint-passed, and on a device it produced: + +``` +Error code 7001 (WALLET_UNEXPECTED_EXCEPTION) +``` + +which the simulator immediately flagged as an `internal-error-screen` — its +oracle looks for words like "unexpected" and "exception" on screen, on the +grounds that they should not reach a user, and it was right. The enum name is +an identifier for developers; it is also untranslatable English in a UI that is +otherwise localised, and `TalerErrorInfo` has no `Context` to localise with. +Moving the fallback to the sheet, where there *is* a `Context`, fixes both: the +string is in `strings.xml` like every other, and the user sees a number they can +report rather than a phrase that reads like a crash. + +The second version was re-run on the same scenario, on a device, and the sheet +is now recorded as an ordinary error screen rather than an internal one: + +``` + error_screen_without_dev_mode ok 0 serious, 2 total, 128.7s + [error-screen] { "code": 7001, "hint": null, "message": null } + [error-screen] Error code 7001 +``` + +Worth noting for whoever takes this further: the other six places that render +`userFacingMsg` — the transactions list, the peer screens, the contact and +alias screens, and `TestWithdrawStatus` — still show nothing for an error that +carries neither hint nor message. The sheet is the one a release user meets +first, which is why the patch stops there. diff --git a/simulator/findings/repro_aborted_fee.py b/simulator/findings/repro_aborted_fee.py @@ -0,0 +1,77 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: an aborted withdrawal shows the whole amount as a fee. + +The fee row on every credit screen is the difference between the raw and the +effective amount. Aborting zeroes the effective amount, so the difference +becomes the entire amount and the screen claims it all went to fees. + + cd /opt/taler-sim/driver + python3 ../findings/repro_aborted_fee.py [emulator-5554] +""" + +from __future__ import annotations + +import re +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from device import Device # noqa: E402 +from stack import Bank, Env # noqa: E402 +from wallet import Wallet # noqa: E402 + +AMOUNT = "EUR:5" +AS_SHOWN = "5.00" + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + bank = Bank(env.bank) + + app.fresh_start(dev_mode=True) + op = bank.create_withdrawal(*scenarios.WALLET_USER, AMOUNT) + app.handle_uri(op["taler_withdraw_uri"]) + scenarios.accept_tos(app) + dev.tap_text(r"(?i)confirm withdrawal", timeout=60) + dev.wait_for(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + + # Abort before the bank confirms: nothing is withdrawn and no fee is paid. + dev.tap_text(r"(?i)^Abort$", timeout=30) + time.sleep(1.5) + if dev.dump().find(r"(?i)Abort transaction|Are you sure") is not None: + dev.tap_text(r"(?i)^Abort$|^OK$|^Yes$", timeout=15) + screen = dev.wait_for(r"(?i)was aborted|has failed", timeout=60) + time.sleep(1) + screen = dev.dump() + texts = screen.texts() + print(f"aborted transaction: {texts[:14]}") + + has_fee_row = screen.find(r"(?i)^Fee$") is not None + amounts = [t for t in texts if re.match(r"^[-−]?[€$]?\d", t)] + whole_as_fee = any(t.lstrip("-−").lstrip("€$") == AS_SHOWN for t in amounts[1:]) + print(f"fee row present: {has_fee_row}") + print(f"amounts shown: {amounts[:6]}") + print(f"\nreproduced: {has_fee_row and whole_as_fee}") + return 0 if (has_fee_row and whole_as_fee) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/repro_action_buttons_no_a11y_name.py b/simulator/findings/repro_action_buttons_no_a11y_name.py @@ -0,0 +1,76 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: the balance card's action buttons have no accessible name. + +Needs a wallet with a balance, so the action row is on screen; run +`driver/smoke_withdraw.py` first, or pass --fund to do a withdrawal here. + + cd /opt/taler-sim/driver + python3 ../findings/repro_action_buttons_no_a11y_name.py [--fund] + +Exits 0 when the defect is present (unnamed clickable buttons paired with +separate text labels), 1 when every action button has a name. +""" + +from __future__ import annotations + +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import Device # noqa: E402 +from stack import Bank, Env # noqa: E402 +from wallet import Wallet # noqa: E402 + +ACTIONS = ("Send", "Request", "Withdraw", "Deposit") + + +def main() -> int: + dev = Device(sys.argv[1] if len(sys.argv) > 1 and sys.argv[1].startswith("emulator") + else "emulator-5554") + app = Wallet(dev) + if "--fund" in sys.argv: + import scenarios + env = Env.load() + app.fresh_start(dev_mode=True) + scenarios.withdraw(app, Bank(env.bank), "EUR:10") + screen = app.home() + + labels = {name: screen.find(f"^{name}$") for name in ACTIONS} + missing = [name for name, node in labels.items() if node is None] + if missing: + print(f"action row not on screen (missing {missing}); " + f"does the wallet have a balance?\nscreen: {screen.texts()}") + return 2 + + unnamed = [] + for name, node in labels.items(): + button = screen.tap_target(node) + named = bool(button.label.strip()) + print(f"{name:10} label node at {node.center}, " + f"clickable={node.clickable} -> button {button.cls.rsplit('.', 1)[-1]} " + f"at {button.center} accessible-name={button.label.strip()!r}") + if not named and button is not node: + unnamed.append(name) + + print(f"\nclickable nodes on this screen with no accessible name: " + f"{len(screen.unnamed_clickables())}") + print(f"action buttons without an accessible name: {unnamed}") + print(f"\nreproduced: {len(unnamed) == len(ACTIONS)}") + return 0 if len(unnamed) == len(ACTIONS) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/repro_add_exchange_fails_silently.py b/simulator/findings/repro_add_exchange_fails_silently.py @@ -0,0 +1,90 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: adding a payment service with a bad URL fails without saying so. + + cd /opt/taler-sim/driver + python3 ../findings/repro_add_exchange_fails_silently.py [emulator-5554] + +Exits 0 when wallet-core rejected the URL and nothing said so on screen. +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +BAD_URL = "file:///etc/passwd" +COMPLAINT = r"(?i)could not add|error|invalid|failed|not supported" + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + app.fresh_start(dev_mode=True) + + app.open_settings() + app.scroll_to_text(r"(?i)^Payment services$") + dev.tap_text(r"(?i)^Payment services$", timeout=30) + time.sleep(2) + dev.tap_text(r"(?i)^Add payment service$", timeout=30) + time.sleep(2) + + screen = dev.dump() + fields = screen.editable() + if not fields: + print(f"no URL field: {screen.texts()}") + return 2 + dev.tap_node(fields[0], screen) + dev.type_text(BAD_URL) + time.sleep(1) + dev.logcat(clear=True) + + screen = dev.dump() + ok = screen.find(r"(?i)^OK$") + if ok is None: + print(f"no OK button: {screen.texts()}") + return 2 + dev.tap_node(ok, screen) + + # Watch for anything that explains the failure, for longer than a snackbar + # would last. + complaints = [] + for _ in range(6): + time.sleep(1.5) + current = dev.dump() + found = current.find(COMPLAINT) + if found is not None: + complaints.append(found.label) + log = dev.logcat() + rejected = [ln for ln in log.splitlines() + if "addExchange" in ln and '"code":7048' in ln] + + print(f"wallet-core rejections logged: {len(rejected)}") + if rejected: + print(" " + rejected[0][-200:]) + print(f"anything shown to the user: {complaints or 'nothing'}") + print(f"screen now: {dev.dump().texts()[:8]}") + print(f"\nreproduced: {bool(rejected) and not complaints}") + return 0 if (rejected and not complaints) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/repro_age_restricted_refresh_fails.py b/simulator/findings/repro_age_restricted_refresh_fails.py @@ -0,0 +1,101 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: spending age-restricted coins leaves the change stuck. + +Withdraws with an age restriction, spends part of it, and watches what the +exchange says about the refresh that follows. + + cd /opt/taler-sim/driver + python3 ../findings/repro_age_restricted_refresh_fails.py [emulator-5554] + +Needs a stack whose exchange offers age-restricted denominations (the +simulator's sim.conf does). Exits 0 when the exchange rejects the refresh. +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import oracles # noqa: E402 +import scenarios # noqa: E402 +from device import Device # noqa: E402 +from stack import Bank, Env, Merchant # noqa: E402 +from wallet import Wallet # noqa: E402 + +CYCLES = int(sys.argv[2]) if len(sys.argv) > 2 else 3 + + +def spend_and_refund(app: Wallet, dev: Device, bank: Bank, merchant: Merchant, + env: Env) -> list[str]: + """Withdraw, spend part of it, take a refund — each step leaves change to + refresh, which is where the exchange rejects the melt.""" + app.fresh_start(dev_mode=True) + scenarios.withdraw(app, bank, "EUR:10") + app.home() + dev.logcat(clear=True) + + order = merchant.create_order("EUR:2", summary="Partial spend") + app.handle_uri(order["pay_uri"]) + dev.tap_text(r"(?i)^Pay\b|confirm payment", timeout=60) + for _ in range(25): + if merchant.order_status(order["order_id"], + order["token"]).get("order_status") == "paid": + break + time.sleep(2) + # A refund puts the money back, which also has to be refreshed. + res = merchant.refund(order["order_id"], "EUR:1") + if res.get("taler_refund_uri"): + app.handle_uri(res["taler_refund_uri"]) + + rejections: list[str] = [] + for _ in range(5): + time.sleep(15) + log = dev.logcat(lines=6000) + rejections = [ln for ln in log.splitlines() if '"code":1365' in ln] + if rejections: + break + return rejections + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + bank, merchant = Bank(env.bank), Merchant(env.merchant) + + for attempt in range(1, CYCLES + 1): + print(f"--- cycle {attempt} ---") + rejections = spend_and_refund(app, dev, bank, merchant, env) + stuck = [f for f in oracles.background_failures(dev) + if f.kind in ("stuck-operation", "background-error") + and "refresh" in f.detail] + print(f"age-commitment rejections: {len(rejections)}") + for finding in stuck: + print(f" {finding.detail[:140]}") + if rejections: + print(" " + rejections[0][-220:]) + print("\nreproduced: True") + return 0 + print("\nreproduced: False (it is probabilistic: which member of a " + "denomination family the wallet picks decides it)") + return 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/repro_config_change_db_ownership.py b/simulator/findings/repro_config_change_db_ownership.py @@ -0,0 +1,105 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: a configuration change locks the wallet out of its database. + +Changing the app's language restarts it, and the new instance cannot take the +SQLite database while the one it replaced still holds it: + + code 7001, "could not acquire exclusive ownership of the wallet database; + another wallet process may still be using it" + +which lands the user on the Initialization error screen -- the whole app +replaced by two export buttons and an invitation to retry that nothing on the +screen can act on. + +It is a race between the dying and the starting process, so this tries a few +times and reports how often it lost, rather than pretending it is certain. + + cd /opt/taler-sim/driver + python3 ../findings/repro_config_change_db_ownership.py [emulator-5554] [attempts] + +Exits 0 when at least one attempt reaches the error screen. +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +ERROR_SCREEN = (r"(?i)Initialization error|Initialisierungsfehler" + r"|error occurred while starting|Fehler aufgetreten") +OWNERSHIP = r"(?i)exclusive ownership of the wallet database" + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + attempts = int(sys.argv[2]) if len(sys.argv) > 2 else 3 + dev = Device(serial) + app = Wallet(dev) + + if dev.sdk_int < 33: + print(f"this device is API {dev.sdk_int}; this reproducer changes the " + "per-app language, which needs 33+. The same defect should be " + "reachable by changing the font size or the display size, which " + "every version supports -- see the finding's table.") + return 2 + broke = 0 + try: + for n in range(1, attempts + 1): + dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales", check=False) + app.fresh_start(dev_mode=True) + # Any screen will do; a settings sub-screen is where it was first + # seen, and it keeps the wallet busy while the change lands. + app.open_settings() + app.scroll_to_text(r"(?i)^Contacts$", max_scrolls=12) + dev.tap_text(r"(?i)^Contacts$", timeout=20) + time.sleep(3) + + dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales de-DE", + check=False) + time.sleep(9) + screen = dev.dump() + hit = screen.find(ERROR_SCREEN) is not None + print(f"attempt {n}: " + + ("INITIALIZATION ERROR" if hit else "survived") + + f" -- {' | '.join(screen.texts()[:4])[:150]}") + if hit: + broke += 1 + if screen.find(OWNERSHIP) is not None: + print(" the error is the database ownership one") + # Nothing on the screen can retry; the app has to be killed. + buttons = [n_.label for n_ in screen.tappable() if n_.label] + print(f" what the screen offers: {buttons}") + dev.stop() + time.sleep(2) + dev.launch() + time.sleep(10) + again = dev.dump().find(ERROR_SCREEN) is not None + print(f" still broken after a relaunch: {again}") + break + + print(f"\nreproduced: {broke > 0} ({broke} of {n} attempts)") + return 0 if broke else 1 + finally: + dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales", check=False) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/simulator/findings/repro_delete_requeries_transaction.py b/simulator/findings/repro_delete_requeries_transaction.py @@ -0,0 +1,83 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: deleting a transaction makes the app ask for it again. + + cd /opt/taler-sim/driver + python3 ../findings/repro_delete_requeries_transaction.py [emulator-5554] + +Exits 0 when the stray getTransactionById error shows up in the log. +""" + +from __future__ import annotations + +import re +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +import suite # noqa: E402 +from device import Device # noqa: E402 +from stack import Env # noqa: E402 +from wallet import Wallet # noqa: E402 + +# The error carries a nested "when" object between the code and the hint, so +# the two are matched independently rather than with one span. +STRAY = re.compile(r'"operation":"getTransactionById".*?"code":(\d+).*?not found') + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + + # A wallet with one finished withdrawal and one finished purchase. + scenarios.funded_and_paid(app, env) + dev.logcat(clear=True) + + screen = app.home() + if screen.find(r"(?i)^Recent transactions$") is None: + screen = app.scroll_to_text(r"(?i)^Recent transactions$") + rows = suite.transaction_rows(screen) + if not rows: + print(f"no transactions to delete; screen: {screen.texts()}") + return 2 + dev.tap_node(rows[0], screen) + time.sleep(2) + dev.tap_text(r"(?i)^Delete$", timeout=30) + time.sleep(1) + # Confirm the dialog. + confirm = dev.dump().find(r"(?i)^Delete$") + if confirm is not None: + dev.tap_node(confirm, dev.dump()) + time.sleep(4) + + log = dev.logcat() + hits = [ln for ln in log.splitlines() if STRAY.search(ln)] + queries = [ln for ln in log.splitlines() + if '"operation": "getTransactionById"' in ln or + '"operation":"getTransactionById"' in ln] + print(f"getTransactionById mentions after the delete: {len(queries)}") + for line in hits[:4]: + print(line.strip()[:320]) + print(f"\nscreen now: {dev.dump().texts()[:10]}") + print(f"reproduced: {bool(hits)}") + return 0 if hits else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/repro_dev_experiment_uri_exits_app.py b/simulator/findings/repro_dev_experiment_uri_exits_app.py @@ -0,0 +1,82 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: an unknown dev-experiment URI errors internally and exits the app. + +The wallet must be closed when the URI arrives — scanning a QR code or opening +a link from elsewhere — because that is the case where the screen it pops is +the only one in the task. + + cd /opt/taler-sim/driver + python3 ../findings/repro_dev_experiment_uri_exits_app.py [emulator-5554] + +Exits 0 when both halves reproduce: the 7001 error in the log, and the wallet +no longer being the foreground app. +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import PKG, Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +URI = "taler+http://dev-experiment/nonexistent" + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + app.fresh_start(dev_mode=True) + app.home() + # The URI has to arrive while the wallet is *not* open: with the app + # already running the screen pops back to the main screen, and only a + # cold start has nothing behind it to pop to. + dev.stop() + time.sleep(2) + dev.logcat(clear=True) + + dev.send_uri(URI) + # The wallet opens, handles the URI and only then pops the screen, so the + # foreground is sampled until it settles rather than once. + left_at = None + for _ in range(10): + time.sleep(2) + if PKG not in dev.current_activity(): + left_at = dev.current_activity() + break + + screen = dev.dump() + log = dev.logcat() + internal = [ln for ln in log.splitlines() + if "applyDevExperiment" in ln and "7001" in ln] + left_app = left_at is not None or PKG not in screen.activity + + print(f"foreground activity afterwards: " + f"{left_at or screen.activity or '(none)'}") + print(f"on screen: {screen.texts()[:8]}") + for line in internal[:2]: + print(line.strip()[:260]) + print(f"\nwallet left the foreground: {left_app}") + print(f"internal error logged: {bool(internal)}") + print(f"reproduced: {left_app and bool(internal)}") + return 0 if (left_app and internal) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/repro_failed_query_empty_state.py b/simulator/findings/repro_failed_query_empty_state.py @@ -0,0 +1,88 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: a failed query is shown as an empty wallet. + +Two screens state a failure as a fact about the user's wallet: the deposit +screen says there are no bank accounts, and the send screen offers €0.00. +Both are driven by an injected failure of the one wallet-core call each screen +makes. + + cd /opt/taler-sim/driver + python3 ../findings/repro_failed_query_empty_state.py [emulator-5554] +""" + +from __future__ import annotations + +import base64 +import json +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from device import PKG, Device # noqa: E402 +from stack import Env # noqa: E402 +from wallet import Wallet # noqa: E402 + + +def inject(app: Wallet, dev: Device, operation: str, count: int = 4) -> None: + detail = base64.urlsafe_b64encode( + json.dumps({"code": 7001, "hint": "injected"}).encode() + ).decode().rstrip("=") + app.handle_uri(f"taler+http://dev-experiment/api-error?operation={operation}" + f"&detail={detail}&count={count}") + time.sleep(2) + # Applying an experiment ends with a back navigation, which closes the app + # when the URI is what started it. + for _ in range(3): + if dev.dump().activity.startswith(PKG): + return + dev.launch() + time.sleep(6) + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + scenarios.fund_wallet(app, env, "EUR:10") + + inject(app, dev, "getDepositWireTypes") + app.home() + dev.tap_text(r"(?i)^Deposit$", timeout=30) + time.sleep(4) + deposit = dev.dump().texts() + print(f"deposit screen: {deposit[:8]}") + no_accounts = any("No bank accounts" in t for t in deposit) + + app.home() + inject(app, dev, "getMaxPeerPushDebitAmount") + app.home() + dev.tap_text(r"(?i)^Send$", timeout=30) + time.sleep(4) + send = dev.dump().texts() + print(f"send screen: {send[:10]}") + zero_to_send = any(t.strip() in ("€0.00", "Send €0.00") for t in send) + + print(f"\ndeposit claims there are no accounts: {no_accounts}") + print(f"send offers nothing to send: {zero_to_send}") + print(f"reproduced: {no_accounts or zero_to_send}") + return 0 if (no_accounts or zero_to_send) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/repro_global_currency_null_masterpub.py b/simulator/findings/repro_global_currency_null_masterpub.py @@ -0,0 +1,68 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Minimal reproducer: "Treat as global" on an un-contacted exchange. + +Found by explore.py (seed 11, step 34) and shrunk to four taps. See +addglobalcurrencyexchange-null-masterpub.md for the analysis. + + cd /opt/taler-sim/driver && python3 ../findings/repro_global_currency_null_masterpub.py + +Exits 0 when the internal error reproduces, 1 when it does not. +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +# A builtin exchange the wallet has never talked to, so its masterPub is still +# null. exchange.demo.taler.net works too; the local one does not, because +# withdrawing from it fetches /keys and fills masterPub in. +UNCONTACTED = "exchange.taler-ops.ch" + + +def main() -> int: + dev = Device(sys.argv[1] if len(sys.argv) > 1 else "emulator-5554") + app = Wallet(dev) + + app.fresh_start(dev_mode=True) + dev.logcat(clear=True) + + app.open_settings() + app.scroll_to_text(r"(?i)^Payment services$") + dev.tap_text(r"(?i)^Payment services$") + dev.wait_for(UNCONTACTED, timeout=30) + dev.tap_text(f"Menu: {UNCONTACTED}", timeout=30) + dev.tap_text(r"(?i)^Treat as global$", timeout=30) + time.sleep(3) + + log = dev.logcat() + screen = dev.dump() + hit = "addGlobalCurrencyExchange error" in log and "exchangeMasterPub" in log + print(f"screen after the tap: {screen.texts()}") + for line in log.splitlines(): + if "addGlobalCurrencyExchange" in line and "error" in line: + print(line.strip()[:400]) + print(f"\nreproduced: {hit}") + return 0 if hit else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/simulator/findings/repro_mailbox_private_keys_in_log.py b/simulator/findings/repro_mailbox_private_keys_in_log.py @@ -0,0 +1,61 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: mailbox private keys end up in the log. + +The periodic refresh runs every 30 seconds while developer mode is on, so this +waits a little over one period. + + cd /opt/taler-sim/driver + python3 ../findings/repro_mailbox_private_keys_in_log.py [emulator-5554] + +Exits 0 when a private key is found in logcat. +""" + +from __future__ import annotations + +import re +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +KEYS = re.compile(r"(privateKey|privateEncryptionKey)=([A-Z0-9]{20,})") + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + app.fresh_start(dev_mode=True) + dev.logcat(clear=True) + + print("waiting for the 30 s mailbox refresh ...") + found: list[tuple[str, str]] = [] + deadline = time.time() + 120 + while time.time() < deadline and not found: + time.sleep(10) + found = KEYS.findall(dev.logcat()) + + for field, value in found[:4]: + print(f" {field} = {value[:12]}… ({len(value)} chars) in logcat") + print(f"\nreproduced: {bool(found)}") + return 0 if found else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/repro_pos_confirmation_codes.py b/simulator/findings/repro_pos_confirmation_codes.py @@ -0,0 +1,81 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: the point-of-sale confirmation shows every code in the window. + +An order that names a merchant OTP device gets a `pos_confirmation` in its pay +reply, and the wallet prints it verbatim -- which is every T-OTP code in the +valid time range, newline separated, under the singular label "Confirmation +code". + + cd /opt/taler-sim/driver + python3 ../findings/repro_pos_confirmation_codes.py [emulator-5554] +""" + +from __future__ import annotations + +import re +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from device import Device # noqa: E402 +from stack import Env, Merchant # noqa: E402 +from wallet import Wallet # noqa: E402 + +DEVICE_ID = "reprotill" + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + merchant = Merchant(env.merchant) + + scenarios.fund_wallet(app, env, "EUR:10") + merchant.create_otp_device(DEVICE_ID) + order = merchant.create_order("EUR:1", summary="Reproducer till order", + otp_id=DEVICE_ID) + app.handle_uri(order["pay_uri"]) + dev.tap_text(r"(?i)^pay\b|confirm payment", timeout=60) + + deadline = time.time() + 90 + while time.time() < deadline: + if merchant.order_status(order["order_id"], + order["token"]).get("order_status") == "paid": + break + time.sleep(2) + else: + print("the order was never paid") + return 2 + + screen = dev.wait_for(r"(?i)Confirmation code|completed successfully", timeout=45) + time.sleep(2) + screen = dev.dump() + codes = [line.strip() for t in screen.texts() for line in t.splitlines() + if re.fullmatch(r"\d{6,}", line.strip())] + labelled = screen.find(r"(?i)^Confirmation code$") is not None + + print(f"screen: {screen.texts()[:12]}") + print(f"'Confirmation code' label present: {labelled}") + print(f"codes shown: {codes}") + print(f"\nreproduced: {labelled and len(codes) > 1}") + return 0 if (labelled and len(codes) > 1) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/repro_release_error_screen.py b/simulator/findings/repro_release_error_screen.py @@ -0,0 +1,91 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: a release build's error screen can explain nothing. + +With developer mode off, the whole explanation is `userFacingMsg` -- the hint +and the message concatenated -- so an error carrying neither renders as the +word "Error" and the export buttons. + + cd /opt/taler-sim/driver + python3 ../findings/repro_release_error_screen.py [emulator-5554] +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from device import PKG, Device # noqa: E402 +from stack import Env # noqa: E402 +from wallet import Wallet # noqa: E402 + +# {"code": 7001}: no hint, no message. +BARE_ERROR = ("taler+http://dev-experiment/api-error?operation=getBalances" + "&detail=eyJjb2RlIjogNzAwMX0&count=20") +CHROME = ("Error", "Copy", "Share", "Settings", "Internal event log", + "Scan QR code", "Wallet") + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + scenarios.fund_wallet(app, env, "EUR:10") + + app.handle_uri(BARE_ERROR) + time.sleep(2) + for _ in range(3): + if dev.dump().activity.startswith(PKG): + break + dev.launch() + time.sleep(6) + app.home() + time.sleep(3) + print(f"with developer mode: {dev.dump().texts()[:8]}") + + # Turn developer mode off: that is what a release build is. + app.open_settings() + app.scroll_to_text(r"(?i)^Developer mode$") + screen = dev.dump() + row = screen.find(r"(?i)^Developer mode$") + if row is None: + print("no developer mode row") + return 2 + _, y = row.center + width = max(n.bounds[2] for n in screen.nodes) + dev.tap(width - 100, y) + time.sleep(2) + if app.dev_mode_on(): + print("could not turn developer mode off") + return 2 + + app.home() + time.sleep(4) + texts = dev.dump().texts() + print(f"without developer mode: {texts[:8]}") + said_error = any(t.strip() == "Error" for t in texts) + explained = [t for t in texts + if t.strip() not in CHROME and "Export error" not in t] + print(f"anything explaining it: {explained[:6]}") + print(f"\nreproduced: {said_error and not explained}") + return 0 if (said_error and not explained) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/repro_unknown_currency_formatting.py b/simulator/findings/repro_unknown_currency_formatting.py @@ -0,0 +1,58 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: a word-shaped currency symbol is glued to the number. + + cd /opt/taler-sim/driver + python3 ../findings/repro_unknown_currency_formatting.py [emulator-5554] + +Exits 0 when an amount like "UNKNOWN0.00" is on screen. +""" + +from __future__ import annotations + +import re +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +# A currency word immediately followed by digits, with no separator. +GLUED = re.compile(r"^[A-Za-z]{3,}\d") +# Any order id that does not exist at the merchant will do. +PAY_URI = "taler+http://pay/localhost:8080/instances/sim/NOSUCHORDER12345/" + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + app.fresh_start(dev_mode=True) + app.handle_uri(PAY_URI) + time.sleep(8) + + screen = dev.dump() + texts = screen.texts() + glued = [t for t in texts if GLUED.match(t.strip())] + print(f"screen: {texts[:14]}") + print(f"amounts rendered without a separator: {glued}") + print(f"\nreproduced: {bool(glued)}") + return 0 if glued else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/repro_unknown_wire_method.py b/simulator/findings/repro_unknown_wire_method.py @@ -0,0 +1,76 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: an unknown wire method hangs the add-account form. + +The exchange advertises a `cyclos` account; `WireType` has no member for it and +the property it decodes into has no default, so the whole getDepositWireTypes +reply throws and the form sits on its spinner for ever. + +Needs the simulator's stack, whose exchange signs a Cyclos address by default +(SIM_EXTRA_PAYTOS in backend/stack.sh). + + cd /opt/taler-sim/driver + python3 ../findings/repro_unknown_wire_method.py [emulator-5554] +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from device import Device # noqa: E402 +from stack import Env # noqa: E402 +from wallet import Wallet # noqa: E402 + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + scenarios.fund_wallet(app, env, "EUR:10") + + dev.logcat(clear=True) + app.open_settings() + app.scroll_to_text(r"(?i)^Bank accounts$") + dev.tap_text(r"(?i)^Bank accounts$", timeout=20) + time.sleep(3) + dev.tap_text(r"(?i)^Add account$", timeout=20) + # Give the form far longer than it should need. + time.sleep(20) + texts = dev.dump().texts() + print(f"the add-account form after 20s: {texts}") + + log = dev.logcat(lines=600) + failures = [l for l in log.splitlines() if "getDepositWireTypes" in l + and "Error" in l] + print("the log says: " + (failures[-1][-220:] if failures else "nothing")) + + fields = dev.dump().editable() + stuck = not fields and not any( + t.strip().lower() in ("iban", "x-taler-bank", "bitcoin") for t in texts) + unknown_method = any("does not contain element with name" in l + for l in failures) + print(f"\nform is empty: {stuck}") + print(f"an unknown wire method is why: {unknown_method}") + print(f"reproduced: {stuck and unknown_method}") + return 0 if (stuck and unknown_method) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/repro_unreachable_host_zombie_purchase.py b/simulator/findings/repro_unreachable_host_zombie_purchase.py @@ -0,0 +1,80 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: a pay URI the app may never fetch leaves an empty, retrying purchase. + + cd /opt/taler-sim/driver + python3 ../findings/repro_unreachable_host_zombie_purchase.py [emulator-5554] + +Exits 0 when the purchase screen comes up empty and the request keeps being +retried. +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import oracles # noqa: E402 +from device import Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +# 127.0.0.1 is the same machine as localhost, but the app's network security +# config names only "localhost", so the platform refuses the connection. +URI = "taler+http://pay/127.0.0.1:8080/instances/sim/" + "A" * 52 + "/" + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + app.fresh_start(dev_mode=True) + dev.logcat(clear=True) + + app.handle_uri(URI) + time.sleep(10) + screen = dev.dump() + labels = screen.texts() + empty = [t for t in labels + if t.strip().lower() not in ("go back", "purchase", "internal event log")] + refusals = [ln for ln in dev.logcat(lines=800).splitlines() if "CLEARTEXT" in ln] + + print(f"screen: {labels[:10]}") + print(f"content beyond the title and back button: {empty or 'none'}") + print(f"cleartext refusals in the first 10 s: {len(refusals)}") + if refusals: + print(" " + refusals[0][-140:]) + + # Watch the retry counter climb rather than the transaction giving up. + counts = [] + for _ in range(2): + time.sleep(25) + for finding in oracles.background_failures(dev): + if finding.kind == "stuck-operation": + counts.append(finding.detail) + for line in counts: + print(f" {line}") + + blank = not empty + retrying = len(refusals) > 1 and bool(counts) + print(f"\nblank purchase screen: {blank}") + print(f"still retrying a request that can never succeed: {retrying}") + print(f"reproduced: {blank and retrying}") + return 0 if (blank and retrying) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/repro_unspecced_amounts.py b/simulator/findings/repro_unspecced_amounts.py @@ -0,0 +1,100 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: amounts rendered without their currency specification. + +Two screens show the wallet's fallback notation ("5.00 EUR") where the rest of +the app shows "€5.00": + + * the manual withdrawal's wire transfer instructions, which put both + notations in one sentence; + * the incoming peer-payment prompt, whose composable takes no currency + specification at all. + + cd /opt/taler-sim/driver + python3 ../findings/repro_unspecced_amounts.py [emulator-5554] +""" + +from __future__ import annotations + +import re +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from cli import CliWallet # noqa: E402 +from device import Device # noqa: E402 +from stack import Bank, Env # noqa: E402 +from wallet import Wallet # noqa: E402 + +# "5.00 EUR": a number followed by the currency code, which is what +# Amount.toString() produces when it has no specification to work from. +UNSPECCED = re.compile(r"\d+[.,]\d\d\s+[A-Z]{3,}") + + +def transfer_instructions(dev: Device, app: Wallet, bank: Bank) -> list[str]: + """A manual withdrawal, as far as the wire transfer instructions.""" + app.home() + dev.tap_text(r"(?i)^Withdraw$", timeout=30) + dev.wait_for(r"(?i)Amount to withdraw|Total amount", timeout=30) + screen = dev.dump() + fields = screen.editable() + if fields: + dev.tap_node(fields[0], screen) + dev.type_text("500") + time.sleep(2) + scenarios.accept_tos(app) + dev.tap_text(r"(?i)Confirm withdrawal", timeout=30) + dev.wait_for(r"(?i)Wire transfer instructions|transaction is pending", timeout=60) + dev.tap_text(r"(?i)Wire transfer instructions", timeout=30) + screen = dev.wait_for(r"(?i)Subject|Recipient|IBAN|Account", timeout=30) + time.sleep(1) + return dev.dump().texts() + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + bank = Bank(env.bank) + + scenarios.fund_wallet(app, env, "EUR:10") + instructions = transfer_instructions(dev, app, bank) + bad_transfer = [t for t in instructions if UNSPECCED.search(t)] + print(f"transfer instructions: {instructions[:6]}") + print(f"unformatted there: {bad_transfer[:2]}") + + # The peer prompt: another wallet pushes money to this one. The prompt is + # read before accepting anything, so nothing here depends on the timing of + # the accept. + peer = CliWallet() + app.home() + scenarios.fund_peer(peer, env, "EUR:5") + uri = peer.peer_send("EUR:1", env.exchange) + app.handle_uri(uri) + prompt = dev.wait_for(r"(?i)Do you want to receive this payment|Total:", + timeout=60) + bad_peer = [t for t in prompt.texts() if UNSPECCED.search(t)] + print(f"peer prompt: {prompt.texts()[:10]}") + print(f"unformatted there: {bad_peer[:3]}") + + print(f"\nreproduced: {bool(bad_transfer) or bool(bad_peer)}") + return 0 if (bad_transfer or bad_peer) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/repro_untranslated_contacts_mailbox.py b/simulator/findings/repro_untranslated_contacts_mailbox.py @@ -0,0 +1,140 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: the contacts and mailbox screens stay English in every language. + +Their labels are string literals in the Compose sources rather than entries in +strings.xml, so there is nothing for a translator to translate and nothing for +./check-translations.py to miss. + +The script's own navigation is the evidence. Reaching Settings in a German +wallet needs a bilingual pattern ("Settings|Einstellungen") because that label +*is* translated; the two entries inside it, and every label on the screens they +open, are matched in English alone -- and found. + +The app is restarted after the language is set, which is what a user does +anyway, and which avoids the unrelated defect in +`config-change-locks-the-wallet-out-of-its-database.md`. + + cd /opt/taler-sim/driver + python3 ../findings/repro_untranslated_contacts_mailbox.py [emulator-5554] + +Exits 0 when English labels are on screen in a German wallet. The per-app +language needs no root (Android 13+) and is restored on the way out. +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +# Labels with no entry in res/values/strings.xml, so no values-de/ can carry +# them, per screen, with the (English) settings entry that opens it. +SCREENS = { + "Contacts": [r"^Add Contact$", r"^Petname$", r"^Alias$", r"^Alias Type$", + r"Lookup with Taldir", r"No contacts yet", r"Search contacts"], + "Mailbox": [r"^Your Mailbox Address$", r"^Configure Mailbox URL$", + r"^Mailbox Base URL$", r"No messages yet", r"^Mailbox$"], +} +# These are translated, so the script has to know both spellings to get around. +SETTINGS = r"(?i)^(Settings|Einstellungen)$" +IN_SETTINGS = r"(?i)Developer mode|Entwicklermodus|Payment services|Bezahldienste" +# A fresh wallet shows its welcome state rather than the four action +# buttons, so the markers have to cover both. +GERMAN_HOME = [r"^Einstellungen$", r"^QR-Code scannen$", + r"Willkommen bei Taler Wallet", r"abheben", + r"^Senden$", r"^Anfordern$"] + + +HOME = r"(?i)^(Scan QR code|QR-Code scannen)$" + + +def go_home(dev: Device) -> None: + """Back out to the wallet's own home screen, in either language. + + Wallet.home() looks for the English "Scan QR code" only, so in a German + wallet it presses back until the app itself is gone. + """ + for _ in range(6): + if dev.dump().find(HOME) is not None: + return + dev.back() + time.sleep(1) + # Backed out of the app altogether; bring it up again. + dev.launch() + time.sleep(8) + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + + if dev.sdk_int < 33: + print(f"this device is API {dev.sdk_int}; a per-app language needs 33+, " + "so there is no way to switch the wallet's language from here") + return 2 + try: + dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales", check=False) + app.fresh_start(dev_mode=True) + app.home() + + dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales de-DE", + check=False) + time.sleep(3) + dev.stop() + time.sleep(2) + dev.launch() + time.sleep(12) + home = dev.dump() + german = [p for p in GERMAN_HOME if home.find(f"(?i){p}") is not None] + print(f"the wallet is in German: {[p.strip('^$') for p in german]}") + print(f" home screen: {' | '.join(home.texts()[:10])}") + if not german: + print("the language did not change; nothing to measure") + return 1 + + found: dict[str, list[str]] = {} + for entry, labels in SCREENS.items(): + dev.tap_text(SETTINGS, timeout=30) + dev.wait_for(IN_SETTINGS, timeout=30) + app.scroll_to_text(rf"(?i)^{entry}$", max_scrolls=12) + # The entry itself is matched in English, in a German wallet. + dev.tap_text(rf"(?i)^{entry}$", timeout=20) + time.sleep(3) + shown = dev.dump() + found[entry] = [l for l in labels + if shown.find(f"(?i){l}") is not None] + print(f"\n=== {entry} (reached by its English name)") + print(" " + " | ".join(shown.texts()[:14])) + print(f" {len(found[entry])} untranslatable labels: " + f"{[l.strip('^$') for l in found[entry]]}") + go_home(dev) + + total = sum(len(v) for v in found.values()) + print(f"\nreproduced: {total >= 4} ({total} English labels in a German " + f"wallet, plus the two settings entries that opened them)") + return 0 if total >= 4 else 1 + finally: + dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales", check=False) + print("restored the app's language") + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/simulator/findings/repro_wallet_lock_bypass.py b/simulator/findings/repro_wallet_lock_bypass.py @@ -0,0 +1,96 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: the wallet lock opens with no credential. + +"Protect access to wallet" can only be switched on while the device can +authenticate, but nothing re-checks afterwards: when the credential is gone, +the prompt fails with ERROR_NO_DEVICE_CREDENTIAL and the app unlocks anyway, +while still showing its lock screen. + +Touches the device's lock settings and clears them again afterwards. + + cd /opt/taler-sim/driver + python3 ../findings/repro_wallet_lock_bypass.py [emulator-5554] +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from device import Device # noqa: E402 +from stack import Env # noqa: E402 +from wallet import Wallet # noqa: E402 + +PIN = "1234" + + +def restart(dev: Device, app: Wallet) -> None: + dev.stop() + time.sleep(2) + dev.launch() + time.sleep(6) + + +def locked(dev: Device) -> bool: + """The overlay covers the app, but the nodes underneath are still dumped.""" + return dev.dump().find(r"(?i)Tap to unlock") is not None + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + try: + out = dev.shell(f"locksettings set-pin {PIN}", check=False) + if "set" not in out.lower(): + print(f"could not set a device credential: {out.strip()[:120]}") + return 2 + scenarios.fund_wallet(app, env, "EUR:10") + app.open_settings() + app.scroll_to_text(r"(?i)^Protect access to wallet$") + dev.tap_text(r"(?i)^Protect access to wallet$", timeout=20) + time.sleep(3) + + restart(dev, app) + with_credential = locked(dev) + print(f"locked with a credential: {with_credential}") + if not with_credential: + print("the switch did not take; nothing to test") + return 2 + + print(dev.shell(f"locksettings clear --old {PIN}", check=False).strip()) + restart(dev, app) + before = locked(dev) + print(f"locked after the credential was removed: {before}") + dev.tap_text(r"(?i)Tap to unlock", timeout=20) + time.sleep(5) + after = locked(dev) + texts = dev.dump().texts() + print(f"still locked after tapping unlock: {after}") + print(f"screen: {texts[:10]}") + print(f"\nreproduced: {before and not after}") + return 0 if (before and not after) else 1 + finally: + dev.shell(f"locksettings clear --old {PIN}", check=False) + dev.shell("locksettings set-disabled true", check=False) + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/repro_zero_deposit.py b/simulator/findings/repro_zero_deposit.py @@ -0,0 +1,108 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: the deposit screen does not guard the zero/below-fee case. + +Two halves: + * clearing the amount asks wallet-core to price a zero deposit, which fails + with WALLET_UNEXPECTED_EXCEPTION ("can't sum zero amounts"); + * depositing an amount at or below the deposit fee creates a transaction + whose raw amount is zero. + + cd /opt/taler-sim/driver + python3 ../findings/repro_zero_deposit.py [emulator-5554] +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from device import Device # noqa: E402 +from stack import Env # noqa: E402 +from wallet import Wallet # noqa: E402 + + +def open_deposit_amount(dev: Device, app: Wallet): + app.home() + dev.tap_text(r"(?i)^Deposit$", timeout=30) + time.sleep(3) + screen = dev.dump() + account = screen.find(r"(?i)^wallet\d+$") or screen.find(r"(?i)x-taler-bank") + if account is not None: + dev.tap_node(account, screen) + time.sleep(3) + return dev.dump() + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + scenarios.fund_wallet(app, env, "EUR:10") + + # Half one: type an amount, then clear it. + screen = open_deposit_amount(dev, app) + fields = screen.editable() + if not fields: + print(f"no amount field: {screen.texts()}") + return 2 + dev.tap_node(fields[0], screen) + dev.type_text("500") # 5.00 + time.sleep(3) + dev.logcat(clear=True) + screen = dev.dump() + reset = screen.find(r"(?i)^Reset$") + if reset is None: + print(f"no Reset button: {screen.texts()}") + return 2 + dev.tap_node(reset, screen) + time.sleep(5) + log = dev.logcat() + zero_sum = [ln for ln in log.splitlines() if "sum zero amounts" in ln] + print(f"internal errors after clearing the amount: {len(zero_sum)}") + if zero_sum: + print(" " + zero_sum[0][-200:]) + + # Half two: deposit exactly the fee. + screen = open_deposit_amount(dev, app) + fields = screen.editable() + dev.tap_node(fields[0], screen) + dev.type_text("1") # 0.01, at or below the deposit fee + time.sleep(2) + screen = dev.dump() + make = screen.find(r"(?i)^Make deposit$") + if make is None: + print(f"no Make deposit button: {screen.texts()}") + return 2 + dev.tap_node(make, screen) + time.sleep(8) + after = dev.dump() + texts = after.texts() + print(f"transaction afterwards: {texts[:10]}") + degenerate = any("0.00" in t for t in texts) and any( + t.startswith("-") or t.startswith("−") for t in texts) + + print(f"\nzero-amount pricing error: {bool(zero_sum)}") + print(f"zero-value deposit created: {degenerate}") + print(f"reproduced: {bool(zero_sum) or degenerate}") + return 0 if (zero_sum or degenerate) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/simulator/findings/reset-dialog-puts-the-wipe-where-cancel-belongs.diff b/simulator/findings/reset-dialog-puts-the-wipe-where-cancel-belongs.diff @@ -0,0 +1,41 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt b/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt +index 5d904900..fd354ce8 100644 +--- a/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt ++++ b/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt +@@ -295,10 +295,15 @@ fun SettingsScreen( + onClick = { + MaterialAlertDialogBuilder(context) + .setMessage(R.string.settings_dialog_import_message) +- .setNegativeButton(R.string.import_db) { _, _ -> ++ // The affirmative action goes in the positive slot: ++ // MaterialAlertDialogBuilder draws that one on the ++ // right, where this app's other dialogs and the ++ // platform put "continue" -- and the left-hand ++ // button is the one a user taps to back out. ++ .setPositiveButton(R.string.import_db) { _, _ -> + dbImportLauncher.launch(arrayOf("application/json")) + } +- .setPositiveButton(R.string.cancel) { _, _ -> ++ .setNegativeButton(R.string.cancel) { _, _ -> + scope.launch { snackbarHostState.showSnackbar(importCanceledMessage) } + } + .show() +@@ -358,13 +363,16 @@ fun SettingsScreen( + onClick = { + MaterialAlertDialogBuilder(context) + .setMessage(R.string.settings_dialog_reset_message) +- .setNegativeButton(R.string.reset) { _, _ -> ++ // Likewise: wiping the wallet is the affirmative ++ // action, so it belongs on the right rather than ++ // where a dismissive tap lands. ++ .setPositiveButton(R.string.reset) { _, _ -> + settingsManager.clearDb { + model.dangerouslyReset() + } + scope.launch { snackbarHostState.showSnackbar(resetDoneMessage) } + } +- .setPositiveButton(R.string.cancel) { _, _ -> ++ .setNegativeButton(R.string.cancel) { _, _ -> + scope.launch { snackbarHostState.showSnackbar(resetCanceledMessage) } + } + .show() diff --git a/simulator/findings/reset-dialog-puts-the-wipe-where-cancel-belongs.md b/simulator/findings/reset-dialog-puts-the-wipe-where-cancel-belongs.md @@ -0,0 +1,125 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# The two dialogs that can destroy a wallet put their button where Cancel belongs + +Found while writing the scenario that confirms a wallet reset — the only thing +that calls `clearDb`, and therefore the only scenario that had ever seen this +dialog's buttons. + +**Severity: moderate.** Nothing is wrong with the reset itself; the danger is +where its button is drawn. A user who dismisses dialogs by tapping the +left-hand button — the position Android has used for "Cancel" since +Holo — destroys their wallet, and the dialog's own text says what that costs: +"you will lose all coins and purchases". + +## What happens + +**Settings → Reset Wallet (dangerous!)** opens + +``` +Do you really want to reset the wallet and lose all coins and purchases? + + [ Reset ] [ Cancel ] +``` + +Measured on a 1080-wide screen, the buttons' centres are + +``` +the reset dialog's buttons, left to right: [('Reset', 642), ('Cancel', 836)] +``` + +so **Reset is the left-hand button and Cancel the right-hand one** — the +opposite of every other confirmation in the app and of the platform +convention, where the rightmost text button is the affirmative one and the +dismissive action sits to its left. + +Tapping Reset does reset: the balance goes to nothing and `clearDb` runs. + +## Why + +The two buttons are assigned the wrong way round: + +```kotlin +// wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt:358 +MaterialAlertDialogBuilder(context) + .setMessage(R.string.settings_dialog_reset_message) + .setNegativeButton(R.string.reset) { _, _ -> // destroys the wallet + settingsManager.clearDb { model.dangerouslyReset() } + … + } + .setPositiveButton(R.string.cancel) { _, _ -> // does nothing + … + } + .show() +``` + +`MaterialAlertDialogBuilder` draws the **positive** button rightmost, so +putting `cancel` there and `reset` in the negative slot swaps them on screen. + +It is not the only one. The app uses `MaterialAlertDialogBuilder` in exactly +two places that matter, and **both** are inverted the same way — the other is +the database import, which is also destructive: + +```kotlin +// wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt:295 + .setMessage(R.string.settings_dialog_import_message) // "This operation + .setNegativeButton(R.string.import_db) { _, _ -> … } // will overwrite + .setPositiveButton(R.string.cancel) { _, _ -> … } // your existing + // database" +``` + +Every *other* confirmation in the app is a Compose `AlertDialog` with +`confirmButton`/`dismissButton` — the bank-account forget dialog, the +transaction delete dialog, the contacts send dialog — and those are right by +construction, because Compose places `confirmButton` on the right. The two +builder-based dialogs are the only ones where the slot has to be chosen by +hand, and both chose wrong. + +## Reproduce by hand + +1. Install a debug build and withdraw something, so there is money to lose. +2. **Settings → Reset Wallet (dangerous!)**. +3. Look at the buttons: **Reset** is on the left, **Cancel** on the right. +4. Tap the left-hand button the way one dismisses a dialog. The wallet is + emptied — balance gone, transactions gone. + +Expected: the destructive action on the right, where this app and the platform +put affirmative actions, so that the reflexive left-hand tap is the safe one. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=0 python3 -u suite.py settings_reset_confirmed +``` + +The scenario reports the two buttons with their x coordinates, confirms +`clearDb` reached wallet-core, and checks that no coins survive. + +## Suggested fix + +Swap them, in both dialogs: + +```kotlin +.setPositiveButton(R.string.reset) { _, _ -> settingsManager.clearDb { … } } +.setNegativeButton(R.string.cancel) { _, _ -> … } +``` + +A dialog that can destroy someone's money is also worth a second gate — the +database exports warn first ("this file holds your money… Export anyway?"), +and the reset is strictly more destructive than an export. diff --git a/simulator/findings/suspended-looks-like-completed-in-the-list.diff b/simulator/findings/suspended-looks-like-completed-in-the-list.diff @@ -0,0 +1,40 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionsComposable.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionsComposable.kt +index c6a17561..90bcfc33 100644 +--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionsComposable.kt ++++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionsComposable.kt +@@ -85,8 +85,12 @@ import net.taler.wallet.transactions.TransactionMajorState.Aborted + import net.taler.wallet.transactions.TransactionMajorState.Aborting + import net.taler.wallet.transactions.TransactionMajorState.Dialog + import net.taler.wallet.transactions.TransactionMajorState.Done ++import net.taler.wallet.transactions.TransactionMajorState.Expired + import net.taler.wallet.transactions.TransactionMajorState.Failed + import net.taler.wallet.transactions.TransactionMajorState.Pending ++import net.taler.wallet.transactions.TransactionMajorState.Suspended ++import net.taler.wallet.transactions.TransactionMajorState.SuspendedAborting ++import net.taler.wallet.transactions.TransactionMajorState.SuspendedFinalizing + import net.taler.wallet.transactions.TransactionMinorState.BalanceKycRequired + import net.taler.wallet.transactions.TransactionMinorState.BankConfirmTransfer + import net.taler.wallet.transactions.TransactionMinorState.KycAuthRequired +@@ -423,6 +427,22 @@ fun TransactionExtraInfo(tx: Transaction) { + + tx.txState.major == Dialog -> {} + ++ // Suspended and its two compound forms said nothing at all here, so a ++ // suspended transaction looked exactly like a completed one in the ++ // list -- the only difference was on the detail screen. The string ++ // already exists. ++ tx.txState.major == Suspended || ++ tx.txState.major == SuspendedFinalizing || ++ tx.txState.major == SuspendedAborting -> Text( ++ stringResource(R.string.transaction_state_suspended), ++ color = MaterialTheme.colorScheme.error, ++ ) ++ ++ tx.txState.major == Expired -> Text( ++ stringResource(R.string.transaction_state_expired), ++ color = MaterialTheme.colorScheme.error, ++ ) ++ + tx is TransactionWithdrawal && !tx.confirmed -> Text(stringResource(R.string.withdraw_waiting_confirm)) + tx is TransactionPeerPushCredit && tx.info.summary != null -> Text(tx.info.summary) + tx is TransactionPeerPushDebit && tx.info.summary != null -> Text(tx.info.summary) diff --git a/simulator/findings/suspended-looks-like-completed-in-the-list.md b/simulator/findings/suspended-looks-like-completed-in-the-list.md @@ -0,0 +1,137 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# A suspended transaction is indistinguishable from a completed one in the list + +Found by the `transaction_states_rendered` scenario, which renders every +transaction state the app has a branch for by feeding the list a canned +wallet-core reply. + +**Severity: low-moderate.** Suspending is an action the app offers on nearly +every transaction, and the transaction list — the screen a user scans to see +what is going on — gives no sign that anything was suspended. For a suspended +withdrawal the row goes further and says "Waiting for confirmation", which is +the opposite of what is happening. + +## What happens + +Six withdrawals, one per state, in the transaction list: + +| state | what the row shows | +| --- | --- | +| `pending` + `kyc` | the "PENDING" chip and "KYC required to proceed" | +| `aborting` | "Aborting" | +| `failed` | "Failed" | +| `done` | nothing, which is right | +| **`suspended`** | **nothing** | +| an unknown future state | nothing | + +The detail screen does say it — "This transaction is suspended" — so the +information is there; it is the row that omits it. + +On a *real* suspension it is worse than an omission. Suspending a withdrawal +that is waiting for the bank gives this: + +``` +its detail screen: ['This transaction is suspended', 'Chosen amount', '€5.00', + 'Fee', '-€0.12', 'Total amount', '€4.88', …] +its row in the list: ['0 min. ago', 'Withdraw', 'Waiting for confirmation', '+4.88'] +``` + +The row says **"Waiting for confirmation"** — i.e. that the wallet is waiting +for the bank — when in fact the transaction is suspended and nothing is +happening until the user resumes it. That comes from the fall-through at the +end of the same `when`: + +```kotlin +tx is TransactionWithdrawal && !tx.confirmed -> Text(stringResource(R.string.withdraw_waiting_confirm)) +``` + +which a suspended, unconfirmed withdrawal reaches because no earlier branch +claimed it. + +## Why + +The row's state line has no branch for `Suspended`, and the "PENDING" chip is +only drawn for `Pending` and `Dialog`: + +```kotlin +// wallet/src/main/java/net/taler/wallet/transactions/TransactionsComposable.kt:382 +if (tx.txState.major == Pending || tx.txState.major == Dialog) { + … Text(stringResource(R.string.transaction_pending)) // the "PENDING" chip +} +… +// …:395 +when { + tx.txState.major == Aborted -> Text(…payment_aborted…) + tx.txState.minor == Repurchase -> … + tx.txState.major == Failed -> Text(…payment_failed…) + tx.txState.major == Aborting -> Text(…payment_aborting…) + tx.txState.major == Pending -> when (tx.txState.minor) { … } + tx.txState.major == Dialog -> {} + … +} +``` + +`Suspended` falls through all of it. The detail screen's own state card +(`TransactionStateComposable`) *does* handle it. + +The same `when` has no branch for a state this version of the app does not +know, and the detail screen's card ends in `else -> return` — so a future +state renders as nothing in both places, although `TransactionState` goes out +of its way to keep the unrecognised name (`majorName`, `minorName`) precisely +so that it could be shown. + +## Reproduce by hand + +No injection needed for the suspended case: + +1. Start a withdrawal and confirm it, so it waits for the bank. +2. On its detail screen tap **Suspend**. The screen says "This transaction is + suspended". +3. Go back to the main screen and look at the row under "Recent + transactions": it shows the time, "Withdraw" and the amount, exactly as a + completed withdrawal does. + +For the unknown-state case, a canned reply is needed (developer mode): + +```bash +# {"transactions":[{… "txState":{"major":"transmogrified","minor":"inside-out"} …}]} +adb shell am start -a android.intent.action.VIEW -d \ + 'taler+http://dev-experiment/api-response?operation=getTransactionsV2&response=<base64url>&count=8' +``` + +`simulator/driver/suite.py`'s `_fake_withdrawal` builds the object; the +scenario below does the encoding. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=4 python3 suite.py transaction_states_rendered # all six states +SIM_WORKER=4 python3 suite.py withdraw_suspend_resume # a real suspension +``` + +The first prints the whole list; the second reports what the suspended +transaction's own row says, which is nothing. + +## Suggested fix + +Add `tx.txState.major == Suspended -> Text(stringResource(R.string.transaction_state_suspended))` +to the row's `when`, before the `!tx.confirmed` fall-through — the string +already exists — and a final `else` that shows the unrecognised state name the +app kept, rather than nothing. diff --git a/simulator/findings/taldir-protocol-version-mismatch.md b/simulator/findings/taldir-protocol-version-mismatch.md @@ -0,0 +1,108 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# The wallet and the Taler directory disagree on the protocol version + +Found while deploying a real directory beside the simulator's stack +(`git://git.taler.net/taldir` at `3dca5c1b`, master of 2026-10-18): the wallet +refuses to talk to it at all, before any alias is registered. + +**Severity: low-moderate, and it is an integration fact rather than a bug in +either side.** Both are in development; the point is that today's heads do not +interoperate, and the failure is reported as a generic error. + +## What happens + +The directory's configuration endpoint answers: + +```json +{"version":"0:0:0","name":"taler-directory", + "alias_types":[{"name":"email","challenge_fee":"EUR:0"}],"monthly_fee":"EUR:0"} +``` + +and that version is a literal in the service: + +```go +// taldir, pkg/taldir/taldir.go:694 +cfg := VersionResponse{ + Version: "0:0:0", + Name: "taler-directory", +``` + +The wallet's client declares `1:0:0` and checks compatibility before using the +service: + +```ts +// taler-util/src/http-client/taldir.ts:53 +public static readonly PROTOCOL_VERSION = "1:0:0"; +``` + +```ts +// taler-util/src/operation.ts:166, in carefullyParseConfig +if (!LibtoolVersion.isCompatible(clientVersion, minBody.version)) { + throw TalerError.fromUncheckedDetail({ + code: TalerErrorCode.GENERIC_CLIENT_UNSUPPORTED_PROTOCOL_VERSION, + … + detail: `Unsupported protocol version, client supports ${clientVersion}, server supports ${minBody.version}`, + }); +} +``` + +`1:0:0` against `0:0:0` is incompatible in libtool terms, so `lookupAlias`, +`registerAlias` and `completeRegisterAlias` all fail at the first step. What +reaches the caller is not the version detail but +`WALLET_ALIAS_REGISTRATION_FAILED` with the hint "could not read the +configuration of the directory service" — the specific reason is thrown away +by `taldir.ts`'s own `default:` branch. + +For contrast, the mailbox service gets this right: `taler-mailbox`'s +`Makefile.in` carries `LT_VERSION="1:1:0"` and passes it in at build time, and +`1:0:0` against `1:1:0` is compatible. + +## How it was established + +Deploy the directory and ask it: + +```bash +git clone git://git.taler.net/taldir && cd taldir +GOFLAGS=-mod=vendor go build -o taldir-server ./cmd/taldir-server +./taldir-dbinit -c sim.conf && ./taldir-server -c sim.conf & +curl -s http://127.0.0.1:11001/config +``` + +Then point wallet-core at it (the app cannot be pointed anywhere, see +[`alias-registration-hardcodes-the-directory.md`](alias-registration-hardcodes-the-directory.md)): + +```bash +taler-wallet-cli --wallet-db /tmp/w.sqlite3 advanced api lookupAlias \ + '{"alias":"sim@example.com","aliasType":"email","taldirBaseUrl":"http://127.0.0.1:11001/"}' +``` + +With the service as it ships, that fails. With one character changed in +`taldir.go` (`0:0:0` → `1:0:0`) the whole flow — register, challenge, +complete, look up — works on the first attempt. + +## Suggested fix + +Whichever side is wrong about the number, two things would have helped: + +* taldir should take its protocol version from `LT_VERSION` at build time, the + way `taler-mailbox` does, rather than hard-coding it in the handler; +* `taldir.ts` should pass the configuration error through instead of replacing + it: its `default:` branch turns a precise + `GENERIC_CLIENT_UNSUPPORTED_PROTOCOL_VERSION` ("client supports 1:0:0, + server supports 0:0:0") into "could not read the configuration of the + directory service", which is what an operator would have to debug from. diff --git a/simulator/findings/unknown-wire-method-hangs-the-deposit-form.md b/simulator/findings/unknown-wire-method-hangs-the-deposit-form.md @@ -0,0 +1,166 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# An unknown wire method hangs the add-account form for ever + +Found by the `deposit_methods` scenario in round 12, the first round after the +simulator's exchange was given a `payto://cyclos/…` account: the add-account +form came up empty and stayed that way. + +**Severity: moderate.** Any exchange that advertises a wire method this version +of the app does not know breaks the deposit account form for every wallet of +that version — and `cyclos` is not hypothetical, the app has a Cyclos +*transfer* screen already. The failure mode is a spinner with no message. + +## What happens + +Settings → **Bank accounts** → **Add account** shows only the app bar: + +``` +['Go back', 'Add account', 'Internal event log'] +``` + +no fields, no tabs, no error — the form's `LoadingScreen`, for ever. The log +says why: + +``` +E taler-wallet: Error getDepositWireTypes TalerErrorInfo(code=NONE, hint=, + message=kotlinx.serialization.SerializationException: + net.taler.wallet.deposit.WireType does not contain element with name 'cyclos', + extra={}, rawCode=0) +``` + +One unrecognised method makes the whole reply undecodable, so the app has no +wire types at all, and `AddBankAccountScreen` shows `LoadingScreen` while +`depositWireTypes == null`: + +```kotlin +// wallet/src/main/java/net/taler/wallet/accounts/AddBankAccountScreen.kt:63 +LaunchedEffect(Unit) { depositWireTypes = depositManager.getDepositWireTypes() } +… +if (depositWireTypes == null || (bankAccountId != null && bankAccount == null)) { + LoadingScreen(Modifier.padding(paddingValues)) +} +``` + +and `getDepositWireTypes` returns `null` on error, logging it and nothing else +(the same shape as +[`a-failed-query-is-shown-as-an-empty-wallet.md`](a-failed-query-is-shown-as-an-empty-wallet.md), +with a spinner instead of an empty list). + +## Why the fallback does not fire + +The enum already has the member it needs: + +```kotlin +// wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt:296 +@Serializable +enum class WireType { + Unknown, + @SerialName("iban") IBAN, + @SerialName("x-taler-bank") TalerBank, + @SerialName("bitcoin") Bitcoin, +} +``` + +and `BackendManager.json` is built with `coerceInputValues = true`, which is +exactly the switch for "coerce an unrecognised value to the default". But +kotlinx only coerces to a declared *default value* (or to null for a nullable +property), and the property has neither: + +```kotlin +// …/DepositManager.kt:311 +val paymentTargetType: WireType, +``` + +So `Unknown` is unreachable, and the decode throws. + +**Two more enums have the same shape**, each with an `Unknown` member that can +never be used: + +- `WithdrawalOperationStatusFlag` — `withdraw/WithdrawManager.kt:184`, + `val status: WithdrawalOperationStatusFlag` (an unknown status from the bank + would break the withdrawal status reply); +- `ExchangeTosStatus` — `exchanges/Exchanges.kt:38`, `val tosStatus: + ExchangeTosStatus` (an unknown terms status would break the exchange list). + +`InsufficientBalanceHint` is used only through nullable properties, where +`coerceInputValues` does fire, so that one is safe. + +## Reproduce by hand + +Give any exchange a wire method the app does not know — `cyclos` will do, and +the wire fee matters because wallet-core hides a method that has none: + +```bash +taler-exchange-offline -c <conf> \ + enable-account 'payto://cyclos/cyclos.example.com/exchange?receiver-name=Test' upload +taler-exchange-offline -c <conf> \ + wire-fee now cyclos EUR:0.01 EUR:0.01 upload +``` + +Then in the wallet: + +1. Settings → **Bank accounts** → **Add account**. +2. The screen stays empty. `adb logcat | grep getDepositWireTypes` shows the + `SerializationException`. +3. The same happens on the **Deposit** flow's account form. + +The simulator can do this for you, but not by default: keeping a Cyclos +address signed blocks every deposit scenario, so it is opt-in — + +```bash +SIM_EXTRA_PAYTOS='payto://cyclos/cyclos.example.com/exchange?receiver-name=X' \ + backend/stack.sh start +``` + +(it was signed by default for one round, which is how this was found). + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/backend +SIM_EXTRA_PAYTOS='payto://cyclos/cyclos.example.com/exchange?receiver-name=X' \ + ./stack.sh start # sign a method the app does not know +cd ../driver && python3 stack.py # re-provision after the restart +python3 ../findings/repro_unknown_wire_method.py # worker 0 by default +``` + +The reproducer waits twenty seconds on the form and then reports both what is +on it and the `SerializationException` from the log. Restart the stack without +`SIM_EXTRA_PAYTOS` afterwards to get the deposit scenarios working again. + +## Suggested fix + +Give each of the three properties the default its enum was written for: + +```kotlin +val paymentTargetType: WireType = WireType.Unknown, +``` + +With `coerceInputValues = true` already set, that is enough to make an +unrecognised method decode as `Unknown` instead of throwing; the UI then needs +to skip `Unknown` entries when listing tabs (`AddAccountComposable` already +has an `else -> {}` branch for them) rather than showing nothing at all. + +Separately: `getDepositWireTypes` returning `null` for both "no answer yet" +and "the answer did not parse" is what turns the failure into an endless +spinner. An error state would make this visible even when the next unknown +method arrives. + +Worth adding `cyclos` to `WireType` as well — the app renders a Cyclos +transfer screen, so it already knows the method exists. diff --git a/simulator/findings/unreachable-host-leaves-blank-retrying-purchase.diff b/simulator/findings/unreachable-host-leaves-blank-retrying-purchase.diff @@ -0,0 +1,21 @@ +diff --git a/wallet/src/main/res/xml/network_security_config.xml b/wallet/src/main/res/xml/network_security_config.xml +index de61259a..546a817f 100644 +--- a/wallet/src/main/res/xml/network_security_config.xml ++++ b/wallet/src/main/res/xml/network_security_config.xml +@@ -1,6 +1,16 @@ + <?xml version="1.0" encoding="utf-8"?> + <network-security-config> ++ <!-- ++ 127.0.0.1 and ::1 are the same machine as "localhost", but the platform ++ matches this by name: a developer pointing the wallet at ++ http://127.0.0.1:8081/ got UnknownServiceException ("CLEARTEXT ++ communication to 127.0.0.1 not permitted by network security policy"), ++ which wallet-core retries for ever because it looks like a transient ++ network failure. ++ --> + <domain-config cleartextTrafficPermitted="true"> + <domain includeSubdomains="true">localhost</domain> ++ <domain includeSubdomains="false">127.0.0.1</domain> ++ <domain includeSubdomains="false">::1</domain> + </domain-config> + </network-security-config> diff --git a/simulator/findings/unreachable-host-leaves-blank-retrying-purchase.md b/simulator/findings/unreachable-host-leaves-blank-retrying-purchase.md @@ -0,0 +1,188 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# A prompt the app cannot prepare shows an empty screen and retries for ever + +Found by random exploration (seeds 31 and 33, from the hostile-URI corpus) and +reproduced deliberately. + +**Severity: moderate.** The original trigger was a URI the wallet cannot reach +— a stale QR code, a typo, a developer pointing the wallet at `127.0.0.1` — +and what the user gets is a screen with nothing on it and a transaction that +never stops trying. Fault injection then showed the same empty screen for +eleven unrelated failures of the exchange, including ones that look like an +attack, and that it does not recover when the failure goes away. + +## What happens + +Sharing `taler+http://pay/127.0.0.1:8080/instances/sim/AAAA…/` into the wallet: + +* the purchase screen opens with **no content at all** — the only labels are + "Purchase", "Go back" and the developer-mode log button; +* the request is refused by the platform, 32 times in the first ten seconds: + + ``` + D taler-wallet: java.net.UnknownServiceException: CLEARTEXT communication to + 127.0.0.1 not permitted by network security policy + ``` + +* wallet-core records it as a retried operation and keeps going — the retry + counter was still climbing (7 → 8 → …) a minute later, and in the + exploration runs it reached 12. + +`[::1]` behaves identically. The refusal is permanent: the app's +`res/xml/network_security_config.xml` permits cleartext for the name +`localhost` only, so no number of retries will ever make `127.0.0.1` or `::1` +work. + +## Reproduce by hand + +1. Install a debug build and enable **Developer mode** (needed for + `taler+http://`; an `https://` URI to an unreachable host shows the same + empty screen without it). +2. Run `adb logcat | grep -E "CLEARTEXT|taler-wallet"`. +3. Share the URI into the wallet: + + ```bash + adb shell am start -a android.intent.action.SEND -t text/plain \ + -n net.taler.wallet.fdroid.debug/net.taler.wallet.main.MainActivity \ + --es android.intent.extra.TEXT \ + 'taler+http://pay/127.0.0.1:8080/instances/sim/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/' + ``` + +4. The wallet opens an empty "Purchase" screen. The log fills with cleartext + refusals, and they keep coming. + +Expected: the screen says what went wrong, and a refusal the platform will +never allow is not retried. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_unreachable_host_zombie_purchase.py +``` + +## The empty prompt is not specific to this cause + +Fault injection showed the same screen for every way of spoiling the +exchange's replies. With `taler-twister` in front of the exchange, a +withdrawal whose preparation fails renders as + +``` +['Go back', 'Withdraw UNKNOWN', 'Internal event log'] +``` + +— no amount, no error, and "UNKNOWN" where the currency belongs. That held for +a truncated response, HTTP 500, 404, 403 and 502, a wrong content type, and +for structural damage (a deleted `denoms`, a deleted signature, a flipped +master public key, a rewritten version or currency). + +In that run the wallet was in fact refusing for a different reason — +`WALLET_EXCHANGE_BASE_URL_MISMATCH` (7030), logged six times — which makes the +point more sharply: the wallet detected a problem and told the user nothing. +A prompt with no error state looks the same whatever went wrong. + +A later fault-injection run put a number on "whatever went wrong". With +`taler-twister` between the wallet and the exchange, kept armed for the whole +withdrawal, **eleven different faults all produced the same screen**: + +``` +['Go back', 'Withdraw UNKNOWN', 'Internal event log'] +``` + +a truncated response, HTTP 500, 404, 403 and 502, a response with the wrong +content type, a `/keys` with its denomination list deleted, with a flipped +master public key, with a forged denomination signature, with no wire fees, and +with an impossible protocol version. The withdrawal prompt is empty in all +eleven cases, and the title reads "Withdraw UNKNOWN" — the placeholder +currency, because the wallet has no exchange configuration to take a currency +from. + +Two things make this worse than the original observation: + +* **It does not recover.** The run disarmed each fault and waited; the screen + was still `['Go back', 'Withdraw UNKNOWN', 'Internal event log']` afterwards + for every fault that damaged `/keys`. There is nothing on the screen to + retry with, so a withdrawal interrupted by a bad reply is lost even once the + exchange is healthy again. +* **The same screen means "your exchange is lying to you".** A forged + denomination signature and a flipped master public key are what an attack + looks like, and the wallet shows the same blank page it shows for a + typo. + +## Why + +Two separate things meet here. + +* **The screen renders nothing while it has nothing.** `PromptPayment` is + waiting for contract terms that will never arrive, and there is no state for + "still fetching" or "could not fetch" — so the user is left looking at an + empty page rather than a spinner or an error. +* **A policy refusal looks like a network blip.** `UnknownServiceException` + reaches wallet-core as a generic HTTP failure (code 7003), which is retried + with backoff like any transient error. It is not transient: the cleartext + policy is fixed at build time. + +## The cheapest reproduction of the empty prompt + +No proxy needed at all: one injected error does it. With developer mode on, + +```bash +adb shell am start -a android.intent.action.VIEW -d \ + 'taler+http://dev-experiment/api-error?operation=getWithdrawalDetailsForAmount&detail=eyJjb2RlIjogNzAwMSwgImhpbnQiOiAiaW5qZWN0ZWQifQ&count=4' +``` + +then tapping **Withdraw** gives +`['Go back', 'Withdraw from bank', 'Internal event log']` — the same empty +screen, from a single failed call. This is one of the screens +[`a-failed-query-is-shown-as-an-empty-wallet.md`](a-failed-query-is-shown-as-an-empty-wallet.md) +sweeps. + +## Reproduce with fault injection + +No manual reproduction for this half: it needs a proxy between the wallet and +the exchange. + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +./phase.sh sim-twister.conf twister_withdraw_faults twister_field_faults +``` + +The phase swaps in `backend/sim-twister.conf` (the exchange behind +`taler-twister` on port 8088), runs the scenarios and restores the ordinary +stack. Each scenario's notes list what every fault produced, and how many +times the fault was re-armed — a fault is one-shot, so it has to be re-armed +continuously or it lands on an unrelated poll instead of on the request under +test. + +## Suggested fix + +Give the payment and withdrawal prompts something to show while they are +loading, and an error state when the load fails — the error sheet used +elsewhere would do. The withdrawal prompt additionally needs a title that does +not say "UNKNOWN" when it has no currency yet, and a way to try again. + +For the retries, treat `UnknownServiceException` (and the cleartext refusal in +particular) as permanent in `NetworkInterface`, so the transaction fails with +an explanation instead of looping. A user-visible "this address cannot be +reached over plain HTTP" is far more useful than silence. + +Worth considering separately: `network_security_config.xml` permits cleartext +for the name `localhost` but not for `127.0.0.1` or `::1`, which are the same +machine. Adding both would save developers this exact confusion. diff --git a/simulator/findings/wallet-lock-opens-when-the-credential-is-gone.md b/simulator/findings/wallet-lock-opens-when-the-credential-is-gone.md @@ -0,0 +1,112 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# "Protect access to wallet" opens the wallet when the device credential is gone + +Found by the `wallet_lock_without_credential` scenario, written to see what a +locked wallet does when the screen lock it depends on is taken away. + +**Severity: moderate, security-relevant, release builds.** The lock screen +still appears, so the user has every reason to believe the wallet is +protected, and it opens on a single tap with no authentication of any kind. + +## What happens + +1. With a device credential set (a PIN is enough), Settings → **Protect + access to wallet** can be switched on. The app checks that the device can + authenticate before allowing this (`enableBiometrics` in + `settings/SettingsScreen.kt` requires `BIOMETRIC_SUCCESS`). +2. Restarting the app now covers it with `BiometricOverlay`: a shield and a + single **Tap to unlock** button. +3. The user later removes their screen lock — Settings → Security → screen + lock → None, which is an ordinary thing to do and needs the credential + they still have. +4. The wallet still shows the lock screen on every start. **Tapping "Tap to + unlock" opens it**, with no prompt, no credential, nothing. + +Measured, on a device whose credential was removed after the lock was +switched on: + +``` +after a restart with a credential: locked=True +cleared the device credential +after a restart with no credential: locked=True +after tapping unlock: still locked=False <- wallet open +``` + +The code says so plainly: + +```kotlin +// wallet/src/main/java/net/taler/wallet/main/MainActivity.kt:281 +override fun onAuthenticationError(errorCode: Int, errString: CharSequence) { + super.onAuthenticationError(errorCode, errString) + if (errorCode == ERROR_NO_BIOMETRICS || errorCode == ERROR_NO_DEVICE_CREDENTIAL) { + model.unlockWallet() + } + Toast.makeText(this@MainActivity, getString(R.string.biometric_auth_error, errString), LENGTH_SHORT).show() +} +``` + +Unlocking on `ERROR_NO_BIOMETRICS` / `ERROR_NO_DEVICE_CREDENTIAL` is +presumably there so that nobody is locked out of their own money — which is a +real concern, since the only other way back in is clearing the app's data, +and that destroys the coins. But as written, the protection disappears +silently: the preference stays on, the overlay keeps appearing, and anyone +holding the phone gets in. + +## Reproduce by hand + +On a device or emulator with a screen lock: + +1. Settings → **Protect access to wallet** → on. (The switch refuses if the + device has no credential; that part is correct.) +2. Close and reopen the wallet: the shield screen appears, and unlocking asks + for the PIN or fingerprint. +3. In the *system* settings, remove the screen lock (Security → Screen lock → + None). +4. Reopen the wallet. The shield screen appears as before. Tap **Tap to + unlock**: the wallet opens immediately, showing the balance, with no + authentication. + +On an emulator the same thing without touching the system UI: + +```bash +adb shell locksettings set-pin 1234 # before step 1 +adb shell locksettings clear --old 1234 # instead of step 3 +``` + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_wallet_lock_bypass.py # worker 0 +SIM_WORKER=4 SIM_DESTRUCTIVE=1 python3 suite.py wallet_lock_without_credential +``` + +The scenario sets a PIN, switches the lock on, clears the PIN, restarts the +app and reports `locked=` at each step. It clears the device credential again +whatever happens, because the setting is device-wide. + +## Suggested fix + +Do not treat "this device cannot authenticate" as "this user is +authenticated". When the overlay finds that `canAuthenticate()` no longer +returns `BIOMETRIC_SUCCESS`, say so on the overlay and offer to turn the +protection off explicitly — a deliberate act by the user, which also clears +the preference, instead of a silent unlock that leaves the switch on. The +escape hatch stays (nobody is locked out), but the user is told that the +protection is gone and the UI stops claiming otherwise. diff --git a/simulator/findings/word-currency-symbol-glued-to-amount.md b/simulator/findings/word-currency-symbol-glued-to-amount.md @@ -0,0 +1,125 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# A word-shaped currency symbol is glued to the amount: "UNKNOWN0.00" + +Found while testing QR scanning: a code pointing at an order that does not +exist leaves a failed purchase in the history whose amounts read +**`UNKNOWN0.00`**. + +**Severity: low (cosmetic), and it is not limited to the UNKNOWN placeholder.** +The same run showed a real payment prompt reading **`Total: EUR1.00`**, because +the contract's currency specification gives `alt_unit_names[0] = "EUR"` rather +than a sign. Any currency whose first alternative unit name is a word — a +regional currency called `KUDOS`, or `EUR` as served by a backend that +publishes no symbol — renders this way. + +## What happens + +A purchase whose contract could not be downloaded: + +``` +This transaction has failed or been abandoned +Total UNKNOWN0.00 +Paid UNKNOWN0.00 +``` + +And an ordinary payment prompt, against a merchant whose currency +specification carries no symbol: + +``` +Simulator Shop +Review order +QR scanned order +Total: EUR1.00 +``` + +wallet-core reports the amounts of a purchase whose contract it could not +download with its placeholder currency: + +```json +"amountRaw":"UNKNOWN:0", "amountEffective":"UNKNOWN:0", +"currencySpecification":{"name":"UNKNOWN", … ,"alt_unit_names":{"0":"UNKNOWN"}} +``` + +## Reproduce by hand + +1. Install a debug build and enable **Developer mode** in Settings. +2. Share a `taler+http://pay/…` URI for an order id that does not exist into + the wallet — scan it as a QR code, or share it as text. Against the + simulator's stack: + `taler+http://pay/localhost:8080/instances/sim/NOSUCHORDER12345/` + (Any deployment works; the point is that the merchant has no such order.) +3. The wallet opens a transaction that failed, with "Total" and "Paid" shown + as `UNKNOWN0.00`. + +Expected: a separator, as in `0.00 UNKNOWN`, which is what the same formatter +produces when there is no currency specification at all. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_unknown_currency_formatting.py +``` + +## Why + +`CurrencySpecification.symbol` is defined as the first alternative unit name +(`taler-kotlin-android/.../CurrencySpecification.kt:37`): + +```kotlin +val symbol: String? get() = altUnitNames[0] +``` + +`Amount.toString()` then hands that to a currency formatter +(`Amount.kt:272`): + +```kotlin +val format = NumberFormat.getCurrencyInstance() +s.currencySymbol = spec.symbol ?: "" +… +return if (spec.symbol != null) fmt else "$fmt $currency" +``` + +`NumberFormat.getCurrencyInstance()` places the symbol immediately before the +number in most locales, which is right for `€` or `$` and wrong for a word. +The branch that already formats as `"$fmt $currency"` is only taken when there +is no symbol at all. + +The existing unit test covers a one-character symbol (`"ク"`), so the word case +is untested. + +## Suggested fix + +Use the currency-instance layout only for a sign-shaped symbol, and fall back +to the spaced form otherwise, e.g. in `Amount.toString()`: + +```kotlin +val sign = spec.symbol?.takeIf { it.length <= 2 && !it.any(Char::isLetter) } +… +return if (sign != null) fmt else "$fmt ${spec.symbol ?: currency}".trim() +``` + +An `AmountTest` case with `symbol = "KUDOS"` would pin it. + +## Also worth deciding + +The wallet records a *failed purchase transaction* for a URI that pointed at +nothing, so a mistyped or stale QR code leaves a permanent entry in the +history. Reporting the failure without keeping a transaction may be the better +behaviour; that is a product decision rather than a defect. diff --git a/simulator/tls/README.md b/simulator/tls/README.md @@ -0,0 +1,85 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Answering for the names the app hard-codes + +Two service URLs are literals in the wallet: + +* `https://taldir.gnunet.org` — the Taler directory, in two files, with no way + to change it (`findings/alias-registration-hardcodes-the-directory.md`); +* `https://mailbox.gnunet.org` — the mailbox default, which the UI *can* + override, so this only saves typing. + +To exercise those code paths as they ship, two separate things are needed: the +device has to *resolve* the names to something local, and the app has to +*trust* what answers. Neither one changes a URL the app under test uses. + +Trust is the easy half, and it belongs in the APK: the `sim` build type — which +exists for the simulator and is never published — carries the CA as an extra +trust anchor in `wallet/src/sim/res/xml/network_security_config.xml`, alongside +the system store and with src/main's cleartext policy unchanged. The private +key stays on the host running the stack, so the committed certificate on its +own authorises nobody. + +```bash +# once, on the host +openssl req -x509 -newkey rsa:2048 -nodes -keyout ca.key -out ca.crt -days 3650 \ + -subj "/CN=Taler wallet simulator CA" \ + -addext "basicConstraints=critical,CA:TRUE" -addext "keyUsage=critical,keyCertSign,cRLSign" +openssl req -newkey rsa:2048 -nodes -keyout srv.key -out srv.csr -subj "/CN=taldir.gnunet.org" +printf 'subjectAltName=DNS:taldir.gnunet.org,DNS:mailbox.gnunet.org\nextendedKeyUsage=serverAuth\n' > srv.ext +openssl x509 -req -in srv.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out srv.crt -days 3650 -extfile srv.ext + +# regenerating the CA means rebuilding the APK that trusts it +cp ca.crt ../../wallet/src/sim/res/raw/sim_ca.crt + +GOTOOLCHAIN=local go build -o tlsproxy . # this directory +./tlsproxy & # 127.0.0.1:8443, routes by Host + +# per emulator +../emu/tls-names.sh 4 +``` + +`tls-names.sh` does the resolving half: it roots that one emulator (a root adbd +is what makes a privileged listening port possible), bind-mounts a hosts file +carrying `127.0.0.1 taldir.gnunet.org mailbox.gnunet.org` over +`/system/etc/hosts`, and forwards the device's port 443 to the host's 8443. + +It is undone by rebooting or wiping the emulator, so re-run it after one. The +scenarios that need it (`alias_registration_real`) check for the port-443 +mapping and skip with a note when it is absent, rather than measuring the +refusal. + +## Why the trust anchor is not installed on the device + +That was tried first, and it is a trap worth recording. + +* There are **two** system stores on these images — + `/apex/com.android.conscrypt/cacerts` and `/system/etc/security/cacerts`, + which is a real directory and not a symlink into the APEX — and the app reads + the second one. +* Both are read-only, so each has to be replaced by a `tmpfs` holding a copy of + the originals plus ours. A mount made from `adbd` is **invisible to app + processes**, because APEX paths live in a mount namespace of their own; it has + to be made inside init's namespace (`nsenter --mount=/proc/1/ns/mnt`). +* Zygote has already forked by then, so the framework has to be restarted + (`stop && start`) for apps to see the store at all. That leaves the network at + `PARTIAL_CONNECTIVITY` for a while, and a wallet on such a network refuses + everything with "This action requires internet connection" — which looks + exactly like a wallet bug. + +All of that for a file the build system can simply put in the APK, in a build +type that never ships. diff --git a/simulator/tls/go.mod b/simulator/tls/go.mod @@ -0,0 +1,3 @@ +module tlsproxy + +go 1.21 diff --git a/simulator/tls/tlsproxy.go b/simulator/tls/tlsproxy.go @@ -0,0 +1,67 @@ +// A TLS front end for the simulator's local services. +// +// The wallet hard-codes https://taldir.gnunet.org for the directory and +// https://mailbox.gnunet.org as the mailbox default, so the only way to +// exercise those code paths is to answer for those names: this listens with a +// certificate for both and forwards by Host header to the plain-HTTP service +// behind. The app is not modified; the device is told the names resolve here. +package main + +import ( + "crypto/tls" + "flag" + "log" + "net/http" + "net/http/httputil" + "net/url" + "strings" +) + +func proxyTo(target string) *httputil.ReverseProxy { + u, err := url.Parse(target) + if err != nil { + log.Fatalf("bad target %q: %v", target, err) + } + p := httputil.NewSingleHostReverseProxy(u) + p.Director = func(r *http.Request) { + r.URL.Scheme = u.Scheme + r.URL.Host = u.Host + r.Host = u.Host + } + return p +} + +func main() { + listen := flag.String("listen", "127.0.0.1:8443", "address to listen on") + taldir := flag.String("taldir", "http://127.0.0.1:11001", "directory service") + mailbox := flag.String("mailbox", "http://127.0.0.1:11000", "mailbox service") + cert := flag.String("cert", "srv.crt", "server certificate") + key := flag.String("key", "srv.key", "server key") + flag.Parse() + + routes := map[string]*httputil.ReverseProxy{ + "taldir.gnunet.org": proxyTo(*taldir), + "mailbox.gnunet.org": proxyTo(*mailbox), + } + mux := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + host := r.Host + if i := strings.IndexByte(host, ':'); i >= 0 { + host = host[:i] + } + p, ok := routes[host] + if !ok { + log.Printf("no route for %q (%s)", host, r.URL.Path) + http.Error(w, "no route for "+host, http.StatusNotFound) + return + } + log.Printf("%s %s%s", r.Method, host, r.URL.Path) + p.ServeHTTP(w, r) + }) + srv := &http.Server{ + Addr: *listen, + Handler: mux, + TLSConfig: &tls.Config{MinVersion: tls.VersionTLS12}, + } + log.Printf("TLS front end on %s: taldir=%s mailbox=%s", *listen, *taldir, *mailbox) + log.Fatal(srv.ListenAndServeTLS(*cert, *key)) +} diff --git a/wallet-simulator/.gitignore b/wallet-simulator/.gitignore @@ -0,0 +1,2 @@ +# Generated by the simulator: coverage reports, episode artifacts, pulled logs. +out/ diff --git a/wallet-simulator/README.md b/wallet-simulator/README.md @@ -0,0 +1,401 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Wallet simulator + +Drives the Android wallet in an emulator against a local GNU Taler stack, to +measure how much of the app gets exercised and to find sequences that end in an +internal-core-error screen, a stuck transaction or a crash. + +## Where it runs + +Everything runs on `tripwire.taler.net` (256 cores, 251 GB RAM, KVM): the Taler +services, the emulators and the driver all live there, so the observe-act loop +never crosses the network. Only the APK is built elsewhere and copied in. + +``` +tripwire:/opt/taler-sim/ + backend/ sim.conf, stack.sh the Taler services + emu/ emu.sh AVD lifecycle, one AVD per worker + driver/ device.py stack.py emulator control, counterparty HTTP clients + apk/ wallet.apk pushed from a build host + run/ stack/env.json, logs, emulator logs +``` + +The checkout under `simulator/` in taler-android is the source of truth; push it +with + +```bash +rsync -a simulator/ root@tripwire.taler.net:/opt/taler-sim/ +``` + +## Running it + +Bring the stack and one emulator up, then check that the basics work: + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim + +backend/stack.sh start # wipes the DB, starts the services, ~15 s +emu/emu.sh create 0 # once per worker +emu/emu.sh boot 0 # ~50 s +emu/emu.sh prepare 0 # install the APK, kill animations, adb reverse +cd driver +python3 stack.py # merchant instance, bank accounts, top-ups +python3 smoke_withdraw.py # end-to-end withdrawal through the UI +python3 smoke_pay.py # order, pay, refund +``` + +Then drive it in earnest. One scenario, or a few, on one worker: + +```bash +python3 suite.py --list +SIM_WORKER=0 python3 suite.py history exchange_add_remove +``` + +Everything, across four emulators, with the findings merged: + +```bash +python3 campaign.py suite --workers 4 --tag try1 +python3 campaign.py explore --workers 4 --steps 150 --seed 42 +``` + +Unattended, round after round (provision, a random walk with a fresh seed, +then every scenario, dumping coverage after each phase): + +```bash +nohup setsid ./forever.sh 1 > /opt/taler-sim/run/forever.log 2>&1 & +tail -f /opt/taler-sim/run/rounds.log +touch /opt/taler-sim/run/STOP # stops after the round in flight +``` + +A set of scenarios that needs a different stack — KYC, or fault injection — +goes through `phase.sh`, which pauses the rounds, swaps the stack, runs them, +restores the default stack and resumes: + +```bash +./phase.sh sim-kyc.conf kyc_withdraw_trips_rule kyc_transaction_actions +./phase.sh sim-twister.conf twister_withdraw_faults twister_field_faults +SIM_DESTRUCTIVE=1 ./phase.sh sim.conf revoke_denomination +``` + +The environment reaches the scenarios, so a phase is also how a destructive +scenario gets a stack of its own to ruin. + +Reading the results: + +```bash +python3 report.py '*history*' --notes # episodes and their findings +python3 ../coverage/operations.py # wallet-core operations exercised +``` + +Coverage reports are built where the APK was built, because they need the +uninstrumented classes and the sources: + +```bash +rsync -a root@tripwire.taler.net:/opt/taler-sim/run/coverage/ /tmp/ec/ +JAVA_HOME=/home/claude/jdk-17 simulator/coverage/report.sh /tmp/ec +python3 simulator/coverage/gaps.py simulator/out/coverage/coverage.xml +``` + +`gaps.py` ranks what is still untouched. Four composables in that ranking have +no caller at all -- `PromptAddContactScreen`, `GridMenu`, `DemandAttention` and +`SelectExchangeDialogFragment`, about 190 lines -- so no scenario can ever +reach them. + +## The app under test + +The simulator drives the **`sim` build type** of the wallet +(`./gradlew :wallet:assembleFdroidSim`), which is `debug` plus two things: + +* `enableAndroidTestCoverage`, so the APK carries the JaCoCo agent and + `driver/coverage.py` can ask it for execution data mid-session; +* `wallet/src/sim/`, a receiver (`SimHooks`) for the two things adb cannot do — + dumping that coverage, and delivering an NDEF message the way a tapped NFC + tag would (the extra is a Parcelable, so `am start` cannot carry it). + +It keeps the `.debug` application id, so the package driven is the same +`net.taler.wallet.fdroid.debug` a developer would install, and it is never +published. + +One side effect worth knowing: `testBuildType "sim"` is what makes AGP create +an androidTest variant for this build type (and therefore instrument the app's +classes at all), and it also moves which unit-test task `:wallet:check` +resolves to — `testFdroidSimUnitTest` rather than `testFdroidDebugUnitTest`. +`sim` is `initWith debug`, so the same tests run against the same code, and CI +asks for `:wallet:check` rather than a task name. + +### Developer mode is mandatory + +`HandleUriScreen` only accepts `taler+http://` URIs when developer mode is on, +and `MainActivity` pushes the *persisted* flag into `MainViewModel` at every +start — so a debug build does **not** come up in developer mode, whatever +`BuildConfig.DEBUG` says. `Wallet.fresh_start()` therefore switches it on +through Settings before anything else; without that step every URI from a local +http stack comes back as "Unsupported URI". + +### A stack restart invalidates the wallet + +`stack.sh start` drops the database, so the exchange comes back with a new +master key and any coins already in the wallet are worthless. Always pair a +stack restart with a wallet wipe (`fresh_start()`, i.e. `pm clear`). + +## URL topology + +Every service is configured with a `http://localhost:<port>/` base URL, and the +driver maps those same ports into each emulator with `adb reverse`. One URL +namespace is therefore valid both on the host and inside the wallet, which +matters because the merchant and the bank hand out absolute URLs that both sides +have to be able to resolve. + +| Service | Port | +| --- | --- | +| donau | 8079 | +| merchant | 8080 | +| exchange | 8081 | +| libeufin-bank | 8082 | +| auditor | 8083 | + +Plain HTTP needs no patched app: `usesCleartextTraffic` is already set in the +wallet manifest, and wallet-core 1.6.42 (the version in the shipped +`net.taler:qtart` AAR) has retired its `allowHttp` flag — it logs +"allowHttp flag not supported anymore" and never requires TLS. A debug build +also starts in dev mode on its own, because `MainViewModel` seeds dev mode from +`BuildConfig.DEBUG`. + +## Config variants + +`backend/sim.conf` is the default stack. `SIM_CONF` selects a variant: + +| Variant | What it adds | +| --- | --- | +| `sim.conf` | exchange, merchant, libeufin bank, donau; two exchange accounts (x-taler-bank and IBAN) with a wire fee each, a signed Bitcoin address, terms of service, and age-restricted denominations | +| `sim-kyc.conf` | KYC on, with a rule that trips when more than EUR:5 is withdrawn in a day | +| `sim-twister.conf` | `taler-twister` in front of the exchange on port 8088, for fault injection | + +```bash +SIM_CONF=sim-twister.conf backend/stack.sh start +``` + +**Only one stack at a time.** The exchange's secmod helpers use a runtime +directory derived from the user, not from the config, so a second stack +started alongside the first takes its sockets away and both fail with +"Could not connect to taler-exchange-helper-secmod-cs". Stop one before +starting another, or give the second its own `TALER_RUNTIME_DIR`. + +### The second exchange + +`backend/exchange2.sh` runs a second, independent exchange on port 8091 from +`backend/sim-exchange2.conf`: its own database, offline key (so its own master +key), `TALER_RUNTIME_DIR` for the secmod sockets, and account at the stack's +libeufin bank. `stack.sh start` starts it as well unless `SIM_EXCHANGE2=0`, +and stops it first on the way down -- it has an account at a bank whose +database the stack wipes, so it cannot outlive a stack start. + +With only one payment service every "which one?" step picks the only +candidate: the exchange picker, "treat as global" and the balance scopes a +second service creates are unreachable without this. + +### Three things the default config gets wrong for a wallet + +Each cost this campaign a round or two to notice, and each is a one-line +config fix: + +* **A wire method the app does not know breaks the whole reply.** The + exchange's wire methods reach the app as an enum, and one unrecognised name + makes `getDepositWireTypes` throw rather than skipping it, which hangs the + add-account form (`findings/unknown-wire-method-hangs-the-deposit-form.md`). + `SIM_EXTRA_PAYTOS` therefore signs a Bitcoin address only; a Cyclos one is + opt-in, because keeping it would block every deposit scenario. +* **A wire method with no fee does not exist** as far as the wallet is + concerned. `taler-unified-setup.sh` signs a wire fee only for the method it + is told about with `-d`, and wallet-core hides every account whose method + has none, so a second enabled account stays invisible. `stack.sh` uploads a + fee for each extra account's method. +* **The shipped `TERMS_DIR` is empty.** It is `${TALER_DATA_HOME}terms/`, + which in a test home has nothing in it, so `/terms` answers "501 not + configured" and the wallet never asks anyone to accept anything. The + exchange serves *rendered* terms (one subdirectory per language), not the + `.rst` sources it ships, so `stack.sh` runs `taler-terms-generator` once + into `$SIM_ROOT/terms`. +* **Age restriction needs `AGE_RESTRICTION_ENABLED`** in `[exchange]` on top + of the age-restricted denominations, or `/keys` advertises an age mask of 0 + and the age picker never appears. + +## The three ways it drives the app + +**Scenarios** (`driver/suite.py`, 87 of them) walk one feature each, +deliberately: the transaction list and its per-transaction actions, suspend / +resume / abort / abandon, exchange management and terms of service, every +settings row, deposits in all three account formats, peer payments in both +directions, order templates, v1 contract choices and token issuance, the scan +screen's manual entry, and a batch of adversarial sequences (process death +mid-flow, airplane mode mid-withdrawal, two pay URIs at once, force-purging an +exchange that still holds coins). + +```bash +python3 suite.py --list +python3 suite.py history exchange_add_remove # a few +python3 campaign.py suite --workers 4 --tag iter5 # all of them, 4 emulators +``` + +A scenario that cannot reach its feature fails loudly (`Ctx.require`) instead +of reporting a green row for having done nothing. + +**Exploration** (`driver/explore.py`) takes over where scenarios end: it starts +from a funded, already-paid wallet and walks at random, biased towards screens +it has not seen, mixing in URIs from the corpus and environment faults. + +**QR codes through the camera** (`driver/qrsuite.py`) render a payload with +`qrencode`, hang it on the wall of the emulator's virtual scene and read it +with the camera, so the scan screen and `QrCameraAnalyzer` run for real. The +poster can only be set at launch, so there is one emulator boot per payload. + +## How the wallet is driven + +`device.py` works through the accessibility tree. The wallet is ~90 Compose +files with no `testTag`s anywhere, so widgets are addressed by the semantics the +app already publishes — `text` and `content-desc` — and tapped at the centre of +their bounds. A screen's "signature" (its set of labels, with numbers masked, +plus the count of interactive nodes) identifies a state well enough to detect +novelty during random exploration. + +Taler URIs reach the wallet as `ACTION_SEND` / `text/plain` rather than as a +`VIEW` deep link: the manifest's VIEW filter covers `taler://` and `payto://` +but not the `taler+http://` form a local http deployment produces. `view_uri()` +is kept for the schemes the filter does cover. + +### Destructive scenarios + +`revoke_denomination` takes a denomination key away from the exchange while the +wallet holds coins of it. That is stack-wide and lasts until the next stack +start, so it refuses to run unless `SIM_DESTRUCTIVE=1`, and it belongs in a +phase of its own. + +`wallet_lock_without_credential` is destructive to the *device* rather than the +stack: it sets a PIN with `locksettings` so that the wallet lock can be +switched on, and clears it again in a `finally`. If that scenario is ever +killed outright, clear it by hand before the emulator sees a keyguard: + +```bash +adb -s emulator-5562 shell locksettings clear --old 1234 +adb -s emulator-5562 shell locksettings set-disabled true +``` + + +```bash +SIM_DESTRUCTIVE=1 driver/phase.sh sim.conf revoke_denomination +``` + +### Failing a wallet-core call from the outside + +wallet-core takes two developer-mode URIs that are worth more than any proxy +for testing the app's own error handling: + +``` +taler+http://dev-experiment/api-error?operation=<op>&detail=<base64url JSON>&count=<n> +taler+http://dev-experiment/api-response?operation=<op>&response=<base64url JSON>&count=<n> +``` + +The first fails the named operation `n` times with the given error (the detail +must be an object with a numeric `code`); the second answers it with a canned +reply. `api_error_sweep` uses the first to make each screen's own call fail and +records which screens then say nothing; `api_response_hostile` uses the second +to feed the balance screen values this stack cannot produce. Both clear up +after themselves (`clear-api-errors`, `clear-api-responses`), and a fresh +profile resets the state anyway. + +Two things to know: the operation name must be one wallet-core knows (the app's +own list is in `coverage/app-operations.txt`), and applying an experiment ends +with a back navigation, which *closes the app* when the URI is what started +it — so a scenario has to put the app back in the foreground before it can +look at anything. + +## What counts as a finding + +`driver/oracles.py` is the contract. A refusal is not a bug — the wallet is +supposed to reject a stale order or a malformed URI and say so. A finding is a +crash, an ANR, a native abort, an error wallet-core itself calls unexpected or +an invariant failure (`TalerErrorCode` 2, 56, 60, 7001, 7007, 7047, 7048), an +error screen whose text reads like a defect, a blank screen, or a corrupt +database. Each one is written to the episode directory with a screenshot, the +logcat tail, the screen's labels and the full action list that produced it, and +fingerprinted so repeats collapse. + +## Tools + +| Tool | What it is for | +| --- | --- | +| `driver/probe.py` | one action, then a dump — how labels get discovered | +| `driver/report.py` | summarise episode directories and their findings | +| `driver/dbprobe.py` | copy the wallet's SQLite database off the device and query it | +| `driver/replay.py` | replay an episode, and shrink it with ddmin | +| `coverage/report.sh` | merge `.ec` files into an HTML/XML report | +| `coverage/gaps.py` | rank what is still uncovered, and diff two reports | +| `findings/new_finding.py` | scaffold a write-up from an episode's artifacts | + +## Findings + +`findings/` holds a write-up plus a standalone reproducer per confirmed defect. +So far: + +* `addglobalcurrencyexchange-null-masterpub.md` — "Treat as global" on an + exchange the wallet has never contacted sends a request with no + `exchangeMasterPub`, so wallet-core answers `WALLET_UNEXPECTED_EXCEPTION` + (7001) and the UI shows nothing at all. Four taps from a fresh profile. + +## Gotchas the harness learned the hard way + +* **Rotation outlives app data.** `user_rotation` is a system setting, so + `pm clear` does not undo a `rotate` action from an earlier episode, and a + landscape device invalidates every gesture computed for portrait. + `Device.portrait()` runs at the start of each episode, and `Device.scroll()` + derives its swipe from the scrollable node's own bounds rather than from + fixed coordinates. +* **`input text` cannot type non-ASCII.** It maps characters through a + KeyCharacterMap and throws `NullPointerException`. Non-ASCII text goes + through `SimHooks.SET_CLIPBOARD` plus `KEYCODE_PASTE` instead; the clipboard + may only be written by the foreground app, which is where the simulator is + pasting anyway. +* **Settings is longer than one screen**, and how much fits depends on how many + rows the wallet has to show, so callers wait for the screen and then scroll + to the row they want. +* **`uiautomator dump` fails while the UI is settling** ("could not get idle + state"); `Device.dump()` retries. +* **A label is often not the thing you can tap.** The main screen's action + buttons keep their text in a sibling node, so `Screen.tap_target()` resolves + a label to the clickable node that contains it *or sits next to it*. +* **A screen's title and its submit button often share a string.** "Add + account" is the app bar title, the list screen's add icon and the form's + submit button; a label search finds the title, which is not clickable, and + the neighbour search then lands on a tab or the back arrow. `Ctx.tap_button` + takes the lowest matching node that is clickable *and* contains the label. +* **An ad-hoc probe must name its serial.** `Device()` defaults to + `emulator-5554`, which is worker 0 -- a probe written without a serial + interferes with a running round. Worker 4 (`emulator-5562`) is the spare: + `SIM_WORKER=4`, or `Device("emulator-5562")`. +* **Reachable from the host is not reachable from the emulator.** Everything + goes through `adb reverse`, and a port that is not in `env.json`'s `ports` + is not mapped; the wallet then fails to add a payment service and says + nothing about it, which looks exactly like a scenario that worked. +* **`pgrep -f X` matches the shell whose command line contains X**, so a "wait + until the run finishes" loop waits forever on itself — and a bracket class + (`[f]orever.sh`) only helps when the *pattern* is bracketed and the waiting + command does not also mention the plain name later on its own command line. + Prefer matching on something the waiter cannot contain, or check a pid file. + The same trap kills an ssh session when `pkill -f` matches the ssh command + itself. diff --git a/wallet-simulator/backend/exchange2.sh b/wallet-simulator/backend/exchange2.sh @@ -0,0 +1,147 @@ +#!/bin/bash +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# A second exchange beside the stack, so the wallet has something to choose +# between. +# +# Usage: exchange2.sh start|stop|status +# +# The main stack has to be up already: this one has no bank of its own, it +# registers an account at the stack's libeufin bank and uses it. Everything +# else (port, database, offline key, secmod sockets) is its own; see +# sim-exchange2.conf. + +set -eu + +SIM_ROOT=${SIM_ROOT:-/opt/taler-sim} +RUN=${SIM_RUN:-$SIM_ROOT/run/stack} +RUN2=${SIM_RUN2:-$SIM_ROOT/run/exchange2} +HERE="$(cd "$(dirname "$0")" && pwd)" +CONF_NAME=sim-exchange2.conf +DB=${SIM_DB2:-talersim2} +ACCOUNT=exchange-account-sim2 +CURRENCY=${SIM_CURRENCY:-EUR} +PORT=8091 +BANK_PORT=8082 +BANK_ADMIN=${SIM_BANK_ADMIN:-admin} +BANK_ADMIN_PASS=${SIM_BANK_ADMIN_PASS:-secret-password} +READY_TIMEOUT=${SIM_READY_TIMEOUT:-300} +PIDFILE="$RUN2/exchange2.pid" + +die() { echo "exchange2.sh: $*" >&2; exit 1; } + +running_pid() { + [ -s "$PIDFILE" ] || return 1 + local pid + pid=$(cat "$PIDFILE") + kill -0 "$pid" 2>/dev/null || return 1 + echo "$pid" +} + +register_bank_account() { + # is_taler_exchange makes libeufin expose the wire gateway API on it, which + # is what wirewatch and the aggregator talk to. A second call comes back + # 409, which is fine. + local code + code=$(curl -s -o register-account.log -w '%{http_code}' \ + -u "$BANK_ADMIN:$BANK_ADMIN_PASS" \ + -H 'Content-Type: application/json' \ + -X POST "http://localhost:$BANK_PORT/accounts" \ + -d '{"username":"exchange2","password":"password2", + "name":"Second Exchange","is_taler_exchange":true, + "payto_uri":"payto://x-taler-bank/localhost/exchange2?receiver-name=Second+Exchange"}') + case "$code" in + 200|201|204|409) echo "bank account exchange2: HTTP $code" >&2 ;; + *) die "could not register the exchange2 bank account (HTTP $code): $(cat register-account.log)" ;; + esac +} + +start() { + if running_pid > /dev/null; then + echo "already running (pid $(running_pid))" >&2 + return 0 + fi + curl -s -m 5 -o /dev/null "http://localhost:$BANK_PORT/config" || + die "the stack's bank is not up; start the stack first" + rm -rf "$RUN2" + mkdir -p "$RUN2/home" + dropdb "$DB" 2>/dev/null || true + createdb "$DB" || die "could not create the database $DB" + cp "$HERE/$CONF_NAME" "$RUN2/$CONF_NAME" + cd "$RUN2" + register_bank_account + # Exchange, wirewatch, aggregator, transfer: enough to withdraw from it and + # to deposit into it, which is all the wallet needs from a second one. + setsid taler-unified-setup.sh -W -c "$CONF_NAME" -u "$ACCOUNT" -e -w -g -t \ + > setup.stdout 2> setup.stderr < /dev/null & + echo $! > "$PIDFILE" + local pid waited + pid=$(cat "$PIDFILE") + waited=0 + while [ "$waited" -lt "$READY_TIMEOUT" ]; do + if grep -q '^READY:' setup.stdout 2>/dev/null; then + echo "exchange2 up after ${waited}s on port $PORT" >&2 + echo "READY" + return 0 + fi + if ! kill -0 "$pid" 2>/dev/null; then + echo "--- setup.stderr (tail) ---" >&2 + tail -40 setup.stderr >&2 || true + die "taler-unified-setup.sh died before exchange2 became ready" + fi + sleep 1 + waited=$((waited + 1)) + done + echo "--- setup.stderr (tail) ---" >&2 + tail -40 setup.stderr >&2 || true + die "timed out after ${READY_TIMEOUT}s waiting for exchange2" +} + +stop() { + if pid=$(running_pid); then + kill -TERM "$pid" + local waited=0 + while kill -0 "$pid" 2>/dev/null && [ "$waited" -lt 60 ]; do + sleep 1 + waited=$((waited + 1)) + done + kill -KILL "$pid" 2>/dev/null || true + echo "stopped" >&2 + else + echo "not running" >&2 + fi + rm -f "$PIDFILE" +} + +status() { + if pid=$(running_pid); then + echo "running (pid $pid)" + else + echo "not running" + fi + printf ' port %s: ' "$PORT" + if curl -s -m 2 -o /dev/null "http://localhost:$PORT/config"; then + echo "ok" + else + echo "DOWN" + fi +} + +case "${1:-}" in + start) start ;; + stop) stop ;; + status) status ;; + *) die "usage: $0 start|stop|status" ;; +esac diff --git a/wallet-simulator/backend/services/README.md b/wallet-simulator/backend/services/README.md @@ -0,0 +1,97 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Services beside the stack + +`taler-unified-setup.sh` brings up the exchange, the merchant, the bank, donau +and the auditor. Two more services the wallet can use are not part of it, and +the wallet has screens for both: + +| service | repository | port | what it unlocks in the app | +| --- | --- | --- | --- | +| Taler mailbox | `git://git.taler.net/taler-mailbox` | 11000 | the Mailbox screen: register, list, refresh, delete | +| Taler directory | `git://git.taler.net/taldir` | 11001 | nothing, see below — but it makes the contacts operations testable through wallet-core | + +Both are Go services with vendored dependencies, so they build without network +access to a module proxy — but they need **Go 1.25**, which Debian does not +have yet; `GOTOOLCHAIN=auto` (the default) downloads it: + +```bash +git clone git://git.taler.net/taler-mailbox && cd taler-mailbox +GOFLAGS=-mod=vendor go build -ldflags "-X main.ltversion=1:1:0" -o /tmp/ ./cmd/... +``` + +The `ltversion` ldflag matters: without it the service advertises an empty +protocol version and the wallet refuses it (`carefullyParseConfig`). + +## Deploying them + +The simulator runs them on the emulator host, beside the stack: + +``` +/opt/taler-mailbox/{mailbox-server,mailbox-dbinit,sim.conf} +/opt/taldir/{taldir-server,taldir-dbinit,sim.conf,sim-validator.sh} +``` + +`services/mailbox-sim.conf` and `services/taldir-sim.conf` here are the +deployed configurations. Databases are Postgres, created once: + +```bash +createdb -h /var/run/postgresql talermailbox +createdb -h /var/run/postgresql talerdir +cd /opt/taler-mailbox && ./mailbox-dbinit -c sim.conf +cd /opt/taldir && ./taldir-dbinit -c sim.conf +cd /opt/taler-mailbox && ./mailbox-server -c sim.conf -L DEBUG > /tmp/mb.log 2>&1 & +cd /opt/taldir && ./taldir-server -c sim.conf -L DEBUG > server.log 2>&1 & +``` + +They keep their own databases, so unlike `exchange2` they survive a stack +restart and need starting only once. Their ports are in `stack.sh`'s port list, +so `emu.sh reverse` maps them into every emulator. + +## Things that cost an hour each + +* **`localhost` is not `127.0.0.1`.** Both services bind `127.0.0.1` only, and + wallet-core resolves `localhost` to `::1` first, so a `localhost` URL gets + ECONNREFUSED. Use the numeric address in anything handed to wallet-core. +* **Every `GetDuration`/`GetAmount` in the mailbox server errors out when its + key is missing**, default or no default, so `sim.conf` spells out every fee + and every duration. +* **`taldir-dbinit` reads `[taldir-pq]` while `taldir-server` reads + `[directory-pq]`.** The config carries both, saying the same thing. +* **The directory's protocol version is a literal `0:0:0`** in + `pkg/taldir/taldir.go`, which the wallet refuses; the deployment patches it + to `1:0:0`. See `findings/taldir-protocol-version-mismatch.md`. +* **The email validator is a command.** `[directory-validator-email] COMMAND` + is run as `COMMAND <alias> <challenge> <topic> <message>`, so + `sim-validator.sh` appends the alias and the challenge to + `/opt/taldir/challenges.log` — the simulator's stand-in for reading a + validation email, and the only way a scenario can complete a registration. + +## Why the directory unlocks nothing in the app + +The app hard-codes `https://taldir.gnunet.org` in two files, so no deployment +can be reached from it; the service is still worth having, because wallet-core +takes the base URL as a parameter and the three contact operations can be +driven through `taler-wallet-cli advanced api`. See +`findings/alias-registration-hardcodes-the-directory.md`. + +## Sync + +`git://git.taler.net/sync` is *not* deployed: the Android wallet has no backup +or sync feature at all — no screens, and none of the wallet-core backup +operations appear in `coverage/app-operations.txt`. Deploying it would add +nothing to drive. diff --git a/wallet-simulator/backend/services/mailbox-sim.conf b/wallet-simulator/backend/services/mailbox-sim.conf @@ -0,0 +1,34 @@ +# Taler mailbox for the Android wallet simulator. +# +# Plain HTTP on localhost: the wallet's mailbox URL is editable in its own UI +# ("Configure Mailbox URL"), so this needs no TLS and no DNS games -- unlike +# the directory, whose URL the app hard-codes. +# +# cd /opt/taler-mailbox && ./mailbox-server -c sim.conf -L DEBUG +[mailbox] +production = false +host = "http://localhost:11000" +base_url = "http://localhost:11000" +bind_to = "localhost:11000" +monthly_fee = EUR:0 +registration_update_fee = EUR:0 +message_fee = EUR:0 +free_message_quota = 1000 +message_body_bytes = 4096 +message_response_limit = 50 +# Every GetDuration/GetAmount in the server errors out when its key is absent, +# default or no default, so each one has to be spelled out. +pending_registration_expiration = 24h +delivery_period = 72h +default_doc_filetype = text/html +default_doc_lang = en +default_tos_path = terms/ +default_pp_path = privacy/ +supported_doc_filetypes = text/html application/pdf application/epub application/xml text/plain + +[mailbox-pq] +connection_string = "postgres:///talermailbox?host=/var/run/postgresql&sslmode=disable" +host = "localhost" +port = 5432 +user = "root" +db_name = "talermailbox" diff --git a/wallet-simulator/backend/services/taldir-sim.conf b/wallet-simulator/backend/services/taldir-sim.conf @@ -0,0 +1,49 @@ +# Taler directory for the Android wallet simulator. +[paths] +TALER_DATA_HOME = /opt/taldir/data/ + +[directory] +BASE_URL = https://taldir.gnunet.org/ +BIND_TO = localhost:11001 +FOOTER = /opt/taldir/web/templates/footer.html +CHALLENGE_BYTES = 16 +VALIDATION_INITIATION_MAX = 10 +SOLUTION_ATTEMPT_MAX = 10 +VALIDATION_TIMEFRAME = 60m +SOLUTION_ATTEMPT_TIMEFRAME = 24h +MONTHLY_FEE = EUR:0 +PURGE_MAPPINGS_ON_STARTUP_DANGEROUS = false +VALIDATION_EXPIRATION = 24h +VALIDATION_LANDING = /opt/taldir/web/templates/validation_landing.html +LANDING_PAGE = /opt/taldir/web/templates/landing.html +LOOKUP_RESULT_PAGE = /opt/taldir/web/templates/lookup_result.html +SALT = simulator +DEFAULT_DOC_FILETYPE = text/html +DEFAULT_DOC_LANG = en +DEFAULT_TOS_PATH = /opt/taldir/terms/ +DEFAULT_PP_PATH = /opt/taldir/privacy/ +SUPPORTED_DOC_FILETYPES = text/html application/pdf application/epub application/xml text/plain +MERCHANT_BASE_URL = http://localhost:8080/instances/sim +MERCHANT_TOKEN = sandbox +VALID_PAYMENT_SYSTEM_ADDRESS_REGEX = .* + +[directory-pq] +CONNECTION_STRING = postgres:///talerdir?host=/var/run/postgresql&sslmode=disable + +# taldir-dbinit reads this section; the server reads [directory-pq]. Both have +# to say the same thing. +[taldir-pq] +connection_string = postgres:///talerdir?host=/var/run/postgresql&sslmode=disable + +[directory-validator-email] +TYPE = command +ENABLED = true +COMMAND = /opt/taldir/sim-validator.sh +VALID_ALIAS_REGEX = ^\S+@\S+\.\S+$ +CHALLENGE_FEE = EUR:0 + +[directory-validator-phone] +TYPE = command +ENABLED = true +COMMAND = /opt/taldir/sim-validator.sh +CHALLENGE_FEE = EUR:0 diff --git a/wallet-simulator/backend/services/taldir-validator.sh b/wallet-simulator/backend/services/taldir-validator.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# The simulator's stand-in for sending a validation email: it records the +# challenge where the driver can read it, which is all the wallet needs to +# complete a registration. +printf '%s\t%s\t%s\n' "$(date -Is)" "$1" "$2" >> /opt/taldir/challenges.log +exit 0 diff --git a/wallet-simulator/backend/sim-exchange2.conf b/wallet-simulator/backend/sim-exchange2.conf @@ -0,0 +1,197 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# A second exchange, beside the one in sim.conf, in the same currency and at +# the same libeufin bank. +# +# One exchange leaves a whole class of screens unreachable: the exchange picker +# (`SelectExchangeDialogFragment`), the balance scopes that a second payment +# service creates, "treat as global", and every "which payment service?" step +# in withdraw, deposit and peer payments silently picks the only candidate. +# +# It is started by exchange2.sh as a separate taler-unified-setup.sh run +# (services: exchange, wirewatch, aggregator, transfer), so everything here is +# deliberately disjoint from sim.conf: its own port, database, bank account, +# runtime directory for the secmod sockets and TALER_TEST_HOME -- which is +# where its offline key lives, and therefore where its master key comes from. + +[PATHS] +TALER_TEST_HOME = home/ +# The secmod helpers listen on unix sockets under this directory; sharing it +# with the first exchange makes the two fight over the same socket names. +TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/taler-sim/exchange2-runtime/ + +[taler-helper-crypto-rsa] +LOOKAHEAD_SIGN = 10 days + +[taler-helper-crypto-cs] +LOOKAHEAD_SIGN = 10 days + +[taler-helper-crypto-eddsa] +LOOKAHEAD_SIGN = 24 days +DURATION = 14 days + +[exchange] +PURSE_EXPIRATION_LIMIT = 3 years +CURRENCY = EUR +CURRENCY_ROUND_UNIT = EUR:0.01 +TINY_AMOUNT = EUR:0.01 +PORT = 8091 +SERVE = tcp +BASE_URL = "http://localhost:8091/" +# Two exchanges advertising one shopping URL each is the only way to +# reach ExchangeShoppingScreen: the balance card that opens it is +# hidden when the list is empty, and a single URL opens the browser +# instead of the screen (balances/BalancesPagerComposable.kt:331, +# main/MainScreen.kt:186). +SHOPPING_URL = http://localhost:8080/config?shop=two +# Rewritten by taler-unified-setup.sh in the copy it is given. +MASTER_PUBLIC_KEY = KHA6YSPRQV1ZFCF144SY8KJNR588XA8DA0F6510FKJW30DJFJNAG +STEFAN_ABS = "EUR:5" +ENABLE_KYC = NO +AGE_RESTRICTION_ENABLED = YES +# Same reason as in sim.conf: without this /terms answers "not configured". +TERMS_DIR = /opt/taler-sim/terms/ +TERMS_ETAG = exchange-tos-tops-v0 +PRIVACY_DIR = /opt/taler-sim/terms/ +PRIVACY_ETAG = exchange-pp-v0 + +[exchangedb-postgres] +CONFIG = "postgres:///talersim2" + +# Its own account at the shared libeufin bank, registered by exchange2.sh. +[exchange-account-sim2] +PAYTO_URI = "payto://x-taler-bank/localhost/exchange2?receiver-name=Second+Exchange" +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-sim2] +WIRE_GATEWAY_AUTH_METHOD = basic +USERNAME = exchange2 +PASSWORD = password2 +WIRE_GATEWAY_URL = "http://localhost:8082/accounts/exchange2/taler-wire-gateway/" +CORE_BANK_URL = "http://localhost:8082/accounts/exchange2/" + +[admin-accountcredentials-sim2] +WIRE_GATEWAY_AUTH_METHOD = basic +USERNAME = exchange2 +PASSWORD = password2 +WIRE_GATEWAY_URL = "http://localhost:8082/accounts/exchange2/taler-wire-gateway/" + +# ----------------------------------------------------------- denominations --- + +[coin_eur_ct_1] +value = EUR:0.01 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.00 +fee_deposit = EUR:0.00 +fee_refresh = EUR:0.01 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_ct_10] +value = EUR:0.10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_1] +value = EUR:1 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_5] +value = EUR:5 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_10] +value = EUR:10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +# Age-restricted denominations, so the withdrawal screen offers "Restrict +# usage to age" and the age-restriction paths in the wallet are reachable. +# Taken from exchange/src/testing/coins-rsa.conf. + +[coin_eur_ct_10_age_restricted] +value = EUR:0.10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +age_restricted = YES +CIPHER = RSA + +[coin_eur_1_age_restricted] +value = EUR:1 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +age_restricted = YES +CIPHER = RSA + +[coin_eur_5_age_restricted] +value = EUR:5 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +age_restricted = YES +CIPHER = RSA + +# Sections starting with "doco_" are the donau's denominations. diff --git a/wallet-simulator/backend/sim-kyc.conf b/wallet-simulator/backend/sim-kyc.conf @@ -0,0 +1,84 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# The simulator stack with KYC turned on, so the wallet's "KYC required" and +# "Complete KYC" paths become reachable: withdrawing more than EUR:5 within a +# day trips a rule. +# +# The exchange's own test suite uses a form check backed by +# taler-exchange-helper-measure-test-form, which is built only in its test +# tree, so this uses the helpers the packaged exchange ships. + +@INLINE@ sim.conf + +[exchange] +ENABLE_KYC = YES + +# What the user has to do when a rule trips: fill in a form served by the +# exchange's KYC SPA. A FORM check (rather than INFO) is what gives the wallet +# a link to offer, and "none" accepts whatever the form returns — the test +# suite's validating program, taler-exchange-helper-measure-test-form, is not +# part of the packaged exchange. +[kyc-check-sim-form] +VOLUNTARY = NO +TYPE = FORM +DESCRIPTION = "The simulator requires identification for larger withdrawals" +DESCRIPTION_I18N = {} +REQUIRES = +FALLBACK = sim-freeze +FORM_NAME = full_name_and_birthdate +OUTPUTS = FULL_NAME DATE_OF_BIRTH + +[kyc-measure-sim-form] +CHECK_NAME = sim-form +PROGRAM = none +CONTEXT = {} + +# Shown once the check has been passed. +[kyc-check-sim-info] +VOLUNTARY = NO +TYPE = INFO +DESCRIPTION = "Your account is operating normally" +DESCRIPTION_I18N = {} +REQUIRES = +FALLBACK = sim-freeze + +[kyc-measure-sim-info] +CHECK_NAME = sim-info +CONTEXT = {} + +[kyc-measure-sim-freeze] +CHECK_NAME = skip +PROGRAM = freeze +CONTEXT = {} + +[aml-program-none] +DESCRIPTION = "Do nothing" +COMMAND = taler-exchange-helper-measure-none +FALLBACK = sim-freeze + +[aml-program-freeze] +DESCRIPTION = "Freeze the account pending investigation" +COMMAND = taler-exchange-helper-measure-freeze +FALLBACK = sim-freeze + +# Withdrawing more than EUR:5 in a day needs the check above. +[kyc-rule-sim-withdraw] +ENABLED = YES +EXPOSED = YES +IS_AND_COMBINATOR = YES +OPERATION_TYPE = WITHDRAW +THRESHOLD = EUR:5 +TIMEFRAME = 1d +NEXT_MEASURES = sim-form diff --git a/wallet-simulator/backend/sim-twister.conf b/wallet-simulator/backend/sim-twister.conf @@ -0,0 +1,49 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# The simulator stack with twister in front of the exchange, for fault +# injection: the wallet and the merchant both talk to port 8088, twister +# forwards to the real exchange on 8081 and can truncate, rewrite or fail what +# passes through. +# +# The exchange's own BASE_URL has to be the twister URL, because that is what +# it signs and what the wallet checks. + +@INLINE@ sim.conf + +[exchange] +BASE_URL = "http://localhost:8088/" + +[merchant-exchange-sim] +EXCHANGE_BASE_URL = http://localhost:8088/ + +# The bank hands the wallet this URL in every withdrawal it starts. Left +# pointing at the exchange directly, the wallet compares it with the URL the +# exchange signs (the proxy) and refuses with +# WALLET_EXCHANGE_BASE_URL_MISMATCH before any injected fault can matter. +[libeufin-bank] +SUGGESTED_WITHDRAWAL_EXCHANGE = http://localhost:8088/ + +[twister] +# What the wallet and the merchant treat as "the exchange". +HTTP_PORT = 8088 +SERVE = tcp +# The real exchange. No trailing slash, by twister's own convention. +DESTINATION_BASE_URL = "http://localhost:8081" +HOSTNAME = localhost +ACCEPT_FROM = 127.0.0.1; +ACCEPT_FROM6 = ::1; +UNIXPATH = /tmp/taler-sim-twister.sock +UNIX_MATCH_UID = NO +UNIX_MATCH_GID = YES diff --git a/wallet-simulator/backend/sim.conf b/wallet-simulator/backend/sim.conf @@ -0,0 +1,374 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# Stack configuration for the Android wallet simulator. Derived from +# merchant/src/testing/test_merchant_api.conf plus the libeufin-bank exchange +# account from exchange/src/testing/test_exchange_api.conf. +# +# Every BASE_URL is http://localhost:<port>/ on purpose: the driver maps the +# same ports into each emulator with "adb reverse", so one URL namespace is +# valid both on the host and inside the wallet. taler-unified-setup.sh is run +# with the run directory as CWD, so the relative TALER_TEST_HOME below lands +# there. Note that taler-unified-setup.sh *rewrites* MASTER_PUBLIC_KEY in the +# copy of this file it is given, so it is always run against a copy. + +[PATHS] +TALER_TEST_HOME = home/ +DONAU_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/taler-sim/donau-runtime/ + +[taler-helper-crypto-rsa] +LOOKAHEAD_SIGN = 10 days + +[taler-helper-crypto-cs] +LOOKAHEAD_SIGN = 10 days + +[taler-helper-crypto-eddsa] +LOOKAHEAD_SIGN = 24 days +DURATION = 14 days + +[donau-helper-crypto-rsa] +LOOKAHEAD_SIGN = 10 days + +# ---------------------------------------------------------------- exchange --- + +[exchange] +# A purse must not outlive the denominations of the coins in it. +PURSE_EXPIRATION_LIMIT = 3 years +CURRENCY = EUR +CURRENCY_ROUND_UNIT = EUR:0.01 +TINY_AMOUNT = EUR:0.01 +PORT = 8081 +SERVE = tcp +BASE_URL = "http://localhost:8081/" +# Two exchanges advertising one shopping URL each is the only way to +# reach ExchangeShoppingScreen: the balance card that opens it is +# hidden when the list is empty, and a single URL opens the browser +# instead of the screen (balances/BalancesPagerComposable.kt:331, +# main/MainScreen.kt:186). +SHOPPING_URL = http://localhost:8080/config?shop=one +MASTER_PUBLIC_KEY = KHA6YSPRQV1ZFCF144SY8KJNR588XA8DA0F6510FKJW30DJFJNAG +STEFAN_ABS = "EUR:5" +ENABLE_KYC = NO +# Without this the age-restricted denominations below are ignored and /keys +# advertises an age mask of 0. +AGE_RESTRICTION_ENABLED = YES +# The shipped TERMS_DIR is ${TALER_DATA_HOME}terms/, which in a test setup is +# an empty directory under TALER_TEST_HOME, so /terms answers "501 not +# configured" and the wallet never asks anyone to accept anything. Serving +# terms is what makes the terms-of-service screens -- and +# setExchangeTosAccepted -- reachable at all. +# +# The directory holds *rendered* terms, one subdirectory per language, not the +# .rst sources that ship with the exchange: stack.sh runs +# taler-terms-generator over them once. +TERMS_DIR = /opt/taler-sim/terms/ +TERMS_ETAG = exchange-tos-tops-v0 +PRIVACY_DIR = /opt/taler-sim/terms/ +PRIVACY_ETAG = exchange-pp-v0 + +[exchangedb-postgres] +CONFIG = "postgres:///talersim" + +# The account the exchange uses at the libeufin bank. Registered by +# taler-unified-setup.sh as user "exchange" with password "password". +[exchange-account-sim] +PAYTO_URI = "payto://x-taler-bank/localhost/exchange?receiver-name=Exchange" +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-sim] +WIRE_GATEWAY_AUTH_METHOD = basic +USERNAME = exchange +PASSWORD = password +WIRE_GATEWAY_URL = "http://localhost:8082/accounts/exchange/taler-wire-gateway/" +CORE_BANK_URL = "http://localhost:8082/accounts/exchange/" + +[admin-accountcredentials-sim] +WIRE_GATEWAY_AUTH_METHOD = basic +USERNAME = exchange +PASSWORD = password +WIRE_GATEWAY_URL = "http://localhost:8082/accounts/exchange/taler-wire-gateway/" + +# A second account for the same exchange, in IBAN form. The exchange then +# advertises two ways to be paid, which is what makes the wallet show its +# account picker and the IBAN transfer screens (EPC QR, Swiss QR bill) that the +# x-taler-bank form never reaches. Both point at the same libeufin account. +[exchange-account-iban] +PAYTO_URI = "payto://iban/SANDBOXX/DE89370400440532013000?receiver-name=Exchange+Company" +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-iban] +WIRE_GATEWAY_AUTH_METHOD = basic +USERNAME = exchange +PASSWORD = password +WIRE_GATEWAY_URL = "http://localhost:8082/accounts/exchange/taler-wire-gateway/" +CORE_BANK_URL = "http://localhost:8082/accounts/exchange/" + +# ------------------------------------------------------------ libeufin bank --- + +[libeufin-bank] +CURRENCY = EUR +WIRE_TYPE = x-taler-bank +X_TALER_BANK_PAYTO_HOSTNAME = localhost +# The simulator registers wallet-side customers itself, so registration and the +# registration bonus both have to be open. +ALLOW_REGISTRATION = YES +REGISTRATION_BONUS_ENABLED = yes +REGISTRATION_BONUS = EUR:100 +DEFAULT_CUSTOMER_DEBT_LIMIT = EUR:200 +DEFAULT_ADMIN_DEBT_LIMIT = EUR:2000 +IBAN_PAYTO_BIC = SANDBOXX +SUGGESTED_WITHDRAWAL_EXCHANGE = http://localhost:8081/ +SERVE = tcp +PORT = 8082 +# Cheap password hashing: the simulator creates throwaway accounts in bulk. +PWD_HASH_CONFIG = { "cost": 4 } +PWD_AUTH_COMPAT = yes +BASE_URL = http://localhost:8082/ + +[libeufin-bankdb-postgres] +CONFIG = postgresql:///talersim + +# ---------------------------------------------------------------- merchant --- + +[merchant] +CURRENCY = EUR +PORT = 8080 +SERVE = tcp +DB = postgres +BASE_URL = http://localhost:8080/ + +[merchantdb-postgres] +CONFIG = postgres:///talersim +SQL_DIR = ${DATADIR}sql/ + +[merchant-exchange-sim] +MASTER_KEY = KHA6YSPRQV1ZFCF144SY8KJNR588XA8DA0F6510FKJW30DJFJNAG +EXCHANGE_BASE_URL = http://localhost:8081/ +CURRENCY = EUR + +# Disable the exchanges the shipped merchant config.d pulls in, so the merchant +# only ever talks to the simulator's exchange. +[merchant-exchange-chf] +DISABLED = YES + +[merchant-exchange-kudos] +DISABLED = YES + +# ------------------------------------------------------------------- donau --- + +[donau] +TERMS_ETAG = tos +PRIVACY_ETAG = 0 +CURRENCY = EUR +PORT = 8079 +DB = postgres +LEGAL_DOMAIN = "Bern" +BASE_URL = "http://localhost:8079/" +SERVE = tcp +EXPIRE_IDLE_SLEEP_INTERVAL = "1 s" +EXPIRE_LEGAL_YEARS = 5 + +[donaudb-postgres] +CONFIG = "postgres:///talersim" + +# ----------------------------------------------------------------- auditor --- + +[auditor] +BASE_URL = "http://localhost:8083/" +PORT = 8083 +SERVE = tcp +DB = postgres +TINY_AMOUNT = EUR:0.01 + +[auditordb-postgres] +CONFIG = postgres:///talersim + +# ----------------------------------------------------------- denominations --- +# +# Taken from merchant/src/testing/test_merchant_api-rsa.conf: RSA with a 1024 +# bit key size, because the simulator values fast key setup over strength. The +# age-restricted variants from exchange/src/testing/coins-rsa.conf are left out +# for now; they belong in a separate config variant. + +[coin_eur_ct_1] +value = EUR:0.01 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.00 +fee_deposit = EUR:0.00 +fee_refresh = EUR:0.01 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_ct_10] +value = EUR:0.10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_1] +value = EUR:1 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_5] +value = EUR:5 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +[coin_eur_10] +value = EUR:10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = RSA + +# Age-restricted denominations, so the withdrawal screen offers "Restrict +# usage to age" and the age-restriction paths in the wallet are reachable. +# Taken from exchange/src/testing/coins-rsa.conf. + +[coin_eur_ct_10_age_restricted] +value = EUR:0.10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +age_restricted = YES +CIPHER = RSA + +[coin_eur_1_age_restricted] +value = EUR:1 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +age_restricted = YES +CIPHER = RSA + +[coin_eur_5_age_restricted] +value = EUR:5 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +age_restricted = YES +CIPHER = RSA + +# Sections starting with "doco_" are the donau's denominations. + +[doco_eur_ct_1] +value = EUR:0.01 +duration_withdraw = 1 year +anchor_round = 1 year +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.00 +fee_deposit = EUR:0.00 +fee_refresh = EUR:0.01 +fee_refund = EUR:0.01 +CIPHER = RSA +rsa_keysize = 1024 + +[doco_eur_ct_10] +value = EUR:0.10 +duration_withdraw = 1 year +anchor_round = 1 year +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = RSA +rsa_keysize = 1024 + +[doco_eur_1] +value = EUR:1 +duration_withdraw = 1 year +anchor_round = 1 year +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = RSA +rsa_keysize = 1024 + +[doco_eur_5] +value = EUR:5 +duration_withdraw = 1 year +anchor_round = 1 year +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = RSA +rsa_keysize = 1024 + +[doco_eur_10] +value = EUR:10 +duration_withdraw = 1 year +anchor_round = 1 year +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +CIPHER = RSA +rsa_keysize = 1024 diff --git a/wallet-simulator/backend/stack.sh b/wallet-simulator/backend/stack.sh @@ -0,0 +1,366 @@ +#!/bin/bash +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# Bring the Taler services for the wallet simulator up and down. +# +# Usage: stack.sh start|stop|status|urls +# +# "start" wipes the run directory and the database, so every run begins from a +# known state. taler-unified-setup.sh is started with -W (wait for signal) and +# detached, so it keeps running after this script returns; "stop" sends it +# SIGTERM, which makes it shut down every service it started. + +set -eu + +SIM_ROOT=${SIM_ROOT:-/opt/taler-sim} +RUN=${SIM_RUN:-$SIM_ROOT/run/stack} +HERE="$(cd "$(dirname "$0")" && pwd)" +# SIM_CONF picks the variant: sim.conf plain, sim-kyc.conf with KYC rules, or +# sim-twister.conf to put the fault injector in front of the exchange. +CONF_NAME=${SIM_CONF:-sim.conf} +CONF_SRC="$HERE/$CONF_NAME" +TWISTER_BIN=${SIM_TWISTER_BIN:-/opt/twister/bin/taler-twister-service} +DB=${SIM_DB:-talersim} +# Services: exchange, merchant, libeufin bank, wirewatch, aggregator, transfer, +# merchant depositcheck, merchant wirewatch, donau. +SERVICES=${SIM_SERVICES:="-e -m -b -w -g -t -M -z -D"} +ACCOUNT=${SIM_ACCOUNT:-exchange-account-sim} +# Without -r, taler-unified-setup.sh never patches the merchant's copy of the +# exchange master key, and the merchant then rejects every order with +# "exchange failed to provide a valid response to /keys". +MERCHANT_EXCHANGE=${SIM_MERCHANT_EXCHANGE:-merchant-exchange-sim} +READY_TIMEOUT=${SIM_READY_TIMEOUT:-300} +PIDFILE="$RUN/stack.pid" + +# Accounts to enable beyond the one taler-unified-setup.sh handles via -u. +# It enables exactly one, so a second wire method stays invisible in /keys +# until it is uploaded explicitly. +EXTRA_ACCOUNTS=${SIM_EXTRA_ACCOUNTS:-exchange-account-iban} +# Payto URIs to sign without a config section behind them. The wallet decides +# which deposit and transfer forms to offer purely from the wire methods in +# /keys, so signing an address is enough to reach those screens even when no +# service could ever settle on it. +# Bitcoin only, by default. A Cyclos address belongs here too -- the wallet +# has a Cyclos transfer screen -- but its WireType enum does not know the +# method, and one unknown method makes the whole getDepositWireTypes reply +# throw, which hangs the add-account form for ever (see +# findings/unknown-wire-method-hangs-the-deposit-form.md). Keeping it in the +# default stack would block every deposit scenario, so it is opt-in: +# +# SIM_EXTRA_PAYTOS='payto://cyclos/cyclos.example.com/exchange?receiver-name=X' \ +# ./stack.sh start +EXTRA_PAYTOS=${SIM_EXTRA_PAYTOS:-payto://bitcoin/bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq?receiver-name=Exchange+Bitcoin} +CURRENCY=${SIM_CURRENCY:-EUR} + +# Ports as configured in sim.conf; the emulator side maps exactly these. +PORT_MERCHANT=8080 +PORT_EXCHANGE=8081 +PORT_BANK=8082 +PORT_AUDITOR=8083 +PORT_DONAU=8079 +PORT_TWISTER=8088 +# A second exchange, started by exchange2.sh right after the stack is up; the +# port is mapped into the emulators either way, so turning it off needs no +# re-mapping. It shares the stack's bank, whose database this script wipes, so +# it has to be restarted together with the stack rather than left running. +PORT_EXCHANGE2=8091 +# Services deployed beside the stack (see services/README.md): the Taler +# mailbox and the Taler directory. They have their own databases and outlive a +# stack restart, but their ports have to be mapped into the emulators, so they +# belong in the list below. +PORT_MAILBOX=11000 +PORT_TALDIR=11001 +SIM_EXCHANGE2=${SIM_EXCHANGE2:-1} +EXCHANGE2_JSON=null +# Rendered terms of service, referenced by TERMS_DIR in the configs. +TERMS_OUT=${SIM_TERMS_DIR:-$SIM_ROOT/terms} + +die() { echo "stack.sh: $*" >&2; exit 1; } + +ensure_db() { + local me + me=$(id -un) + if ! sudo -u postgres psql -tAc \ + "SELECT 1 FROM pg_roles WHERE rolname='$me'" | grep -q 1; then + echo "creating postgres superuser role $me" >&2 + sudo -u postgres createuser -s "$me" + fi + # Drop and recreate so each run starts from an empty database; the service + # dbinit calls in taler-unified-setup.sh only reset the schemas they know. + dropdb --if-exists "$DB" + createdb "$DB" +} + +running_pid() { + [ -s "$PIDFILE" ] || return 1 + local pid + pid=$(cat "$PIDFILE") + kill -0 "$pid" 2>/dev/null || return 1 + echo "$pid" +} + +start_twister() { + # Only for the twister variant: taler-unified-setup.sh knows nothing about + # it, so the proxy is started here, once the exchange it forwards to is up. + case "$CONF_NAME" in + *twister*) ;; + *) return 0 ;; + esac + [ -x "$TWISTER_BIN" ] || { echo "WARNING: no twister at $TWISTER_BIN" >&2; return 0; } + setsid "$TWISTER_BIN" -c "$CONF_NAME" > twister.log 2>&1 < /dev/null & + echo $! > twister.pid + local waited=0 + while [ "$waited" -lt 20 ]; do + # Only that it is listening: the exchange it forwards to is not up yet. + if ss -ltn 2>/dev/null | grep -q ":$PORT_TWISTER "; then + echo "twister listening on $PORT_TWISTER -> 8081" >&2 + return 0 + fi + sleep 1 + waited=$((waited + 1)) + done + echo "WARNING: twister is not listening on $PORT_TWISTER; see $RUN/twister.log" >&2 +} + +# taler-unified-setup.sh only uploads a wire fee for the one wire method it was +# told about, and wallet-core hides every exchange account whose method has no +# fee -- so an extra account stays invisible to the wallet until we add one. +upload_wire_fee() { + local method=$1 next_year + next_year=$(( 1 + $(date +%Y) )) + if taler-exchange-offline -c "$CONF_NAME" \ + wire-fee now "$method" "$CURRENCY:0.01" "$CURRENCY:0.01" \ + wire-fee "$next_year" "$method" "$CURRENCY:0.01" "$CURRENCY:0.01" \ + upload >> enable-extra-accounts.log 2>&1; then + echo "uploaded $method wire fees" >&2 + else + echo "WARNING: no wire fee for $method; see enable-extra-accounts.log" >&2 + fi +} + +# The exchange serves rendered terms, one subdirectory per language; what ships +# with it are the .rst sources. Generating them once is the difference between +# /terms answering with the terms and answering "not configured". +# The wallet's terms screen only shows its language selector when the exchange +# offers more than one language (ReviewExchangeTosScreen.kt:183), and the +# shipped exchange-tos-v0 has an English source only -- so the terms used here +# are exchange-tos-tops-v0, which ships de and en. +TERMS_ID=${SIM_TERMS_ID:-exchange-tos-tops-v0} +TERMS_LANGS=${SIM_TERMS_LANGS:-"en de"} + +ensure_terms() { + [ -s "$TERMS_OUT/en/$TERMS_ID.txt" ] && return 0 + command -v taler-terms-generator > /dev/null || { + echo "WARNING: no taler-terms-generator; the exchange will serve no terms" >&2 + return 0 + } + mkdir -p "$TERMS_OUT" + local src=/usr/share/taler-exchange/terms lang + : > "$TERMS_OUT/generate.log" + for lang in $TERMS_LANGS; do + (cd "$src" && + taler-terms-generator -i "$TERMS_ID" -l "$lang" -o "$TERMS_OUT" && + taler-terms-generator -i exchange-pp-v0 -l "$lang" -o "$TERMS_OUT") \ + >> "$TERMS_OUT/generate.log" 2>&1 || + echo "WARNING: could not render the $lang terms; see $TERMS_OUT/generate.log" >&2 + done +} + +enable_payto() { + local payto=$1 what=$2 method + if taler-exchange-offline -c "$CONF_NAME" enable-account "$payto" upload \ + >> enable-extra-accounts.log 2>&1; then + echo "enabled $what ($payto)" >&2 + else + echo "WARNING: could not enable $what; see enable-extra-accounts.log" >&2 + return 0 + fi + method=$(echo "$payto" | sed -n 's|^payto://\([^/]*\)/.*|\1|p') + [ -n "$method" ] && upload_wire_fee "$method" +} + +enable_extra_accounts() { + local section payto + for section in $EXTRA_ACCOUNTS; do + payto=$(taler-exchange-config -c "$CONF_NAME" -s "$section" -o PAYTO_URI 2>/dev/null) + [ -n "$payto" ] || continue + enable_payto "$payto" "$section" + done + local IFS=' +' + for payto in $EXTRA_PAYTOS; do + [ -n "$payto" ] && enable_payto "$payto" "extra payto" + done +} + +start_exchange2() { + [ "$SIM_EXCHANGE2" = "1" ] || return 0 + if (cd "$HERE" && ./exchange2.sh start > "$RUN/exchange2.log" 2>&1); then + EXCHANGE2_JSON="\"http://localhost:$PORT_EXCHANGE2/\"" + echo "second exchange up on $PORT_EXCHANGE2" >&2 + else + echo "WARNING: the second exchange did not start; see exchange2.log" >&2 + tail -5 "$RUN/exchange2.log" >&2 || true + fi +} + +write_env() { + local EXCHANGE_URL="http://localhost:$PORT_EXCHANGE/" + local TWISTER_JSON=null + case "$CONF_NAME" in + *twister*) + EXCHANGE_URL="http://localhost:$PORT_TWISTER/" + TWISTER_JSON="{\"url\": \"http://localhost:$PORT_TWISTER/\", \"config\": \"$RUN/$CONF_NAME\"}" + ;; + esac + cat > "$RUN/env.json" <<JSON +{ + "host": "localhost", + "ports": [$PORT_DONAU, $PORT_MERCHANT, $PORT_EXCHANGE, $PORT_BANK, $PORT_AUDITOR, + $PORT_TWISTER, $PORT_EXCHANGE2, $PORT_MAILBOX, $PORT_TALDIR], + "exchange": "$EXCHANGE_URL", + "exchange_direct": "http://localhost:$PORT_EXCHANGE/", + "exchange2": $EXCHANGE2_JSON, + "mailbox": "http://localhost:$PORT_MAILBOX/", + "taldir": "http://localhost:$PORT_TALDIR/", + "twister": $TWISTER_JSON, + "merchant": "http://localhost:$PORT_MERCHANT/", + "bank": "http://localhost:$PORT_BANK/", + "donau": "http://localhost:$PORT_DONAU/", + "auditor": "http://localhost:$PORT_AUDITOR/", + "currency": "EUR", + "run_dir": "$RUN", + "bank_admin": {"username": "admin", "password": "secret-password"}, + "exchange_bank_account": {"username": "exchange", "password": "password"} +} +JSON +} + +start() { + if pid=$(running_pid); then + die "already running (pid $pid); run 'stack.sh stop' first" + fi + command -v taler-unified-setup.sh >/dev/null || die "taler-unified-setup.sh not in PATH" + ensure_db + rm -rf "$RUN" + mkdir -p "$RUN/home" + # taler-unified-setup.sh rewrites MASTER_PUBLIC_KEY in the config it is + # handed, so it always gets a copy. + # sim.conf is @INLINE@d by the variants, so both have to be in the run + # directory, and taler-unified-setup.sh rewrites the one it is given. + cp "$HERE/sim.conf" "$RUN/sim.conf" + [ "$CONF_NAME" = "sim.conf" ] || cp "$CONF_SRC" "$RUN/$CONF_NAME" + cd "$RUN" + ensure_terms + # Before the services, not after: with the twister variant the exchange's + # own BASE_URL is the proxy, and its key setup talks to that URL. If + # nothing is listening there yet, "Setting up exchange keys" fails and the + # whole stack dies. + start_twister + # shellcheck disable=SC2086 + setsid taler-unified-setup.sh -W -c "$CONF_NAME" -u "$ACCOUNT" \ + -r "$MERCHANT_EXCHANGE" $SERVICES \ + > setup.stdout 2> setup.stderr < /dev/null & + echo $! > "$PIDFILE" + local pid waited + pid=$(cat "$PIDFILE") + waited=0 + while [ "$waited" -lt "$READY_TIMEOUT" ]; do + if grep -q '^READY:' setup.stdout 2>/dev/null; then + enable_extra_accounts + start_exchange2 + write_env + echo "stack up after ${waited}s: $(cat "$RUN/env.json" | tr -d '\n')" >&2 + echo "READY" + return 0 + fi + if ! kill -0 "$pid" 2>/dev/null; then + echo "--- setup.stderr (tail) ---" >&2 + tail -40 setup.stderr >&2 || true + die "taler-unified-setup.sh died before becoming ready" + fi + sleep 1 + waited=$((waited + 1)) + done + echo "--- setup.stderr (tail) ---" >&2 + tail -40 setup.stderr >&2 || true + die "timed out after ${READY_TIMEOUT}s waiting for READY" +} + +stop() { + # The second exchange first: it has an account at the bank this stack is + # about to take down. + [ "$SIM_EXCHANGE2" = "1" ] && (cd "$HERE" && ./exchange2.sh stop >/dev/null 2>&1 || true) + if pid=$(running_pid); then + kill -TERM "$pid" + local waited=0 + while kill -0 "$pid" 2>/dev/null && [ "$waited" -lt 60 ]; do + sleep 1 + waited=$((waited + 1)) + done + kill -KILL "$pid" 2>/dev/null || true + if [ -s "$RUN/twister.pid" ]; then + kill "$(cat "$RUN/twister.pid")" 2>/dev/null || true + rm -f "$RUN/twister.pid" + fi + echo "stopped" >&2 + else + echo "not running" >&2 + fi + rm -f "$PIDFILE" + # The supervisor dying is not the same as its children letting go of the + # ports: starting again five seconds later made taler-unified-setup.sh die + # at the merchant, which cost a phase run. Wait for the ones this stack + # owns to be free. 11000 and 11001 (mailbox, taldir) are deliberately + # left out: they are run separately and outlive the stack. + local waited=0 busy + while [ "$waited" -lt 60 ]; do + busy="" + for p in "$PORT_DONAU" "$PORT_MERCHANT" "$PORT_EXCHANGE" "$PORT_BANK" \ + "$PORT_AUDITOR" "$PORT_EXCHANGE2"; do + if ss -ltn 2>/dev/null | grep -q ":$p\b"; then busy="$busy $p"; fi + done + [ -z "$busy" ] && break + sleep 2 + waited=$((waited + 2)) + done + [ -n "$busy" ] && echo "still listening after ${waited}s:$busy" >&2 + return 0 +} + +status() { + if pid=$(running_pid); then + echo "running (pid $pid)" + for p in $PORT_DONAU $PORT_MERCHANT $PORT_EXCHANGE $PORT_BANK; do + printf ' port %s: ' "$p" + if curl -s -m 2 -o /dev/null "http://localhost:$p/config"; then + echo "ok" + else + echo "NO /config" + fi + done + else + echo "not running" + return 1 + fi +} + +case "${1:-}" in + start) start ;; + stop) stop ;; + status) status ;; + urls) cat "$RUN/env.json" ;; + *) die "usage: stack.sh start|stop|status|urls" ;; +esac diff --git a/wallet-simulator/corpus/uris.py b/wallet-simulator/corpus/uris.py @@ -0,0 +1,150 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Corpus of URIs to feed the wallet, by QR code or shared text. + +Three kinds live here: + +* STRUCTURAL — well-formed URIs of every action the wallet claims to handle, + pointing at the local stack but at ids that do not exist. The + wallet must report a clean error, not an internal one. +* MALFORMED — syntactically broken or hostile input. Nothing here may crash + the app or reach an "internal error" screen. +* TEMPLATES — formats a scenario fills in with live ids, to test the + *semantically* wrong cases (already paid, aborted, expired). + +A value may legitimately be rejected; what matters is *how*. The oracle looks +for crashes, internal/unexpected error codes and hangs, not for success. +""" + +from __future__ import annotations + +# A 52-character Crockford base32 string, the shape of most Taler identifiers. +FAKE_ID = "A" * 52 +EXCHANGE = "localhost:8081" +MERCHANT = "localhost:8080" +BANK = "localhost:8082" + +STRUCTURAL: dict[str, str] = { + "pay": f"taler+http://pay/{MERCHANT}/instances/sim/{FAKE_ID}/", + "pay_with_token": f"taler+http://pay/{MERCHANT}/instances/sim/{FAKE_ID}/?c={FAKE_ID}", + "withdraw": f"taler+http://withdraw/{BANK}/taler-integration/{FAKE_ID}", + "withdraw_exchange": f"taler+http://withdraw-exchange/{EXCHANGE}/", + "add_exchange": f"taler+http://add-exchange/{EXCHANGE}/", + "pay_pull": f"taler+http://pay-pull/{EXCHANGE}/{FAKE_ID}", + "pay_push": f"taler+http://pay-push/{EXCHANGE}/{FAKE_ID}", + "refund": f"taler+http://refund/{MERCHANT}/instances/sim/{FAKE_ID}/", + "pay_template": f"taler+http://pay-template/{MERCHANT}/instances/sim/template1", + "reward": f"taler+http://reward/{MERCHANT}/instances/sim/{FAKE_ID}/", + "payto_iban": "payto://iban/SANDBOXX/DE89370400440532013000?receiver-name=Test", + "payto_x_taler_bank": f"payto://x-taler-bank/{BANK}/wallet1?receiver-name=Wallet", + # The https forms the production app would see; they must fail on the + # network, not in parsing. + "pay_https": f"taler://pay/{MERCHANT}/instances/sim/{FAKE_ID}/", + "withdraw_https": f"taler://withdraw/{BANK}/taler-integration/{FAKE_ID}", + # Developer-mode entry points. They are part of the app's URI surface and + # an unknown one already drops the user on the home screen (see + # dev-experiment-uri-exits-the-app.md), so the known ones belong here too. + # Only the harmless ones: the others change how the wallet behaves for the + # rest of the session, which a URI storm must not do to its own scenario. + "dev_experiment_clear_api_errors": "taler+http://dev-experiment/clear-api-errors", + "add_contact": f"taler+http://add-contact/email/friend@example.com/{EXCHANGE}/{FAKE_ID}", +} + +MALFORMED: dict[str, str] = { + "empty": "", + "whitespace": " \t ", + "scheme_only": "taler://", + "scheme_no_slash": "taler:", + "unknown_action": f"taler+http://frobnicate/{EXCHANGE}/{FAKE_ID}", + "wrong_scheme": f"gnunet://pay/{MERCHANT}/{FAKE_ID}/", + "http_url": f"http://{MERCHANT}/instances/sim/orders/{FAKE_ID}", + "javascript": "javascript:alert(1)", + "file_uri": "file:///etc/passwd", + "intent_uri": "intent://scan/#Intent;scheme=taler;package=net.taler.wallet;end", + "content_uri": "content://net.taler.wallet.fdroid.debug.fileprovider/db/wallet.sqlite3", + "uppercase": f"TALER+HTTP://PAY/{MERCHANT}/INSTANCES/SIM/{FAKE_ID}/", + "ext_prefix": f"ext+taler://pay/{MERCHANT}/instances/sim/{FAKE_ID}/", + "double_scheme": f"taler://taler://pay/{MERCHANT}/{FAKE_ID}/", + "no_host": f"taler+http://pay//instances/sim/{FAKE_ID}/", + "missing_id": f"taler+http://pay/{MERCHANT}/instances/sim/", + "truncated_id": f"taler+http://pay/{MERCHANT}/instances/sim/{'A' * 7}/", + # I, L, O and U are not in the Crockford alphabet Taler uses. + "bad_base32": f"taler+http://pay/{MERCHANT}/instances/sim/{'ILOU' * 13}/", + "id_too_long": f"taler+http://pay/{MERCHANT}/instances/sim/{'A' * 5000}/", + "path_traversal": f"taler+http://pay/{MERCHANT}/../../etc/passwd/{FAKE_ID}/", + "double_encoded": f"taler+http://pay/{MERCHANT}/instances/sim/%2541%2541/", + "percent_broken": f"taler+http://pay/{MERCHANT}/instances/sim/%ZZ/", + "null_byte": f"taler+http://pay/{MERCHANT}/instances/sim/{FAKE_ID}\x00/", + "newline": f"taler+http://pay/{MERCHANT}/instances/sim/{FAKE_ID}\n/", + "crlf_header": f"taler+http://pay/{MERCHANT}/\r\nX-Evil: 1/{FAKE_ID}/", + "unicode": f"taler+http://pay/{MERCHANT}/instances/sim/日本語テスト/", + "rtl_override": f"taler+http://pay/{MERCHANT}/instances/‮sim/{FAKE_ID}/", + "emoji": "taler+http://pay/localhost:8080/instances/🎉/🎉/", + "huge": "taler+http://pay/" + "a" * 10000, + "many_params": f"taler+http://pay/{MERCHANT}/instances/sim/{FAKE_ID}/?" + + "&".join(f"p{i}=1" for i in range(500)), + "port_overflow": f"taler+http://pay/localhost:99999/instances/sim/{FAKE_ID}/", + "port_negative": f"taler+http://pay/localhost:-1/instances/sim/{FAKE_ID}/", + "ipv6_host": f"taler+http://pay/[::1]:8080/instances/sim/{FAKE_ID}/", + "credentials_host": f"taler+http://pay/user:pw@{MERCHANT}/instances/sim/{FAKE_ID}/", + "private_host": f"taler+http://pay/169.254.169.254/instances/sim/{FAKE_ID}/", + "payto_no_target": "payto://iban/", + "payto_unknown_method": f"payto://frobnicate/{FAKE_ID}", + "payto_bad_amount": "payto://iban/SANDBOXX/DE89370400440532013000?amount=EUR:-1", + "payto_huge_amount": "payto://iban/SANDBOXX/DE89370400440532013000?amount=EUR:" + + "9" * 40, +} + +# Formats a scenario fills in once it has live identifiers; the interesting +# cases are the ones that are perfectly well-formed but semantically stale. +TEMPLATES: dict[str, str] = { + "pay": "taler+http://pay/{merchant}/instances/{instance}/{order_id}/?c={token}", + "withdraw": "taler+http://withdraw/{bank}/taler-integration/{withdrawal_id}", + "refund": "taler+http://refund/{merchant}/instances/{instance}/{order_id}/", + "pay_pull": "taler+http://pay-pull/{exchange}/{contract_id}", + "pay_push": "taler+http://pay-push/{exchange}/{contract_id}", +} + +# Text fed into amount and free-text fields; the amount parser and Amount's own +# overflow rules are the target. +TEXT_INPUTS: list[str] = [ + "", " ", "0", "0.00", "-1", "-0.01", "+5", + "1e10", "1E308", "0x10", "٠١٢", "1,50", "1.5.5", "1..5", + "999999999999999999999999", # beyond Amount's value range + "9007199254740993", # beyond 2^53 + "0.000000001", # below the smallest fraction + "10.123456789", # more fraction digits than allowed + "EUR:10", "10 EUR", "KUDOS:10", # currency where a number is expected + "NaN", "Infinity", "null", "undefined", + "'; DROP TABLE coins; --", + "<script>alert(1)</script>", + "${jndi:ldap://x/y}", + "%s%s%s%n", + "‮RTL", "🎉🎉🎉", "日本語", + "A" * 2000, +] + + +def all_uris() -> dict[str, str]: + """Everything that can be fired without live state.""" + return {**{f"structural/{k}": v for k, v in STRUCTURAL.items()}, + **{f"malformed/{k}": v for k, v in MALFORMED.items()}} + + +if __name__ == "__main__": + for name, uri in all_uris().items(): + shown = uri if len(uri) <= 90 else uri[:87] + "..." + print(f"{name:34} {shown!r}") + print(f"\n{len(all_uris())} URIs, {len(TEXT_INPUTS)} text inputs, " + f"{len(TEMPLATES)} templates") diff --git a/wallet-simulator/coverage/app-operations.txt b/wallet-simulator/coverage/app-operations.txt @@ -0,0 +1,71 @@ +abortTransaction +acceptBankIntegratedWithdrawal +acceptManualWithdrawal +addBankAccount +addContact +addExchange +addGlobalCurrencyExchange +addMailboxMessage +applyDevExperiment +cancelProgressToken +checkDeposit +checkPayForTemplate +checkPeerPullCredit +clearDb +completeRegisterAlias +confirmPay +confirmPeerPullDebit +confirmPeerPushCredit +createDepositGroup +deleteContact +deleteExchange +deleteMailboxMessage +deleteTransaction +exportDb +failTransaction +forgetBankAccount +getBalances +getBankAccountById +getChoicesForPayment +getContacts +getCurrencySpecification +getDepositWireTypes +getDonau +getDonauStatements +getExchangeEntryByUrl +getExchangeTos +getMailbox +getMailboxMessage +getMaxDepositAmount +getMaxPeerPushDebitAmount +getTransactionById +getWithdrawalDetailsForAmount +hintNetworkAvailability +importDb +init +initializeMailbox +initiatePeerPullCredit +initiatePeerPushDebit +initWallet +listBankAccounts +listDiscounts +listExchanges +listSubscriptions +lookupAlias +preparePeerPullDebit +preparePeerPushCredit +prepareWithdrawExchange +refreshMailbox +registerAlias +removeGlobalCurrencyExchange +resumeTransaction +retryTransaction +sendTalerUriMailboxMessage +setDonau +setExchangeTosAccepted +setExchangeTosForgotten +startRefundQueryForUri +suspendTransaction +updateExchangeEntry +validateIban +withdrawTestBalance diff --git a/wallet-simulator/coverage/gaps.py b/wallet-simulator/coverage/gaps.py @@ -0,0 +1,252 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Where the simulator has not been yet. + +Reads the JaCoCo XML report and ranks what is still untouched, so the next +iteration can aim at a feature rather than at random. Compose generates a lot +of synthetic classes, so lambdas and `*ComposableSingletons` are folded into +their owner and the ranking is by missed *lines* per package and per class. + + python3 gaps.py out/coverage/coverage.xml # ranking + python3 gaps.py out/coverage/coverage.xml --since old.xml # what moved +""" + +from __future__ import annotations + +import re +import sys +import xml.etree.ElementTree as ET +from pathlib import Path +from collections import defaultdict +from dataclasses import dataclass, field + +SYNTHETIC = re.compile(r"\$\$|ComposableSingletons|\$lambda|\$WhenMappings|Kt\$\d") + + +# Lines inside an @Preview body cannot be covered by an instrumented app run: +# the function exists for Android Studio's preview pane and nothing calls it. +# They are 27 % of everything this report calls "missed", so counting them +# makes every ranking point at work that cannot be done. +def preview_lines(repo: Path) -> dict[str, set[int]]: + """Line numbers belonging to @Preview functions, per source file name.""" + out: dict[str, set[int]] = {} + for tree in ("wallet/src/main/java", "taler-kotlin-android/src/main/java"): + base = repo / tree + if not base.is_dir(): + continue + for path in base.rglob("*.kt"): + lines = path.read_text(errors="replace").splitlines() + marked: set[int] = set() + i = 0 + while i < len(lines): + if "@Preview" in lines[i]: + depth, started, j = 0, False, i + while j < len(lines): + marked.add(j + 1) + depth += lines[j].count("{") - lines[j].count("}") + if "{" in lines[j]: + started = True + if started and depth <= 0: + break + j += 1 + i = j + i += 1 + if marked: + out[path.name] = marked + return out + + +def source_misses(path: str, skip: dict[str, set[int]]) -> tuple[int, int, int]: + """(missed, covered, missed-inside-previews) counted line by line.""" + root = ET.parse(path).getroot() + missed = covered = in_preview = 0 + for pkg in root.findall("package"): + for sf in pkg.findall("sourcefile"): + skipped = skip.get(sf.get("name") or "", ()) + for line in sf.findall("line"): + nr = int(line.get("nr", 0)) + mi, ci = int(line.get("mi", 0)), int(line.get("ci", 0)) + if ci: + covered += 1 + elif mi: + missed += 1 + if nr in skipped: + in_preview += 1 + return missed, covered, in_preview + + +def reachable_misses_by_package(path: str, skip: dict[str, set[int]]) -> dict[str, int]: + """Missed lines per package, not counting the ones inside @Preview bodies. + + Ranking packages by raw misses points at work that cannot be done: the + peer package looked like the third-biggest gap in the report and is mostly + four preview functions in one file. + """ + root = ET.parse(path).getroot() + out: dict[str, int] = defaultdict(int) + for pkg in root.findall("package"): + pname = (pkg.get("name") or "").replace("/", ".") + for sf in pkg.findall("sourcefile"): + skipped = skip.get(sf.get("name") or "", ()) + for line in sf.findall("line"): + if int(line.get("ci", 0)): + continue + if not int(line.get("mi", 0)): + continue + if int(line.get("nr", 0)) not in skipped: + out[pname] += 1 + return dict(out) + + +@dataclass +class Unit: + missed: int = 0 + covered: int = 0 + + @property + def total(self) -> int: + return self.missed + self.covered + + @property + def pct(self) -> float: + return 100.0 * self.covered / self.total if self.total else 100.0 + + +def counter(el: ET.Element, kind: str = "LINE") -> tuple[int, int]: + for c in el.findall("counter"): + if c.get("type") == kind: + return int(c.get("missed", 0)), int(c.get("covered", 0)) + return 0, 0 + + +def read(path: str) -> tuple[dict[str, Unit], dict[str, Unit], Unit]: + root = ET.parse(path).getroot() + packages: dict[str, Unit] = defaultdict(Unit) + classes: dict[str, Unit] = defaultdict(Unit) + overall = Unit() + m, c = counter(root) + overall.missed, overall.covered = m, c + for pkg in root.findall("package"): + pname = (pkg.get("name") or "").replace("/", ".") + pm, pc = counter(pkg) + packages[pname].missed += pm + packages[pname].covered += pc + for cls in pkg.findall("class"): + cname = (cls.get("name") or "").replace("/", ".") + # Fold Compose's synthetic classes into the file they came from. + owner = re.split(SYNTHETIC, cname)[0] or cname + cm, cc = counter(cls) + classes[owner].missed += cm + classes[owner].covered += cc + return dict(packages), dict(classes), overall + + +def main() -> int: + if len(sys.argv) < 2: + print(__doc__) + return 2 + packages, classes, overall = read(sys.argv[1]) + print(f"overall lines: {overall.covered}/{overall.total} ({overall.pct:.1f}%)") + # What of the shortfall is even reachable. + repo = Path(__file__).resolve().parent.parent.parent + try: + missed, covered, in_preview = source_misses(sys.argv[1], preview_lines(repo)) + except Exception: # noqa: BLE001 + in_preview = 0 + in_dead = 0 + if "--dead" in sys.argv: + # Opt-in: the dead-code search takes a few minutes, which is too slow + # for a report meant to be read while a round runs. + try: + sys.path.insert(0, str(Path(__file__).resolve().parent)) + import deadcode + found, _ = deadcode.dead(repo, deadcode.MODULES["wallet"]) + dead_by_file: dict[str, set[int]] = defaultdict(set) + for d in found: + dead_by_file[d.path.name].update(range(d.start, d.end + 1)) + root = ET.parse(sys.argv[1]).getroot() + previews = preview_lines(repo) + for pkg in root.findall("package"): + for sf in pkg.findall("sourcefile"): + name = sf.get("name") or "" + pv = previews.get(name, set()) + dd = dead_by_file.get(name, set()) + for line in sf.findall("line"): + nr = int(line.get("nr", 0)) + if int(line.get("ci", 0)) or not int(line.get("mi", 0)): + continue + if nr in dd and nr not in pv: + in_dead += 1 + except Exception as e: # noqa: BLE001 + print(f" (dead-code pass failed: {e})") + if in_preview: + reachable = covered + missed - in_preview - in_dead + print(f" of the {missed} missed lines, {in_preview} are inside @Preview " + f"bodies and cannot run at all") + if in_dead: + print(f" of the rest, {in_dead} are in declarations nothing " + f"refers to (deadcode.py)") + print(f" reachable lines covered: {covered}/{reachable} " + f"({100.0 * covered / reachable:.1f}%); the highest this report " + f"can ever read is {100.0 * reachable / (covered + missed):.1f}%") + if not in_dead: + print(" (pass --dead to discount unreachable declarations too)") + print() + + if "--since" in sys.argv: + before_path = sys.argv[sys.argv.index("--since") + 1] + bp, bc, bo = read(before_path) + print(f"since {before_path}: {bo.covered} -> {overall.covered} lines " + f"({bo.pct:.1f}% -> {overall.pct:.1f}%)\n") + moved = sorted( + ((name, u.covered - bc.get(name, Unit()).covered, u) + for name, u in classes.items()), + key=lambda row: -row[1], + ) + print("newly covered (top 15):") + for name, delta, u in moved[:15]: + if delta <= 0: + break + print(f" +{delta:5} {u.pct:5.1f}% {name.split('.')[-1]}") + print() + + try: + reachable_by_pkg = reachable_misses_by_package(sys.argv[1], preview_lines(repo)) + except Exception: # noqa: BLE001 + reachable_by_pkg = {} + + print("packages by missed lines that can actually be reached:") + ranked = sorted(packages.items(), + key=lambda kv: -reachable_by_pkg.get(kv[0], kv[1].missed)) + for name, u in ranked[:18]: + short = name.replace("net.taler.wallet", "~").replace("net.taler.common", "common") + reach = reachable_by_pkg.get(name) + extra = "" if reach is None else f" ({u.missed} counting previews)" + print(f" {reach if reach is not None else u.missed:6} missed " + f"{u.pct:5.1f}% {short}{extra}") + + print("\nuntouched classes with the most lines (0% covered):") + untouched = [(n, u) for n, u in classes.items() if u.covered == 0 and u.total >= 12] + for name, u in sorted(untouched, key=lambda kv: -kv[1].missed)[:25]: + print(f" {u.missed:6} lines {name}") + + print("\npartly covered, biggest remainder:") + partial = [(n, u) for n, u in classes.items() if u.covered > 0 and u.missed >= 25] + for name, u in sorted(partial, key=lambda kv: -kv[1].missed)[:20]: + print(f" {u.missed:6} missed {u.pct:5.1f}% {name.split('.')[-1]}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/wallet-simulator/coverage/operations.py b/wallet-simulator/coverage/operations.py @@ -0,0 +1,102 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Which wallet-core operations the simulator has actually exercised. + +JaCoCo measures the Kotlin shell; the logic that produces "internal error" +screens is TypeScript inside QuickJS and cannot be instrumented through qtart. +The boundary between them can be measured though: `BackendManager` logs every +request it sends and every reply it gets, so the operations exercised, and the +error codes each one produced, can be counted from the logcats the episodes +already keep. + +The denominator is the set of operations the app's own Kotlin code can issue +(`app-operations.txt`, extracted from the sources), not everything wallet-core +offers. + + python3 operations.py /opt/taler-sim/run/out + python3 operations.py /opt/taler-sim/run/out --ops app-operations.txt +""" + +from __future__ import annotations + +import argparse +import json +import re +from collections import Counter, defaultdict +from pathlib import Path + +SENT = re.compile(r'"operation"\s*:\s*"([a-zA-Z]+)"') +ERROR_REPLY = re.compile( + r'\{"type":"error","operation":"([a-zA-Z]+)","id":\d+,"error":\{"code":(\d+)') + + +def scan(root: Path) -> tuple[Counter, dict[str, Counter]]: + operations: Counter = Counter() + errors: dict[str, Counter] = defaultdict(Counter) + for log in root.rglob("*logcat*.txt"): + try: + text = log.read_text(errors="replace") + except OSError: + continue + for name in SENT.findall(text): + operations[name] += 1 + for name, code in ERROR_REPLY.findall(text): + errors[name][int(code)] += 1 + return operations, errors + + +def main() -> int: + ap = argparse.ArgumentParser(description=__doc__) + ap.add_argument("root", type=Path, nargs="?", + default=Path("/opt/taler-sim/run/out")) + ap.add_argument("--ops", type=Path, + default=Path(__file__).with_name("app-operations.txt")) + ap.add_argument("--json", action="store_true") + args = ap.parse_args() + + known = [line.strip() for line in args.ops.read_text().splitlines() + if line.strip()] if args.ops.is_file() else [] + seen, errors = scan(args.root) + + exercised = [op for op in known if seen.get(op)] + missing = [op for op in known if not seen.get(op)] + extra = sorted(set(seen) - set(known)) + + if args.json: + print(json.dumps({ + "exercised": exercised, "missing": missing, "undeclared": extra, + "counts": seen, "errors": {k: dict(v) for k, v in errors.items()}, + }, indent=2)) + return 0 + + total = len(known) or len(seen) + print(f"wallet-core operations exercised: {len(exercised)}/{total} " + f"({100 * len(exercised) / total:.0f}%)\n") + print("top operations by calls:") + for name, count in seen.most_common(15): + print(f" {count:6} {name}") + print(f"\nnever exercised ({len(missing)}):") + for name in missing: + print(f" {name}") + if extra: + print(f"\nseen but not in the app's list ({len(extra)}): " + f"{', '.join(extra[:20])}") + print("\noperations that returned an error, with codes:") + for name, codes in sorted(errors.items(), key=lambda kv: -sum(kv[1].values())): + print(f" {name}: {dict(codes)}") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/coverage/report.sh b/wallet-simulator/coverage/report.sh @@ -0,0 +1,102 @@ +#!/bin/bash +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# Turn collected .ec files into a coverage report. +# +# Runs on the *build* host, not on the emulator host: the report needs the +# uninstrumented class files and the sources, which only exist where the APK +# was built. Collect the .ec files first (driver/coverage.py on the emulator +# host, then rsync them here). +# +# Usage: report.sh <dir-with-.ec-files> [out-dir] +# +# One warning about the input: jacoco matches execution data to classes by a +# checksum of the class file, so data recorded by one APK is dropped (with +# "Execution data for class … does not match") when reported against a +# different build. Resources are enough to do it -- an added res/ file shifts +# the inlined R constants -- so rebuilding the APK starts a new coverage +# baseline, and .ec files from before it have to be reported separately or not +# at all. + +set -eu + +EC_DIR=${1:?usage: report.sh <dir-with-.ec-files> [out-dir]} +OUT_DIR=${2:-$(dirname "$0")/../out/coverage} +REPO=$(cd "$(dirname "$0")/../.." && pwd) +VARIANT=${SIM_VARIANT:-fdroidSim} +JACOCO_VERSION=${JACOCO_VERSION:-0.8.14} +CACHE=${SIM_TOOLS:-$HOME/.cache/taler-sim} +CLI="$CACHE/org.jacoco.cli-$JACOCO_VERSION-nodeps.jar" + +mkdir -p "$CACHE" "$OUT_DIR" +if [ ! -s "$CLI" ]; then + echo "fetching jacoco cli $JACOCO_VERSION" >&2 + curl -sSfL -o "$CLI" \ + "https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/$JACOCO_VERSION/org.jacoco.cli-$JACOCO_VERSION-nodeps.jar" +fi + +# One truncated .ec -- a dump whose app was killed mid-write -- makes jacoco's +# `merge` abort over every other file, so the files are checked first and only +# the complete ones go in. +mapfile -t EC_FILES < <(python3 "$(dirname "$0")/validate_ec.py" "$EC_DIR") +[ "${#EC_FILES[@]}" -gt 0 ] || { echo "no usable .ec files under $EC_DIR" >&2; exit 1; } +echo "merging ${#EC_FILES[@]} execution data file(s)" >&2 + +# JAVA_HOME when it points at a usable JVM, otherwise whatever is on PATH: +# this used to hard-code the workstation's JDK, so a run on the emulator host +# -- where JAVA_HOME is not set -- died with "no such file or directory" after +# validating all 2400 dumps. +if [ -n "${JAVA_HOME:-}" ] && [ -x "$JAVA_HOME/bin/java" ]; then + JAVA="$JAVA_HOME/bin/java" +else + JAVA=$(command -v java) || + { echo "no java on PATH and no usable JAVA_HOME" >&2; exit 1; } +fi +MERGED="$OUT_DIR/merged.exec" +# `merge` appends to an existing --destfile, which silently doubles everything +# on a second run. +rm -f "$MERGED" +"$JAVA" -jar "$CLI" merge "${EC_FILES[@]}" --destfile "$MERGED" + +# Kotlin and Java classes land in separate trees; both belong in the report, +# and both must be the uninstrumented ones. +CLASS_ARGS=() +for d in "$REPO/wallet/build/tmp/kotlin-classes/$VARIANT" \ + "$REPO/wallet/build/intermediates/javac/$VARIANT/classes"; do + [ -d "$d" ] && CLASS_ARGS+=(--classfiles "$d") +done +[ "${#CLASS_ARGS[@]}" -gt 0 ] || { echo "no class files for variant $VARIANT" >&2; exit 1; } + +"$JAVA" -jar "$CLI" report "$MERGED" \ + "${CLASS_ARGS[@]}" \ + --sourcefiles "$REPO/wallet/src/main/java" \ + --sourcefiles "$REPO/taler-kotlin-android/src/main/java" \ + --html "$OUT_DIR/html" \ + --xml "$OUT_DIR/coverage.xml" \ + --name "Taler wallet simulator ($VARIANT)" + +python3 - "$OUT_DIR/coverage.xml" <<'PY' +import sys, xml.etree.ElementTree as ET +root = ET.parse(sys.argv[1]).getroot() +print() +for counter in root.findall("counter"): + t = counter.get("type") + covered, missed = int(counter.get("covered")), int(counter.get("missed")) + total = covered + missed + if total: + print(f"{t.lower():12} {covered:7}/{total:<7} {100 * covered / total:5.1f}%") +PY +echo +echo "report: $OUT_DIR/html/index.html" >&2 diff --git a/wallet-simulator/coverage/validate_ec.py b/wallet-simulator/coverage/validate_ec.py @@ -0,0 +1,131 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Print the .ec files that are complete execution data, skip the rest. + +A dump whose app was killed while writing leaves a truncated file, and jacoco's +`merge` aborts on the first one it cannot read -- so one bad file out of a +thousand loses a whole campaign's coverage. Rather than merge in batches and +guess, this walks each file's block structure once and keeps only the files +that end on a block boundary. + + python3 validate_ec.py <dir> [--quiet] # one good path per line on stdout + +The format is org.jacoco.core.data.ExecutionDataWriter's: a header block, then +session-info and execution-data blocks, with Java DataOutput encodings and +jacoco's own var-int for array lengths. +""" + +from __future__ import annotations + +import sys +from pathlib import Path + +BLOCK_HEADER = 0x01 +BLOCK_SESSIONINFO = 0x10 +BLOCK_EXECUTIONDATA = 0x11 +MAGIC = 0xC0C0 + + +class Truncated(Exception): + pass + + +class Reader: + def __init__(self, data: bytes) -> None: + self.data = data + self.pos = 0 + + def take(self, n: int) -> bytes: + if self.pos + n > len(self.data): + raise Truncated(f"wanted {n} bytes at {self.pos} of {len(self.data)}") + out = self.data[self.pos:self.pos + n] + self.pos += n + return out + + def u8(self) -> int: + return self.take(1)[0] + + def u16(self) -> int: + return int.from_bytes(self.take(2), "big") + + def u64(self) -> int: + return int.from_bytes(self.take(8), "big") + + def utf(self) -> bytes: + return self.take(self.u16()) + + def var_int(self) -> int: + value, shift = 0, 0 + while True: + b = self.u8() + value |= (b & 0x7F) << shift + if not b & 0x80: + return value + shift += 7 + + def boolean_array(self) -> None: + bits = self.var_int() + self.take((bits + 7) // 8) + + +def complete(path: Path) -> bool: + """Whether this file is execution data all the way to its last byte.""" + r = Reader(path.read_bytes()) + if not r.data: + return False + try: + while r.pos < len(r.data): + block = r.u8() + if block == BLOCK_HEADER: + if r.u16() != MAGIC: + return False + r.u16() # format version + elif block == BLOCK_SESSIONINFO: + r.utf() + r.u64() # start + r.u64() # dump + elif block == BLOCK_EXECUTIONDATA: + r.u64() # class id + r.utf() # class name + r.boolean_array() + else: + return False + except Truncated: + return False + return True + + +def main() -> int: + if len(sys.argv) < 2: + print(__doc__, file=sys.stderr) + return 2 + quiet = "--quiet" in sys.argv + files = sorted(Path(sys.argv[1]).rglob("*.ec")) + good = [] + for f in files: + if complete(f): + good.append(f) + elif not quiet: + print(f"skipping incomplete {f} ({f.stat().st_size} bytes)", + file=sys.stderr) + if not quiet: + print(f"{len(good)} of {len(files)} execution data files are complete", + file=sys.stderr) + for f in good: + print(f) + return 0 if good else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/wallet-simulator/driver/campaign.py b/wallet-simulator/driver/campaign.py @@ -0,0 +1,192 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Run scenarios and explorations across several emulators at once. + +Each worker has its own emulator, its own bank customer and its own CLI peer +wallet, so they only share the Taler services. Work is split round-robin and +the per-worker summaries are merged into one report. + + python3 campaign.py suite # every scenario, 4 ways + python3 campaign.py suite --workers 2 + python3 campaign.py explore --steps 150 # one exploration per worker + python3 campaign.py both +""" + +from __future__ import annotations + +import argparse +import json +import os +import subprocess +import time +from collections.abc import Iterable +from pathlib import Path + +import oracles +import suite +from device import Device + +OUT = Path("/opt/taler-sim/run/out") +COVERAGE = Path("/opt/taler-sim/run/coverage") +HERE = Path(__file__).resolve().parent + + +def online_workers(limit: int) -> list[int]: + """Workers whose emulator is actually up.""" + listed = subprocess.run( + ["/opt/android-sdk/platform-tools/adb", "devices"], + capture_output=True, text=True, timeout=60, + ).stdout + found = [] + for worker in range(limit): + if f"emulator-{5554 + 2 * worker}\tdevice" in listed: + found.append(worker) + return found + + +def split(names: list[str], workers: list[int]) -> dict[int, list[str]]: + buckets: dict[int, list[str]] = {w: [] for w in workers} + for i, name in enumerate(names): + buckets[workers[i % len(workers)]].append(name) + return buckets + + +def launch(worker: int, args: list[str], tag: str) -> tuple[int, subprocess.Popen, Path]: + env = dict(os.environ, SIM_WORKER=str(worker)) + log = OUT / f"{tag}-w{worker}.log" + log.parent.mkdir(parents=True, exist_ok=True) + handle = log.open("w") + proc = subprocess.Popen(args, cwd=HERE, env=env, stdout=handle, + stderr=subprocess.STDOUT, text=True) + return worker, proc, log + + +def wait_all(jobs: list[tuple[int, subprocess.Popen, Path]], poll: int = 20) -> None: + pending = {w: (p, log) for w, p, log in jobs} + while pending: + for worker in list(pending): + proc, log = pending[worker] + if proc.poll() is not None: + print(f"worker {worker} finished with code {proc.returncode} ({log})") + del pending[worker] + if pending: + time.sleep(poll) + + +def collect(stamp_after: float, workers: Iterable[int] | None = None) -> dict: + """Merge the per-worker suite summaries this run produced. + + Filtered by worker as well as by time: a scenario run by hand on a spare + emulator writes a summary into the same directory, and round 20's tally + swallowed three such runs -- 147 "scenarios", and findings from a patched + APK reported against an unpatched round. + """ + wanted = None if workers is None else {f"suite-w{w}-" for w in workers} + merged: dict = {"scenarios": [], "findings": {}} + for path in sorted(OUT.glob("suite-w*-summary.json")): + if path.stat().st_mtime < stamp_after: + continue + if wanted is not None and not any(path.name.startswith(p) for p in wanted): + continue + data = json.loads(path.read_text()) + merged["scenarios"] += data.get("scenarios", []) + for f in data.get("findings", []): + merged["findings"][f["fingerprint"]] = f + return merged + + +def report(merged: dict) -> None: + rows = merged["scenarios"] + ok = [r for r in rows if r.get("status") == "ok"] + broken = [r for r in rows if r.get("status") != "ok"] + print(f"\n{len(rows)} scenarios: {len(ok)} ok, {len(broken)} driver errors") + for r in sorted(rows, key=lambda r: r.get("scenario") or ""): + flag = " " if r.get("status") == "ok" else "!" + print(f" {flag} {r.get('scenario'):26} {r.get('serious', 0)} serious, " + f"{len(r.get('findings', []))} findings, {r.get('seconds')}s") + if r.get("error"): + print(f" error: {r['error'][:200]}") + # oracles.INFORMATIONAL, the same rule the session and the suite use: a + # withdrawal the suite leaves pending on purpose is not a defect. + serious = [f for f in merged["findings"].values() + if f["kind"] not in oracles.INFORMATIONAL] + print(f"\nfindings: {len(merged['findings'])} distinct, {len(serious)} serious") + for f in merged["findings"].values(): + mark = "***" if f["kind"] not in oracles.INFORMATIONAL else " " + print(f" {mark} [{f['kind']}] {f['fingerprint']} {f['detail'][:170]}") + + +def dump_coverage(workers: list[int], tag: str) -> None: + import coverage as coverage_mod + for worker in workers: + dev = Device(f"emulator-{5554 + 2 * worker}") + try: + path = coverage_mod.dump(dev, COVERAGE / f"{tag}-w{worker}.ec", name=f"{tag}.ec") + print(f"coverage worker {worker}: {path} ({path.stat().st_size} bytes)") + except Exception as e: + print(f"coverage worker {worker} failed: {e}") + + +def main() -> int: + ap = argparse.ArgumentParser(description=__doc__) + ap.add_argument("mode", choices=["suite", "explore", "both"]) + ap.add_argument("--workers", type=int, default=4) + ap.add_argument("--steps", type=int, default=120, help="explore steps per worker") + ap.add_argument("--seed", type=int, default=100) + ap.add_argument("--only", nargs="*", help="scenario names (suite mode)") + ap.add_argument("--tag", default=None) + args = ap.parse_args() + + workers = online_workers(args.workers) + if not workers: + print("no emulators online") + return 1 + tag = args.tag or f"{args.mode}-{int(time.time())}" + started = time.time() + print(f"workers online: {workers} tag: {tag}") + + if args.mode in ("suite", "both"): + names = args.only or list(suite.REGISTRY) + buckets = split(names, workers) + jobs = [] + for worker, bucket in buckets.items(): + if not bucket: + continue + print(f"worker {worker}: {len(bucket)} scenarios -> {bucket}") + jobs.append(launch(worker, ["python3", "-u", "suite.py", *bucket], + f"{tag}-suite")) + wait_all(jobs) + dump_coverage(list(buckets), f"{tag}-suite") + report(collect(started, buckets)) + + if args.mode in ("explore", "both"): + started = time.time() + jobs = [] + for worker in workers: + seed = args.seed + worker + print(f"worker {worker}: explore {args.steps} steps, seed {seed}") + jobs.append(launch(worker, ["python3", "-u", "explore.py", + str(args.steps), str(seed)], f"{tag}-explore")) + wait_all(jobs) + dump_coverage(workers, f"{tag}-explore") + for worker in workers: + log = OUT / f"{tag}-explore-w{worker}.log" + if log.exists(): + print(f"\n--- worker {worker} ---") + print(log.read_text()[-1500:]) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/driver/cli.py b/wallet-simulator/driver/cli.py @@ -0,0 +1,254 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""taler-wallet-cli as the wallet's peer. + +Peer-to-peer payments need a second wallet. A command-line wallet on the host +is far cheaper than a second emulator and just as real from the app's point of +view: it holds its own coins at the same exchange and exchanges the same URIs. +""" + +from __future__ import annotations + +import json +import os +import re +import subprocess +import time +from pathlib import Path + +BINARY = "taler-wallet-cli" +URI_RE = re.compile(r"taler(?:\+http)?://[^\s'\"]+") + + +class CliWallet: + def __init__(self, db: str | Path | None = None, timeout: int = 300): + # One database per worker: the peer wallet is state, like the app's. + if db is None: + worker = os.environ.get("SIM_WORKER", "0") + # The extension picks the backend, and this build no longer has the + # JSON/in-memory one ("memory backend not supported"). + db = f"/opt/taler-sim/run/cli-wallet-{worker}.sqlite3" + self.db = str(db) + self.timeout = timeout + + def run(self, *args: str, check: bool = True) -> str: + proc = subprocess.run( + [BINARY, "--wallet-db", self.db, "--non-interactive", *args], + capture_output=True, text=True, timeout=self.timeout, + ) + if check and proc.returncode != 0: + raise RuntimeError( + f"{BINARY} {' '.join(args)} failed ({proc.returncode}): " + f"{(proc.stderr or proc.stdout)[-600:]}" + ) + return proc.stdout + proc.stderr + + def reset(self) -> None: + for suffix in ("", "-wal", "-shm"): + Path(self.db + suffix).unlink(missing_ok=True) + + def add_exchange(self, exchange: str) -> str: + """Teach the peer wallet about an exchange and accept its terms.""" + out = self.run("exchanges", "add", exchange, check=False) + return out + self.run("exchanges", "accept-tos", exchange, check=False) + + def fund_via_bank(self, bank, user: tuple[str, str], amount: str, + exchange: str, timeout: int = 150) -> str: + """Fund the peer wallet with a bank-integrated withdrawal. + + `withdraw --exchange --amount` would create a *manual* withdrawal that + waits for a wire transfer nobody is going to make, and `withdraw --uri` + does not always get as far as choosing an exchange, which leaves the + bank refusing to confirm ("Cannot confirm an unselected withdrawal"). + So the exchange is selected through the same wallet-core call the app + uses, and only then is the operation confirmed in the bank. + """ + self.add_exchange(exchange) + op = bank.create_withdrawal(*user, amount) + accepted = self.api("acceptBankIntegratedWithdrawal", { + "talerWithdrawUri": op["taler_withdraw_uri"], + "exchangeBaseUrl": exchange, + }) + if "master public key" in json.dumps(accepted): + # The stack was rebuilt since this wallet last ran, so its memory + # of the exchange is stale; start it over rather than carrying a + # wallet that refuses to talk to the only exchange there is. + self.reset() + self.add_exchange(exchange) + op = bank.create_withdrawal(*user, amount) + accepted = self.api("acceptBankIntegratedWithdrawal", { + "talerWithdrawUri": op["taler_withdraw_uri"], + "exchangeBaseUrl": exchange, + }) + result = accepted.get("result") or {} + transaction = result.get("transactionId") + if not transaction: + raise RuntimeError(f"the peer wallet could not accept the withdrawal: " + f"{str(accepted)[:400]}") + # The CLI is not a daemon: each invocation starts wallet-core, answers + # one request and exits, so the task that tells the bank which exchange + # was chosen only runs while something is waiting on the transaction. + # "--state pending" is useless for that -- the transaction is already + # pending, so the wait returns before any task has run. "pending/idle" + # is the state that means the wallet has done all it can and is now + # waiting on the bank. + self.pump(transaction, "pending/idle", 90) + deadline = time.time() + 90 + while time.time() < deadline: + if bank.withdrawal_status(op["withdrawal_id"])["status"] == "selected": + break + self.pump(transaction, "pending/idle", 30) + time.sleep(2) + else: + raise RuntimeError(f"the bank never saw an exchange selected for {amount}") + bank.confirm_withdrawal(*user, op["withdrawal_id"]) + # Pump the task loop again so the coins are actually withdrawn. + self.pump(transaction, "final", 120) + return self.balance() + + def pump(self, transaction: str, state: str = "pending/idle", + timeout: int = 60) -> str: + """Run wallet-core until `transaction` reaches `state`. + + This is the only way to make the CLI do background work: it processes + tasks while a wait is outstanding and exits as soon as it is over. + """ + return self.run("wait-tx", "--state", state, + "--timeout", f"{timeout}s", transaction, check=False) + + def balance(self) -> str: + return self.run("balance") + + def withdraw(self, exchange: str, amount: str) -> str: + """Fund the peer wallet straight from the exchange, no bank UI needed.""" + return self.run("withdraw", "--exchange", exchange, "--amount", amount, + "--wait", "--timeout", "120s") + + def accept_tos(self, exchange: str) -> str: + return self.run("exchanges", "accept-tos", exchange, check=False) + + def peer_send(self, amount: str, exchange: str, + summary: str = "from the simulator's peer") -> str: + """Push money to the app; returns the taler://pay-push URI.""" + out = self.run_fresh_on_key_change( + exchange, "peer-send", "--exchange", exchange, + "--summary", summary, amount) + return self._uri(out, "pay-push") + + def peer_request(self, amount: str, + summary: str = "invoice from the simulator's peer", + exchange: str | None = None) -> str: + """Invoice the app; returns the taler://pay-pull URI.""" + if exchange is None: + out = self.run("peer-request", "--summary", summary, amount) + else: + out = self.run_fresh_on_key_change( + exchange, "peer-request", "--summary", summary, amount) + return self._uri(out, "pay-pull") + + def send_mailbox_message(self, address: str, taler_uri: str, + mailbox_base: str = "http://127.0.0.1:11000/", + petname: str = "The app under test") -> dict: + """Put a real message in another wallet's mailbox. + + The app has no caller for `sendTalerUriMailboxMessage` -- the manager + method exists and nothing invokes it -- so the sender has to be this + wallet. The envelope is encrypted for the recipient's address, which + is why a hand-made POST to the service cannot stand in for it: the app + reads an unreadable message and discards it without a word. + """ + contact = { + "alias": "simulator@example.com", + "aliasType": "email", + "mailboxBaseUri": mailbox_base, + "mailboxAddress": address, + "source": "local", + "petname": petname, + "originMailboxBaseUrl": mailbox_base, + "downloadedAt": {"t_s": int(time.time())}, + "talerUri": "", + "transactionId": "", + } + return self.api("sendTalerUriMailboxMessage", + {"contact": contact, "talerUri": taler_uri}) + + def run_fresh_on_key_change(self, exchange: str, *args: str) -> str: + """Run a command, starting the wallet over if its exchange moved on. + + Every stack start gives the exchange a new master key, and a wallet + that remembers the old one refuses every operation with "the exchange + changed its master public key" (7066). Funding already coped with + this; the peer commands have to as well, because a scenario may be the + first thing to touch this wallet after a restart. + """ + try: + return self.run(*args) + except RuntimeError as e: + if "master public key" not in str(e): + raise + self.reset() + self.add_exchange(exchange) + return self.run(*args) + + def _uri(self, output: str, kind: str) -> str: + for match in URI_RE.finditer(output): + if kind in match.group(0): + return match.group(0).rstrip(".,)") + raise RuntimeError(f"no {kind} URI in output: {output[-600:]}") + + def api(self, operation: str, payload: dict | None = None) -> dict: + """Call wallet-core directly, bypassing the CLI's prompts. + + `handle-uri` asks whether to accept an incoming payment, and neither + `-y` nor the global `--non-interactive` answers that question off a + terminal, so the peer wallet drives the two-step API itself. + """ + out = self.run("advanced", "api", operation, + json.dumps(payload or {}), check=False) + start = out.find("{") + if start < 0: + raise RuntimeError(f"{operation}: no JSON in {out[-400:]}") + try: + # The CLI prints its own lines after the response, so only the + # first JSON value is ours. + parsed, _ = json.JSONDecoder().raw_decode(out[start:]) + return parsed + except json.JSONDecodeError as e: + raise RuntimeError(f"{operation}: {e}; output was {out[-400:]}") from None + + def accept_push(self, uri: str) -> dict: + """Accept an incoming push payment the app sent.""" + prepared = self.api("preparePeerPushCredit", {"talerUri": uri}) + result = prepared.get("result", {}) + transaction_id = result.get("transactionId") + if not transaction_id: + raise RuntimeError(f"preparePeerPushCredit gave no transaction: {prepared}") + return self.api("confirmPeerPushCredit", {"transactionId": transaction_id}) + + def pay_pull(self, uri: str) -> dict: + """Pay an invoice the app issued.""" + prepared = self.api("preparePeerPullDebit", {"talerUri": uri}) + result = prepared.get("result", {}) + transaction_id = result.get("transactionId") + if not transaction_id: + raise RuntimeError(f"preparePeerPullDebit gave no transaction: {prepared}") + return self.api("confirmPeerPullDebit", {"transactionId": transaction_id}) + + def handle_uri(self, uri: str) -> str: + """Hand a URI to the peer wallet, answering its questions. + + Prefer accept_push/pay_pull for peer payments; this stays for URIs that + need no confirmation. + """ + return self.run("handle-uri", "-y", uri) diff --git a/wallet-simulator/driver/coverage.py b/wallet-simulator/driver/coverage.py @@ -0,0 +1,83 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Pull JaCoCo execution data out of a running wallet. + +The simulator drives the app from outside, so AGP's own instrumented-test +coverage plumbing never runs. Instead the "sim" build type carries the JaCoCo +agent plus the SimHooks receiver, and this module asks the agent for what it +has collected so far. Data accumulates in the live process, so dumping is +cheap and can be done between episodes; the file only has to be collected +before the process dies. +""" + +from __future__ import annotations + +import subprocess +from pathlib import Path + +from device import ADB, PKG, Device + +RECEIVER = f"{PKG}/net.taler.wallet.sim.SimHooks" +ACTION = "net.taler.wallet.sim.DUMP_COVERAGE" + + +# Every jacoco .exec stream starts with a block header and this magic. +MAGIC = b"\x01\xc0\xc0" + + +def dump(dev: Device, out_path: str | Path, name: str = "coverage.ec") -> Path: + """Dump coverage from the app and copy it off the device. + + Raises if the agent is missing, which means the APK under test was not + built from the "sim" build type. + """ + out = Path(out_path) + out.parent.mkdir(parents=True, exist_ok=True) + res = dev.shell(f"am broadcast -a {ACTION} -n {RECEIVER} --es file {name}") + if "Broadcast completed" not in res: + raise RuntimeError(f"coverage broadcast not delivered: {res.strip()}") + # run-as is the only way into the app's private files; the sim build is + # debuggable, so it is allowed. + data = subprocess.run( + [ADB, "-s", dev.serial, "exec-out", "run-as", PKG, "cat", f"files/{name}"], + capture_output=True, timeout=120, + ) + if not data.stdout: + raise RuntimeError( + f"no coverage data (stderr: {data.stderr.decode(errors='replace').strip()}); " + "is this the fdroidSim APK?" + ) + # A dump whose process was killed while writing (the before-wipe one, as + # often as not) leaves a truncated file, and jacoco's `merge` aborts on the + # first one it cannot read -- losing every other file's data with it. So a + # dump that does not at least begin like execution data never gets the + # final name. + if not data.stdout.startswith(MAGIC): + raise RuntimeError( + f"coverage data for {name} is not jacoco execution data " + f"({len(data.stdout)} bytes, starts {data.stdout[:8]!r}); " + "the app was probably killed mid-dump" + ) + part = out.with_suffix(out.suffix + ".part") + part.write_bytes(data.stdout) + part.replace(out) + return out + + +if __name__ == "__main__": + import sys + d = Device(sys.argv[2] if len(sys.argv) > 2 else "emulator-5554") + target = sys.argv[1] if len(sys.argv) > 1 else "/opt/taler-sim/run/coverage/manual.ec" + p = dump(d, target) + print(f"{p} ({p.stat().st_size} bytes)") diff --git a/wallet-simulator/driver/dbprobe.py b/wallet-simulator/driver/dbprobe.py @@ -0,0 +1,106 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Read the wallet's SQLite database by copying it off the device. + +wallet-core runs with `useNativeDb`, so transaction state lives in a plain +SQLite file. The app's own SELinux domain may not exec /system/bin/sqlite3, +so the file (and its write-ahead log) are copied out with `run-as ... cat` and +queried on the host. The copy doubles as evidence for a finding. + + python3 dbprobe.py tables + python3 dbprobe.py emulator-5556 schema transactions + python3 dbprobe.py sql "select * from transactions limit 5" +""" + +from __future__ import annotations + +import sqlite3 +import subprocess +import sys +import tempfile +from pathlib import Path + +from device import ADB, PKG, Device + +DB_NAME = "talerwalletdb.sqlite3" + + +def pull(dev: Device, into: Path | None = None) -> Path: + """Copy the wallet database (plus its WAL) off the device.""" + target_dir = into or Path(tempfile.mkdtemp(prefix="walletdb-")) + target_dir.mkdir(parents=True, exist_ok=True) + db = target_dir / DB_NAME + for suffix in ("", "-wal", "-shm"): + data = subprocess.run( + [ADB, "-s", dev.serial, "exec-out", "run-as", PKG, "cat", + f"files/{DB_NAME}{suffix}"], + capture_output=True, timeout=180, + ).stdout + if data: + (target_dir / f"{DB_NAME}{suffix}").write_bytes(data) + elif suffix == "": + raise RuntimeError("could not read the wallet database off the device") + return db + + +def connect(db: Path) -> sqlite3.Connection: + conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True) + conn.row_factory = sqlite3.Row + return conn + + +def tables(db: Path) -> list[str]: + with connect(db) as conn: + return [r[0] for r in conn.execute( + "select name from sqlite_master where type='table' order by name")] + + +def columns(db: Path, table: str) -> list[str]: + with connect(db) as conn: + return [r[1] for r in conn.execute(f"pragma table_info({table})")] + + +def has_native_schema(db: Path) -> bool: + """Whether this database holds the native wallet schema. + + A wallet that has not been migrated keeps everything in the IndexedDB + emulation tables (`object_data` and friends), where none of the oracles' + queries apply. Asking first is cheaper than catching "no such table" on + every query, and it distinguishes "nothing to look at" from "the probe + broke". + """ + return "operation_retries" in set(tables(db)) + + +def rows(db: Path, sql: str, limit: int = 50) -> list[sqlite3.Row]: + with connect(db) as conn: + return list(conn.execute(sql))[:limit] + + +if __name__ == "__main__": + args = sys.argv[1:] + serial = "emulator-5554" + if args and args[0].startswith("emulator-"): + serial = args.pop(0) + database = pull(Device(serial)) + print(f"# {database}") + if not args or args[0] == "tables": + for name in tables(database): + print(name) + elif args[0] == "schema": + for name in args[1:] or tables(database): + print(f"{name}: {', '.join(columns(database, name))}") + elif args[0] == "sql": + for row in rows(database, args[1]): + print(dict(row)) diff --git a/wallet-simulator/driver/device.py b/wallet-simulator/driver/device.py @@ -0,0 +1,515 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Thin adb wrapper: one emulator, seen through the accessibility tree. + +The wallet is almost entirely Jetpack Compose and carries no testTags, so the +driver addresses widgets through the semantics the app already exposes: text, +content-description and bounds. Everything here is therefore black-box; the +only app-specific knowledge is the package name. +""" + +from __future__ import annotations + +import re +import shlex +import subprocess +import time +import xml.etree.ElementTree as ET +from dataclasses import dataclass, field +from typing import Iterable, Optional + +ADB = "/opt/android-sdk/platform-tools/adb" +PKG = "net.taler.wallet.fdroid.debug" +ACTIVITY = f"{PKG}/net.taler.wallet.main.MainActivity" + +BOUNDS_RE = re.compile(r"\[(-?\d+),(-?\d+)\]\[(-?\d+),(-?\d+)\]") + + +@dataclass(frozen=True) +class Node: + """One node of the accessibility tree, flattened.""" + + cls: str + text: str + desc: str + rid: str + clickable: bool + scrollable: bool + editable: bool + checkable: bool + checked: bool + enabled: bool + bounds: tuple[int, int, int, int] + + @property + def center(self) -> tuple[int, int]: + x1, y1, x2, y2 = self.bounds + return (x1 + x2) // 2, (y1 + y2) // 2 + + @property + def label(self) -> str: + return self.text or self.desc + + @property + def area(self) -> int: + x1, y1, x2, y2 = self.bounds + return max(0, x2 - x1) * max(0, y2 - y1) + + def __str__(self) -> str: + kind = self.cls.rsplit(".", 1)[-1] + flags = "".join( + f for f, on in (("C", self.clickable), ("S", self.scrollable), + ("E", self.editable), ("x", not self.enabled)) + if on + ) + return f"{kind}{'[' + flags + ']' if flags else ''} {self.label!r} @{self.center}" + + +@dataclass +class Screen: + """A parsed UI dump plus the cheap derived views the driver needs.""" + + nodes: list[Node] = field(default_factory=list) + activity: str = "" + + def labelled(self) -> list[Node]: + return [n for n in self.nodes if n.label.strip()] + + def tappable(self) -> list[Node]: + """Clickable nodes, plus labelled leaves (Compose often marks only an + ancestor clickable, so a text node's own box is the better tap target).""" + out = [n for n in self.nodes if n.clickable and n.enabled and n.area > 0] + seen = {n.bounds for n in out} + for n in self.labelled(): + if n.bounds not in seen and n.area > 0: + out.append(n) + seen.add(n.bounds) + return out + + def editable(self) -> list[Node]: + return [n for n in self.nodes if n.editable and n.enabled] + + def texts(self) -> list[str]: + return [n.label.strip() for n in self.labelled()] + + def tap_target(self, node: Node) -> Node: + """The node that actually reacts when the user aims at `node`. + + Three shapes occur in this app: the labelled node is itself clickable; + the label sits inside a clickable ancestor (ordinary Compose); or the + label is a separate TextView *underneath* an unlabelled Button, which + is how the main screen's Send/Request/Withdraw/Deposit buttons are + built. The last case needs a neighbour search, not a containment + search, or the tap lands on nothing at all. + """ + if node.clickable and node.enabled: + return node + cx, cy = node.center + clickables = [n for n in self.nodes if n.clickable and n.enabled and n.area > 0] + containing = [n for n in clickables + if n.bounds[0] <= cx <= n.bounds[2] + and n.bounds[1] <= cy <= n.bounds[3]] + if containing: + return min(containing, key=lambda n: n.area) + # A clickable node directly above or below, overlapping horizontally. + x1, y1, x2, y2 = node.bounds + + def neighbour_distance(n: Node) -> Optional[int]: + if n.bounds[2] < x1 or n.bounds[0] > x2: + return None + if n.bounds[3] <= y1: + return y1 - n.bounds[3] + if n.bounds[1] >= y2: + return n.bounds[1] - y2 + return 0 + + scored = [(d, n) for n in clickables + if (d := neighbour_distance(n)) is not None and d <= 120] + if scored: + return min(scored, key=lambda row: row[0])[1] + return node + + def unnamed_clickables(self) -> list[Node]: + """Clickable nodes a screen reader cannot announce. + + A clickable node with no text of its own is fine when the label sits + *inside* it: Compose merges the semantics and TalkBack reads the child. + What is not fine is a label that is only a neighbour, which is how the + main screen's action buttons are built. Only the latter are returned. + """ + labelled = [n for n in self.nodes if n.label.strip() and n.area > 0] + out = [] + for node in self.nodes: + if not (node.clickable and node.enabled and node.area > 0): + continue + if node.label.strip(): + continue + x1, y1, x2, y2 = node.bounds + if x2 - x1 >= 600 and y2 - y1 >= 600: + continue # a full-screen container, not a control + contains_label = any( + x1 <= n.bounds[0] and y1 <= n.bounds[1] + and n.bounds[2] <= x2 and n.bounds[3] <= y2 + for n in labelled + ) + if not contains_label: + out.append(node) + return out + + def find(self, pattern: str) -> Optional[Node]: + rx = re.compile(pattern, re.I) + for n in self.nodes: + if n.label and rx.search(n.label): + return n + return None + + def signature(self) -> str: + """Stable-ish identity of a screen, for novelty tracking and oracles. + + Only the set of labels and the shape of the interactive nodes go in, so + the same screen with a different balance still matches itself. + """ + labels = sorted({re.sub(r"\d+[.,]?\d*", "#", t) for t in self.texts()}) + shape = f"{len(self.tappable())}/{len(self.editable())}" + return f"{self.activity}|{shape}|{'|'.join(labels)}" + + def __str__(self) -> str: + return "\n".join(str(n) for n in self.labelled()) + + +class Device: + def __init__(self, serial: str = "emulator-5554", pkg: str = PKG): + self.serial = serial + self.pkg = pkg + self._sdk_int: Optional[int] = None + self._size: Optional[tuple[int, int]] = None + + # -- plumbing --------------------------------------------------------- + + def adb(self, *args: str, timeout: int = 60, check: bool = True) -> str: + proc = subprocess.run( + [ADB, "-s", self.serial, *args], + capture_output=True, text=True, timeout=timeout, + ) + if check and proc.returncode != 0: + raise RuntimeError(f"adb {' '.join(args)} failed: {proc.stderr.strip()}") + return proc.stdout + + def shell(self, cmd: str, timeout: int = 60, check: bool = True) -> str: + return self.adb("shell", cmd, timeout=timeout, check=check) + + # -- observation ------------------------------------------------------ + + @property + def sdk_int(self) -> int: + """The device's API level, read once. + + Scenarios need this because the *harness* has version floors of its + own: per-app language is API 33+, for instance, so a scenario that + changes it on an older device is testing adb, not the wallet. + """ + if self._sdk_int is None: + out = self.shell("getprop ro.build.version.sdk", check=False) + try: + self._sdk_int = int(out.strip() or 0) + except ValueError: + self._sdk_int = 0 + return self._sdk_int + + def current_activity(self) -> str: + out = self.shell("dumpsys activity activities | grep -m1 ResumedActivity", check=False) + m = re.search(r"([A-Za-z0-9_.]+/[A-Za-z0-9_.]+)", out) + return m.group(1) if m else "" + + def dump(self, retries: int = 3) -> Screen: + """Read the accessibility tree. + + uiautomator fails while the UI is still settling ("could not get idle + state"), which is routine right after a tap, so this retries. + """ + xml = "" + for attempt in range(retries): + out = self.shell("uiautomator dump /sdcard/ui.xml", check=False) + if "dumped" in out.lower(): + xml = self.adb("exec-out", "cat", "/sdcard/ui.xml", check=False) + if xml.lstrip().startswith("<?xml"): + break + time.sleep(1 + attempt) + if not xml.lstrip().startswith("<?xml"): + return Screen(activity=self.current_activity()) + return self._parse(xml) + + def _parse(self, xml: str) -> Screen: + screen = Screen(activity=self.current_activity()) + try: + root = ET.fromstring(xml) + except ET.ParseError: + return screen + for el in root.iter("node"): + m = BOUNDS_RE.match(el.get("bounds", "")) + if not m: + continue + cls = el.get("class", "") + screen.nodes.append(Node( + cls=cls, + text=el.get("text", ""), + desc=el.get("content-desc", ""), + rid=el.get("resource-id", ""), + clickable=el.get("clickable") == "true", + scrollable=el.get("scrollable") == "true", + editable=el.get("class", "").endswith("EditText") + or el.get("focusable") == "true" and "EditText" in cls, + checkable=el.get("checkable") == "true", + checked=el.get("checked") == "true", + enabled=el.get("enabled") == "true", + bounds=tuple(int(v) for v in m.groups()), # type: ignore[arg-type] + )) + return screen + + def screenshot(self, path: str) -> None: + png = subprocess.run([ADB, "-s", self.serial, "exec-out", "screencap", "-p"], + capture_output=True, timeout=60).stdout + with open(path, "wb") as f: + f.write(png) + + def logcat(self, clear: bool = False, lines: Optional[int] = None) -> str: + """Read the log, or clear it. + + `lines` bounds the read to the most recent entries. Reading the whole + buffer costs seconds once it has filled up, which is far too slow to + do after every action in an exploration. + """ + if clear: + self.adb("logcat", "-c", check=False) + return "" + args = ["logcat", "-d"] + if lines: + args += ["-t", str(lines)] + return self.adb(*args, timeout=120, check=False) + + # -- acting ----------------------------------------------------------- + + def tap(self, x: int, y: int) -> None: + self.shell(f"input tap {x} {y}") + + def tap_node(self, node: Node, screen: Optional[Screen] = None) -> None: + """Tap a node, or whatever clickable element really serves it.""" + target = screen.tap_target(node) if screen is not None else node + x, y = target.center + self.tap(x, y) + + def long_press(self, node: Node, ms: int = 800) -> None: + """Hold a finger on a node long enough for a long-press gesture. + + A zero-distance `input swipe` is what works: Compose's + `combinedClickable` sees it as a press that never moved. Moving even + two pixels turns it into a drag and the long press is cancelled, and + two separate `input motionevent` calls do not form one gesture at all + -- both were tried on a live transaction row, and only this registers. + """ + x, y = node.center + self.shell(f"input swipe {x} {y} {x} {y} {ms}") + + def type_text(self, s: str) -> None: + """Type into the focused field. + + "input text" maps each character through a KeyCharacterMap and throws + NullPointerException on anything it cannot map, so non-ASCII text goes + through the clipboard instead (which needs the sim build's SimHooks). + """ + if not s: + return + if not s.isascii() or len(s) > 200: + # Long strings are also pasted: "input text" sends them one + # keystroke at a time, which takes minutes for a few thousand + # characters and tests nothing extra. + self.paste_text(s) + return + # Shell-quote one chunk at a time; a space has to be a keyevent because + # "input text" splits its arguments on it. + for chunk in re.split(r"( )", s): + if not chunk: + continue + if chunk == " ": + self.shell("input keyevent 62") + else: + self.shell(f"input text {shlex.quote(chunk)}", check=False) + + def paste_text(self, s: str) -> None: + """Put text on the clipboard through SimHooks, then paste it.""" + res = self.shell( + f"am broadcast -a net.taler.wallet.sim.SET_CLIPBOARD " + f"-n {self.pkg}/net.taler.wallet.sim.SimHooks --es text {shlex.quote(s)}", + check=False, + ) + if "Broadcast completed" not in res: + raise RuntimeError( + f"clipboard hook unavailable (is this the fdroidSim APK?): {res.strip()[:200]}" + ) + self.shell("input keyevent KEYCODE_PASTE") + + def key(self, keycode: str) -> None: + self.shell(f"input keyevent {keycode}") + + def back(self) -> None: + self.key("KEYCODE_BACK") + + def size(self) -> tuple[int, int]: + """Current display size in pixels, cached per orientation.""" + if self._size is None: + out = self.shell("wm size") + m = re.search(r"Override size: (\d+)x(\d+)", out) or \ + re.search(r"Physical size: (\d+)x(\d+)", out) + w, h = (int(m.group(1)), int(m.group(2))) if m else (1080, 2400) + # wm size always reports the natural orientation, so swap when the + # device is rotated. + rotation = self.shell("settings get system user_rotation", + check=False).strip() + if rotation in ("1", "3"): + w, h = h, w + self._size = (w, h) + return self._size + + def scroll(self, down: bool = True, screen: Optional[Screen] = None) -> None: + """Swipe inside the scrollable area of the current screen. + + Fixed coordinates break as soon as the device is rotated or the layout + changes, so the gesture is derived from the scrollable node when there + is one and from the display size otherwise. + """ + width, height = self.size() + area = None + if screen is not None: + scrollables = [n for n in screen.nodes if n.scrollable and n.area > 0] + if scrollables: + area = max(scrollables, key=lambda n: n.area).bounds + if area is None: + area = (0, height // 8, width, height - height // 8) + x1, y1, x2, y2 = area + x = (x1 + x2) // 2 + near, far = y1 + (y2 - y1) // 6, y2 - (y2 - y1) // 6 + start, end = (far, near) if down else (near, far) + # 800 ms makes this a drag rather than a fling: a fling carries on + # under its own momentum and can scroll a whole row past the next dump. + self.shell(f"input swipe {x} {start} {x} {end} 800") + + def portrait(self) -> None: + """Undo any rotation left behind by an earlier episode. + + user_rotation is a system setting, so "pm clear" on the app does not + reset it and a landscape device silently invalidates every gesture + computed for portrait. + """ + self.shell("settings put system accelerometer_rotation 0") + self.shell("settings put system user_rotation 0") + self._size = None + + def rotate(self, landscape: bool) -> None: + self.shell("settings put system accelerometer_rotation 0") + self.shell(f"settings put system user_rotation {1 if landscape else 0}") + self._size = None + + # -- app lifecycle and entry points ----------------------------------- + + def launch(self) -> None: + self.shell(f"am start -W -n {ACTIVITY}", timeout=120) + + def stop(self) -> None: + self.shell(f"am force-stop {self.pkg}") + + def kill(self) -> None: + """Process death without a clean shutdown, to test state restoration.""" + self.shell(f"am kill {self.pkg}") + + def clear_data(self) -> None: + self.shell(f"pm clear {self.pkg}") + + def grant_camera(self) -> None: + """Re-grant the camera permission, which "pm clear" takes away.""" + self.shell(f"pm grant {self.pkg} android.permission.CAMERA", check=False) + + def send_uri(self, uri: str) -> None: + """Hand a Taler URI to the wallet. + + ACTION_SEND/text/plain is used rather than a VIEW intent because the + manifest's VIEW filter covers taler:// and payto:// but not the + taler+http:// form that a local http deployment hands out. + """ + self.shell( + "am start -a android.intent.action.SEND -t text/plain " + f"-n {ACTIVITY} --es android.intent.extra.TEXT {uri!r}", + timeout=120, + ) + + def send_ndef(self, uri: str) -> None: + """Deliver a URI the way a tapped NFC tag does. + + ACTION_NDEF_DISCOVERED carries its URI in a Parcelable NdefMessage, + which `am start` cannot build, so the sim build's SimHooks receiver + constructs it in-process. It deliberately leaves `intent.data` unset, + which is the branch MainActivity falls back to -- the one no scenario + had ever reached. + """ + self.shell( + f"am broadcast -a net.taler.wallet.sim.SEND_NDEF " + f"-n {self.pkg}/net.taler.wallet.sim.SimHooks --es uri {uri!r}", + timeout=120, + ) + + # -- waiting and convenience ------------------------------------------ + + def wait_for(self, pattern: str, timeout: int = 60, poll: float = 1.5) -> Screen: + """Poll the UI until some label matches, and return that screen. + + Raises TimeoutError with the last screen's labels attached, which is + what makes a failing scenario readable afterwards. + """ + deadline = time.monotonic() + timeout + last = Screen() + while time.monotonic() < deadline: + last = self.dump() + if last.find(pattern): + return last + time.sleep(poll) + raise TimeoutError( + f"no label matching {pattern!r} within {timeout}s; " + f"screen showed: {last.texts()}" + ) + + def tap_text(self, pattern: str, timeout: int = 30) -> Screen: + """Wait for a label, tap what serves it, and return that screen.""" + screen = self.wait_for(pattern, timeout=timeout) + node = screen.find(pattern) + if node is None: + # The screen changed between matching and tapping; say so plainly + # rather than failing with a bare assertion. + raise RuntimeError(f"{pattern!r} matched but was gone before the tap; " + f"screen now: {self.dump().texts()}") + self.tap_node(node, screen) + return screen + + def view_uri(self, uri: str) -> None: + """Deliver a URI the way a browser link or QR deep link would.""" + self.shell(f"am start -a android.intent.action.VIEW -d {uri!r}", timeout=120, check=False) + + +if __name__ == "__main__": + import sys + d = Device(sys.argv[1] if len(sys.argv) > 1 else "emulator-5554") + s = d.dump() + print(f"activity: {s.activity}") + print(f"nodes: {len(s.nodes)} labelled: {len(s.labelled())} " + f"tappable: {len(s.tappable())} editable: {len(s.editable())}") + print(s) + print("signature:", s.signature()[:200]) diff --git a/wallet-simulator/driver/episode.py b/wallet-simulator/driver/episode.py @@ -0,0 +1,255 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""One run of the simulator: actions in, artifacts and findings out. + +Every action is recorded in a form that can be replayed, which is what makes a +finding useful: the artifact directory holds the shortest sequence that still +reproduces it, not just a stack trace. Actions are addressed by label wherever +possible, because coordinates stop meaning anything as soon as a layout shifts. +""" + +from __future__ import annotations + +import json +import time +from dataclasses import asdict, dataclass, field +from pathlib import Path +from typing import Any, Optional + +import coverage as coverage_mod +import oracles +from device import Device, Screen +from wallet import Wallet + + +@dataclass +class Action: + """A replayable step.""" + + op: str + arg: Any = None + + def describe(self) -> str: + return f"{self.op}({self.arg!r})" if self.arg is not None else f"{self.op}()" + + +class Episode: + def __init__( + self, + dev: Device, + out_dir: str | Path, + name: str = "episode", + settle: float = 1.2, + coverage_dir: str | Path | None = None, + ): + self.dev = dev + self.app = Wallet(dev) + # Whatever has been exercised so far lives in the app process; a wipe + # takes it with it unless it is dumped first. + self.app.before_wipe = lambda: self.dump_coverage("before-wipe") + self.dir = Path(out_dir) / name + self.dir.mkdir(parents=True, exist_ok=True) + self.name = name + self.settle = settle + self.actions: list[Action] = [] + self.session = oracles.Session() + self.signatures: set[str] = set() + self.steps = 0 + self._shots = 0 + # JaCoCo data lives in the app process, so it has to be collected + # before anything kills it. + self.coverage_dir = Path(coverage_dir) if coverage_dir else None + self._dumps = 0 + self.dev.logcat(clear=True) + + # -- acting ----------------------------------------------------------- + + def perform(self, action: Action, screen: Optional[Screen] = None) -> None: + """Run one action, recording it first so a crash still leaves a trace.""" + self.actions.append(action) + self._write_actions() + op, arg = action.op, action.arg + if op == "tap_label": + current = screen or self.dev.dump() + target = current.find(f"^{_escape(arg)}$") or current.find(_escape(arg)) + if target is None: + return + before = current.signature() + # A random walk taps labels indiscriminately, and a label that is + # not a control legitimately changes nothing -- "Pending:", a + # timestamp, a section header. Only a tap that had something to + # hit can have failed silently. + resolved = current.tap_target(target) + interactive = resolved.clickable and resolved.enabled + self.dev.tap_node(target, current) + time.sleep(self.settle) + after = self.dev.dump() + if interactive: + fresh = self.session.add(oracles.silent_failure( + self.dev, str(arg), before, after.signature())) + for finding in fresh: + self._capture(finding, after, None) + elif op == "tap_xy": + self.dev.tap(arg[0], arg[1]) + elif op == "long_press_label": + target = (screen or self.dev.dump()).find(_escape(arg)) + if target is not None: + self.dev.long_press(target) + elif op == "type": + fields = (screen or self.dev.dump()).editable() + if fields: + self.dev.tap_node(fields[0], screen) + time.sleep(0.4) + self.dev.shell("input keyevent KEYCODE_MOVE_END") + for _ in range(24): + self.dev.shell("input keyevent KEYCODE_DEL") + self.dev.type_text(arg) + elif op == "scroll_down": + self.dev.scroll(down=True, screen=screen) + elif op == "scroll_up": + self.dev.scroll(down=False, screen=screen) + elif op == "back": + self.dev.back() + elif op == "rotate": + self.dev.rotate(landscape=bool(arg)) + elif op == "uri": + self.dev.send_uri(arg) + elif op == "view_uri": + self.dev.view_uri(arg) + elif op == "offline_blip": + self.dev.shell("cmd connectivity airplane-mode enable", check=False) + time.sleep(3) + self.dev.shell("cmd connectivity airplane-mode disable", check=False) + time.sleep(2) + elif op == "process_death": + self.dump_coverage("before-kill") + self.dev.kill() + time.sleep(1) + self.dev.launch() + elif op == "relaunch": + self.dump_coverage("before-relaunch") + self.dev.stop() + self.dev.launch() + elif op == "home_screen": + self.app.home() + else: + raise ValueError(f"unknown action {op}") + self.steps += 1 + time.sleep(self.settle) + + # -- observing -------------------------------------------------------- + + def observe(self, with_log: bool = True, + log_lines: int = 600) -> tuple[Screen, list[oracles.Finding]]: + """Read the screen, run the oracles, keep the evidence for anything new. + + Only the tail of the log is read: the whole buffer takes seconds once + it has filled, and the oracles are looking at what just happened. + """ + screen = self.dev.dump() + log = self.dev.logcat(lines=log_lines) if with_log else None + fresh = self.session.check(self.dev, screen=screen, log=log) + self.signatures.add(screen.signature()) + for finding in fresh: + self._capture(finding, screen, log) + return screen, fresh + + def _capture(self, finding: oracles.Finding, screen: Screen, log: Optional[str]) -> None: + stem = f"{finding.kind}-{finding.fingerprint}" + self._shots += 1 + try: + self.dev.screenshot(str(self.dir / f"{stem}.png")) + except Exception: + pass + payload = { + "finding": asdict(finding), + "fingerprint": finding.fingerprint, + "step": self.steps, + "screen": screen.texts(), + "signature": screen.signature(), + "actions": [asdict(a) for a in self.actions], + } + (self.dir / f"{stem}.json").write_text(json.dumps(payload, indent=2)) + if log: + (self.dir / f"{stem}.logcat.txt").write_text(log[-400_000:]) + + # -- finishing -------------------------------------------------------- + + def _write_actions(self) -> None: + (self.dir / "actions.json").write_text( + json.dumps([asdict(a) for a in self.actions], indent=2) + ) + + def dump_coverage(self, tag: str = "end") -> Optional[Path]: + """Collect execution data, if this is an instrumented build.""" + if self.coverage_dir is None: + return None + self._dumps += 1 + target = self.coverage_dir / f"{self.name}-{self._dumps:02d}-{tag}.ec" + try: + return coverage_mod.dump(self.dev, target, name=f"{tag}.ec") + except Exception as e: + print(f"coverage dump failed ({tag}): {e}") + return None + + def check_database(self) -> list[oracles.Finding]: + """Oracles that read the wallet database, not the screen. + + Done once per episode rather than per step: the database has to be + copied off the device, which is too slow for the action loop. + """ + found = oracles.background_failures(self.dev, keep_db_at=str(self.dir / "walletdb")) + found += oracles.unfinished_transactions(self.dev) + found += oracles.db_intact(self.dev) + fresh = self.session.add(found) + for finding in fresh: + self._capture(finding, self.dev.dump(), None) + return fresh + + def finish(self, extra: Optional[dict] = None) -> dict: + self.dump_coverage("end") + try: + self.check_database() + except Exception as e: + print(f"database oracle failed: {e}") + findings = list(self.session.findings.values()) + summary = { + "name": self.name, + "steps": self.steps, + "distinct_screens": len(self.signatures), + "findings": [asdict(f) | {"fingerprint": f.fingerprint} for f in findings], + "serious": len(self.session.serious()), + **(extra or {}), + } + (self.dir / "summary.json").write_text(json.dumps(summary, indent=2)) + # Keeping only the tail of the raw log loses the start of a chatty + # scenario, and with it whatever wallet-core operations ran early -- + # `coverage/operations.py` reads these files and reported + # updateExchangeEntry as never exercised although tapping "Reload + # information" calls it forty times. So the wallet's own lines are + # kept in full (they are what the oracles and the operation census + # read) and the rest of the system log keeps its tail. + log = self.dev.logcat() + mine = [l for l in log.splitlines() + if "taler-wallet" in l or "BackendManager" in l + or "SimHooks" in l] + (self.dir / "logcat.txt").write_text( + "\n".join(mine)[-4_000_000:] + "\n--- other tags, tail ---\n" + + log[-400_000:]) + return summary + + +def _escape(text: str) -> str: + import re + return re.escape(text) diff --git a/wallet-simulator/driver/explore.py b/wallet-simulator/driver/explore.py @@ -0,0 +1,213 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Random exploration of the wallet, biased towards screens not yet seen. + +A plain monkey spends its time on the main screen, so this keeps a count of +which labels it has already tapped in each screen signature and prefers the +untried ones. Environment actions — back, rotation, process death, a URI +arriving from outside — are mixed in at low rates, because they are where +state-restoration bugs live. + +The seed makes a run reproducible, but the authoritative record is still the +action log the episode writes: it replays even if the exploration policy +changes. +""" + +from __future__ import annotations + +import random +import sys +import time +from collections import Counter +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "corpus")) + +import oracles # noqa: E402 +import uris as corpus # noqa: E402 +from device import PKG, Device # noqa: E402 +from episode import Action, Episode # noqa: E402 +import scenarios # noqa: E402 +from stack import Env # noqa: E402 + +# Labels that end the session or throw away the wallet; reachable, but rarely, +# or exploration would spend its life on the first screen again. +DESTRUCTIVE = ( + "reset wallet", "delete wallet", "dangerously", "wipe", "logout", "log out", + "reset", "clear", +) +# Labels that lead out of the app entirely. +LEAVES_APP = ("authorize in bank", "export", "share", "save", "open in browser") + + +class Explorer: + def __init__(self, episode: Episode, seed: int = 0, allow_destructive: bool = False, + env=None): + self.ep = episode + self.rng = random.Random(seed) + self.allow_destructive = allow_destructive + self.tapped: dict[str, Counter] = {} + self.new_screens = 0 + self.uri_pool = list(corpus.all_uris().items()) + self.rng.shuffle(self.uri_pool) + self.env = env + # Steps since the walk last saw a screen it had not seen before. + self.stale = 0 + self.restarts = 0 + + def _pick_label(self, signature: str, labels: list[str]) -> str | None: + """Prefer a label never tapped on this screen before.""" + seen = self.tapped.setdefault(signature, Counter()) + usable = [ + label for label in labels + if (self.allow_destructive or not any(d in label.lower() for d in DESTRUCTIVE)) + and not any(x in label.lower() for x in LEAVES_APP) + ] + if not usable: + return None + fresh = [label for label in usable if seen[label] == 0] + choice = self.rng.choice(fresh or usable) + seen[choice] += 1 + return choice + + def refresh_state(self) -> None: + """Go back to a deep state when the walk stops finding anything new. + + A random walk settles into a few screens it can reach from wherever it + is; re-running a scenario setup puts it somewhere else entirely, which + is cheaper than waiting for chance to do it. + """ + import scenarios + if self.env is None: + return + choices = [scenarios.funded_and_paid, scenarios.fund_wallet, + lambda app, env: app.fresh_start(dev_mode=True)] + setup = self.rng.choice(choices) + self.restarts += 1 + self.ep.actions.append(Action("restart_state", setup.__name__ + if hasattr(setup, "__name__") else "fresh")) + try: + setup(self.ep.app, self.env) + except Exception as e: + print(f"could not refresh the state: {e}") + self.stale = 0 + + def step(self) -> None: + screen, _ = self.ep.observe() + # A tap can leave the app -- a KYC link opens Chrome, "Open in banking + # app" opens whatever handles payto -- and a random walk has no reason + # to find its way back, so a whole run can end up exploring a browser. + if screen.activity and not screen.activity.startswith(PKG): + self.ep.actions.append(Action("return_to_app", screen.activity[:60])) + self.ep.dev.launch() + time.sleep(4) + screen, _ = self.ep.observe() + signature = screen.signature() + if len(self.ep.signatures) > self.new_screens: + self.new_screens = len(self.ep.signatures) + self.stale = 0 + else: + self.stale += 1 + if self.stale >= 25: + self.refresh_state() + return + + roll = self.rng.random() + # An error sheet or a dead end: get out before doing anything else. + if screen.find(r"(?i)export error diagnostics") or not screen.labelled(): + self.ep.perform(Action("back"), screen) + return + if roll < 0.06: + self.ep.perform(Action("back"), screen) + return + if roll < 0.12: + self.ep.perform(Action("scroll_down" if self.rng.random() < 0.75 else "scroll_up"), + screen) + return + if roll < 0.14: + self.ep.perform(Action("rotate", self.rng.random() < 0.5), screen) + return + if roll < 0.16: + self.ep.perform(Action("process_death"), screen) + return + if roll < 0.175: + # Losing the network mid-operation is where retry logic shows its + # seams; it is turned back on immediately so the walk can continue. + self.ep.perform(Action("offline_blip"), screen) + return + if roll < 0.21 and self.uri_pool: + name, uri = self.uri_pool[self.ep.steps % len(self.uri_pool)] + self.ep.perform(Action("uri", uri), screen) + return + if roll < 0.33 and screen.editable(): + self.ep.perform(Action("type", self.rng.choice(corpus.TEXT_INPUTS)), screen) + return + + labels = [n.label.strip() for n in screen.tappable() if n.label.strip()] + label = self._pick_label(signature, labels) + if label is None: + self.ep.perform(Action("back"), screen) + return + self.ep.perform(Action("tap_label", label), screen) + + def run(self, steps: int) -> dict: + for i in range(steps): + try: + self.step() + except Exception as e: # keep exploring; the oracle records the state + self.ep.session.add([oracles.Finding("driver-error", f"{type(e).__name__}: {e}")]) + screen, _ = self.ep.observe() + return self.ep.finish({"new_screens": len(self.ep.signatures)}) + + +def main() -> int: + steps = int(sys.argv[1]) if len(sys.argv) > 1 else 60 + seed = int(sys.argv[2]) if len(sys.argv) > 2 else 1 + serial = sys.argv[3] if len(sys.argv) > 3 else "emulator-5554" + out = Path("/opt/taler-sim/run/out") + + dev = Device(serial) + ep = Episode(dev, out, name=f"explore-seed{seed}-{int(time.time())}", + coverage_dir=Path("/opt/taler-sim/run/coverage")) + # Start from a wallet that already holds coins and has paid once: most of + # the interesting screens do not exist in an empty wallet. + env = Env.load() + # Vary the starting point: a wallet with coins and a purchase behind it + # reaches different screens than an empty one, and both are worth walking. + setups = [ + ("funded_and_paid", scenarios.funded_and_paid), + ("fund_wallet", scenarios.fund_wallet), + ("fresh", lambda app, env: app.fresh_start(dev_mode=True)), + ] + name, setup = setups[seed % len(setups)] if seed % 4 else setups[0] + print(f"starting state: {name}") + try: + setup(ep.app, env) + except Exception as e: + print(f"warning: could not reach the {name} state ({e}); " + f"exploring from wherever the app is") + explorer = Explorer(ep, seed=seed, env=env) + summary = explorer.run(steps) + + print(f"steps: {summary['steps']} distinct screens: {summary['distinct_screens']}" + f" state refreshes: {explorer.restarts}") + print(f"findings: {len(summary['findings'])} ({summary['serious']} serious)") + for f in summary["findings"]: + print(f" [{f['kind']}] {f['detail'][:160]}") + print(f"artifacts: {ep.dir}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/wallet-simulator/driver/forever.sh b/wallet-simulator/driver/forever.sh @@ -0,0 +1,87 @@ +#!/bin/bash +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# Keep the campaign running without supervision. +# +# Each round: top the bank accounts up, run every scenario across the +# emulators, then explore at random with fresh seeds. Coverage is dumped after +# each phase and one line per round is appended to rounds.log, so progress can +# be read at a glance later. +# +# Usage: nohup ./forever.sh [first-round-number] > /opt/taler-sim/run/forever.log 2>&1 & +# Stop: touch /opt/taler-sim/run/STOP + +set -u + +HERE=$(cd "$(dirname "$0")" && pwd) +RUN=${SIM_RUN_DIR:-/opt/taler-sim/run} +ROUNDS_LOG="$RUN/rounds.log" +STOP="$RUN/STOP" +STEPS=${SIM_EXPLORE_STEPS:-120} +round=${1:-1} + +cd "$HERE" +mkdir -p "$RUN" + +log() { printf '%s round %s: %s\n' "$(date -Is)" "$round" "$*" | tee -a "$ROUNDS_LOG"; } + +while [ ! -e "$STOP" ]; do + log "starting" + + # Registration bonuses do not last; an empty bank account looks exactly + # like a wallet bug in the logs. + python3 stack.py > "$RUN/round$round-provision.log" 2>&1 || + log "provisioning failed, see round$round-provision.log" + + # Exploration first. It used to come after the suite, and a suite of 83 + # scenarios takes so long that a phase always set the STOP file first -- + # which breaks out of the loop here, so the random walks never ran at all. + # They are what found two of the findings, so they go before the queue. + seed=$((1000 + round * 10)) + python3 -u campaign.py explore --workers 4 --steps "$STEPS" --seed "$seed" \ + --tag "r${round}-explore" > "$RUN/round$round-explore.log" 2>&1 + found=$(grep -c '^ \[' "$RUN/round$round-explore.log" 2>/dev/null || echo 0) + log "explore: seed $seed, $STEPS steps/worker, $found finding lines" + + [ -e "$STOP" ] && break + + python3 -u campaign.py suite --workers 4 --tag "r${round}-suite" \ + > "$RUN/round$round-suite.log" 2>&1 + ok=$(grep -cE '^ [a-z_]+ ' "$RUN/round$round-suite.log" 2>/dev/null || echo 0) + bad=$(grep -cE '^ ! [a-z_]+ ' "$RUN/round$round-suite.log" 2>/dev/null || echo 0) + serious=$(grep -c '^ \*\*\*' "$RUN/round$round-suite.log" 2>/dev/null || echo 0) + log "suite: $ok ok, $bad driver errors, $serious serious findings" + + # Keep the on-device coverage from growing stale in case a later round + # restarts the app process. + python3 - <<'PY' >> "$RUN/round$round-coverage.log" 2>&1 +import coverage, time +from pathlib import Path +from device import Device +stamp = int(time.time()) +for worker in range(4): + try: + path = coverage.dump(Device(f"emulator-{5554 + 2 * worker}"), + Path(f"/opt/taler-sim/run/coverage/round-{stamp}-w{worker}.ec"), + name=f"round{stamp}w{worker}.ec") + print(f"worker {worker}: {path} ({path.stat().st_size} bytes)") + except Exception as e: + print(f"worker {worker}: {e}") +PY + log "coverage dumped" + round=$((round + 1)) +done + +log "stopped (STOP file present)" diff --git a/wallet-simulator/driver/matrix.py b/wallet-simulator/driver/matrix.py @@ -0,0 +1,182 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Run the platform-sensitive scenarios on every Android version the app supports. + +The campaign proper runs one image (the newest), which is the wrong shape for a +report like "scanning works on 15 but not on 14": a defect that depends on the +platform cannot be seen from a single platform. + +`wallet/build.gradle` says `minSdkVersion 24`, so the supported range is API +24 up to the compile target. Testing all thirteen is mostly waste -- what +matters are the levels where the app's own behaviour forks, and every entry in +API_LEVELS below names the code that makes it fork. + +One emulator at a time, because each wants 4 GB: + + python3 matrix.py # every level, the default subset + python3 matrix.py --apis 34 36 # just these two + python3 matrix.py --scenarios scan_manual_entry nfc_tap_to_pay + python3 matrix.py --keep # leave the last emulator running + +Results land in run/matrix-<stamp>.json and are printed as a table: one row per +scenario, one column per API level. +""" + +from __future__ import annotations + +import argparse +import json +import os +import subprocess +import sys +import time +from pathlib import Path + +HERE = Path(__file__).resolve().parent +SIM_ROOT = Path(os.environ.get("SIM_ROOT", "/opt/taler-sim")) +RUN = Path(os.environ.get("SIM_RUN_DIR", SIM_ROOT / "run")) +APK = Path(os.environ.get("SIM_APK", SIM_ROOT / "apk" / "wallet.apk")) +EMU = SIM_ROOT / "emu" / "emu.sh" + +# The worker index the matrix borrows. It is past the campaign's four and past +# the scratch worker, so a matrix run and a campaign round can coexist. +MATRIX_WORKER = int(os.environ.get("SIM_MATRIX_WORKER", "6")) + +# Why each level is in the list. Keep the reason with the number: without it +# the list grows by superstition. +API_LEVELS: dict[int, str] = { + 24: "minSdkVersion -- the oldest the app claims to run on", + 26: "TalerUtils.kt:29 branches below 26", + 28: "SettingsScreen.kt:562 branches at P", + 29: "Utils.kt:70 and AndroidUtils.kt:109 branch at 29 (scoped storage)", + 30: "MainActivity.kt:301 and SettingsScreen.kt:507,554 branch at R", + 31: "Theme.kt:158 takes dynamic colour from S", + 33: "MainActivity.kt:360 reads NDEF the TIRAMISU way; per-app language", + 34: "Amount.kt:256 formats with the monetary grouping separator from 34", + 36: "the compile target, and what the campaign runs", +} + +# The scenarios whose outcome can plausibly depend on the platform: anything +# touching the camera, NFC, storage, locale, biometrics or the window manager, +# plus enough of a money path to notice a wallet that cannot work at all. +DEFAULT_SCENARIOS = [ + "balances_screens", + "history", + "scan_manual_entry", + "nfc_tap_to_pay", + "settings_walk", + "settings_export", + "settings_import", + "config_changes", + "wallet_lock_without_credential", + "a11y_audit", + "lifecycle_kill", + "db_corruption", +] + + +def run(cmd: list[str], **kw) -> subprocess.CompletedProcess: + return subprocess.run(cmd, text=True, capture_output=True, **kw) + + +def emu(action: str, *args: str, api: int | None = None, timeout: int = 900): + env = dict(os.environ) + if api is not None: + env["SIM_SYSTEM_IMAGE"] = f"system-images;android-{api};google_apis;x86_64" + return subprocess.run( + [str(EMU), action, str(MATRIX_WORKER), *args], + text=True, capture_output=True, env=env, timeout=timeout, + ) + + +def boot(api: int) -> str: + """Create, boot and prepare one emulator on this API level.""" + serial = f"emulator-{5554 + 2 * MATRIX_WORKER}" + print(f" creating an API {api} emulator ...", flush=True) + made = emu("create", api=api) + if made.returncode != 0: + raise RuntimeError(f"could not create the AVD: {made.stderr.strip()[:300]}") + print(f" booting {serial} ...", flush=True) + booted = emu("boot", api=api, timeout=1200) + if booted.returncode != 0: + raise RuntimeError(f"could not boot: {booted.stderr.strip()[:300]}") + prepared = emu("prepare", str(APK), api=api, timeout=900) + if prepared.returncode != 0: + raise RuntimeError(f"could not prepare: {prepared.stderr.strip()[:300]}") + return serial + + +def scenarios_on(api: int, scenarios: list[str], timeout: int) -> dict: + """Run the subset and return each scenario's status.""" + env = dict(os.environ, SIM_WORKER=str(MATRIX_WORKER)) + log = RUN / f"matrix-api{api}.log" + with open(log, "w") as out: + proc = subprocess.run( + [sys.executable, "-u", str(HERE / "suite.py"), *scenarios], + text=True, stdout=out, stderr=subprocess.STDOUT, + env=env, cwd=HERE, timeout=timeout, + ) + results: dict[str, str] = {} + for line in log.read_text(errors="replace").splitlines(): + parts = line.split() + if len(parts) >= 2 and parts[0] in scenarios: + results[parts[0]] = parts[1] + return {"exit": proc.returncode, "log": str(log), "scenarios": results} + + +def main() -> int: + ap = argparse.ArgumentParser(description=__doc__) + ap.add_argument("--apis", nargs="*", type=int, default=sorted(API_LEVELS), + help="API levels to run (default: all of them)") + ap.add_argument("--scenarios", nargs="*", default=DEFAULT_SCENARIOS) + ap.add_argument("--timeout", type=int, default=5400, + help="seconds for one level's scenarios") + ap.add_argument("--keep", action="store_true", + help="leave the last emulator running") + args = ap.parse_args() + + stamp = int(time.time()) + out_path = RUN / f"matrix-{stamp}.json" + report: dict = {"stamp": stamp, "scenarios": args.scenarios, "levels": {}} + + for api in args.apis: + print(f"=== API {api}: {API_LEVELS.get(api, 'no reason recorded')}", flush=True) + try: + boot(api) + report["levels"][api] = scenarios_on(api, args.scenarios, args.timeout) + except Exception as e: # noqa: BLE001 + print(f" !! {e}", flush=True) + report["levels"][api] = {"error": str(e)[:400], "scenarios": {}} + finally: + if not (args.keep and api == args.apis[-1]): + emu("kill", api=api, timeout=120) + out_path.write_text(json.dumps(report, indent=2)) + + # One row per scenario, one column per level: a difference between columns + # is the thing this exists to find. + levels = [a for a in args.apis if a in report["levels"]] + width = max((len(s) for s in args.scenarios), default=10) + 2 + print("\n" + "scenario".ljust(width) + "".join(f"{a:>7}" for a in levels)) + for name in args.scenarios: + row = "".join( + f"{report['levels'][a]['scenarios'].get(name, '-')[:6]:>7}" + for a in levels + ) + print(name.ljust(width) + row) + print(f"\n{out_path}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/wallet-simulator/driver/oracles.py b/wallet-simulator/driver/oracles.py @@ -0,0 +1,488 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""What counts as a failure. + +An ordinary error is not a finding: the wallet is supposed to refuse a stale +order or a malformed URI, and say so. A finding is the app breaking its own +contract — a crash, an ANR, an error that wallet-core itself calls unexpected +or an invariant failure, a transaction that never leaves a pending state, or a +database that no longer opens. +""" + +from __future__ import annotations + +import hashlib +import json +import re +import time +from dataclasses import dataclass, field +from pathlib import Path +from typing import Iterable, Optional + +from device import PKG, Device, Screen + +# Error codes that mean "this should not have happened" rather than "your +# request was bad"; see wallet/src/main/java/net/taler/wallet/backend/ +# TalerErrorCode.kt. +INTERNAL_CODES = { + 2, # GENERIC_CLIENT_INTERNAL_ERROR + 56, # GENERIC_DB_INVARIANT_FAILURE + 60, # GENERIC_INTERNAL_INVARIANT_FAILURE + 7001, # WALLET_UNEXPECTED_EXCEPTION + 7007, # WALLET_CORE_API_OPERATION_UNKNOWN + 7047, # WALLET_TRANSACTION_PROTOCOL_VIOLATION + 7048, # WALLET_CORE_API_BAD_REQUEST +} + +CRASH_PATTERNS = ( + ("crash", re.compile(r"FATAL EXCEPTION")), + ("anr", re.compile(r"ANR in ")), + ("native-crash", re.compile(r"\*\*\* \*\*\* \*\*\*|signal \d+ \(SIG")), + ("core-internal", re.compile(r"(?i)unexpected exception|invariant (failure|violated)" + r"|unhandled (promise )?rejection|assertion failed")), + ("core-unreachable", re.compile(r"(?i)refusing to run a second wallet-core")), +) + +# The wallet's error bottom sheet always offers this; it is the cheapest marker +# that the screen on display is an error screen at all. +ERROR_SHEET_MARKER = re.compile(r"(?i)export error diagnostics") +# \bbug\b matters: without the word boundaries this matched the "debug" in +# the application id of every URI the wallet quoted back in an error message. +INTERNAL_TEXT = re.compile( + r"(?i)internal error|invariant|unexpected|assertion|\bbug\b" + r"|NullPointer|[A-Za-z]+Exception\b" +) + + +# Kinds that describe the wallet behaving reasonably (refusing bad input, +# waiting for a counterparty) rather than a defect. +INFORMATIONAL = {"error-screen", "unfinished-transaction", "harness-crash"} + + +@dataclass(frozen=True) +class Finding: + kind: str + detail: str + evidence: str = "" + + @property + def fingerprint(self) -> str: + """Dedup key: the same bug found twice should collapse to one entry.""" + # Strip ids, amounts, timestamps and addresses so that two instances of + # the same defect hash alike. + norm = re.sub(r"[0-9A-Z]{20,}", "<ID>", self.detail) + norm = re.sub(r"\b\d+\b", "#", norm) + norm = re.sub(r"0x[0-9a-f]+", "<ADDR>", norm) + return hashlib.sha256(f"{self.kind}|{norm}".encode()).hexdigest()[:16] + + def __str__(self) -> str: + return f"[{self.kind}] {self.detail}" + + +def from_logcat(log: str, pkg: str = PKG) -> list[Finding]: + """Crashes, ANRs and wallet-core's own internal errors. + + A crash is only the app's when the trace says so: `uiautomator dump` + itself dies with "UiAutomationService … already registered!" whenever two + dumps overlap, and that is the driver's problem, not the wallet's. + """ + out: list[Finding] = [] + lines = log.splitlines() + for kind, pattern in CRASH_PATTERNS: + for i, line in enumerate(lines): + if not pattern.search(line): + continue + # A stack trace's first frames identify the defect far better + # than the header line does. + context = "\n".join(lines[i:i + 12]) + if kind in ("crash", "native-crash") and pkg not in context: + out.append(Finding("harness-crash", + f"not the app: {line.strip()[:200]}", context)) + continue + out.append(Finding(kind, line.strip()[:400], context)) + for m in re.finditer(r'"code"\s*:\s*(\d+)', log): + code = int(m.group(1)) + if code in INTERNAL_CODES: + start = max(0, m.start() - 300) + out.append(Finding("internal-error-code", f"wallet-core returned code {code}", + log[start:m.end() + 300])) + return out + + +def from_screen(screen: Screen) -> list[Finding]: + """Error screens that look like a bug rather than a refusal.""" + texts = screen.texts() + joined = " | ".join(texts) + if not any(ERROR_SHEET_MARKER.search(t) for t in texts): + return [] + message = next((t for t in texts + if not ERROR_SHEET_MARKER.search(t) + and t.lower() not in ("error", "copy", "share", "close", + "drag handle", "close sheet")), "") + if INTERNAL_TEXT.search(joined): + return [Finding("internal-error-screen", message[:400] or joined[:400], joined)] + # A plain error sheet is recorded, but only as information: whether it is + # legitimate depends on what the scenario was trying to do. + return [Finding("error-screen", message[:400] or joined[:400], joined)] + + +# Text that should never reach a user. +SANITY_PATTERNS = ( + ("placeholder-leak", re.compile(r"%[0-9]+\$[sd]|%s\b|%d\b")), + ("null-leak", re.compile(r"(?<![A-Za-z])(null|undefined|NaN|Infinity)(?![A-Za-z])")), + ("exception-leak", re.compile(r"java\.lang\.|kotlin\.[A-Za-z]+Exception|" + r"[A-Za-z]+Exception:")), + # A word stuck to a number, like "UNKNOWN0.00" or "EUR1.00": a currency + # symbol that is a word, formatted as if it were a sign. + ("glued-currency", re.compile(r"(?:^|[\s:])[A-Z]{3,}\d+[.,]\d\d(?:$|\s)")), +) +# Labels that legitimately contain such words: the developer-mode error sheet +# and the JSON viewer render raw wallet-core payloads, nulls and all. +SANITY_EXEMPT = re.compile( + r"(?i)export error diagnostics|show json|internal event log" + r'|^\s*[\{\[]|"\s*:' +) + + +def screen_sanity(screen: Screen) -> list[Finding]: + """Rendering that is obviously wrong, whatever the screen is for. + + An unsubstituted format string, a stray "null", a stack-trace class name or + a currency word glued to a number are all defects no matter which flow + produced them, and they are cheap to notice on every dump. + """ + out: list[Finding] = [] + for text in screen.texts(): + label = text.strip() + if not label or SANITY_EXEMPT.search(label): + continue + for kind, pattern in SANITY_PATTERNS: + if pattern.search(label): + out.append(Finding(kind, f"{label[:160]!r} on {screen.activity}", + " | ".join(screen.texts())[:800])) + break + return out + + +# A transaction that never happened cannot have cost a fee. The fee row on +# every credit screen is the difference between the raw and the effective +# amount, and an aborted or failed transaction has an effective amount of +# zero, so the difference becomes the whole amount. +DEAD_STATE = re.compile(r"(?i)was aborted|has failed|has expired|been abandoned") + + +def fee_on_a_dead_transaction(screen: Screen) -> list[Finding]: + """A fee shown on a transaction that did not happen.""" + texts = screen.texts() + if not any(DEAD_STATE.search(t) for t in texts): + return [] + if not any(t.strip().lower() == "fee" for t in texts): + return [] + return [Finding( + "fee-on-dead-transaction", + f"a fee is shown on a transaction that did not happen, on {screen.activity}", + " | ".join(texts)[:800], + )] + + +# A screen that states an absence -- no accounts, no contacts, nothing to send +# -- while the log says the query behind it failed. Found by hand first (see +# findings/a-failed-query-is-shown-as-an-empty-wallet.md); this is the general +# shape of it. +ABSENCE_CLAIM = re.compile( + r"(?i)^No [a-z ]*(accounts|contacts|transactions|payment services|" + r"methods|statements)|^No [a-z ]+ (yet|saved)[.!]?$" +) +FAILED_QUERY = re.compile( + r'Error (?:retrieving )?(get|list)[A-Za-z]+' + r'|"operation"\s*:\s*"(get|list)[A-Za-z]+"' +) + + +def absence_after_error(screen: Screen, log: Optional[str]) -> list[Finding]: + """An empty state shown while the query behind it was failing.""" + if not log: + return [] + claims = [t for t in screen.texts() if ABSENCE_CLAIM.search(t.strip())] + if not claims: + return [] + failures = [l for l in log.splitlines() + if FAILED_QUERY.search(l) and ('"error"' in l or "Error " in l)] + if not failures: + return [] + return [Finding( + "absence-after-error", + f"{claims[0][:80]!r} while a query was failing, on {screen.activity}", + "\n".join(failures[-3:])[:600] + "\n--\n" + " | ".join(screen.texts())[:400], + )] + + +# Amounts rendered both with and without their currency specification on the +# same screen: "5.00 EUR" beside "€4.88" reads like two currencies. +AMOUNT_UNSPECCED = re.compile(r"(?:^|\s)\d+[.,]\d\d\s+[A-Z]{3,}(?:$|\s)") +AMOUNT_SPECCED = re.compile(r"[€$£¥₹]\s?\d+(?:[.,]\d+)?") + + +def mixed_amount_notation(screen: Screen) -> list[Finding]: + """Two notations for money on one screen.""" + texts = screen.texts() + plain = [m.group(0).strip() for t in texts + for m in [AMOUNT_UNSPECCED.search(t)] if m] + symbol = [m.group(0).strip() for t in texts + for m in [AMOUNT_SPECCED.search(t)] if m] + if not (plain and symbol): + return [] + # The two notations are often in the *same* sentence ("transfer 5.00 EUR + # ... to receive EUR4.88"), so name the amounts rather than their nodes: + # quoting whole nodes made the finding read as the same text twice. + return [Finding( + "mixed-amount-notation", + f"{plain[0]!r} beside {symbol[0]!r} on {screen.activity}", + " | ".join(texts)[:700], + )] + + +def blank_screen(screen: Screen) -> list[Finding]: + """A screen with nothing to read and nothing to tap is a dead end.""" + if not screen.nodes: + return [Finding("empty-hierarchy", "no view hierarchy returned")] + if not screen.labelled() and not screen.tappable(): + return [Finding("blank-screen", f"{len(screen.nodes)} nodes, none labelled or tappable")] + return [] + + +# Retry counters above this mean wallet-core has given up repeatedly on the +# same operation. +STUCK_RETRIES = 4 + + +def background_failures(dev: Device, keep_db_at: Optional[str] = None) -> list[Finding]: + """Operations failing where the UI never looks. + + wallet-core keeps one `operation_retries` row per retried operation, with + the last error and a retry counter. A row with an error is a failure the + user may never be shown; an error with an internal code is a defect, and a + high retry counter is an operation that is not getting anywhere. + """ + import dbprobe + + out: list[Finding] = [] + try: + db = dbprobe.pull(dev, Path(keep_db_at) if keep_db_at else None) + if not dbprobe.has_native_schema(db): + # A wallet on the legacy IndexedDB-emulation backend keeps its + # records in object_data, not in tables this oracle can read. + # That is a state the wallet can legitimately be in -- see + # db_migration_prompt -- so there is nothing to report rather than + # an oracle failure. + return [] + rows = dbprobe.rows(db, "select id, last_error, retry_info from operation_retries") + except Exception as e: + return [Finding("oracle-error", f"could not read the wallet database: {e}")] + for row in rows: + op = row["id"] + error = row["last_error"] + if error: + try: + info = json.loads(error) + except (json.JSONDecodeError, TypeError): + info = {} + code = info.get("code") + hint = str(info.get("hint") or info.get("message") or error)[:300] + kind = ("background-internal-error" if code in INTERNAL_CODES + else "background-error") + out.append(Finding(kind, f"{op}: code {code}: {hint}", error[:2000])) + try: + retries = json.loads(row["retry_info"] or "{}").get("retryCounter", 0) + except (json.JSONDecodeError, TypeError): + retries = 0 + if retries >= STUCK_RETRIES: + out.append(Finding("stuck-operation", + f"{op}: retried {retries} times", str(dict(row))[:1000])) + return out + + +# Tables that record one long-running operation each, with the column that +# says when it finished. +OPERATION_TABLES = { + "withdrawal_groups": ("withdrawal_group_id", "timestamp_start", "timestamp_finish"), + "refresh_groups": ("refresh_group_id", "timestamp_created", "timestamp_finished"), + "deposit_groups": ("deposit_group_id", "timestamp_created", "timestamp_finished"), +} + + +def unfinished_transactions(dev: Device, older_than: int = 240) -> list[Finding]: + """Operations that started a while ago and never finished. + + Advisory rather than damning: a suspended or aborted transaction is + legitimately unfinished, and so is one waiting for the bank. What makes it + worth printing is the pattern — the same operation unfinished across runs + that should have completed it. + """ + import dbprobe + + out: list[Finding] = [] + try: + db = dbprobe.pull(dev) + except Exception as e: + return [Finding("oracle-error", f"could not read the wallet database: {e}")] + if not dbprobe.has_native_schema(db): + return [] + now_us = time.time() * 1_000_000 + for table, (key, started, finished) in OPERATION_TABLES.items(): + try: + rows = dbprobe.rows( + db, f"select {key} as id, {started} as started, {finished} as finished, " + f"status from {table}") + except Exception: + continue + for row in rows: + if row["finished"]: + continue + start = row["started"] + if not isinstance(start, (int, float)): + continue + age = (now_us - float(start)) / 1_000_000 + if age > older_than: + out.append(Finding( + "unfinished-transaction", + f"{table} {str(row['id'])[:24]} unfinished after {age:.0f}s " + f"(status {row['status']})", + str(dict(row))[:500], + )) + return out + + +# Lines that mean wallet-core refused or failed an operation the UI asked for. +# Deliberately narrow: any "E taler-wallet" line also matches background +# chatter that has nothing to do with the tap being judged. +TAIL_ERROR = re.compile( + r'"type"\s*:\s*"error"\s*,\s*"operation"' + r"|got \w+ error" + r"|FATAL EXCEPTION" +) + + +LOGCAT_STAMP = re.compile(r"^(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)\.(\d+)") + + +def recent_lines(log: str, seconds: float = 6.0) -> list[str]: + """Log lines written within the last few seconds. + + logcat has no "since my last read" option, so the timestamps are compared + against the wall clock. The device and the host share it closely enough + for a window this wide. + """ + now = time.localtime() + cutoff = time.time() - seconds + out = [] + for line in log.splitlines(): + m = LOGCAT_STAMP.match(line) + if not m: + continue + month, day, hour, minute, second = (int(m.group(i)) for i in range(1, 6)) + stamp = time.mktime((now.tm_year, month, day, hour, minute, second, + 0, 0, now.tm_isdst)) + if stamp >= cutoff: + out.append(line) + return out + + +def silent_failure(dev: Device, label: str, before: str, after: str, + lines: int = 200) -> list[Finding]: + """A primary action that did nothing, while the log says it failed. + + This is the shape of the first defect the simulator found: tapping "Treat + as global" sent a malformed request, wallet-core rejected it, and the user + saw nothing at all. Comparing the screen before and after a tap catches + the whole class. + """ + if before != after: + return [] + # Only the app's own screens: a random walk taps around in Chrome too, and + # "tapping 'Sign in' changed nothing" is not a finding about the wallet. + activity = dev.dump().activity + if activity and not activity.startswith(PKG): + return [] + tail = dev.adb("logcat", "-d", "-t", str(lines), check=False) + fresh = "\n".join(recent_lines(tail)) + errors = [ln for ln in fresh.splitlines() if TAIL_ERROR.search(ln)] + if not errors: + return [] + codes = sorted({int(m.group(1)) for m in re.finditer(r'"code"\s*:\s*(\d+)', fresh)}) + internal = [c for c in codes if c in INTERNAL_CODES] + kind = "silent-internal-failure" if internal else "silent-failure" + return [Finding( + kind, + f"tapping {label!r} changed nothing on screen while the log reported " + f"an error (codes {codes or 'none'})", + "\n".join(errors[-8:])[:2000], + )] + + +def db_intact(dev: Device, pkg: Optional[str] = None) -> list[Finding]: + """Ask sqlite whether the wallet database still checks out.""" + from device import PKG + pkg = pkg or PKG + out = dev.shell( + f"run-as {pkg} sqlite3 files/talerwalletdb.sqlite3 'PRAGMA integrity_check;'", + check=False, + ).strip() + if not out: + # No sqlite3 on the image, or no database yet: not a finding. + return [] + if out.splitlines()[-1].strip() != "ok": + return [Finding("db-corrupt", out[:400])] + return [] + + +@dataclass +class Session: + """Collects findings over an episode, deduplicated.""" + + findings: dict[str, Finding] = field(default_factory=dict) + + def add(self, found: Iterable[Finding]) -> list[Finding]: + fresh = [] + for f in found: + if f.fingerprint not in self.findings: + self.findings[f.fingerprint] = f + fresh.append(f) + return fresh + + def check(self, dev: Device, screen: Optional[Screen] = None, + log: Optional[str] = None) -> list[Finding]: + found: list[Finding] = [] + # Screen oracles only apply to the app's own screens. A random walk + # leaves the wallet now and then -- a KYC link opens Chrome -- and + # Chrome's search suggestions are full of the words these oracles look + # for ("undefined behavior", "null"), which is 16 findings of pure + # noise in a 120-step walk. + if screen is not None and screen.activity and not screen.activity.startswith(PKG): + screen = None + if screen is not None: + found += from_screen(screen) + found += blank_screen(screen) + found += screen_sanity(screen) + found += fee_on_a_dead_transaction(screen) + found += mixed_amount_notation(screen) + if log is not None: + found += absence_after_error(screen, log) + if log is not None: + found += from_logcat(log) + return self.add(found) + + def serious(self) -> list[Finding]: + """Everything except what only describes the wallet refusing or waiting.""" + return [f for f in self.findings.values() if f.kind not in INFORMATIONAL] diff --git a/wallet-simulator/driver/phase.sh b/wallet-simulator/driver/phase.sh @@ -0,0 +1,105 @@ +#!/bin/bash +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# Run a set of scenarios against a different stack, then put the default stack +# back and resume the rounds. +# +# ./phase.sh sim-kyc.conf kyc_withdraw_trips_rule kyc_transaction_actions +# ./phase.sh sim-twister.conf twister_withdraw_faults twister_field_faults +# +# Only one stack can run at a time (the exchange's secmod sockets are shared), +# so this stops the unattended loop first and restarts it afterwards at the +# next round number. + +set -u + +HERE=$(cd "$(dirname "$0")" && pwd) +RUN=${SIM_RUN_DIR:-/opt/taler-sim/run} +BACKEND="$HERE/../backend" +CONF=${1:?usage: phase.sh <config> <scenario>...} +shift +SCENARIOS=("$@") +[ "${#SCENARIOS[@]}" -gt 0 ] || { echo "no scenarios given" >&2; exit 2; } +TAG=${SIM_PHASE_TAG:-phase-${CONF%.conf}-$(date +%s)} + +say() { printf '%s phase %s: %s\n' "$(date -Is)" "$TAG" "$*" | tee -a "$RUN/rounds.log"; } + +# 1. Pause the unattended loop and wait for the round in flight to end. +say "pausing the rounds" +touch "$RUN/STOP" +# A round is an exploration pass plus every scenario, which is well over an +# hour now; waiting only 40 minutes meant the stack was swapped *under* a +# running round, which corrupts both it and the phase. Three hours, and if a +# campaign is still running after that, do not swap the stack at all. +for _ in $(seq 1 1080); do + pgrep -f "python3 -u campaign.py" >/dev/null || break + sleep 10 +done +if pgrep -f "python3 -u campaign.py" >/dev/null; then + say "a campaign is STILL running after three hours; not swapping the stack" + rm -f "$RUN/STOP" + exit 1 +fi + +# 2. Swap the stack. +say "starting the stack from $CONF" +(cd "$BACKEND" && ./stack.sh stop >/dev/null 2>&1) +if ! (cd "$BACKEND" && SIM_CONF="$CONF" ./stack.sh start > "$RUN/$TAG-stack.log" 2>&1); then + say "the stack would not start from $CONF; see $TAG-stack.log" + tail -15 "$RUN/$TAG-stack.log" >&2 + (cd "$BACKEND" && ./stack.sh start >/dev/null 2>&1) && say "default stack restored" + python3 "$HERE/stack.py" > "$RUN/$TAG-provision.log" 2>&1 || true + for w in 0 1 2 3 4; do + "$HERE/../emu/emu.sh" reverse "$w" >> "$RUN/$TAG-reverse.log" 2>&1 || true + done + # The rounds must carry on even when a variant will not start, or a failed + # phase silently ends the campaign. + rm -f "$RUN/STOP" + NEXT=$(( $(grep -c 'round .*: starting' "$RUN/rounds.log" 2>/dev/null || echo 5) + 5 )) + say "resuming rounds at $NEXT after the failed phase" + nohup setsid "$HERE/forever.sh" "$NEXT" > "$RUN/forever-after-$TAG.log" 2>&1 < /dev/null & + exit 1 +fi +python3 "$HERE/stack.py" > "$RUN/$TAG-provision.log" 2>&1 || say "provisioning complained" + +# The variant may serve on a port the emulators have never had mapped (the +# twister proxy, for one), and adb reverse only knows what it was told. +for w in 0 1 2 3 4; do + "$HERE/../emu/emu.sh" reverse "$w" >> "$RUN/$TAG-reverse.log" 2>&1 || true +done +say "re-mapped the stack ports into the emulators" + +# 3. Run the scenarios across the workers. +say "running ${SCENARIOS[*]}" +python3 -u "$HERE/campaign.py" suite --workers 4 --tag "$TAG" \ + --only "${SCENARIOS[@]}" > "$RUN/$TAG.log" 2>&1 +ok=$(grep -cE '^ [a-z_]+ ' "$RUN/$TAG.log" 2>/dev/null || echo 0) +bad=$(grep -cE '^ ! [a-z_]+ ' "$RUN/$TAG.log" 2>/dev/null || echo 0) +serious=$(grep -c '^ \*\*\*' "$RUN/$TAG.log" 2>/dev/null || echo 0) +say "$ok ok, $bad driver errors, $serious serious findings (see $TAG.log)" + +# 4. Put the default stack back and let the rounds continue. +say "restoring the default stack" +(cd "$BACKEND" && ./stack.sh stop >/dev/null 2>&1) +(cd "$BACKEND" && ./stack.sh start > "$RUN/$TAG-restore.log" 2>&1) || + say "WARNING: the default stack did not come back; see $TAG-restore.log" +python3 "$HERE/stack.py" >> "$RUN/$TAG-provision.log" 2>&1 +for w in 0 1 2 3 4; do + "$HERE/../emu/emu.sh" reverse "$w" >> "$RUN/$TAG-reverse.log" 2>&1 || true +done +rm -f "$RUN/STOP" +NEXT=$(( $(grep -c 'round .*: starting' "$RUN/rounds.log" 2>/dev/null || echo 5) + 5 )) +say "resuming rounds at $NEXT" +nohup setsid "$HERE/forever.sh" "$NEXT" > "$RUN/forever-after-$TAG.log" 2>&1 < /dev/null & diff --git a/wallet-simulator/driver/probe.py b/wallet-simulator/driver/probe.py @@ -0,0 +1,98 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Poke at a running wallet one step at a time, printing what each step shows. + +Label discovery is most of the work in writing a scenario, and guessing from +source is slower than looking. Each invocation performs one action and dumps +the resulting screen. + + python3 probe.py dump + python3 probe.py tap Request + python3 probe.py fill 1 + python3 probe.py back + python3 probe.py uri 'taler+http://pay/...' + SIM_SERIAL=emulator-5556 python3 probe.py dump +""" + +from __future__ import annotations + +import os +import sys +import time + +from device import Device +from wallet import Wallet + + +def show(dev: Device) -> None: + screen = dev.dump() + print(f"activity: {screen.activity}") + for node in screen.labelled(): + print(f" {node}") + fields = screen.editable() + print(f"editable fields: {len(fields)}") + for node in fields: + print(f" FIELD {node}") + + +def main() -> int: + serial = os.environ.get("SIM_SERIAL", "emulator-5554") + dev = Device(serial) + app = Wallet(dev) + args = sys.argv[1:] or ["dump"] + op, rest = args[0], args[1:] + + if op == "dump": + pass + elif op == "home": + app.home() + elif op == "tap": + dev.tap_text(rest[0], timeout=20) + time.sleep(1.5) + elif op == "fill": + screen = dev.dump() + fields = screen.editable() + index = int(rest[1]) if len(rest) > 1 else 0 + if len(fields) <= index: + print(f"no editable field {index} (found {len(fields)})") + return 1 + dev.tap_node(fields[index]) + time.sleep(0.5) + dev.type_text(rest[0]) + time.sleep(1.5) + elif op == "back": + dev.back() + time.sleep(1.2) + elif op == "scroll": + dev.scroll(down=(not rest or rest[0] != "up"), screen=dev.dump()) + time.sleep(1.2) + elif op == "uri": + app.handle_uri(rest[0]) + time.sleep(2) + elif op == "settings": + app.open_settings() + elif op == "fresh": + app.fresh_start(dev_mode=True) + elif op == "enter": + dev.key("KEYCODE_ENTER") + time.sleep(1.5) + else: + print(__doc__) + return 2 + show(dev) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/driver/qrsuite.py b/wallet-simulator/driver/qrsuite.py @@ -0,0 +1,230 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Decode real QR images with the app, through its own scan screen. + +Everything else in the simulator hands URIs to the app as shared text, which +skips the decoder entirely. Here the payload is rendered to a PNG with +`qrencode`, pushed into the device's gallery and picked with the scan screen's +"Scan from gallery", so the image decoder and everything downstream of it run +for real. + +The live camera was tried first and does not work unattended: the emulator's +virtual scene hangs its poster on a wall that is rotated away from the default +camera pose (`Toren1BD.posters`: `rotation 0 -150 0`), and the pose cannot be +moved from outside. `--camera` keeps that path available for a human to watch. + + python3 qrsuite.py --worker 4 + python3 qrsuite.py --worker 4 --only valid_withdraw malformed_base32 +""" + +from __future__ import annotations + +import argparse +import json +import subprocess +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "corpus")) + +import oracles # noqa: E402 +import uris as corpus # noqa: E402 +from device import Device # noqa: E402 +from episode import Episode # noqa: E402 +from stack import Bank, Env, Merchant # noqa: E402 +from wallet import Wallet # noqa: E402 + +EMU = Path("/opt/taler-sim/emu/emu.sh") +POSTERS = Path("/opt/taler-sim/run/posters") +OUT = Path("/opt/taler-sim/run/out") +COVERAGE = Path("/opt/taler-sim/run/coverage") + + +def render(payload: str, name: str) -> Path: + """Make a QR poster. Large modules, because the camera sees it from afar.""" + POSTERS.mkdir(parents=True, exist_ok=True) + path = POSTERS / f"{name}.png" + subprocess.run( + ["qrencode", "-s", "20", "-m", "2", "-l", "L", "-o", str(path), payload], + check=True, timeout=60, + ) + return path + + +def payloads(env: Env) -> dict[str, str]: + """What to put on the wall. + + The valid entries point at live services but at identifiers that do not + exist, so no funds are needed: reaching the prompt (or a clean error) is + proof that the decode worked. + """ + merchant = Merchant(env.merchant) + bank = Bank(env.bank) + out = { + "valid_pay": corpus.STRUCTURAL["pay"], + "valid_withdraw": corpus.STRUCTURAL["withdraw"], + "valid_withdraw_exchange": corpus.STRUCTURAL["withdraw_exchange"], + "payto": corpus.STRUCTURAL["payto_iban"], + "malformed_base32": corpus.MALFORMED["bad_base32"], + "unknown_action": corpus.MALFORMED["unknown_action"], + "not_taler": "https://www.gnu.org/software/taler/", + "plain_text": "this is not a URI at all", + } + # One genuinely live pay URI, so a successful decode leads somewhere real. + try: + order = merchant.create_order("EUR:1", summary="QR scanned order") + out["live_pay"] = order["pay_uri"] + except Exception as e: + print(f"could not create a live order ({e}); skipping live_pay") + try: + op = bank.create_withdrawal("wallet1", "walletpass1", "EUR:5") + out["live_withdraw"] = op["taler_withdraw_uri"] + except Exception as e: + print(f"could not create a live withdrawal ({e}); skipping live_withdraw") + return out + + +def boot_with(worker: int, poster: Path) -> None: + subprocess.run([str(EMU), "kill", str(worker)], timeout=120, check=False) + time.sleep(3) + env = {"SIM_POSTER": str(poster), "PATH": "/usr/bin:/bin:/usr/sbin:/sbin"} + subprocess.run([str(EMU), "boot", str(worker)], timeout=600, check=True, + env={**env}) + subprocess.run([str(EMU), "prepare", str(worker)], timeout=600, check=True) + + +def push_to_gallery(dev: Device, poster: Path) -> None: + """Put the image where the system photo picker will offer it.""" + target = f"/sdcard/Pictures/{poster.name}" + dev.adb("push", str(poster), target, timeout=120) + # MediaStore has to learn about the file, or the picker shows nothing. + dev.shell(f"am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE " + f"-d file://{target}", check=False) + time.sleep(1.5) + + +def scan_from_gallery(dev: Device, app: Wallet, ep: Episode, name: str, + payload: str, poster: Path, settle: int = 20) -> dict: + """Pick the rendered QR image with the scan screen's gallery button.""" + app.fresh_start(dev_mode=True) + push_to_gallery(dev, poster) + dev.logcat(clear=True) + screen = app.open_scanner() + before = screen.signature() + dev.tap_text(r"(?i)Scan from gallery", timeout=30) + time.sleep(3) + picker = dev.dump() + photo = picker.find(r"(?i)^Photo taken on") or picker.find(r"(?i)photo") + if photo is None: + return {"payload": payload[:120], "error": "no photo in the picker", + "screen": picker.texts()[:12]} + dev.tap_node(photo, picker) + start = time.time() + reacted = None + while time.time() - start < settle: + current = dev.dump() + if current.signature() != before and "photopicker" not in current.activity: + reacted = current + break + time.sleep(2) + after = reacted or dev.dump() + ep.observe() + result = { + "payload": payload[:120], + "decoded_and_reacted": reacted is not None, + "screen": after.texts()[:14], + "seconds": round(time.time() - start, 1), + } + print(f" {name:24} reacted={result['decoded_and_reacted']} " + f"{result['screen'][:6]}") + return result + + +def scan_with_camera(dev: Device, app: Wallet, ep: Episode, name: str, + payload: str, settle: int = 25) -> dict: + """Open the scan screen and see what the camera makes of the wall.""" + app.fresh_start(dev_mode=True) + dev.logcat(clear=True) + screen = app.open_scanner() + start = time.time() + reacted = None + while time.time() - start < settle: + current = dev.dump() + if current.signature() != screen.signature(): + reacted = current + break + time.sleep(2) + after = reacted or dev.dump() + ep.observe() + result = { + "payload": payload[:120], + "decoded_and_reacted": reacted is not None, + "screen": after.texts()[:14], + "seconds": round(time.time() - start, 1), + } + print(f" {name:24} reacted={result['decoded_and_reacted']} " + f"{result['screen'][:6]}") + return result + + +def main() -> int: + ap = argparse.ArgumentParser(description=__doc__) + ap.add_argument("--worker", type=int, default=4) + ap.add_argument("--only", nargs="*") + ap.add_argument("--camera", action="store_true", + help="use the virtual scene's camera instead of the gallery " + "(needs a human to aim it; see the module docstring)") + args = ap.parse_args() + + env = Env.load() + cases = payloads(env) + if args.only: + cases = {k: v for k, v in cases.items() if k in args.only} + serial = f"emulator-{5554 + 2 * args.worker}" + stamp = int(time.time()) + results: dict[str, dict] = {} + + dev = Device(serial) + app = Wallet(dev) + for name, payload in cases.items(): + poster = render(payload, name) + print(f"{name}: {poster} ({poster.stat().st_size} bytes)") + if args.camera: + boot_with(args.worker, poster) + dev = Device(serial) + app = Wallet(dev) + ep = Episode(dev, OUT, name=f"qr-w{args.worker}-{stamp}-{name}", + coverage_dir=COVERAGE) + try: + if args.camera: + results[name] = scan_with_camera(dev, app, ep, name, payload) + else: + results[name] = scan_from_gallery(dev, app, ep, name, payload, poster) + except Exception as e: + results[name] = {"error": f"{type(e).__name__}: {e}"} + print(f" {name:24} ERROR {e}") + ep.finish({"qr_case": name, "result": results[name]}) + + summary = OUT / f"qr-w{args.worker}-{stamp}-summary.json" + summary.write_text(json.dumps(results, indent=2)) + decoded = [k for k, v in results.items() if v.get("decoded_and_reacted")] + print(f"\n{len(results)} QR codes scanned, {len(decoded)} produced a reaction: " + f"{decoded}") + print(f"summary: {summary}") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/driver/replay.py b/wallet-simulator/driver/replay.py @@ -0,0 +1,158 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Replay a recorded episode, and shrink it to the steps that matter. + +An 80-step random walk that ends in a crash is not a bug report. Delta +debugging over the action list turns it into one: each candidate subsequence is +replayed from the same starting state, and the shortest one that still produces +the same finding fingerprint is what gets written out. + +Replay is not perfectly deterministic — wallet-core retries on its own clock — +so a candidate is only discarded after it fails to reproduce `attempts` times. +""" + +from __future__ import annotations + +import argparse +import json +import sys +import time +from pathlib import Path +from typing import Callable, Optional, Sequence + +import scenarios +from device import Device +from episode import Action, Episode +from stack import Env + +SETUPS: dict[str, Callable] = { + "fresh": lambda app, env: app.fresh_start(dev_mode=True), + "fund_wallet": scenarios.fund_wallet, + "funded_and_paid": scenarios.funded_and_paid, +} + + +def load_actions(path: Path) -> list[Action]: + data = json.loads((path / "actions.json").read_text() + if path.is_dir() else path.read_text()) + return [Action(op=a["op"], arg=a.get("arg")) for a in data] + + +def replay( + dev: Device, + actions: Sequence[Action], + out_dir: Path, + setup: str = "funded_and_paid", + name: str = "replay", +) -> Episode: + env = Env.load() + ep = Episode(dev, out_dir, name=name) + SETUPS[setup](ep.app, env) + # The setup itself must not count as a finding of the sequence. + ep.session = type(ep.session)() + dev.logcat(clear=True) + for action in actions: + ep.perform(action) + ep.observe(with_log=False) + ep.observe(with_log=True) + ep.finish({"setup": setup, "replayed": len(actions)}) + return ep + + +def reproduces(ep: Episode, fingerprint: Optional[str]) -> bool: + if fingerprint: + return fingerprint in ep.session.findings + return bool(ep.session.serious()) + + +def minimize( + dev: Device, + actions: Sequence[Action], + out_dir: Path, + fingerprint: Optional[str], + setup: str = "funded_and_paid", + attempts: int = 2, +) -> list[Action]: + """Classic ddmin, with repeats to survive a flaky reproduction.""" + + def still_fails(candidate: Sequence[Action], tag: str) -> bool: + for attempt in range(attempts): + ep = replay(dev, candidate, out_dir, setup=setup, + name=f"min-{tag}-{attempt}") + if reproduces(ep, fingerprint): + return True + return False + + current = list(actions) + granularity = 2 + while len(current) >= 2: + chunk = max(1, len(current) // granularity) + reduced = False + for i in range(0, len(current), chunk): + candidate = current[:i] + current[i + chunk:] + if not candidate: + continue + if still_fails(candidate, f"{len(current)}-{i}"): + current = candidate + granularity = max(granularity - 1, 2) + reduced = True + break + if not reduced: + if granularity >= len(current): + break + granularity = min(len(current), granularity * 2) + return current + + +def main() -> int: + ap = argparse.ArgumentParser(description=__doc__) + ap.add_argument("episode", type=Path, help="episode directory or actions.json") + ap.add_argument("--fingerprint", help="the finding to preserve (default: any serious one)") + ap.add_argument("--setup", default="funded_and_paid", choices=sorted(SETUPS)) + ap.add_argument("--minimize", action="store_true") + ap.add_argument("--serial", default="emulator-5554") + ap.add_argument("--out", type=Path, default=Path("/opt/taler-sim/run/out/replays")) + args = ap.parse_args() + + dev = Device(args.serial) + actions = load_actions(args.episode) + print(f"{len(actions)} actions from {args.episode}") + + ep = replay(dev, actions, args.out, setup=args.setup, + name=f"replay-{int(time.time())}") + ok = reproduces(ep, args.fingerprint) + print(f"reproduced: {ok}") + for f in ep.session.findings.values(): + print(f" [{f.kind}] {f.fingerprint} {f.detail[:140]}") + if not ok: + print("nothing to minimize") + return 1 + + if args.minimize: + target = args.fingerprint or next(iter( + f.fingerprint for f in ep.session.serious())) + shortest = minimize(dev, actions, args.out, target, setup=args.setup) + print(f"\nminimized {len(actions)} -> {len(shortest)} actions:") + for a in shortest: + print(" ", a.describe()) + target_file = args.out / f"minimal-{target}.json" + target_file.write_text(json.dumps( + {"setup": args.setup, "fingerprint": target, + "actions": [{"op": a.op, "arg": a.arg} for a in shortest]}, indent=2)) + print(f"written: {target_file}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/wallet-simulator/driver/report.py b/wallet-simulator/driver/report.py @@ -0,0 +1,83 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Summarise episode directories. + + python3 report.py # everything, newest last + python3 report.py 'suite-w*-1792268945-*' + python3 report.py --notes 'suite-*' # with the scenario notes + python3 report.py --findings # only the findings, deduplicated +""" + +from __future__ import annotations + +import glob +import json +import os +import sys +from pathlib import Path + +OUT = Path("/opt/taler-sim/run/out") + + +def load(pattern: str) -> list[dict]: + rows = [] + for d in sorted(glob.glob(str(OUT / pattern)), key=os.path.getmtime): + path = Path(d) / "summary.json" + if path.is_file(): + try: + rows.append(json.loads(path.read_text()) | {"dir": d}) + except json.JSONDecodeError: + continue + return rows + + +def main() -> int: + args = [a for a in sys.argv[1:] if not a.startswith("--")] + pattern = args[0] if args else "*" + rows = load(pattern) + show_notes = "--notes" in sys.argv + only_findings = "--findings" in sys.argv + + findings: dict[str, dict] = {} + broken = 0 + for r in rows: + for f in r.get("findings", []): + findings.setdefault(f.get("fingerprint", f["detail"][:40]), f) + if r.get("status") not in (None, "ok"): + broken += 1 + if only_findings: + continue + name = r.get("scenario") or r.get("name", "?") + status = r.get("status", "-") + print(f"{name:28} {status:13} serious={r.get('serious', 0)} " + f"findings={len(r.get('findings', []))} steps={r.get('steps', 0)} " + f"{r.get('seconds', '?')}s") + if r.get("error"): + print(f" error: {r['error'][:200]}") + if show_notes: + for note in r.get("notes", []): + print(f" note: {note[:200]}") + + serious = [f for f in findings.values() if f["kind"] != "error-screen"] + print(f"\n{len(rows)} episodes, {broken} driver errors, " + f"{len(findings)} distinct findings ({len(serious)} serious)") + for f in findings.values(): + mark = "***" if f["kind"] != "error-screen" else " " + print(f" {mark} [{f['kind']:22}] {f.get('fingerprint', '')} " + f"{f['detail'][:150].replace(chr(10), ' ')}") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/driver/scenarios.py b/wallet-simulator/driver/scenarios.py @@ -0,0 +1,346 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Scripted flows that put the wallet into a deep, interesting state. + +Random exploration from the launcher almost never reaches "has coins and has +paid for something"; these do it in a handful of steps, so exploration can +start from there instead. Each one drives the real UI and uses the host-side +APIs only for the steps a counterparty would perform. +""" + +from __future__ import annotations + +import os +import time +from typing import Callable + +from cli import CliWallet +from device import Screen +from stack import Bank, Env, Merchant +from wallet import Wallet + +# Each parallel worker gets its own bank customer, so two emulators running +# scenarios at the same time cannot spend each other's money. +WORKER = int(os.environ.get("SIM_WORKER", "0")) +WALLET_USER = (f"wallet{WORKER + 1}", f"walletpass{WORKER + 1}") + + +def tap_if(app: Wallet, pattern: str, timeout: int = 8) -> bool: + """Tap a label if it is there; unlike Device.tap_text, do not raise.""" + try: + app.dev.tap_text(pattern, timeout=timeout) + return True + except TimeoutError: + return False + + +def tap_lowest_button(app: Wallet, pattern: str, timeout: int = 60) -> bool: + """Tap the lowest *clickable* node whose label matches. + + Several screens use one string for the heading and the submit button; the + heading comes first in the hierarchy and is not clickable, so a plain + tap_text hits nothing. Ctx.tap_button does this for scenarios; flows need + their own copy. + """ + import re as _re + rx = _re.compile(pattern, _re.I) + deadline = time.time() + timeout + while time.time() < deadline: + screen = app.dev.dump() + targets = [] + for node in screen.labelled(): + if not rx.search(node.label): + continue + target = screen.tap_target(node) + if target.clickable and target.enabled: + targets.append(target) + if targets: + app.dev.tap_node(max(targets, key=lambda n: n.bounds[1]), screen) + time.sleep(1.5) + return True + time.sleep(1.5) + return False + + +def accept_tos(app: Wallet, timeout: int = 20) -> bool: + """Get past the terms of service, if the exchange has any. + + An exchange that serves /terms turns the withdrawal prompt's own button + into "Terms of Service", which opens the review screen; nothing else can + be done until the terms are accepted. An exchange without terms (the + shipped TERMS_DIR points into an empty test home) never shows this, so + every caller has to cope with both. + """ + # Two orders of events: the button is already there, or the screen says the + # terms are required and the button arrives with the next recomposition + # (which is what happens after switching to a different payment service). + deadline = time.time() + 10 + while True: + screen = app.dev.dump() + if screen.find(r"(?i)^Terms of Service$") is not None: + break + if screen.find(r"(?i)terms of service before you can withdraw|" + r"must first accept") is None: + return False + if time.time() > deadline: + return False + time.sleep(1.5) + # Opening the review screen fetches the terms document, which on a loaded + # host takes longer than one tap's patience; and the accept button can sit + # below the fold. So: tap, look, scroll, and tap again rather than giving + # up on the first miss -- a flaky accept here fails the *setup* of whatever + # scenario asked for a funded wallet, which reads as that scenario being + # broken. + for attempt in range(3): + if not tap_if(app, r"(?i)^Terms of Service$", timeout=timeout): + break + time.sleep(2) + deadline = time.time() + timeout + while time.time() < deadline: + if app.dev.dump().find(r"(?i)^Accept Terms of Service$") is not None: + app.dev.tap_text(r"(?i)^Accept Terms of Service$", timeout=10) + time.sleep(2) + return True + app.dev.scroll(down=True) + time.sleep(1.5) + # Still on the prompt: go back up and try the button once more. + if app.dev.dump().find(r"(?i)^Terms of Service$") is None: + app.dev.back() + time.sleep(1.5) + return False + + +def pick_payment_service(app: Wallet, url: str) -> bool: + """Switch the withdrawal prompt to a particular payment service. + + The prompt shows the chosen service as a row labelled with its URL, and + that row is `clickable` but **disabled** until the terms of service have + been accepted -- so this only works after accept_tos, and tapping it + earlier does nothing (or lands on a neighbour and leaves the screen). + """ + import re as _re + screen = app.dev.dump() + row = next((n for n in screen.labelled() + if _re.match(r"(?i)^https?://", n.label.strip())), None) + if row is None: + return False + target = screen.tap_target(row) + if not target.enabled: + return False + app.dev.tap_node(target, screen) + time.sleep(2) + # The picker lists every service that can serve this currency. + return tap_lowest_button(app, _re.escape(url.rstrip("/")), timeout=15) + + +def withdraw(app: Wallet, bank: Bank, amount: str = "EUR:10", timeout: int = 180, + pick_exchange: str | None = None) -> Screen: + """Bank-initiated withdrawal, all the way to a completed transaction. + + The bank opens the operation, the wallet picks the exchange and confirms, + and the host plays the part of the human authorising it in the bank's own + UI. `pick_exchange` switches the service first, which is the only way to + get coins at a second exchange. + """ + op = bank.create_withdrawal(*WALLET_USER, amount) + app.handle_uri(op["taler_withdraw_uri"]) + accept_tos(app) + if pick_exchange and pick_payment_service(app, pick_exchange): + # A different service means its own terms. + accept_tos(app) + app.dev.tap_text(r"(?i)confirm withdrawal", timeout=60) + # The wallet has to have selected the exchange before the bank will let the + # operation be confirmed; confirming anyway answers "Cannot confirm an + # unselected withdrawal" (5130), which reads like a bank problem rather + # than a wallet that was still thinking. + deadline = time.monotonic() + 90 + while True: + status = bank.withdrawal_status(op["withdrawal_id"])["status"] + if status == "selected": + break + if time.monotonic() > deadline: + raise TimeoutError( + f"the wallet did not select an exchange for {amount} within 90s " + f"(bank says {status!r}; screen: {app.dev.dump().texts()[:12]})") + time.sleep(2) + bank.confirm_withdrawal(*WALLET_USER, op["withdrawal_id"]) + deadline = time.monotonic() + timeout + while time.monotonic() < deadline: + screen = app.dev.dump() + if screen.find(r"(?i)completed successfully"): + return screen + time.sleep(3) + raise TimeoutError(f"withdrawal {op['withdrawal_id']} did not complete") + + +def pay(app: Wallet, merchant: Merchant, amount: str = "EUR:2", + summary: str = "Simulator order") -> dict: + """Create an order and pay it from the wallet's balance.""" + order = merchant.create_order(amount, summary=summary) + app.handle_uri(order["pay_uri"]) + # The button carries the amount, e.g. "Pay €2.00". + app.dev.tap_text(r"(?i)^pay\b|confirm payment", timeout=60) + deadline = time.monotonic() + 90 + while time.monotonic() < deadline: + if merchant.order_status(order["order_id"], + order["token"]).get("order_status") == "paid": + return order + time.sleep(2) + raise TimeoutError(f"order {order['order_id']} was not paid") + + +def fund_wallet(app: Wallet, env: Env | None = None, amount: str = "EUR:10") -> Screen: + """Fresh profile in developer mode, with coins in it.""" + env = env or Env.load() + app.fresh_start(dev_mode=True) + screen = withdraw(app, Bank(env.bank), amount) + app.home() + return screen + + +def funded_and_paid(app: Wallet, env: Env | None = None) -> dict: + """The deepest cheap state: coins, one completed purchase, refundable.""" + env = env or Env.load() + fund_wallet(app, env) + order = pay(app, Merchant(env.merchant)) + app.home() + return order + + +def deposit_via_payto_link(app: Wallet, env: Env | None = None) -> Screen: + """Try to start a deposit from a payto link, which the wallet refuses. + + `DepositManager.isSupportedPayToUri` accepts `payto://iban/...` and nothing + else, so the `payto://x-taler-bank/...` URI the simulator's bank hands out + answers "Not a valid Taler link" -- see + findings/payto-link-only-accepts-iban.md. + """ + env = env or Env.load() + payto = Bank(env.bank).payto(*WALLET_USER) + app.handle_uri(payto) + app.dev.wait_for(r"(?i)Not a valid Taler link|deposit|amount|send", timeout=60) + return app.dev.dump() + + +def deposit_to_bank(app: Wallet, env: Env | None = None, + digits: str = "100", + before_submit: Callable[[], None] | None = None) -> Screen: + """Deposit from the app to a bank account, through the UI. + + Not through a payto link: the wallet refuses every target type but IBAN + (see `deposit_via_payto_link`), and the simulator's bank is x-taler-bank, + so the link path cannot deposit at all. The Deposit button can, and the + account is already known to the wallet from its withdrawals. + + `digits` is typed as an amount field takes them, from the right: "100" is + 1.00. + """ + env = env or Env.load() + app.home() + app.dev.tap_text(r"(?i)^Deposit$", timeout=30) + screen = app.dev.wait_for( + r"(?i)deposit to bank account|Manage bank accounts|x-taler-bank", + timeout=30) + account = screen.find(r"(?i)^wallet\d+$") or screen.find(r"(?i)x-taler-bank") + if account is not None: + app.dev.tap_node(account, screen) + time.sleep(2) + app.dev.wait_for(r"(?i)Amount to deposit|Make deposit", timeout=25) + fields = app.dev.dump().editable() + if fields: + app.dev.tap_node(fields[0]) + app.dev.type_text(digits) + time.sleep(1) + # The fees appear on their own once an amount is in; older builds had a + # "Check fees" button, so it is tapped when present and skipped otherwise. + tap_if(app, r"(?i)^Check fees$", timeout=6) + # A caller that wants the deposit to *stay* pending -- to reach the + # aborting state, say -- takes the network away here: against a healthy + # exchange the whole thing is over in under four seconds. + if before_submit is not None: + before_submit() + app.dev.tap_text(r"(?i)^Make deposit$|^Deposit$", timeout=20) + time.sleep(4) + return app.dev.dump() + + +# The peer wallet gets a bank customer of its own, so funding it never eats +# into the balance the app under test is spending. +PEER_USER = (f"peer{WORKER + 1}", f"peerpass{WORKER + 1}") + + +def fund_peer(peer: CliWallet, env: Env, amount: str = "EUR:5", + exchange: str | None = None) -> str: + """Give the CLI peer wallet coins, through the bank like any wallet. + + `exchange` picks which one they come from, which is how the app ends up + holding a second currency scope: a peer payment is spent at the sender's + exchange. + """ + from stack import Bank + return peer.fund_via_bank(Bank(env.bank), PEER_USER, amount, + exchange or env.exchange) + + +def peer_receive(app: Wallet, env: Env | None = None, amount: str = "EUR:1", + peer: CliWallet | None = None, + exchange: str | None = None) -> Screen: + """The CLI wallet pushes money; the app accepts it. + + `exchange` is where the peer's coins come from, and therefore which scope + the app ends up holding -- the cheapest way to give this wallet a balance + at a second exchange, since no withdrawal UI lets one be chosen. + """ + env = env or Env.load() + peer = peer or CliWallet() + exchange = exchange or env.exchange + if exchange != env.exchange: + peer.add_exchange(exchange) + fund_peer(peer, env, "EUR:5", exchange=exchange) + uri = peer.peer_send(amount, exchange) + app.handle_uri(uri) + # With terms the prompt's button is "Review terms of service" first, and + # the review screen has to be accepted before the payment can be. + if app.dev.wait_for(r"(?i)Review terms of service|Receive payment|accept", + timeout=60).find(r"(?i)Review terms of service") is not None: + app.dev.tap_text(r"(?i)Review terms of service", timeout=20) + time.sleep(2) + app.dev.tap_text(r"(?i)^Accept Terms of Service$", timeout=20) + time.sleep(3) + # "Receive payment" is both the screen's heading and its button, and + # tap_text takes the first match -- the heading, which is not clickable, so + # the payment was never accepted and the balance stayed at zero while the + # scenario reported success. Tap the lowest clickable match instead. + tap_lowest_button(app, r"(?i)^Receive payment$|accept|confirm") + return app.dev.dump() + + +def peer_pay_invoice(app: Wallet, env: Env | None = None, amount: str = "EUR:1", + peer: CliWallet | None = None) -> Screen: + """The CLI wallet invoices the app; the app pays it.""" + env = env or Env.load() + peer = peer or CliWallet() + peer.add_exchange(env.exchange) + uri = peer.peer_request(amount, exchange=env.exchange) + app.handle_uri(uri) + # Paying an invoice needs the exchange's terms accepted first, like any + # other first use of it. + if app.dev.wait_for(r"(?i)Review terms of service|^Pay\b|accept|confirm", + timeout=60).find(r"(?i)Review terms of service") is not None: + app.dev.tap_text(r"(?i)Review terms of service", timeout=20) + time.sleep(2) + app.dev.tap_text(r"(?i)^Accept Terms of Service$", timeout=20) + time.sleep(3) + app.dev.tap_text(r"(?i)^pay\b|accept|confirm", timeout=60) + return app.dev.dump() diff --git a/wallet-simulator/driver/smoke_pay.py b/wallet-simulator/driver/smoke_pay.py @@ -0,0 +1,92 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""P0 smoke test: pay a merchant order, then take a refund. + +Assumes the wallet already holds coins (run smoke_withdraw.py first); it keeps +the app's state rather than wiping it, because paying from an existing balance +is the state the explorer will spend most of its time in. +""" + +from __future__ import annotations + +import json +import sys +import time + +from device import Device +from stack import Env, Merchant +from wallet import Wallet + +PRICE = "EUR:2" +REFUND = "EUR:1" + + +def main() -> int: + env = Env.load() + merchant = Merchant(env.merchant) + + dev = Device(sys.argv[1] if len(sys.argv) > 1 else "emulator-5554") + app = Wallet(dev) + dev.logcat(clear=True) + app.home() + print("balances on screen:", app.balances()) + + order = merchant.create_order(PRICE, summary="Simulator test order") + print("order:", order["order_id"], "pay uri:", order["pay_uri"]) + + screen = app.handle_uri(order["pay_uri"]) + print("\n--- payment prompt ---") + print(screen) + + # The button carries the amount: "Pay €2.00". + dev.tap_text(r"(?i)^pay\b|confirm payment", timeout=60) + time.sleep(4) + print("\n--- after paying ---") + print(dev.dump()) + + paid = False + for _ in range(20): + status = merchant.order_status(order["order_id"], order["token"]) + if status.get("order_status") == "paid": + paid = True + break + time.sleep(2) + print("\nmerchant order status:", json.dumps( + {k: v for k, v in merchant.order_status(order['order_id'], order['token']).items() + if k in ("order_status", "refunded", "wired", "deposit_total")}, indent=2)) + if not paid: + print("ORDER NOT PAID") + + # Refund: the merchant grants it, the wallet picks it up from the URI the + # merchant hands back. + res = merchant.refund(order["order_id"], REFUND) + refund_uri = res.get("taler_refund_uri") + print("\nrefund uri:", refund_uri) + if refund_uri: + screen = app.handle_uri(refund_uri) + print("\n--- after refund uri ---") + print(screen) + + log = dev.logcat() + bad = [ln for ln in log.splitlines() + if "FATAL EXCEPTION" in ln or "ANR in" in ln + or "unexpected exception" in ln.lower() or "invariant" in ln.lower()] + print(f"\noracle hits in logcat: {len(bad)}") + for ln in bad[:10]: + print(" ", ln) + return 0 if paid else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/wallet-simulator/driver/smoke_withdraw.py b/wallet-simulator/driver/smoke_withdraw.py @@ -0,0 +1,106 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""P0 smoke test: withdraw from the local libeufin bank into the wallet app. + +Prints every screen it sees, because the labels it discovers are what the +scenario library will later be written against. +""" + +from __future__ import annotations + +import sys +import time + +from device import Device +from stack import Bank, Env, provision +from wallet import Wallet + +AMOUNT = "EUR:10" + + +def main() -> int: + env = Env.load() + bank = Bank(env.bank) + print("provisioning:", provision(env)) + + dev = Device(sys.argv[1] if len(sys.argv) > 1 else "emulator-5554") + app = Wallet(dev) + dev.logcat(clear=True) + dev.stop() + # A fresh profile in developer mode: taler+http:// URIs are rejected + # outright without it. + app.fresh_start(dev_mode=True) + print("\n--- home (developer mode on) ---") + print(dev.dump()) + + before = bank.balance("wallet1", "walletpass1") + op = bank.create_withdrawal("wallet1", "walletpass1", AMOUNT) + uri = op["taler_withdraw_uri"] + print(f"\nbank balance before: {before}\nwithdraw uri: {uri}") + + dev.send_uri(uri) + screen = dev.wait_for(r"(?i)withdraw|exchange|confirm|accept|terms", timeout=90) + print("\n--- withdrawal screen ---") + print(screen) + + # The exchange is unknown to a fresh wallet, so terms of service have to be + # accepted before the withdrawal can be confirmed. Both labels are tried, + # in the order they can appear. + for pattern in (r"(?i)^(accept|agree|i accept)", r"(?i)confirm|withdraw now|^withdraw$"): + try: + tapped = dev.tap_text(pattern, timeout=20) + print(f"\ntapped {pattern!r} on screen with {tapped.texts()}") + time.sleep(3) + except TimeoutError as e: + print(f"\n(no match for {pattern!r}: {e})") + + print("\n--- after confirm attempt ---") + print(dev.dump()) + + status = bank.withdrawal_status(op["withdrawal_id"]) + print("\nbank-side withdrawal status:", status) + + # The wallet has selected the exchange and registered the reserve; the + # human step left is confirming in the bank, which the host does here. + bank.confirm_withdrawal("wallet1", "walletpass1", op["withdrawal_id"]) + print("confirmed in bank") + + deadline = time.monotonic() + 120 + seen = None + while time.monotonic() < deadline: + screen = dev.dump() + seen = screen.texts() + if screen.find(r"EUR|€|\d+\.\d\d"): + break + time.sleep(3) + print("\n--- final wallet screen ---") + print("\n".join(str(t) for t in (seen or []))) + print("\nbank balance after:", bank.balance("wallet1", "walletpass1")) + + log = dev.logcat() + bad = [ln for ln in log.splitlines() + if "FATAL EXCEPTION" in ln or "ANR in" in ln + or "unexpected exception" in ln.lower() + or "invariant" in ln.lower()] + print(f"\noracle hits in logcat: {len(bad)}") + for ln in bad[:10]: + print(" ", ln) + with open("/opt/taler-sim/run/smoke-logcat.txt", "w") as f: + f.write(log) + print("full logcat: /opt/taler-sim/run/smoke-logcat.txt") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/wallet-simulator/driver/stack.py b/wallet-simulator/driver/stack.py @@ -0,0 +1,508 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Host-side clients for the simulator's Taler stack. + +Everything the wallet's counterparties do happens here over HTTP: the bank +(libeufin corebank) registers customers, opens and confirms withdrawals and +reports balances; the merchant creates instances, orders and refunds. Keeping +the counterparties on the host makes a scenario deterministic — the only thing +being explored is the wallet. +""" + +from __future__ import annotations + +import base64 +import json +import os +from pathlib import Path +from urllib.parse import quote +import uuid +import urllib.error +import urllib.request +from dataclasses import dataclass +from typing import Any, Optional + +DEFAULT_ENV = "/opt/taler-sim/run/stack/env.json" + + +class HttpError(RuntimeError): + def __init__(self, status: int, body: str, url: str): + super().__init__(f"HTTP {status} for {url}: {body[:300]}") + self.status = status + self.body = body + + +def _request( + url: str, + method: str = "GET", + payload: Any = None, + auth: Optional[tuple[str, str]] = None, + timeout: int = 30, +) -> Any: + data = None + headers = {"Accept": "application/json"} + if payload is not None: + data = json.dumps(payload).encode() + headers["Content-Type"] = "application/json" + if auth: + token = base64.b64encode(f"{auth[0]}:{auth[1]}".encode()).decode() + headers["Authorization"] = f"Basic {token}" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + try: + with urllib.request.urlopen(req, timeout=timeout) as resp: + body = resp.read().decode() + except urllib.error.HTTPError as e: + raise HttpError(e.code, e.read().decode(errors="replace"), url) from None + if not body.strip(): + return None + try: + return json.loads(body) + except json.JSONDecodeError: + return body + + +@dataclass +class Env: + """The URLs and credentials stack.sh wrote out.""" + + exchange: str + merchant: str + bank: str + donau: str + auditor: str + currency: str + # Only there when backend/exchange2.sh is running beside the stack. + exchange2: str | None = None + + @classmethod + def load(cls, path: str = DEFAULT_ENV) -> "Env": + with open(path) as f: + d = json.load(f) + return cls( + exchange=d["exchange"], merchant=d["merchant"], bank=d["bank"], + donau=d["donau"], auditor=d["auditor"], currency=d["currency"], + exchange2=d.get("exchange2"), + ) + + +class Bank: + """libeufin-bank corebank API.""" + + def __init__(self, base_url: str): + self.base = base_url.rstrip("/") + + def config(self) -> Any: + return _request(f"{self.base}/config") + + def register(self, username: str, password: str, name: str) -> Any: + # Passwords shorter than 8 characters are rejected by the bank. + return _request(f"{self.base}/accounts", "POST", + {"username": username, "password": password, "name": name}) + + def account(self, username: str, password: str) -> Any: + return _request(f"{self.base}/accounts/{username}", auth=(username, password)) + + def balance(self, username: str, password: str) -> str: + acc = self.account(username, password) + bal = acc["balance"] + sign = "-" if bal["credit_debit_indicator"] == "debit" else "" + return f"{sign}{bal['amount']}" + + def payto(self, username: str, password: str) -> str: + return self.account(username, password)["payto_uri"] + + def create_withdrawal(self, username: str, password: str, amount: str) -> Any: + """Open a withdrawal operation; returns withdrawal_id + taler_withdraw_uri. + + A round spends more than the registration bonus, so an exhausted + account is topped up and the request retried once rather than failing + the scenario with something that looks like a wallet bug. + """ + try: + return _request(f"{self.base}/accounts/{username}/withdrawals", "POST", + {"amount": amount}, auth=(username, password)) + except HttpError as e: + if e.status != 409 or "5102" not in e.body: + raise + self.top_up(username, "EUR:2000") + return _request(f"{self.base}/accounts/{username}/withdrawals", "POST", + {"amount": amount}, auth=(username, password)) + + def withdrawal_status(self, wid: str) -> Any: + return _request(f"{self.base}/withdrawals/{wid}") + + def confirm_withdrawal(self, username: str, password: str, wid: str) -> Any: + """The step a human would take in the bank's own UI.""" + return _request(f"{self.base}/accounts/{username}/withdrawals/{wid}/confirm", + "POST", {}, auth=(username, password)) + + def abort_withdrawal(self, username: str, password: str, wid: str) -> Any: + return _request(f"{self.base}/accounts/{username}/withdrawals/{wid}/abort", + "POST", {}, auth=(username, password)) + + ADMIN = ("admin", "secret-password") # set by taler-unified-setup.sh + + def top_up(self, username: str, amount: str = "EUR:200") -> Any: + """Credit a customer from the admin account. + + Scenario runs spend the registration bonus quickly, and an exhausted + bank account looks just like a wallet bug in the logs, so accounts get + topped up between iterations. Admin may read any account, so the + customer's own password is not needed. + """ + account = _request(f"{self.base}/accounts/{username}", auth=self.ADMIN) + payto = account["payto_uri"] + joiner = "&" if "?" in payto else "?" + return _request( + f"{self.base}/accounts/{self.ADMIN[0]}/transactions", "POST", + {"payto_uri": f"{payto}{joiner}amount={amount}&message=simulator top up"}, + auth=self.ADMIN, + ) + + def transfer(self, username: str, password: str, to_payto: str, + amount: str, subject: str) -> Any: + """Pay from one customer account to any payto URI, with a subject. + + This is how a manual (not bank-integrated) withdrawal is completed: the + wallet shows a subject -- the reserve public key -- and the user makes + the transfer in their own bank. The exchange's wirewatch then sees the + credit and the withdrawal goes through. + """ + joiner = "&" if "?" in to_payto else "?" + return _request( + f"{self.base}/accounts/{username}/transactions", "POST", + {"payto_uri": f"{to_payto}{joiner}amount={amount}" + f"&message={quote(subject)}"}, + auth=(username, password), + ) + + def transactions(self, username: str, password: str) -> Any: + return _request(f"{self.base}/accounts/{username}/transactions", + auth=(username, password)) + + +class Merchant: + """taler-merchant backend, private and management APIs.""" + + def __init__(self, base_url: str, instance: str = "sim"): + self.base = base_url.rstrip("/") + self.instance = instance + + @property + def private(self) -> str: + return f"{self.base}/instances/{self.instance}/private" + + def config(self) -> Any: + return _request(f"{self.base}/config") + + def exists(self) -> bool: + try: + _request(f"{self.base}/instances/{self.instance}/config") + return True + except HttpError: + return False + + def create_instance(self, name: str = "Simulator Shop") -> None: + """Idempotent. + + The management API is only open while the instance does not exist yet: + a second POST for the same id is an update and comes back 401 (or 409), + so an existing instance is probed for first and both codes tolerated. + """ + if self.exists(): + return + try: + _request(f"{self.base}/management/instances", "POST", { + "id": self.instance, + "name": name, + "auth": {"method": "external"}, + "address": {}, + "jurisdiction": {}, + "use_stefan": True, + "default_wire_transfer_delay": {"d_us": 3600 * 1000 * 1000}, + "default_pay_delay": {"d_us": 3600 * 1000 * 1000}, + }) + except HttpError as e: + if e.status not in (401, 409): + raise + + def add_account(self, payto_uri: str) -> Any: + """Idempotent: re-adding the same account comes back 409.""" + try: + return _request(f"{self.private}/accounts", "POST", {"payto_uri": payto_uri}) + except HttpError as e: + if e.status != 409: + raise + return None + + def create_otp_device(self, device_id: str = "simpos", + key: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", + algorithm: str = "TOTP_WITHOUT_PRICE") -> Any: + """A point-of-sale confirmation device. Idempotent. + + An order that names one gets a `pos_confirmation` in its pay reply, + which is the only thing that makes the wallet show its TOTP screen. + The key is RFC 3548 base32, not Crockford. + """ + body = { + "otp_device_id": device_id, + "otp_device_description": "Simulator point of sale", + "otp_algorithm": algorithm, + "otp_key": key, + "otp_ctr": 0, + } + try: + return _request(f"{self.private}/otp-devices", "POST", body) + except HttpError as e: + if e.status != 409: + raise + return None + + def create_order( + self, + amount: str, + summary: str = "Simulator order", + fulfillment_url: str | None = None, + otp_id: str | None = None, + **order_extra: Any, + ) -> dict: + """Create an order and return it with its taler://pay URI. + + Each order gets its own fulfillment URL unless one is given: the + wallet treats a second order with a fulfillment URL it has already + paid for as a repurchase and answers "You've already paid for this + purchase", which silently skips the payment a scenario was testing. + """ + if fulfillment_url is None: + fulfillment_url = ( + "https://example.com/fulfillment/" + f"{uuid.uuid4().hex[:16]}" + ) + order = { + "amount": amount, + "summary": summary, + "fulfillment_url": fulfillment_url, + **order_extra, + } + # otp_id is a sibling of "order", not a field of it. + body: dict = {"order": order} + if otp_id is not None: + body["otp_id"] = otp_id + res = _request(f"{self.private}/orders", "POST", body) + status = self.order_status(res["order_id"], res.get("token")) + return { + "order_id": res["order_id"], + "token": res.get("token"), + "pay_uri": status.get("taler_pay_uri"), + "status": status, + } + + def create_token_family(self, slug: str = "simdiscount", + kind: str = "discount", + name: str = "Simulator discount") -> Any: + """A token family, so orders can issue and demand tokens. + + Discount tokens are what the wallet shows under "Discounts"; nothing + reaches that screen until an order issues one. + """ + body = { + "slug": slug, + "name": name, + "description": f"{kind} tokens issued by the simulator", + "duration": {"d_us": 365 * 24 * 3600 * 1000 * 1000}, + "validity_granularity": {"d_us": 24 * 3600 * 1000 * 1000}, + "start_offset": {"d_us": 0}, + "kind": kind, + } + try: + return _request(f"{self.private}/tokenfamilies", "POST", body) + except HttpError as e: + if e.status != 409: + raise + return None + + def create_v1_order(self, choices: list[dict], summary: str = "Simulator v1 order", + fulfillment_url: str = "https://example.com/fulfillment", + **extra: Any) -> dict: + """A version 1 ("mumimo") order: several choices, with token inputs + and outputs.""" + order = { + "version": 1, + "summary": summary, + "fulfillment_url": fulfillment_url, + "choices": choices, + **extra, + } + res = _request(f"{self.private}/orders", "POST", {"order": order}) + status = self.order_status(res["order_id"], res.get("token")) + return { + "order_id": res["order_id"], + "token": res.get("token"), + "pay_uri": status.get("taler_pay_uri"), + "status": status, + } + + @staticmethod + def token_output(slug: str = "simdiscount", count: int = 1) -> dict: + return {"type": "token", "token_family_slug": slug, "count": count, + "key_index": 0} + + @staticmethod + def token_input(slug: str = "simdiscount", count: int = 1) -> dict: + return {"type": "token", "token_family_slug": slug, "count": count} + + def create_template(self, template_id: str = "simtemplate", + amount: str = "EUR:1") -> Any: + """A reusable order template, paid through a taler://pay-template URI.""" + body = { + "template_id": template_id, + "template_description": "Simulator template", + "template_contract": { + "amount": amount, + "minimum_age": 0, + "pay_duration": {"d_us": 3600 * 1000 * 1000}, + }, + } + try: + return _request(f"{self.private}/templates", "POST", body) + except HttpError as e: + if e.status != 409: + raise + return None + + def order_status(self, order_id: str, token: Optional[str] = None) -> Any: + url = f"{self.private}/orders/{order_id}" + if token: + url += f"?token={token}" + return _request(url) + + def refund(self, order_id: str, amount: str, reason: str = "simulator refund") -> Any: + return _request(f"{self.private}/orders/{order_id}/refund", "POST", + {"refund": amount, "reason": reason}) + + def delete_order(self, order_id: str) -> Any: + return _request(f"{self.private}/orders/{order_id}", "DELETE") + + +CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ" + + +def encode_crock(data: bytes) -> str: + """The base32 Taler uses for hashes and keys (GNUNET_STRINGS_data_to_string). + + Crockford's alphabet, big-endian bit order, no padding. Verified against + the exchange's own signing keys: the hex in `exchange.exchange_sign_keys` + encodes to exactly the strings /keys publishes. + """ + out = [] + bits = vbit = rpos = 0 + while rpos < len(data) or vbit > 0: + if rpos < len(data) and vbit < 5: + bits = (bits << 8) | data[rpos] + rpos += 1 + vbit += 8 + if vbit < 5: + bits <<= (5 - vbit) + vbit = 5 + out.append(CROCKFORD[(bits >> (vbit - 5)) & 31]) + vbit -= 5 + return "".join(out) + + +def revoke_denomination(denom_pub_hash: bytes | str, + conf: str = "sim.conf", + run_dir: str = "/opt/taler-sim/run/stack") -> str: + """Revoke a denomination key, as an exchange operator would. + + Destructive and stack-wide: the denomination stays revoked until the stack + is started again, and every wallet holding one of its coins has to recoup. + """ + import subprocess + crock = (denom_pub_hash if isinstance(denom_pub_hash, str) + else encode_crock(denom_pub_hash)) + proc = subprocess.run( + ["taler-exchange-offline", "-c", conf, + "revoke-denomination", crock, "upload"], + cwd=run_dir, capture_output=True, text=True, timeout=120, + ) + if proc.returncode != 0: + raise RuntimeError(f"revoking {crock} failed: " + f"{(proc.stderr or proc.stdout).strip()[:300]}") + return crock + + +def provision(env: Optional[Env] = None, + # Seven, not five: the harness has AVDs for workers 0..6 and + # worker 6 (the version matrix) banks as wallet7. A plain + # `python3 stack.py` used to leave that account out, and every + # scenario on that worker then died with + # `HTTP 401 ... accounts/wallet7 ... Unknown account` -- which + # looked exactly like a platform failure in the matrix. + workers: int = int(os.environ.get("SIM_WORKERS", "7"))) -> dict: + """Make the stack usable by a wallet: one merchant instance with a bank + account, and one bank customer per parallel worker.""" + env = env or Env.load() + bank, merchant = Bank(env.bank), Merchant(env.merchant) + out: dict[str, Any] = {"currency": env.currency} + # A stack start wipes the exchange database, so its master key is new while + # the peer wallets still remember the old one and refuse to talk to it + # ("the exchange changed its master public key", code 7066). Provisioning + # runs right after every stack start, which is exactly when they should be + # thrown away. + out["cli_wallets_removed"] = sorted( + p.name for p in Path("/opt/taler-sim/run").glob("cli-wallet-*.sqlite3*") + ) + for stale in Path("/opt/taler-sim/run").glob("cli-wallet-*.sqlite3*"): + stale.unlink(missing_ok=True) + accounts = [("merchant", "merchantpass1", "Simulator Shop")] + accounts += [(f"wallet{i + 1}", f"walletpass{i + 1}", f"Wallet {i + 1}") + for i in range(workers)] + # One more per worker for the taler-wallet-cli peer wallet. + accounts += [(f"peer{i + 1}", f"peerpass{i + 1}", f"Peer {i + 1}") + for i in range(workers)] + for user, password, name in accounts: + try: + bank.register(user, password, name) + out[f"{user}_registered"] = True + except HttpError as e: + # 409 means the account survived from an earlier run. + if e.status != 409: + raise + out[f"{user}_registered"] = False + # Keep every account well above what one round can spend: ~75 scenarios + # share these accounts, and a fresh one holds only the EUR:100 + # registration bonus. + for user, password, _ in accounts[1:]: + try: + balance = bank.balance(user, password) + value = float(balance.split(":")[1]) + if value < 1000: + bank.top_up(user, "EUR:2000") + out[f"{user}_topped_up"] = True + except (HttpError, ValueError, IndexError) as e: + out[f"{user}_top_up_error"] = str(e)[:120] + merchant.create_instance() + merchant.add_account(bank.payto("merchant", "merchantpass1")) + out["merchant_instance"] = merchant.instance + out["balances"] = { + f"wallet{i + 1}": bank.balance(f"wallet{i + 1}", f"walletpass{i + 1}") + for i in range(workers) + } + return out + + +if __name__ == "__main__": + import sys + e = Env.load(sys.argv[1] if len(sys.argv) > 1 else DEFAULT_ENV) + print(json.dumps(provision(e), indent=2)) diff --git a/wallet-simulator/driver/suite.py b/wallet-simulator/driver/suite.py @@ -0,0 +1,5755 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Feature scenarios, run as a suite. + +Each scenario walks one feature of the wallet deliberately, rather than at +random: the transaction list and its per-transaction actions, exchange +management, every settings row, the scan screen's manual entry, deposits and +peer payments. Random exploration finds the sequences nobody thought of; +these make sure the obvious ones are covered at all. + +A scenario failing because a label moved is *not* a finding — it is recorded +as a driver error so the two never get confused. Real findings come from the +oracles in oracles.py. + + python3 suite.py # every scenario + python3 suite.py history exchange_add_remove + python3 suite.py --list +""" + +from __future__ import annotations + +import json +import os +import re +import sys +import time +from pathlib import Path +import traceback +from dataclasses import dataclass, field +from typing import Callable, Optional + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "corpus")) + +import oracles # noqa: E402 +import scenarios as flows # noqa: E402 +import uris as corpus # noqa: E402 +from cli import CliWallet # noqa: E402 +from twister import FAULTS, Twister, TwisterUnavailable # noqa: E402 +from device import PKG, Device, Screen # noqa: E402 +from episode import Episode # noqa: E402 +import stack as stack_mod # noqa: E402 +from stack import Bank, Env, Merchant # noqa: E402 + +WORKER = int(os.environ.get("SIM_WORKER", "0")) +SERIAL = os.environ.get("SIM_SERIAL", f"emulator-{5554 + 2 * WORKER}") +OUT = Path("/opt/taler-sim/run/out") +# Where the JaCoCo dumps land. Settable so that a run against a *different* +# build -- a patched APK, say -- can keep its dumps out of the campaign's +# report: JaCoCo keys classes by a hash of their bytecode, so dumps from two +# builds cannot be merged. +COVERAGE = Path(os.environ.get("SIM_COVERAGE_DIR", + "/opt/taler-sim/run/coverage")) +LOCAL_EXCHANGE = "http://localhost:8081/" +# The second exchange, if backend/exchange2.sh has been started beside the +# stack. Scenarios that need a choice check for it rather than assume it. +SECOND_EXCHANGE = "http://localhost:8091/" +# Services deployed beside the stack, with their own databases: the Taler +# mailbox (whose URL the wallet lets you type in) and the Taler directory +# (whose URL the app hard-codes, so only wallet-core can be pointed at it). +LOCAL_MAILBOX = "http://localhost:11000/" +LOCAL_TALDIR = "http://localhost:11001/" + + +class Ctx: + """What a scenario gets to work with.""" + + def __init__(self, ep: Episode, env: Env): + self.ep = ep + self.dev = ep.dev + self.app = ep.app + self.env = env + self.bank = Bank(env.bank) + self.merchant = Merchant(env.merchant) + self.cli = CliWallet() + self.notes: list[str] = [] + + # Tolerant helpers: a scenario says what it wants to touch, and missing + # optional elements do not abort the walk. + + def tap(self, pattern: str, timeout: int = 12) -> bool: + try: + self._tap_watching(pattern, timeout) + return True + except TimeoutError: + return False + + def must_tap(self, pattern: str, timeout: int = 30) -> None: + self._tap_watching(pattern, timeout) + + def accept_tos(self) -> bool: + """Get past the exchange's terms of service, if it has any.""" + accepted = flows.accept_tos(self.app) + if accepted: + self.note("accepted the exchange's terms of service") + self.check() + return accepted + + def tap_exact(self, pattern: str, timeout: int = 12) -> bool: + """Tap the matching node's own centre, with no hunt for an ancestor. + + `tap` and `tap_button` look for a clickable ancestor or neighbour when + the matching node is not itself clickable, which is right for a label + inside a button and wrong in three places this campaign has now hit: + + * a document picker's rows, where the hunt lands somewhere that + dismisses the picker without selecting (`pick_file_in_picker`); + * a Compose `AlertDialog`'s text buttons, where it dismissed the + mailbox address dialog instead of pressing Copy; + * a dropdown item, whose clickable ancestor is the menu rather than + the item. + + In all three the node's own centre is inside the real touch target, so + tapping it directly is both simpler and correct. Use this when the + thing being tapped is a row, a dialog button or a menu item. + """ + deadline = time.time() + timeout + rx = re.compile(pattern, re.I) + while time.time() < deadline: + screen = self.dev.dump() + node = next((n for n in screen.labelled() + if rx.search(n.label.strip())), None) + if node is not None: + self.dev.tap(*node.center) + return True + time.sleep(1) + return False + + def tap_button(self, pattern: str, timeout: int = 12) -> bool: + """Tap a *button* whose label is used elsewhere on the same screen. + + Several screens give the title and the submit button the same string -- + "Add account" is the app bar title, the list screen's add icon and the + form's submit button -- and `find` returns the first match, which is + the title. A title is not clickable, so its tap goes nowhere (or, via + the neighbour search, to the back arrow). This picks the lowest + matching node that is clickable or sits inside something clickable. + """ + deadline = time.time() + timeout + rx = re.compile(pattern, re.I) + while time.time() < deadline: + screen = self.dev.dump() + matches = [n for n in screen.labelled() if rx.search(n.label)] + targets = [] + for n in matches: + target = screen.tap_target(n) + if not (target.clickable and target.enabled): + continue + # tap_target also looks at clickable *neighbours*, which on + # this screen means a tab beside the title: a disabled submit + # button would otherwise be "tapped" by switching tabs. Only + # a target that is the label itself, or contains it, counts. + x, y = n.center + x1, y1, x2, y2 = target.bounds + if target is n or (x1 <= x <= x2 and y1 <= y <= y2): + targets.append(target) + if targets: + lowest = max(targets, key=lambda t: t.center[1]) + before = screen.signature() + self.dev.tap(*lowest.center) + time.sleep(1.2) + after = self.dev.dump() + fresh = self.ep.session.add(oracles.silent_failure( + self.dev, pattern, before, after.signature())) + for finding in fresh: + self.ep._capture(finding, after, None) + return True + time.sleep(1) + return False + + def _tap_watching(self, pattern: str, timeout: int) -> None: + """Tap, and notice when the tap achieves nothing but an error.""" + before = self.dev.dump() + screen = self.dev.tap_text(pattern, timeout=timeout) + time.sleep(1.2) + after = self.dev.dump() + fresh = self.ep.session.add(oracles.silent_failure( + self.dev, pattern, before.signature(), after.signature())) + for finding in fresh: + self.ep._capture(finding, after, None) + + def see(self, pattern: str, timeout: int = 15) -> Optional[Screen]: + try: + return self.dev.wait_for(pattern, timeout=timeout) + except TimeoutError: + return None + + def set_amount(self, chip: str = "€5.00", digits: str = "500") -> bool: + """Choose an amount, by quick-amount chip if the screen offers one. + + The amount fields do not always take injected text — focus does not + always follow the tap — but every amount screen also offers preset + chips, which is what a user would reach for anyway. + """ + screen = self.dev.dump() + preset = screen.find(rf"(?i)^{re.escape(chip)}$") + if preset is not None: + self.dev.tap_node(preset, screen) + time.sleep(1.5) + if self.dev.dump().find(rf"(?i){re.escape(chip)}"): + return True + return self.fill(digits) + + def require(self, pattern: str, timeout: int = 30) -> Screen: + """Insist on reaching a screen. + + Without this a scenario whose entry point silently fails to open still + reports "ok" having exercised nothing, which is worse than a failure: + it hides a gap behind a green row. + """ + screen = self.see(pattern, timeout=timeout) + if screen is None: + raise RuntimeError( + f"expected a screen matching {pattern!r}; " + f"got {self.dev.dump().texts()}" + ) + return screen + + def note(self, text: str) -> None: + self.notes.append(text) + + def uri_from_logcat(self, kind: str, timeout: int = 30) -> str: + """Pull a URI the wallet just generated out of wallet-core's log. + + The Send/Request screens show the URI as a QR code and in a copy + button, neither of which can be read from the view hierarchy, but + wallet-core logs its own response. + """ + import re as _re + pattern = _re.compile(r"taler(?:\+http)?://" + kind + r"/[A-Za-z0-9:._/?=&%-]+") + deadline = time.time() + timeout + while time.time() < deadline: + for match in pattern.finditer(self.dev.logcat()): + return match.group(0).rstrip('\\"\',.)') + time.sleep(2) + raise RuntimeError(f"no taler://{kind}/ URI in the log") + + def fill(self, value: str, which: int = 0, clear: bool = False) -> bool: + """Type into the n-th editable field on the current screen. + + Amount fields append digits from the right, as a cash register does: + typing "5" yields 0.05 and "500" yields 5.00. Scenarios therefore pass + the digit sequence they want, not a decimal string. + + `clear` empties a pre-filled field first. Deleting backwards from the + tap position leaves whatever was to the right of it -- which is how + "https://mailbox.gnunet.org" became + "http://localhost:11000unet.org" -- so the cursor goes to the end + first. + """ + screen = self.dev.dump() + fields = screen.editable() + if len(fields) <= which: + return False + field = fields[which] + if clear: + # Tapping the node's centre puts the cursor in the middle of the + # text, and KEYCODE_MOVE_END does not move it in a Compose field, + # so deleting backwards left the tail behind: tap just inside the + # right-hand edge instead, where the cursor lands after the last + # character. + x1, y1, x2, y2 = field.bounds + self.dev.tap(max(x1 + 1, x2 - 12), (y1 + y2) // 2) + time.sleep(0.5) + self.dev.shell("input keyevent " + " ".join(["KEYCODE_DEL"] * 80), + check=False) + time.sleep(0.5) + else: + self.dev.tap_node(field, screen) + time.sleep(0.5) + self.dev.type_text(value) + time.sleep(0.5) + return True + + def check(self) -> None: + """Run the oracles against the current screen.""" + self.ep.observe() + + def back_to_home(self) -> None: + self.app.home() + + +@dataclass +class Scenario: + name: str + setup: str # fresh | funded | paid | keep + fn: Callable[[Ctx], None] + about: str = "" + # Finding kinds this scenario provokes on purpose: corrupting the database + # is supposed to produce an init error, and pointing the wallet at a dead + # host is supposed to produce connection failures. Reporting those as + # defects every round would bury the real ones. + expects: tuple[str, ...] = () + + +REGISTRY: dict[str, Scenario] = {} + + +def scenario(name: str, setup: str = "keep", about: str = "", + expects: tuple[str, ...] = ()) -> Callable: + def register(fn: Callable[[Ctx], None]) -> Callable[[Ctx], None]: + REGISTRY[name] = Scenario(name=name, setup=setup, fn=fn, + about=about or fn.__doc__ or "", expects=expects) + return fn + return register + + +# --------------------------------------------------------------- navigation --- + +# Section headers and chips that sit below "Recent transactions" but are not +# transactions themselves. +BELOW_BUT_NOT_A_TRANSACTION = ( + "all", "discounts", "passes", "donation statements", "other assets", + "settings", "internal event log", "scan qr code", "contacts", "pending", + "where to pay", "shopping", + # The dedicated transactions screen puts the balance card between its app + # bar and the list, and that card carries an unsigned amount and a + # relative time -- enough to be taken for a transaction, whose row then + # swallowed every long press aimed at the first "transaction". + "balance", +) +# A transaction row always carries a relative time and a signed amount; either +# is enough to tell it apart from a header or a chip. +TIME_LABEL = re.compile(r"(?i)\b(ago|yesterday|today)\b|\d{1,2}:\d\d|\d{4}") +AMOUNT_LABEL = re.compile(r"^[+\-\u2212]?\s*\d+[.,]\d\d$") +# Only a transaction's amount carries a sign; a balance is printed bare. +SIGNED_AMOUNT_LABEL = re.compile(r"^[+\-\u2212]\s*\d+[.,]\d\d$") + + +def open_transactions(c: Ctx) -> Screen: + """The main screen lists the recent transactions itself. + + There is no separate list screen: the balance pager shows a "Recent + transactions" header with the transactions under it, and tapping one opens + its detail screen. + """ + c.back_to_home() + screen = c.dev.dump() + if screen.find(r"(?i)^Recent transactions$") is None: + try: + screen = c.app.scroll_to_text(r"(?i)^Recent transactions$", max_scrolls=4) + except TimeoutError: + c.note("no transaction section on the main screen") + return screen + + +def open_exchange_list(c: Ctx) -> None: + """Settings -> Payment services, the exchange list.""" + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Payment services$") + c.must_tap(r"(?i)^Payment services$") + c.see(r"(?i)Add payment service|Currency:|No payment services") + + +def exchange_menu(c: Ctx, which: str = "localhost") -> bool: + """Open the per-exchange menu, whose label embeds the exchange URL.""" + return c.tap(rf"(?i)^Menu: .*{which}", timeout=25) + + +def transaction_rows(screen: Screen, + header: str = r"(?i)^Recent transactions$", + signed_only: bool = False) -> list: + """One tap target per transaction listed under the header. + + Nodes are grouped into horizontal bands, because a row is several nodes + (time, title, amount); a band counts as a transaction when something in it + looks like a time or a signed amount, which keeps the filter chips and the + "Discounts"/"Passes" sections out. + + The default header is the main screen's section title. The dedicated + transactions screen behind the "All" chip has no such header -- its rows + sit under the app bar -- so a caller there passes the screen's own title + instead, and the banding works the same way. + """ + header_node = screen.find(header) + if header_node is None: + return [] + top = header_node.center[1] + bands: dict[int, list] = {} + for node in screen.tappable(): + label = node.label.strip() + if not label or node.center[1] <= top: + continue + bands.setdefault(node.center[1] // 110, []).append(node) + rows = [] + for band in sorted(bands): + nodes = bands[band] + labels = [n.label.strip() for n in nodes] + if any(l.lower() in BELOW_BUT_NOT_A_TRANSACTION for l in labels): + continue + # With signed_only, a band needs an amount carrying a sign. The + # dedicated transactions screen shows a balance card above the list, + # and its parts -- the currency, the exchange URL, the bare amount -- + # band into something that looks exactly like a transaction; the first + # "row" there was the exchange URL, which swallowed every long press. + amount = SIGNED_AMOUNT_LABEL if signed_only else AMOUNT_LABEL + if signed_only: + if not any(amount.match(l) for l in labels): + continue + elif not any(TIME_LABEL.search(l) or amount.match(l) for l in labels): + continue + # Prefer the title over the time or the amount as the tap target. + target = next((n for n in nodes + if not TIME_LABEL.search(n.label.strip()) + and not AMOUNT_LABEL.match(n.label.strip()) + and "://" not in n.label), nodes[0]) + rows.append(target) + return rows + + +# ---------------------------------------------------------------- scenarios --- + +@scenario("history", setup="paid", about="transaction list, details, JSON view, filters") +def s_history(c: Ctx) -> None: + screen = open_transactions(c) + c.note(f"main screen: {screen.texts()[:14]}") + rows = transaction_rows(screen) + c.note(f"{len(rows)} transaction rows: {[n.label[:28] for n in rows]}") + opened = 0 + for index in range(min(len(rows), 4)): + screen = open_transactions(c) + rows = transaction_rows(screen) + if index >= len(rows): + break + c.dev.tap_node(rows[index], screen) + time.sleep(2) + detail = c.dev.dump() + if detail.find(r"(?i)^Show JSON$|completed successfully|^Delete$|^Transaction$"): + opened += 1 + c.note(f"detail {index}: {detail.texts()[:10]}") + c.check() + # The raw JSON view is dev-mode only and renders the whole + # transaction record. + if c.tap(r"(?i)^Show JSON$", timeout=10): + c.check() + c.dev.back() + time.sleep(1) + else: + c.note(f"row {index} did not open a detail screen: {detail.texts()[:8]}") + c.dev.back() + time.sleep(1) + c.note(f"opened {opened} transaction detail screens") + if opened == 0 and rows: + raise RuntimeError("transaction rows present but none opened a detail screen") + c.check() + + +@scenario("history_delete", setup="paid", about="delete a finished transaction") +def s_history_delete(c: Ctx) -> None: + screen = open_transactions(c) + rows = transaction_rows(screen) + before = len(rows) + if not rows: + raise RuntimeError(f"no transaction rows to delete; screen: {screen.texts()}") + c.dev.tap_node(rows[0], screen) + time.sleep(1.5) + c.must_tap(r"(?i)^Delete$") + # A confirmation dialog guards the deletion. + if c.see(r"(?i)Delete transaction|Are you sure"): + c.tap(r"(?i)^Delete$|^OK$|^Yes$") + time.sleep(2) + after = len(transaction_rows(open_transactions(c))) + c.note(f"transaction rows before={before} after={after}") + if after >= before: + c.note("WARNING: the row count did not drop after deleting") + c.check() + + +@scenario("withdraw_suspend_resume", setup="fresh", + about="suspend a pending withdrawal, then resume it") +def s_withdraw_suspend_resume(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + # The transaction now waits for the bank; its detail screen offers the + # lifecycle actions. + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + c.must_tap(r"(?i)^Suspend$") + if c.see(r"(?i)Are you sure|Suspend"): + c.tap(r"(?i)^Suspend$|^OK$|^Yes$", timeout=6) + time.sleep(2) + detail = c.dev.dump() + c.note("suspended, on its detail screen: " + str(detail.texts()[:12])) + c.check() + # What the *list* says about it: the detail screen says "This transaction + # is suspended", and the row is what a user scanning their history sees. + row_texts = [] + c.back_to_home() + listed = c.dev.dump() + rows = transaction_rows(listed) + if rows: + band = rows[0].bounds + row_texts = [n.label for n in listed.labelled() + if abs(n.bounds[1] - band[1]) < 120] + c.note(f"its row in the list: {row_texts}") + if row_texts and not any("suspend" in t.lower() for t in row_texts): + c.note("WARNING: nothing on the row says the transaction is suspended") + c.check() + rows = transaction_rows(c.dev.dump()) + if rows: + c.dev.tap_node(rows[0]) + time.sleep(2.5) + c.must_tap(r"(?i)^Resume$", timeout=30) + time.sleep(2) + c.note("resumed; screen: " + str(c.dev.dump().texts()[:8])) + c.check() + + +@scenario("withdraw_suspend_abort", setup="fresh", + about="suspend a pending withdrawal, then abort it") +def s_withdraw_suspend_abort(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + c.must_tap(r"(?i)^Suspend$") + time.sleep(2) + c.must_tap(r"(?i)^Abort$", timeout=30) + if c.see(r"(?i)Abort transaction|Are you sure"): + c.tap(r"(?i)^Abort$|^OK$|^Yes$") + time.sleep(3) + c.note("after abort: " + str(c.dev.dump().texts()[:10])) + c.check() + + +@scenario("withdraw_abort", setup="fresh", about="abort a withdrawal before the bank confirms") +def s_withdraw_abort(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + c.must_tap(r"(?i)^Abort$") + if c.see(r"(?i)Abort transaction|Are you sure"): + c.tap(r"(?i)^Abort$|^OK$|^Yes$") + time.sleep(3) + status = c.bank.withdrawal_status(op["withdrawal_id"]) + c.note(f"bank-side status after abort: {status.get('status')}") + # What the aborted transaction says about itself: nothing was withdrawn, so + # "Fee -<the whole amount>" would be a misstatement. Aborting navigates + # back to the list, so the detail screen has to be opened again. + aborted = c.dev.dump() + if aborted.find(r"(?i)was aborted|has failed") is None: + open_transactions(c) + rows = transaction_rows(c.dev.dump()) + if rows: + c.dev.tap_node(rows[0]) + time.sleep(2.5) + aborted = c.dev.dump() + c.note("aborted withdrawal: " + str(aborted.texts()[:14])) + labels = aborted.texts() + if "Fee" in labels: + fee_node = aborted.find(r"(?i)^Fee$") + amounts = [t for t in labels if re.match(r"^[-−]?[€$]?\d", t)] + c.note(f"amounts beside Fee: {amounts[:6]}") + if any(t.lstrip("-−").lstrip("€$") == "5.00" for t in amounts): + c.note("WARNING: the whole chosen amount is shown as a fee") + c.check() + + +@scenario("withdraw_abandon", setup="fresh", about="abandon (fail) a pending withdrawal") +def s_withdraw_abandon(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + if not c.tap(r"(?i)^Abandon$", timeout=20): + # Abandon is only offered in some states; suspend first and look again. + c.tap(r"(?i)^Suspend$") + if not c.tap(r"(?i)^Abandon$", timeout=20): + c.note("Abandon not offered for a withdrawal waiting on the bank") + return + if c.see(r"(?i)Abandon transaction|Are you sure"): + c.tap(r"(?i)^Abandon$|^OK$|^Yes$") + time.sleep(3) + c.check() + + +# "funded" rather than "fresh": the exchange menu only exists once the wallet +# knows the local exchange, which the first withdrawal is what teaches it. +@scenario("withdraw_manual", setup="funded", + about="manual withdrawal from the exchange menu: wire instructions and QR") +def s_withdraw_manual(c: Ctx) -> None: + open_exchange_list(c) + if not exchange_menu(c): + raise RuntimeError(f"no exchange menu; screen: {c.dev.dump().texts()}") + if not c.tap(r"(?i)^Withdraw$"): + c.note("no manual withdraw entry in the exchange menu") + return + screen = c.see(r"(?i)Withdraw|amount|Confirm", timeout=30) + fields = screen.editable() if screen else [] + if fields: + c.dev.tap_node(fields[0], screen) + c.dev.type_text("5") + c.accept_tos() + c.tap(r"(?i)^Withdraw$|Confirm withdrawal", timeout=20) + # Wire transfer instructions, with the QR variants below them. + if c.see(r"(?i)Wire transfer instructions|Subject|IBAN|Recipient", timeout=40): + c.note("reached manual withdrawal instructions") + c.app.scroll_to_text(r"(?i)Wire transfer QR codes|Open in banking app", max_scrolls=5) + c.check() + + +@scenario("payment_abort", setup="funded", about="decline a payment at the prompt") +def s_payment_abort(c: Ctx) -> None: + order = c.merchant.create_order("EUR:1", summary="Order the wallet will decline") + c.app.handle_uri(order["pay_uri"]) + c.see(r"(?i)Review order|Total:|^Pay", timeout=60) + c.must_tap(r"(?i)^Cancel$") + time.sleep(2) + status = c.merchant.order_status(order["order_id"], order["token"]) + c.note(f"order status after cancel: {status.get('order_status')}") + c.check() + + +@scenario("payment_insufficient", setup="funded", + about="an order larger than the balance, and what the Pay button does") +def s_payment_insufficient(c: Ctx) -> None: + order = c.merchant.create_order("EUR:99", summary="More than the wallet holds") + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)insufficient|not enough|balance|Review order", timeout=40) + c.note("screen: " + str(screen.texts()[:12])) + pay = screen.find(r"(?i)^Pay ") + if pay is not None: + button = screen.tap_target(pay) + c.note(f"Pay button present with an insufficient balance: " + f"label={pay.label!r} enabled={button.enabled} " + f"clickable={button.clickable}") + # Offering it is only a problem if it can actually be pressed. + if button.enabled and button.clickable: + c.dev.tap_node(pay, screen) + time.sleep(4) + after = c.dev.dump() + c.note("after pressing Pay anyway: " + str(after.texts()[:12])) + status = c.merchant.order_status(order["order_id"], order["token"]) + c.note(f"merchant says: {status.get('order_status')}") + c.check() + else: + c.note("no Pay button offered, which is the expected behaviour") + c.check() + c.ep.check_database() + + +@scenario("payment_twice", setup="funded", about="pay the same order twice") +def s_payment_twice(c: Ctx) -> None: + order = flows.pay(c.app, c.merchant, "EUR:1", summary="Paid once already") + c.app.home() + c.app.handle_uri(order["pay_uri"]) + c.see(r"(?i)already paid|paid|Error|Review order", timeout=40) + c.note("second attempt: " + str(c.dev.dump().texts()[:10])) + c.check() + + +@scenario("refund", setup="funded", about="take a refund for a paid order") +def s_refund(c: Ctx) -> None: + order = flows.pay(c.app, c.merchant, "EUR:2", summary="Order to be refunded") + c.app.home() + res = c.merchant.refund(order["order_id"], "EUR:1") + uri = res.get("taler_refund_uri") + if not uri: + raise RuntimeError(f"merchant returned no refund uri: {res}") + c.app.handle_uri(uri) + time.sleep(3) + c.note("after refund uri: " + str(c.dev.dump().texts()[:10])) + open_transactions(c) + c.check() + + +@scenario("exchange_add_remove", setup="fresh", about="add an exchange by URL, then delete it") +def s_exchange_add_remove(c: Ctx) -> None: + open_exchange_list(c) + c.must_tap(r"(?i)^Add payment service$") + screen = c.require(r"(?i)Enter address of payment service|address", timeout=30) + fields = screen.editable() if screen else [] + if not fields: + raise RuntimeError(f"no URL field on the add screen: {screen.texts() if screen else None}") + c.dev.tap_node(fields[0], screen) + c.dev.type_text(LOCAL_EXCHANGE) + c.tap(r"(?i)^Add$|^OK$|^Continue$|^Next$") + time.sleep(4) + c.check() + # Now remove it again. + open_exchange_list(c) + if exchange_menu(c): + if c.tap(r"(?i)^Delete payment service$"): + if c.see(r"(?i)Force deletion|Are you sure|Delete"): + c.tap(r"(?i)^Delete$|^OK$|^Yes$", timeout=8) + time.sleep(2) + c.note("deleted the local exchange") + c.check() + + +@scenario("exchange_tos", setup="fresh", about="view, reject and re-accept terms of service") +def s_exchange_tos(c: Ctx) -> None: + # Contact the exchange first so there are terms to look at. + flows.withdraw(c.app, c.bank, "EUR:5") + open_exchange_list(c) + if not exchange_menu(c): + raise RuntimeError(f"no exchange menu; screen: {c.dev.dump().texts()}") + if c.tap(r"(?i)^Review terms of service$"): + shown = c.see(r"(?i)Terms of Service|Accept|terms", timeout=30) + c.check() + # The language selector only exists when the exchange offers more than + # one language, which is why backend/stack.sh renders the terms in + # English *and* German (exchange-tos-tops-v0 ships both). + if shown is not None and shown.find(r"(?i)^Language$") is not None: + before = [x for x in shown.texts() if len(x) > 40][:1] + c.tap(r"(?i)^Language$", timeout=10) + time.sleep(2) + menu = c.dev.dump() + # The menu items are text nodes whose clickable ancestor is the + # row, so they do not appear in tappable() -- looking there found + # nothing and read as "the exchange offers one language". + known = ("English", "German", "Deutsch", "French", "Français") + offered = [n for n in menu.labelled() if n.label.strip() in known] + c.note(f"languages offered: {[n.label.strip() for n in offered]}") + other = next((n for n in offered + if n.label.strip() != "English"), None) + if other is not None and (c.dev.tap(*other.center) or True): + time.sleep(3) + after = c.dev.dump() + body = [x for x in after.texts() if len(x) > 40][:1] + c.note(f"after picking {other.label.strip()!r}: {str(body)[:160]}") + if before and body and before == body: + c.note("the terms text did not change with the language") + c.check() + else: + c.note("no language selector on the terms screen: " + + str(shown.texts()[:10] if shown else None)) + c.dev.back() + open_exchange_list(c) + exchange_menu(c) + if c.tap(r"(?i)^Reject terms of service$"): + time.sleep(2) + c.note("rejected the terms of service") + c.check() + open_exchange_list(c) + exchange_menu(c) + if c.tap(r"(?i)^Accept Terms of Service$|^Review terms of service$"): + c.tap(r"(?i)^Accept$|I accept|^Confirm$", timeout=20) + c.check() + + +@scenario("exchange_reload_global", setup="funded", + about="reload exchange info and toggle global-currency treatment") +def s_exchange_reload_global(c: Ctx) -> None: + open_exchange_list(c) + if not exchange_menu(c): + raise RuntimeError(f"no exchange menu; screen: {c.dev.dump().texts()}") + menu = c.dev.dump() + c.note("exchange menu: " + str(menu.texts()[:14])) + if c.tap(r"(?i)^Reload information$"): + time.sleep(3) + c.note("after reloading: " + str(c.dev.dump().texts()[:12])) + c.check() + else: + c.note("no 'Reload information' entry in the menu") + open_exchange_list(c) + exchange_menu(c) + if c.tap(r"(?i)^Treat as global$"): + time.sleep(3) + c.note("after treat-as-global: " + str(c.dev.dump().texts()[:12])) + c.check() + open_exchange_list(c) + exchange_menu(c) + after = c.dev.dump() + c.note("menu now offers: " + str(after.texts()[:14])) + if after.find(r"(?i)Stop treating as global") is None: + c.note("WARNING: the exchange was not marked global; the menu is " + "unchanged, which is what the null master key bug looks like") + c.tap(r"(?i)^Stop treating as global$") + time.sleep(2) + c.note("after stopping: " + str(c.dev.dump().texts()[:12])) + else: + c.note("no 'Treat as global' entry in the menu") + c.check() + + +@scenario("exchange_dev_add", setup="fresh", about="add the built-in development exchanges") +def s_exchange_dev_add(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Add development payment services$") + c.must_tap(r"(?i)^Add development payment services$") + time.sleep(4) + c.note("exchange list: " + str(c.dev.dump().texts()[:14])) + c.check() + + +@scenario("settings_walk", setup="funded", about="visit every settings row and toggle the switches") +def s_settings_walk(c: Ctx) -> None: + # Every row except the destructive ones and the two that talk to + # demo.taler.net; those have their own scenarios. + rows = [ + r"(?i)^Payment services$", + r"(?i)^Bank accounts$", + r"(?i)^Tax-deductible donations$", + r"(?i)^Performance stats$", + r"(?i)^Upgrade wallet database$", + r"(?i)^App version$", + r"(?i)^Wallet Core version$", + ] + for row in rows: + c.app.open_settings() + try: + c.app.scroll_to_text(row, max_scrolls=10) + except TimeoutError: + c.note(f"row not present: {row}") + continue + if c.tap(row): + time.sleep(1.5) + c.check() + c.note(f"visited {row}: {c.dev.dump().texts()[:6]}") + # The switches: flip each one off and on again. + for switch in (r"(?i)^Protect access to wallet$", r"(?i)^Developer mode$"): + c.app.open_settings() + try: + screen = c.app.scroll_to_text(switch, max_scrolls=10) + except TimeoutError: + continue + node = screen.find(switch) + if node is None: + continue + width, _ = c.dev.size() + _, y = node.center + c.dev.tap(width - 100, y) + time.sleep(2) + c.check() + c.dev.tap(width - 100, y) + time.sleep(2) + c.check() + # Developer mode must survive the round trip, or later scenarios break. + c.app.enable_dev_mode() + c.check() + + +def save_through_picker(c: Ctx, timeout: int = 30) -> bool: + """Carry a "save as" through the system document picker. + + The wallet hands off to DocumentsUI, which prefills a file name and offers + SAVE; without completing it the export never runs at all. + """ + screen = c.see(r"(?i)^SAVE$|Files in Downloads", timeout=timeout) + if screen is None: + return False + if not c.tap(r"(?i)^SAVE$", timeout=15): + return False + time.sleep(4) + return True + + +def pick_file_in_picker(c: Ctx, pattern: str = r"taler-wallet-db.*\.json", + timeout: int = 25) -> bool: + """Choose the newest matching file in DocumentsUI and wait for the hand-back. + + Three things here are easy to get wrong, and all three were: + + * the picker labels the row with the file name *and* the thumbnail with + "Preview the file <name>", so matching the name alone hits the preview; + * it lists newest first, so "the last row" is the *oldest* file -- which + for these exports is the one taken from an emptiest wallet, and + importing it looks exactly like an import that lost everything; + * `Screen.tap_target` hunts for a clickable ancestor or neighbour, and on + these rows that lands somewhere that dismisses the picker without + selecting, so the import never runs at all. + + So: skip the preview labels, pick the greatest *name* (they are + timestamps), and tap the label's own centre. + + Note also that `adb shell ls /sdcard/Download` and the picker disagree: + the shell sees its own scoped view, while the picker lists MediaStore, + which still holds everything the app wrote. Deleting old exports from the + shell therefore does not clear the picker. + """ + rx = re.compile(pattern, re.I) + preview = re.compile(r"(?i)^preview\b") + deadline = time.time() + timeout + while time.time() < deadline: + screen = c.dev.dump() + rows = [n for n in screen.labelled() + if rx.search(n.label) and not preview.match(n.label.strip())] + if rows: + newest = max(rows, key=lambda n: n.label.strip()) + c.note(f"picking {newest.label.strip()!r} of " + f"{len(rows)} offered") + c.dev.tap_node(newest, screen) + break + time.sleep(1.5) + else: + c.note(f"no file matching {pattern!r} in the picker: " + + str(c.dev.dump().texts()[:12])) + return False + # Some pickers need the selection confirmed. + for label in (r"(?i)^(OPEN|SELECT|DONE)$",): + c.tap(label, timeout=4) + # Handing back means the app is in the foreground again. + deadline = time.time() + 25 + while time.time() < deadline: + where = c.dev.dump().activity + if where.startswith(PKG): + return True + time.sleep(2) + c.note(f"the picker did not hand back to the wallet (now in {where}): " + + str(c.dev.dump().texts()[:10])) + return False + + +@scenario("settings_export", setup="funded", + about="database and log export, carried through the save dialog") +def s_settings_export(c: Ctx) -> None: + exported = [] + for row in (r"(?i)^Export database$", r"(?i)^Export raw database$", + r"(?i)^Debug log$"): + c.app.open_settings() + try: + c.app.scroll_to_text(row, max_scrolls=10) + except TimeoutError: + c.note(f"row not present: {row}") + continue + c.tap(row) + time.sleep(2) + # The database exports warn first, because the file holds the money. + if c.see(r"(?i)sensitive data|Export anyway", timeout=8): + c.note(f"{row}: warned before exporting") + c.tap(r"(?i)^Export anyway$", timeout=8) + if save_through_picker(c): + exported.append(row) + c.check() + else: + c.note(f"{row}: no save dialog appeared") + c.dev.back() + time.sleep(1.5) + c.check() + listing = c.dev.shell("ls -la /sdcard/Download/", check=False) + c.note(f"exported {len(exported)} file(s); Download now holds: " + f"{[l.split()[-1] for l in listing.splitlines()[1:] if l.strip()][:5]}") + c.app.home() + c.ep.check_database() + + +@scenario("settings_import", setup="funded", + about="export the database, then import it back") +def s_settings_import(c: Ctx) -> None: + # Export first, so there is something to import. + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Export database$", max_scrolls=10) + c.must_tap(r"(?i)^Export database$") + if c.see(r"(?i)sensitive data|Export anyway", timeout=8): + c.tap(r"(?i)^Export anyway$", timeout=8) + if not save_through_picker(c): + c.note("could not export, so there is nothing to import") + return + c.check() + + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Import database$", max_scrolls=10) + c.must_tap(r"(?i)^Import database$") + if c.see(r"(?i)overwrite|Do you want", timeout=15): + c.tap(r"(?i)^OK$|^Import$|^Yes$|^Continue$", timeout=10) + screen = c.see(r"(?i)taler-wallet-db|Files in Downloads|Downloads", timeout=25) + if screen is None: + c.note("no document picker for the import") + return + c.note("picker: " + str(screen.texts()[:10])) + if not pick_file_in_picker(c): + c.dev.back() + return + time.sleep(8) + c.note("after importing: " + str(c.dev.dump().texts()[:12])) + log = c.dev.logcat() + if "importDb" in log: + c.note("importDb reached wallet-core") + else: + c.note("WARNING: the file was picked but importDb never ran") + c.check() + # The wallet has to still work on the imported database. + c.back_to_home() + rows = transaction_rows(open_transactions(c)) + c.note(f"{len(rows)} transactions after the import") + c.check() + c.ep.check_database() + + +@scenario("settings_import_bad_file", setup="funded", + about="import a file that is not a wallet database") +def s_settings_import_bad_file(c: Ctx) -> None: + """The import's error path. + + `SettingsManager.importDb` reads the chosen file as text, parses it as + JSON, and hands the object to wallet-core; anything that is not JSON + throws before the request and lands in `onDbImportError`. The suite's + other import scenarios always pick a genuine export, so that branch -- and + the "Error importing database" it shows -- had never run. + + The file is written straight into Downloads and scanned into MediaStore, + because the picker lists MediaStore rather than the shell's view of the + directory. + """ + name = f"sim-not-a-db-{int(time.time())}.json" + path = f"/sdcard/Download/{name}" + c.dev.shell(f"echo 'this is not a wallet database' > {path}", check=False) + c.dev.shell("content call --uri content://media/external/file " + f"--method scan_file --arg {path}", check=False) + listed = c.dev.shell(f"ls -l {path}", check=False) + c.note(f"planted {name}: {listed.strip()[:100]}") + c.dev.logcat(clear=True) + + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Import database$", max_scrolls=10) + c.must_tap(r"(?i)^Import database$") + if c.see(r"(?i)overwrite|Do you want", timeout=15): + c.tap(r"(?i)^OK$|^Import$|^Yes$|^Continue$", timeout=10) + screen = c.see(r"(?i)Files in Downloads|Downloads|sim-not-a-db", timeout=25) + if screen is None: + c.note("no document picker for the import") + return + c.note("picker: " + str(screen.texts()[:10])) + if not pick_file_in_picker(c, pattern=r"sim-not-a-db.*\.json"): + c.note("could not pick the planted file; the picker showed " + + str(c.dev.dump().texts()[:12])) + c.dev.back() + return + # The error is a Toast (SettingsManager.onDbImportError), and LENGTH_LONG + # is about three and a half seconds: dumping at +6s missed it entirely and + # made it look as though nothing was reported. Look early and repeatedly. + shown = False + after = c.dev.dump() + for _ in range(6): + after = c.dev.dump() + if after.find(r"(?i)Error importing database") is not None: + shown = True + break + time.sleep(1) + c.note("after importing rubbish: " + str(after.texts()[:12])) + log = c.dev.logcat() + logged = "Error importing db" in log + # Not an assertion: the feedback is a Toast, and a Toast is a system + # window that a hierarchy dump does not reliably contain. "False" here + # means the harness could not see it, not that a user cannot. What can + # be asserted is that the failure was detected at all. + c.note(f"the error toast was visible to the dump: {shown}") + c.note(f"the failure reached the log: {logged}") + if not logged: + c.note("WARNING: importing a non-database was not reported anywhere " + "this harness can see") + c.check() + + # And the wallet has to be usable afterwards: a failed import must not + # have touched the database it was going to replace. + c.back_to_home() + home = c.dev.dump() + c.note("home after the failed import: " + str(home.texts()[:12])) + if home.find(r"€|EUR") is None: + c.note("WARNING: no balance on the main screen after a failed import") + c.check() + c.dev.shell(f"rm -f {path}", check=False) + c.ep.check_database() + + +@scenario("settings_import_cancel", setup="funded", about="start a database import and cancel it") +def s_settings_import_cancel(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Import database$", max_scrolls=10) + c.must_tap(r"(?i)^Import database$") + asked = c.see(r"(?i)overwrite|Do you want|Cancel", timeout=20) + c.note("import prompt: " + str((asked or c.dev.dump()).texts()[:12])) + if asked: + c.tap(r"(?i)^Cancel$|^No$") + else: + c.note("WARNING: importing a database asked nothing before proceeding") + time.sleep(1.5) + c.dev.back() + c.note("back in settings: " + str(c.dev.dump().texts()[:10])) + c.check() + + +@scenario("settings_reset_confirmed", setup="funded", + about="confirm the wallet reset, which is the only caller of clearDb") +def s_settings_reset_confirmed(c: Ctx) -> None: + """Reset Wallet, carried through. + + `settings_reset_cancel` backs out of this dialog; nothing confirmed it, so + `clearDb` was one of the last wallet-core operations no scenario reached. + + The dialog is also worth looking at: the destructive action is the + *negative* button and Cancel is the *positive* one + (`settings/SettingsScreen.kt:361`), so Android draws "Reset" where + convention puts "Cancel". + """ + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Reset Wallet", max_scrolls=12) + c.must_tap(r"(?i)^Reset Wallet") + dialog = c.require(r"(?i)really want to reset|lose all coins", timeout=20) + buttons = [(n.label.strip(), n.center[0]) for n in dialog.tappable() + if n.label.strip() in ("Reset", "Cancel")] + c.note(f"the reset dialog's buttons, left to right: " + + str(sorted(buttons, key=lambda b: b[1]))) + c.check() + if not c.tap_button(r"(?i)^Reset$", timeout=15): + c.note("no Reset button in the dialog: " + str(dialog.texts()[:10])) + return + time.sleep(8) + after = c.dev.dump() + c.note("after resetting: " + str(after.texts()[:12])) + c.check() + log = c.dev.logcat() + if "clearDb" not in log: + c.note("WARNING: the reset did not reach clearDb") + # A reset wallet is an empty wallet. + balances = c.app.balances() + c.note(f"balance after the reset: {balances}") + if any(re.search(r"[1-9]", b) for b in balances): + c.note("WARNING: coins survived a wallet reset") + c.check() + c.ep.check_database() + + +@scenario("settings_reset_cancel", setup="funded", about="open the wallet reset dialog and cancel") +def s_settings_reset_cancel(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Reset Wallet", max_scrolls=10) + c.must_tap(r"(?i)^Reset Wallet") + if c.see(r"(?i)really want to reset|lose all coins|Cancel", timeout=20): + c.tap(r"(?i)^Cancel$|^No$") + time.sleep(2) + c.note("after cancelling the reset: " + str(c.dev.dump().texts()[:8])) + c.check() + + +@scenario("scan_manual_entry", setup="funded", + about="the scan screen's manual link entry, fed hostile input") +def s_scan_manual_entry(c: Ctx) -> None: + hostile = ["", "taler://", "not a uri at all", + corpus.MALFORMED["bad_base32"], corpus.MALFORMED["id_too_long"], + corpus.MALFORMED["unicode"], corpus.STRUCTURAL["pay"]] + for value in hostile: + try: + screen = c.app.open_scanner() + except TimeoutError: + c.note("could not open the scan screen: " + + str(c.dev.dump().texts()[:10])) + return + fields = screen.editable() if screen else [] + if not fields: + c.note("scan screen has no text field: " + str(screen.texts() if screen else None)) + c.dev.back() + continue + c.dev.tap_node(fields[0], screen) + if value: + c.dev.type_text(value) + c.dev.key("KEYCODE_ENTER") + time.sleep(2.5) + c.check() + c.dev.back() + time.sleep(1) + c.check() + + +def tap_if_any(c: Ctx, patterns: tuple[str, ...], timeout: int = 6) -> bool: + """Tap the first of these labels that is present, if any.""" + for pattern in patterns: + if c.tap(pattern, timeout=timeout): + return True + return False + + +def fill_account_note(c: Ctx, label: str = "Simulator account") -> bool: + """Fill the add-account form's required "Note" field. + + The form is a LazyColumn, so the note is often below the fold and absent + from the view hierarchy altogether -- filling "the last editable field" + then types into Town instead, leaves the note empty, and the submit button + stays disabled with nothing to show for it + (findings/add-account-note-is-required-but-unmarked.md). + """ + try: + c.app.scroll_to_text(r"(?i)^Note$", max_scrolls=6) + except TimeoutError: + c.note("no Note field on this screen: " + str(c.dev.dump().texts()[:10])) + return False + fields = c.dev.dump().editable() + if not fields: + c.note("the add-account form has no editable fields") + return False + return c.fill(label, len(fields) - 1, clear=True) + + +def amount_value(amount: str) -> float: + """The numeric part of a "EUR:12.34" amount.""" + try: + return float(amount.split(":", 1)[1]) + except (IndexError, ValueError): + return float("nan") + + +@scenario("deposit", setup="funded", about="deposit coins back to a bank account") +def s_deposit(c: Ctx) -> None: + """A deposit that is checked, not just watched. + + This noted the bank balance before and after and passed either way, so it + reported "ok" for thirteen rounds while depositing nothing at all: the + balance was identical every time, because the payto link it used is one the + wallet refuses (findings/payto-link-only-accepts-iban.md). + """ + before = c.bank.balance(*flows.WALLET_USER) + screen = flows.deposit_to_bank(c.app, c.env, "100") + c.note("after the deposit: " + str(screen.texts()[:12])) + c.check() + # The exchange has to aggregate and wire it, which is not instant. + deadline = time.monotonic() + 120 + after = before + while time.monotonic() < deadline: + after = c.bank.balance(*flows.WALLET_USER) + if amount_value(after) > amount_value(before): + break + time.sleep(5) + c.note(f"bank balance {before} -> {after}") + if not amount_value(after) > amount_value(before): + raise RuntimeError( + f"the deposit did not reach the bank: balance stayed at {after} " + f"(screen: {c.dev.dump().texts()[:12]})") + c.check() + + +@scenario("deposit_payto_link", setup="funded", + about="a payto link for a non-IBAN account, which the wallet refuses") +def s_deposit_payto_link(c: Ctx) -> None: + """Pins the refusal, so a fix shows up here. + + `DepositManager.isSupportedPayToUri` accepts `payto://iban/...` only, so + the x-taler-bank account the wallet withdraws from -- and deposits to + perfectly well when it is picked from the account list -- cannot be reached + by a link. + """ + screen = flows.deposit_via_payto_link(c.app, c.env) + refused = screen.find(r"(?i)Not a valid Taler link") is not None + c.note(f"x-taler-bank payto link refused: {refused} -- " + + str(screen.texts()[:10])) + if not refused: + c.note("the wallet now accepts an x-taler-bank payto link; " + "payto-link-only-accepts-iban.md may be fixed") + c.check() + + +# Everyday configuration changes, each of which restarts the app. The wallet +# has to come back usable from all of them; one of them does not. +# Each change carries the API level the *driver* needs to make it: a per-app +# language is API 33+, so asking for one on an older device tests adb rather +# than the wallet, and reports a pass or a failure that means nothing. +CONFIG_CHANGES = ( + ("app language", 33, "cmd locale set-app-locales {pkg} --locales de-DE", + "cmd locale set-app-locales {pkg} --locales"), + ("dark mode", 29, "cmd uimode night yes", "cmd uimode night no"), + ("font size", 24, "settings put system font_scale 1.30", + "settings put system font_scale 1.0"), + ("display size", 24, "wm density 480", "wm density reset"), +) + + +def undo_of(name: str) -> str: + for n, _, _, undo in CONFIG_CHANGES: + if n == name: + return undo + raise KeyError(name) + + +INIT_ERROR = (r"(?i)Initialization error|Initialisierungsfehler" + r"|error occurred while starting|Fehler aufgetreten") + + +@scenario("config_changes", setup="funded", + about="change the language, theme, font and display size mid-flow", + expects=("error-screen", "internal-error-code")) +def s_config_changes(c: Ctx) -> None: + """Does the wallet survive what Android does to every app? + + Each of these recreates the activity -- and restarts the app -- while the + wallet is open. Changing the language loses the race for the SQLite + database and dead-ends on the Initialization error screen + (`config-change-locks-the-wallet-out-of-its-database.md`), so the others + are worth measuring in the same place. + """ + pkg = c.dev.pkg + broken: list[str] = [] + try: + for name, needs_api, apply_cmd, _ in CONFIG_CHANGES: + if c.dev.sdk_int < needs_api: + c.note(f"{name}: skipped, the driver needs API {needs_api} " + f"and this device is API {c.dev.sdk_int}") + continue + # A settings sub-screen keeps the wallet busy while the change + # lands, which is where this was first seen. + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Contacts$", max_scrolls=12) + c.tap(r"(?i)^Contacts$", timeout=20) + time.sleep(2) + c.dev.shell(apply_cmd.format(pkg=pkg), check=False) + time.sleep(9) + screen = c.dev.dump() + if screen.find(INIT_ERROR) is not None: + broken.append(name) + c.note(f"{name}: the wallet came back on its init error screen: " + + str(screen.texts()[:4])) + else: + c.note(f"{name}: survived -- " + str(screen.texts()[:8])) + c.check() + # Undo before the next one, so a failure is attributable. + c.dev.shell(undo_of(name).format(pkg=pkg), check=False) + time.sleep(6) + c.dev.stop() + time.sleep(2) + c.dev.launch() + time.sleep(8) + back = c.dev.dump() + if back.find(INIT_ERROR) is not None: + c.note(f"WARNING: still on the init error screen after undoing " + f"{name} and relaunching") + c.check() + c.note(f"configuration changes the wallet did not survive: {broken}") + finally: + for name, needs_api, _, undo in CONFIG_CHANGES: + if c.dev.sdk_int >= needs_api: + c.dev.shell(undo.format(pkg=pkg), check=False) + + +@scenario("abandon_aborting_deposit", setup="funded", + about="abort a deposit with no network, then abandon it", + # The abandoned deposit shows a fee on a transaction that failed, + # which is recorded under aborted-credit-shows-the-whole-amount-as-fee.md + # and may be correct, so it does not need flagging every round. + expects=("fee-on-dead-transaction", "unfinished-transaction")) +def s_abandon_aborting_deposit(c: Ctx) -> None: + """The only reachable "Abandon". + + wallet-core offers TransactionAction.Fail -- "Abandon", the one button + that calls failTransaction -- for a deposit or peer-push that is + *aborting*, and for little else: a withdrawal waiting on the bank never + offers it, which is what `withdraw_abandon` keeps recording. An abort + against a healthy exchange finishes in a blink, so the transaction only + sits in that state while the wallet is offline, and the dialog's own + warning ("Funds still in transit WILL GET LOST") is exactly what is being + tested. + """ + # The network goes away between entering the amount and submitting: a + # deposit against a reachable exchange completes in under four seconds, so + # taking the network afterwards only ever found a finished transaction. + def go_offline() -> None: + c.dev.shell("cmd connectivity airplane-mode enable", check=False) + time.sleep(3) + + screen = flows.deposit_to_bank(c.app, c.env, "100", before_submit=go_offline) + c.note("the deposit, submitted offline: " + str(screen.texts()[:12])) + c.check() + if not c.tap(r"(?i)^Abort$", timeout=20): + c.note("no Abort on the deposit: " + str(c.dev.dump().texts()[:14])) + c.dev.shell("cmd connectivity airplane-mode disable", check=False) + return + if c.see(r"(?i)Abort transaction|Are you sure", timeout=10): + c.tap(r"(?i)^Abort$|^OK$|^Yes$") + time.sleep(5) + # abortTransaction's onSuccess navigates back, so the detail screen -- and + # with it every action button -- is gone by now; the transaction has to be + # reopened to see what it offers. + rows = transaction_rows(open_transactions(c)) + if rows: + c.dev.tap_node(rows[0]) + time.sleep(3) + aborting = c.dev.dump() + c.note("the aborting deposit, reopened: " + str(aborting.texts()[:16])) + c.check() + if not c.tap(r"(?i)^Abandon$", timeout=20): + c.note("Abandon not offered on the aborting deposit; it offers " + + str([n.label for n in aborting.tappable() if n.label][:10])) + c.dev.shell("cmd connectivity airplane-mode disable", check=False) + return + dialog = c.dev.dump() + c.note("the abandon dialog: " + str(dialog.texts()[:10])) + c.tap(r"(?i)^Abandon$|^OK$|^Yes$") + time.sleep(4) + c.note("after abandoning: " + str(c.dev.dump().texts()[:14])) + c.check() + # Back online: an abandoned transaction must stay abandoned, and the + # balance must not count the coins twice. + c.dev.shell("cmd connectivity airplane-mode disable", check=False) + time.sleep(10) + c.note("after reconnecting: " + str(c.dev.dump().texts()[:14])) + c.check() + c.back_to_home() + c.note("balance afterwards: " + str(c.dev.dump().texts()[:10])) + c.check() + c.ep.check_database() + + +@scenario("peer_push_receive", setup="fresh", about="receive a peer push payment from the CLI wallet") +def s_peer_push(c: Ctx) -> None: + screen = flows.peer_receive(c.app, c.env, "EUR:1", c.cli) + c.note("the prompt: " + str(screen.texts()[:12])) + # The prompt is still on screen right after the tap; accepting is a + # round trip to the exchange, and only its completion reaches + # confirmPeerPushCredit and the credit transaction's own screen. + for _ in range(12): + time.sleep(3) + now = c.dev.dump() + if now.find(r"(?i)completed successfully|This transaction is pending|€") is not None \ + and now.find(r"(?i)Do you want to receive") is None: + break + c.note("after accepting: " + str(c.dev.dump().texts()[:14])) + c.check() + # The balance has to move, and this has to *fail* when it does not: the + # old check asked for a screen with no "€" on it, which a zero balance of + # "€0.00" never is, so a payment that never arrived read as success for + # every round of this campaign. + deadline = time.monotonic() + 90 + shown: list[str] = [] + while time.monotonic() < deadline: + shown = c.app.balances() + if any(re.search(r"[1-9]", s) for s in shown): + break + time.sleep(5) + c.note(f"balance after receiving: {shown}") + if not any(re.search(r"[1-9]", s) for s in shown): + raise RuntimeError( + f"the received push payment did not reach the balance: {shown} " + f"(screen: {c.dev.dump().texts()[:12]})") + c.check() + # The credit's own detail screen: nothing had opened it, so + # TransactionPeerPushCreditComposable had never rendered. + rows = transaction_rows(open_transactions(c)) + if rows: + c.dev.tap_node(rows[0]) + time.sleep(2.5) + detail = c.dev.dump() + c.note("the received push, in detail: " + str(detail.texts()[:16])) + c.check() + c.app.scroll_to_text(r"(?i)^Show JSON$|^Delete$", max_scrolls=4) + c.check() + c.ep.check_database() + + +@scenario("peer_pull_pay", setup="funded", about="pay an invoice the CLI wallet issued") +def s_peer_pull(c: Ctx) -> None: + flows.peer_pay_invoice(c.app, c.env, "EUR:1", c.cli) + time.sleep(3) + c.note("after paying the invoice: " + str(c.dev.dump().texts()[:10])) + c.check() + + +@scenario("balances_screens", setup="paid", about="balances, tokens and donation statements") +def s_balances(c: Ctx) -> None: + c.back_to_home() + for label in (r"(?i)^Balances$", r"(?i)^Other assets$", r"(?i)^Donation statements$", + r"(?i)^Contacts$"): + c.back_to_home() + if c.tap(label, timeout=10): + time.sleep(1.5) + c.note(f"{label}: {c.dev.dump().texts()[:8]}") + c.check() + c.check() + + +@scenario("peer_send", setup="funded", about="wallet sends money to the CLI wallet (OutgoingPush)") +def s_peer_send(c: Ctx) -> None: + c.back_to_home() + c.must_tap(r"(?i)^Send$", timeout=30) + c.require(r"(?i)Send money|Amount to send|Purpose", timeout=30) + c.set_amount("€5.00", "500") + c.check() + # Purpose and expiry are optional; touch them so their code runs. + c.tap(r"(?i)^Purpose$", timeout=6) + c.tap(r"(?i)Expires in|1 week|30 days", timeout=6) + c.must_tap(r"(?i)^Send ", timeout=30) + c.see(r"(?i)Scan this QR code to receive|copy and send this URI", timeout=60) + uri = c.uri_from_logcat("pay-push") + c.note(f"push uri: {uri[:70]}") + # The app's side of the flow is what is under test; whether the CLI peer + # can accept depends on its wallet-core being compatible with this + # exchange, so a failure there is recorded rather than raised. + try: + flows.fund_peer(c.cli, c.env, "EUR:5") + result = c.cli.accept_push(uri) + c.note(f"peer accepted: {str(result)[:200]}") + except Exception as e: + c.note(f"peer could not accept (counterparty problem): {str(e)[:220]}") + time.sleep(4) + c.back_to_home() + rows = transaction_rows(open_transactions(c)) + c.note(f"transactions after sending: {[n.label[:24] for n in rows]}") + c.check() + c.ep.check_database() + + +@scenario("peer_request", setup="funded", about="wallet invoices the CLI wallet (OutgoingPull)") +def s_peer_request(c: Ctx) -> None: + c.back_to_home() + c.must_tap(r"(?i)^Request$", timeout=30) + c.require(r"(?i)Request money|Amount to receive|Amount requested", timeout=30) + c.set_amount("€5.00", "500") + c.check() + c.must_tap(r"(?i)^Request ", timeout=30) + c.see(r"(?i)Scan this QR code to pay|copy and send this URI", timeout=60) + uri = c.uri_from_logcat("pay-pull") + c.note(f"pull uri: {uri[:70]}") + try: + flows.fund_peer(c.cli, c.env, "EUR:5") + result = c.cli.pay_pull(uri) + c.note(f"peer paid the invoice: {str(result)[:160]}") + except Exception as e: + c.note(f"peer could not pay (counterparty problem): {str(e)[:200]}") + time.sleep(4) + c.check() + + +@scenario("deposit_flow", setup="funded", + about="the Deposit button: amount, account selection, IBAN entry") +def s_deposit_flow(c: Ctx) -> None: + c.back_to_home() + c.must_tap(r"(?i)^Deposit$", timeout=30) + # The account comes first: the amount field only appears once a target + # account has been picked. + screen = c.require(r"(?i)deposit to bank account|Manage bank accounts|x-taler-bank", + timeout=30) + c.note("account step: " + str(screen.texts()[:10])) + account = screen.find(r"(?i)^wallet\d+$") or screen.find(r"(?i)x-taler-bank") + if account is not None: + c.dev.tap_node(account, screen) + time.sleep(2) + c.require(r"(?i)Amount to deposit|Make deposit", timeout=25) + c.set_amount("€5.00", "500") + c.check() + c.tap(r"(?i)^Check fees$", timeout=8) + c.tap(r"(?i)^Make deposit$|^Deposit$|^Next$|^Continue$", timeout=15) + # The account manager, with the IBAN form behind "Add account". + if c.see(r"(?i)Select bank account|Known bank accounts|Add account|Manage bank accounts", + timeout=20): + c.tap(r"(?i)^Manage bank accounts$", timeout=8) + if c.tap(r"(?i)^Add account$", timeout=15): + c.see(r"(?i)IBAN|Account holder|x-taler-bank", timeout=20) + c.check() + c.fill("Wallet One", 0) + c.fill("DE89370400440532013000", 1) + c.tap(r"(?i)^Save$|^Add$|^OK$|^Continue$", timeout=15) + time.sleep(2) + c.check() + c.tap(r"(?i)^Make deposit$|^Deposit$", timeout=20) + time.sleep(4) + c.note("after deposit attempt: " + str(c.dev.dump().texts()[:10])) + c.check() + + +@scenario("bank_accounts", setup="funded", about="Settings - Bank accounts: add, edit, forget") +def s_bank_accounts(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Bank accounts$") + c.must_tap(r"(?i)^Bank accounts$") + c.require(r"(?i)Known bank accounts|No bank accounts saved|Add account", timeout=25) + c.check() + if c.tap(r"(?i)^Add account$", timeout=20): + c.see(r"(?i)IBAN|Account holder", timeout=20) + # The form opens on the x-taler-bank tab, whose fields are a host + # dropdown, holder, account and note -- so filling "field 1" with an + # IBAN typed it into the account name. Pick the tab first. + c.tap(r"(?i)^IBAN$", timeout=10) + time.sleep(1.5) + # Wrong IBAN first: the form should say so rather than accept it. + c.fill("Test Holder", 0, clear=True) + c.fill("NOT-AN-IBAN", 1, clear=True) + # "Note" carries no "(optional)" but the submit button is disabled + # without it (findings/add-account-note-is-required-but-unmarked.md), + # so it has to be filled or nothing can ever be added. + fill_account_note(c, "Test account") + # The submit button carries the same string as the title and the add + # icon, so it has to be picked as a button, not as a label. + submitted = c.tap_button(r"(?i)^Add account$|^Save$|^OK$", timeout=10) + time.sleep(1.5) + c.note(f"invalid IBAN (submit tappable: {submitted}): " + + str(c.dev.dump().texts()[:10])) + c.check() + # Without clear=True this appends, leaving "NOT-AN-IBANDE89370…", + # which keeps the submit button disabled: no account was ever added. + c.fill("DE89370400440532013000", 1, clear=True) + c.tap_button(r"(?i)^Add account$|^Save$|^OK$", timeout=10) + time.sleep(3) + listed = c.dev.dump() + c.note("after adding: " + str(listed.texts()[:12])) + if listed.find(r"DE89|370400440532013000|Test Holder") is None: + c.note("WARNING: the account does not appear in the list") + c.check() + # Edit whatever is listed now. There is no "Edit" label to tap: the row + # itself is clickable and opens the add screen with the account's id, + # which is the only thing that ever calls getBankAccountById. + if c.tap(r"(?i)Test Holder|DE89|370400440532013000", timeout=10): + if c.see(r"(?i)^Edit account$", timeout=20): + edit = c.dev.dump() + c.note("the edit form: " + str(edit.texts()[:14])) + if edit.find(r"(?i)Test Holder") is None: + c.note("WARNING: the edit form did not load the account") + # Change the holder and save, then check the list shows the change. + c.fill("Edited Holder", 0, clear=True) + c.tap_button(r"(?i)^Save$|^Edit account$|^OK$", timeout=10) + time.sleep(3) + c.note("after saving: " + str(c.dev.dump().texts()[:12])) + else: + c.note("tapping the account row did not open the edit form: " + + str(c.dev.dump().texts()[:12])) + c.check() + c.back_to_home() + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Bank accounts$") + c.must_tap(r"(?i)^Bank accounts$") + c.require(r"(?i)Known bank accounts|No bank accounts saved|Add account", timeout=25) + if c.tap(r"(?i)^Delete$|^Forget", timeout=10): + if c.see(r"(?i)Forget account|really wish to forget", timeout=10): + c.tap(r"(?i)^Forget$|^OK$|^Yes$|^Delete$") + time.sleep(2) + c.check() + + +@scenario("manual_withdraw_transfer", setup="funded", + about="the Withdraw button: manual wire transfer details and QR codes") +def s_manual_withdraw_transfer(c: Ctx) -> None: + c.back_to_home() + c.must_tap(r"(?i)^Withdraw$", timeout=30) + c.require(r"(?i)Amount to withdraw|Select target bank account|Payment service", + timeout=30) + c.fill("5") + c.check() + c.tap(r"(?i)Restrict usage to age|Unrestricted", timeout=6) + c.accept_tos() + c.must_tap(r"(?i)^Withdraw$|Confirm withdrawal", timeout=30) + if c.see(r"(?i)Wire transfer instructions|Subject|IBAN|Recipient|Account", timeout=60): + c.note("manual withdrawal instructions reached") + c.check() + # Each of these used to be tried and dropped on the floor, so a button + # that stopped working looked exactly like one that is not offered for + # this account type. Say which happened. + reached = [] + for label in (r"(?i)Wire transfer QR codes", r"(?i)EPC QR", r"(?i)Swiss QR bill", + r"(?i)Open in banking app"): + try: + c.app.scroll_to_text(label, max_scrolls=6) + except TimeoutError: + c.note(f"{label}: not offered on this screen") + continue + if not c.tap(label, timeout=8): + c.note(f"{label}: on screen but the tap did not take") + continue + time.sleep(1.5) + reached.append(label) + c.note(f"{label}: " + str(c.dev.dump().texts()[:10])) + c.check() + # "Wire transfer QR codes" is the one that navigates away, to the + # transfer screen with showQrCodes set -- the only way that branch + # of ScreenTransfer runs. + if "QR codes" in label: + if c.see(r"(?i)you can scan one of these QR codes|share this QR code", + timeout=15) is None: + c.note("the QR code screen did not show its own text: " + + str(c.dev.dump().texts()[:12])) + else: + c.note("the QR variant of the transfer screen rendered") + c.check() + c.dev.back() + time.sleep(1.5) + c.note(f"transfer actions reached: {reached}") + c.note("screen: " + str(c.dev.dump().texts()[:12])) + c.check() + + +@scenario("tokens_screen", setup="paid", about="the Other assets / token list screen") +def s_tokens(c: Ctx) -> None: + c.back_to_home() + # The main screen's own labels: "Discounts" and "Passes" are the token + # views, "Donation statements" the donau receipts. + for label in (r"(?i)^Discounts$", r"(?i)^Passes$", r"(?i)^Donation statements$"): + c.back_to_home() + try: + c.app.scroll_to_text(label, max_scrolls=5) + except TimeoutError: + c.note(f"{label} not on the main screen") + continue + c.tap(label, timeout=10) + time.sleep(2) + c.note(f"{label}: {c.dev.dump().texts()[:10]}") + c.check() + for tab in (r"(?i)^Available$", r"(?i)^Expired$"): + c.tap(tab, timeout=6) + c.check() + c.check() + + +@scenario("donau_setup", setup="funded", about="configure the donation tax authority") +def s_donau(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Tax-deductible donations$") + c.must_tap(r"(?i)^Tax-deductible donations$") + c.require(r"(?i)tax authority|Donor tax payer ID|donation", timeout=25) + c.check() + if c.tap(r"(?i)^Select tax authority$", timeout=15): + time.sleep(2) + c.check() + c.tap(r"(?i)localhost:8079|Bern", timeout=10) + c.tap_button(r"(?i)^Setup tax payer ID$", timeout=10) + time.sleep(2) + # The form has two fields in this order: the authority's URL, then the tax + # payer ID. Save stays disabled until both are filled, which is why + # filling only the first one made the tap do nothing at all. + c.fill(c.env.donau, 0) + c.fill("TAXID-12345", 1) + time.sleep(1) + saved = c.tap_button(r"(?i)^Save$", timeout=15) + time.sleep(4) + screen = c.dev.dump() + c.note(f"after donau setup (save tappable: {saved}): " + str(screen.texts()[:12])) + if screen.find(r"(?i)configured successfully|Tax-deductible donations") is None: + c.note("WARNING: the tax authority was not accepted") + c.check() + + +@scenario("contacts_alias", setup="funded", about="contacts and alias registration") +def s_contacts(c: Ctx) -> None: + c.back_to_home() + if not c.tap(r"(?i)^Contacts$", timeout=15): + c.app.open_settings() + try: + c.app.scroll_to_text(r"(?i)^Contacts$|Alias Registration", max_scrolls=10) + c.tap(r"(?i)^Contacts$|Alias Registration", timeout=10) + except TimeoutError: + c.note("no way into contacts from home or settings") + return + screen = c.see(r"(?i)Contacts|Alias", timeout=20) + c.note("contacts screen: " + str((screen or c.dev.dump()).texts()[:14])) + c.check() + if c.tap(r"(?i)Alias Registration|^Register", timeout=15): + c.see(r"(?i)Alias Type|Alias|Duration", timeout=20) + c.fill("simulator@example.com") + c.tap(r"(?i)^Register Alias$", timeout=15) + time.sleep(3) + c.note("after alias registration: " + str(c.dev.dump().texts()[:10])) + c.check() + + +@scenario("transactions_bulk_delete", setup="paid", + about="selection mode: long-press, Select All, delete the lot") +def s_bulk_delete(c: Ctx) -> None: + """The main screen's rows do not select, and that is deliberate. + + This scenario used to long-press a row here, look for "Select All", and + return with "long press did not open selection mode" -- every round, while + counting as a pass. It never could: `BalancesPagerComposable`'s + `BalanceRecentTransactions` builds each `TransactionRow` with + `selectionMode = false` and `onTransactionSelect = {}`, so a long press on + the main screen is a no-op by construction. Selection and bulk deletion + live on the dedicated screen behind the "All" chip, which is what + `transactions_screen_selection` drives. + + What is left here is worth pinning: a long press must do *nothing* -- not + open a detail screen, not select, not crash. + """ + screen = open_transactions(c) + rows = transaction_rows(screen) + if not rows: + raise RuntimeError(f"no transaction rows; screen: {screen.texts()}") + before = screen.signature() + c.dev.long_press(rows[0]) + time.sleep(2) + after = c.dev.dump() + c.note("after a long press on the main screen: " + str(after.texts()[:12])) + if after.find(r"(?i)^Select All$") is not None: + c.note("selection mode opened on the main screen, which it is not " + "built to do -- the list's arguments must have changed") + elif after.signature() != before: + c.note("the long press changed the screen: " + str(after.texts()[:12])) + else: + c.note("the long press did nothing, as the main screen's rows intend") + c.check() + c.ep.check_database() + + +@scenario("transactions_screen_selection", setup="paid", + about="selection mode on the dedicated transactions screen") +def s_transactions_screen_selection(c: Ctx) -> None: + """The other transaction list. + + `transactions_bulk_delete` works on the main screen's "Recent + transactions" section. The **dedicated** screen behind the "All" chip is + `TransactionsScreen.kt`, and its selection mode -- select all, leave + selection mode, and the delete-selected dialog -- is the uncovered half of + that file. + """ + c.back_to_home() + try: + c.app.scroll_to_text(r"(?i)^All$", max_scrolls=6) + except TimeoutError: + c.note("no All chip on the main screen: " + str(c.dev.dump().texts()[:14])) + return + c.must_tap(r"(?i)^All$", timeout=15) + time.sleep(2) + screen = c.dev.dump() + c.note("after the All chip: " + str(screen.texts()[:14])) + if screen.find(r"(?i)^Transactions$") is None: + c.note("the All chip did not open the transactions screen") + c.check() + return + c.check() + + rows = transaction_rows(screen, header=r"(?i)^Transactions$", + signed_only=True) + if not rows: + c.note("no rows on the transactions screen: " + str(screen.texts()[:14])) + c.check() + return + c.dev.long_press(rows[0]) + time.sleep(2) + screen = c.dev.dump() + c.note("selection mode: " + str(screen.texts()[:14])) + if screen.find(r"(?i)^Select All$") is None: + c.note("long press did not open selection mode here either") + c.check() + return + c.must_tap(r"(?i)^Select All$", timeout=15) + time.sleep(1.5) + c.note("after select all: " + str(c.dev.dump().texts()[:14])) + c.check() + + # Leaving selection mode is an unnamed icon button in the app bar + # (TransactionsScreen.kt:112 passes contentDescription = null), so it can + # only be found by position: the top-left clickable. + screen = c.dev.dump() + unnamed = [n for n in screen.unnamed_clickables() if n.bounds[1] < 400] + c.note(f"{len(unnamed)} unnamed clickable(s) in the app bar: " + + str([n.bounds for n in unnamed][:4])) + if unnamed: + leftmost = min(unnamed, key=lambda n: n.bounds[0]) + c.dev.tap(*leftmost.center) + time.sleep(1.5) + back = c.dev.dump() + c.note("after closing selection mode: " + str(back.texts()[:12])) + if back.find(r"(?i)^Select All$") is not None: + c.note("WARNING: still in selection mode") + c.check() + + # Round two: select all and delete, through the confirmation dialog. + screen = c.dev.dump() + rows = transaction_rows(screen, header=r"(?i)^Transactions$", + signed_only=True) + if not rows: + c.note("no rows left to select") + c.check() + return + c.dev.long_press(rows[0]) + time.sleep(2) + if not c.tap(r"(?i)^Select All$", timeout=10): + c.note("could not re-enter selection mode") + c.check() + return + time.sleep(1) + if not c.tap(r"(?i)^Delete$", timeout=15): + c.note("no Delete in the selection app bar: " + + str(c.dev.dump().texts()[:12])) + c.check() + return + dialog = c.see(r"(?i)Delete transactions|Are you sure you want to remove", + timeout=15) + c.note("the delete dialog: " + + (str(dialog.texts()[:10]) if dialog else "did not appear")) + if dialog is not None: + c.must_tap(r"(?i)^Delete$|^OK$|^Yes$", timeout=10) + time.sleep(3) + left = transaction_rows(c.dev.dump(), header=r"(?i)^Transactions$", + signed_only=True) + c.note(f"rows after deleting the selection: {len(left)}") + c.check() + c.ep.check_database() + + +@scenario("transactions_filter", setup="paid", about="the transaction list filter chip") +def s_tx_filter(c: Ctx) -> None: + open_transactions(c) + for _ in range(3): + if not c.tap(r"(?i)^All$", timeout=10): + break + time.sleep(1.5) + screen = c.dev.dump() + c.note("filter menu: " + str(screen.texts()[:12])) + c.check() + # Pick whatever option the menu offers, then come back to All. + if not c.tap(r"(?i)pending|final|complete|incoming|outgoing", timeout=8): + c.dev.back() + break + time.sleep(1.5) + c.check() + c.check() + + +def open_mailbox(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Mailbox$", max_scrolls=10) + c.must_tap(r"(?i)^Mailbox$") + c.require(r"(?i)mailbox|message|P2P|empty|Loading", timeout=25) + + +@scenario("mailbox", setup="funded", about="the P2P messaging mailbox screen") +def s_mailbox(c: Ctx) -> None: + """The mailbox screen and both of its dialogs. + + The screen has three actions in its app bar -- the address, the URL + configuration and a refresh -- and this used to tap for "Add"/"New"/"+" + and "refresh", which matched only the last of them. The two dialogs are + half of `MailboxScreen.kt`'s uncovered lines, and the address one is the + only caller of its clipboard copy. + """ + open_mailbox(c) + screen = c.dev.dump() + c.note("mailbox: " + str(screen.texts()[:14])) + c.check() + + # "Show Mailbox Address" exists only once the mailbox has registered. + if c.tap(r"(?i)^Show Mailbox Address$", timeout=10): + dialog = c.see(r"(?i)Your Mailbox Address", timeout=15) + c.note("the address dialog: " + + (str(dialog.texts()[:8]) if dialog else "did not open")) + if dialog is not None: + address = next((t for t in dialog.texts() + if "/" in t and "mailbox" in t.lower()), None) + c.note(f"the address it shows: {address}") + # The confirm button copies it to the clipboard and says so in a + # snackbar. Polled tightly on purpose: `c.see` took long enough + # over its first dump to miss it, and reported "no confirmation" + # for a message that a probe found 0.4 s after the tap. + # tap_exact, not tap: on a dialog's text buttons the ancestor + # hunt lands somewhere that dismisses the dialog instead. + if c.tap_exact(r"(?i)^Copy$", timeout=8): + snack = None + for _ in range(10): + dump = c.dev.dump() + if dump.find(r"(?i)copied to clipboard") is not None: + snack = dump + break + time.sleep(0.4) + c.note("after copying: " + + (str([t for t in snack.texts() if "clipboard" in t.lower()]) + if snack else "no confirmation seen")) + c.check() + else: + c.note("no address action; the mailbox has not registered: " + + str(c.dev.dump().texts()[:12])) + + # The URL dialog is always there, and cancelling it must change nothing. + if c.tap(r"(?i)^Configure Mailbox$", timeout=10): + dialog = c.see(r"(?i)Configure Mailbox URL|Mailbox Base URL", timeout=15) + c.note("the URL dialog: " + + (str(dialog.texts()[:8]) if dialog else "did not open")) + if dialog is not None: + c.fill("https://mailbox.example.org", 0, clear=True) + c.note("after typing a URL: " + str(c.dev.dump().texts()[:10])) + c.must_tap(r"(?i)^Cancel$", timeout=10) + time.sleep(1.5) + c.note("after cancelling: " + str(c.dev.dump().texts()[:12])) + c.check() + + if c.tap(r"(?i)^Refresh$", timeout=8): + time.sleep(3) + c.note("after refreshing: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + + +@scenario("forward_payment_to_contact", setup="funded", + about="forward a peer-push URI to a contact through the mailbox", + expects=("error-screen", "internal-error-code", "core-internal")) +def s_forward_payment_to_contact(c: Ctx) -> None: + """The app's sending side of the mailbox, which looks unreachable. + + `sendTalerUriMailboxMessage` hangs off a button that only exists in + developer mode, only on a pay-push/pay-pull QR screen, and is labelled + "Contacts" rather than anything about sending + (`compose/QrCodeUriComposable.kt:183`). Tapping it opens the contacts + screen as "Send to Contact"; confirming a contact there is the call. + + The contact is the wallet's own mailbox address, so the message has + somewhere real to go and comes back to the sender -- which also checks that + a wallet can read what it sent itself. + """ + # The wallet's own address, which it registers on first use against the + # default mailbox (now answered locally through the TLS front end). + open_mailbox(c) + if not c.tap(r"(?i)^Show Mailbox Address$", timeout=20): + c.note("no address dialog; the mailbox did not register: " + + str(c.dev.dump().texts()[:12])) + return + dialog = c.require(r"(?i)Your Mailbox Address", timeout=15) + address = next((t for t in dialog.texts() + if "mailbox" in t.lower() and "/" in t), None) + c.note(f"the wallet's own mailbox address: {address}") + c.tap(r"(?i)^Cancel$|^OK$", timeout=8) + if not address: + return + c.check() + + # A peer-push payment, which is what the forward button appears on. + c.back_to_home() + c.must_tap(r"(?i)^Send$", timeout=30) + c.require(r"(?i)Send money|Amount to send|Purpose", timeout=30) + c.set_amount("€5.00", "500") + c.must_tap(r"(?i)^Send ", timeout=30) + if not c.see(r"(?i)Scan this QR code to receive|copy and send this URI", + timeout=60): + c.note("the push never reached its QR screen: " + + str(c.dev.dump().texts()[:14])) + return + c.check() + + # "Contacts" here means "forward this payment to one". + if not c.tap_button(r"(?i)^Contacts$", timeout=20): + c.note("no forward button on the push screen (developer mode off?): " + + str(c.dev.dump().texts()[:14])) + return + picker = c.require(r"(?i)Send to Contact|No contacts yet|Add Contact", + timeout=20) + c.note("the picker: " + str(picker.texts()[:12])) + c.check() + + # Add the wallet itself as a contact, if it is not already one. + if picker.find(r"(?i)^self$") is None: + if not c.tap(r"(?i)^Add Contact$", timeout=15): + c.note("no way to add a contact from the picker") + return + c.require(r"(?i)Petname|Alias Type", timeout=15) + fields = c.dev.dump().editable() + # petname, alias, (alias type is a read-only dropdown), mailbox + c.fill("self", 0, clear=True) + c.fill(f"self-w{WORKER}@example.com", 1, clear=True) + if len(fields) >= 4: + c.fill(address, len(fields) - 1, clear=True) + else: + c.note(f"the add-contact form has {len(fields)} fields, not 4") + c.tap_button(r"(?i)^OK$|^Add$|^Save$", timeout=10) + time.sleep(3) + c.note("after adding the contact: " + str(c.dev.dump().texts()[:12])) + c.check() + + if not c.tap(r"(?i)^self$", timeout=15): + c.note("the contact is not in the list: " + + str(c.dev.dump().texts()[:14])) + return + if c.see(r"(?i)Are you sure you want to send", timeout=15): + c.tap_button(r"(?i)^OK$", timeout=10) + time.sleep(8) + c.note("after sending: " + str(c.dev.dump().texts()[:14])) + c.check() + + # The message should arrive back in this very wallet. + open_mailbox(c) + for _ in range(8): + time.sleep(5) + c.tap(r"(?i)^Refresh$", timeout=5) + inbox = c.dev.dump() + if inbox.find(r"(?i)Accept payment|Pay invoice|From:") is not None: + c.note("the forwarded payment came back: " + str(inbox.texts()[:14])) + break + else: + c.note("the forwarded message did not arrive within 40s: " + + str(c.dev.dump().texts()[:14])) + c.check() + c.ep.check_database() + + +@scenario("mailbox_roundtrip", setup="funded", + about="register with a real mailbox service, receive and delete a message", + expects=("error-screen", "internal-error-code", "core-internal")) +def s_mailbox_roundtrip(c: Ctx) -> None: + """The mailbox screen against a deployed taler-mailbox. + + Its URL is the one service address the app lets the user type in, so no + DNS or TLS games are needed: point it at the local service, let the wallet + register itself, deliver a message to its address the way another wallet + would, and read and delete it. + """ + url = service_or_skip(c, LOCAL_MAILBOX, "mailbox") + if url is None: + return + open_mailbox(c) + c.check() + # "Configure Mailbox" is an icon; its content description is the only name. + if not c.tap(r"(?i)^Configure Mailbox$", timeout=15): + c.note("no way to configure the mailbox URL: " + + str(c.dev.dump().texts()[:12])) + return + screen = c.require(r"(?i)Configure Mailbox URL|Mailbox Base URL", timeout=15) + if not screen.editable(): + c.note("no URL field in the dialog") + return + # The field comes pre-filled with the production URL. + if not c.fill(url.rstrip("/"), 0, clear=True): + c.note("could not type the mailbox URL") + return + c.tap_button(r"(?i)^OK$", timeout=10) + time.sleep(6) + c.note("after configuring: " + str(c.dev.dump().texts()[:14])) + c.check() + # The wallet registers itself on first use; its address is behind the info + # icon. + if not c.tap(r"(?i)^Show Mailbox Address$", timeout=15): + c.note("no address dialog; the mailbox may not have registered") + return + dialog = c.require(r"(?i)Your Mailbox Address", timeout=15) + address = next((t for t in dialog.texts() if "localhost:11000" in t), None) + c.note(f"the wallet's mailbox address: {address}") + c.tap(r"(?i)^Cancel$", timeout=8) + if not address: + c.note("WARNING: the address dialog showed no address") + return + h_address = address.rstrip("/").rsplit("/", 1)[-1] + c.check() + + # Deliver a real message: the CLI wallet encrypts a taler:// URI for this + # address, which is what another wallet would do. (The app itself has no + # caller for sendTalerUriMailboxMessage, so it can only receive.) + # Two messages, differing only in the scheme of the URI they carry: the + # row offers "Accept payment" only for a literal taler:// prefix, so the + # developer-mode scheme the rest of the app accepts everywhere else falls + # through to a bare string. + for scheme in ("taler://", "taler+http://"): + try: + sent = c.cli.send_mailbox_message( + h_address.upper(), + f"{scheme}pay-push/localhost:8081/" + "A" * 52, + mailbox_base=url.replace("localhost", "127.0.0.1")) + c.note(f"another wallet sent a {scheme} message: {str(sent)[:120]}") + except Exception as e: # noqa: BLE001 + c.note(f"the peer wallet could not send {scheme}: {str(e)[:160]}") + time.sleep(2) + c.tap(r"(?i)^Refresh$", timeout=10) + time.sleep(8) + listed = c.dev.dump() + c.note("after two real messages: " + str(listed.texts()[:20])) + if listed.find(r"(?i)No messages yet") is not None: + c.note("WARNING: a message another wallet sent does not appear") + actions = [t for t in listed.texts() + if t.strip() in ("Accept payment", "Pay invoice")] + raw = [t for t in listed.texts() if t.startswith(("taler://", "taler+http://"))] + c.note(f"rows offering an action: {len(actions)}; rows showing a raw URI: {raw}") + if raw: + c.note("WARNING: a received payment with no way to accept it") + c.check() + + # And one the wallet cannot read: anyone may POST to a mailbox address, so + # what the app does with junk is worth knowing. It turns out to fetch it, + # fail to make sense of it, delete it from the server and say nothing -- + # which is the right instinct for a public drop box. + import urllib.request + # The service insists on exactly message_body_bytes, so ask it how long a + # message is rather than guessing (43 bytes earns a flat 400). + size = 256 + try: + with urllib.request.urlopen(url + "config", timeout=5) as r: + size = int(json.loads(r.read()).get("message_body_bytes", 256)) + except Exception as e: # noqa: BLE001 + c.note(f"could not read the mailbox config: {str(e)[:80]}") + c.note(f"a message is {size} bytes here") + # Not a valid envelope: what the app does with a message it cannot make + # sense of is worth knowing too. + body = (b"simulator test message, not a valid envelope. " + * (size // 46 + 1))[:size] + req = urllib.request.Request(url + h_address.upper(), data=body, + method="POST") + try: + with urllib.request.urlopen(req, timeout=10) as r: + c.note(f"delivered a message: HTTP {r.status}") + except Exception as e: # noqa: BLE001 + c.note(f"could not deliver a message: {str(e)[:160]}") + time.sleep(2) + c.tap(r"(?i)^Refresh$", timeout=10) + time.sleep(6) + after = c.dev.dump() + c.note("after refreshing: " + str(after.texts()[:16])) + c.check() + # A message row offers a delete button; that is the only path to + # deleteMailboxMessage. + if c.tap(r"(?i)^Delete$|delete message", timeout=10): + time.sleep(3) + c.note("after deleting: " + str(c.dev.dump().texts()[:14])) + c.check() + c.ep.check_database() + + +@scenario("contacts_list", setup="funded", about="the contacts screen from settings") +def s_contacts_list(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Contacts$", max_scrolls=10) + c.must_tap(r"(?i)^Contacts$") + c.require(r"(?i)contact|alias|empty", timeout=25) + c.note("contacts: " + str(c.dev.dump().texts()[:14])) + c.check() + c.tap(r"(?i)^Add$|^New$|Add contact", timeout=8) + c.check() + + +@scenario("uri_add_contact", setup="funded", about="a taler://add-contact/ URI") +def s_uri_add_contact(c: Ctx) -> None: + for uri in (f"taler+http://add-contact/{corpus.EXCHANGE}/{corpus.FAKE_ID}", + "taler+http://add-contact/"): + c.app.handle_uri(uri) + time.sleep(2.5) + c.note(f"{uri[:48]}: {c.dev.dump().texts()[:8]}") + c.check() + c.back_to_home() + + +@scenario("uri_dev_experiment", setup="funded", about="a taler://dev-experiment/ URI") +def s_uri_dev_experiment(c: Ctx) -> None: + for uri in ("taler+http://dev-experiment/nonexistent", + "taler+http://dev-experiment/", + "taler+http://dev-experiment/" + "x" * 300): + c.app.handle_uri(uri) + time.sleep(2.5) + c.note(f"{uri[:42]}: {c.dev.dump().texts()[:8]}") + c.check() + c.back_to_home() + + +@scenario("payment_insufficient_reason", setup="funded", + about="a payment refused for a named reason, not just 'insufficient'", + expects=("error-screen", "internal-error-code", "core-internal")) +def s_payment_insufficient_reason(c: Ctx) -> None: + """The typed half of `PaymentResponses.kt`. + + `payment_insufficient` reaches the plain "not enough money" case. The + insufficient-balance *details* -- `PaymentInsufficientBalanceDetails`, + `PerExchange`, and the mapping from each reason to its own hint string at + `PaymentResponses.kt:186` -- need a refusal with a reason attached, and the + wallet cannot manufacture one. wallet-core can: the + `merchant-deposit-insufficient` dev experiment + (`dev-experiments.ts:269`) makes the next payment fail as though the + merchant's account could not take the deposit. + """ + c.app.handle_uri("taler+http://dev-experiment/merchant-deposit-insufficient") + time.sleep(3) + c.note("after arming the experiment: " + str(c.dev.dump().texts()[:10])) + c.back_to_home() + c.check() + + # A neutral summary on purpose: the first version called the order + # "Order the merchant cannot take", and every pattern below then matched + # the summary instead of the wallet's own text. + order = c.merchant.create_order("EUR:1", summary="Simulator order") + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)Review order|Total|^Pay\b|Insufficient balance", + timeout=60) + c.note("the prompt: " + str(screen.texts()[:16])) + c.check() + # "Insufficient balance" is the state; the hint beside it is the reason, + # and the reason is what PaymentResponses.kt:186 maps. + state = screen.find(r"(?i)^Insufficient balance$") + if state is None and c.tap_button(r"(?i)^Pay\b", timeout=20): + time.sleep(6) + screen = c.dev.dump() + c.note("after confirming: " + str(screen.texts()[:16])) + state = screen.find(r"(?i)^Insufficient balance$") + c.note(f"the wallet says the balance is insufficient: {state is not None}") + # One of the seven hint strings, matched on wording the order summary + # cannot contain. + hint = screen.find( + r"(?i)wire method of the payment service" + r"|doesn't accept money from one or more" + r"|due to age restriction" + r"|missing the global fee configuration" + r"|fees not covered by the merchant" + r"|coins needed for this purchase are currently unavailable") + c.note(f"a reason-specific hint: {hint is not None}" + + (f" -- {hint.label[:140]}" if hint is not None else "")) + if state is not None and hint is None: + c.note("WARNING: insufficient balance with no reason shown, though " + "the experiment armed a specific one") + c.check() + c.ep.check_database() + + +@scenario("payment_template", setup="funded", about="pay through an order template") +def s_payment_template(c: Ctx) -> None: + c.merchant.create_template("simtemplate", "EUR:1") + uri = (f"taler+http://pay-template/localhost:8080/instances/" + f"{c.merchant.instance}/simtemplate") + c.app.handle_uri(uri) + screen = c.see(r"(?i)amount|summary|Pay|Order|template", timeout=40) + c.note("template prompt: " + str(screen.texts()[:12] if screen else None)) + c.check() + # Templates can ask for the amount and the subject. + if screen and screen.editable(): + c.fill("1") + c.tap(r"(?i)^Pay|^Continue$|^Next$|^Order$", timeout=20) + time.sleep(4) + c.note("after template pay: " + str(c.dev.dump().texts()[:10])) + c.check() + + +@scenario("payment_expired", setup="funded", about="pay an order whose deadline has passed") +def s_payment_expired(c: Ctx) -> None: + import time as _t + deadline = int(_t.time()) + 5 + order = c.merchant.create_order( + "EUR:1", summary="Order that expires at once", + pay_deadline={"t_s": deadline}, + ) + _t.sleep(10) + c.app.handle_uri(order["pay_uri"]) + time.sleep(3) + c.note("expired order: " + str(c.dev.dump().texts()[:12])) + c.check() + + +@scenario("payment_deleted_order", setup="funded", + about="pay an order the merchant deleted in the meantime") +def s_payment_deleted(c: Ctx) -> None: + order = c.merchant.create_order("EUR:1", summary="Order about to vanish") + try: + c.merchant.delete_order(order["order_id"]) + c.note("merchant deleted the order") + except Exception as e: + c.note(f"merchant refused to delete the order: {e}") + c.app.handle_uri(order["pay_uri"]) + time.sleep(3) + c.note("after paying a deleted order: " + str(c.dev.dump().texts()[:12])) + c.check() + + +@scenario("refresh_history", setup="paid", + about="the refresh transaction left behind by paying") +def s_refresh_history(c: Ctx) -> None: + screen = open_transactions(c) + rows = transaction_rows(screen) + c.note(f"rows: {[n.label[:24] for n in rows]}") + # Change ("refresh") transactions appear after spending part of a coin. + for index, node in enumerate(rows): + screen = open_transactions(c) + rows_now = transaction_rows(screen) + if index >= len(rows_now): + break + c.dev.tap_node(rows_now[index], screen) + time.sleep(2) + detail = c.dev.dump() + if detail.find(r"(?i)change|refresh"): + c.note(f"change transaction detail: {detail.texts()[:10]}") + c.check() + c.dev.back() + time.sleep(1) + c.check() + + +@scenario("lifecycle_kill", setup="fresh", + about="suspend, kill the app, relaunch, resume: does the state survive?") +def s_lifecycle_kill(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + c.must_tap(r"(?i)^Suspend$") + time.sleep(2) + suspended = c.dev.dump().texts() + c.note(f"suspended: {suspended[:8]}") + # Process death without a clean shutdown, the way the system would do it. + c.dev.kill() + time.sleep(2) + c.dev.launch() + time.sleep(6) + c.check() + screen = open_transactions(c) + rows = transaction_rows(screen) + c.note(f"after relaunch, {len(rows)} rows: {[n.label[:24] for n in rows]}") + if rows: + c.dev.tap_node(rows[0], screen) + time.sleep(2) + detail = c.dev.dump() + c.note(f"detail after relaunch: {detail.texts()[:10]}") + # A suspended transaction must still offer Resume. + if detail.find(r"(?i)^Resume$") is None: + c.note("WARNING: no Resume on a suspended transaction after process death") + c.tap(r"(?i)^Resume$", timeout=15) + time.sleep(3) + c.check() + c.ep.check_database() + + +@scenario("abort_then_retry", setup="fresh", + about="abort a withdrawal, then hand the same URI in again") +def s_abort_then_retry(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + uri = op["taler_withdraw_uri"] + c.app.handle_uri(uri) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + c.must_tap(r"(?i)^Abort$") + if c.see(r"(?i)Abort transaction|Are you sure", timeout=10): + c.tap(r"(?i)^Abort$|^OK$|^Yes$") + time.sleep(3) + c.check() + # The same URI again: the operation is dead at the bank, so the wallet has + # to say so rather than start over. + c.app.handle_uri(uri) + time.sleep(4) + c.note("re-handled an aborted withdraw URI: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + + +@scenario("amount_edges_deposit", setup="funded", + about="hostile amounts in the deposit amount field") +def s_amount_edges_deposit(c: Ctx) -> None: + values = ["0", "0.00", "-1", "999999999", "1.999", "0.001", "1e5", "abc", "9.87"] + for value in values: + c.back_to_home() + if not c.tap(r"(?i)^Deposit$", timeout=20): + c.note("no Deposit button on the balance card") + return + screen = c.see(r"(?i)deposit to bank account|x-taler-bank|Amount to deposit", + timeout=20) + if screen is not None and screen.find(r"(?i)Amount to deposit") is None: + # Pick a target account to reach the amount field. + account = (screen.find(r"(?i)^wallet\d+$") + or screen.find(r"(?i)x-taler-bank")) + if account is not None: + c.dev.tap_node(account, screen) + time.sleep(2) + if not c.fill(value): + c.note(f"no amount field for {value!r}") + c.dev.back() + continue + time.sleep(1) + screen = c.dev.dump() + c.note(f"{value!r}: {[t for t in screen.texts() if 'nvalid' in t or 'xceed' in t or 'rror' in t][:3]}") + # Try to proceed; a bad amount must not get past the form. + c.tap(r"(?i)^Make deposit$|^Check fees$|^Deposit$|^Next$", timeout=8) + time.sleep(1.5) + c.check() + c.back_to_home() + c.ep.check_database() + + +@scenario("amount_edges_peer", setup="funded", + about="hostile amounts in the peer send amount field") +def s_amount_edges_peer(c: Ctx) -> None: + values = ["0", "-5", "100000", "1.999", "0.001", "9.87", "1,5"] + for value in values: + c.back_to_home() + if not c.tap(r"(?i)^Send$", timeout=20): + c.note("no Send button on the balance card") + return + c.see(r"(?i)Amount to send|Purpose|Send money", timeout=20) + if not c.fill(value): + c.note(f"no amount field for {value!r}") + c.dev.back() + continue + time.sleep(1) + screen = c.dev.dump() + c.note(f"{value!r}: {[t for t in screen.texts() if 'nvalid' in t or 'xceed' in t or 'rror' in t][:3]}") + c.tap(r"(?i)^Send ", timeout=8) + time.sleep(1.5) + c.check() + c.back_to_home() + c.ep.check_database() + + +@scenario("offline_withdraw", setup="fresh", + about="lose the network in the middle of a withdrawal, then get it back") +def s_offline_withdraw(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + # Airplane mode: the emulator keeps the adb connection, so the driver can + # still watch what the app does without a network. + c.dev.shell("cmd connectivity airplane-mode enable", check=False) + time.sleep(3) + c.bank.confirm_withdrawal(*flows.WALLET_USER, op["withdrawal_id"]) + time.sleep(6) + c.note("offline: " + str(c.dev.dump().texts()[:10])) + c.check() + c.tap(r"(?i)^Retry$", timeout=10) + time.sleep(3) + c.check() + c.dev.shell("cmd connectivity airplane-mode disable", check=False) + time.sleep(8) + # Once the network is back the withdrawal should finish on its own. + done = False + for _ in range(12): + if c.dev.dump().find(r"(?i)completed successfully"): + done = True + break + c.tap(r"(?i)^Retry$", timeout=4) + time.sleep(5) + c.note(f"recovered after reconnect: {done}") + if not done: + c.note("WARNING: withdrawal did not complete after the network came back") + c.check() + c.ep.check_database() + + +@scenario("concurrent_uris", setup="funded", about="two pay URIs delivered back to back") +def s_concurrent_uris(c: Ctx) -> None: + first = c.merchant.create_order("EUR:1", summary="First of two") + second = c.merchant.create_order("EUR:1", summary="Second of two") + c.dev.send_uri(first["pay_uri"]) + time.sleep(0.8) + c.dev.send_uri(second["pay_uri"]) + time.sleep(4) + screen = c.dev.dump() + c.note("after two URIs: " + str(screen.texts()[:12])) + c.check() + c.tap(r"(?i)^Pay", timeout=20) + time.sleep(4) + for order in (first, second): + status = c.merchant.order_status(order["order_id"], order["token"]) + c.note(f"{order['order_id']}: {status.get('order_status')}") + c.check() + c.ep.check_database() + + +@scenario("exchange_delete_with_coins", setup="funded", + about="delete (and purge) an exchange the wallet holds coins at") +def s_exchange_delete_with_coins(c: Ctx) -> None: + open_exchange_list(c) + if not exchange_menu(c): + raise RuntimeError(f"no exchange menu; screen: {c.dev.dump().texts()}") + c.must_tap(r"(?i)^Delete payment service$") + screen = c.see(r"(?i)Force deletion|Are you sure|purge|Delete", timeout=20) + c.note("delete dialog: " + str(screen.texts()[:10] if screen else None)) + c.check() + # Refusing to delete while coins remain is correct; forcing it is the + # interesting path. + c.tap(r"(?i)Force deletion", timeout=10) + c.tap(r"(?i)^Delete$|^OK$|^Yes$", timeout=10) + time.sleep(4) + c.note("after forced deletion: " + str(c.dev.dump().texts()[:12])) + c.check() + c.back_to_home() + c.note("home after purge: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + + +@scenario("tos_reject_midflow", setup="fresh", + about="reject the terms of service while a withdrawal is pending") +def s_tos_reject_midflow(c: Ctx) -> None: + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + open_exchange_list(c) + if exchange_menu(c): + if c.tap(r"(?i)^Reject terms of service$"): + time.sleep(3) + c.note("rejected the terms of service mid-withdrawal") + c.check() + c.bank.confirm_withdrawal(*flows.WALLET_USER, op["withdrawal_id"]) + time.sleep(8) + c.back_to_home() + c.note("after the bank confirmed: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + + +@scenario("tokens_issue_and_view", setup="funded", + about="pay a v1 order that issues a discount token, then view it") +def s_tokens_issue(c: Ctx) -> None: + c.merchant.create_token_family("simdiscount", "discount") + order = c.merchant.create_v1_order( + [{"amount": "EUR:1", "description": "Buy one, get a discount token", + "inputs": [], "outputs": [c.merchant.token_output("simdiscount")], + "max_fee": "EUR:0.5"}], + summary="Issues a discount token", + ) + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)Review order|Total:|^Pay", timeout=60) + c.note("v1 prompt: " + str(screen.texts()[:14])) + c.check() + c.must_tap(r"(?i)^Pay\b|confirm payment", timeout=40) + paid = False + for _ in range(20): + if c.merchant.order_status(order["order_id"], + order["token"]).get("order_status") == "paid": + paid = True + break + time.sleep(2) + c.note(f"order paid: {paid}") + # The issued token should now show up under Discounts. + c.back_to_home() + try: + c.app.scroll_to_text(r"(?i)^Discounts$", max_scrolls=5) + except TimeoutError: + c.note("no Discounts section on the main screen") + c.check() + return + c.must_tap(r"(?i)^Discounts$") + screen = c.require(r"(?i)discount|available|expired|empty", timeout=25) + c.note("discounts screen: " + str(screen.texts()[:14])) + for tab in (r"(?i)^Available$", r"(?i)^Expired$"): + c.tap(tab, timeout=8) + c.check() + c.check() + c.ep.check_database() + + +# An 8x8 red PNG, which is enough for the wallet to decode and draw. The +# wallet accepts exactly `data:image/(jpeg|png);base64,<b64>` +# (AndroidUtils.kt:278), so the prefix matters. +PRODUCT_IMAGE = ( + "data:image/png;base64," + "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAEUlEQVR4nGM4ISeHFTEMLQkA" + "kL9BAbKfPiIAAAAASUVORK5CYII=" +) + + +@scenario("payment_product_image", setup="funded", + about="an order whose product carries an image, and the image dialog") +def s_payment_product_image(c: Ctx) -> None: + """`ProductImageDialog` has exactly one caller: tapping a product's image + on the payment prompt. No order any scenario made carried an image, so + neither the image nor the dialog had ever been drawn. + """ + order = c.merchant.create_order( + "EUR:2", summary="Order with a pictured product", + products=[{"description": "A red square", "price": "EUR:2", + "image": PRODUCT_IMAGE, "quantity": 1}], + ) + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)A red square|Review order|^Pay\b", timeout=60) + c.note("prompt with a product: " + str(screen.texts()[:14])) + if screen.find(r"(?i)A red square") is None: + c.note("WARNING: the product is not on the prompt at all") + c.check() + + # The image carries no content description (PromptPaymentComposable.kt:372 + # passes null), so it can only be found as an unnamed clickable -- which + # is also what a11y_audit would say about it, if any order it saw had an + # image. + unnamed = screen.unnamed_clickables() + c.note(f"{len(unnamed)} unnamed clickable(s): " + + str([n.bounds for n in unnamed][:6])) + if not unnamed: + c.note("no unnamed clickable, so the image did not render") + c.check() + return + target = min(unnamed, key=lambda n: n.area) + c.dev.tap(*target.center) + time.sleep(2) + after = c.dev.dump() + c.note("after tapping the image: " + str(after.texts()[:12])) + # The dialog is its own window with no text in it, so what says it opened + # is that the prompt behind it is no longer in the dump. + if after.find(r"(?i)^Pay\b|Review order") is None: + c.note("the image dialog is up: the prompt is no longer dumped") + c.check() + # It dismisses by being tapped. + c.dev.tap(*target.center) + time.sleep(2) + back = c.dev.dump() + c.note("after dismissing: " + str(back.texts()[:12])) + if back.find(r"(?i)^Pay\b|Review order") is None: + c.note("WARNING: the prompt did not come back") + else: + c.note("tapping the smallest unnamed clickable changed nothing; " + "the image may be elsewhere in the row") + c.check() + # Leave nothing pending behind. + c.tap(r"(?i)^Cancel$|^Abort$", timeout=8) + c.ep.check_database() + + +@scenario("payment_choices", setup="funded", + about="a v1 order with several choices to pick from") +def s_payment_choices(c: Ctx) -> None: + c.merchant.create_token_family("simdiscount", "discount") + order = c.merchant.create_v1_order( + [ + {"amount": "EUR:2", "description": "Full price", "inputs": [], + "outputs": [], "max_fee": "EUR:0.5"}, + {"amount": "EUR:1", "description": "Discounted, needs a token", + "inputs": [c.merchant.token_input("simdiscount")], "outputs": [], + "max_fee": "EUR:0.5"}, + {"amount": "EUR:3", "description": "Full price plus a token", + "inputs": [], "outputs": [c.merchant.token_output("simdiscount")], + "max_fee": "EUR:0.5"}, + ], + summary="Three ways to pay", + ) + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)Review order|choice|Full price|Total:|^Pay", timeout=60) + c.note("choices prompt: " + str(screen.texts()[:18])) + c.check() + # Pick the choice that needs no token, then pay it. + c.tap(r"(?i)Full price$", timeout=15) + c.check() + c.tap(r"(?i)^Pay\b|confirm payment", timeout=30) + time.sleep(4) + status = c.merchant.order_status(order["order_id"], order["token"]) + c.note(f"order status: {status.get('order_status')}") + c.check() + c.ep.check_database() + + +@scenario("subscription_issued_and_viewed", setup="funded", + about="buy a subscription token and open it under Passes") +def s_subscription_issued_and_viewed(c: Ctx) -> None: + """A subscription the wallet actually holds. + + `payment_needs_token` creates a subscription family and *demands* the + token, so the wallet never holds one and `PassList`'s rows never render -- + the pass list item and `SubscriptionListDetail` are the uncovered half of + `TokenListScreen`. This buys one instead: an order whose output is a + subscription token. + """ + c.merchant.create_token_family("simsub", "subscription", "Simulator pass") + order = c.merchant.create_v1_order( + [{"amount": "EUR:2", "description": "A month of something", + "inputs": [], "outputs": [c.merchant.token_output("simsub")], + "max_fee": "EUR:0.5"}], + summary="Subscription purchase", + ) + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)Review order|Total:|^Pay\b|subscription", timeout=60) + c.note("subscription prompt: " + str(screen.texts()[:14])) + c.check() + c.must_tap(r"(?i)^Pay\b|confirm payment", timeout=30) + deadline = time.time() + 60 + paid = False + while time.time() < deadline: + if c.merchant.order_status(order["order_id"], + order["token"]).get("order_status") == "paid": + paid = True + break + time.sleep(2) + c.note(f"the merchant says the order was paid: {paid}") + c.check() + + # "Passes" is the subscription view; "Discounts" is the other one. + c.back_to_home() + try: + c.app.scroll_to_text(r"(?i)^Passes$", max_scrolls=6) + except TimeoutError: + c.note("no Passes entry on the main screen: " + + str(c.dev.dump().texts()[:16])) + c.check() + c.ep.check_database() + return + c.must_tap(r"(?i)^Passes$", timeout=10) + time.sleep(2.5) + screen = c.dev.dump() + c.note("passes: " + str(screen.texts()[:16])) + # Not matched on the family's name: `create_token_family` returns 409 when + # the slug exists and leaves the old name in place, so "simsub" is called + # whatever the scenario that created it first called it. What says a pass + # is listed is a row with a validity. + if screen.find(r"(?i)^Active$|Valid until") is None: + c.note("WARNING: the pass the wallet just bought is not listed") + c.check() + # Tapping a row opens its detail, which is its own composable. + rows = [n for n in screen.labelled() + if re.search(r"(?i)Valid until|^Active$|tokens issued", n.label)] + if rows: + c.dev.tap(*rows[0].center) + time.sleep(2) + c.note("pass detail: " + str(c.dev.dump().texts()[:14])) + c.check() + for tab in (r"(?i)^Available$", r"(?i)^Expired$"): + if c.tap(tab, timeout=6): + time.sleep(1.5) + c.note(f"{tab}: " + str(c.dev.dump().texts()[:10])) + c.check() + c.ep.check_database() + + +@scenario("payment_needs_token", setup="funded", + about="an order that can only be paid with a token the wallet lacks") +def s_payment_needs_token(c: Ctx) -> None: + c.merchant.create_token_family("simsub", "subscription") + order = c.merchant.create_v1_order( + [{"amount": "EUR:0", "description": "Subscribers only", + "inputs": [c.merchant.token_input("simsub")], "outputs": [], + "max_fee": "EUR:0.5"}], + summary="Requires a subscription token", + ) + c.app.handle_uri(order["pay_uri"]) + time.sleep(4) + screen = c.dev.dump() + c.note("prompt without the token: " + str(screen.texts()[:16])) + # The wallet should explain that it cannot satisfy the contract. + if screen.find(r"(?i)token|subscription|cannot|unavailable|missing|insufficient") is None: + c.note("WARNING: nothing on screen explains the missing token") + c.check() + c.ep.check_database() + + +@scenario("payment_pos_confirmation", setup="funded", + about="an order tied to a point-of-sale device shows its TOTP code") +def s_payment_pos_confirmation(c: Ctx) -> None: + """`PayTotpComposable` is only reachable through a pos_confirmation. + + The merchant puts one in the pay reply when the order names an OTP + device, and the wallet then renders the code (and an NDEF message) on the + payment's detail screen. + """ + c.merchant.create_otp_device("simpos") + order = c.merchant.create_order("EUR:1", summary="Point of sale order", + otp_id="simpos") + c.app.handle_uri(order["pay_uri"]) + c.app.dev.tap_text(r"(?i)^pay\b|confirm payment", timeout=60) + deadline = time.time() + 90 + while time.time() < deadline: + if c.merchant.order_status(order["order_id"], + order["token"]).get("order_status") == "paid": + break + time.sleep(2) + else: + raise RuntimeError(f"order {order['order_id']} was not paid") + screen = c.require(r"(?i)Payment|Completed|paid", timeout=45) + c.note("after paying a pos order: " + str(screen.texts()[:16])) + # The merchant returns every T-OTP code in the valid time range, newline + # separated, and the wallet prints the lot in one Text node. + codes = [line.strip() for t in screen.texts() for line in t.splitlines() + if re.fullmatch(r"\d{6,}", line.strip())] + c.note(f"confirmation codes on the detail screen: {codes}") + if not codes: + c.note("WARNING: no pos_confirmation shown for an order with an OTP device") + elif len(codes) > 1: + c.note(f"WARNING: {len(codes)} codes shown under a singular label") + c.check() + # A TOTP code is valid for 30 s, and the composable has a timer that + # recomputes it -- so staying on the screen for one period is the only way + # to run that half of PayTotpComposable. + time.sleep(35) + later = c.dev.dump() + codes_later = [line.strip() for x in later.texts() for line in x.splitlines() + if re.fullmatch(r"\d{6,}", line.strip())] + c.note(f"codes after one TOTP period: {codes_later}") + if codes and codes_later and codes == codes_later: + c.note("the codes did not change across a TOTP period") + c.check() + c.ep.check_database() + + +@scenario("a11y_audit", setup="paid", + about="walk the main screens and list clickable elements with no name") +def s_a11y_audit(c: Ctx) -> None: + """Every unnamed clickable node is a control a screen reader cannot announce. + + Layout containers show up too, so this records rather than judges; what + makes it useful is the per-screen count and the neighbouring labels, which + is how the Send/Request/Withdraw/Deposit defect was spotted. + """ + visited: dict[str, int] = {} + + def audit(where: str) -> None: + screen = c.dev.dump() + unnamed = screen.unnamed_clickables() + visited[where] = len(unnamed) + if unnamed: + near = [] + for node in unnamed[:6]: + label = min( + (n for n in screen.labelled()), + key=lambda n: abs(n.center[1] - node.center[1]) + + abs(n.center[0] - node.center[0]) // 4, + default=None, + ) + near.append(f"{node.cls.rsplit('.', 1)[-1]}@{node.center}" + f"~{label.label[:18] if label else '?'}") + c.note(f"{where}: {len(unnamed)} unnamed clickables: {near}") + else: + c.note(f"{where}: all clickable elements are named") + c.check() + + c.back_to_home() + audit("main") + c.app.open_settings() + audit("settings") + for label, where in ((r"(?i)^Payment services$", "exchange list"), + (r"(?i)^Bank accounts$", "bank accounts")): + c.app.open_settings() + try: + c.app.scroll_to_text(label, max_scrolls=10) + except TimeoutError: + continue + if c.tap(label): + audit(where) + c.back_to_home() + for label, where in ((r"(?i)^Send$", "peer send"), (r"(?i)^Request$", "peer request"), + (r"(?i)^Deposit$", "deposit"), (r"(?i)^Withdraw$", "withdraw")): + c.back_to_home() + if c.tap(label, timeout=15): + audit(where) + screen = open_transactions(c) + rows = transaction_rows(screen) + if rows: + c.dev.tap_node(rows[0], screen) + time.sleep(2) + audit("transaction detail") + c.note(f"summary: {visited}") + c.check() + + +@scenario("exchange_url_fuzz", setup="fresh", + about="hostile payment-service URLs in the add-exchange field") +def s_exchange_url_fuzz(c: Ctx) -> None: + urls = [ + "", + "not a url", + "http://", + "http://localhost:9/", # nothing listening + "http://localhost:8082/", # a bank, not an exchange + "https://localhost:8081/", # right host, wrong scheme + "http://localhost:8081/../../etc/passwd", + "http://127.0.0.1:8081/", # same exchange, other spelling + "http://localhost:8081/" + "a" * 500, + "http://日本語.example/", + "javascript:alert(1)", + "file:///etc/passwd", + ] + # The dialog closes back onto the exchange list, so the list is opened + # once and every address goes through from there. + open_exchange_list(c) + for url in urls: + if not c.tap(r"(?i)^Add payment service$", timeout=20): + c.note("no add-payment-service entry; " + + str(c.dev.dump().texts()[:8])) + break + screen = c.see(r"(?i)Enter address of payment service|address", timeout=20) + fields = screen.editable() if screen else [] + if not fields: + c.note("no URL field") + c.dev.back() + continue + c.dev.tap_node(fields[0], screen) + if url: + c.dev.type_text(url) + c.tap(r"(?i)^OK$|^Add$|^Continue$|^Next$", timeout=10) + time.sleep(2) + after = c.dev.dump() + c.note(f"{url[:46]!r} -> {after.texts()[:8]}") + c.check() + if after.find(r"(?i)Enter address of payment service") is not None: + # The dialog stayed open (it should, with an error); close it. + c.tap(r"(?i)^Cancel$", timeout=6) + c.ep.check_database() + + +@scenario("peer_expiry_custom", setup="funded", + about="the peer-send expiry picker, including a custom period") +def s_peer_expiry(c: Ctx) -> None: + c.back_to_home() + c.must_tap(r"(?i)^Send$", timeout=30) + c.require(r"(?i)Send money|Amount to send|Purpose", timeout=30) + c.set_amount("€5.00", "500") + for option in (r"(?i)^1 day$", r"(?i)^1 week$", r"(?i)^30 days$", r"(?i)^Custom$"): + if not c.tap(r"(?i)Expires in|^1 week$|^1 day$|^30 days$|^Custom$", timeout=8): + break + if c.tap(option, timeout=8): + c.note(f"picked {option}") + c.check() + # Custom opens day and hour fields. + screen = c.dev.dump() + if screen.find(r"(?i)^Days$|^Hours$"): + c.note("custom expiry fields: " + str(screen.texts()[:10])) + c.fill("3", 1) + c.check() + c.tap(r"(?i)^Send ", timeout=20) + time.sleep(4) + c.note("after send: " + str(c.dev.dump().texts()[:10])) + c.check() + c.ep.check_database() + + +@scenario("deposit_methods", setup="funded", + about="all three deposit account types and their validation") +def s_deposit_methods(c: Ctx) -> None: + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Bank accounts$") + c.must_tap(r"(?i)^Bank accounts$") + c.require(r"(?i)Known bank accounts|No bank accounts saved|Add account", timeout=25) + if not c.tap(r"(?i)^Add account$", timeout=20): + c.note("no add-account entry") + return + c.require(r"(?i)IBAN|x-taler-bank|Bitcoin|Account holder", timeout=25) + cases = [ + (r"(?i)^IBAN$", [("Holder One", 0), ("DE89370400440532013000", 1)]), + (r"(?i)^x-taler-bank$", [("Holder Two", 0), ("http://localhost:8082/wallet1", 1)]), + # The Bitcoin tab has no holder field: its first field is the address + # and the second is the note. Filling them the other way round sent + # `payto://bitcoin/Holder%20Three` and read as a wallet defect. + (r"(?i)^Bitcoin$", [("bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh", 0), + ("Holder Three", 1)]), + ] + for tab, fields in cases: + # A successful submit closes the form and goes back to the account + # list, so every case has to open it again -- without this the first + # case to succeed left the later tabs with no form to tap, and the + # Bitcoin one was never tried ("no Bitcoin tab"). + if c.dev.dump().find(r"(?i)^Note$") is None: + if not c.tap_button(r"(?i)^Add account$", timeout=15): + c.note("could not reopen the add-account form") + break + # "IBAN" is also the wire method printed on an account *row*, so + # requiring it matches the list we just came from; the note field + # exists only on the form. + if c.see(r"(?i)^Note$", timeout=20) is None: + c.note("the add-account form did not reopen: " + + str(c.dev.dump().texts()[:10])) + break + if not c.tap(tab, timeout=10): + c.note(f"no {tab} tab: " + str(c.dev.dump().texts()[:10])) + continue + c.check() + for value, index in fields: + c.fill(value, index, clear=True) + # Every type needs the unmarked "Note" field, or the submit button + # stays disabled and the account is never added -- which is how this + # scenario reported "ok" while adding nothing. + name = re.sub(r"[^A-Za-z-]", "", tab.replace("(?i)", "")) + fill_account_note(c, f"Simulator {name}") + time.sleep(1) + screen = c.dev.dump() + complaints = [t for t in screen.texts() + if "invalid" in t.lower() or "error" in t.lower()] + c.note(f"{tab}: complaints={complaints[:2]} labels={screen.texts()[:8]}") + c.tap_button(r"(?i)^Add account$|^Save$|^OK$", timeout=8) + time.sleep(3) + c.note(f"{tab} after submitting: {c.dev.dump().texts()[:10]}") + c.check() + c.ep.check_database() + + +@scenario("deposit_bad_payto", setup="funded", + about="deposit to an account the exchange will reject, then read the " + "failed transaction") +def s_deposit_bad_payto(c: Ctx) -> None: + # A syntactically fine IBAN that belongs to nobody: the deposit should be + # accepted by the wallet and then fail, which is the only cheap way to + # reach the failed-transaction screens. + bad = "payto://iban/SANDBOXX/DE02100100109307118603?receiver-name=Nobody" + c.app.handle_uri(bad) + time.sleep(3) + screen = c.dev.dump() + c.note("payto prompt: " + str(screen.texts()[:12])) + c.check() + if screen.editable(): + # Amount fields take digits from the right: "100" is 1.00, and "1" + # made a one-cent deposit. No clear=True: on this field the 80 + # KEYCODE_DELs leave it at 0.00 and the typed digits do not land, so + # the submit button stays disabled. + c.fill("100") + # The button on this screen is "Send", not "Deposit": tapping for the + # latter did nothing at all, and the scenario then read the funding + # withdrawal's detail and called it a failed deposit. + tap_if_any(c, (r"(?i)^Check fees$",)) + if not c.tap_button(r"(?i)^Send$|^Make deposit$|^Deposit$", timeout=20): + c.note("nothing to submit the deposit with: " + + str(c.dev.dump().texts()[:12])) + time.sleep(8) + c.note("after depositing: " + str(c.dev.dump().texts()[:12])) + c.check() + # Whatever state it reached, look at the transaction and its actions. + screen = open_transactions(c) + rows = transaction_rows(screen) + if rows: + c.dev.tap_node(rows[0], screen) + time.sleep(2) + detail = c.dev.dump() + c.note("deposit detail: " + str(detail.texts()[:12])) + # A transaction that carries an error shows an "Error" button in + # developer mode, and it is the only way into + # ErrorTransactionComposable's dialog -- the error object as JSON, with + # a copy button. + if c.tap(r"(?i)^Error$", timeout=10): + dialog = c.dev.dump() + c.note("the error dialog: " + str(dialog.texts()[:10])) + c.check() + c.tap(r"(?i)^OK$|^Close$|^Cancel$|^Copy$", timeout=8) + time.sleep(1.5) + else: + c.note("no Error button on the failed deposit: " + + str([n.label for n in detail.tappable() if n.label][:10])) + for action in (r"(?i)^Retry$", r"(?i)^Abandon$", r"(?i)^Abort$"): + if c.tap(action, timeout=8): + c.tap(r"(?i)^Abandon$|^Abort$|^OK$|^Yes$", timeout=6) + time.sleep(2) + c.check() + break + c.check() + c.ep.check_database() + + +@scenario("withdraw_to_dead_exchange", setup="fresh", + about="withdraw from an exchange that is not listening", + expects=("background-error", "stuck-operation", "error-screen")) +def s_withdraw_dead_exchange(c: Ctx) -> None: + c.app.handle_uri("taler+http://withdraw-exchange/localhost:9/") + time.sleep(5) + screen = c.dev.dump() + c.note("dead exchange: " + str(screen.texts()[:12])) + c.check() + c.tap(r"(?i)^Retry$", timeout=10) + time.sleep(4) + c.check() + c.back_to_home() + rows = transaction_rows(open_transactions(c)) + c.note(f"{len(rows)} transactions after the failed attempt") + if rows: + screen = open_transactions(c) + c.dev.tap_node(transaction_rows(screen)[0], screen) + time.sleep(2) + c.note("failed withdrawal detail: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + + +@scenario("withdraw_account_details", setup="funded", + about="the manual withdrawal's account picker and wire details") +def s_withdraw_account_details(c: Ctx) -> None: + c.back_to_home() + c.must_tap(r"(?i)^Withdraw$", timeout=30) + c.require(r"(?i)Amount to withdraw|Select target bank account|Payment service", + timeout=30) + c.set_amount("€5.00", "500") + c.check() + # Tapping the age row opens the picker, which covers the confirm button, so + # an age has to be chosen before confirming; the age path itself is + # withdraw_age_restricted's job. + if c.tap(r"(?i)Restrict usage to age|Unrestricted", timeout=6): + if not c.tap(r"(?i)^Unrestricted$|^18$", timeout=8): + c.dev.back() + time.sleep(1) + c.accept_tos() + c.must_tap(r"(?i)Confirm withdrawal|^Withdraw$", timeout=25) + # A manual withdrawal waits for a wire transfer, and its detail screen + # links to the instructions. + screen = c.require(r"(?i)Wire transfer instructions|transaction is pending", + timeout=45) + c.note("pending withdrawal: " + str(screen.texts()[:12])) + c.check() + c.must_tap(r"(?i)Wire transfer instructions", timeout=25) + screen = c.require(r"(?i)Subject|Recipient|IBAN|Account", timeout=30) + c.note("transfer instructions: " + str(screen.texts()[:16])) + c.check() + # Copy buttons, the QR variants and the hand-off to a banking app. + copies = [n for n in screen.tappable() if n.label.strip().lower() == "copy"] + c.note(f"{len(copies)} copy buttons") + if copies: + c.dev.tap_node(copies[0], screen) + time.sleep(1) + c.check() + for label in (r"(?i)Wire transfer QR codes", r"(?i)EPC QR", r"(?i)Swiss QR bill", + r"(?i)Unknown payment QR", r"(?i)Open in banking app", + r"(?i)^Share$"): + try: + c.app.scroll_to_text(label, max_scrolls=4) + except TimeoutError: + continue + c.note(f"saw {label}") + if "Share" not in label and "banking app" not in label: + c.tap(label, timeout=6) + c.check() + c.ep.check_database() + + +@scenario("withdraw_account_tabs", setup="funded", + about="every wire account the exchange offers for a manual withdrawal") +def s_withdraw_account_tabs(c: Ctx) -> None: + """One transfer screen per wire method. + + `TransferAccountChooser` only appears once the exchange advertises more + than one account, and the IBAN and Bitcoin transfer screens are only + reachable through it. + """ + c.back_to_home() + c.must_tap(r"(?i)^Withdraw$", timeout=30) + c.require(r"(?i)Amount to withdraw|Select target bank account|Payment service", + timeout=30) + c.set_amount("€5.00", "500") + # Deliberately leave the age chooser alone: tapping it opens the age picker + # and hides the confirm button, and the age path has its own scenario. + c.accept_tos() + c.must_tap(r"(?i)Confirm withdrawal|^Withdraw$", timeout=25) + screen = c.require(r"(?i)Wire transfer instructions|transaction is pending", + timeout=45) + c.note("pending withdrawal screen: " + str(screen.texts())) + tabs = [t for t in screen.texts() if re.match(r"(?i)^Account #\d", t.strip())] + c.note(f"account tabs: {tabs}") + if not tabs: + c.note("the exchange advertises a single wire account; nothing to choose") + for tab in tabs or [None]: + if tab is not None: + # Tap the tab by its node: the label carries parentheses and the + # account index, which is awkward to match as a pattern. + screen = c.dev.dump() + node = next((n for n in screen.labelled() + if n.label.strip() == tab.strip()), None) + if node is None: + c.note(f"could not find the tab {tab!r} again") + continue + # Tap the tab's own centre: the neighbour search in tap_target + # would reach the app bar's back arrow, which is within its reach. + c.dev.tap(*node.center) + time.sleep(2) + c.check() + try: + c.app.scroll_to_text(r"(?i)Wire transfer instructions", max_scrolls=4) + except TimeoutError: + c.note(f"{tab}: no instructions link; screen " + + str(c.dev.dump().texts())) + continue + if not c.tap(r"(?i)Wire transfer instructions", timeout=20): + c.note(f"{tab}: the instructions link would not tap") + continue + # Each method has its own labels: a subject and a recipient for + # x-taler-bank, an IBAN block for IBAN, and a split transaction with + # segwit outputs for Bitcoin. + screen = c.require(r"(?i)Subject|Recipient|IBAN|Account|Address|" + r"split transaction|BTC", timeout=30) + c.note(f"{tab} instructions: {screen.texts()[:14]}") + if screen.find(r"(?i)BTC") is not None: + amounts = [t for t in screen.texts() if "BTC" in t] + c.note(f"{tab}: amounts labelled BTC: {amounts[:4]}") + c.check() + # Each method renders its own transfer screen; the QR variants hang off + # it and differ per method (EPC for IBAN, none for Bitcoin). + for label in (r"(?i)Wire transfer QR codes", r"(?i)EPC QR", + r"(?i)Swiss QR bill", r"(?i)Unknown payment QR"): + try: + c.app.scroll_to_text(label, max_scrolls=3) + except TimeoutError: + continue + c.note(f"{tab}: saw {label}") + c.tap(label, timeout=6) + c.check() + c.dev.back() + c.require(r"(?i)Wire transfer instructions|transaction is pending", timeout=25) + c.ep.check_database() + + +def second_exchange_or_skip(c: Ctx) -> Optional[str]: + """The second exchange's URL, or None with a note saying why not. + + exchange2.sh runs it beside the stack; it is not part of the stack itself, + so a scenario that needs two payment services has to cope without one. + """ + url = getattr(c.env, "exchange2", None) or SECOND_EXCHANGE + try: + import urllib.request + with urllib.request.urlopen(url + "config", timeout=5) as r: + if r.status != 200: + raise RuntimeError(f"HTTP {r.status}") + except Exception as e: # noqa: BLE001 - absence is a skip, not a failure + c.note(f"no second exchange at {url} ({str(e)[:60]}); nothing to choose") + return None + # Reachable from here is not reachable from the emulator: without the + # reverse mapping the wallet adds nothing and says nothing about it, which + # looks exactly like a scenario that worked. + port = url.rstrip("/").rsplit(":", 1)[-1] + if f"tcp:{port}" not in c.dev.adb("reverse", "--list", check=False): + c.note(f"port {port} is not mapped into {c.dev.serial}; " + f"the wallet cannot reach the second exchange") + return None + return url + + +def service_or_skip(c: Ctx, url: str, what: str) -> Optional[str]: + """A service beside the stack, if it is up and the emulator can reach it.""" + try: + import urllib.request + with urllib.request.urlopen(url + "config", timeout=5) as r: + if r.status != 200: + raise RuntimeError(f"HTTP {r.status}") + except Exception as e: # noqa: BLE001 - absence is a skip, not a failure + c.note(f"no {what} at {url} ({str(e)[:60]})") + return None + port = url.rstrip("/").rsplit(":", 1)[-1] + if f"tcp:{port}" not in c.dev.adb("reverse", "--list", check=False): + c.note(f"port {port} is not mapped into {c.dev.serial}; " + f"the wallet cannot reach the {what}") + return None + return url + + +def add_exchange_by_url(c: Ctx, url: str) -> None: + """Settings -> Payment services -> Add, typing a URL.""" + open_exchange_list(c) + c.must_tap(r"(?i)^Add payment service$") + screen = c.require(r"(?i)Enter address of payment service|address", timeout=30) + fields = screen.editable() + if not fields: + raise RuntimeError(f"no URL field on the add screen: {screen.texts()}") + c.dev.tap_node(fields[0], screen) + c.dev.type_text(url) + c.tap(r"(?i)^Add$|^OK$|^Continue$|^Next$") + time.sleep(4) + # Adding one may ask for its terms of service. + c.tap(r"(?i)^Accept Terms of Service$|^Accept$|I accept", timeout=8) + time.sleep(2) + c.check() + + +@scenario("exchange_two_services", setup="fresh", + about="two payment services in the same currency, side by side") +def s_exchange_two_services(c: Ctx) -> None: + second = second_exchange_or_skip(c) + if second is None: + return + add_exchange_by_url(c, LOCAL_EXCHANGE) + add_exchange_by_url(c, second) + open_exchange_list(c) + screen = c.require(r"(?i)Currency:|localhost", timeout=25) + listed = [t for t in screen.texts() if "localhost" in t] + c.note(f"payment services listed: {listed}") + if len(listed) < 2: + c.note("WARNING: the second payment service is not listed") + c.check() + # The per-exchange menu, which is how the app exposes anything about one: + # tapping the URL itself does not navigate. + for which in ("8081", "8091"): + open_exchange_list(c) + if not exchange_menu(c, f"localhost:{which}"): + c.note(f"no menu for localhost:{which}") + continue + time.sleep(1.5) + c.note(f"{which} menu: {c.dev.dump().texts()[:14]}") + c.check() + c.dev.back() + c.ep.check_database() + + +@scenario("withdraw_pick_exchange", setup="funded", + about="the manual withdrawal's payment-service dropdown") +def s_withdraw_pick_exchange(c: Ctx) -> None: + """Choosing which payment service to withdraw from. + + This was written for `SelectExchangeDialogFragment`, on the assumption that + a withdrawal with two candidates would raise it. It does not: + **that fragment has no caller anywhere in the app** (the last + DialogFragment left, and dead), and the bank-integrated prompt has no + service row at all -- its exchange is fixed, and the prompt shows only the + amount, the age restriction and "Confirm withdrawal". + + The real control is on the *manual* withdraw screen: an + `AmountScopeField` whose "via <service>" row is an exposed dropdown over + the known scopes. It is `clickable` but **disabled** until the service's + terms are accepted, which is what made every earlier attempt tap a + neighbour and leave the screen. + """ + second = second_exchange_or_skip(c) + if second is None: + return + add_exchange_by_url(c, second) + c.back_to_home() + c.must_tap(r"(?i)^Withdraw$", timeout=30) + screen = c.require(r"(?i)Amount to withdraw|Select target|Payment service|via", + timeout=30) + c.note("the manual withdraw screen: " + str(screen.texts()[:18])) + c.check() + # Terms first: the dropdown is disabled until they are accepted. + c.accept_tos() + row = next((n for n in c.dev.dump().labelled() + if re.match(r"(?i)^https?://", n.label.strip())), None) + if row is None: + c.note("no payment-service row on the withdraw screen") + return + target = c.dev.dump().tap_target(row) + c.note(f"the service row {row.label!r}: clickable={target.clickable} " + f"enabled={target.enabled}") + if not target.enabled: + c.note("the service row is still disabled after accepting the terms") + c.check() + return + c.dev.tap_node(target) + time.sleep(2) + opened = c.dev.dump() + c.note("after opening the dropdown: " + str(opened.texts()[:18])) + c.check() + # The menu lists one entry per known scope. + if c.tap(r"(?i)localhost:8091|8091", timeout=10): + time.sleep(2) + c.note("picked the second service: " + str(c.dev.dump().texts()[:14])) + else: + c.note("the second service is not among the scopes offered") + c.check() + c.set_amount("€5.00", "500") + c.accept_tos() + c.tap_button(r"(?i)Confirm withdrawal|^Withdraw", timeout=25) + time.sleep(5) + c.note("after confirming: " + str(c.dev.dump().texts()[:16])) + c.check() + c.ep.check_database() + + +@scenario("balances_two_exchanges", setup="fresh", + about="coins from two payment services in one currency") +def s_balances_two_exchanges(c: Ctx) -> None: + """Two services in one currency is what creates a second balance scope, + and what "treat as global" is for.""" + second = second_exchange_or_skip(c) + if second is None: + return + # Coins from the stack's exchange, through the bank as usual. + flows.withdraw(c.app, c.bank, "EUR:10") + c.app.home() + add_exchange_by_url(c, second) + c.back_to_home() + screen = c.dev.dump() + c.note("home with two services: " + str(screen.texts()[:18])) + c.check() + # The balance detail and its transaction list, per scope. + if c.tap(r"(?i)^€|EUR", timeout=10): + time.sleep(2) + c.note("balance detail: " + str(c.dev.dump().texts()[:16])) + c.check() + c.back_to_home() + # "Treat as global" lives in the per-exchange menu and is where a null + # master key used to come from. + open_exchange_list(c) + # Contact each service before treating it as global: "treat as global" + # sends the master public key, which is null until the exchange's /keys + # has been fetched, and a null one is dropped from the request -- + # findings/addglobalcurrencyexchange-null-masterpub.md. The second + # service is the one that arrives un-contacted, with its terms + # unaccepted. + for which in ("8081", "8091"): + if not exchange_menu(c, f"localhost:{which}"): + continue + time.sleep(1) + if c.tap(r"(?i)^Accept Terms of Service$", timeout=6): + time.sleep(2) + c.accept_tos() + open_exchange_list(c) + exchange_menu(c, f"localhost:{which}") + time.sleep(1) + if c.tap(r"(?i)^Reload information$", timeout=8): + time.sleep(4) + c.note(f"{which}: reloaded") + open_exchange_list(c) + for which in ("8081", "8091"): + if not exchange_menu(c, f"localhost:{which}"): + c.note(f"no menu for localhost:{which}") + continue + time.sleep(1) + c.note(f"{which} menu: {c.dev.dump().texts()[:12]}") + if c.tap(r"(?i)Treat as global|global currency", timeout=8): + time.sleep(3) + c.note(f"{which} after treat-as-global: {c.dev.dump().texts()[:12]}") + c.check() + open_exchange_list(c) + + # With both services global, the currency scope carries both their shopping + # URLs, and the card goes to ExchangeShoppingScreen rather than straight + # out to a browser -- MainScreen.kt:188 opens the browser when there is + # exactly one URL, so one service can never reach that screen. + c.back_to_home() + try: + c.app.scroll_to_text(r"(?i)^Where to pay with ", max_scrolls=6) + except TimeoutError: + c.note("no shopping card on the main screen: " + + str(c.dev.dump().texts()[:16])) + c.check() + c.ep.check_database() + return + if not c.tap(r"(?i)^Where to pay with ", timeout=10): + c.note("the shopping card would not tap") + else: + time.sleep(3) + screen = c.dev.dump() + # Recognised by the screen's own message rather than its title: the + # title reads "Where to pay with EUR", which is also what the card on + # the main screen says, so matching the title cannot tell the two + # apart. + if screen.find(r"(?i)offers the following website") is not None: + c.note("the shopping screen: " + str(screen.texts()[:12])) + # Each row is one exchange's shopping URL; opening one leaves the + # app, so the list itself is what is checked here. + rows = [n for n in screen.labelled() if "http" in n.label.lower()] + c.note(f"{len(rows)} shopping URLs listed: " + + str([n.label[:40] for n in rows])) + else: + # MainScreen.kt:188 only navigates when the scope carries more than + # one shopping URL; with one it opens the URL instead, which is + # what this means. + c.note("the card did not open the shopping screen, so the scope " + "still carries one shopping URL: " + + str(screen.texts()[:12])) + c.check() + c.ep.check_database() + + +@scenario("revoke_denomination", setup="funded", + about="revoke a denomination the wallet holds and watch the recoup", + # Revocation is supposed to make the wallet give the coins back to + # the exchange and get new ones; errors along the way are the point. + expects=("background-error", "stuck-operation", "internal-error-code", + "error-screen", "core-internal")) +def s_revoke_denomination(c: Ctx) -> None: + """What happens when the exchange withdraws a denomination under the wallet. + + Destructive and stack-wide -- the denomination stays revoked until the + stack is started again -- so this only runs when a phase says so with + SIM_DESTRUCTIVE=1. + """ + if os.environ.get("SIM_DESTRUCTIVE") != "1": + c.note("destructive scenarios are off; set SIM_DESTRUCTIVE=1 in a phase") + return + import dbprobe + c.back_to_home() + before = c.dev.dump() + c.note("balance before: " + str(before.texts()[:8])) + + db = dbprobe.pull(c.dev) + held = dbprobe.rows(db, "select denom_pub_hash, count(*) c from coins " + "where status = 'fresh' group by denom_pub_hash " + "order by c asc", limit=10) + if not held: + c.note("the wallet holds no fresh coins; nothing to revoke") + return + c.note(f"the wallet holds {len(held)} denominations: " + + str([r["c"] for r in held])) + # The one it holds fewest of: enough to force a recoup without taking the + # whole balance away. + target = held[0]["denom_pub_hash"] + try: + crock = stack_mod.revoke_denomination(target) + except Exception as e: # noqa: BLE001 - reported as a note, not a crash + c.note(f"could not revoke: {str(e)[:200]}") + return + c.note(f"revoked {crock} ({held[0]['c']} coin(s) held)") + + # The wallet learns about it from /keys, which it re-reads on its own + # schedule. Opening the exchange list is not enough; the menu has a + # "Reload information" entry, which is the user's way of asking. + open_exchange_list(c) + if exchange_menu(c): + time.sleep(1) + if c.tap(r"(?i)^Reload information$", timeout=10): + c.note("asked the wallet to reload the exchange") + time.sleep(8) + c.back_to_home() + for _ in range(20): + time.sleep(6) + screen = c.dev.dump() + if screen.find(r"(?i)recoup|loss of funds") is not None: + c.note("something about a recoup or a loss appeared") + break + c.note("home after revocation: " + str(c.dev.dump().texts()[:12])) + c.check() + open_transactions(c) + c.note("transactions after revocation: " + + str(c.dev.dump().texts()[:16])) + c.check() + # The database knows about losses and recoups even when the screens say + # nothing. A revocation the wallet has seen leaves a trace in one of + # these; nothing in any of them means it never noticed. + db = dbprobe.pull(c.dev) + for table in ("denom_loss_events", "recoup_groups", "coins"): + try: + rows = dbprobe.rows(db, f"select * from {table}", limit=3) + c.note(f"{table}: {len(rows)} rows") + except Exception as e: # noqa: BLE001 + c.note(f"{table}: {str(e)[:80]}") + try: + rows = dbprobe.rows(db, "select status, count(*) c from coins " + "group by status", limit=8) + c.note("coins by status: " + str([dict(r) for r in rows])) + except Exception as e: # noqa: BLE001 + c.note(f"coin status: {str(e)[:80]}") + log = c.dev.logcat(lines=600) + hits = [l for l in log.splitlines() + if "recoup" in l.lower() or "revok" in l.lower()][:3] + c.note("the log on recoup/revocation: " + (" / ".join(hits)[:300] or "nothing")) + + # Recoup is how the money comes back, and it is a background task: the + # first measurement above catches the coin marked `denom-loss` and the + # balance down by its value, which is the *start* of the story. Whether + # the wallet ends up whole is the question worth answering, so wait for + # the recoup group to finish and say what the balance did. + def shown_balance() -> str: + """The first euro amount on the main screen, as text.""" + c.back_to_home() + for t in c.dev.dump().texts(): + m = re.search(r"€\s*([0-9]+[.,][0-9]{2})", t) + if m: + return m.group(1) + return "?" + + before = shown_balance() + settled = False + for _ in range(20): + time.sleep(15) + db = dbprobe.pull(c.dev) + try: + pending = dbprobe.rows( + db, "select recoup_group_id, operation_status, timestamp_finished " + "from recoup_groups where timestamp_finished is null", limit=5) + except Exception as e: # noqa: BLE001 + c.note(f"recoup_groups: {str(e)[:80]}") + break + if not pending: + settled = True + break + c.note(f"the recoup group finished within five minutes: {settled}") + after = shown_balance() + c.note(f"balance before the wait: {before}, after: {after}") + db = dbprobe.pull(c.dev) + try: + rows = dbprobe.rows(db, "select status, count(*) c from coins " + "group by status", limit=8) + c.note("coins by status once settled: " + str([dict(r) for r in rows])) + except Exception as e: # noqa: BLE001 + c.note(f"coin status: {str(e)[:80]}") + screen = open_transactions(c) + c.note("history once settled: " + str(screen.texts()[:16])) + c.check() + + # A revocation is the one thing in this stack that makes a *EUR* loss + # event, and therefore the only way to the loss transaction and its detail + # screen: the dev experiment's injected loss is hard-coded to TESTKUDOS + # (dev-experiments.ts:243), which a euro wallet has no scope to show it + # under. `TransactionDenomLoss` and `TransitionLossComposable` have never + # rendered for that reason. + row = screen.find(r"(?i)^Loss of funds$") + if row is None: + try: + screen = c.app.scroll_to_text(r"(?i)^Loss of funds$", max_scrolls=6) + row = screen.find(r"(?i)^Loss of funds$") + except TimeoutError: + row = None + if row is None: + c.note("no loss transaction in the history, though the database has " + "a loss event: " + str(screen.texts()[:16])) + c.check() + c.ep.check_database() + return + c.dev.tap_node(row, screen) + time.sleep(2.5) + detail = c.dev.dump() + c.note("the loss detail screen: " + str(detail.texts()[:16])) + # Its own labels: the reason, and one of the three explanations. + if detail.find(r"(?i)^Reason$") is None: + c.note("WARNING: the loss detail shows no reason") + reason = detail.find(r"(?i)not renewed|stopped offering|lost the record") + c.note(f"the loss reason is spelled out: {reason is not None}") + c.check() + c.ep.check_database() + + +@scenario("wallet_lock_without_credential", setup="funded", + about="turn the wallet lock on, then take the device credential away", + expects=("error-screen",)) +def s_wallet_lock(c: Ctx) -> None: + """What happens to a locked wallet when the screen lock goes away. + + "Protect access to wallet" can only be switched on while the device can + authenticate (`enableBiometrics` checks `canAuthenticate`), but nothing + re-checks afterwards, and `BiometricOverlay` covers the whole app with a + single "Tap to unlock" button. Removing the credential afterwards is an + ordinary thing to do. + + Touches the device's lock settings, so it only runs under + SIM_DESTRUCTIVE=1, and it clears the credential again whatever happens. + """ + if os.environ.get("SIM_DESTRUCTIVE") != "1": + c.note("destructive scenarios are off; set SIM_DESTRUCTIVE=1 in a phase") + return + try: + out = c.dev.shell("locksettings set-pin 1234", check=False) + c.note(f"set a device PIN: {out.strip()[:80]}") + if "set" not in out.lower(): + c.note("could not set a device credential; nothing to test") + return + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Protect access to wallet$") + c.must_tap(r"(?i)^Protect access to wallet$", timeout=20) + time.sleep(3) + c.note("after switching the lock on: " + str(c.dev.dump().texts()[:10])) + c.check() + # Locked now: a restart has to ask before showing anything. + c.dev.stop() + time.sleep(2) + c.dev.launch() + time.sleep(6) + locked = c.dev.dump() + # The overlay covers the app, but uiautomator still reports the nodes + # underneath it, so presence has to be asked about rather than read off + # the first few labels. + c.note(f"after a restart with a credential: locked=" + f"{locked.find(r'(?i)Tap to unlock') is not None}; " + + str(locked.texts()[:8])) + if locked.find(r"(?i)Tap to unlock") is None: + c.note("the wallet is not locked; the switch did not take") + return + c.check() + # Now the credential goes away, as it does when a user turns their + # screen lock off. + out = c.dev.shell("locksettings clear --old 1234", check=False) + c.note(f"cleared the device credential: {out.strip()[:80]}") + c.dev.stop() + time.sleep(2) + c.dev.launch() + time.sleep(6) + screen = c.dev.dump() + c.note(f"after a restart with no credential: locked=" + f"{screen.find(r'(?i)Tap to unlock') is not None}; " + + str(screen.texts()[:8])) + c.check() + if screen.find(r"(?i)Tap to unlock") is not None: + c.dev.logcat(clear=True) + c.must_tap(r"(?i)Tap to unlock", timeout=20) + time.sleep(5) + after = c.dev.dump() + still = after.find(r"(?i)Tap to unlock") is not None + c.note(f"after tapping unlock: still locked={still}; " + + str(after.texts()[:8])) + # The prompt reports its refusal through a toast, which is not in + # the hierarchy; the log has it. + log = c.dev.logcat(lines=400) + lines = [l for l in log.splitlines() + if "iometric" in l or "uthenticat" in l] + c.note("authentication log: " + " / ".join(lines[-3:])[:300]) + c.check() + if still: + c.note("WARNING: the wallet cannot be unlocked at all; the only " + "way back in is clearing the app's data, which destroys " + "the coins") + finally: + c.dev.shell("locksettings clear --old 1234", check=False) + c.dev.shell("locksettings set-disabled true", check=False) + + +# wallet-core can be told to fail a named operation from the outside, which is +# the only way to see what each screen does with an error it cannot otherwise +# be made to produce. The detail is base64url JSON with a numeric code. +def api_error_uri(operation: str, code: int = 7001, + hint: str = "injected by the simulator", + count: int = 4) -> str: + import base64 + detail_obj: dict = {"code": code} + if hint: + detail_obj["hint"] = hint + detail = base64.urlsafe_b64encode( + json.dumps(detail_obj).encode()).decode().rstrip("=") + return (f"taler+http://dev-experiment/api-error?operation={operation}" + f"&detail={detail}&count={count}") + + +@scenario("api_error_sweep", setup="funded", + about="make each screen's wallet-core call fail and see what it says", + expects=("error-screen", "internal-error-code", "core-internal", + "silent-failure", "blank-screen")) +def s_api_error_sweep(c: Ctx) -> None: + """One injected failure per screen. + + Every one of these is a reply the app can get in the field -- a request + that times out, an exchange that is down, a database that is busy -- and + each screen either says so or says nothing. The oracles decide; this + scenario only has to get each screen to make its call while the error is + queued. + """ + cases = [ + ("getBalances", lambda: c.back_to_home()), + ("getTransactionsV2", lambda: open_transactions(c)), + ("listExchanges", lambda: open_exchange_list(c)), + ("getContacts", lambda: (c.app.open_settings(), + c.app.scroll_to_text(r"(?i)^Contacts$"), + c.must_tap(r"(?i)^Contacts$"))), + ("listBankAccounts", lambda: (c.app.open_settings(), + c.app.scroll_to_text(r"(?i)^Bank accounts$"), + c.must_tap(r"(?i)^Bank accounts$"))), + ("getDepositWireTypes", lambda: (c.back_to_home(), + c.must_tap(r"(?i)^Deposit$", timeout=20))), + ("getWithdrawalDetailsForAmount", + lambda: (c.back_to_home(), c.must_tap(r"(?i)^Withdraw$", timeout=20))), + ("getMaxPeerPushDebitAmount", + lambda: (c.back_to_home(), c.must_tap(r"(?i)^Send$", timeout=20))), + ("listDiscounts", lambda: (c.back_to_home(), + c.app.scroll_to_text(r"(?i)^Discounts$"), + c.must_tap(r"(?i)^Discounts$"))), + ("getDonau", lambda: (c.app.open_settings(), + c.app.scroll_to_text(r"(?i)^Tax-deductible donations$"), + c.must_tap(r"(?i)^Tax-deductible donations$"))), + ("getCurrencySpecification", lambda: c.back_to_home()), + ("getExchangeTos", lambda: (open_exchange_list(c), + exchange_menu(c), + c.must_tap(r"(?i)terms of service", timeout=15))), + ("getMaxDepositAmount", lambda: (c.back_to_home(), + c.must_tap(r"(?i)^Deposit$", timeout=20))), + ("listSubscriptions", lambda: (c.back_to_home(), + c.app.scroll_to_text(r"(?i)^Passes$"), + c.must_tap(r"(?i)^Passes$"))), + ] + # The shipped wallet-core may be older than the experiment: a wallet-core + # that does not know "api-error" treats the URI as an unknown experiment + # and the whole sweep would measure nothing. + c.dev.logcat(clear=True) + c.app.handle_uri(api_error_uri("getBalances", count=1)) + time.sleep(3) + log = c.dev.logcat(lines=400) + if "unknown" in log.lower() and "experiment" in log.lower(): + bad = [l for l in log.splitlines() if "experiment" in l.lower()][:2] + c.note("this wallet-core does not support api-error: " + " / ".join(bad)[:240]) + return + c.note("api-error is accepted by this wallet-core") + + for operation, visit in cases: + c.back_to_home() + c.dev.logcat(clear=True) + c.app.handle_uri(api_error_uri(operation)) + time.sleep(2) + # Applying an experiment ends with a back navigation, which closes the + # app when the URI is what started it; without this the next case + # measures the launcher instead of a wallet screen. + for attempt in range(3): + if c.dev.dump().activity.startswith(PKG): + break + c.note(f"{operation}: the app left the foreground; relaunching") + c.dev.launch() + time.sleep(6) + else: + c.note(f"{operation}: could not get the app back; skipping") + continue + try: + c.app.home() + visit() + except (TimeoutError, RuntimeError) as e: + c.note(f"{operation}: could not reach its screen ({str(e)[:120]})") + continue + time.sleep(4) + screen = c.dev.dump() + said = screen.find(r"(?i)error|failed|could not|unavailable|try again|" + r"something went wrong") is not None + c.note(f"{operation}: shows an error: {said}; " + + str(screen.texts()[:12])) + if not said: + c.note(f"WARNING: {operation} failed and the screen says nothing") + c.check() + # Leave no injected errors behind for the next scenario. + c.app.handle_uri("taler+http://dev-experiment/clear-api-errors") + c.ep.check_database() + + +@scenario("contacts_add_and_forget", setup="funded", + about="add a contact by hand, then delete it") +def s_contacts_add(c: Ctx) -> None: + """`addContact` and `deleteContact` have never run. + + The contact list's own dialog is the only way to them that does not go + through the directory service, and its OK button stays disabled until the + petname, the alias and the mailbox are all filled. + """ + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Contacts$") + c.must_tap(r"(?i)^Contacts$", timeout=20) + c.require(r"(?i)Contacts|No contacts yet|Add Contact", timeout=25) + c.check() + if not c.tap(r"(?i)^Add Contact$", timeout=20): + c.note("no way to add a contact") + return + screen = c.require(r"(?i)Petname|Alias|Mailbox", timeout=20) + c.note("add-contact dialog: " + str(screen.texts()[:12])) + fields = screen.editable() + c.note(f"{len(fields)} fields in the dialog") + if len(fields) < 3: + c.note("the dialog does not have the fields it is supposed to") + return + c.fill("Simulator Friend", 0) + c.fill("friend@example.com", 1) + c.fill("http://localhost:8081/mailbox/ABCD1234", len(fields) - 1) + time.sleep(1) + added = c.tap_button(r"(?i)^OK$|^Add$", timeout=15) + time.sleep(3) + listed = c.dev.dump() + c.note(f"after adding (OK tappable: {added}): " + str(listed.texts()[:12])) + if listed.find(r"(?i)Simulator Friend|friend@example.com") is None: + c.note("WARNING: the contact does not appear in the list") + c.check() + # And away again: long-press or a menu, whichever the list offers. + row = listed.find(r"(?i)Simulator Friend") + if row is not None: + c.dev.long_press(row) + time.sleep(2) + c.note("after a long press: " + str(c.dev.dump().texts()[:12])) + c.tap(r"(?i)^Delete$|^Forget$|^Remove$", timeout=8) + time.sleep(2) + c.tap(r"(?i)^OK$|^Yes$|^Delete$", timeout=8) + time.sleep(2) + c.note("after deleting: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + + +def api_response_uri(operation: str, response: dict, count: int = 5) -> str: + """A canned reply for a wallet-core operation, base64url JSON.""" + import base64 + blob = base64.urlsafe_b64encode( + json.dumps(response).encode()).decode().rstrip("=") + return (f"taler+http://dev-experiment/api-response?operation={operation}" + f"&response={blob}&count={count}") + + +def _balance(currency: str, url: str, available: str) -> dict: + return { + "scopeInfo": {"type": "exchange", "currency": currency, "url": url}, + "available": available, + "pendingIncoming": f"{currency}:0", + "pendingOutgoing": f"{currency}:0", + "disablePeerPayments": False, + } + + +@scenario("api_response_hostile", setup="funded", + about="feed the balance screen replies it would never see in a test", + expects=("error-screen", "internal-error-screen", "internal-error-code", + "core-internal", "glued-currency", "blank-screen", + "mixed-amount-notation")) +def s_api_response_hostile(c: Ctx) -> None: + """Well-formed replies with hostile *values*. + + An amount larger than the wallet's own maximum, a currency name longer + than any symbol, and a dozen scopes at once are all things a real + deployment can produce, and none of them can be produced by this stack. + """ + cases = { + "huge amount": {"balances": [ + _balance("EUR", LOCAL_EXCHANGE, "EUR:999999999999.99")]}, + "long currency name": {"balances": [ + _balance("VERYLONGCURRENCY", LOCAL_EXCHANGE, "VERYLONGCURRENCY:1.00")]}, + "twelve scopes": {"balances": [ + _balance("EUR", f"http://localhost:80{80 + i}/", f"EUR:{i + 1}.00") + for i in range(12)]}, + "zero everywhere": {"balances": [ + _balance("EUR", LOCAL_EXCHANGE, "EUR:0")]}, + } + for name, response in cases.items(): + c.back_to_home() + c.dev.logcat(clear=True) + # The queue is FIFO and holds `count` copies, so leftovers from the + # previous case would be what the next one measures. + c.app.handle_uri("taler+http://dev-experiment/clear-api-responses") + time.sleep(1.5) + if not c.dev.dump().activity.startswith(PKG): + c.dev.launch() + time.sleep(5) + c.app.handle_uri(api_response_uri("getBalances", response, count=2)) + time.sleep(2) + if not c.dev.dump().activity.startswith(PKG): + c.dev.launch() + time.sleep(5) + # The main screen asks for balances whenever it is shown. + c.back_to_home() + time.sleep(4) + screen = c.dev.dump() + c.note(f"{name}: " + str(screen.texts()[:16])) + c.check() + # More than one scope gives the pager a list page as well, which is + # the only thing that renders BalancesListComposable. + if name == "twelve scopes": + w, h = c.dev.size() + for _ in range(3): + c.dev.shell(f"input swipe {int(w * 0.85)} {int(h * 0.45)} " + f"{int(w * 0.15)} {int(h * 0.45)} 400") + time.sleep(1.5) + c.note("after paging: " + str(c.dev.dump().texts()[:16])) + c.check() + c.app.handle_uri("taler+http://dev-experiment/clear-api-responses") + c.ep.check_database() + + +@scenario("error_screen_without_dev_mode", setup="funded", + about="what a release build shows for an error with no hint", + expects=("error-screen", "internal-error-code", "core-internal", + "blank-screen")) +def s_error_screen_release(c: Ctx) -> None: + """The error screen the campaign never sees. + + Everything here runs in developer mode, because `taler+http://` needs it, + and the error screen shows the raw JSON in that mode. Without it the whole + explanation is `TalerErrorInfo.userFacingMsg`, which is the hint and the + message concatenated -- and nothing at all when the reply carries neither. + """ + # Queue the failure first: the URI needs developer mode to be delivered. + # An error with neither hint nor message is what makes the release screen + # empty, so api_error_uri is asked for one without a hint. + c.back_to_home() + c.app.handle_uri(api_error_uri("getBalances", hint="", count=20)) + time.sleep(2) + if not c.dev.dump().activity.startswith(PKG): + c.dev.launch() + time.sleep(5) + with_dev = c.dev.dump() + c.note("with developer mode: " + str(with_dev.texts()[:10])) + c.check() + + # Now turn developer mode off, which is what a release build is. + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Developer mode$") + screen = c.dev.dump() + row = screen.find(r"(?i)^Developer mode$") + if row is None: + c.note("no developer mode row") + return + _, y = row.center + width = max(n.bounds[2] for n in screen.nodes) + c.dev.tap(width - 100, y) + time.sleep(2) + c.note(f"developer mode now on: {c.app.dev_mode_on()}") + c.back_to_home() + time.sleep(4) + without_dev = c.dev.dump() + c.note("without developer mode: " + str(without_dev.texts()[:12])) + # "Error" and an export affordance, and nothing that says what happened. + explained = [t for t in without_dev.texts() + if t.strip() not in ("Error", "Copy", "Share", "Settings", + "Internal event log", "Scan QR code", + "Wallet") + and "Export error" not in t] + c.note(f"anything explaining the error: {explained[:6]}") + if not explained: + c.note("WARNING: the error screen explains nothing without developer mode") + c.check() + # taler+http:// is refused while developer mode is off, so the clearing URI + # needs it back first. + c.app.enable_dev_mode() + c.app.handle_uri("taler+http://dev-experiment/clear-api-errors") + c.ep.check_database() + + +@scenario("denom_loss_transaction", setup="funded", + about="a loss-of-funds transaction and its detail screen", + expects=("error-screen",)) +def s_denom_loss(c: Ctx) -> None: + """`TransactionDenomLoss` has never been rendered. + + It appears when an exchange's denomination expires or is revoked while the + wallet still holds coins of it -- which no stack can produce on demand, but + wallet-core will insert one on request. + """ + import dbprobe + c.back_to_home() + c.dev.logcat(clear=True) + c.app.handle_uri("taler+http://dev-experiment/insert-denom-loss") + time.sleep(3) + for _ in range(3): + if c.dev.dump().activity.startswith(PKG): + break + c.dev.launch() + time.sleep(6) + # Did wallet-core accept the experiment at all? The shipped qtart may be + # older than it. + log = c.dev.logcat(lines=400) + complaints = [l for l in log.splitlines() + if "experiment" in l.lower() and ("error" in l.lower() + or "unknown" in l.lower())] + c.note("wallet-core on the experiment: " + (" / ".join(complaints[-2:])[:240] + or "no complaint")) + db = dbprobe.pull(c.dev) + rows: list = [] + try: + rows = dbprobe.rows(db, "select * from denom_loss_events", limit=5) + c.note(f"denom_loss_events rows: {len(rows)}") + for r in rows: + c.note(" " + str({k: str(v)[:40] for k, v in dict(r).items()})[:240]) + except Exception as e: # noqa: BLE001 + c.note(f"could not read denom_loss_events: {str(e)[:120]}") + c.app.home() + time.sleep(3) + c.note("home after the loss event: " + str(c.dev.dump().texts()[:14])) + c.check() + screen = open_transactions(c) + c.note("recent transactions: " + str(screen.texts()[:18])) + loss = screen.find(r"(?i)Loss of funds") + if loss is None: + # The main screen's list belongs to the selected scope, and the event + # is in a currency of its own; "All" is the unscoped list. + if c.tap(r"(?i)^All$", timeout=10): + time.sleep(3) + screen = c.dev.dump() + c.note("all transactions: " + str(screen.texts()[:18])) + loss = screen.find(r"(?i)Loss of funds") + if loss is None: + # Not a defect, and worth saying so rather than leaving a WARNING that + # reads like one: the dev experiment inserts the event for TESTKUDOS + # (the row's own `currency` column says so), and a wallet holding only + # EUR has no TESTKUDOS scope for it to appear under. Rendering + # TransactionDenomLoss would need a loss in a currency the wallet + # actually holds, which means a denomination expiring under it -- + # not something this stack can arrange. + currencies = {dict(row).get("currency") for row in rows} + c.note(f"the loss event does not appear in any list, as expected: it is " + f"in {currencies or '(unknown)'} and this wallet holds EUR") + c.check() + return + c.dev.tap_node(loss, screen) + time.sleep(3) + detail = c.dev.dump() + c.note("loss detail: " + str(detail.texts()[:16])) + if detail.find(r"(?i)Amount lost|Reason|expired|revoked") is None: + c.note("WARNING: the loss detail screen shows none of its own labels") + c.check() + c.ep.check_database() + + +@scenario("exchange_turns_hostile", setup="funded", + about="the exchange's protocol version and master key change under the wallet", + expects=("error-screen", "internal-error-code", "core-internal", + "background-error", "stuck-operation", "blank-screen")) +def s_exchange_turns_hostile(c: Ctx) -> None: + """Two events a wallet must survive and explain. + + An exchange that answers with a protocol version this wallet cannot speak + is unusable; an exchange whose master public key has changed is either + compromised or has been replaced, and the wallet holds coins signed by the + old one. Neither can be produced by configuration -- wallet-core will + pretend, per exchange base URL, on request. + """ + url = LOCAL_EXCHANGE + quoted = url.replace(":", "%3A").replace("/", "%2F") + cases = [ + ("protocol version 999", + f"taler+http://dev-experiment/start-fakeprotover" + f"?base_url={quoted}&fake_ver=999%3A0%3A0&fup=1"), + ("a different master key", + f"taler+http://dev-experiment/start-fakemasterpub" + f"?base_url={quoted}" + f"&fake_pub=0000000000000000000000000000000000000000000000000000&fup=1"), + ] + for name, uri in cases: + c.back_to_home() + c.dev.logcat(clear=True) + c.app.handle_uri(uri) + time.sleep(4) + for _ in range(3): + if c.dev.dump().activity.startswith(PKG): + break + c.dev.launch() + time.sleep(6) + c.app.home() + time.sleep(4) + c.note(f"{name}: home shows " + str(c.dev.dump().texts()[:14])) + c.check() + # The payment services screen is where the wallet would say so. + open_exchange_list(c) + time.sleep(3) + listed = c.dev.dump() + c.note(f"{name}: payment services show " + str(listed.texts()[:16])) + if listed.find(r"(?i)error|not supported|incompatible|too old|too new|" + r"changed|unavailable") is None: + c.note(f"WARNING: nothing on the exchange list mentions {name}") + c.check() + # And a withdrawal, which is what the user would try next. + c.back_to_home() + if c.tap(r"(?i)^Withdraw$", timeout=20): + time.sleep(5) + prompt = c.dev.dump() + c.note(f"{name}: the withdraw screen shows " + str(prompt.texts()[:14])) + c.check() + log = c.dev.logcat(lines=500) + codes = sorted({m for m in re.findall(r'"code":\s*(\d{4})', log)}) + c.note(f"{name}: error codes in the log: {codes[:8]}") + + # And the case that puts an error *on a transaction*: a withdrawal that is + # already pending when the exchange becomes unusable. Nothing else in the + # suite has ever rendered `ErrorTransactionButton`. + c.app.fresh_start(dev_mode=True) + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + if not c.tap(r"(?i)confirm withdrawal", timeout=40): + c.note("could not start a withdrawal to break") + return + c.see(r"(?i)Waiting for authorization|Authorize in bank|transaction is pending", + timeout=60) + c.app.handle_uri( + f"taler+http://dev-experiment/start-fakemasterpub?base_url={quoted}" + f"&fake_pub=0000000000000000000000000000000000000000000000000000&fup=1") + time.sleep(3) + for _ in range(3): + if c.dev.dump().activity.startswith(PKG): + break + c.dev.launch() + time.sleep(6) + # Push the withdrawal along, so its next step fails. + c.bank.confirm_withdrawal(*flows.WALLET_USER, op["withdrawal_id"]) + for _ in range(8): + time.sleep(5) + screen = c.dev.dump() + if screen.find(r"(?i)has failed|error|Show error") is not None: + break + c.note("the pending withdrawal now: " + str(c.dev.dump().texts()[:16])) + c.check() + open_transactions(c) + rows = transaction_rows(c.dev.dump()) + if rows: + c.dev.tap_node(rows[0]) + time.sleep(3) + detail = c.dev.dump() + c.note("its detail screen: " + str(detail.texts()[:16])) + if c.tap(r"(?i)Show error|^Error$", timeout=8): + time.sleep(2) + c.note("error block: " + str(c.dev.dump().texts()[:14])) + c.check() + c.ep.check_database() + + +@scenario("peer_push_abandon", setup="funded", + about="look for Abandon on an outgoing peer payment and on a deposit") +def s_peer_push_abandon(c: Ctx) -> None: + """Where `failTransaction` can be reached from, if anywhere. + + wallet-core puts `TransactionAction.Fail` in the action list for deposits + and for outgoing peer payments, so the withdrawal scenarios could never + reach it -- but an outgoing peer payment turns out to offer Retry, Abort + and Suspend while it is live, and Resume and Abort once suspended, with no + Abandon in sight. This scenario records both, and then tries a deposit. + """ + c.back_to_home() + before = c.app.balances() + c.note(f"balance before: {before}") + c.must_tap(r"(?i)^Send$", timeout=30) + c.require(r"(?i)Send money|Amount to send|Purpose", timeout=30) + c.set_amount("€5.00", "500") + c.must_tap(r"(?i)^Send ", timeout=30) + c.see(r"(?i)Scan this QR code to receive|copy and send this URI", timeout=60) + c.check() + # Nobody accepts it; the wallet's own way out is Abandon. wallet-core + # offers it on an outgoing peer payment only once the transaction is + # suspended -- while it is live the choices are Suspend and Abort. + # The QR code is the top of the screen; the actions are below it. + try: + c.app.scroll_to_text(r"(?i)^Suspend$|^Abandon$|^Abort$", max_scrolls=5) + except TimeoutError: + c.note("no actions on the outgoing payment: " + + str(c.dev.dump().texts()[:16])) + return + c.note("live actions: " + str(c.dev.dump().texts()[:18])) + if not c.tap(r"(?i)^Abandon$", timeout=10): + if not c.tap(r"(?i)^Suspend$", timeout=15): + c.note("neither Abandon nor Suspend is offered") + return + time.sleep(4) + try: + c.app.scroll_to_text(r"(?i)^Abandon$|^Resume$", max_scrolls=5) + except TimeoutError: + pass + c.note("after suspending: " + str(c.dev.dump().texts()[:18])) + c.check() + if not c.tap(r"(?i)^Abandon$", timeout=15): + c.note("Abandon is not offered even once suspended: " + + str(c.dev.dump().texts()[:18])) + # A deposit is the other place wallet-core offers it. + c.back_to_home() + if not c.tap(r"(?i)^Deposit$", timeout=20): + return + screen = c.require(r"(?i)Deposit|bank account|Amount", timeout=25) + account = screen.find(r"(?i)^wallet\d+$") or screen.find(r"(?i)x-taler-bank") + if account is not None: + c.dev.tap_node(account, screen) + time.sleep(3) + if not c.set_amount("€1.00", "100"): + c.note("could not set a deposit amount") + return + if not c.tap(r"(?i)^Make deposit$|^Deposit$", timeout=20): + c.note("could not make the deposit") + return + time.sleep(4) + try: + c.app.scroll_to_text(r"(?i)^Abandon$|^Suspend$|^Abort$", + max_scrolls=5) + except TimeoutError: + pass + c.note("a deposit's actions: " + str(c.dev.dump().texts()[:18])) + if not c.tap(r"(?i)^Abandon$", timeout=10): + # wallet-core offers Fail on a deposit that is *aborting* + # (deposits.ts: Aborting, SuspendedAborting, + # PendingAggregateKyc, …), so aborting one is the way in -- if + # the aggregator has not already finalised it. + if c.tap(r"(?i)^Abort$", timeout=10): + time.sleep(4) + c.note("after aborting the deposit: " + + str(c.dev.dump().texts()[:18])) + c.check() + if c.tap(r"(?i)^Abandon$", timeout=10): + time.sleep(4) + c.note("abandoned the deposit: " + str(c.dev.dump().texts()[:14])) + c.check() + else: + c.note("Abandon is offered in none of the deposit states this " + "stack produces") + return + if c.see(r"(?i)Abandon transaction|Are you sure", timeout=10): + c.tap(r"(?i)^Abandon$|^OK$|^Yes$") + time.sleep(5) + after_screen = c.dev.dump() + c.note("after abandoning: " + str(after_screen.texts()[:14])) + c.check() + # The coins are refreshed back into the balance; that takes a moment. + for _ in range(10): + time.sleep(4) + c.back_to_home() + now = c.app.balances() + if now and now != before: + break + c.note(f"balance after: {c.app.balances()} (was {before})") + c.check() + c.ep.check_database() + + +@scenario("history_after_forgetting_exchange", setup="funded", + about="forget the payment service and look for the transactions again") +def s_history_after_forget(c: Ctx) -> None: + """Every transaction list is scope-filtered. + + `TransactionManager.getTransactions` always passes a `scopeInfo`, and the + scopes come from the balances, so a currency with no balance scope has no + list to appear in. Forgetting the only payment service is the ordinary way + to reach that state. + """ + c.back_to_home() + before = transaction_rows(open_transactions(c)) + c.note(f"transactions before: {[n.label[:24] for n in before]}") + c.check() + open_exchange_list(c) + if not exchange_menu(c): + c.note("no exchange menu") + return + c.note("menu: " + str(c.dev.dump().texts()[:14])) + if not c.tap(r"(?i)^Delete payment service$|^Forget payment service$|" + r"^Forget$|^Delete$", timeout=15): + c.note("no way to forget the payment service") + return + time.sleep(2) + dialog = c.dev.dump() + c.note("the delete dialog: " + str(dialog.texts()[:10])) + # The wallet holds coins on this exchange, so a plain delete is refused; + # the dialog's own checkbox is what forces it. + if dialog.find(r"(?i)Force deletion") is not None: + c.tap(r"(?i)Force deletion") + time.sleep(1) + c.tap_button(r"(?i)^Delete$|^Forget$|^OK$|^Yes$", timeout=10) + time.sleep(6) + c.note("after forgetting: " + str(c.dev.dump().texts()[:14])) + c.check() + c.back_to_home() + time.sleep(3) + home = c.dev.dump() + c.note("home afterwards: " + str(home.texts()[:16])) + after = transaction_rows(c.dev.dump()) + c.note(f"transactions after: {[n.label[:24] for n in after]}") + if before and not after: + c.note("WARNING: forgetting the payment service took the history with " + "it; the record of what was done with the money is gone") + c.check() + c.ep.check_database() + + +def _fake_withdrawal(txid: str, major: str, minor: str | None, + actions: list[str], error: dict | None = None) -> dict: + """A withdrawal transaction as wallet-core would report it.""" + tx: dict = { + "type": "withdrawal", + "transactionId": f"txn:withdrawal:{txid}", + "timestamp": {"t_s": int(time.time())}, + "txState": {"major": major, **({"minor": minor} if minor else {})}, + "txActions": actions, + "amountRaw": "EUR:10", + "amountEffective": "EUR:9.87", + "scopes": [{"type": "exchange", "currency": "EUR", + "url": LOCAL_EXCHANGE}], + "exchangeBaseUrl": LOCAL_EXCHANGE, + "withdrawalDetails": {"type": "manual-transfer", + "reserveClosingDelay": {"d_us": 3600000000}}, + } + if error is not None: + tx["error"] = error + return tx + + +@scenario("nfc_tap_to_pay", setup="funded", + about="a payment arriving over NFC, as a tapped tag delivers it", + expects=("error-screen", "background-error", "stuck-operation")) +def s_nfc_tap_to_pay(c: Ctx) -> None: + """The tap-to-pay entry point, which nothing had ever used. + + `MainActivity` has three external entry points -- a VIEW intent, shared + text, and `NfcAdapter.ACTION_NDEF_DISCOVERED` -- and only the first two had + ever been driven, although the sim build ships a `SEND_NDEF` hook built for + exactly this (the URI travels in a Parcelable `NdefMessage`, which `am + start` cannot construct). The handler's own comment calls the NDEF-record + path a fallback for when the system leaves `intent.data` unset, and that is + the branch the hook exercises. + """ + order = c.merchant.create_order("EUR:1", summary="Tapped order") + c.dev.send_ndef(order["pay_uri"]) + screen = c.see(r"(?i)^Pay\b|Review order|Total:|Purchase", timeout=60) + if screen is None: + c.note("an NDEF tap did not open the payment prompt: " + + str(c.dev.dump().texts()[:14])) + c.check() + return + c.note("the tapped payment prompt: " + str(screen.texts()[:14])) + c.check() + c.tap_button(r"(?i)^Pay\b|confirm payment", timeout=30) + deadline = time.monotonic() + 90 + paid = False + while time.monotonic() < deadline: + if c.merchant.order_status(order["order_id"], + order["token"]).get("order_status") == "paid": + paid = True + break + time.sleep(2) + c.note(f"the tapped order was paid: {paid}") + if not paid: + raise RuntimeError("a payment delivered over NFC was never paid") + c.check() + + # And the hostile taps: a tag carrying something that is not a Taler URI at + # all, and one carrying a Taler URI for an order that does not exist. + for label, uri in ( + ("a plain website", "https://example.org/not-taler"), + ("a nonsense scheme", "taler+http://pay/"), + ("an order that does not exist", + f"taler+http://pay/{corpus.EXCHANGE}/{corpus.FAKE_ID}/"), + ): + c.back_to_home() + c.dev.send_ndef(uri) + time.sleep(4) + c.note(f"tapped {label}: " + str(c.dev.dump().texts()[:10])) + c.check() + c.ep.check_database() + + +@scenario("transaction_details_by_type", setup="funded", + about="open the detail screen of every transaction type the stack " + "can produce", + expects=("error-screen", "unfinished-transaction", + "mixed-amount-notation", "glued-currency")) +def s_transaction_details_by_type(c: Ctx) -> None: + """One detail screen per transaction kind. + + `TransactionDetailScreen` branches on the transaction's type -- withdrawal, + payment, refund, deposit, peer push/pull debit/credit, denomination loss -- + and each branch has its own composable. Scenarios create those + transactions all the time but almost never open them, which is why the + detail screen sits at 56 % and several per-type composables at 0 %. + + Each counterparty step is allowed to fail on its own: what matters is that + whatever did end up in the list gets opened. + """ + made: list[str] = [] + steps = ( + ("payment", lambda: flows.pay(c.app, c.merchant, "EUR:2", + "Detail-screen order")), + ("deposit", lambda: flows.deposit_to_bank(c.app, c.env, "100")), + ("peer push credit", lambda: flows.peer_receive(c.app, c.env, "EUR:1", + c.cli)), + ("peer pull debit", lambda: flows.peer_pay_invoice(c.app, c.env, + "EUR:1", c.cli)), + ) + for name, step in steps: + try: + step() + made.append(name) + except Exception as e: # noqa: BLE001 + c.note(f"could not make a {name}: {str(e)[:140]}") + c.back_to_home() + c.note(f"transaction types created: {made}") + c.check() + + # Now the point of the scenario: open every row there is. The list lives + # on the main screen under "Recent transactions", which is what + # transaction_rows understands; tapping the "All" chip navigates to the + # dedicated screen instead, where that header does not exist and every row + # went missing. + screen = open_transactions(c) + rows = transaction_rows(screen) + c.note(f"{len(rows)} transactions listed: " + + str([n.label[:26] for n in rows])) + opened = 0 + for index in range(len(rows)): + # Re-read the list each time: going back recomposes it, and holding a + # node from an older dump taps whatever is at those coordinates now. + listing = open_transactions(c) + rows_now = transaction_rows(listing) + if index >= len(rows_now): + break + c.dev.tap_node(rows_now[index], listing) + time.sleep(2.5) + detail = c.dev.dump() + title = next((t for t in detail.texts() + if re.search(r"(?i)transaction (is|was)|Received|Sent", t)), + None) + c.note(f"detail {index}: {title!r} | " + + str([x for x in detail.texts()[:10]])) + c.check() + # The JSON dump and the error button are both developer-mode only and + # both on this screen. + if c.tap(r"(?i)^Show JSON$", timeout=6): + time.sleep(1.5) + c.check() + c.dev.back() + time.sleep(1) + if c.tap(r"(?i)^Error$", timeout=5): + time.sleep(1.5) + c.note(f"detail {index} carries an error: " + + str(c.dev.dump().texts()[:8])) + c.check() + c.tap(r"(?i)^OK$|^Close$|^Cancel$", timeout=5) + # The overflow menu exists only for a transaction with a payto target + # -- a deposit or a manual withdrawal -- and holds one item, which is + # the only caller of copyToClipBoard on this screen. + if c.tap(r"(?i)^Menu$", timeout=4): + time.sleep(1) + menu = c.dev.dump() + c.note(f"detail {index} overflow menu: " + str(menu.texts()[:8])) + if c.tap(r"(?i)^Copy payto URI$", timeout=5): + time.sleep(1) + c.note(f"detail {index}: copied the payto URI") + else: + c.dev.back() + c.check() + opened += 1 + c.dev.back() + time.sleep(1.5) + c.note(f"opened {opened} detail screens") + c.check() + c.ep.check_database() + + +@scenario("transaction_states_rendered", setup="funded", + about="transaction states this stack cannot produce", + expects=("error-screen", "internal-error-screen", "internal-error-code", + "core-internal", "blank-screen", "fee-on-dead-transaction")) +def s_transaction_states(c: Ctx) -> None: + """Every state the list has a branch for. + + `TransactionsComposable` renders differently for pending, aborting, + suspended, failed and unknown states, and for a transaction that carries + its own error; a stack produces two or three of those on a good day. A + canned `getTransactionsV2` reply produces all of them, including a state + from the future -- the app keeps the unrecognised name on purpose, so what + it does with it is worth seeing. + """ + transactions = [ + _fake_withdrawal("AAAA1", "pending", "kyc", ["suspend", "abort"]), + _fake_withdrawal("AAAA2", "aborting", "bank", ["fail"]), + _fake_withdrawal("AAAA3", "suspended", "exchange-wait-reserve", + ["resume", "fail"]), + _fake_withdrawal("AAAA4", "failed", None, ["delete"], + error={"code": 7003, + "hint": "the exchange could not be reached"}), + _fake_withdrawal("AAAA5", "done", None, ["delete"]), + # A state this version of the app has never heard of. + _fake_withdrawal("AAAA6", "transmogrified", "inside-out", ["delete"]), + # And two the app cannot *parse* at all, which is the only way to reach + # TransactionSerializer's catch branch and the DummyTransaction it + # falls back to: a type that does not exist, and a known type missing + # a field it needs. + { + "type": "interpretive-dance", + "transactionId": "txn:interpretive-dance:AAAA7", + "timestamp": {"t_s": int(time.time())}, + "txState": {"major": "done"}, + "txActions": ["delete"], + }, + { + "type": "withdrawal", + "transactionId": "txn:withdrawal:AAAA8", + "timestamp": {"t_s": int(time.time())}, + "txState": {"major": "done"}, + "txActions": ["delete"], + # no amountRaw/amountEffective/scopes: required, so this throws + }, + ] + c.back_to_home() + c.app.handle_uri("taler+http://dev-experiment/clear-api-responses") + time.sleep(1.5) + if not c.dev.dump().activity.startswith(PKG): + c.dev.launch() + time.sleep(5) + c.app.handle_uri(api_response_uri("getTransactionsV2", + {"transactions": transactions}, count=8)) + time.sleep(2) + for _ in range(3): + if c.dev.dump().activity.startswith(PKG): + break + c.dev.launch() + time.sleep(6) + c.app.home() + time.sleep(4) + screen = open_transactions(c) + c.note("the list: " + str(screen.texts()[:24])) + c.check() + if c.tap(r"(?i)^All$", timeout=10): + time.sleep(3) + full = c.dev.dump() + c.note("the full list: " + str(full.texts()[:28])) + c.check() + rows = transaction_rows(full) + c.note(f"{len(rows)} rows: {[n.label[:20] for n in rows][:8]}") + # The two unparseable transactions become DummyTransactions, which + # carry an error and no amount; the list should still render, and + # whatever it shows for them is worth reading. + if full.find(r"(?i)interpretive|UNKNOWN|Error") is not None: + c.note("the unparseable transactions show as: " + + str([x for x in full.texts() + if re.search(r"(?i)unknown|error|interpretive", x)][:4])) + else: + c.note("nothing on screen marks the two unparseable transactions") + # The failed one carries an error, which is the only way to render + # ErrorTransactionButton; its detail screen needs its own canned reply. + c.app.handle_uri(api_response_uri( + "getTransactionById", + _fake_withdrawal("AAAA4", "failed", None, ["delete"], + error={"code": 7003, + "hint": "the exchange could not be reached"}), + count=4)) + time.sleep(2) + for _ in range(3): + if c.dev.dump().activity.startswith(PKG): + break + c.dev.launch() + time.sleep(6) + c.app.home() + rows = transaction_rows(open_transactions(c)) + if rows: + c.dev.tap_node(rows[0]) + time.sleep(4) + detail = c.dev.dump() + c.note("a detail screen: " + str(detail.texts()[:20])) + if c.tap(r"(?i)Show error|^Error$", timeout=8): + time.sleep(2) + c.note("the error block: " + str(c.dev.dump().texts()[:16])) + c.check() + c.app.handle_uri("taler+http://dev-experiment/clear-api-responses") + c.ep.check_database() + + +TALDIR_CHALLENGES = "/opt/taldir/challenges.log" + + +def taldir_ready(c: Ctx) -> bool: + """Whether this worker can reach the directory the app hard-codes. + + The app always talks to https://taldir.gnunet.org, so the device has to + answer for that name: emu/tls-names.sh adds the hosts entry and forwards + the device's port 443 to the TLS front end, whose CA the sim build type + trusts. Without that the scenario would only measure the refusal. + """ + if "tcp:443" not in c.dev.adb("reverse", "--list", check=False): + c.note("port 443 is not mapped on this worker; run emu/tls-names.sh") + return False + try: + import socket + import ssl + # The front end's certificate is for the two hostnames and nothing + # else, so the probe has to validate the name the *device* validates + # while connecting to the address the device's port 443 forwards to. + # Asking for https://127.0.0.1:8443 instead fails with "IP address + # mismatch" and says nothing about whether the front end works. + ctx = ssl.create_default_context(cafile="/opt/taler-sim/tls/ca.crt") + with socket.create_connection(("127.0.0.1", 8443), timeout=5) as raw: + with ctx.wrap_socket(raw, server_hostname="taldir.gnunet.org") as tls: + tls.sendall(b"GET /config HTTP/1.1\r\n" + b"Host: taldir.gnunet.org\r\n" + b"Connection: close\r\n\r\n") + head = tls.recv(64) + if b" 200 " not in head: + raise RuntimeError(f"answered {head[:40]!r}") + except Exception as e: # noqa: BLE001 + c.note(f"the TLS front end is not answering: {str(e)[:120]}") + return False + return True + + +def latest_challenge(alias: str) -> Optional[str]: + """The challenge the directory's validator recorded for this alias.""" + try: + with open(TALDIR_CHALLENGES) as f: + lines = [l.strip().split("\t") for l in f if alias in l] + except OSError: + return None + return lines[-1][2] if lines and len(lines[-1]) >= 3 else None + + +@scenario("alias_registration_real", setup="funded", + about="register an alias with a real directory, challenge and all", + expects=("error-screen", "internal-error-code", "core-internal")) +def s_alias_registration_real(c: Ctx) -> None: + """The whole alias registration, against a deployed taldir. + + Everything past the "Register Alias" button has never run: the app's URL + is a literal, so without the device answering for that name there is + nothing behind it. With the directory deployed and the name resolved, the + flow is register -> challenge -> complete -> look up, and the challenge + comes from the validator's log the way it would come from an email. + """ + if not taldir_ready(c): + return + alias = f"sim-w{WORKER}-{int(time.time())}@example.com" + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Alias Registration$", max_scrolls=12) + c.must_tap(r"(?i)^Alias Registration$") + screen = c.require(r"(?i)Alias|Duration|Register", timeout=25) + c.note("the form: " + str(screen.texts()[:12])) + c.check() + # Field 0 is the alias *type*, a read-only dropdown: tapping it opens the + # menu, typing goes nowhere, the alias stays empty -- which disables the + # register button -- and the open menu covers it. The alias is field 1. + if not c.fill(alias, 1, clear=True): + c.note("no alias field") + return + time.sleep(1) + if not c.tap_button(r"(?i)^Register Alias$", timeout=15): + c.note("the register button would not tap; the form reads " + + str(c.dev.dump().texts()[:12])) + return + # The directory has to answer, and the validator has to run, before the + # challenge exists. + challenge = None + for _ in range(12): + time.sleep(3) + challenge = latest_challenge(alias) + if challenge: + break + after = c.dev.dump() + c.note(f"after registering (challenge: {challenge}): " + str(after.texts()[:14])) + c.check() + if challenge is None: + c.note("WARNING: the directory recorded no challenge for this alias") + return + # The screen should now be asking for it, in a field labelled "Challenge + # Solution", with an OK button under it. + waiting = c.dev.dump() + if waiting.find(r"(?i)Challenge Solution") is None: + c.note("the screen is not asking for the challenge: " + + str(waiting.texts()[:16])) + return + fields = [n for n in waiting.editable()] + if not fields: + c.note("no field to type the challenge into") + return + # The alias and duration fields are still above it; the solution field is + # the last one. + if not c.fill(challenge, len(fields) - 1, clear=True): + c.note("could not type the challenge") + return + time.sleep(1) + c.tap_button(r"(?i)^OK$", timeout=15) + time.sleep(6) + done = c.dev.dump() + c.note("after completing: " + str(done.texts()[:16])) + c.check() + # And the other half: look the alias up from the contacts screen. + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Contacts$", max_scrolls=12) + c.must_tap(r"(?i)^Contacts$") + if c.tap(r"(?i)^Add Contact$", timeout=20): + screen = c.require(r"(?i)Petname|Alias|Mailbox", timeout=20) + c.fill("Looked up", 0) + c.fill(alias, 1) + time.sleep(1) + if c.tap_button(r"(?i)Lookup with Taldir", timeout=15): + time.sleep(8) + c.note("after the lookup: " + str(c.dev.dump().texts()[:16])) + c.check() + c.ep.check_database() + + +@scenario("db_corruption", setup="funded", + about="scribble on the wallet database and restart the app", + # A corrupt database is supposed to fail to open; what is being + # checked is that the app explains it instead of crashing. + expects=("internal-error-screen", "core-internal", "internal-error-code")) +def s_db_corruption(c: Ctx) -> None: + """A corrupt database must produce an explained failure, not a crash. + + `WalletInitErrorScreen` exists for exactly this and has never been reached + by any other scenario. + """ + from device import PKG + before = c.dev.shell(f"run-as {PKG} ls -l files/talerwalletdb.sqlite3", check=False) + c.note(f"database before: {before.strip()[:120]}") + c.dev.stop() + time.sleep(2) + # Overwrite the SQLite header in place; the file keeps its size, so this is + # corruption rather than truncation. + cmd = ("dd if=/dev/urandom of=files/talerwalletdb.sqlite3 " + "bs=512 count=2 conv=notrunc") + out = c.dev.shell(f"run-as {PKG} {cmd}", check=False) + c.note(f"corrupting: {out.strip()[:160]}") + c.dev.launch() + time.sleep(8) + screen = c.dev.dump() + c.note("after relaunch: " + str(screen.texts()[:14])) + c.check() + log = c.dev.logcat() + crashed = "FATAL EXCEPTION" in log + c.note(f"crashed: {crashed}") + if crashed: + c.ep.session.add([oracles.Finding( + "crash", "the app crashed after its database was corrupted", + "\n".join(l for l in log.splitlines() if "FATAL" in l)[:1000])]) + # Whatever it shows, the wallet has to be usable again afterwards. + c.app.fresh_start(dev_mode=True) + c.note("after a wipe: " + str(c.dev.dump().texts()[:8])) + c.check() + + +@scenario("db_migration_prompt", setup="fresh", + about="plant a wallet database in the old format and migrate it") +def s_db_migration_prompt(c: Ctx) -> None: + """The database migration, which needs a database in the legacy format. + + wallet-core picks its backend from what the file already holds + (`host-impl.qtart.ts`: `inspectWalletDbFile`), so a file carrying + IndexedDB-emulation records is opened with the bridge and `init` reports + `IndexedDB`. That is the only way to reach the "Upgrade wallet database" + row in the settings, `MainActivity`'s migration prompt and progress + dialog, `migrateDatabase`, and -- if the migration can be caught while it + runs -- `cancelProgressToken`, the last wallet-core operation no scenario + had exercised. + + The fixture in `corpus/legacy-indexeddb-wallet.db` has to come from the + *app's own* wallet-core, because IndexedDB refuses to open a database + newer than the schema version the opener asks for. `taler-wallet-cli` + with `TALER_WALLET_DB_BACKEND=indexeddb` does write a legacy database, but + the checkout beside this one is 1.6.48, whose schema is version 36, while + the qtart the app embeds is 1.6.42 and asks for 34: + + VersionError: requested version 34, existing version is 36 + + So the fixture is made by the app itself: build it with + `useNativeDb = false` in `MainViewModel`, launch it once, and copy + `files/talerwalletdb.sqlite3` back out. That file carries + `taler-wallet-main-v10` at version 34, and has to be remade whenever the + bundled qtart moves its schema version. + """ + from device import PKG + # The committed fixture is deliberately small. A bigger one -- made the + # same way, by driving the useNativeDb=false build through a scenario + # first -- migrates slowly enough that the Cancel below can be caught, and + # is passed in with SIM_LEGACY_DB rather than carried in the repository. + legacy = Path(os.environ.get( + "SIM_LEGACY_DB", + Path(__file__).resolve().parent.parent / "corpus" + / "legacy-indexeddb-wallet.db")) + if not legacy.exists(): + c.note(f"no legacy database at {legacy}; nothing to plant") + return + + c.dev.stop() + time.sleep(2) + c.dev.adb("push", str(legacy), "/data/local/tmp/legacy-wallet.db") + c.dev.shell("chmod 644 /data/local/tmp/legacy-wallet.db", check=False) + # The write-ahead log belongs to the database being replaced. + for leftover in ("talerwalletdb.sqlite3-wal", "talerwalletdb.sqlite3-shm"): + c.dev.shell(f"run-as {PKG} rm -f files/{leftover}", check=False) + # dd rather than a redirection: run-as execs its argument without a shell. + out = c.dev.shell( + f"run-as {PKG} dd if=/data/local/tmp/legacy-wallet.db " + "of=files/talerwalletdb.sqlite3", check=False) + c.note("planting the legacy database: " + out.strip()[:160]) + planted = c.dev.shell(f"run-as {PKG} ls -l files/talerwalletdb.sqlite3", + check=False) + c.note("database now: " + planted.strip()[:120]) + + c.dev.launch() + time.sleep(10) + c.note("after relaunch: " + str(c.dev.dump().texts()[:14])) + c.check() + + # The row only exists when wallet-core reports the IndexedDB backend, so + # finding it is the proof that the planted file was accepted. + c.app.open_settings() + try: + c.app.scroll_to_text(r"(?i)^Upgrade wallet database$", max_scrolls=8) + except TimeoutError: + c.note("no migration row in the settings: wallet-core did not report " + "the IndexedDB backend for the planted database; " + + str(c.dev.dump().texts()[:16])) + c.check() + return + c.must_tap(r"(?i)^Upgrade wallet database$") + prompt = c.see(r"(?i)Upgrade wallet database\?", timeout=15) + if prompt is None: + c.note("the migration prompt did not open: " + + str(c.dev.dump().texts()[:14])) + c.check() + return + c.note("the prompt: " + str(prompt.texts()[:8])) + c.check() + + # "Later" first, so the deferral path is exercised too, then ask again. + if c.tap(r"(?i)^Later$", timeout=8): + time.sleep(2) + c.note("after Later: " + str(c.dev.dump().texts()[:10])) + c.check() + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Upgrade wallet database$", max_scrolls=8) + c.must_tap(r"(?i)^Upgrade wallet database$") + c.require(r"(?i)Upgrade wallet database\?", timeout=15) + + # Where the prompt's buttons are, so the progress dialog's Cancel can be + # tapped without a dump first: a dump costs about a second, which is + # longer than the whole migration on a database this size. + prompt_screen = c.dev.dump() + slots = [n.center for n in prompt_screen.labelled() + if re.match(r"(?i)^(Migrate now|Later)$", n.label.strip())] + # The Cancel on the progress dialog is the only caller of + # cancelProgressToken, and this harness cannot reach it. Four attempts, + # all recorded in CAMPAIGN.md: + # + # * a 57 KB legacy fixture -- migrates in well under a second; + # * a 1.7 MB fixture with 512 records and 112 progress notifications -- + # the same; + # * blind taps at the prompt's button coordinates, with no screen dump + # in between (a dump alone costs about a second); + # * freezing the process with SIGSTOP so the taps queue in the input + # dispatcher, both before and after starting the migration. + # + # The taps below are the third of those, kept because they cost nothing + # and would start working the moment a fixture is large enough. What + # would actually settle it is a legacy database of some thousands of + # records, or a debug hook that pauses the migration. + c.must_tap(r"(?i)^Migrate now$", timeout=15) + for x, y in slots: + c.dev.tap(x, y) + + # No separate dump before each attempt: every dump costs about a second, + # which is most of the window on a small database. + cancelled = False + for _ in range(15): + if c.tap(r"(?i)^Cancel$", timeout=1): + cancelled = True + c.note("cancelled the migration while it was running") + break + if cancelled: + # Cancelling is itself a state with its own dialog, and the operation + # it cancels is the only caller of cancelProgressToken. + if c.see(r"(?i)Cancelling", timeout=6) is not None: + c.note("the cancelling dialog was shown") + c.note(f"caught the migration in progress: {cancelled}") + time.sleep(8) + c.note("after the migration: " + str(c.dev.dump().texts()[:14])) + c.check() + + # Whichever way it went, the wallet has to be usable, and the backend it + # ends on has to be one of the two -- not a half-migrated database. + c.app.open_settings() + row = c.dev.dump().find(r"(?i)^Upgrade wallet database$") + c.note("the migration row is still offered: " + str(row is not None)) + c.back_to_home() + c.check() + c.ep.check_database() + + +@scenario("donau_receipt", setup="funded", + about="pay for a tax receipt, then read the donation statement") +def s_donau_receipt(c: Ctx) -> None: + # The donau output type makes the merchant issue a tax receipt for the + # payment, which is what the statements screen lists. + order = c.merchant.create_v1_order( + [{"amount": "EUR:2", "description": "Donation with a receipt", + "inputs": [], "outputs": [{"type": "tax-receipt"}], + "max_fee": "EUR:0.5"}], + summary="Donation with a tax receipt", + ) + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)Review order|Total:|^Pay|donation|receipt", timeout=60) + c.note("donation prompt: " + str(screen.texts()[:14])) + c.check() + c.tap(r"(?i)^Pay\b|confirm payment", timeout=30) + time.sleep(6) + c.note("after paying: " + str(c.dev.dump().texts()[:12])) + c.back_to_home() + try: + c.app.scroll_to_text(r"(?i)^Donation statements$", max_scrolls=5) + except TimeoutError: + c.note("no donation statements section") + c.check() + return + c.must_tap(r"(?i)^Donation statements$") + # "Donation statements" is also the section header on the main screen, so + # the arrival has to be recognised by something only the statements screen + # has: its per-year list ("Donations 2026") or its own title. + screen = c.see(r"(?i)^Donations \d{4}$|^Donation statement$", timeout=25) + if screen is None: + # Expected, and now explained: the button is wired to + # onBalanceSelected(null) rather than to WalletDestination.DonauStatement, + # which has no caller at all -- see + # findings/donation-statements-button-is-wired-to-nothing.md. + c.note("the donation statements screen did not open (the button is a " + "no-op; donation-statements-button-is-wired-to-nothing.md): " + + str(c.dev.dump().texts()[:14])) + c.check() + return + c.note("statements: " + str(screen.texts()[:14])) + c.check() + rows = [n for n in screen.labelled() + if re.match(r"(?i)^Donations \d{4}$", n.label.strip())] + if rows: + c.dev.tap(*rows[0].center) + time.sleep(2) + detail = c.dev.dump() + c.note("statement detail: " + str(detail.texts()[:14])) + if detail.find(r"(?i)Show this QR code|Tax authority|Legal domain") is None: + c.note("WARNING: the statement detail shows none of its own labels") + c.check() + c.ep.check_database() + + +@scenario("refund_detail", setup="funded", + about="take a refund and open the refund transaction") +def s_refund_detail(c: Ctx) -> None: + order = flows.pay(c.app, c.merchant, "EUR:2", summary="Order to refund fully") + c.app.home() + res = c.merchant.refund(order["order_id"], "EUR:2", reason="simulator full refund") + uri = res.get("taler_refund_uri") + if not uri: + raise RuntimeError(f"merchant returned no refund uri: {res}") + c.app.handle_uri(uri) + time.sleep(5) + c.note("after the refund uri: " + str(c.dev.dump().texts()[:12])) + screen = open_transactions(c) + rows = transaction_rows(screen) + c.note(f"{len(rows)} transactions: {[n.label[:22] for n in rows]}") + for index in range(min(3, len(rows))): + screen = open_transactions(c) + rows_now = transaction_rows(screen) + if index >= len(rows_now): + break + c.dev.tap_node(rows_now[index], screen) + time.sleep(2) + detail = c.dev.dump() + if detail.find(r"(?i)refund"): + c.note("refund detail: " + str(detail.texts()[:12])) + c.check() + c.tap(r"(?i)^Show JSON$", timeout=8) + c.check() + c.dev.back() + c.dev.back() + time.sleep(1) + c.check() + + +@scenario("exchange_shopping", setup="funded", + about="the exchange's \"where to pay\" screen") +def s_exchange_shopping(c: Ctx) -> None: + """The "Where to pay" screen, which needs two exchanges to exist at all. + + The balance card that opens it is hidden while `shoppingUrls` is empty, and + with exactly one URL the button opens that site in a browser instead of the + screen -- so the screen is reachable only when the wallet holds a currency + from **two** exchanges that both advertise one (`SHOPPING_URL` in each + exchange's config). The second exchange has to be in the balance, so this + withdraws from it first. + """ + second = second_exchange_or_skip(c) + if second is not None: + # One URL is not enough: with a single entry the button opens that site + # in a browser. Two take a *balance* at each exchange, so the second + # one has to be picked during a withdrawal rather than merely added. + # Coins at the second exchange, without touching any exchange-picking + # UI: the bank-integrated prompt has no service row (its exchange is + # fixed), and a manual withdrawal would need a real wire transfer. A + # peer payment lands at the *sender's* exchange, so a peer funded at + # the second one gives this wallet a second EUR scope. + try: + # peer_receive knows both shapes of the terms prompt on this + # screen -- "Terms of Service" and "Review terms of service" -- + # which is why this does not drive the accept by hand. + screen = flows.peer_receive(c.app, c.env, "EUR:2", c.cli, + exchange=second) + c.note("after receiving from the second service: " + + str(screen.texts()[:12])) + time.sleep(8) + except Exception as e: # noqa: BLE001 + c.note(f"the second service did not reach the balance: {str(e)[:160]}") + c.check() + # What is left, for whoever picks this up: two services give two + # balance *scopes*, one pager page each, and the card on a page carries + # only that service's URL -- so each card still has one URL and the + # button opens a browser. Merging them with "treat as global" (per the + # exchange menu) should put both on one card; driving that menu from + # here kept landing back on the home screen, and the screen is 62 + # lines, so it was not worth more rounds of guessing. + c.back_to_home() + card = c.dev.dump() + c.note("the balance screen: " + str(card.texts()[:14])) + for label in (r"(?i)Where to pay", r"(?i)^Shopping$"): + if c.tap(label, timeout=10): + screen = c.see(r"(?i)where to pay|website|shopping", timeout=20) + c.note("shopping: " + str(screen.texts()[:12] if screen else None)) + c.check() + return + c.note("the card is there but the screen is not: with one URL the button " + "opens that site in a browser, and reaching ExchangeShoppingScreen " + "needs one scope carrying two") + c.check() + + +@scenario("cancel_in_flight", setup="funded", + about="back out of prompts while they are still loading") +def s_cancel_in_flight(c: Ctx) -> None: + """Leaving a prompt before it has loaded, which is where a half-finished + request would show up as a stuck transaction. + + It does *not* reach `cancelProgressToken`, whatever this docstring used to + claim: that operation has exactly one caller, + `WalletBackendApi.cancelDatabaseMigration`, and the only thing that offers + a database migration is a wallet whose database is still in the IndexedDB + emulation. `MainViewModel` hard-codes `useNativeDb = true`, so a new + install never has one, and `taler-wallet-cli`'s database is native too -- + so nothing in this environment can produce the legacy format, and + `cancelProgressToken`, `migrateDatabase` and the migration UI stay out of + reach without a database written by an older wallet. + """ + order = c.merchant.create_order("EUR:1", summary="Cancelled while loading") + for delay in (0.3, 1.0, 2.0): + c.dev.send_uri(order["pay_uri"]) + time.sleep(delay) + c.dev.back() + time.sleep(1.5) + c.note(f"after backing out {delay}s in: {c.dev.dump().texts()[:8]}") + c.check() + c.back_to_home() + # The same for a withdrawal, which takes longer to prepare. + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + for delay in (0.3, 1.5): + c.dev.send_uri(op["taler_withdraw_uri"]) + time.sleep(delay) + c.dev.back() + time.sleep(1.5) + c.note(f"withdrawal, backed out {delay}s in: {c.dev.dump().texts()[:8]}") + c.check() + c.back_to_home() + # Nothing should be left half-done. + c.ep.check_database() + rows = transaction_rows(open_transactions(c)) + c.note(f"{len(rows)} transactions after cancelling: " + f"{[n.label[:22] for n in rows]}") + c.check() + + +@scenario("alias_registration", setup="funded", + about="the Taldir alias registration form") +def s_alias_registration(c: Ctx) -> None: + """Fill and submit the alias form. + + No Taldir service runs in this stack, so registration is expected to fail; + the point is the screen itself, which nothing else reaches, and that the + failure is reported rather than swallowed. + """ + c.app.open_settings() + c.app.scroll_to_text(r"(?i)^Alias Registration$", max_scrolls=12) + c.must_tap(r"(?i)^Alias Registration$") + screen = c.require(r"(?i)Alias|Duration|Register", timeout=25) + c.note("alias screen: " + str(screen.texts()[:14])) + c.check() + # The type picker is a dropdown: choosing from it leaves the menu open, and + # a "Register Alias" tap underneath it does nothing at all, which is how + # this scenario used to report a submission it never made. + for kind, value in ((r"(?i)^email$", "simulator@example.com"), + (r"(?i)^phone$", "+10000000000")): + if c.tap(r"(?i)Alias Type", timeout=8): + c.tap(kind, timeout=8) + time.sleep(1) + c.check() + if not c.fill(value): + c.note(f"no alias field for {value!r}") + break + time.sleep(1) + if not c.tap(r"(?i)^Register Alias$", timeout=12): + c.note("the register button is not tappable") + break + # Registration goes to the hard-coded https://taldir.gnunet.org, which + # is not reachable from here, so what matters is whether the screen + # says so. + time.sleep(8) + after = c.dev.dump() + c.note(f"{value!r} -> {after.texts()[:14]}") + if after.find(r"(?i)error|failed|could not|unreachable|retry") is None: + c.note("WARNING: no sign on screen that the registration failed") + c.check() + c.ep.check_database() + + +@scenario("uri_storm", setup="funded", + about="many URIs in rapid succession, valid and malformed") +def s_uri_storm(c: Ctx) -> None: + """Fire URIs faster than the app can finish handling them. + + Each one starts an asynchronous request; overlapping them is where a + half-initialised screen or a lost cancellation would show up. + """ + order = c.merchant.create_order("EUR:1", summary="Storm order") + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + storm = [ + order["pay_uri"], + op["taler_withdraw_uri"], + corpus.MALFORMED["bad_base32"], + corpus.STRUCTURAL["pay"], + corpus.MALFORMED["huge"], + order["pay_uri"], + corpus.STRUCTURAL["withdraw_exchange"], + corpus.MALFORMED["unknown_action"], + ] + for round_number in range(3): + for uri in storm: + c.dev.send_uri(uri) + time.sleep(0.35) + time.sleep(3) + screen = c.dev.dump() + c.note(f"after burst {round_number + 1}: {screen.texts()[:10]}") + c.check() + c.back_to_home() + # Everything should still work afterwards. + c.app.home() + rows = transaction_rows(open_transactions(c)) + c.note(f"{len(rows)} transactions after the storm") + c.check() + c.ep.check_database() + + +@scenario("long_text_fields", setup="funded", + about="very long input in every text field that will take it") +def s_long_text(c: Ctx) -> None: + blob = "A" * 4000 + places = [ + (r"(?i)^Send$", r"(?i)Send money|Amount to send|Purpose"), + (r"(?i)^Request$", r"(?i)Request money|Amount to receive"), + ] + for entry, marker in places: + c.back_to_home() + if not c.tap(entry, timeout=20): + continue + screen = c.see(marker, timeout=25) + if screen is None: + continue + # The purpose/summary field takes free text; the amount field does not. + fields = screen.editable() + c.note(f"{entry}: {len(fields)} editable fields") + for index in range(len(fields)): + if not c.fill(blob, index): + continue + time.sleep(1.5) + after = c.dev.dump() + c.note(f" field {index} after 4000 chars: {after.texts()[:6]}") + c.check() + c.back_to_home() + c.ep.check_database() + + +@scenario("withdraw_age_restricted", setup="fresh", + about="withdraw coins restricted to an age group") +def s_withdraw_age(c: Ctx) -> None: + """The age picker only appears when the exchange offers age-restricted + denominations, which the simulator's exchange now does.""" + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:10") + c.app.handle_uri(op["taler_withdraw_uri"]) + screen = c.require(r"(?i)Confirm withdrawal|Total amount", timeout=60) + c.note("withdrawal prompt: " + str(screen.texts()[:14])) + if not c.tap(r"(?i)Restrict usage to age|^Unrestricted$", timeout=15): + c.note("no age restriction offered") + return + picker = c.dev.dump() + c.note("age options: " + str(picker.texts()[:14])) + c.check() + chosen = None + for age in (r"(?i)^12$", r"(?i)^13$", r"(?i)^16$", r"(?i)^18$"): + if c.tap(age, timeout=6): + chosen = age + break + c.note(f"chose {chosen}") + c.check() + c.accept_tos() + c.must_tap(r"(?i)Confirm withdrawal", timeout=30) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + deadline = time.time() + 60 + while time.time() < deadline: + if c.bank.withdrawal_status(op["withdrawal_id"])["status"] == "selected": + break + time.sleep(2) + c.bank.confirm_withdrawal(*flows.WALLET_USER, op["withdrawal_id"]) + for _ in range(20): + if c.dev.dump().find(r"(?i)completed successfully"): + break + time.sleep(3) + detail = c.dev.dump() + c.note("after the age-restricted withdrawal: " + str(detail.texts()[:14])) + c.tap(r"(?i)^Show JSON$", timeout=8) + c.check() + c.ep.check_database() + + +def kyc_enabled(c: Ctx) -> bool: + """Whether the stack was started from the KYC variant. + + The exchange says so itself, which is more reliable than guessing from the + config file the stack happens to have been given. + """ + import urllib.request + try: + with urllib.request.urlopen(f"{c.env.exchange}keys", timeout=15) as resp: + keys = json.loads(resp.read().decode()) + except Exception as e: + c.note(f"could not read the exchange's keys: {e}") + return False + if not keys.get("kyc_enabled"): + c.note("this stack has KYC switched off; start it with " + "SIM_CONF=sim-kyc.conf to exercise these paths") + return False + return True + + +@scenario("kyc_withdraw_trips_rule", setup="fresh", + about="withdraw past the KYC threshold and follow what the wallet offers", + expects=("error-screen", "unfinished-transaction", "background-error")) +def s_kyc_withdraw(c: Ctx) -> None: + """The KYC stack trips a rule above EUR:5 within a day. + + What matters here is the wallet's half: that it says identification is + needed, offers a way to start it, and does not leave the transaction + looking finished when it is not. + """ + if not kyc_enabled(c): + return + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:10") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + c.see(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + deadline = time.time() + 60 + while time.time() < deadline: + if c.bank.withdrawal_status(op["withdrawal_id"])["status"] == "selected": + break + time.sleep(2) + c.bank.confirm_withdrawal(*flows.WALLET_USER, op["withdrawal_id"]) + + # Now the exchange should ask for identification rather than paying out. + kyc_screen = None + deadline = time.time() + 120 + while time.time() < deadline: + screen = c.dev.dump() + if screen.find(r"(?i)KYC|identification|verify|Complete"): + kyc_screen = screen + break + if screen.find(r"(?i)completed successfully"): + c.note("the withdrawal completed without any KYC step") + break + time.sleep(4) + if kyc_screen is None: + c.note("no KYC prompt appeared: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + return + c.note("KYC prompt: " + str(kyc_screen.texts()[:14])) + c.check() + # Follow the call to action; it hands off to a browser, so coming back is + # part of the test. + if c.tap(r"(?i)Complete KYC|KYC required|verify|identification", timeout=20): + time.sleep(6) + after = c.dev.dump() + c.note(f"after tapping the KYC action: activity={after.activity} " + f"{after.texts()[:10]}") + c.check() + c.dev.launch() + time.sleep(4) + c.note("back in the wallet: " + str(c.dev.dump().texts()[:12])) + c.check() + c.ep.check_database() + + +@scenario("kyc_transaction_actions", setup="fresh", + about="what a KYC-blocked transaction offers in its detail screen", + expects=("error-screen", "unfinished-transaction", "background-error")) +def s_kyc_actions(c: Ctx) -> None: + if not kyc_enabled(c): + return + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:10") + c.app.handle_uri(op["taler_withdraw_uri"]) + c.accept_tos() + c.must_tap(r"(?i)confirm withdrawal", timeout=60) + deadline = time.time() + 60 + while time.time() < deadline: + if c.bank.withdrawal_status(op["withdrawal_id"])["status"] == "selected": + break + time.sleep(2) + c.bank.confirm_withdrawal(*flows.WALLET_USER, op["withdrawal_id"]) + time.sleep(25) + screen = open_transactions(c) + rows = transaction_rows(screen) + c.note(f"{len(rows)} transactions: {[n.label[:24] for n in rows]}") + if rows: + c.dev.tap_node(rows[0], screen) + time.sleep(3) + detail = c.dev.dump() + c.note("KYC-blocked transaction: " + str(detail.texts()[:16])) + c.check() + for action in (r"(?i)^Show JSON$", r"(?i)^Retry$", r"(?i)^Suspend$", + r"(?i)^Resume$"): + if c.tap(action, timeout=8): + c.check() + c.dev.back() + time.sleep(1) + c.ep.check_database() + + +def twister_or_skip(c: Ctx) -> Twister | None: + """The fault injector, or None when the stack was not started with it. + + Only the sim-twister.conf variant puts a proxy in front of the exchange; + on an ordinary stack these scenarios have nothing to break and say so + rather than failing. + """ + env_file = Path("/opt/taler-sim/run/stack/env.json") + try: + if not json.loads(env_file.read_text()).get("twister"): + c.note("the stack is not running twister; nothing to inject") + return None + except (OSError, json.JSONDecodeError): + c.note("no stack env.json; cannot tell whether twister is running") + return None + try: + twister = Twister() + if not twister.alive(): + c.note("twister is configured but not answering") + return None + return twister + except TwisterUnavailable as e: + c.note(f"twister unavailable: {e}") + return None + + +@scenario("twister_withdraw_faults", setup="fresh", + about="damage the exchange's replies during a withdrawal", + expects=("error-screen", "background-error", "stuck-operation", + "unfinished-transaction")) +def s_twister_withdraw(c: Ctx) -> None: + """Each fault is armed, then a withdrawal is attempted. + + What is being checked is the shape of the failure: a refusal the user can + read, or a retry, rather than an internal error, a blank screen or a + transaction that sits there for ever. + """ + twister = twister_or_skip(c) + if twister is None: + return + for name, arm in FAULTS.items(): + c.app.fresh_start(dev_mode=True) + c.dev.logcat(clear=True) + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + # The fault stays armed for the whole withdrawal: one arming would be + # spent on whichever poll happened to come first. + with twister.armed(arm) as a: + c.app.handle_uri(op["taler_withdraw_uri"]) + time.sleep(6) + screen = c.dev.dump() + c.note(f"{name}: {screen.texts()[:10]}") + c.check() + # Try to carry on: the wallet should either recover or explain itself. + c.accept_tos() + c.tap(r"(?i)confirm withdrawal|^Retry$", timeout=15) + time.sleep(6) + c.note(f"{name} after retry: {c.dev.dump().texts()[:10]}") + c.check() + if a.errors: + c.note(f"{name}: arming complained: {a.errors}") + c.note(f"{name}: armed {a.fired} times") + # ... and recover with the fault gone, so a permanent failure is + # distinguishable from one the wallet retries out of. + time.sleep(8) + c.note(f"{name} once the fault stops: {c.dev.dump().texts()[:10]}") + c.check() + c.ep.check_database() + + +@scenario("twister_payment_faults", setup="funded", + about="damage the exchange's replies during a payment", + expects=("error-screen", "background-error", "stuck-operation", + "unfinished-transaction")) +def s_twister_payment(c: Ctx) -> None: + twister = twister_or_skip(c) + if twister is None: + return + # Seven payments of EUR:1, each of which may strand coins on a purchase + # that cannot finish, exhaust the EUR:10 the fixture withdraws: the last + # faults then measure "Insufficient balance" rather than the fault. + flows.withdraw(c.app, c.bank, "EUR:20") + c.back_to_home() + recovered = {} + for name, arm in FAULTS.items(): + order = c.merchant.create_order("EUR:1", summary=f"Order during {name}") + # Only the exchange sits behind the proxy, so the prompt itself comes + # through intact and the fault has to survive until the coins are + # deposited -- which only happens once "Pay" is tapped. + with twister.armed(arm) as a: + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)^Pay\b|Review order|Total", timeout=40) + c.note(f"{name} prompt: {screen.texts()[:10]}") + c.must_tap(r"(?i)^Pay\b", timeout=30) + time.sleep(8) + c.note(f"{name} after paying: {c.dev.dump().texts()[:12]}") + c.check() + status = c.merchant.order_status(order["order_id"], order["token"]) + c.note(f"{name}: merchant says {status.get('order_status')}") + c.note(f"{name}: armed {a.fired} times") + # With the fault gone the payment should either complete or fail for + # good. Retries have a backoff, so this has to wait properly: the + # finding would be a purchase that never resolves either way. + # Five minutes, not ninety seconds: the first fault-injection phase + # reported every payment still "claimed" after 90s, which says nothing + # -- wallet-core retries with a backoff, and a deposit that has not + # been retried yet looks exactly like one that never will. Long + # enough to tell those apart, and the elapsed time is recorded so a + # slow recovery can be told from none. + started = time.time() + deadline = started + 300 + final = None + while time.time() < deadline: + final = c.merchant.order_status(order["order_id"], + order["token"]).get("order_status") + if final == "paid": + break + time.sleep(10) + recovered[name] = final + c.note(f"{name}: {int(time.time() - started)}s after the fault " + f"stopped the merchant says {final}; screen " + f"{c.dev.dump().texts()[:10]}") + c.check() + c.back_to_home() + c.note("recovery per fault: " + str(recovered)) + stuck = [k for k, v in recovered.items() if v != "paid"] + if stuck: + c.note(f"WARNING: these payments never completed: {stuck}") + c.ep.check_database() + + +@scenario("twister_field_faults", setup="fresh", + about="delete and rewrite fields of the exchange's replies", + expects=("error-screen", "background-error", "stuck-operation", + "unfinished-transaction")) +def s_twister_fields(c: Ctx) -> None: + """Structural damage rather than transport damage: a reply that parses but + is missing a field, or carries a wrong one.""" + twister = twister_or_skip(c) + if twister is None: + return + # Twister walks dot paths and takes a numeric token as an array index, so + # a nested field can be named exactly: "denoms" alone is not a key of + # /keys and silently matched nothing. + cases = [ + ("delete-denominations", lambda t: t.delete("denominations")), + ("delete-denom-list", lambda t: t.delete("denominations.0.denoms")), + ("delete-signature", lambda t: t.delete("exchange_sig")), + ("flip-master-pub", lambda t: t.flip("master_public_key")), + ("flip-denom-sig", lambda t: t.flip("denominations.0.denoms.0.master_sig")), + ("delete-wire-fees", lambda t: t.delete("wire_fees")), + ("rewrite-version", lambda t: t.modify("version", "999:0:0")), + ("rewrite-currency", lambda t: t.modify("currency", "XXX")), + ("rewrite-base-url", lambda t: t.modify("base_url", "http://elsewhere.invalid/")), + ] + for name, arm in cases: + c.app.fresh_start(dev_mode=True) + c.dev.logcat(clear=True) + op = c.bank.create_withdrawal(*flows.WALLET_USER, "EUR:5") + with twister.armed(arm) as a: + c.app.handle_uri(op["taler_withdraw_uri"]) + time.sleep(7) + c.note(f"{name}: {c.dev.dump().texts()[:12]}") + c.check() + c.accept_tos() + c.accept_tos() + c.tap(r"(?i)confirm withdrawal", timeout=10) + time.sleep(6) + c.note(f"{name} after confirming: {c.dev.dump().texts()[:12]}") + c.check() + if a.errors: + c.note(f"{name}: arming complained: {a.errors}") + c.note(f"{name}: armed {a.fired} times") + c.ep.check_database() + + +@scenario("memory_pressure", setup="paid", + about="trim memory and background the app mid-flow") +def s_memory_pressure(c: Ctx) -> None: + """What Android does to an app it wants memory back from. + + TRIM_MEMORY_RUNNING_CRITICAL while a prompt is open, then a trip through + the background, is where a screen that kept state outside the saved + instance falls over. + """ + from device import PKG + order = c.merchant.create_order("EUR:1", summary="Order under memory pressure") + c.app.handle_uri(order["pay_uri"]) + c.require(r"(?i)Review order|Total:|^Pay", timeout=60) + pid = c.dev.shell(f"pidof {PKG}", check=False).strip().split()[0:1] + c.note(f"pid: {pid}") + for level in ("RUNNING_MODERATE", "RUNNING_LOW", "RUNNING_CRITICAL"): + c.dev.shell(f"am send-trim-memory {PKG} {level}", check=False) + time.sleep(1.5) + c.note("after trimming: " + str(c.dev.dump().texts()[:10])) + c.check() + # Background the app, trim again, come back. + c.dev.key("KEYCODE_HOME") + time.sleep(2) + c.dev.shell(f"am send-trim-memory {PKG} COMPLETE", check=False) + time.sleep(2) + c.dev.launch() + time.sleep(4) + restored = c.dev.dump() + c.note("after returning: " + str(restored.texts()[:12])) + c.check() + # The prompt should either still be there or be gone cleanly; either way + # the wallet has to work afterwards. + c.back_to_home() + rows = transaction_rows(open_transactions(c)) + c.note(f"{len(rows)} transactions afterwards") + c.check() + c.ep.check_database() + + +@scenario("rapid_taps", setup="funded", + about="hammer confirm buttons faster than the app can respond") +def s_rapid_taps(c: Ctx) -> None: + """Double-submission is the classic way to pay twice or abort twice.""" + order = c.merchant.create_order("EUR:1", summary="Hammered order") + c.app.handle_uri(order["pay_uri"]) + screen = c.require(r"(?i)Review order|^Pay", timeout=60) + pay = screen.find(r"(?i)^Pay\b") + if pay is None: + c.note("no pay button: " + str(screen.texts()[:10])) + return + target = screen.tap_target(pay) + x, y = target.center + for _ in range(6): + c.dev.tap(x, y) + time.sleep(0.15) + time.sleep(6) + c.note("after hammering pay: " + str(c.dev.dump().texts()[:12])) + c.check() + status = c.merchant.order_status(order["order_id"], order["token"]) + c.note(f"order status: {status.get('order_status')}, refunded: {status.get('refunded')}") + # One payment, not six. + rows = transaction_rows(open_transactions(c)) + purchases = [n.label for n in rows] + c.note(f"transactions: {purchases}") + c.check() + c.ep.check_database() + + +# -------------------------------------------------------------------- runner --- + +SETUPS: dict[str, Callable] = { + "fresh": lambda app, env: app.fresh_start(dev_mode=True), + "funded": flows.fund_wallet, + "paid": flows.funded_and_paid, + "keep": lambda app, env: app.home(), +} + + +def run(names: list[str], serial: str = SERIAL) -> dict: + env = Env.load() + dev = Device(serial) + stamp = int(time.time()) + results = [] + all_findings: dict[str, oracles.Finding] = {} + + for name in names: + sc = REGISTRY[name] + ep = Episode(dev, OUT, name=f"suite-w{WORKER}-{stamp}-{name}", + coverage_dir=COVERAGE) + c = Ctx(ep, env) + status, error = "ok", None + started = time.time() + try: + SETUPS[sc.setup](ep.app, env) + # Only what the scenario itself provokes should count. + ep.session = oracles.Session() + dev.logcat(clear=True) + sc.fn(c) + ep.observe() + except Exception as e: + status = "driver-error" + error = f"{type(e).__name__}: {e}" + traceback.print_exc(limit=3) + expected = [f for f in ep.session.findings.values() if f.kind in sc.expects] + summary = ep.finish({"scenario": name, "setup": sc.setup, "status": status, + "error": error, "notes": c.notes, + "expected_findings": [f.fingerprint for f in expected], + "seconds": round(time.time() - started, 1)}) + summary["serious"] = len([f for f in ep.session.serious() + if f.kind not in sc.expects]) + all_findings.update({k: v for k, v in ep.session.findings.items() + if v.kind not in sc.expects}) + results.append(summary) + print(f" {name:26} {status:13} {summary['serious']} serious, " + f"{len(summary['findings'])} total, {summary['seconds']}s") + for f in ep.session.findings.values(): + print(f" [{f.kind}] {f.detail[:150]}") + + out = { + "stamp": stamp, + "scenarios": results, + "findings": [f.__dict__ | {"fingerprint": f.fingerprint} + for f in all_findings.values()], + } + (OUT / f"suite-w{WORKER}-{stamp}-summary.json").write_text(json.dumps(out, indent=2)) + # oracles.INFORMATIONAL, not just "error-screen": this tally used its own + # narrower rule, so a withdrawal left pending on purpose -- every manual + # withdrawal the suite starts and never wires money to sits in + # PendingQueryingStatus forever, by design -- was counted as a serious + # finding twice a round and triaged again every time. + serious = [f for f in all_findings.values() + if f.kind not in oracles.INFORMATIONAL] + print(f"\n{len(results)} scenarios, " + f"{sum(1 for r in results if r['status'] == 'ok')} ok, " + f"{len(all_findings)} findings ({len(serious)} serious)") + print(f"summary: {OUT}/suite-w{WORKER}-{stamp}-summary.json") + return out + + +def main() -> int: + args = [a for a in sys.argv[1:] if not a.startswith("-")] + if "--list" in sys.argv: + for name, sc in REGISTRY.items(): + print(f"{name:26} [{sc.setup}] {sc.about.strip().splitlines()[0][:70]}") + return 0 + names = args or list(REGISTRY) + unknown = [n for n in names if n not in REGISTRY] + if unknown: + print(f"unknown scenarios: {unknown}\nknown: {list(REGISTRY)}") + return 2 + out = run(names) + return 0 if all(r["status"] == "ok" for r in out["scenarios"]) else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/wallet-simulator/driver/twister.py b/wallet-simulator/driver/twister.py @@ -0,0 +1,186 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Fault injection between the wallet and the exchange. + +`taler-twister` is an HTTP proxy that forwards to the real exchange and can +damage what passes through: truncate a response, force a status code, delete +or rewrite a field of the JSON. The stack has to be started from +`sim-twister.conf` for any of this to have something to talk to, and the +wallet's exchange base URL is then the twister port. + +Each command affects the *next* response (or upload) the proxy handles and is +then forgotten, so arming once and then starting a wallet operation usually +damages some unrelated poll instead of the request under test. `armed` keeps a +fault re-armed for as long as the step runs, which is what a scenario wants. + + t = Twister() + t.response_code(500) # the next exchange reply becomes a 500 + t.malform() # ... or is truncated at a random point + t.delete("denominations") # ... or loses a field + + with t.armed(lambda x: x.response_code(500)): + ... # every exchange reply in here is a 500 + +Dot paths address nested fields, and a numeric token is an array index, so +`denominations.0.denoms.0.master_sig` names one denomination signature. +""" + +from __future__ import annotations + +import json +import subprocess +import threading +import time +from pathlib import Path +from typing import Callable + +BINARY = "/opt/twister/bin/taler-twister" +DEFAULT_CONFIG = "/opt/taler-sim/run/stack/sim-twister.conf" +ENV_FILE = Path("/opt/taler-sim/run/stack/env.json") + + +class TwisterUnavailable(RuntimeError): + pass + + +class Twister: + def __init__(self, config: str | None = None, timeout: int = 30): + self.config = config or self._config_from_env() or DEFAULT_CONFIG + self.timeout = timeout + + @staticmethod + def _config_from_env() -> str | None: + try: + info = json.loads(ENV_FILE.read_text()).get("twister") + except (OSError, json.JSONDecodeError): + return None + return (info or {}).get("config") + + def _run(self, *args: str) -> str: + if not Path(BINARY).is_file(): + raise TwisterUnavailable(f"no twister binary at {BINARY}") + proc = subprocess.run([BINARY, "-c", self.config, *args], + capture_output=True, text=True, timeout=self.timeout) + if proc.returncode != 0: + raise TwisterUnavailable( + f"taler-twister {' '.join(args)} failed: " + f"{(proc.stderr or proc.stdout).strip()[:300]}" + ) + return proc.stdout + + # -- state ------------------------------------------------------------ + + def alive(self) -> bool: + try: + self._run("--checkalive") + return True + except TwisterUnavailable: + return False + + # -- faults ----------------------------------------------------------- + + def malform(self) -> None: + """Truncate the next response at a random point.""" + self._run("--malform") + + def malform_upload(self) -> None: + """Truncate the next request the wallet sends.""" + self._run("--malformupload") + + def response_code(self, status: int) -> None: + """Answer the next request with this status code.""" + self._run(f"--responsecode={status}") + + def delete(self, path: str) -> None: + """Remove a field from the next response body.""" + self._run(f"--deleteobject={path}") + + def modify(self, path: str, value: str) -> None: + """Replace a field in the next response body (always as a string).""" + self._run(f"--modify-dl={path}", f"--value={value}") + + def flip(self, path: str) -> None: + """Flip one character of a string field in the next response.""" + self._run(f"--flip-dl={path}") + + def flip_upload(self, path: str) -> None: + self._run(f"--flip-ul={path}") + + def header(self, name: str, value: str) -> None: + """Rewrite a header of the next response.""" + self._run(f"--modify-header-dl={name}", f"--value={value}") + + + # -- keeping a fault armed -------------------------------------------- + + def armed(self, arm: "Callable[[Twister], None]", period: float = 0.4): + """Context manager that re-arms `arm` until the block exits. + + A fault is one-shot, and the wallet talks to the exchange constantly + (/config, /keys, /reserves/...), so a single arming lands on an + arbitrary request. Re-arming in the background makes the fault apply + to the whole step; the number of times it actually fired is reported + as `fired` on the handle. + """ + twister = self + + class _Armed: + fired = 0 + errors: list[str] = [] + + def __init__(self) -> None: + self._stop = threading.Event() + self._thread = threading.Thread(target=self._loop, daemon=True) + + def _loop(self) -> None: + while not self._stop.is_set(): + try: + arm(twister) + self.fired += 1 + except Exception as e: # noqa: BLE001 - reported, not raised + if len(self.errors) < 3: + self.errors.append(str(e)[:120]) + self._stop.wait(period) + + def __enter__(self) -> "_Armed": + self._thread.start() + return self + + def __exit__(self, *exc: object) -> None: + self._stop.set() + self._thread.join(timeout=5) + + return _Armed() + + +# The faults a scenario can arm, with names that read in a report. +FAULTS = { + "truncated-response": lambda t: t.malform(), + "truncated-request": lambda t: t.malform_upload(), + "http-500": lambda t: t.response_code(500), + "http-404": lambda t: t.response_code(404), + "http-403": lambda t: t.response_code(403), + "http-502": lambda t: t.response_code(502), + "wrong-content-type": lambda t: t.header("Content-Type", "text/plain"), +} + + +if __name__ == "__main__": + import sys + t = Twister() + print(f"config: {t.config}") + print(f"alive: {t.alive()}") + if len(sys.argv) > 1: + FAULTS[sys.argv[1]](t) + print(f"armed {sys.argv[1]}") diff --git a/wallet-simulator/driver/wallet.py b/wallet-simulator/driver/wallet.py @@ -0,0 +1,200 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Wallet-app operations on top of the raw device driver. + +Only app-level knowledge lives here: the labels of the screens the simulator +has to pass through to reach a feature, and the one setting the whole simulator +depends on — developer mode, without which HandleUriScreen refuses every +taler+http:// URI that a local http deployment produces. +""" + +from __future__ import annotations + +import re +import time + +from device import Device, Screen + +DEV_MODE_LABEL = "Developer mode" +# Only shown while developer mode is on, so it doubles as the check that the +# toggle took effect. +DEV_MODE_MARKER = "Withdraw demo KUDOS" + + +class Wallet: + def __init__(self, dev: Device): + self.dev = dev + # Set by Episode: dump coverage before the process is wiped. + self.before_wipe = None + + # -- navigation ------------------------------------------------------- + + def fresh_start(self, dev_mode: bool = True) -> None: + """Wipe app data and come back up, optionally in developer mode.""" + # Coverage lives in the app process, so whatever ran before this point + # is lost when the process goes. The Episode sets this hook; without + # it, every scenario that restarts mid-run threw its measurement away + # (WalletInitErrorScreen reads 0% although db_corruption renders it). + if self.before_wipe is not None: + try: + self.before_wipe() + except Exception as e: # noqa: BLE001 - never fail a wipe over this + print(f"pre-wipe coverage dump failed: {e}") + # Rotation outlives the app's data, so reset it before anything else. + self.dev.portrait() + self.dev.clear_data() + # "pm clear" also revokes runtime permissions, so the camera has to be + # granted again or the scan screen opens on a system dialog instead. + self.dev.grant_camera() + self.dev.launch() + self.dev.wait_for(r"(?i)wallet|balance|withdraw", timeout=90) + if dev_mode: + self.enable_dev_mode() + + def home(self, tries: int = 6) -> Screen: + """Back out to the main screen.""" + for _ in range(tries): + screen = self.dev.dump() + if screen.find(r"(?i)^Scan QR code$") and not screen.find(r"(?i)^Close sheet$"): + return screen + self.dev.back() + time.sleep(1) + return self.dev.dump() + + def scroll_to_text(self, pattern: str, max_scrolls: int = 8) -> Screen: + """Scroll until a label shows up, downwards and then back up. + + Scrolling only one way misses a row that was already above the fold, + and a list that has reached its end stops moving, so the upward sweep + is where a missed row is usually found. + """ + seen: list[str] = [] + for direction in (True, False): + for _ in range(max_scrolls): + screen = self.dev.dump() + if screen.find(pattern): + return screen + signature = screen.signature() + if seen and seen[-1] == signature and not direction: + break # the list is not moving any more + seen.append(signature) + self.dev.scroll(down=direction, screen=screen) + time.sleep(0.8) + screen = self.dev.dump() + if screen.find(pattern): + return screen + raise TimeoutError(f"{pattern!r} not reachable by scrolling; " + f"last screen: {screen.texts()}") + + def open_settings(self, tries: int = 3) -> Screen: + """Open the Settings root and wait for it. + + How much of the list is on screen depends on how many rows the wallet + has to show, so waiting for "Developer mode" here fails as soon as the + list grows; callers scroll to the row they want. Landing in one of + Settings' own sub-screens (Payment services, Bank accounts) is treated + as not having arrived, and backed out of. + """ + sub_screen = re.compile( + r"(?i)^(Add payment service|Known bank accounts|No bank accounts saved" + r"|Select tax authority|Alias Type)$" + ) + for _ in range(tries): + self.home() + self.dev.tap_text(r"(?i)^Settings$", timeout=30) + screen = self.dev.wait_for( + r"(?i)Payment services|Developer mode|About|Version|Protect access", + timeout=30, + ) + if not any(sub_screen.match(t.strip()) for t in screen.texts()): + return screen + self.dev.back() + time.sleep(1.5) + return self.dev.dump() + + # -- the one setting the simulator cannot do without ------------------ + + def dev_mode_on(self) -> bool: + screen = self.dev.dump() + return screen.find(DEV_MODE_MARKER) is not None + + def enable_dev_mode(self) -> None: + """Turn developer mode on through the UI. + + MainActivity pushes the persisted flag into MainViewModel on every + start, so a debug build does *not* come up in developer mode however + BuildConfig.DEBUG is set; it has to be switched on here. + """ + self.open_settings() + self.scroll_to_text(DEV_MODE_LABEL) + if self.dev_mode_on(): + self.home() + return + screen = self.dev.dump() + row = screen.find(DEV_MODE_LABEL) + if row is None: + # Scrolling settled differently between the search and the dump. + screen = self.scroll_to_text(DEV_MODE_LABEL) + row = screen.find(DEV_MODE_LABEL) + if row is None: + raise RuntimeError(f"the developer mode row went away; " + f"settings showed: {screen.texts()}") + # Hit the switch at the right-hand end of the row rather than the label, + # which is not itself the clickable node. + _, y = row.center + width = max(n.bounds[2] for n in screen.nodes) + self.dev.tap(width - 100, y) + time.sleep(1.5) + if not self.dev_mode_on(): + # Fall back to the row itself, in case the switch moved. + self.dev.tap_node(row) + time.sleep(1.5) + if not self.dev_mode_on(): + raise RuntimeError(f"could not enable developer mode; " + f"settings showed: {self.dev.dump().texts()}") + self.home() + + # -- entry points ----------------------------------------------------- + + def dismiss_permission_dialog(self) -> bool: + """Answer a runtime-permission dialog if one is in the way.""" + screen = self.dev.dump() + if screen.find(r"(?i)allow .* to take pictures|While using the app") is None: + return False + node = screen.find(r"(?i)While using the app") or screen.find(r"(?i)^Allow$") + if node is None: + return False + self.dev.tap_node(node, screen) + time.sleep(1.5) + return True + + def open_scanner(self) -> Screen: + """Open the QR scan screen, past any permission prompt.""" + self.home() + self.dev.tap_text(r"(?i)^Scan QR code$", timeout=30) + time.sleep(1.5) + self.dismiss_permission_dialog() + return self.dev.wait_for(r"(?i)Scan or enter link|Scan QR", timeout=30) + + def handle_uri(self, uri: str) -> Screen: + """Share a URI into the wallet and return the screen it produced.""" + self.dev.send_uri(uri) + time.sleep(2) + return self.dev.dump() + + def balances(self) -> list[str]: + """Amounts visible on the main screen.""" + import re + screen = self.home() + return [t for t in screen.texts() if re.search(r"\d+[.,]\d\d", t)] diff --git a/wallet-simulator/emu/emu.sh b/wallet-simulator/emu/emu.sh @@ -0,0 +1,208 @@ +#!/bin/bash +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# Emulator lifecycle for the wallet simulator. One AVD per worker; the worker +# index picks both the AVD name and the (even) console port, so several workers +# can run side by side against the same Taler stack. +# +# Usage: +# emu.sh create <worker> create/replace the AVD +# emu.sh boot <worker> boot headless and wait for boot_completed +# emu.sh prepare <worker> <apk> install the wallet, grant permissions, +# kill animations, map the stack ports +# emu.sh reverse <worker> (re)map the stack ports into the emulator +# emu.sh snapshot <worker> <name> save a snapshot +# emu.sh restore <worker> <name> load a snapshot (fast episode reset) +# emu.sh serial <worker> print the adb serial +# emu.sh kill <worker> shut the emulator down + +set -eu + +SIM_ROOT=${SIM_ROOT:-/opt/taler-sim} +export ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT:-/opt/android-sdk} +export ANDROID_HOME=$ANDROID_SDK_ROOT +export ANDROID_AVD_HOME=${ANDROID_AVD_HOME:-$SIM_ROOT/avd} +ADB=$ANDROID_SDK_ROOT/platform-tools/adb +EMULATOR=$ANDROID_SDK_ROOT/emulator/emulator +AVDMANAGER=$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager +IMAGE=${SIM_SYSTEM_IMAGE:-"system-images;android-36;google_apis;x86_64"} +# A PNG to hang on the wall of the emulator's virtual scene, so the camera has +# something real to decode. Only settable at launch, hence one boot per image. +POSTER=${SIM_POSTER:-} +PKG=${SIM_PKG:-net.taler.wallet.fdroid.debug} +BOOT_TIMEOUT=${SIM_BOOT_TIMEOUT:-300} + +die() { echo "emu.sh: $*" >&2; exit 1; } + +worker=${2:-0} +avd_name() { echo "taler-sim-$worker"; } +# The API level the image carries, so the AVD can be tuned per platform. +api_level() { echo "$IMAGE" | sed -n 's/.*android-\([0-9][0-9]*\).*/\1/p'; } +# The virtual scene camera, which is what lets a QR code be shown to the +# device, needs an image that can deliver NV21 frames: below API 26 the camera +# service rejects the format ("Unsupported camera format for virtual scene +# views 825382478" -- that number is the NV21 fourcc) and retries until the +# boot times out. Those levels get the old emulated camera instead, which no +# scenario in the version matrix needs to decode from. +camera_back() { [ "$(api_level)" -ge 26 ] 2>/dev/null && echo virtualscene || echo emulated; } +# An old system image will not boot on a new image's budget. API 24 never +# finished booting with 4 GB of RAM and a 6 GB data partition -- 1200 seconds, +# twice, from a clean start and with the emulated camera, so neither the +# teardown nor the camera was the cause -- and boots in 35 seconds with 2 GB +# and 2 GB. The device profile is not the problem: pixel_6 boots fine at that +# size. Levels below 29 therefore get the smaller budget. +old_image() { [ "$(api_level)" -lt 29 ] 2>/dev/null; } +ram_size() { old_image && echo 2048 || echo 4096; } +heap_size() { old_image && echo 256 || echo 512; } +data_partition() { old_image && echo 2048M || echo 6144M; } +console_port() { echo $((5554 + 2 * worker)); } +serial() { echo "emulator-$(console_port)"; } + +create() { + mkdir -p "$ANDROID_AVD_HOME" + echo no | "$AVDMANAGER" create avd -n "$(avd_name)" -k "$IMAGE" \ + -d pixel_6 --force >/dev/null + local cfg="$ANDROID_AVD_HOME/$(avd_name).avd/config.ini" + python3 - "$cfg" "$(camera_back)" "$(ram_size)" "$(heap_size)" "$(data_partition)" <<'PY' +import sys +path = sys.argv[1] +cfg = {} +for line in open(path): + if '=' in line: + k, v = line.rstrip('\n').split('=', 1) + cfg[k] = v +# A temp data partition would throw away everything on shutdown, which breaks +# snapshots; the rest is headless tuning. +cfg.pop('disk.dataPartition.path', None) +cfg.update({ + 'hw.ramSize': sys.argv[3], + 'vm.heapSize': sys.argv[4], + 'disk.dataPartition.size': sys.argv[5], + 'hw.audioInput': 'no', + 'hw.audioOutput': 'no', + 'hw.camera.back': sys.argv[2], + 'hw.camera.front': 'emulated', + 'hw.keyboard': 'yes', + 'hw.gpu.enabled': 'yes', + 'hw.gpu.mode': 'swiftshader_indirect', + 'hw.lcd.width': '1080', + 'hw.lcd.height': '2400', + 'hw.lcd.density': '420', + 'showDeviceFrame': 'no', +}) +with open(path, 'w') as f: + f.writelines(f'{k}={v}\n' for k, v in sorted(cfg.items())) +PY + echo "created $(avd_name)" +} + +kill_emu() { + local s waited=0 port pid + s=$(serial) + port=$(console_port) + "$ADB" -s "$s" emu kill >/dev/null 2>&1 || true + # Waiting matters: `emu kill` returns as soon as the console accepts it, + # and the next AVD is created with the same name. A process still holding + # that AVD's lock files is why every second level of the version matrix + # failed to boot -- 26 ok, 28 failed, 29 ok, 30 failed, and so on. + while [ "$waited" -lt 90 ]; do + "$ADB" devices 2>/dev/null | grep -q "^$s" || break + sleep 2 + waited=$((waited + 2)) + done + for _ in $(seq 1 30); do + pid=$(pgrep -f -- "-port $port" | head -1) + [ -n "$pid" ] || break + kill "$pid" 2>/dev/null || true + sleep 2 + done + rm -f "$ANDROID_AVD_HOME/$(avd_name).avd"/*.lock 2>/dev/null || true + echo "killed $s after ${waited}s" +} + +boot() { + local log="$SIM_ROOT/run/emu-$worker.log" + mkdir -p "$SIM_ROOT/run" + "$ADB" start-server >/dev/null 2>&1 || true + local camera="$(camera_back)" + local poster_args=() + if [ -n "$POSTER" ] && [ "$camera" = virtualscene ]; then + [ -r "$POSTER" ] || die "no poster image at $POSTER" + poster_args=(-virtualscene-poster "wall=$POSTER") + fi + local wipe_args=() + [ "${SIM_KEEP_DATA:-0}" = "1" ] || wipe_args=(-wipe-data) + setsid "$EMULATOR" -avd "$(avd_name)" -port "$(console_port)" \ + -no-window -no-audio -no-boot-anim -gpu swiftshader_indirect \ + -no-snapshot-load -no-snapshot-save "${wipe_args[@]}" \ + -camera-back "$camera" "${poster_args[@]}" \ + > "$log" 2>&1 < /dev/null & + echo "booting $(avd_name) on $(serial), log $log" >&2 + local waited=0 + while [ "$waited" -lt "$BOOT_TIMEOUT" ]; do + if [ "$("$ADB" -s "$(serial)" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r\n')" = "1" ]; then + echo "booted after ${waited}s" + return 0 + fi + sleep 2 + waited=$((waited + 2)) + done + tail -20 "$log" >&2 || true + die "emulator did not finish booting within ${BOOT_TIMEOUT}s" +} + +reverse() { + local s env_json p + s=$(serial) + env_json=${SIM_RUN:-$SIM_ROOT/run/stack}/env.json + [ -r "$env_json" ] || die "no $env_json; start the stack first" + for p in $(python3 -c 'import json,sys; print(" ".join(str(p) for p in json.load(open(sys.argv[1]))["ports"]))' "$env_json"); do + "$ADB" -s "$s" reverse "tcp:$p" "tcp:$p" >/dev/null + done + echo "mapped stack ports into $s" +} + +prepare() { + local s apk + s=$(serial) + apk=${3:-$SIM_ROOT/apk/wallet.apk} + [ -r "$apk" ] || die "no APK at $apk" + # Deterministic, animation-free UI: the driver reads the view hierarchy and + # animations make it race. + "$ADB" -s "$s" shell settings put global window_animation_scale 0 + "$ADB" -s "$s" shell settings put global transition_animation_scale 0 + "$ADB" -s "$s" shell settings put global animator_duration_scale 0 + "$ADB" -s "$s" shell settings put secure long_press_timeout 250 + "$ADB" -s "$s" shell svc power stayon true + # Leave the device in portrait: user_rotation survives app data wipes. + "$ADB" -s "$s" shell settings put system accelerometer_rotation 0 + "$ADB" -s "$s" shell settings put system user_rotation 0 + "$ADB" -s "$s" install -r -g "$apk" + "$ADB" -s "$s" shell pm grant "$PKG" android.permission.CAMERA 2>/dev/null || true + reverse + echo "prepared $s with $apk" +} + +case "${1:-}" in + create) create ;; + boot) boot ;; + prepare) prepare "$@" ;; + reverse) reverse ;; + snapshot) "$ADB" -s "$(serial)" emu avd snapshot save "${3:-clean}" ;; + restore) "$ADB" -s "$(serial)" emu avd snapshot load "${3:-clean}" ;; + serial) serial ;; + kill) kill_emu ;; + *) die "usage: emu.sh create|boot|prepare|reverse|snapshot|restore|serial|kill <worker> [arg]" ;; +esac diff --git a/wallet-simulator/emu/tls-names.sh b/wallet-simulator/emu/tls-names.sh @@ -0,0 +1,89 @@ +#!/bin/bash +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +# +# Make one emulator resolve the hostnames the wallet hard-codes to the TLS +# front end on the host. +# +# The wallet hard-codes https://taldir.gnunet.org (see +# findings/alias-registration-hardcodes-the-directory.md) and defaults to +# https://mailbox.gnunet.org, so the only way to exercise those code paths as +# they ship is to answer for the names. The URLs under test are not touched. +# +# The simulator's CA is trusted because the "sim" build type bundles it as a +# trust anchor (wallet/src/sim/res/xml/network_security_config.xml), not by +# anything done here. Installing it into the device's own store instead is a +# dead end worth recording: both system stores have to be replaced by a tmpfs +# from inside init's mount namespace (an APEX mount made from adbd is invisible +# to apps, which shows up as "tls: unknown certificate" in the proxy log while +# everything else looks right), and the framework restart that is then needed +# to make zygote see them leaves the network at PARTIAL_CONNECTIVITY for a +# while -- during which the wallet refuses to do anything with "This action +# requires internet connection". +# +# Usage: tls-names.sh <worker> +# +# Needs the TLS front end running on the host (tls/tlsproxy, port 8443) and is +# undone by a `wipe`/reboot of the emulator, so it has to be re-run after one. + +set -eu + +SIM_ROOT=${SIM_ROOT:-/opt/taler-sim} +export ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT:-/opt/android-sdk} +ADB=$ANDROID_SDK_ROOT/platform-tools/adb +WORKER=${1:?usage: tls-names.sh <worker>} +SERIAL=emulator-$((5554 + 2 * WORKER)) +HOSTS_ENTRY="127.0.0.1 taldir.gnunet.org mailbox.gnunet.org" +PROXY_PORT=${SIM_TLS_PORT:-8443} + +say() { printf 'tls-names %s: %s\n' "$SERIAL" "$*" >&2; } + +# 1. A privileged listening port on the device needs a root adbd. Restarting +# adbd takes every `adb reverse` mapping with it, so the stack's ports have +# to be put back afterwards or the wallet loses the exchange -- and a wallet +# that cannot reach the exchange reproduces unrelated findings very +# convincingly. +if [ "$("$ADB" -s "$SERIAL" shell id -u | tr -d '\r\n')" = 0 ]; then + say "adbd is already root" +else + "$ADB" -s "$SERIAL" root >/dev/null 2>&1 || true + sleep 4 + "$ADB" -s "$SERIAL" wait-for-device + "$(dirname "$0")/emu.sh" reverse "$WORKER" >/dev/null 2>&1 || + say "WARNING: could not restore the stack's port mappings" + say "rooted, stack ports restored" +fi + +# 2. The name has to resolve to the device's own loopback, where the reverse +# mapping is listening. /system is read-only on these images and `adb +# remount` does not help (no overlay), so the file is replaced by a bind +# mount rather than edited -- a mount needs no write access to /system. +if "$ADB" -s "$SERIAL" shell "grep -q taldir.gnunet.org /system/etc/hosts" 2>/dev/null; then + say "hosts entry already there" +else + "$ADB" -s "$SERIAL" shell " +set -e +cp /system/etc/hosts /data/local/tmp/hosts +echo '$HOSTS_ENTRY' >> /data/local/tmp/hosts +chmod 644 /data/local/tmp/hosts +chcon u:object_r:system_file:s0 /data/local/tmp/hosts 2>/dev/null || true +mount --bind /data/local/tmp/hosts /system/etc/hosts +grep taldir /system/etc/hosts +" >/dev/null || { say "could not bind a hosts file over /system/etc/hosts"; exit 1; } + say "hosts entry bind-mounted" +fi + +# 3. Port 443 on the device forwards to the host's TLS front end. +"$ADB" -s "$SERIAL" reverse "tcp:443" "tcp:$PROXY_PORT" >/dev/null +say "device port 443 -> host $PROXY_PORT; done" diff --git a/wallet-simulator/findings/CAMPAIGN.md b/wallet-simulator/findings/CAMPAIGN.md @@ -0,0 +1,2007 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Simulator campaign log + +Every finding here has three things: what happens, how to reproduce it by hand +on a device, and a `repro_*.py` beside it that reproduces it against the +simulator. To run one: + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_zero_deposit.py # worker 0 by default +python3 ../findings/repro_zero_deposit.py emulator-5562 +``` + +Each exits 0 when the defect is present and prints the evidence it checked, so +they double as regression tests once a fix lands. + +## Findings so far + +| Finding | Severity | How it was found | +| --- | --- | --- | +| [`addglobalcurrencyexchange-null-masterpub.md`](addglobalcurrencyexchange-null-masterpub.md) — "Treat as global" sends a request with no `exchangeMasterPub`, so wallet-core answers `WALLET_UNEXPECTED_EXCEPTION` and nothing happens | low-moderate (developer mode only) | random exploration, seed 11 | +| [`action-buttons-have-no-accessible-name.md`](action-buttons-have-no-accessible-name.md) — none of the main screen's seven action buttons has an accessible name; TalkBack cannot announce them | moderate (release builds) | the driver could not tap them | +| [`mailbox-private-keys-written-to-log.md`](mailbox-private-keys-written-to-log.md) — both mailbox private keys are logged every 30 s, where the app's own log export picks them up | moderate | an oracle false positive led to the line | +| [`word-currency-symbol-glued-to-amount.md`](word-currency-symbol-glued-to-amount.md) — amounts render as `UNKNOWN0.00` and `Total: EUR1.00` when the currency symbol is a word | low (cosmetic) | QR scan of an order that does not exist | +| [`delete-transaction-requeries-deleted-id.md`](delete-transaction-requeries-deleted-id.md) — deleting a transaction makes the app ask wallet-core for it again | low | the `history_delete` scenario, twice | +| [`error-code-registry-behind-wallet-core.md`](error-code-registry-behind-wallet-core.md) — the app's registry is 26 wallet codes behind the wallet-core it ships; two were hit in normal runs | low | tallying error replies across all logs | +| [`dev-experiment-uri-exits-the-app.md`](dev-experiment-uri-exits-the-app.md) — an unknown `dev-experiment` URI logs an internal error and drops the user on the home screen | low (developer mode only) | the `uri_dev_experiment` scenario | +| [`add-payment-service-fails-silently.md`](add-payment-service-fails-silently.md) — every payment-service failure is silent: `ExchangeManager` publishes four error channels and nothing reads any of them | moderate | the `exchange_url_fuzz` scenario | +| [`deposit-does-not-guard-zero-amounts.md`](deposit-does-not-guard-zero-amounts.md) — clearing the deposit amount raises `WALLET_UNEXPECTED_EXCEPTION`, and depositing at or below the fee stores a zero-value deposit | low-moderate | the `deposit_flow` scenario | +| [`unreachable-host-leaves-blank-retrying-purchase.md`](unreachable-host-leaves-blank-retrying-purchase.md) — a prompt the app cannot prepare is an empty screen: eleven different exchange faults produce the same blank "Withdraw UNKNOWN", and it does not recover when the fault stops | moderate | random exploration, then fault injection | +| [`refresh-fails-on-mixed-age-denominations.md`](refresh-fails-on-mixed-age-denominations.md) — on an exchange offering age-restricted and ordinary denominations, the exchange rejects the melt and the change is never recovered; fixed upstream after the shipped wallet-core was built | high where it applies | the `refund` scenario, once age restriction was enabled | +| [`bitcoin-transfer-relabels-the-amount-as-btc.md`](bitcoin-transfer-relabels-the-amount-as-btc.md) — the Bitcoin wire instructions say "5.00 BTC" for a withdrawal of EUR 5.00, in the screen and on the clipboard | low | the `withdraw_account_tabs` scenario, once a Bitcoin account was signed | +| [`mailbox-payment-only-actionable-for-one-scheme.md`](mailbox-payment-only-actionable-for-one-scheme.md) — a payment received by mailbox shows an "Accept payment" button only for a literal `taler://` prefix; the developer-mode and extension schemes become a bare string | low-moderate | the `mailbox_roundtrip` scenario | +| [`taldir-protocol-version-mismatch.md`](taldir-protocol-version-mismatch.md) — the directory advertises protocol `0:0:0`, wallet-core's client requires `1:0:0` and refuses, and the precise reason is replaced by "could not read the configuration" | low-moderate | deploying a real taldir | +| [`alias-registration-hardcodes-the-directory.md`](alias-registration-hardcodes-the-directory.md) — the Taler directory URL is a literal in two files, so alias registration and contact lookup can only ever talk to `taldir.gnunet.org` | low | trying to cover the `contacts` package | +| [`amounts-without-currency-specification.md`](amounts-without-currency-specification.md) — the wire transfer instructions read "transfer 5.00 EUR … to receive €4.88", and the incoming peer-payment prompt shows "Total: 1.00 EUR" | low | the `withdraw_account_tabs` and `peer_push_receive` scenarios | +| [`release-error-screen-explains-nothing.md`](release-error-screen-explains-nothing.md) — with developer mode off, an error whose explanation is in `detail` rather than `hint` shows only the word "Error" | moderate (release builds) | the `error_screen_without_dev_mode` scenario | +| [`a-failed-query-is-shown-as-an-empty-wallet.md`](a-failed-query-is-shown-as-an-empty-wallet.md) — a failed `getDepositWireTypes` is shown as "No bank accounts saved", a failed `getMaxPeerPushDebitAmount` as "€0.00" to send; four of ten screens report nothing | moderate | the `api_error_sweep` scenario | +| [`wallet-lock-opens-when-the-credential-is-gone.md`](wallet-lock-opens-when-the-credential-is-gone.md) — once the device credential is removed, "Protect access to wallet" still shows its lock screen but opens on one tap with no authentication | moderate (security, release builds) | the `wallet_lock_without_credential` scenario | +| [`unknown-wire-method-hangs-the-deposit-form.md`](unknown-wire-method-hangs-the-deposit-form.md) — an exchange advertising a wire method the app does not know makes the whole reply undecodable and the add-account form spin for ever; three enums carry an `Unknown` member that can never be used | moderate | the `deposit_methods` scenario, once a Cyclos address was signed | +| [`purge-destroys-coins-and-history-without-saying-so.md`](purge-destroys-coins-and-history-without-saying-so.md) — "Force deletion (purge)" removes the balance and every transaction with the payment service, from a dialog that is a title, a checkbox and two buttons | moderate | the `history_after_forgetting_exchange` scenario | +| [`suspended-looks-like-completed-in-the-list.md`](suspended-looks-like-completed-in-the-list.md) — the transaction list has no branch for `Suspended`, so a suspended withdrawal's row says "Waiting for confirmation" instead | low-moderate | the `transaction_states_rendered` and `withdraw_suspend_resume` scenarios | +| [`aborted-credit-shows-the-whole-amount-as-fee.md`](aborted-credit-shows-the-whole-amount-as-fee.md) — an aborted withdrawal reads "Chosen amount €5.00 / Fee −€5.00 / Total amount €0.00"; the same arithmetic is on three further credit screens | low-moderate | a note of the `abort_then_retry` scenario | +| [`pos-confirmation-shows-five-codes.md`](pos-confirmation-shows-five-codes.md) — "Confirmation code" prints every T-OTP code in the valid time range, with nothing to say which one to read out | low | the `payment_pos_confirmation` scenario | + +Each one has a manual reproduction and, where there is something to run, a +`repro_*.py` script beside it. Three are established by reading rather than +running — the hard-coded directory URL, the error-code registry and the +fault-injection half of the blank-prompt finding — and each says which command +shows it. + +One entry per iteration: what was run, what the coverage was afterwards, what +it found, and what the next iteration aims at. Coverage is JaCoCo line coverage +of the `wallet` module (the Kotlin shell only — wallet-core is TypeScript inside +QuickJS and is not instrumentable through qtart). + +## Iteration 1 — baseline (random exploration only) + +Ran `smoke_withdraw`, `smoke_pay` and two `explore.py` runs (80 and 100 steps). + +* **Coverage: 33.9 %** line (5855/17247), 22.3 % branch, 35.8 % class. +* Findings: one confirmed defect, `addglobalcurrencyexchange-null-masterpub.md` + (`WALLET_UNEXPECTED_EXCEPTION` from "Treat as global"). Everything else the + oracles flagged was a correct refusal. +* Gaps, by missed lines: `peer` 0.9 % covered, `deposit` 0.8 %, `accounts` + 1.3 %, `transfer` 0.0 %, `tokens` 1.1 %, `donau` 3.4 %, `mailbox` 20.2 %, + `payment` 27.4 %, `exchanges` 27.8 %, `transactions` 45.4 %. + +Random exploration reaches the screens that are one tap from the main screen and +stops there: everything behind an amount field or a multi-step form stayed +untouched. Hence the scenario suite. + +## Iteration 2 — feature scenarios + +`suite.py` with 33 scenarios covering the flows named in the campaign brief: +transaction history and detail views, deleting transactions, aborting, +suspending and resuming, suspending and aborting, abandoning, adding and +removing exchanges, terms-of-service accept/reject, every settings row and +switch, the scan screen's manual entry, deposits, peer send/request in both +directions, manual withdrawal with wire-transfer details, tokens, donau and +contacts. + +Ran 33 scenarios across 4 emulators on tripwire (one bank customer and one +CLI peer wallet per worker, all against one Taler stack). + +* **Coverage: 40.8 %** line (7043/17247), up from 33.9 %; class 44.7 %, + branch 27.5 %. +* 23 of 33 scenarios passed. The 10 failures were all harness faults, not + wallet faults, and each one taught the driver something: + * a helper lost in an edit (`open_exchange_list`) — restored; + * `taler-wallet-cli` needs a `.sqlite3` database ("memory backend not + supported") and cannot fund itself with `withdraw --exchange`, which + creates a *manual* withdrawal nobody completes — the peer wallet now goes + through the bank like the app, with a bank customer of its own; + * bank accounts ran out of money mid-run ("Insufficient funds to withdraw + with Taler") — provisioning now tops every account up past EUR:100; + * **tapping a label did nothing** for the main screen's Send / Request / + Withdraw / Deposit buttons, because the clickable element is an unnamed + `Button` *above* the text. `Screen.tap_target()` now resolves a label to + the clickable node that contains it or sits next to it. +* Findings: the tap problem turned out to be a defect in the app, not just in + the driver — see `action-buttons-have-no-accessible-name.md`. The oracles + flagged nothing else: no crash, no internal error, no stuck operation, and + the new database oracles (`operation_retries`, unfinished operations) were + quiet throughout. +* New oracles this iteration: background failures and stuck operations read + out of the wallet's own SQLite database (`dbprobe.py`), which sees errors the + UI never shows. + +## Iteration 3 — the same scenarios with a working driver, plus 17 new ones + +50 scenarios: everything from iteration 2 (10 of which never really ran), plus +selection-mode bulk delete, transaction filters, mailbox, contacts, the +`add-contact` and `dev-experiment` URIs, order templates, expired and deleted +orders, change (refresh) transactions, and a batch of adversarial sequences — +suspend/kill/relaunch/resume, abort-then-reuse-the-URI, hostile amounts in the +deposit and peer fields, airplane mode mid-withdrawal, two pay URIs at once, +force-purging an exchange that still holds coins, and rejecting the terms of +service mid-withdrawal. + +Ran 60 scenarios across 4 emulators; 55 passed, and the 5 that did not were +harness faults (all since fixed: the CLI peer could not fund itself, the +Mailbox row needed scrolling in both directions, and `withdraw_manual` needs a +wallet that already knows the exchange). + +* **Coverage: 56.5 %** line (9743/17247), up from 40.8 %; class 60.9 %, branch + 44.8 %. +* **wallet-core operations exercised: 44/71 (62 %)**, up from 26/71. What is + left is mostly features that need services this stack does not run (Taldir + alias registration, the GNUnet mailbox) plus the database export/import + pickers. +* Newly reached, from 0 %: token issuance and the Discounts screen (a v1 + contract with a token output), contract choices, the deposit account forms, + the donau setup screen, performance stats, and the bank-account manager. +* Findings: the two written up above, plus repeats of the known ones. Two + `silent-failure` reports were false positives from background log chatter, + which is why that oracle now only counts wallet-core error replies. + +## Verified good behaviour + +Negative results worth recording, because each was a plausible place for a +crash and is not one: + +* **A corrupted wallet database is handled.** Overwriting the SQLite header and + restarting shows "An error occurred while starting the wallet … Please retry, + and if the problem persists, export the …" — no crash, and the wallet works + again after a wipe (`db_corruption`). +* **Suspend survives process death.** Suspending a withdrawal, killing the app + and reopening it leaves the transaction suspended and still offering *Resume* + (`lifecycle_kill`). +* **A withdrawal survives losing the network.** Turning on airplane mode + mid-withdrawal and turning it off again lets the transaction finish without + intervention (`offline_withdraw`). +* **Invalid QR codes are refused cleanly.** All ten payloads in the QR suite — + malformed base32, unknown actions, a plain https URL, free text — produce an + explained refusal rather than silence or a crash. +* **Paying the same order twice** shows the completed transaction rather than + charging again (`payment_twice`). +* **A transaction the app cannot parse is handled.** `TransactionSerializer` + falls back to a `DummyTransaction` when deserialization throws, and nothing + had ever given it one. Fed a type that does not exist + (`interpretive-dance`) and a withdrawal with no amounts, the list renders + both as "Unknown transaction" with a zero amount and stays usable -- no + crash, no blank row (`transaction_states_rendered`). +* **A database export can be restored.** The export/import round trip brings a + wiped wallet back to its balance and its transactions + (`settings_import`). This one took three attempts to establish, all of + them harness error; see the near-miss above. +* **Tap-to-pay works, and refuses what it should.** An order delivered as an + NDEF record is paid like any other, and a tag carrying a plain website, a + bare `taler+http://pay/` or a non-existent order each produce their own + explained error (`nfc_tap_to_pay`). +* **KYC works end to end.** On the KYC stack a withdrawal above the threshold + shows "KYC required, preparing challenge", then "This transaction would + exceed a limit set by the payment service. To increase the limit, follow the + instructions linked below."; the call to action hands off to the exchange's + KYC page in Chrome, and coming back to the wallet shows the explanation + again. No internal errors anywhere in that path. +* **The app has not crashed once.** Across every round, scenario and + exploration step, no `FATAL EXCEPTION` belongs to `net.taler.wallet`. The + ones in the logs are `uiautomator dump` colliding with itself, which is the + driver's problem — the oracle now says so rather than reporting a wallet + crash. + +## Iteration 4 and onward — unattended rounds + +`driver/forever.sh` runs continuously: provision (topping up the bank), all 65 +scenarios across 4 emulators, then a random-exploration pass with a fresh seed +each round, dumping coverage after each phase and appending one line per round +to `run/rounds.log`. Round 4 started at 23:24. + +### Where the numbers stand + +| After | Line coverage | wallet-core operations | +| --- | --- | --- | +| random exploration only | 33.9 % | 26/71 (37 %) | +| iteration 2 (first scenario pass) | 40.8 % | — | +| iteration 3 (working driver) | 56.5 % | 44/71 (62 %) | +| round 4 | 61.2 % | 48/71 (68 %) | + +The 23 operations still unexercised are mostly features with no service behind +them here: Taldir alias registration (`registerAlias`, `lookupAlias`, +`completeRegisterAlias`, `addContact`, `deleteContact`) and GNUnet mailbox +messaging (`addMailboxMessage`, `sendTalerUriMailboxMessage`, +`deleteMailboxMessage`). The rest — the database import/reset pickers, +`failTransaction`, `cancelProgressToken`, the donau statements and the +incoming-peer-payment pair — are covered by scenarios added for round 5. + +### What the stack gained + +Round 4 ended with a config swap that unlocked two feature areas the wallet +could not reach before: + +* a **second exchange account in IBAN form**, so the manual withdrawal offers + an account picker and the IBAN transfer screens; +* **age-restricted denominations**, so the withdrawal screen offers "Restrict + usage to age" (8, 10, 12, 14, 16, 18) — exercised end to end. + +Neither happens by itself: `taler-unified-setup.sh` enables only the account +given with `-u`, and age restriction needs `AGE_RESTRICTION_ENABLED` in the +`[exchange]` section on top of the age-restricted denominations. + +### Round 5 + +75 scenarios; 49 ran, and 26 failed on one shared cause: the bank accounts ran +dry. A fresh account holds exactly the EUR:100 registration bonus, the +provisioning top-up only triggered *below* EUR:100, and a round of 75 +scenarios spends far more. Accounts are now kept at EUR:2000 and a refused +withdrawal tops up and retries, so the whole class is gone. + +No new defects. What the round did show is that the oracles now catch by +themselves what used to take noticing by hand: the screen-sanity oracle +flagged `UNKNOWN0.00` on the main screen without anyone looking for it, and the +`expects` declarations kept the deliberate failures (a corrupted database, a +dead exchange) out of the serious column. + +### Rounds 6 to 10, the KYC pass, and two fault-injection phases + +Rounds kept running unattended; `phase.sh` can now pause them, swap the stack +for a variant, run a named set of scenarios and put everything back. + +* **KYC pass** (`sim-kyc.conf`, a FORM check with a EUR:5 withdraw threshold): + the hand-off works — the withdrawal reports "KYC required, preparing + challenge", the action opens the KYC page in Chrome, and coming back shows + "This transaction would exceed a limit set by the payment service". The one + serious finding of that phase was a withdrawal "retried 4 times", which is + the ordinary scenarios doing a plain EUR:10 withdrawal on a stack that + demands identification above EUR:5 — correct behaviour, not a defect. +* **Fault injection**, twice, and both runs measured nothing: + 1. the first because the bank still suggested the direct exchange URL while + the wallet was configured for the proxy, so every withdrawal was refused + with `WALLET_EXCHANGE_BASE_URL_MISMATCH` before a fault could matter + (`SUGGESTED_WITHDRAWAL_EXCHANGE` now points at the proxy); + 2. the second because **a twister fault is one-shot**. Arming it and then + starting a withdrawal spends it on whichever poll happens to come first, + which is why all seven fault types produced an untouched withdrawal + prompt and a withdrawal that then completed normally. `Twister.armed()` + re-arms in the background for as long as the step runs, and the field + faults now name real paths (`denominations.0.denoms.0.master_sig`, not + `denoms`, which matched nothing and said so in twister's log). + +### Iteration 5 — what one exchange and one wire method were hiding + +Two configuration facts, not scenarios, were holding coverage down: + +* `taler-unified-setup.sh` uploads a wire fee only for the method it was told + about, and **wallet-core hides every exchange account whose method has no + fee**. The IBAN account had been enabled since round 4 and was still + invisible: `/keys` listed it under `accounts` but `wire_fees` had only + `x-taler-bank`. One `taler-exchange-offline wire-fee now iban …` made the + account picker, the IBAN transfer screen (0 % → 61 %), the IBAN deposit form + (0 % → 95 %) and the EPC QR card appear. +* With **one** payment service every "which one?" step picks the only + candidate, so the exchange picker, "treat as global" and the balance scopes a + second service creates were unreachable. `backend/exchange2.sh` now starts a + second, independent exchange (own port, database, offline key, secmod + sockets, bank account at the shared libeufin) beside the stack in 11 s. + +Also fixed: the peer wallet could not be funded at all — +`taler-wallet-cli wait-tx --state pending` returns immediately, because the +transaction is already pending, so no task ever ran. Waiting for +`pending/idle` is the pump; all four peer scenarios pass now where they used +to be driver errors. + +* **Coverage: 66.0 %** line (11390/17247), up from 61.2 %; branch 53.8 %, + class 70.2 %. +* New scenarios: `withdraw_account_tabs` (one transfer screen per wire + method), `payment_pos_confirmation` (an order tied to a merchant OTP + device — the only way to reach the TOTP screen), `exchange_two_services`, + `withdraw_pick_exchange`, `balances_two_exchanges`. +* New findings: the hard-coded directory URL, the two amount notations in one + sentence, and the five confirmation codes. + +## Iteration 6 — fault injection that lands, and three more defects + +### Fault injection, third attempt + +With `Twister.armed()` re-arming in the background, every fault finally hit +the request it was aimed at (the notes record 64 to 116 re-arms per step): + +* **Payments survive transport faults.** A truncated reply, 500, 404, 403, + 502 or the wrong content type leaves the purchase pending and the merchant + saying "claimed"; when the fault stops, the wallet retries and the merchant + says "paid". Two of three faulted payments recovered on their own within the + measurement window, and the third had run the wallet out of coins — the + scenario now withdraws EUR:20 first and waits 90 s for the recovery, so the + distinction is recorded rather than guessed. +* **Withdrawals do not.** Eleven ways of breaking `/keys` — truncation, five + status codes, the wrong content type, a deleted denomination list, a flipped + master public key, a forged denomination signature, missing wire fees, an + impossible protocol version — all produce the *same* screen, + `['Go back', 'Withdraw UNKNOWN', 'Internal event log']`, and it stays that + way after the fault is removed. That went into + `unreachable-host-leaves-blank-retrying-purchase.md`, which is no longer + about unreachable hosts: it is about a prompt with no error state. + +### Three defects, from three different directions + +* **An aborted withdrawal says the whole amount went to fees** — found by + reading a scenario's notes, now caught by an oracle + (`fee-on-dead-transaction`), and shared by all four credit screens. +* **The wallet lock opens with no credential** — found by asking what happens + when the thing a security feature depends on goes away. The overlay still + appears and a single tap opens the wallet. +* **The point-of-sale confirmation shows five codes** — found by reaching + `PayTotpComposable` for the first time, which needed a merchant OTP device. + +### What the operation counter kept pointing at + +Measuring which wallet-core operations the campaign had *never* reached found +three driver bugs that each hid a feature: + +* `addBankAccount`, `forgetBankAccount` and `getBankAccountById` had never + run, because the form's submit button carries the same string as the app bar + title ("Add account"), the label search found the title, and the neighbour + search then switched tabs instead. `Ctx.tap_button` takes the lowest + matching node that is clickable and contains the label. +* `setDonau` had never run, because the tax payer ID was being typed into the + authority URL field and Save stays disabled until both are filled. +* `addContact` and `deleteContact` had no scenario at all. + +Still out of reach: the directory operations (`registerAlias`, +`completeRegisterAlias`, `lookupAlias`) behind the hard-coded URL, the mailbox +operations with no mailbox service in this stack, and `importDb` / `clearDb`. + +### New: failing a wallet-core call from the outside + +wallet-core takes `taler://dev-experiment/api-error?operation=…&detail=…`, +where the detail is base64url JSON with an error code, and fails that +operation that many times. `api_error_sweep` uses it to make each screen's own +call fail — balances, transactions, exchanges, contacts, bank accounts, +deposit wire types, withdrawal details, peer limits, discounts, donau — and +reports which screens then say nothing. It needs no proxy and no stack +variant, which makes it the cheapest way to hunt for the silent-failure class +that `add-payment-service-fails-silently.md` is one instance of. + +## Iteration 7 — failing wallet-core from the outside + +The sharpest tool so far turned out not to be a proxy at all. wallet-core +accepts two developer-mode URIs: + +``` +dev-experiment/api-error?operation=<op>&detail=<base64url JSON>&count=<n> +dev-experiment/api-response?operation=<op>&response=<base64url JSON>&count=<n> +``` + +the first failing a named operation `n` times with a given error, the second +answering it with a canned reply. No stack variant, no proxy, no restart. + +`api_error_sweep` makes one operation fail per screen and reads what the screen +then says. Thirteen operations in, the split is clean: **six screens report the +failure** (balances, transactions, bank accounts, discounts, passes, terms of +service — an `ErrorComposable` with the code and an export affordance) and +**seven say nothing**. Three of the seven state the failure as a fact about the +user: "No bank accounts saved in the wallet", "No contacts yet.", and a Send +screen offering "€0.00" on a wallet holding €9.87. That is +`a-failed-query-is-shown-as-an-empty-wallet.md`, and it also reproduced the +blank withdrawal prompt from a single injected error — no twister needed. + +`error_screen_without_dev_mode` then asked what a *release* build shows, by +turning developer mode off after queueing the error. Everything in this +campaign runs in developer mode, where the error screen prints the whole error +as JSON; without it the explanation is `userFacingMsg`, the hint and the +message concatenated, and an error carrying neither renders as the word +"Error" and two export buttons. wallet-core puts a bad request's reason in +`detail`, which the app keeps but never shows: +`release-error-screen-explains-nothing.md`. + +Both defects are now oracles — `absence-after-error` (an empty state claimed +while the query behind it was failing) and `mixed-amount-notation` — so the +next round catches the class rather than the instance. + +### Two more screens reached by signing an address + +The wallet picks a transfer screen purely from the payto method, so signing an +address at the exchange is enough to render it. A `payto://bitcoin/…` address +brought up the segwit instructions — and with them a defect: the amount is +relabelled, not converted, so a EUR 5.00 withdrawal reads "5.00 BTC" on the +screen and on the clipboard (`bitcoin-transfer-relabels-the-amount-as-btc.md`). +A `payto://cyclos/…` address covers the fourth and last transfer screen. + +### Scenarios added this iteration + +`api_error_sweep`, `api_response_hostile` (a balance of €999,999,999,999.99 +renders correctly, with grouping separators), `error_screen_without_dev_mode`, +`denom_loss_transaction` (the loss-of-funds transaction, which no stack can +produce), `exchange_turns_hostile` (the exchange's protocol version and master +key change under the wallet), `peer_push_abandon` (the only reachable path to +`failTransaction`: "Abandon" is offered on deposits and outgoing peer +payments, never on withdrawals), `contacts_add_and_forget`, +`wallet_lock_without_credential`, `revoke_denomination`. Ninety-one in total. + +Three scenarios had been passing every round without recording a single +observation, which is indistinguishable from doing nothing; they now say what +they saw. And the random exploration had **never run in any round** — the +STOP file a queued phase sets breaks the loop before it, so it now runs first. + +## Iteration 8 — 69.7 %, and what a config change found + +* **Coverage: 69.7 %** line (12018/17247), up from 66.0 %; branch 57.6 %, + class 73.9 %. The start of the campaign was 33.9 %. +* What is left is mostly out of reach rather than untried: about 190 lines have + **no caller at all** (`PromptAddContactScreen`, `GridMenu`, + `DemandAttention`, `SelectExchangeDialogFragment`, and + `SelectionModeTopAppBar` — the transaction list implements selection mode + inline instead), and another ~350 need a + service this stack has not got (the GNUnet mailbox, donau statements, the + Taler directory). +* The app's *sending* side of the mailbox (`sendTalerUriMailboxMessage`) looked + dead and is not — see iteration 10. It hangs off a developer-mode-only button + labelled "Contacts" on a peer-push QR screen, which is why no scenario had + found it. +* The measurement itself was losing data: coverage accumulates in the app + process, so every scenario that wiped the app mid-run threw away what it had + exercised — `WalletInitErrorScreen` read 0 % although `db_corruption` + renders it, word for word. `fresh_start` now dumps first. + +### A signed address found a real defect + +Signing a `payto://cyclos/…` account — done to reach the last transfer screen +— broke the **deposit** form in the next round: + +``` +E taler-wallet: Error getDepositWireTypes TalerErrorInfo(code=NONE, hint=, + message=kotlinx.serialization.SerializationException: + net.taler.wallet.deposit.WireType does not contain element with name 'cyclos') +``` + +One unrecognised wire method makes the whole reply undecodable, so the +add-account form sits on its spinner for ever with no message. `WireType` has +an `Unknown` member for exactly this case and it can never fire, because the +property that decodes into it has no default value and `coerceInputValues` +only coerces to a declared default. Two more enums have the same shape +(`WithdrawalOperationStatusFlag`, `ExchangeTosStatus`). + +The Cyclos address is therefore opt-in: leaving it signed blocks every deposit +scenario. `findings/unknown-wire-method-hangs-the-deposit-form.md` has the +one-line reproduction. + +### Random exploration, now that it runs in a round + +48 finding lines on its first in-round run, and **19 of them were about +Chrome**: a tap had opened a browser (a KYC link, "Open in banking app") and a +random walk has no reason to come back, so the oracles spent the run reading +Chrome's search suggestions ("undefined behavior", "undefined label") and +tapping its settings. The screen oracles now only apply to the app's own +screens, `silent_failure` likewise, and the explorer notices it has left and +relaunches. + +### Three more defects + +* **`purge-destroys-coins-and-history-without-saying-so.md`** — "Force + deletion (purge)" destroyed €9.87, the payment service and every transaction + made with it, leaving the first-run welcome screen. The dialog is a title, a + checkbox and two buttons, with no body text at all. +* **`suspended-looks-like-completed-in-the-list.md`** — the transaction list + has no branch for `Suspended`, so a suspended withdrawal's row reads + "Waiting for confirmation" — the opposite of what is happening. +* **`unknown-wire-method-hangs-the-deposit-form.md`**, above. + +And `failTransaction` is now pinned down rather than guessed at: wallet-core +offers "Abandon" only for deposits that are aborting, suspended-aborting or +waiting on aggregate KYC (`deposits.ts:955-1000`), none of which this stack +produces, because the aggregator finalises a deposit at once. A withdrawal +never offers it; an outgoing peer payment offers Retry/Abort/Suspend while +live and Resume/Abort once suspended. + +## Iteration 9 — the two services the stack was missing + +`taler-unified-setup.sh` brings up the exchange, merchant, bank, donau and +auditor. The wallet has screens for two more services, and both are now +deployed beside the stack (`backend/services/README.md`): the **Taler +mailbox** (`git://git.taler.net/taler-mailbox`, port 11000) and the **Taler +directory** (`git://git.taler.net/taldir`, port 11001), each Go, each with its +own Postgres database, both outliving a stack restart. + +`sync` was deliberately *not* deployed: the Android wallet has no backup or +sync feature — no screens, and no backup operation in +`coverage/app-operations.txt` — so there would be nothing to drive. + +### The mailbox pays off directly + +Its URL is the one service address the app lets the user type in, so no DNS or +TLS work was needed. The wallet registers itself on first use and shows its own +address: + +``` +http://localhost:11000/V8K0FT9X8DP44T4SW7VK40XVNJPGTMNFQB24GC34DFP7VNNBG70… +``` + +`mailbox_roundtrip` does the whole thing: configure the URL, let the wallet +register, have the **CLI wallet** encrypt a `taler://pay-push` URI for that +address and post it, refresh, read and delete. The sender has to be another +wallet: the app's own `sendTalerUriMailboxMessage` has no caller in the UI, and +a hand-made POST cannot stand in for it, because the app fetches a message it +cannot decrypt, deletes it from the server and says nothing — the right +instinct for a public drop box, and the reason the first two attempts showed +"No messages yet.". + +Three facts that cost an hour each are in `backend/services/README.md`: +wallet-core resolves `localhost` to `::1` while both services bind +`127.0.0.1`; every `GetDuration`/`GetAmount` in the mailbox server errors out +when its key is absent, default or not; and `taldir-dbinit` reads +`[taldir-pq]` while `taldir-server` reads `[directory-pq]`. + +### The directory proves a point instead + +Deployed, with a validator script that records each challenge where the driver +can read it — the simulator's stand-in for a validation email — the three +operations the app can never reach round-trip through wallet-core on the first +attempt: + +``` +registerAlias -> {} (202, challenge recorded) +completeRegisterAlias -> {} +lookupAlias -> {"targetUri": "http://127.0.0.1:11000/SIMADDRESS"} +``` + +So the feature is finished and the protocol is fine; the app is the only thing +that cannot be pointed at a directory. That is now in +`alias-registration-hardcodes-the-directory.md` as evidence rather than +conjecture. + +Getting there needed one character changed in the service: +`taldir-protocol-version-mismatch.md` — its `/config` hard-codes protocol +`0:0:0`, wallet-core's client declares `1:0:0` and refuses anything +incompatible, and `taldir.ts` replaces the precise reason with "could not read +the configuration of the directory service". + +### Answering for a hard-coded name, without touching the app + +`simulator/tls/` is a TLS front end that routes by `Host` and serves a +certificate for `taldir.gnunet.org` and `mailbox.gnunet.org` from the +simulator's own CA; `emu/tls-names.sh` roots one emulator, bind-mounts a hosts +entry over `/system/etc/hosts` and forwards the device's port 443 to the front +end. The CA is trusted because the `sim` build type — the simulator's own, +never published — bundles it as an extra trust anchor. No URL the app uses +changes, so `alias_registration_real` drives the shipped code path: register, +read the challenge from the validator's log, complete, look up. + +Installing the CA into the *device's* store was tried first and abandoned after +two measurements, both written up in `tls/README.md`: a mount made from `adbd` +is invisible to app processes (APEX paths have their own mount namespace, so it +has to be made under `nsenter --mount=/proc/1/ns/mnt`), there are two system +stores and the app reads the one that is not the APEX — and the framework +restart needed to make zygote see either leaves the network at +`PARTIAL_CONNECTIVITY`, where the wallet refuses everything with "This action +requires internet connection". A trust anchor in a test-only build type costs +none of that. + +### Two more harness defects, both of which hid behaviour + +* **Clearing a pre-filled field needs the caret at the end.** Tapping a + Compose field puts it in the middle and `KEYCODE_MOVE_END` does not move it, + so deleting backwards left the tail: `https://mailbox.gnunet.org` became + `http://localhost:11000unet.org`. That mistake is how the mailbox screen was + caught printing a QuickJS stack trace to the user + (`release-error-screen-explains-nothing.md`). +* The **silent-failure oracle** was reporting taps on plain text — "Pending:", + a timestamp, a section header — as findings: 24 lines in round 13. It now + requires the tapped label to resolve to something clickable. + +The exploration fixes from iteration 8 held: round 13's random walks produced +**no findings about Chrome at all**, where round 12 produced 19, and +`return_to_app` fired six to ten times per worker. + +## Iteration 10 — the app reaches the directory, and a crash nobody had to look for + +### The shipped code path, against a real directory + +Iteration 9 proved the directory's three operations work by calling wallet-core +directly. This time the **app** did it, with no URL changed: the emulator +resolves `taldir.gnunet.org` to a TLS front end, and the `sim` build type — the +simulator's own, never published — carries that front end's CA as an extra +trust anchor. The proxy log is the witness: + +``` +POST taldir.gnunet.org/register/email <- the "Register Alias" button +POST taldir.gnunet.org/FAVWP84VPPY4… <- the challenge, typed in +GET taldir.gnunet.org/FAVWP84VPPY4… <- "Lookup with Taldir" +``` + +and the screens followed: `Challenge Solution` → `Registration successful!` → +an `Add Contact` form filled in with the alias and the mailbox address behind +it. **No findings.** The feature works; the hard-coded URL is the entire +defect, which is now written into +`alias-registration-hardcodes-the-directory.md` with the evidence. + +Two blind alleys were worth the time it took to rule them out, both now in +`tls/README.md`: a trust store mounted from `adbd` is invisible to app +processes (APEX paths have their own mount namespace), and there are *two* +system stores of which the app reads the one that is not the APEX. The +framework restart needed to make either visible leaves the network at +`PARTIAL_CONNECTIVITY`, where the wallet refuses everything with "This action +requires internet connection" — which looks exactly like a wallet bug and was +briefly mistaken for one. + +### Changing the language locks the wallet out of its own database + +Found by accident, setting up a translation test: +`config-change-locks-the-wallet-out-of-its-database.md`. Changing the app's +language, the system font size or the display size while the wallet is open +lands it on the **Initialization error** screen, under + +``` +code 7001 "could not acquire exclusive ownership of the wallet database; + another wallet process may still be using it" +``` + +The screen replaces the whole app and says "Please retry" while offering only +*Export logs* and *Export database*; the only way back is to kill the app. Two +of the three triggers are accessibility settings. + +The cause is two lines of lifecycle that disagree. `onDestroy` deliberately +keeps wallet-core alive across a configuration change — + +```kotlin +// wallet-core belongs to the retained MainViewModel, not to this activity +if (!isChangingConfigurations) model.stopWallet() +``` + +— while `onCreate` calls `model.startWallet()` unconditionally, which sends a +second `init`. The pid is unchanged across the whole thing (measured), so the +error's "another wallet process" is this very process. Dark mode and rotation +are safe only because `uiMode` and `orientation` are already in the activity's +`configChanges`. + +This is the first defect in the campaign that a user can hit by changing a +system setting, and the first one found while building a test for something +else entirely. + +### Two whole features cannot be translated + +`contacts-and-mailbox-cannot-be-translated.md`: 34 user-visible strings in +`contacts/`, `mailbox/`, the two settings entries that open them, the +transaction list's selection counter and a couple of error messages are string +literals in the Compose sources, not entries in `strings.xml`. The wallet ships +19 translations; none of them can reach these. Neither defence in the repo can +see it — `./check-translations.py` reads only `values*/strings.xml`, and +lint's `HardcodedText` check only looks at layout XML, of which Compose has +none. `AliasRegistrationScreen.kt`, in the same package, uses `stringResource` +for all of its labels, so this is drift rather than convention. + +The reproducer's own navigation is the demonstration: it needs +`Settings|Einstellungen` to get around a German wallet, and plain English for +`Contacts`, `Mailbox` and everything behind them. + +### Three operations that no scenario could reach + +`registerAlias` and `lookupAlias` now run (above). Two more needed the right +state rather than a service: + +* **`failTransaction`** is the "Abandon" button, and wallet-core offers it only + while an abort is *in progress* — never for a withdrawal waiting on the bank, + which is what `withdraw_abandon` kept recording. An abort against a healthy + exchange finishes too fast to catch, so `abandon_aborting_deposit` takes the + wallet offline first. +* **`getBankAccountById`** is only called when the add-account screen is opened + with an existing id, and nothing is labelled "Edit": the account *row* is the + button. `bank_accounts` now taps it, checks the form came back filled, and + saves a change. + +`sendTalerUriMailboxMessage` is reachable too, by a path worth writing down +because it is easy to conclude it is not: a peer-push transaction's QR screen +shows a *forward* button **in developer mode only**, and only for a +`pay-push`/`pay-pull` URI +(`compose/QrCodeUriComposable.kt:183`); it navigates to the contacts screen +with the URI, and confirming a contact there calls +`mailboxManager.sendMessage` (`contacts/ContactScreen.kt:203`). The button is +labelled "Contacts", which is why it does not read like a send button. +`forward_payment_to_contact` now drives it. + +### Five scenarios were passing without doing anything + +The worst defect of this iteration was in the harness, and it had been hiding +behaviour for thirteen rounds. Five scenarios drove their flow, *noted* what +they saw, and reported "ok" whether or not anything happened: + +| Scenario | What it never did | Why | +| --- | --- | --- | +| `deposit` | deposited | the payto link it used is one the wallet refuses (`payto-link-only-accepts-iban.md`) | +| `deposit_bad_payto` | deposited | the submit button on that screen is **Send**, not Deposit, so the tap went nowhere | +| `peer_push_receive` | received | "Receive payment" is both the heading and the button, and the heading came first | +| `bank_accounts` | added an account | the unmarked required "Note" field left the submit disabled (`add-account-note-is-required-but-unmarked.md`) | +| `deposit_methods` | added any of its three | the same, plus the Bitcoin tab's fields filled in the wrong order | + +Three of the five were hiding a genuine app defect behind the green row. Two +were purely my own mistakes. Either way the lesson is the same one iteration 7 +already wrote down and did not apply widely enough: **a scenario that only +notes what it sees cannot fail.** + +`peer_push_receive` is the sharpest case, because it *had* a check: + +```python +if home.find(r"(?i)0\.00|Welcome") is not None and home.find(r"€") is None: + c.note("WARNING: the received payment did not reach the balance") +``` + +It asks for a screen with no `€` anywhere — which a zero balance, rendered +"€0.00", never is. The condition could not fire, and the note it guarded was a +warning rather than a failure in any case. It now polls the balance and raises. + +Each of the five now asserts: a bank balance that must increase, a wallet +balance that must become non-zero, an account that must appear in the list. + +### The measurement was quietly broken, twice + +* **One truncated `.ec` file lost a whole campaign's coverage.** A dump whose + app was killed mid-write leaves a partial file, and jacoco's `merge` aborts + on the first one it cannot read — taking the other 1099 files' data with it. + `coverage/validate_ec.py` now walks each file's block structure and keeps + only the complete ones (it found exactly the one bad file), and + `driver/coverage.py` refuses to write a dump that is not execution data. +* **`merge` appends to an existing `--destfile`.** A first attempt to merge in + batches reused two scratch files and so doubled the data every other batch: + 4 MB of execution data became 11 GB before it was noticed. Each destination + is now removed first. +* **Rebuilding the APK starts a new coverage baseline.** Jacoco matches data to + classes by a checksum of the class file, and adding the two `src/sim/res` + files shifted the inlined `R` constants, so data from the old APK is dropped + with "Execution data for class … does not match". Reporting rounds 1–13 + against the new build reads 49.7 % where the same data read 69.7 % against + the build that produced it. The figure to compare from here on is the one + measured over rounds 14 and later; the caveat is recorded in `report.sh` so + the next person does not chase it. + +## Iteration 11 — what the remaining 30 % actually is + +**Coverage: 69.8 % line** (12041/17247) on the new APK, measured twice over two +independent rounds with the same figure, so the measurement is now stable +enough that a real gain is distinguishable from noise. + +The more useful number is what is left. Of the 5206 missed lines, **1404 are +inside `@Preview` bodies** — functions that exist for Android Studio's preview +pane, which nothing calls and which no instrumented run can ever execute: + +``` +overall lines: 12041/17247 (69.8%) + of the 5206 missed lines, 1404 are inside @Preview bodies and cannot run at all + reachable lines covered: 12041/15843 (76.0%); the highest this report can ever read is 91.9% +``` + +So the campaign has covered **76 % of the code that can run**, and 91.9 % is the +ceiling of the figure everyone quotes. `coverage/gaps.py` now says this on every +run, because a ranking that counts preview bodies points at work nobody can do: +`ScreenTransfer.kt` leads the "missed" table with 135 lines, and 106 of them are +its five previews. + +A further ~300 lines are unreachable for a second reason — they have no caller. +That list keeps growing as scenarios reach further: +`PromptAddContactScreen`, `GridMenu`, `DemandAttention`, +`SelectionModeTopAppBar`, `SelectExchangeDialogFragment` (the last +DialogFragment in the app, and the premise `withdraw_pick_exchange` was built +on), and `DonauStatementScreen` + `DonauStatementComposable`, which are dead +because the button that should open them is wired to a no-op +(`donation-statements-button-is-wired-to-nothing.md`). + +### What the de-vacuumed scenarios bought + +Round 16 ran with most of iteration 10's fixes and moved the headline by six +lines, which looks like nothing until the per-class diff is read: + +| | before | after | +| --- | --- | --- | +| `TransactionPeerPushCreditKt` | 0 % | 44.7 % | +| `PeerManager$confirmPeerPushCredit$1` | — | 100 % | +| `TransactionPeerPullDebit` | — | 78.3 % | +| `WithdrawalShowInfoKt` | — | 63.3 % | +| `peer` package, missed lines | 482 | 448 | +| `transactions` package, missed lines | 751 | 719 | + +`confirmPeerPushCredit` at 100 % is the proof that the peer payment is now +accepted rather than merely prompted, and `bank_accounts` reached the edit form +and saved a change — which is `getBankAccountById`, one of the operations no +scenario could reach before. + +139 lines moved the other way across 28 classes. Most is run-to-run variance, +but one was a real defect in the fix: `deposit_methods` reported "no Bitcoin +tab", because a successful submit closes the form and returns to the account +list, so the first case that worked left the later tabs with nothing to tap. +Each wire method now reopens the form. + +### Two features that had never been driven at all + +* **Tap-to-pay.** `MainActivity` has three external entry points -- a VIEW + intent, shared text, and `NfcAdapter.ACTION_NDEF_DISCOVERED` -- and the third + had never been used, although the sim build has shipped a `SEND_NDEF` hook + for exactly it since the harness was written (the URI travels in a Parcelable + `NdefMessage`, which `am start` cannot build). `nfc_tap_to_pay` now delivers + a real order over NDEF and requires it to be *paid*, then taps three hostile + tags. All four behave: the order is paid, and a plain website, a bare + `taler+http://pay/` and a non-existent order each produce their own error + (`Unsupported URI`, 7008, 21). + +* **Database import.** `settings_import` had been reaching the document picker + and tapping a label matching the file name -- which DocumentsUI also uses for + the thumbnail ("Preview the file <name>") -- so nothing was selected, + `importDb` never ran, and the scenario noted "after importing" while still + sitting in the picker. Fixed, the export/import round trip **works**: a wiped + wallet comes back with its €9.87 and its transaction. + +### Nearly a serious finding, and why it was not + +The import work is worth recording as a discipline lesson, because for about +twenty minutes the evidence looked like the worst defect of the campaign: a +funded wallet exported 526 KB, was wiped, imported that file, and stayed +empty -- across a relaunch -- while `importDb` returned `result: {}`. + +It was not a defect. Three separate mistakes in the driving produced it: + +| assumed | actually | +| --- | --- | +| `adb shell rm` clears old exports from the picker | the shell sees its own scoped view; the picker lists MediaStore, which keeps everything the app wrote | +| the picker lists oldest first, so `rows[-1]` is the newest | it lists **newest** first -- `rows[-1]` was the oldest export, taken from an empty wallet | +| `Screen.tap_target` selects the row | it resolves to a neighbour that dismisses the picker to the launcher, so no import happened at all | + +The second one is the trap: the app faithfully imported an export of an empty +wallet, which is indistinguishable from an import that lost everything. The +check that caught it was reading the `importDb` *request* -- `"tables": +{"bank_accounts": [], …}` -- rather than trusting the screen. Every step of +that probe is now asserted separately (which file, which activity, which call, +which reply), and `pick_file_in_picker` carries all three findings in its +docstring. + +### The operation census was lying, in both directions + +`coverage/operations.py` counts wallet-core operations from the logcats the +episodes save, and it read **66 of 71** exercised with five never reached. Two +of those five were wrong: + +* `updateExchangeEntry` fires **forty times** when the exchange menu's "Reload + information" is tapped -- which `exchange_reload_global` has been tapping + every round. It read as unexercised because `episode.py` kept only the last + 2 MB of logcat, and in a chatty scenario that cuts the start. The wallet's + own lines (`taler-wallet`, `BackendManager`, `SimHooks`) are now kept in + full to 4 MB, with the rest of the system log keeping its tail. +* `clearDb` was genuinely unreached, because `settings_reset_cancel` only ever + cancelled. `settings_reset_confirmed` now carries the dialog through -- and + found that both of the app's `MaterialAlertDialogBuilder` dialogs put the + destructive action in the *negative* slot, which Material draws on the left + where Cancel belongs + (`reset-dialog-puts-the-wipe-where-cancel-belongs.md`). + +Of the three that remain, two are blocked by defects already written up +(`getDonauStatements` by the no-op button, `sendTalerUriMailboxMessage` by the +`taler://`-only prefix test), and one is out of reach of this environment +altogether: `cancelProgressToken` has a single caller, +`cancelDatabaseMigration`, and a migration is only offered to a wallet whose +database is still the IndexedDB emulation. `MainViewModel` hard-codes +`useNativeDb = true` so a new install never has one, and `taler-wallet-cli` +writes the native schema as well -- nothing here can manufacture the legacy +format. That also keeps the migration UI in `MainViewModel` and +`MainActivity` unreachable, which is a fair slice of their missed lines. + +### Measurement notes worth keeping + +* **Two jobs on one emulator look exactly like app defects.** Twice a scenario + landed on the welcome screen and a probe timed out inside `flows.withdraw`, + and both times the cause was a second run driving the same device. One job + per worker. +* `Wallet.dev_mode_on()` reads the marker on the *current* screen, so it + returns False on the home screen whatever the setting is. It is only + meaningful inside Settings. +* The transaction list is **on the main screen** under "Recent transactions", + which is what `transaction_rows` keys on; the "All" chip navigates to a + different screen where that header does not exist and every row goes missing. + +## Iteration 12 — the last few operations, and three features nothing had driven + +**Coverage: 70.0 % line** (12075/17247) after round 17, **76.2 % of the +reachable lines**. Each of the iteration's fixes shows up on its own in the +per-class diff, which is the useful way to read a +34-line round: + +| | | +| --- | --- | +| `TransactionManager$failTransaction$1` | **100 %** — "Abandon" finally reachable | +| `SettingsManager$importDb$1` | 60 % — the database import runs | +| `SettingsManager$clearDb$1` | the wallet reset, confirmed rather than cancelled | +| `SimHooks` | 81.6 % — the NDEF hook, used for the first time | +| `QrCodeUriComposableKt` | 98.4 % | +| `HandleUriScreenKt$getTalerAction$2` | the hostile-tag URIs | +| `MainActivity` | 76.0 % | + +**Wallet-core operations: 69 of 71.** The three that were outstanding are +settled: `clearDb` and `failTransaction` are exercised, and +`updateExchangeEntry` turned out to have been exercised all along (see below). +What remains is `getDonauStatements` and `sendTalerUriMailboxMessage`, both +blocked by defects already written up, and `cancelProgressToken`, which no +wallet in this environment can reach. + +### Where the Abandon button actually lives + +`failTransaction` took three attempts because the state it belongs to is +narrow. A deposit against a reachable exchange finishes in under four seconds, +so the network has to go away *between entering the amount and submitting*; +and `abortTransaction`'s success handler navigates back, so the transaction has +to be reopened afterwards to see what it now offers: + +``` +pending -> Retry, Suspend, Abort +aborting -> Retry, Abandon, Suspend <- the only state that offers it +abandoned -> "This transaction has failed or been abandoned" +``` + +The money is really gone afterwards (€9.87 -> €8.87), which is what the +dialog promises. That raised a question rather than a finding, recorded under +`aborted-credit-shows-the-whole-amount-as-fee.md`: the amount is honest, but +the exchange never completed the deposit, so the €0.02 "Fee" row is doubtful. + +### Three features the stack could not present + +Twice more the "uncovered" code turned out to be unreachable by configuration +rather than untested, which is the same lesson as the wire fees and the terms +in earlier iterations: + +* **The terms language selector** only renders when the exchange offers more + than one language, and the shipped `exchange-tos-v0` has an English source + only. `exchange-tos-tops-v0` ships de and en, so `stack.sh` now renders both + (`SIM_TERMS_ID`, `SIM_TERMS_LANGS`) and `exchange_tos` picks the other + language and checks the body text changes. +* **`ExchangeShoppingScreen`** needs a *scope* carrying two shopping URLs; one + URL opens a browser instead. Both exchanges now advertise one, which is why + the card appears at all, and what is still missing is written in the + scenario. +* **`DummyTransaction`** is what `TransactionSerializer` falls back to when a + transaction will not deserialize, so it needed a transaction the app cannot + parse: `transaction_states_rendered` now injects an unknown type and a + withdrawal missing its amounts. + +### A warning that was not a defect + +`denom_loss_transaction` had been reporting "WARNING: the loss event appears in +no transaction list" every round. It is not a defect: the dev experiment +inserts the event for **TESTKUDOS** -- the database row's own `currency` column +says so -- and a wallet holding EUR has no scope to show it under. The scenario +now says that, with the currency it found. Rendering `TransactionDenomLoss` +needs a loss in a currency the wallet holds, which means a denomination +expiring under it. + +### Still to do, in order + +1. Keep rounds running and triage what they surface. +2. `alias_registration_real` against the TLS front end, and the coverage the + contacts package then reaches. +3. The revocation phase, with the wallet asked to reload the exchange: a + revoked denomination left no trace in the first minute. +3. A destructive phase for `revoke_denomination`: an exchange that withdraws a + denomination under a wallet holding its coins, which is the only way to + reach the recoup path. +4. The remaining untouched screens are mostly things no service in this stack + can produce: Cyclos transfers, the GNUnet mailbox, and the database + migration prompt (which needs a wallet database in the old IndexedDB + format). + +## The camera path, taken apart without a camera + +A report arrived that scanning works on Android 15 but not on Android 14. The +campaign cannot answer that directly: the emulator's virtual scene camera +cannot be aimed at a code, so the live-camera route behind `qrsuite.py +--camera` has never run unattended, and the QR suite's default route decodes a +*bitmap* through the gallery — a different decoder that never touches the +camera arithmetic. Pointing the gallery route at API 34 and API 36 gave 10 of +10 on both with identical screens, which says nothing about the report and +everything about why it had to be approached another way. + +So the pipeline was rebuilt instead. A camera frame is a luminance plane plus +`rowStride` and `pixelStride`, and nothing in `QrCameraAnalyzer` after that +point is Android-specific — the conversion, the rotation and zxing are all +plain JVM code. `findings/repro_qr_plane_strides.java` builds a frame with a +real QR code in it, lays it out the way hardware is free to, and runs the +app's own arithmetic over it. That turned a code-reading suspicion into +measurements, and it surfaced more than the suspicion: + +* **Padding kills it outright.** Row padding of 16, 32, 64 or 128 bytes: + not one frame decodes. The same frame decodes the moment the stride is + honoured. Interleaved samples likewise. +* **A padded frame held upside down throws.** `rotateNV21`'s 180° branch walks + the chroma tail out to the padded `data.size` and runs off the end of an + array it sized from `width * height`. Because `proxy.close()` sits in the + *decode* `try`'s `finally`, that throw leaks the frame, and with + `STRATEGY_KEEP_ONLY_LATEST` CameraX then never delivers another one — the + scanner is dead for the life of the screen while the preview keeps running. + Nothing in the wallet's manifest locks the orientation, so it is reachable. +* **The rotation was never needed.** zxing finds a QR code by its finder + patterns and takes the orientation from them: all four orientations decode + untouched. The rotation that caused the crash bought nothing, which makes + deleting it the fix rather than repairing it. +* **And the obvious repair would have been worse.** The tempting replacement, + `PlanarYUVLuminanceSource.rotateCounterClockwise()`, throws + `UnsupportedOperationException` — zxing does not implement rotation for that + source, in 3.5.3 or 3.5.4. + +That last one was worth checking because the **merchant terminal already does +it.** `ConfigFragment` keeps its own copy of the pipeline, with the same +stride-blind conversion plus a `rotateCounterClockwise()` call sitting outside +the `try`. On a device whose back camera sensor is oriented 0° — common on +tablets, which is what a terminal usually is — the first frame throws, the +proxy leaks, and scanning the configuration QR code, the normal way to +provision a terminal, has never worked. Two findings, two patches, both +verified to compile and lint: `qr-camera-ignores-the-plane-strides` (now with +nine unit tests, five of which encode a real code into a synthetic frame) and +`pos-config-scanner-asks-for-a-rotation-zxing-refuses`. + +What this still does not establish is that either is *the* reported bug. The +two numbers that would settle it — `rowStride` and `width`, on the two +platforms — can only be read on the devices in the report, so both findings end +with the attended tests a developer should run, ordered to separate causes +rather than to confirm the guess. + +### The version matrix, and what API 24 showed + +`driver/matrix.py` runs the platform-sensitive scenarios on one emulator per +API level, the levels being the ones where the app's own code forks (24, 26, +28, 29, 30, 31, 33, 34, 36, each justified in `API_LEVELS` by the branch that +needs it). Its first run never got past the first level: the API 24 emulator +spent 1200 seconds booting and never finished, with its log full of + +``` +ERROR | Unsupported camera format for virtual scene views 825382478 +``` + +825382478 is the NV21 fourcc, so the virtual scene camera — configured so that +a QR code *can* be shown to the device — is asking the image's camera service +for a format it will not produce. That is **not** established as the cause of +the timeout: the API 26 emulator logs the same error eight times and boots +fine. So the error is at most a suspect. `emu.sh` now picks the camera backend +from the image's API level anyway, virtualscene from 26 up and the old emulated +camera below, because no scenario in the matrix needs to decode from it and it +removes one difference between a level that boots and one that does not. The +API 24 level is queued for a retry on that configuration, which is what will +actually say whether the camera was involved. + +## Iteration 19 — a number that was counting the wrong thing + +101 scenarios, 0 driver errors, and the round reported **7 serious findings**, +up from 5. Every one turned out to be a kind already written up: +`fee-on-dead-transaction` (`aborted-credit-shows-the-whole-amount-as-fee`), +`mixed-amount-notation` (`amounts-without-currency-specification`), +`glued-currency` (`word-currency-symbol-glued-to-amount`), and a refresh +failing with 7029 `WALLET_REFRESH_GROUP_INCOMPLETE` plus its retry +(`refresh-fails-on-mixed-age-denominations`, which is wallet-core's). + +The two remaining ones were the harness's fault, and not in an interesting way: + +``` + *** [unfinished-transaction] withdrawal_groups WQWFW8YK… unfinished after 255s (status 16777219) + *** [unfinished-transaction] withdrawal_groups WQWFW8YK… unfinished after 260s (status 16777219) +``` + +16777219 is `0x0100_0003`, `WithdrawalGroupStatus.PendingQueryingStatus` — +"querying reserve status with the exchange". The scenarios that produced it, +`withdraw_account_details` and `withdraw_account_tabs`, create a **manual** +withdrawal and deliberately never wire the money: their subject is the transfer +instructions screen. A withdrawal waiting for a transfer that is never made +stays pending by design, which is exactly why `unfinished-transaction` is +listed in `oracles.INFORMATIONAL`. + +The round tally did not use that list. `oracles.Session.serious` filters on +`INFORMATIONAL`, while the suite's own summary line filtered on +`kind != "error-screen"` — two rules for one word, and the narrower one made +every deliberately-pending withdrawal a serious finding, twice a round, to be +re-triaged each time. The suite now uses `oracles.INFORMATIONAL` as well. + +Worth stating plainly: this inflated every "serious findings" count this +campaign has reported for scenarios that leave a manual withdrawal pending. +Nothing was *missed* — `stuck-operation` and `background-error`, the kinds that +catch a genuine stall, are untouched — but the number was larger than the +defects behind it. + +### A patched build, on a device + +`PATCHES.md` had to admit that none of the seventeen patches had run anywhere +but a compiler. So the whole set was built into a `sim` APK +(`:wallet:assembleFdroidSim` on a tree with every `.diff` applied) and run on +worker 4 against the same stack, with `SIM_COVERAGE_DIR` pointing somewhere +else — JaCoCo keys classes by a hash of their bytecode, so dumps from two +builds cannot be merged into one report. + +That pass has a second purpose. Two wallet-core operations had no caller the +simulator could reach *because of* defects that are now patched: +`getDonauStatements` sits behind the donation-statements button that was wired +to nothing, and `sendTalerUriMailboxMessage` behind a forward button that only +recognised one URI scheme. On the patched build both are reachable, which is +also the only end-to-end check those two patches can get. + +### The last operation, and the database that unlocks it + +`cancelProgressToken` had been written off as unreachable: it is only called +when a database migration is cancelled, a migration only exists for a wallet +database in the legacy IndexedDB-emulation format, and the note in iteration 12 +said `taler-wallet-cli` writes the native schema. That note was wrong — or +rather, incomplete. wallet-core picks its backend from what the file already +contains, and for *empty* storage the node host reads an environment variable: + +```bash +TALER_WALLET_DB_BACKEND=indexeddb taler-wallet-cli \ + --wallet-db legacy.db api getVersion '{}' +``` + +produces a 53 KB SQLite file holding `object_data`, `object_stores`, `indexes` +and 29 records — the legacy format, confirmed by its tables. + +Planting that file made the wallet **refuse to start**, with the init error +screen. The reason is not a defect, and it is the useful part of this: + +``` +"hint": "unexpected exception (message: requested version 34, existing version is 36)" +VersionError: requested version 34, existing version is 36 +``` + +The checkout beside this one is wallet-core 1.6.48, whose IndexedDB schema is +version 36; the qtart the app embeds is 1.6.42 and asks for 34. IndexedDB does +not open a database newer than the version requested, and refusing is right. +A fixture therefore has to come from *the app's own core*, which is easy enough +to arrange: build the app with `useNativeDb = false` in `MainViewModel`, launch +it once, and copy `files/talerwalletdb.sqlite3` back out. That file carries +`taler-wallet-main-v10` at version 34 — and the fixture has to be remade +whenever the bundled qtart moves its schema version, which the scenario's +docstring now says. + +With that fixture, `db_migration_prompt` works end to end: + +``` +- database now: -rw------- 1 u0_a216 u0_a216 57344 files/talerwalletdb.sqlite3 +- after relaunch: ['Upgrade wallet database?', 'The wallet can use a faster + database. …', 'Migrate now', 'Later'] +- after Later: [settings] +- caught the migration in progress: False +- the migration row is still offered: False +``` + +So the prompt, the "Later" deferral, `migrateDatabase` and the switch to the +native backend are all covered now, and the migration dialog in `MainActivity` +— the last of the "screens nothing had driven" — is reached. + +`cancelProgressToken` is still not. The `Cancel` that calls it lives on the +progress dialog, and the migration finishes faster than the harness can tap: +driving the `useNativeDb = false` build through a scenario first gave a 1.7 MB +fixture with 512 records, the migration emitted 102 progress notifications, and +even tapping blind at the button's coordinates — no screen dump, since a dump +alone costs about a second — never landed while the dialog was up. That leaves +**70 of 71 wallet-core operations exercised**, with the last one behind a race +rather than behind a defect. A fixture of some thousands of records would +probably win it; the big one is passed in with `SIM_LEGACY_DB` rather than +carried in the repository. + +One harness defect fell out of this. Both database oracles query the native +schema, so against a wallet still on the legacy backend they reported +`oracle-error: no such table: operation_retries` — a serious finding for a +state the wallet can legitimately be in. `dbprobe.has_native_schema` now +answers that question and both oracles return nothing instead. + +### Coverage after rounds 18 and 19 + +The report had not been regenerated since the morning, and the stale one was +misleading in a way worth recording: run on the emulator host it printed 49.7 %, +because `report.sh` resolves the checkout two directories above itself, which is +the repository on a workstation and `/opt` on the emulator host — so it merged +2400 dumps and then failed to find any class files. It also hard-coded the +workstation's JDK path, which is why it died with "no such file or directory" +after half an hour of validation. Both are fixed: Java comes from `JAVA_HOME` +when that points at a real JVM and from `PATH` otherwise, and the merge can be +done on the host while the report step runs where the build output is. + +Merged over every dump from rounds 1–19: + +``` +instruction 109639/150580 72.8% +branch 3095/4923 62.9% +line 12585/17247 73.0% +method 2988/4530 66.0% +class 743/942 78.9% +``` + +73.0 % of lines, up from 70.0 %, and **79.4 % of the lines that can run at all** +(1403 of the 4662 missed lines are `@Preview` bodies; the ceiling is 91.9 %). + +Ranked by what is left: + +``` + 636 missed 69.0% ~.transactions + 526 missed 64.8% ~.payment + 432 missed 70.9% ~.peer + 369 missed 73.7% ~.compose + 289 missed 54.3% ~.transfer + 256 missed 38.2% ~.donau +``` + +`~.donau` at 38.2 % is the lowest of any package, and most of what is missing +there is behind the statements button that is wired to nothing. `~.transfer` at +54.3 % is largely the Cyclos path, which no service in this stack can present. +And checking the "untouched classes" list before writing scenarios for it turned +up `ui-with-no-callers.md`: 189 lines of UI that nothing in the app refers to, +including a second, unreachable implementation of the add-contact screen. + +### Still to do, as of round 20 + +Replacing the list at the end of iteration 12, two items of which are done: + +* **`alias_registration_real` — done.** It has been passing since the TLS front + end went in, end to end: register, challenge, complete, look up. + + ``` + - the form: ['email', 'Alias Type', 'Alias', '12', 'Duration (months)', 'Register Alias'] + - after registering (challenge: WJY4TVQQ2D6TCJVBBXBN9R5974): ['Challenge Solution', 'OK'] + - after completing: ['Registration successful!', 'OK'] + - after the lookup: ['Add Contact', 'Looked up', 'Petname', 'sim-w1-…@example.com', 'Alias', …] + ``` + +* **The database migration prompt — done**, see above, with the fixture caveat. + +* **The revocation phase and fault injection — queued as one job.** + `run/phases.sh` waits for the round the loop is in to finish, waits for the + version matrix to clear worker 6, then restarts the stack and runs + `revoke_denomination` alone (it is stack-wide and lasts until the next + restart), restarts it again from `sim-twister.conf` and runs the three + twister scenarios, and finally restores the ordinary stack and puts the loop + back at round 21. + + The twister scenarios are worth saying something about: they have been in the + suite for several rounds and **have been skipping every time**, because + `twister_or_skip` looks for a `twister` entry in the stack's `env.json` and + an ordinary stack has none. They were costing 30–60 seconds a round to + report "the stack is not running twister; nothing to inject". That is the + right behaviour — faults were to be the last avenue, after everything else — + but it does mean no fault has been injected yet, and the phase above is the + first time one will be. + +* **What is left uncovered is now mostly explained rather than pending.** Three + findings written this round account for a good part of it: + `ui-with-no-callers` (189 lines nothing refers to), + `refresh-transactions-are-never-listed` (a whole detail screen for a + transaction type the app never asks wallet-core for), and + `multi-qr-transfer-screen-cannot-be-reached` (a button gated on two QR codes + where there can only ever be one). Cyclos transfers and the GNUnet mailbox + remain genuinely absent from this stack, and `ExchangeShoppingScreen` still + needs an exchange advertising two shopping URLs in one scope. + +### Round 20 — three scenarios written from the gap list + +Reading the fresh report class by class rather than package by package paid off +better than designing scenarios from the feature list did. + +* **The overflow menu on a transaction detail screen.** It only exists when the + transaction has a payto target, and its single item is the only caller of + `copyToClipBoard` there. `transaction_details_by_type` now opens it on every + detail screen it visits. + +* **`manual_withdraw_transfer` stopped swallowing its own failures.** It tried + four buttons -- "Wire transfer QR codes", "EPC QR", "Swiss QR bill", "Open in + banking app" -- inside a `try: … except TimeoutError: continue`, so a button + that had stopped working was indistinguishable from one that is not offered. + It now says which, and the answer turned out to be the finding + `multi-qr-transfer-screen-cannot-be-reached`. + +* **`subscription_issued_and_viewed`, a new scenario.** The uncovered half of + `TokenListScreen` is the pass (subscription) list, and nothing was buying a + subscription: `payment_needs_token` creates a subscription family and + *demands* the token, so the wallet never holds one. An order with a + subscription token as its **output** does: + + ``` + - the merchant says the order was paid: True + - passes: ['Simulator discount', 'subscription tokens issued by the simulator', + 'Provided by Simulator Shop', 'Active', + 'Valid until October 18, 2027 at 2:43 PM', …] + ``` + + One trap worth recording: the first version asserted the pass was called + "Simulator pass", and it is called "Simulator discount". `create_token_family` + answers 409 when the slug already exists and leaves the existing name alone, + so the family that `payment_needs_token` created first keeps its name + whatever a later scenario asks for. The assertion is now on a row having a + validity, which is what actually says a pass is listed. + +* **`balances_two_exchanges` now goes on to the shopping screen.** Same shape + as the QR button: `MainScreen.kt:188` opens a browser when the scope has + exactly one shopping URL and only navigates to `ExchangeShoppingScreen` when + it has more, which needs both exchanges treated as global currency in one + scope. The scenario does the treating already; now it taps the card and says + which of the two happened. + +#### The shopping screen, and what it says about the global-currency defect + +`ExchangeShoppingScreen` (62 lines, untouched since the campaign began) is now +covered, and getting there answered a question the findings had left open. + +The card on the main screen only navigates to that screen when the scope +carries more than one shopping URL, which needs both services in one currency +scope — that is what "treat as global" is for. `balances_two_exchanges` was +already treating both as global and getting nowhere, and the reason is the +defect in `addglobalcurrencyexchange-null-masterpub.md`: the call sends +`masterPub`, which is null until the exchange's `/keys` has been fetched, and +`JSONObject.put` drops a null key, so wallet-core rejects the request. The +second service had just been added by URL and never contacted, so its key was +null every time. + +With the scenario accepting the second service's terms and tapping "Reload +information" first, it works: + +``` +- 8081: reloaded +- 8091: reloaded +- the shopping screen: ['Your payment service offers the following website(s) …', + 'http://localhost:8080/config?shop=one', + 'http://localhost:8080/config?shop=two'] +- 2 shopping URLs listed +``` + +Which sharpens the finding: "treat as global" is not broken, it is broken for +an exchange that has been added and not yet talked to — the state an exchange +is in immediately after being added by URL, and therefore the state a user is +most likely to try it in. + +Two detection mistakes worth recording, both mine, both of the same kind. The +first check for the screen looked for a node reading exactly "Where to pay", +but the title is "Where to pay with EUR" — which is also what the card on the +main screen says, so the title cannot distinguish the two screens at all. The +screen is now recognised by its own message ("offers the following +website(s)"). Before that, the note said the tap "left the app", which was +wrong: the activity was still the wallet's, and the screen text in the very +same note was the shopping screen's. A note that prints what it saw is worth +more than a note that reports a conclusion. + +#### The round tally counted work that was not the round's + +Round 20 reported "147 ok, 1 driver errors, 8 serious findings", and three of +those eight were things this session had done by hand on the spare emulator: +the error screen of a *patched* APK, the oracle error from the deliberately +too-new migration fixture, and the `history` run that built the big legacy +database. `campaign.py`'s `collect()` merged **every** `suite-w*-summary.json` +newer than the round's start, and a scenario run by hand writes one of those +into the same directory. + +It now filters by worker as well as by time — the round knows which emulators +it launched. Recomputed over workers 0–3 only, round 20 is: + +``` +205 scenarios, 205 ok, 9 findings, 5 serious + *** background-error refresh 7029 WALLET_REFRESH_GROUP_INCOMPLETE + *** stuck-operation the same refresh, retried 5 times + *** fee-on-dead-transaction + *** mixed-amount-notation + *** glued-currency +``` + +Five, all of kinds already written up, three of them already patched. That is +the third measurement bug this campaign has found in itself — after the +truncated logcat and the double-counting merge — and all three had the same +shape: a number that was easy to read and quietly measuring something else. + +### The version matrix: three levels clean, four never booted + +`matrix.py`'s first full pass over the nine API levels where the app's own code +branches gave: + +``` +API 24: ERROR boot timed out after 1200s +API 26: 12 scenarios, 12 ok +API 28: ERROR could not boot +API 29: 12 scenarios, 12 ok +API 30: ERROR could not boot +API 31: 12 scenarios, 12 ok +API 33: ERROR could not boot +``` + +The pattern is the finding: **every second level** failed. That is not how +platform incompatibility behaves; it is how a teardown that does not wait +behaves. `emu.sh kill` ran `adb emu kill`, which returns as soon as the +emulator's console accepts the request, and the matrix then immediately +created the next AVD **under the same name** — with the previous process still +holding its lock files. The level after a failure then found nothing running +and booted fine, which is what produced the alternation. + +`kill` now waits for the device to leave `adb devices`, then for the process on +that console port to exit, and clears any `*.lock` left in the AVD directory. +The four failed levels are queued for a retry behind the phase job +(`run/matrix-retry.sh`), which is also where it will become clear whether the +API 24 timeout was ever about the camera format at all. + +One data point in the fix's favour arrived immediately: API 34 passed 12/12, +and under the old alternation the level after a success was the one that +failed — but API 36, the first level whose predecessor was torn down with the +waiting `kill`, booted. One observation is not proof; the retry of the four +failed levels is the test. + +What the three levels that did run say: the twelve platform-sensitive +scenarios — the balances and history screens, manual QR entry, NFC tap to pay, +the settings walk, export and import, the config changes, the lock screen +without a credential, the accessibility audit, the lifecycle kill and the +database corruption — behave on API 26, 29 and 31 exactly as they do on 36. +**No version-specific defect has been found yet**, which is worth saying +plainly given that the whole matrix exists because of a report that scanning +works on one Android version and not another: the matrix cannot speak to that +report, because the camera path is the one thing it cannot drive. + +#### What the last big gap in the detail screen actually is + +`TransactionDetailScreenKt` is the single largest partially-covered class (164 +missed lines, 59 %), and reading it line by line leaves three things, none of +them a scenario anyone can write today: + +* **Its preview** (lines 638–657) — counted correctly as unreachable; checked, + because `gaps.py`'s preview accounting is what the "79.4 % of reachable + lines" figure rests on. `preview_lines()` does find them: 1831 preview lines + across 43 files, of which 1403 are lines the report also calls missed. The + same check cleared the `~.peer` package, whose 432 missed lines are mostly + the four previews in `OutgoingPushComposable.kt` (105 lines) — so no + scenario was worth writing there either. +* **The refresh branch** (320–329) — unreachable by design, see + `refresh-transactions-are-never-listed.md`. +* **The denomination-loss branch** (354–364, 497–531) — needs a loss event in a + currency the wallet holds, and it cannot have one here. + `dev-experiments.ts:243` hard-codes the injected event: + + ```ts + const newRg: WalletDenomLossEvent = { + amount: "TESTKUDOS:42", + currency: "TESTKUDOS", + exchangeBaseUrl: "https://exchange.test.taler.net/", + ``` + + No parameters, so the injected loss is always TESTKUDOS, and a EUR wallet has + no scope to show it under — which is what `denom_loss_transaction` has been + reporting all along. + + **Corrected the same evening:** the revocation phase makes a *EUR* loss + event, because revoking a denomination the wallet holds is a real loss in the + wallet's own currency. The clean revocation run left `denom_loss_events: 1` + and one coin marked `denom-loss`, so the loss transaction and its detail + screen are reachable after all — through the destructive phase rather than + through the dev experiment. `revoke_denomination` now looks for the "Loss of + funds" row, opens it, and checks that the screen names a reason (one of + `loss_reason_expired`, `_unoffered`, `_vanished`). That is + `TransactionDenomLoss`, the loss branch of the detail screen and + `TransitionLossComposable` — around ninety lines that had never rendered — + and it makes the detail screen's remaining gap the refresh branch alone. + +### The phase job's first attempt, and a third teardown that did not wait + +The revocation-and-twister job waited correctly for the campaign loop and the +version matrix, then died: + +``` +=== 17:49:15 restarting the stack with sim.conf +=== 17:49:35 stack did not come up; stopping +``` + +`phases-stack.log` shows `taler-unified-setup.sh` terminating at the merchant. +The cause is the same shape as the emulator one, two sections above: +`stack.sh stop` kills the supervisor and waits for *it*, then returns — while +its children are still holding the ports. The job started the stack again five +seconds later, and the merchant could not bind. + +Both halves are fixed. `stack.sh stop` now waits, after the supervisor is +gone, for the six ports this stack owns to be released (not 11000 and 11001: +the mailbox and taldir are run separately and outlive it), and says so if they +are still held after a minute. `run/phases2.sh` additionally retries the start +once, because losing a phase to a transient failure costs an hour of waiting +for the next round boundary. + +Worth noticing how similar the three are: + +| what | what it waited for | what it should have waited for | +| --- | --- | --- | +| `emu.sh kill` | the console accepting `emu kill` | the process to exit and release the AVD | +| `stack.sh stop` | the supervisor to exit | the children to release the ports | +| the first phase job | a line in `rounds.log` | the loop's process to be gone | + +In all three, something answered "done" before the thing that mattered was +done, and the failure landed on whatever ran next rather than on the component +at fault. In the meantime the stack is back up (18 s, clean), the loop is +running again at round 21, and the phases are queued behind the matrix retry. + +### The revocation phase ran, in the worst possible conditions + +A `pkill` of the first phase script had not actually killed it — the pattern +matched the `bash -c` wrapper of the very command doing the killing, which +ended that ssh session before `pkill` ran. So two phase jobs were alive, and at +17:49 they both stopped and started the stack. One of them won, ran the +revocation phase from 17:50 to 17:59, restarted the stack and started a +*second* campaign loop; the other saw its own start fail at the merchant and +gave up. For about fifteen minutes there were two loops exploring with the same +seeds on the same four emulators, a scenario of mine running on a fifth, and +the stack being restarted underneath all of it. + +Everything is back to one loop and one phase job. The point of recording it is +what it does to the result: `revoke_denomination` completed and reported + +``` +- the wallet holds 4 denominations: [1, 4, 7, 8] +- revoked 1E1SBDFT7V6KX9… (1 coin(s) held) +- asked the wallet to reload the exchange +- home after revocation: [] +- denom_loss_events: 0 rows +- recoup_groups: 0 rows +- coins: 0 rows +``` + +A wallet that held twenty coins has none, with no recoup group and no loss +event to account for them — which would be a serious finding if anything about +that run could be trusted. It cannot: the same episode carries a +`[harness-crash] FATAL EXCEPTION: main` from a process that is not the app and +an `[empty-hierarchy] no view hierarchy returned`, the two scenarios after it +died with `could not enable developer mode; settings showed: []`, and the +exchange it was talking to was restarted twice while it ran. Any of those could +produce an empty wallet. + +So it is **not** filed as a finding. `run/phases2.sh` re-runs the same phase +with the stack to itself, and the question to put to that run is precisely: +after revoking one denomination of four, does the wallet still hold the coins +of the other three, and does the revoked one leave a recoup group or a loss +event behind? Whatever that says is worth a finding; this run is not. + +### Ranking the gaps by what can be reached + +`gaps.py` ranked packages by raw missed lines, and that ranking was misleading +in a way that cost scenario-design time: `~.peer` looked like the third-biggest +gap in the module and is mostly four `@Preview` functions in one file. The +ranking now subtracts preview lines per package — the same data the headline +"reachable" figure already used, applied one level down: + +``` +packages by missed lines that can actually be reached: + 493 missed 69.0% ~.transactions (636 counting previews) + 376 missed 64.8% ~.payment (526 counting previews) + 271 missed 73.7% ~.compose (369 counting previews) + 222 missed 67.8% ~.exchanges (242 counting previews) + 204 missed 38.2% ~.donau (256 counting previews) + … + 122 missed 70.9% ~.peer (432 counting previews) + 97 missed 74.6% ~.balances (233 counting previews) +``` + +`~.peer` moves from third to tenth and `~.balances` from tenth to fourteenth. +`~.donau` keeps the lowest percentage of any package at 38.2 %, and most of +what is missing there is behind the statements button that is wired to nothing +— which the patched build reaches, so that number should move on its own once +the patch lands. + +### Why API 24 never booted: not the camera, not the teardown, the AVD's size + +The retry settled two of the three hypotheses at once. **API 28 booted** this +time, where it had failed in the first pass — so the teardown fix is real. +**API 24 failed again**, from a clean start and with the emulated camera, so +neither the lingering-process theory nor the NV21 virtual-scene error was its +cause. The camera error is therefore cleared: it is noise that API 26 logs +eight times while booting fine. + +What is left is the AVD itself. `emu.sh create` builds every AVD the same way: +`-d pixel_6`, 4 GB of RAM, a 6 GB data partition, 1080×2400 at 420 dpi. Three +probes on a spare emulator, each a fresh AVD from the same API 24 image: + +| profile | RAM | data partition | result | +| --- | --- | --- | --- | +| `pixel_2` | 2 GB | 2 GB | **booted in 35 s** | +| `pixel_6` | 2 GB | 2 GB | **booted in 35 s** | +| `pixel_6` | 4 GB | 6 GB | never booted (the campaign's own configuration) | + +So the device profile is not the problem — a Pixel 6 profile on Android 7 boots +fine. The size is. Which of the two sizes is still open; a fourth probe +(`pixel_6`, 4 GB RAM, 2 GB partition) is running to say whether it is the RAM +or the partition, and `emu.sh` will then pick that one value by API level +rather than giving a 2016 system image the same budget as a 2025 one. + +A note on how the probes were run, since two of them had to be thrown away: the +first attempt printed a hard-coded "booted with -d pixel_2 and 2 GB" while +actually running with `pixel_6`, which nearly produced the wrong conclusion — +the message now interpolates the parameters it was given. And two copies ended +up racing on the same AVD name and console port, because the ssh session +carrying one timed out while the remote script kept going. Probes get +`setsid nohup` and their own log now, like everything else here. + +#### The retried levels booted and had no money + +API 28, 30 and 33 all booted on the second pass — the teardown fix works — and +then every one of their twelve scenarios failed: + +``` +API 28: 0/12 ok + all twelve: driver-error + stack.HttpError: HTTP 401 for http://localhost:8082/accounts/wallet7/withdrawals: + {"code":40,"hint":"Unknown account"} +``` + +Worker 6 — the one the matrix drives — banks as `wallet7`, and +`stack.py`'s `provision()` defaulted to `SIM_WORKERS=5`, so a plain +`python3 stack.py` created `wallet1`…`wallet5` and stopped. The campaign's own +four workers were fine, which is why nobody noticed; the matrix's worker had an +account until the bank database was rebuilt, and after that it did not. + +The failure mode is the thing to watch for: a level that boots and then reports +twelve driver errors looks exactly like a platform that cannot run the app. +Only the exception text says otherwise. The default is now seven, which covers +every AVD the harness has, and the three levels are queued to run again behind +the phase job. + +## Fault injection, at last + +The twister phase ran: three scenarios, all of them actually doing something +for the first time (`twister_withdraw_faults` took 638 s against the 30 s it +used to take while reporting "nothing to inject"). Seven faults, armed one at a +time in front of the exchange: a truncated response, a truncated upload, 500, +404, 403, 502, and a wrong `Content-Type`. + +**One finding.** Five of the seven faults leave a withdrawal on a screen with a +title, a back arrow and nothing else — and it stays that way after the fault is +removed and the exchange is healthy again: + +``` +- http-500: ['Go back', 'Withdraw UNKNOWN', 'Internal event log'] +- http-500 after retry: ['Go back', 'Withdraw UNKNOWN', 'Internal event log'] +- http-500: armed 115 times +- http-500 once the fault stops: ['Go back', 'Withdraw UNKNOWN', 'Internal event log'] +``` + +Written up as `withdrawal-screen-never-recovers-from-an-exchange-outage.md`: +`PromptWithdrawScreen` has a loading state and a success state and nothing in +between, so a preparation that failed looks like one still in flight, and +nothing re-runs it. A user meets this without any proxy whenever an exchange +answers 5xx or truncates a body at the moment a withdrawal starts. + +The two faults that are *survived* are the useful contrast: a damaged **upload** +(`truncated-request`) and a wrong `Content-Type` both carry on to the terms of +service and then to "Waiting for authorization in the bank". So the wallet is +not simply fragile under damage; it is specifically missing an error state on +one screen. + +**One observation held back.** Under every fault, a payment ends with the +wallet showing "This transaction is pending" and "Paid -€1.00" while the +merchant still says `claimed` ninety seconds after the fault stopped. That +could be a purchase that never resolves, or a retry that had not come round +yet — ninety seconds cannot tell them apart, and wallet-core's retry backoff is +measured in minutes. The scenario now waits five minutes and records how long +recovery took, so the next phase will answer it instead of hinting at it. + +**And one thing the faults did not find:** no crash, no internal error screen, +no stuck database, in 21 fault-armed flows. The oracles that have caught real +defects all round — `fee-on-dead-transaction`, `mixed-amount-notation`, +`glued-currency` — reported nothing here either. Fault injection was the last +avenue by design, and on this evidence the wallet's transport-level error +handling is in better shape than its screens are. + +### Two more scenarios from the reachable ranking, and a finding from one of them + +With the ranking subtracting previews, `~.payment` is second (376 reachable +missed) and `PaymentResponses.kt` the worst file in it at 42 %. What is missing +there is the *typed* half: `PaymentInsufficientBalanceDetails`, its +`PerExchange` breakdown, and the mapping from each of seven refusal reasons to +its own string. `payment_insufficient` only ever reaches the plain +"not enough money" case, and the wallet cannot manufacture the others — but +wallet-core can, with the `merchant-deposit-insufficient` dev experiment. + +The new `payment_insufficient_reason` scenario arms it and pays for something +the wallet can easily afford. The answer is +`payment-prompt-says-insufficient-without-the-reason.md`: with €9.87 in the +wallet and a €1.00 order, the prompt says **"Insufficient balance"** and nothing +else. The reason is in the reply, the string for it exists, the mapping from +hint to string exists, and exactly one screen in the app uses that mapping — +the peer-push one. The payment prompt reads `choice.details` and ignores +`choice.details.balanceDetails.causeHint` sitting beside it. Patched with the +same expression the peer screen already uses. + +Two mistakes of mine in writing that scenario, both worth the same warning: +the first version named the order "Order the merchant cannot take", so every +pattern looking for the word "cannot" matched the order summary and the +scenario cheerfully reported a reason-specific hint that was not there. The +summary is neutral now and the patterns match wording only the wallet's own +strings contain. **An assertion that can be satisfied by the test's own input +is not an assertion.** + +The other new scenario comes from the revocation: `revoke_denomination` now +follows the recoup group to completion, reports what the balance did, and then +looks for the "Loss of funds" row and opens it — `TransactionDenomLoss`, the +loss branch of the detail screen and `TransitionLossComposable`, about ninety +lines that had never rendered because the only loss event anyone could make was +TESTKUDOS. A revocation makes one in euros. That phase is queued. + +### A seventh vacuous scenario, and the long press that could not work + +`TransactionsScreen.kt` sat at 49 % with its whole selection mode uncovered — +select all, leaving selection mode, and the delete-selected dialog. There was +already a scenario for that, `transactions_bulk_delete`, and it had been +reporting the same line every round while counting as a pass: + +``` +- after long press: ['http://localhost:8081', '€7.87', 'Pending:', …] +- long press did not open selection mode +``` + +Checked across the last forty summaries: **every** run of it, in every round, +ended on that note. It never could do otherwise. The main screen's list is +built with selection switched off: + +```kotlin +// wallet/src/main/java/net/taler/wallet/balances/BalancesPagerComposable.kt +TransactionRow( + tx = tx, + isSelected = false, + selectionMode = false, + onTransactionClick = { onTransactionClicked(tx) }, + onTransactionSelect = {}, // a no-op, by construction +) +``` + +Selection exists only on the dedicated screen behind the "All" chip. So the +scenario was waiting for a feature that is deliberately absent, and saying so +in a way that read like a flaky gesture. + +Finding the real cause took three wrong turns worth recording, because each was +a plausible theory that the evidence refuted: + +1. **"The gesture is wrong."** `long_press` sends `input swipe x y x y 800`, a + zero-distance swipe, which looks like something Compose might reject. It was + replaced with two `input motionevent` calls — which silently do nothing, + because each `input` invocation is its own input session and the DOWN is + cancelled when it exits. Probing four techniques against a live row settled + it: the original zero-distance swipe is the only one that works, and moving + even two pixels turns it into a drag that cancels the long press. The change + was reverted and the reason written into the function. +2. **"The balance card is being counted as a row."** It is, on the dedicated + screen — the card sits between the app bar and the list — but adding + "balance" to the stop-list did not help, because the card's parts land in + different bands and the offending one holds the exchange URL, not the word + "Balance". +3. **The actual fix.** A transaction's amount carries a sign and a balance's + does not, so `transaction_rows` grew a `signed_only` mode for callers on + that screen, plus a rule that a URL is never a row's title. + +With that, the dedicated screen's selection mode runs end to end: + +``` +- selection mode: [… '1 selected', 'Select All', …] +- after select all: [… '2 selected', …] +- 1 unnamed clickable(s) in the app bar: [(12, 150, 138, 276)] +- after closing selection mode: [… 'Go back', …] +- the delete dialog: ['Delete transactions', 'Are you sure you want to remove + the selected transactions from your wallet?', 'Delete', 'Cancel'] +- rows after deleting the selection: 0 +``` + +`transactions_bulk_delete` now pins what the main screen actually does — a long +press there must do *nothing*, not open a detail screen and not crash — and +says so, and `transactions_screen_selection` owns the deletion flow. Note the +close button in that app bar is an unnamed clickable, which is why the scenario +has to find it by position: `TransactionsScreen.kt:112` passes +`contentDescription = null`, the same omission as +`action-buttons-have-no-accessible-name.md`. + +### The matrix, third pass: five levels clean, and two kinds of infrastructure noise + +With `wallet7` funded, the retried levels do what they should: + +``` +API 30: 12/12 ok +API 28: 0/0 ok -- aborted: adb logcat timed out after 120s +``` + +API 30 joins 26, 29, 31, 34 and 36 at 12 of 12. API 28 did not fail a +scenario; it never finished one, because `adb logcat` stopped answering: + +``` +subprocess.TimeoutExpired: Command '[… 'logcat', '-d', '-t', '600']' + timed out after 120 seconds +``` + +That is the machine, not the app — at the time it was carrying six emulators, +the campaign's four workers, a matrix level, two Gradle builds and a scenario +of mine on a spare worker. The lesson is about discipline rather than code: ad +hoc runs on a spare emulator are cheap individually and not free in aggregate, +and the version matrix is the thing that suffers first because it boots a fresh +emulator for every level. + +Tally so far, across three passes: + +| level | result | +| --- | --- | +| 24 | never booted; the AVD-sizing fix is queued for validation | +| 26, 29, 30, 31, 34, 36 | 12/12 ok | +| 28 | booted twice, aborted twice — provisioning once, an adb timeout once | +| 33 | pending in the current pass | + +So **no version-specific defect has turned up in any level that completed**, +and every failure so far has been the harness or the host. + +## Dead code, enumerated, and coverage without it + +The "untouched classes" list in a coverage report shows the dead code that +happens to be big; `ui-with-no-callers.md` was assembled by reading it and +chasing suspects by hand. `simulator/coverage/deadcode.py` now does it +systematically: every top-level declaration and every direct member of a type, +asked whether its name appears anywhere else in the app. + +**19 declarations, 383 lines in the wallet module; 10 and 56 in the library.** +The full list, with what each one is, is in +`dead-declarations-complete-list.md`. Beyond the five pieces of UI already +written up, it turned up the older generation of a menu component sitting in +the same file as its replacement (`NewMenuItem`, `NewMenuSectionHeader`, +`NewMenuContent`, beside the `Material3MenuGroup` four screens use), two lists +of wallet-core notification type strings superseded by `@SerialName` matching +in `backend/Notifications.kt`, a constructor property nothing passes or reads, +and `fun MerchantInfoSheet() {}` — an empty composable. + +### What it does to the numbers + +``` +lines covered 12585/17247 (73.0%) +missed inside @Preview 1403 +missed in dead code 277 +reachable lines covered 12585/15567 (80.8%) +the ceiling this report can read: 90.3% +``` + +Three figures that have to be kept apart: **73.0 %** of all lines, **79.4 %** +of lines outside `@Preview` bodies, **80.8 %** of lines that are both outside a +preview and reachable at all. Only the last says anything about how well the +app is tested. `gaps.py --dead` prints it; the pass is opt-in because it takes +a few minutes. + +Only *missed* dead lines are subtracted. Some dead lines count as covered — a +file-level `private val` is initialised when its class loads whether anything +reads it or not — and subtracting those would flatter the numerator. + +### Getting the detector to tell the truth took three tries + +Worth recording, because the first two versions produced confident nonsense: + +1. **Indentation is not nesting.** The first version accepted declarations at + indent 0 or 4, which admitted every `val` local to a composable — 43 + "dead declarations" of which most were locals, including `pagerPosition` + and `biometricManager`. It now tracks brace depth and the kind of the + enclosing construct, so a member of a class counts and a local inside a + function does not. +2. **Spans ran away.** Brace-matching from a `val` declaration consumed the + rest of the enclosing block, so a one-line property was reported as 121 + lines — and worse, spans overlapped, which would have double-counted lines + subtracted from the coverage denominator. Each body shape is now handled + separately, and the spans were checked against the source line by line. +3. **Deadness is transitive.** `connectToWifi29` and + `connectToWifiDeprecated` are referenced only from `connectToWifi`, which + is referenced from nowhere. The search now repeats, ignoring references + that come from inside already-dead spans, until a round adds nothing. + +The remaining limits are in the finding: a common name can collide with an +unrelated use and look alive (which under-reports, the safe direction — the +library's `showError` hides the wallet's two), mutually-referencing overloads +keep each other alive (`GridMenu.kt` is dead as a unit but only `GridMenu` is +listed), and anything reached by reflection would be reported wrongly. Which +is why the finding is a list to read, not a deletion to apply. + +### cancelProgressToken: four attempts, and why it stays at 70 of 71 + +The last unexercised wallet-core operation sits behind one button: the Cancel +on the database-migration progress dialog. `MainActivity.kt`'s largest +remaining gap is that dialog (lines 445–482) and the `onCancel` that calls +`cancelDatabaseMigration` (223–227), so this is worth something beyond the +operation count — but it is also the hardest thing in the campaign to reach, +and four attempts did not. + +1. **The committed 57 KB fixture.** Migrates in well under a second. The + fifteen-attempt tap loop never saw the dialog. +2. **A 1.7 MB fixture, 512 records.** Built by driving the + `useNativeDb = false` build through a scenario first. The migration emitted + 112 progress notifications and still finished before a screen dump came + back; a dump costs about a second, which is most of the window. +3. **Blind taps.** Read the prompt's button coordinates first, then tap + "Migrate now" and the same slot again with no dump in between — the + progress dialog's single button sits where the prompt's confirm button was. + No call. +4. **Freezing the process.** `kill -STOP` on the app so the taps queue in the + system input dispatcher, then `kill -CONT`: once after starting the + migration, once with the start *and* the cancel queued together before it. + The freeze itself worked both times (`froze the app: True`); the migration + still finished first. + +What would reach it: a legacy database of some thousands of records, which +means driving the `useNativeDb = false` build through enough withdrawals to +make one, or a debug hook that pauses the migration between steps. Neither is +a scenario, so the operation count stands at **70 of 71**, and the reason is +recorded in the scenario itself rather than left as a mystery for the next +person. + +Worth noting what the attempts *did* buy: the prompt, the "Later" deferral, +`migrateDatabase`, the progress notifications and the switch to the native +backend are all covered, and the migration dialog in `MainActivity` is no +longer a screen nothing had ever driven. + +## Iteration 22 — 106 scenarios, three serious findings, all of them patched kinds + +``` +2026-10-18T20:52:13 round 22: suite: 106 ok, 0 driver errors, 3 serious findings + *** [fee-on-dead-transaction] a fee is shown on a transaction that did not happen + *** [mixed-amount-notation] '5.00 EUR' beside '€4.88' + *** [glued-currency] 'UNKNOWN0.00' +``` + +Three, down from five, and the drop is not luck: two of the five were the +`unfinished-transaction` false positives that the tally fix reclassified. All +three that remain have patches sitting beside them. + +### The mailbox screen's two dialogs, and the same tap trap for the third time + +`MailboxScreen.kt` sat at 61 %, and half of what was missing was its two +dialogs. The scenario had been tapping for `^Add$|^New$|^\+$` and +`refresh|reload`, of which only the last matches anything on that screen — the +app bar offers "Show Mailbox Address", "Configure Mailbox" and "Refresh". + +Both dialogs now run: the address one shows the wallet's real mailbox URI and +copies it, and the URL one accepts a typed URL and is cancelled, which must +leave the screen as it was. + +Getting the copy confirmation to appear took the same mistake twice more: + +* **Too slow.** `c.see(r"copied to clipboard", timeout=10)` reported "no + confirmation" for a snackbar that a probe found **0.4 s** after the tap. The + scenario now polls tightly, as the Toast lesson in the import scenario + already said it should. +* **The wrong control.** Even then it saw nothing, because `c.tap` hunts for a + clickable ancestor and on these dialog buttons lands somewhere that dismisses + the dialog instead of pressing the button — exactly the trap documented in + `pick_file_in_picker`'s docstring for the document picker's rows, and in the + transactions screen's row long-press. Tapping the node's own centre works: + + ``` + - after copying: ['Mailbox address URI copied to clipboard'] + ``` + +Three different screens have now needed that same correction. It is written in +three docstrings; it would be better as one helper, and that is worth doing +before a fourth screen finds it. + +### API 24 boots, and the matrix is eight levels of nine + +The AVD-sizing fix is confirmed end to end. The level that spent 1200 seconds +twice without finishing a boot now boots and runs everything: + +``` +scenario 24 +balances_screens ok +history ok +scan_manual_entry ok +nfc_tap_to_pay ok +settings_walk ok +settings_export ok +settings_import ok +config_changes ok +wallet_lock_without_credential ok +a11y_audit ok +lifecycle_kill ok +db_corruption ok + +API 24: 12/12 ok +``` + +So the cause was never the app, the camera format or the teardown: a 2016 +system image cannot boot on 4 GB of RAM with a 6 GB data partition, and boots +in 35 seconds on 2 GB of each. `emu.sh` picks the smaller budget below API 29. + +The matrix now reads: + +| level | result | +| --- | --- | +| 24, 26, 29, 30, 31, 33, 34, 36 | **12/12 ok** | +| 28 | aborted twice, both times on the harness — provisioning once, an `adb logcat` timeout under load once | + +**Eight of the nine levels the app's own code branches on now pass every +platform-sensitive scenario, identically.** The report that started this — +scanning works on Android 15 but not 14 — is still unanswered, and the matrix +cannot answer it: the camera is the one path no emulator here can drive. What +the matrix *can* say is that nothing else about the app differs across eight +platform generations, which narrows where to look. diff --git a/wallet-simulator/findings/PATCHES.md b/wallet-simulator/findings/PATCHES.md @@ -0,0 +1,148 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Patches for the findings + +Where a finding has a fix that is clear from the code rather than a product +decision, the patch sits beside it as `<finding>.diff`. Each one applies to a +clean checkout with + +```bash +git apply simulator/findings/<finding>.diff +``` + +All nineteen apply together, and with all of them applied +`./gradlew :wallet:compileFdroidDebugKotlin :wallet:lintFdroidDebug +:taler-kotlin-android:testDebugUnitTest` succeeds (lint matters here: it runs +with `abortOnError true` and `ignoreWarnings false`). The terminal patch was +checked on its own module, `:merchant-terminal:compileDebugKotlin` and +`:merchant-terminal:lintDebug`. No two patches touch the same file, with +one exception: `release-error-screen-explains-nothing` and +`product-image-dialog-has-nothing-to-announce` both add strings to +`wallet/src/main/res/values/strings.xml`, in different places, so they apply in +either order. + +Fifteen of the nineteen have also **run on a device**. The four that have not +are the ones written since that run — the terminal's config scanner, the +product-picture labels, the payment prompt's refusal reason, and the second +half of the accessible-names patch — which are built and linted but not +driven. The set that did run was built into a +`sim` APK and put through the sixteen scenarios that touch patched code on one +emulator, with its coverage dumps kept apart (JaCoCo keys classes by a hash of +their bytecode, so two builds' dumps cannot be merged): + +``` +16 scenarios, 16 ok, 1 findings (1 serious) +``` + +Fifteen of the sixteen reported nothing at all, including the scenarios that +produce `fee-on-dead-transaction`, `mixed-amount-notation` and +`glued-currency` on an unpatched build. Two wallet-core operations that no +scenario could reach before — `getDonauStatements` and +`sendTalerUriMailboxMessage`, each behind one of the defects — are exercised by +that run. + +The one finding was the patch set's own fault and is now fixed: see "What +running it changed" in `release-error-screen-explains-nothing.md`, where the +first version of that patch put a wallet-core error-code *name* in front of a +release user. The rebuilt patch was re-run on the same scenario and is clean. + +The exceptions are the two camera patches. `qr-camera-ignores-the-plane-strides` +carries nine JVM unit tests, including five that encode a real QR code into a +synthetic camera frame and decode it back, so the pipeline is verified as far +as arithmetic goes — though still not against a real Android 14 camera. +`pos-config-scanner-asks-for-a-rotation-zxing-refuses` removes a call that +throws unconditionally, which `repro_pos_rotate_unsupported.java` shows in +three lines. Both findings list the attended tests that only a human with a +phone can run. + +| patch | what it changes | +| --- | --- | +| `config-change-locks-the-wallet-out-of-its-database` | `MainActivity` starts wallet-core only when it is not already running, which is the asymmetry that caused the 7001 "exclusive ownership" error screen | +| `reset-dialog-puts-the-wipe-where-cancel-belongs` | swaps the positive and negative buttons in the reset *and* import dialogs, so the destructive action is drawn on the right | +| `payto-link-only-accepts-iban` | `isSupportedPayToUri` delegates to `PaytoUri.parse`, so every target type the app models is accepted | +| `mailbox-payment-only-actionable-for-one-scheme` | one `talerUriAction`/`talerUriIsAction` helper in `Utils.kt`, used by the mailbox rows and the forward button instead of two hand-written prefix tests | +| `donation-statements-button-is-wired-to-nothing` | threads the donau host through `BalancesPagerComposable` and navigates to `DonauStatement`, with the setup screen as the fallback | +| `contacts-and-mailbox-cannot-be-translated` | moves 42 literals into `strings.xml` and references them with `stringResource` | +| `amounts-without-currency-specification` | passes the currency specification into the three transfer screens so `transferAmount` is formatted like every other amount | +| `aborted-credit-shows-the-whole-amount-as-fee` | adds `Transaction.feeIsMeaningful` and gates the inferred fee row on it in all four credit screens | +| `suspended-looks-like-completed-in-the-list` | shows the suspended and expired states in the transaction list, which said nothing for them | +| `release-error-screen-explains-nothing` | `userFacingMsg` falls back to the error code when there is neither a hint nor a message | +| `action-buttons-have-no-accessible-name` | merges `ActionButton`'s semantics, naming all seven action buttons at once, and names the button that leaves selection mode on the transactions screen | +| `mailbox-private-keys-written-to-log` | redacts the keys in `MailboxConfiguration.toString()` and downgrades two `Log.e` traces | +| `add-account-note-is-required-but-unmarked` | labels the field "Note (required)", beside the two that say "(optional)" | +| `unreachable-host-leaves-blank-retrying-purchase` | permits cleartext to `127.0.0.1` and `::1`, which are the same machine as `localhost` | +| `delete-transaction-requeries-deleted-id` | `TransactionManager` remembers the ids it deleted and skips their transition notifications, which is where the three 7052 requests came from | +| `payment-prompt-says-insufficient-without-the-reason` | the payment prompt reads `causeHint` like the peer screen already does, so a refusal the merchant caused stops being reported as the user's balance | +| `product-image-dialog-has-nothing-to-announce` | names the product thumbnail and the picture dialog, whose window had nothing in its accessibility tree at all | +| `qr-camera-ignores-the-plane-strides` | extracts the camera's luminance plane with `rowStride` and `pixelStride` honoured, deletes the hand-rolled rotation zxing never needed, closes the frame whatever happens to it, and moves the analysis off the UI thread — **with nine unit tests** | +| `pos-config-scanner-asks-for-a-rotation-zxing-refuses` | the terminal's own copy of that pipeline: drops a `rotateCounterClockwise()` that `PlanarYUVLuminanceSource` answers with `UnsupportedOperationException`, takes the row stride as zxing's `dataWidth`, and closes the frame in a `finally` | + +## Deliberately not patched + +* **`database-import-reports-only-in-a-toast`** — a snackbar, a dialog or a + "last imported" line in the settings would all work; which one fits the app's + voice is a product decision, and it should cover export and clear too. +* **`withdrawal-screen-never-recovers-from-an-exchange-outage`** — the screen + needs an error state and a way to re-prepare; both are design decisions about + what a failed withdrawal preparation should look like. +* **`multi-qr-transfer-screen-cannot-be-reached`** — the button, the navigation + flag and the screen variant are all gated on a transfer option with two QR + codes, and wallet-core's two encoders exclude each other by IBAN country. + Leaving it for a future encoder, routing the single-QR case through the same + screen, or deleting the variant are all defensible. +* **`refresh-transactions-are-never-listed`** — the app has the whole detail + screen for change transactions but never passes `includeRefreshes`, so + wallet-core withholds them. Showing them always, only in developer mode, or + only when one has failed is a product decision; the finding lays out the + three. +* **`dead-declarations-complete-list`** — the systematic list (19 declarations + and 383 lines in the wallet, 10 and 56 in the library) and coverage + recomputed without them: 80.8 % of reachable lines rather than 79.4 %. + Deletion is a decision about intent, per item. +* **`ui-with-no-callers`** — about 320 lines that nothing refers to: five + pieces of UI (one a second implementation of the add-contact screen) and + four helpers in `Utils.kt`, one of which is the only user of the app's two + WiFi permissions. Whether each is wired up or deleted is a decision about + intent; the unused `CHANGE_WIFI_STATE` is the part worth deciding first. +* **`alias-registration-hardcodes-the-directory`** — the fix is a new setting + (a `taldirBaseUrl` beside the donau one), which is a product decision about + where it belongs and what the default should be, not a mechanical change. +* **`a-failed-query-is-shown-as-an-empty-wallet`** and the empty-prompt half of + `unreachable-host-leaves-blank-retrying-purchase` — both need a loading and + an error state designed into several screens. +* **`refresh-fails-on-mixed-age-denominations`**, + `deposit-does-not-guard-zero-amounts`, `addglobalcurrencyexchange-null-masterpub` + — these are wallet-core (taler-typescript-core), not this repository. +* **`taldir-protocol-version-mismatch`** — one character in the taldir service, + in its own repository. +* **`error-code-registry-behind-wallet-core`** — `TalerErrorCode.kt` is + generated from the upstream registry; it wants a regeneration, not an edit. +* **`pos-confirmation-shows-five-codes`**, `purge-destroys-coins-and-history-without-saying-so`, + `wallet-lock-opens-when-the-credential-is-gone`, + `unknown-wire-method-hangs-the-deposit-form`, + `bitcoin-transfer-relabels-the-amount-as-btc`, + `dev-experiment-uri-exits-the-app`, + `add-payment-service-fails-silently`, + `word-currency-symbol-glued-to-amount` — each needs a decision I would be + guessing at: which TOTP code is the right one to show, what a purge should + warn, whether an absent credential should lock or open, and so on. The + findings say what is wrong and where; the choice is the maintainer's. +* **`contacts-and-mailbox-cannot-be-translated`** covers 42 of the 43 strings. + The last one, `ContactManager.kt:169`'s "Alias not found", is built into a + `TalerErrorInfo.message` by a class that has no `Context`; localising it + means mapping the code at the display site instead, which is a small design + choice rather than a substitution. diff --git a/wallet-simulator/findings/__pycache__/repro_untranslated_contacts_mailbox.cpython-313.pyc b/wallet-simulator/findings/__pycache__/repro_untranslated_contacts_mailbox.cpython-313.pyc Binary files differ. diff --git a/wallet-simulator/findings/a-failed-query-is-shown-as-an-empty-wallet.md b/wallet-simulator/findings/a-failed-query-is-shown-as-an-empty-wallet.md @@ -0,0 +1,139 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# A failed query is shown as an empty wallet + +Found by the `api_error_sweep` scenario, which makes one wallet-core call fail +per screen and reads what the screen then says. Four of the ten screens it +sweeps report nothing at all, and two of those four state the failure as a fact +about the user's money. + +**Severity: moderate.** No money is at risk, but the wallet tells the user +something untrue about their own wallet, and the only trace is in the log. + +## What happens + +The sweep injects `WALLET_UNEXPECTED_EXCEPTION` into one operation and then +opens the screen that calls it: + +| operation | screen | what it shows | +| --- | --- | --- | +| `getBalances` | main screen | the error, with "Export error diagnostics" | +| `getTransactionsV2` | transaction list | the error | +| `listBankAccounts` | Settings → Bank accounts | the error | +| `listDiscounts` | Discounts | the error | +| `listSubscriptions` | Passes | the error | +| `getExchangeTos` | PSP's terms of service | the error, with its own heading | +| `listExchanges` | Settings → Payment services | **nothing** — the list renders | +| `getContacts` | Contacts | **"No contacts yet."** | +| `getDepositWireTypes` | Deposit | **"No bank accounts saved in the wallet"** | +| `getMaxDepositAmount` | Deposit | **nothing** — the account list renders | +| `getMaxPeerPushDebitAmount` | Send | **"€0.00"**, and a "Send €0.00" button | +| `getWithdrawalDetailsForAmount` | Withdraw | **an empty screen** | +| `getCurrencySpecification` | main screen | **nothing** — amounts lose their symbol | + +Six of the thirteen are right: an `ErrorComposable` with the code, the hint and +a way to export diagnostics. The rest are the defect, and three of them are +worse than silence, because they state the failure as a fact about the user: + +* **Deposit** says the user has *no bank accounts*. They may well have + several; the wallet simply could not ask. +* **Contacts** says *"No contacts yet."*, the same way. +* **Send** says the user can send *nothing*, with a disabled-looking + "Send €0.00", on a wallet holding €9.87. + +## Why + +Both are the same shape — a nullable result, an error that only reaches the +log, and a caller that reads `null` as "nothing there": + +```kotlin +// wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt:166 +suspend fun getDepositWireTypes(…): GetDepositWireTypesResponse? { + var result: GetDepositWireTypesResponse? = null + api.request("getDepositWireTypes", …) + .onError { Log.e(TAG, "Error getDepositWireTypes $it") } + .onSuccess { result = it } + return result +} +``` + +```kotlin +// wallet/src/main/java/net/taler/wallet/peer/PeerManager.kt:215 +private suspend fun getMaxPeerPushDebitAmount(…): GetMaxPeerPushDebitAmountResponse? { + var response: GetMaxPeerPushDebitAmountResponse? = null + api.request("getMaxPeerPushDebitAmount", …) + .onError { error -> Log.e(TAG, "got getMaxPeerPushDebitAmount error result $error") } + .onSuccess { response = it } + return response +} +``` + +`PeerManager` alone has nine error handlers whose whole body is a `Log` call; +`grep -n 'onError' wallet/src/main/java/net/taler/wallet/*/*Manager.kt` shows +the shape across the rest. + +The `listExchanges` silence is the same defect as +[`add-payment-service-fails-silently.md`](add-payment-service-fails-silently.md) +seen from the other side: that finding is about `ExchangeManager` publishing +error channels nobody reads, and this is what the user sees when one of them +fires. The empty withdrawal prompt is +[`unreachable-host-leaves-blank-retrying-purchase.md`](unreachable-host-leaves-blank-retrying-purchase.md), +reached without a proxy — one injected error is enough. + +## Reproduce by hand + +Needs a debug build with **Developer mode** on, and a balance. + +1. Share this URI into the wallet (it fails the next four `getDepositWireTypes` + calls with code 7001): + + ```bash + adb shell am start -a android.intent.action.VIEW -d \ + 'taler+http://dev-experiment/api-error?operation=getDepositWireTypes&detail=eyJjb2RlIjogNzAwMSwgImhpbnQiOiAiaW5qZWN0ZWQifQ&count=4' + ``` + + (`detail` is base64url JSON: `{"code": 7001, "hint": "injected"}`.) + +2. On the main screen tap **Deposit**. The screen says "No bank accounts saved + in the wallet". +3. `adb logcat | grep getDepositWireTypes` shows the real reason. +4. The same with `operation=getMaxPeerPushDebitAmount` and the **Send** + button: the screen offers €0.00. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_failed_query_empty_state.py +SIM_WORKER=4 python3 suite.py api_error_sweep +``` + +The notes of the resulting `suite-w4-*-summary.json` list every screen with +"shows an error: True/False" and what was on it. + +## Suggested fix + +Distinguish "no data" from "could not ask". The managers already have the +`TalerErrorInfo`; the cheapest change that fixes all four is to give each of +these screens the same `state` treatment the balance list has — `Loading`, +`Success`, `Error` — rather than a nullable payload, so an error renders as +`ErrorComposable` instead of as an empty list or a zero amount. + +Where that is too much, the minimum is: do not claim a fact the wallet does +not have. "No bank accounts saved" and "€0.00" are both assertions; a failed +query should produce neither. diff --git a/wallet-simulator/findings/aborted-credit-shows-the-whole-amount-as-fee.diff b/wallet-simulator/findings/aborted-credit-shows-the-whole-amount-as-fee.diff @@ -0,0 +1,113 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullCredit.kt b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullCredit.kt +index a329a533..3478a6aa 100644 +--- a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullCredit.kt ++++ b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullCredit.kt +@@ -29,6 +29,7 @@ import net.taler.wallet.R + import net.taler.wallet.backend.TalerErrorCode.EXCHANGE_GENERIC_KYC_REQUIRED + import net.taler.wallet.backend.TalerErrorInfo + import net.taler.wallet.balances.ScopeInfo ++import net.taler.wallet.transactions.feeIsMeaningful + import net.taler.wallet.transactions.AmountType + import net.taler.wallet.transactions.PeerActions + import net.taler.wallet.transactions.PeerInfoShort +@@ -70,7 +71,7 @@ fun ColumnScope.TransactionPeerPullCreditComposable( + amountType = AmountType.Neutral, + ) + +- if (t.amountRaw > t.amountEffective) { ++ if (t.amountRaw > t.amountEffective && t.feeIsMeaningful) { + val fee = t.amountRaw - t.amountEffective + TransactionAmountComposable( + label = stringResource(id = R.string.amount_fee), +diff --git a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushCredit.kt b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushCredit.kt +index 34ab5606..3a8162aa 100644 +--- a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushCredit.kt ++++ b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushCredit.kt +@@ -28,6 +28,7 @@ import net.taler.wallet.R + import net.taler.wallet.backend.TalerErrorCode.EXCHANGE_GENERIC_KYC_REQUIRED + import net.taler.wallet.backend.TalerErrorInfo + import net.taler.wallet.balances.ScopeInfo ++import net.taler.wallet.transactions.feeIsMeaningful + import net.taler.wallet.transactions.AmountType + import net.taler.wallet.transactions.PeerActions + import net.taler.wallet.transactions.PeerInfoShort +@@ -55,7 +56,7 @@ fun ColumnScope.TransactionPeerPushCreditComposable( + amountType = AmountType.Neutral, + ) + +- if (t.amountRaw > t.amountEffective) { ++ if (t.amountRaw > t.amountEffective && t.feeIsMeaningful) { + val fee = t.amountRaw - t.amountEffective + TransactionAmountComposable( + label = stringResource(id = R.string.amount_fee), +diff --git a/wallet/src/main/java/net/taler/wallet/refund/TransactionRefundComposable.kt b/wallet/src/main/java/net/taler/wallet/refund/TransactionRefundComposable.kt +index f2f408cb..743bf4f2 100644 +--- a/wallet/src/main/java/net/taler/wallet/refund/TransactionRefundComposable.kt ++++ b/wallet/src/main/java/net/taler/wallet/refund/TransactionRefundComposable.kt +@@ -40,6 +40,7 @@ import net.taler.wallet.backend.TalerErrorCode + import net.taler.wallet.backend.TalerErrorInfo + import net.taler.wallet.balances.ScopeInfo + import net.taler.wallet.compose.TalerSurface ++import net.taler.wallet.transactions.feeIsMeaningful + import net.taler.wallet.transactions.AmountType + import net.taler.wallet.transactions.ErrorTransactionButton + import net.taler.wallet.transactions.TransactionAction +@@ -89,7 +90,7 @@ fun TransactionRefundComposable( + amountType = AmountType.Neutral, + ) + +- if (t.amountRaw > t.amountEffective) { ++ if (t.amountRaw > t.amountEffective && t.feeIsMeaningful) { + val fee = t.amountRaw - t.amountEffective + TransactionAmountComposable( + label = stringResource(id = R.string.amount_fee), +diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionState.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionState.kt +index 906bfbd7..c55cc54f 100644 +--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionState.kt ++++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionState.kt +@@ -185,3 +185,24 @@ object TransactionStateSerializer : KSerializer<TransactionState> { + }) + } + } ++ ++/** ++ * Whether the difference between a credit's raw and effective amounts is ++ * really a fee. ++ * ++ * The credit screens infer the fee as `amountRaw - amountEffective`, and for a ++ * transaction that never completed wallet-core reports an effective amount of ++ * zero -- so the inference claims the entire amount went to fees. An aborted ++ * €5.00 withdrawal read "Fee -€5.00 / Total €0.00" although nothing was ++ * withdrawn and no fee was charged. ++ */ ++val Transaction.feeIsMeaningful: Boolean ++ get() = when (txState.major) { ++ TransactionMajorState.Aborted, ++ TransactionMajorState.Aborting, ++ TransactionMajorState.SuspendedAborting, ++ TransactionMajorState.Failed, ++ TransactionMajorState.Expired, ++ TransactionMajorState.Deleted -> false ++ else -> true ++ } +diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/TransactionWithdrawalComposable.kt b/wallet/src/main/java/net/taler/wallet/withdraw/TransactionWithdrawalComposable.kt +index bc8bf4a4..73168e97 100644 +--- a/wallet/src/main/java/net/taler/wallet/withdraw/TransactionWithdrawalComposable.kt ++++ b/wallet/src/main/java/net/taler/wallet/withdraw/TransactionWithdrawalComposable.kt +@@ -52,6 +52,7 @@ import net.taler.wallet.backend.TalerErrorCode + import net.taler.wallet.backend.TalerErrorInfo + import net.taler.wallet.balances.ScopeInfo + import net.taler.wallet.cleanExchange ++import net.taler.wallet.transactions.feeIsMeaningful + import net.taler.wallet.transactions.AmountType + import net.taler.wallet.transactions.ErrorTransactionButton + import net.taler.wallet.transactions.TransactionAction +@@ -168,7 +169,7 @@ fun TransactionWithdrawalComposable( + ) + } + +- if (t.amountRaw > t.amountEffective) { ++ if (t.amountRaw > t.amountEffective && t.feeIsMeaningful) { + val fee = t.amountRaw - t.amountEffective + TransactionAmountComposable( + label = stringResource(id = R.string.amount_fee), diff --git a/wallet-simulator/findings/aborted-credit-shows-the-whole-amount-as-fee.md b/wallet-simulator/findings/aborted-credit-shows-the-whole-amount-as-fee.md @@ -0,0 +1,120 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# An aborted withdrawal says the whole amount went to fees + +Found in the notes of the `abort_then_retry` scenario: a withdrawal that was +aborted before the bank confirmed it reads + +``` +This transaction was aborted +Chosen amount €5.00 +Fee -€5.00 +Total amount €0.00 +``` + +Nothing was withdrawn and no fee was charged — the exchange never saw the +money — but the screen says the whole €5.00 was consumed by fees. + +**Severity: low-moderate.** Cosmetic in the sense that no money moved, but it +is alarming in exactly the situation where a user is already unsure what +happened, it is reachable in a release build by anyone who aborts a +withdrawal, and the same arithmetic is used on three further screens. + +## What happens + +The fee row is derived from the difference between the two amounts: + +```kotlin +// wallet/src/main/java/net/taler/wallet/withdraw/TransactionWithdrawalComposable.kt:171 +if (t.amountRaw > t.amountEffective) { + val fee = t.amountRaw - t.amountEffective + TransactionAmountComposable( + label = stringResource(id = R.string.amount_fee), + amount = fee.withSpec(spec), + amountType = AmountType.Negative, + ) +} +``` + +For a successful withdrawal that is right: `amountRaw` is what the bank sends, +`amountEffective` what lands in the wallet, and the difference is the +withdrawal fee. For an aborted one wallet-core reports `amountEffective` of +zero, and the difference becomes the entire amount. + +The same expression appears on every *credit* screen, so each of them makes +the same claim once its transaction is aborted or fails: + +- `withdraw/TransactionWithdrawalComposable.kt:171` +- `peer/TransactionPeerPushCredit.kt` +- `peer/TransactionPeerPullCredit.kt` +- `refund/TransactionRefundComposable.kt` + +The debit screens (payment, deposit, peer-push-debit, peer-pull-debit) use the +difference the other way round (`amountEffective > amountRaw`), which goes to +zero instead of to the full amount — an expired purchase correctly shows +"Total €1.00 / Paid €0.00" with no fee row at all. + +### An abandoned deposit: the same oracle, but probably not the same defect + +`abandon_aborting_deposit` trips the oracle on a *debit*, and it is recorded +here rather than as its own finding because it may well be correct. A deposit +submitted while offline, then aborted, then abandoned reads + +``` +This transaction has failed or been abandoned +Chosen amount €0.98 +Fee -€0.02 +Amount sent -€1.00 +``` + +and the money is genuinely gone — the balance went from €9.87 to €8.87 across +the abandon, which is what the confirmation dialog promises ("Funds still in +transit WILL GET LOST"). So "Amount sent −€1.00" is true. + +What is doubtful is the **fee row**: the exchange never completed the deposit, +so it earned no €0.02 deposit fee; the whole €1.00 was lost in transit, not +split between a fee and a transfer. If that reading is right the screen should +show the loss as a loss rather than as a fee and a payment. A maintainer can +judge that faster than this campaign can — it is recorded, with the balances +either side, rather than asserted. + +## Reproduce by hand + +1. On the main screen tap **Withdraw**, or follow a bank's withdrawal URI. +2. Confirm the withdrawal, so the wallet is waiting for the bank. +3. Tap **Abort**, and confirm. +4. The transaction now reads "This transaction was aborted", with + "Fee −€5.00" and "Total amount €0.00" under a "Chosen amount" of €5.00. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_aborted_fee.py # worker 0 by default +SIM_WORKER=4 python3 suite.py withdraw_abort # the scenario notes it too +``` + +## Suggested fix + +Show the fee row only when the difference is a fee: either gate it on the +transaction's state (`txState.major` of `Pending` or `Done`, not `Aborted`, +`Failed` or `Expired`), or, better, take the fee from the withdrawal's own +details rather than inferring it — wallet-core reports the fee structure, and +inferring it from two amounts means every state where one of them is zeroed +produces a wrong number. The same change applies to the three other credit +screens. diff --git a/wallet-simulator/findings/action-buttons-have-no-accessible-name.diff b/wallet-simulator/findings/action-buttons-have-no-accessible-name.diff @@ -0,0 +1,61 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/compose/ActionButton.kt b/wallet/src/main/java/net/taler/wallet/compose/ActionButton.kt +index 86f3786e..3c0db806 100644 +--- a/wallet/src/main/java/net/taler/wallet/compose/ActionButton.kt ++++ b/wallet/src/main/java/net/taler/wallet/compose/ActionButton.kt +@@ -29,6 +29,7 @@ import androidx.compose.ui.Alignment + import androidx.compose.ui.Modifier + import androidx.compose.ui.graphics.Color + import androidx.compose.ui.graphics.Shape ++import androidx.compose.ui.semantics.semantics + import androidx.compose.ui.text.style.TextAlign + import androidx.compose.ui.unit.dp + +@@ -44,7 +45,15 @@ fun ActionButton( + labelColor: Color = MaterialTheme.colorScheme.onPrimaryContainer, + enabled: Boolean = true, + ) { +- Column(modifier, horizontalAlignment = Alignment.CenterHorizontally) { ++ // One accessibility node for the icon and its label together: the icon ++ // carries no description (right for decoration, but it is the only thing ++ // inside the button), so without this the control is announced as ++ // "Button" with no name, and the label is a separate focus stop. Merging ++ // here fixes every caller at once, and makes the whole column the target. ++ Column( ++ modifier.semantics(mergeDescendants = true) {}, ++ horizontalAlignment = Alignment.CenterHorizontally, ++ ) { + FloatingActionButton( + onClick = if (enabled) onClick else {{}}, + shape = shape, +diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionsScreen.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionsScreen.kt +index a08133df..ff9e4d8d 100644 +--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionsScreen.kt ++++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionsScreen.kt +@@ -116,7 +116,14 @@ fun TransactionsScreen( + }) { + Icon( + imageVector = Icons.Rounded.Close, +- contentDescription = null, ++ // The only way out of selection mode, and the only ++ // thing in the button: without a description it is ++ // announced as an unnamed button, and a screen reader ++ // user has no way to tell it from the back arrow it ++ // replaces. ++ contentDescription = stringResource( ++ R.string.transactions_leave_selection, ++ ), + ) + } + } +diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml +index 905e4390..219246b9 100644 +--- a/wallet/src/main/res/values/strings.xml ++++ b/wallet/src/main/res/values/strings.xml +@@ -227,6 +227,7 @@ GNU Taler is immune to many types of fraud such as credit card data theft, phish + <string name="transactions_retry">Retry</string> + <string name="transactions_required_kyc">KYC required to proceed</string> + <string name="transactions_select_all">Select All</string> ++ <string name="transactions_leave_selection">Leave selection mode</string> + <string name="transactions_send_funds">Send</string> + <string name="transactions_suspend">Suspend</string> + <string name="transactions_title">Transactions</string> diff --git a/wallet-simulator/findings/action-buttons-have-no-accessible-name.md b/wallet-simulator/findings/action-buttons-have-no-accessible-name.md @@ -0,0 +1,162 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Unnamed controls: the seven action buttons, and the way out of selection mode + +Found while teaching the simulator to tap them: the taps did nothing, because +the label a sighted user reads is not part of the button at all. A screen +reader has the same problem. + +**Severity: moderate, and it affects release builds** — these are the wallet's +primary actions, and they are unusable with TalkBack. + +All seven buttons on the main screen are the same `ActionButton`: Send, +Request, Withdraw, Deposit, and -- further down -- Discounts, Passes and +Donation statements (`balances/BalancesPagerComposable.kt`, seven call sites). +Every other floating action button in the app does set a +`contentDescription`, so this one composable is the whole defect. + +## What happens + +On the main screen the balance card shows four buttons. Each one is a +`FloatingActionButton` holding only an icon, with the text in a *sibling* +`Text` below it: + +``` +Button clickable=true text='' content-desc='' bounds=[332,887][479,1034] +TextView clickable=false text='Request' bounds=[338,1050][473,1103] +``` + +So the clickable element has no name and the name is not clickable. TalkBack +announces the button as just "Button, double tap to activate"; the label is +read separately as static text, with nothing tying the two together. + +Seven clickable nodes on the main screen have no accessible name of their own +*and* no labelled descendant to inherit one from — these four among them. (A +clickable wrapper whose label is a child is fine: Compose merges the semantics +and TalkBack reads the child. Only a label that is merely a *neighbour*, as +here, is lost.) + +## The same omission on the transactions screen + +Found later, while driving the dedicated transactions screen's selection mode: +the button that leaves selection mode is unnamed too. + +```kotlin +// wallet/src/main/java/net/taler/wallet/transactions/TransactionsScreen.kt:111 +navigationIcon = if (selectionMode) { + { + IconButton(onClick = { selectionMode = false; selectedItems.clear() }) { + Icon(imageVector = Icons.Rounded.Close, contentDescription = null) + } + } +} else null, +``` + +It is the only way out of selection mode and the only thing inside the button, +and it sits where the back arrow normally is — so a screen reader user is told +there is a button, not what it does or that it has replaced the back arrow. +"Select All" beside it *is* described, which is what makes the omission look +like an oversight rather than a decision. + +The simulator had to find it by position for the same reason: + +``` +- 1 unnamed clickable(s) in the app bar: [(12, 150, 138, 276)] +``` + +The patch gives it `R.string.transactions_leave_selection` +("Leave selection mode"), beside the existing `transactions_select_all`. + +## Reproduce by hand + +With TalkBack, as a user would hit it: + +1. Install the wallet and get a balance into it (withdraw once — against the + local stack, or `Settings → Withdraw demo KUDOS` on a debug build). +2. Enable TalkBack (Settings → Accessibility → TalkBack on the device). +3. Go to the wallet's main screen and swipe right repeatedly to move the + accessibility focus along the balance card. +4. Focus lands on four buttons in a row. Each is announced as an unnamed + button; the words "Send", "Request", "Withdraw", "Deposit" are announced as + separate text, after or before the button they belong to. + +Without TalkBack, from a shell — the same thing, in the accessibility tree: + +```bash +adb shell uiautomator dump /sdcard/ui.xml +adb exec-out cat /sdcard/ui.xml | tr '>' '>\n' | grep -E 'Button|Request' +``` + +The `android.widget.Button` nodes carry `text=""` and `content-desc=""`, while +the `Request` text sits in a non-clickable `TextView` underneath. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_action_buttons_no_a11y_name.py --fund +``` + +Prints each label, the button it really belongs to and that button's +accessible name, then `reproduced: True`. + +## Why + +`compose/ActionButton.kt:47` builds a `Column` of a `FloatingActionButton` and +a label, and every caller passes an icon with no description +(`BalancesPagerComposable.kt:651` and the three below it): + +```kotlin +ActionButton( + icon = { Icon(Icons.AutoMirrored.Default.ArrowForward, contentDescription = null) }, + label = { Text(stringResource(R.string.transactions_send_funds)) }, + ... +) +``` + +`contentDescription = null` is right for a decorative icon *inside* a named +control, but here it is the only thing in the control, so the control ends up +nameless. + +## Suggested fix + +Merge the column's semantics so the label names the button, in `ActionButton` +itself rather than in each of the four call sites: + +```kotlin +Column( + modifier.semantics(mergeDescendants = true) {}, + horizontalAlignment = Alignment.CenterHorizontally, +) { +``` + +That gives the whole column one accessibility node named after the label, which +also makes the much larger column the touch target. Passing the label string as +the icon's `contentDescription` would fix the announcement too, but leaves the +label as a second, redundant focus stop. + +One change covers all seven, which is why it belongs in `ActionButton`: the +Discounts / Passes / Donation statements row is built from the same composable, +and the main screen's QR scanner FAB, the exchange list's, the contact list's +and the bank account list's all set a `contentDescription` already. + +The second half of the patch is the one-line omission on the transactions +screen, with `transactions_leave_selection` ("Leave selection mode") added +beside `transactions_select_all` in `strings.xml`. Verified together: +`:wallet:compileFdroidDebugKotlin` and `:wallet:lintFdroidDebug` clean, and all +nineteen patches still apply together and build. diff --git a/wallet-simulator/findings/add-account-note-is-required-but-unmarked.diff b/wallet-simulator/findings/add-account-note-is-required-but-unmarked.diff @@ -0,0 +1,13 @@ +diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml +index 905e4390..bcb01841 100644 +--- a/wallet/src/main/res/values/strings.xml ++++ b/wallet/src/main/res/values/strings.xml +@@ -348,7 +348,7 @@ GNU Taler is immune to many types of fraud such as credit card data theft, phish + <string name="send_deposit_account_edit">Edit account</string> + <string name="send_deposit_account_forget_dialog_message">Do you really wish to forget this account in the wallet?</string> + <string name="send_deposit_account_forget_dialog_title">Forget account</string> +- <string name="send_deposit_account_note">Note</string> ++ <string name="send_deposit_account_note">Note (required)</string> + <string name="send_deposit_account_manage">Manage bank accounts</string> + <string name="send_deposit_account_warning">You must enter an account that you control, otherwise you will not be able to fulfill the regulatory requirements.</string> + <string name="send_deposit_bitcoin">Bitcoin</string> diff --git a/wallet-simulator/findings/add-account-note-is-required-but-unmarked.md b/wallet-simulator/findings/add-account-note-is-required-but-unmarked.md @@ -0,0 +1,116 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# "Add account" is disabled until you fill a field called "Note" + +Found the slow way: two of this campaign's scenarios had been filling the +add-account form correctly, submitting, and reporting success for rounds on end +without ever adding an account. The button was disabled the whole time and +nothing on the screen said why. + +**Severity: low**, but it costs the user the whole feature until they guess. + +## What happens + +Open **Settings → Bank accounts → Add account**, pick **IBAN**, and fill in the +two fields that look like the form: + +``` +Account holder Test Holder +IBAN DE89370400440532013000 +Postal code (optional) +Town (optional) +Note +``` + +**Add account** stays greyed out. There is no message, and the two fields that +*are* optional say so in their labels — which is exactly what makes "Note" read +as optional too. Typing anything into it enables the button. + +## Why + +The submit button requires the note, which the form calls an alias internally: + +```kotlin +// wallet/src/main/java/net/taler/wallet/accounts/AddAccountComposable.kt:245 +enabled = !formError && formAlias.isNotBlank(), +``` + +```kotlin +// wallet/src/main/java/net/taler/wallet/accounts/AddAccountComposable.kt:229 +OutlinedTextField( + value = formAlias, + … + label = { Text(stringResource(R.string.send_deposit_account_note)) }, + isError = formAlias.isBlank(), +) +``` + +and the label is the bare word: + +```xml +<!-- res/values/strings.xml:351 --> +<string name="send_deposit_account_note">Note</string> +``` + +while the genuinely optional fields are explicit: + +```xml +<!-- res/values/strings.xml:373,377 --> +<string name="send_deposit_postal_code">Postal code (optional)</string> +<string name="send_deposit_town">Town (optional)</string> +``` + +The field does get an error outline (`isError = formAlias.isBlank()`), but it +has that outline from the moment the form opens, before the user has done +anything wrong, so it reads as decoration rather than as a complaint. + +It applies to every account type: `formAlias` is in the parent composable, so +IBAN, x-taler-bank and Bitcoin accounts all need it. + +## Reproduce by hand + +1. **Settings → Bank accounts → Add account**. +2. Choose **IBAN**, type a holder name and `DE89370400440532013000`. +3. **Add account** is disabled. Nothing explains it. +4. Type one character into **Note** — the button enables. + +Expected: the label says the field is required (or the button explains what is +missing), consistently with the "(optional)" labels beside it. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=0 python3 -u suite.py bank_accounts deposit_methods +``` + +Both scenarios now fill the note and check that the account appears in the +list; before they did not, and both passed while adding nothing — which is the +same vacuous-pass pattern as +[`payto-link-only-accepts-iban.md`](payto-link-only-accepts-iban.md). + +## Suggested fix + +Either label it `Note (required)` / `Account name`, or drop the requirement and +fall back to something derived from the account (the IBAN, the Bitcoin address, +the x-taler-bank account name) when the user leaves it blank — the label is +stored as `KnownBankAccountInfo.label` and only used for display, so a +sensible default costs nothing. + +Whichever way, a disabled button with no explanation is the part to remove: if +the form cannot be submitted, it should say what is missing. diff --git a/wallet-simulator/findings/add-payment-service-fails-silently.md b/wallet-simulator/findings/add-payment-service-fails-silently.md @@ -0,0 +1,147 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Payment-service failures are never shown: four error channels have no observer + +Found by the `exchange_url_fuzz` scenario, which fed twelve hostile addresses +to Settings → Payment services → **Add payment service**. Every rejection +looked identical to the user: the dialog closes and the list comes back +unchanged. + +**Severity: moderate.** This is not developer-mode gated — "Payment services" +is in the ordinary settings list. A mistyped address is indistinguishable from +one that is still being added, since a *successful* add also takes several +seconds to appear in the list. + +The same gap covers the whole screen, not just adding: `ExchangeManager` +publishes four error channels and **none of them has a reader**, so failures to +add, list, delete or reload a payment service are all silent. + +## What happens + +Entering `file:///etc/passwd` and tapping OK: the dialog closes, nothing is +shown at +0.6 s, +1.5 s or +3 s, and no payment service is added. wallet-core +did reject it, in the log only: + +``` +{"type":"error","operation":"addExchange","id":109, + "error":{"code":7048,"detail":"scheme \"file:\" is not supported, expected \"https:\""}} +{"type":"error","operation":"addExchange","id":100, + "error":{"code":7048,"detail":"URL cannot be parsed"}} +``` + +For contrast, a good address does work — `http://localhost:8081/` appears in +the list as "Currency: EUR" — but only after a few seconds, which is why the +silence is misleading rather than merely untidy. + +Injecting a failure into the operation behind the *list* shows the same thing +from the other side: with `listExchanges` made to fail +(`taler://dev-experiment/api-error?operation=listExchanges&…`), Settings → +Payment services renders its list as if nothing had happened. Whatever it +shows is whatever it had before; the user is given no reason to doubt it. + +The same silence covers the case that matters most in practice: a *well-formed* +address that simply cannot be reached. Adding `http://localhost:8091/` on a +device where nothing answers on that port behaves exactly like adding nothing +at all — the screen returns to the list, the service is absent, and the user is +given no reason to suspect a network problem rather than a typo. This was +noticed the other way round: a simulator scenario that adds a second payment +service "passed" while silently achieving nothing, because the port had not +been routed into the emulator. + +## Reproduce by hand + +1. Open the wallet, go to **Settings → Payment services**. +2. Tap **Add payment service**. +3. Type `file:///etc/passwd` (or `not a url`, or `http://`) and tap **OK**. +4. The dialog closes. Nothing else happens — no message, no entry in the list. + `adb logcat | grep addExchange` shows the rejection. + +Expected: the dialog stays open with the reason, or an error is shown — the +string for it already exists. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_add_exchange_fails_silently.py +``` + +## Why + +`ExchangeManager.add()` does publish the error +(`exchanges/ExchangeManager.kt:97-112`): + +```kotlin +}.onError { + Log.e(TAG, "Error adding exchange: $it") + mProgress.value = false + mAddError.value = it.toEvent() +} +``` + +but `addError` has no observer anywhere in the app — and neither do its three +siblings: + +| Channel | Set when | Readers | +| --- | --- | --- | +| `addError` (`ExchangeManager.kt:58`) | `addExchange` fails | none | +| `listError` (`:61`) | listing exchanges fails | none | +| `deleteError` (`:64`) | deleting one fails | none | +| `reloadError` (`:67`) | reloading one fails | none | + +```console +$ grep -rn "addError\|deleteError\|listError\|reloadError" \ + --include=*.kt wallet/src/main/java | grep -v "private val m" +wallet/.../ExchangeManager.kt:58: val addError: LiveData<Event<TalerErrorInfo>> = mAddError +wallet/.../ExchangeManager.kt:61: val listError: LiveData<Event<TalerErrorInfo>> = mListError +wallet/.../ExchangeManager.kt:64: val deleteError: LiveData<Event<TalerErrorInfo>> = mDeleteError +wallet/.../ExchangeManager.kt:67: val reloadError: LiveData<Event<TalerErrorInfo>> = mReloadError +``` + +Four declarations, no readers. Two matching string resources exist and are +never referenced either — `R.string.exchange_add_error` ("Could not add +payment service") and `R.string.exchange_list_error` ("Could not list payment +services") — so the error path was designed and then left unwired. There are no +strings at all for the delete and reload cases. + +`ExchangeListScreen.kt:136` also closes the dialog immediately +(`exchangeManager.add(url); showAddDialog = false`), before the asynchronous +call has any result to report. + +## Suggested fix + +Observe all four channels on the exchange list and show them — the screen +already has a snackbar host, and two of the strings are waiting (the delete and +reload cases need new ones). Keeping the add dialog open while `progress` is +true, and closing it only on success, would also tell the user that something +is happening during the seconds a good address takes. + +A lint rule or a small test asserting that every `*Error` channel a manager +exposes is collected somewhere would stop this class of defect coming back. +A sweep of every manager in `wallet/src/main/java` found no others: + +```console +$ for f in wallet/src/main/java/net/taler/wallet/*/[A-Z]*Manager.kt; do … +ExchangeManager.addError has no readers +ExchangeManager.deleteError has no readers +ExchangeManager.listError has no readers +ExchangeManager.reloadError has no readers +``` + +so this is a local lapse rather than a habit, and fixing the exchange list +closes the class. diff --git a/wallet-simulator/findings/addglobalcurrencyexchange-null-masterpub.md b/wallet-simulator/findings/addglobalcurrencyexchange-null-masterpub.md @@ -0,0 +1,154 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# "Treat as global" raises WALLET_UNEXPECTED_EXCEPTION on an un-contacted exchange + +Found by `simulator/driver/explore.py` (seed 11, step 34); reproducer in +`repro_global_currency_null_masterpub.py` (4 taps from a fresh profile). + +**Severity: low-moderate.** The menu entry sits inside `if (devMode)` in +`ExchangeListScreen.kt:231`, so only developer mode shows it. What it costs is a +feature that silently does not work plus a spurious +`WALLET_UNEXPECTED_EXCEPTION` in the logs, which is noise when triaging real +problems. + +## Reproduce by hand + +No local Taler deployment is needed: any payment service the wallet has not +contacted yet will do, and the wallet ships several as built-ins. + +1. Install a debug build of the wallet (`./gradlew :wallet:installFdroidDebug`) + on a device or emulator, or use a release build and skip to step 2 with + developer mode already on. +2. Open the app, go to **Settings** and switch **Developer mode** on. (A fresh + profile always starts with it off, whatever `BuildConfig.DEBUG` is: the + persisted value is pushed into the view model at every start.) +3. Settings → **Payment services**. The list contains built-ins the wallet has + never talked to, for example `exchange.taler-ops.ch`. Do not tap the entry + itself — contacting it would fetch its keys and fill in the missing field. +4. Tap the **⋮ menu** next to `exchange.taler-ops.ch`. +5. Tap **Treat as global**. + +Nothing happens on screen. With `adb logcat | grep addGlobalCurrencyExchange` +running, the request and its error are visible: + +``` +E taler-wallet: got addGlobalCurrencyExchange error: + TalerErrorInfo(code=WALLET_UNEXPECTED_EXCEPTION, + hint=unexpected exception (message: expected string at + (AddGlobalCurrencyExchangeRequest).exchangeMasterPub but got undefined), ...) +``` + +Expected instead: either the entry is not offered for an exchange whose keys +have not been fetched, or tapping it reports a plain, explained failure. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver && python3 ../findings/repro_global_currency_null_masterpub.py +``` + +Exits 0 and prints `reproduced: True` when the internal error appears. + +## What happens + +Settings → Payment services → ⋮ on an exchange the wallet has never contacted +→ **Treat as global**. wallet-core rejects the request: + +``` +code 7001 (WALLET_UNEXPECTED_EXCEPTION) +hint unexpected exception (message: expected string at + (AddGlobalCurrencyExchangeRequest).exchangeMasterPub but got undefined) +stack at _DecodingError … at decode … at dispatchRequestInternal +``` + +Nothing is shown to the user: the action silently does nothing, and the only +trace is the error in logcat. + +## Why + +`ExchangeItem.masterPub` is nullable and starts out null — it is only filled in +once the exchange's `/keys` has been fetched (`Exchanges.kt:33`): + +```kotlin +val masterPub: String? = null, +``` + +`BalanceManager.addGlobalCurrencyExchange` puts it into the request +unconditionally (`BalanceManager.kt:137`): + +```kotlin +api.request<Unit>("addGlobalCurrencyExchange") { + put("currency", currency) + put("exchangeBaseUrl", exchange.exchangeBaseUrl) + put("exchangeMasterPub", exchange.masterPub) // null -> key removed +} +``` + +`org.json.JSONObject.put(String, String?)` *removes* the key when the value is +null rather than storing JSON null, so wallet-core receives a request with no +`exchangeMasterPub` at all and fails to decode it. The failure is reported as +an unexpected exception because a missing required field is, from core's point +of view, a client bug. + +Confirmed from the other side, which pins the precondition exactly: with the +exchange **contacted first** -- its terms accepted and "Reload information" +tapped, so `/keys` has been fetched and `masterPub` is set -- the same menu +entry works. The currency scope then forms across both services, and the +"Where to pay" screen that only exists for a scope with more than one shopping +URL renders: + +``` +- the shopping screen: ['Your payment service offers the following website(s) …', + 'http://localhost:8080/config?shop=one', + 'http://localhost:8080/config?shop=two'] +- 2 shopping URLs listed +``` + +So this is not "treat as global is broken"; it is "treat as global is broken +for an exchange that has been added but not yet talked to", which is exactly +the state an exchange is in right after being added by URL. That is also why +`balances_two_exchanges` reached nothing for several rounds: it treated both +services as global straight after adding the second one. + +Two further places make it invisible rather than merely broken: + +* `removeGlobalCurrencyExchange` (`BalanceManager.kt:154`) has the identical + null-`masterPub` problem. +* `ExchangeListScreen.kt:356` discards both callbacks + (`onSuccess = {}, onError = {}`), so neither outcome reaches the UI. + +## Suggested fix + +Treat a null `masterPub` as "not possible yet" rather than passing it on: have +`ExchangeAction.GlobalAdd`/`GlobalDelete` bail out (or reload the exchange +first) when `exchange.masterPub == null`, and hide or disable the menu entry in +that state. Surfacing the error through `onError` would at least make it +visible, but the request should not be sent in the first place. + +A fix in the UI only is enough for the user-visible symptom; the underlying +sharp edge — `JSONObject.put` dropping null-valued keys, turning a nullable +Kotlin field into a missing required field — is worth checking across the other +`api.request { put(...) }` call sites. A sweep of all of them found every other +nullable argument guarded (`restrictAge?.let { put(…) }`, +`status.exchangeBaseUrl ?: error("no exchangeBaseUrl")`), so +`addGlobalCurrencyExchange` and `removeGlobalCurrencyExchange` are the only two +that pass a nullable straight through. + +The same sweep found `ExchangeListScreen.kt:361` and `:369` to be the only two +places in the app that discard an error callback with `onError = {}` — both of +them this feature. diff --git a/wallet-simulator/findings/alias-registration-hardcodes-the-directory.md b/wallet-simulator/findings/alias-registration-hardcodes-the-directory.md @@ -0,0 +1,143 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Alias registration and contact lookup hard-code a production directory + +Found while trying to cover the `net.taler.wallet.contacts` package: its forms +render and can be filled in (`AliasRegistrationScreen` is 60 % covered), but +nothing past the "Register Alias" button can work against a test or +self-hosted deployment, because the directory it talks to is a literal. + +**Severity: low** as a defect. The consequences are that a self-hosted Taler +deployment cannot have its own directory, and that three wallet-core +operations — `registerAlias`, `completeRegisterAlias`, `lookupAlias` — have no +reachable success path, which is why `contacts` is the least covered package in +the app (442 of its 827 instrumented lines missed). + +## What happens + +The Taler directory (taldir) base URL is a literal in two places: + +```kotlin +// wallet/src/main/java/net/taler/wallet/contacts/AliasRegistrationScreen.kt:100 +val taldirBaseUri = "https://taldir.gnunet.org" +``` + +```kotlin +// wallet/src/main/java/net/taler/wallet/contacts/ContactManager.kt:155,196,222 +taldirBaseUri: String = "https://taldir.gnunet.org", +``` + +`ContactScreen.kt:244` calls `taldirLookupAlias(alias, aliasType)` without the +parameter, so the default applies there too. Nothing in the app — not +developer mode, not the settings screen, not a `taler://` URI — can change it: +`grep -rn taldir wallet/src taler-kotlin-android/src` finds matches only inside +`contacts/`, and there is no `BuildConfig` field, resource or preference for it. + +Every other service the wallet talks to is chosen at runtime: exchanges are +added by URL in Settings, the merchant comes from the pay URI, the bank from +the withdrawal URI, donau from its own settings screen. + +## Why it matters + +1. **Nothing can exercise the second half of these screens.** The form renders + and validates locally, but registering an alias or looking one up always + goes to `taldir.gnunet.org`, so the simulator (and any CI, and any hand test + on a device) either talks to a production service or gets an error. The + challenge step, the completion step and every success state behind them stay + unreachable, as do the operations that drive them. +2. **A self-hosted Taler deployment cannot use it.** An operator who runs their + own exchange, bank and directory still has their users' wallets registering + aliases in GNUnet's directory. +3. **In developer mode it is the one URL that stays remote.** Dev mode exists + to point the wallet at a local stack; this screen ignores that. + +## How it was established + +The two literals are the whole story on the app side: + +```bash +cd taler-android +grep -rn 'taldir' --include=*.kt --include=*.xml wallet/src taler-kotlin-android/src +``` + +### And everything behind them works + +A real directory was then deployed beside the simulator's stack +(`git://git.taler.net/taldir`, a Go service; see +`simulator/backend/services/README.md`) and driven through wallet-core +directly, which *does* take the base URL as a parameter: + +``` +registerAlias -> {} (202 Accepted) + the validator recorded the challenge: J34V6DZG18X6EV0DFHQGDDGNJC +completeRegisterAlias -> {} +lookupAlias -> {"targetUri": "http://127.0.0.1:11000/SIMADDRESS"} +``` + +All three operations — the ones this campaign could never reach from the app — +round-trip on the first attempt. So the feature is not unfinished and the +protocol is not the problem: the app simply cannot be pointed at a directory. +Everything from the "Register Alias" button onwards is unreachable for want of +a URL field. + +### And then through the app itself, with the URL untouched + +To be sure the operations were not just working *beside* the app, the emulator +was made to answer for the hard-coded name — a hosts entry, the device's port +443 forwarded to a TLS front end, and the front end's CA trusted by the +simulator's own build type (`simulator/tls/README.md`). No URL in the app was +changed. The shipped code path then ran end to end: + +``` +POST taldir.gnunet.org/register/email <- the "Register Alias" button + the directory recorded: 285JEWK0894595KHSQSVYZW5E4 +POST taldir.gnunet.org/FAVWP84VPPY4… <- the challenge, typed in +GET taldir.gnunet.org/FAVWP84VPPY4… <- "Lookup with Taldir" +``` + +and the screens followed it exactly as designed: + +``` +the form: ['email', 'Alias Type', 'Alias', '12', 'Duration (months)', 'Register Alias'] +after registering: ['Challenge Solution', 'OK', 'Alias Registration'] +after completing: ['Registration successful!', 'OK', 'Alias Registration'] +after the lookup: ['Add Contact', 'Looked up', 'Petname', 'sim-w4-…@example.com', + 'https://mailbox.gnunet.org/CFEF11D10YTNNM6G…', 'Mailbox', 'OK'] +``` + +Not one finding came out of it: register, challenge, complete and look up all +work, and the lookup even fills the new contact's mailbox address in for the +user. **The hard-coded URL is the only thing wrong with this feature**, and it +is what keeps all of that out of reach of any test and any self-hosted +deployment. + +(Two caveats from doing it: the deployed taldir's `/config` hard-codes +protocol `0:0:0` while wallet-core's client declares `1:0:0` and refuses an +incompatible server, so the version had to be patched locally before anything +worked — see +[`taldir-protocol-version-mismatch.md`](taldir-protocol-version-mismatch.md). +And wallet-core resolved `localhost` to `::1` while the service listened on +`127.0.0.1`, so the URL has to be numeric.) + +## Suggested fix + +Give the directory the same treatment as donau: a `taldirBaseUrl` setting with +`https://taldir.gnunet.org` as its default, read by `ContactManager` and passed +down to `AliasRegistrationScreen`, and settable from the settings screen (or at +least from developer mode). A `BuildConfig` field with the same default would +already be enough to make the screens testable; a setting is what makes +self-hosting work. diff --git a/wallet-simulator/findings/amounts-without-currency-specification.diff b/wallet-simulator/findings/amounts-without-currency-specification.diff @@ -0,0 +1,182 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/transfer/ScreenTransfer.kt b/wallet/src/main/java/net/taler/wallet/transfer/ScreenTransfer.kt +index 940fc43a..5ba1db28 100644 +--- a/wallet/src/main/java/net/taler/wallet/transfer/ScreenTransfer.kt ++++ b/wallet/src/main/java/net/taler/wallet/transfer/ScreenTransfer.kt +@@ -135,17 +135,20 @@ fun ScreenTransfer( + transfer = transfer, + transactionAmountEffective = transfer.amountEffective.withSpec(spec), + transferContext = transferContext, ++ spec = spec, + ) + + is TransferData.IBAN -> TransferIBAN( + transfer = transfer, + transactionAmountEffective = transfer.amountEffective.withSpec(spec), + transferContext = transferContext, ++ spec = spec, + ) + + is TransferData.Cyclos -> TransferCyclos( + transfer = transfer, + transactionAmountEffective = transfer.amountEffective.withSpec(spec), ++ spec = spec, + ) + + is TransferData.Bitcoin -> TransferBitcoin( +diff --git a/wallet/src/main/java/net/taler/wallet/transfer/TransferCyclos.kt b/wallet/src/main/java/net/taler/wallet/transfer/TransferCyclos.kt +index 159fa43c..e1c72909 100644 +--- a/wallet/src/main/java/net/taler/wallet/transfer/TransferCyclos.kt ++++ b/wallet/src/main/java/net/taler/wallet/transfer/TransferCyclos.kt +@@ -27,6 +27,7 @@ import androidx.compose.ui.Modifier + import androidx.compose.ui.res.stringResource + import androidx.compose.ui.unit.dp + import net.taler.common.Amount ++import net.taler.common.CurrencySpecification + import net.taler.wallet.R + import net.taler.wallet.compose.WarningLabel + import net.taler.wallet.withdraw.TransferData +@@ -36,6 +37,7 @@ fun TransferCyclos( + transfer: TransferData.Cyclos, + transactionAmountEffective: Amount, + // TODO: transferContext? ++ spec: CurrencySpecification?, + ) { + Column( + modifier = Modifier.padding(all = 16.dp), +@@ -44,7 +46,7 @@ fun TransferCyclos( + Text( + stringResource( + R.string.withdraw_manual_ready_intro, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + transactionAmountEffective, + ), + style = MaterialTheme.typography.bodyLarge, +@@ -72,7 +74,7 @@ fun TransferCyclos( + ) + + WithdrawalAmountTransfer( +- conversionAmountRaw = transfer.transferAmount, ++ conversionAmountRaw = transfer.transferAmount.withSpec(spec), + ) + + TransferStep(2, stringResource(R.string.withdraw_manual_step_subject)) +@@ -94,7 +96,7 @@ fun TransferCyclos( + TransferStep(3, + stringResource( + R.string.withdraw_manual_step_finish, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + ), + ) + } +diff --git a/wallet/src/main/java/net/taler/wallet/transfer/TransferIBAN.kt b/wallet/src/main/java/net/taler/wallet/transfer/TransferIBAN.kt +index dc9ad5c8..dfc11ea6 100644 +--- a/wallet/src/main/java/net/taler/wallet/transfer/TransferIBAN.kt ++++ b/wallet/src/main/java/net/taler/wallet/transfer/TransferIBAN.kt +@@ -29,6 +29,7 @@ import androidx.compose.ui.Modifier + import androidx.compose.ui.res.stringResource + import androidx.compose.ui.unit.dp + import net.taler.common.Amount ++import net.taler.common.CurrencySpecification + import net.taler.common.TalerUtils + import net.taler.wallet.R + import net.taler.wallet.accounts.PaytoUri +@@ -44,6 +45,7 @@ fun TransferIBAN( + transfer: TransferData.IBAN, + transactionAmountEffective: Amount, + transferContext: TransferContext, ++ spec: CurrencySpecification?, + ) { + Column( + modifier = Modifier.padding(all = 16.dp), +@@ -53,7 +55,7 @@ fun TransferIBAN( + text = when(transferContext) { + ManualWithdrawal -> stringResource( + R.string.withdraw_manual_ready_intro, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + transactionAmountEffective, + ) + +@@ -62,7 +64,7 @@ fun TransferIBAN( + if (paytoIban !is PaytoUriIban) return@Column // TODO: render error + stringResource( + R.string.send_deposit_kyc_auth_intro_bank, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + paytoIban.iban, + ) + } +@@ -123,7 +125,7 @@ fun TransferIBAN( + } + + WithdrawalAmountTransfer( +- conversionAmountRaw = transfer.transferAmount, ++ conversionAmountRaw = transfer.transferAmount.withSpec(spec), + ) + + TransferStep(2, stringResource(R.string.withdraw_manual_step_subject)) +@@ -149,12 +151,12 @@ fun TransferIBAN( + when (transferContext) { + ManualWithdrawal -> stringResource( + R.string.withdraw_manual_step_finish, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + ) + + is DepositKycAuth -> stringResource( + R.string.send_deposit_kyc_auth_step_finish, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + transfer.iban, + ) + } +diff --git a/wallet/src/main/java/net/taler/wallet/transfer/TransferTaler.kt b/wallet/src/main/java/net/taler/wallet/transfer/TransferTaler.kt +index 6bcfaf98..5a36cb9d 100644 +--- a/wallet/src/main/java/net/taler/wallet/transfer/TransferTaler.kt ++++ b/wallet/src/main/java/net/taler/wallet/transfer/TransferTaler.kt +@@ -27,6 +27,7 @@ import androidx.compose.ui.Modifier + import androidx.compose.ui.res.stringResource + import androidx.compose.ui.unit.dp + import net.taler.common.Amount ++import net.taler.common.CurrencySpecification + import net.taler.wallet.R + import net.taler.wallet.accounts.PaytoUri + import net.taler.wallet.accounts.PaytoUriTalerBank +@@ -40,6 +41,7 @@ fun TransferTaler( + transfer: TransferData.Taler, + transactionAmountEffective: Amount, + transferContext: TransferContext, ++ spec: CurrencySpecification?, + ) { + Column( + modifier = Modifier.padding(all = 16.dp), +@@ -49,7 +51,7 @@ fun TransferTaler( + text = when (transferContext) { + ManualWithdrawal -> stringResource( + R.string.withdraw_manual_ready_intro, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + transactionAmountEffective, + ) + +@@ -58,7 +60,7 @@ fun TransferTaler( + if (paytoTaler !is PaytoUriTalerBank) return@Column // TODO: render error + stringResource( + R.string.send_deposit_kyc_auth_intro_bank, +- transfer.transferAmount, ++ transfer.transferAmount.withSpec(spec), + paytoTaler.account, + ) + } +@@ -108,7 +110,7 @@ fun TransferTaler( + DetailRow(stringResource(R.string.withdraw_exchange), cleanExchange(transfer.exchangeBaseUrl)) + + WithdrawalAmountTransfer( +- conversionAmountRaw = transfer.transferAmount, ++ conversionAmountRaw = transfer.transferAmount.withSpec(spec), + ) + } + } +\ No newline at end of file diff --git a/wallet-simulator/findings/amounts-without-currency-specification.md b/wallet-simulator/findings/amounts-without-currency-specification.md @@ -0,0 +1,140 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Amounts reach two screens without their currency specification + +Found by the `withdraw_account_tabs` and `peer_push_receive` scenarios: the +wire transfer instructions and the incoming peer-payment prompt print amounts +in the wallet's fallback notation ("5.00 EUR") while the rest of the app shows +"€5.00". On the transfer screen the two notations appear in the same sentence. + +**Severity: low.** Cosmetic, but both are screens the user acts on: one carries +the amount to copy into a banking app, the other is where a payment is +accepted. + +## What happens + +The manual-withdrawal instructions say: + +``` +You need to transfer 5.00 EUR from your regular bank account to the payment +service to receive €4.88 as digital cash in this wallet. +``` + +Both amounts are EUR. The first is rendered "5.00 EUR", the second "€4.88". + +The sentence is `R.string.withdraw_manual_ready_intro` and takes two +arguments: + +```kotlin +// wallet/src/main/java/net/taler/wallet/transfer/TransferIBAN.kt:55 +stringResource( + R.string.withdraw_manual_ready_intro, + transfer.transferAmount, // no currency specification + transactionAmountEffective, // .withSpec(spec) by the caller +) +``` + +`ScreenTransfer` applies the currency specification to the effective amount +before passing it down (`transfer.amountEffective.withSpec(spec)`), but +`transfer.transferAmount` is handed over as it came from wallet-core. With +`spec == null`, `Amount.toString()` takes its no-specification branch and +prints "5.00 EUR"; with a specification it prints "€5.00". + +The same pairing appears in every transfer screen: + +- `transfer/TransferTaler.kt:52,61` +- `transfer/TransferIBAN.kt:56,65,152,157` +- `transfer/TransferCyclos.kt:47,97` + +and in the deposit KYC variant of the sentence +(`send_deposit_kyc_auth_intro_bank`). + +## The same thing on the incoming peer-payment prompt + +Accepting money from another wallet shows: + +``` +Do you want to receive this payment? +from the simulator's peer +Total: 1.00 EUR + −0.09 EUR +Receive payment +``` + +`IncomingComposable` takes no `CurrencySpecification` parameter at all, so both +the total and the fee are rendered with `Amount.toString()` on an amount that +never had one: + +```kotlin +// wallet/src/main/java/net/taler/wallet/peer/IncomingComposable.kt:145 +text = terms.contractTerms.amount.toString(), +// ...:159 +stringResource(R.string.amount_negative, fee) +``` + +The same composable serves `IncomingPushPaymentScreen` and +`IncomingPullPaymentScreen`, so this is the prompt for both receiving a push +payment and paying an invoice. Its sibling screens get this right — +`TransactionAmountInfo` and `PeerQrCode` are both passed `withSpec(spec)`. + +## Reproduce by hand — the transfer instructions + +Needs an exchange that offers a manual (not bank-integrated) withdrawal; any +deployment does, including a plain `taler-unified-setup.sh` stack. + +1. Install a debug build, enable **Developer mode**, add the exchange. +2. On the main screen tap **Withdraw**, enter an amount, tap + **Confirm withdrawal** — do not use the bank's own "withdraw" button, as + that is the bank-integrated flow. +3. On the pending transaction tap **Wire transfer instructions**. +4. The first sentence reads "You need to transfer 5.00 EUR … to receive €4.88 + …". + +## Reproduce by hand — the peer prompt + +Needs a second wallet (`taler-wallet-cli` will do) with a balance: + +1. `taler-wallet-cli peer-send --exchange <url> --summary test EUR:1` +2. Hand the `taler://pay-push/…` URI it prints to the wallet under test. +3. The prompt reads "Total: 1.00 EUR" and "−0.09 EUR". + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_unspecced_amounts.py # both screens +SIM_WORKER=4 python3 suite.py withdraw_account_tabs peer_push_receive +``` + +The reproducer prints the offending lines from each screen; the scenarios' +`suite-w4-*-summary.json` quotes them in its notes. + +## Suggested fix + +Give `IncomingComposable` a `spec: CurrencySpecification?` parameter — both its +screens have the exchange base URL in hand and so can use +`rememberCurrencySpec` as the transaction screens do — and apply it to the +total and the fee. + +On the transfer screens, pass `transfer.transferAmount.withSpec(spec)` the way +the effective amount already is — the specification is in scope in `ScreenTransfer`, which is where +`transactionAmountEffective` is computed, so the simplest fix is to compute +both there and hand both down formatted. Note the spec belongs to the +*transfer* currency, which for a currency-converting account is not the +wallet's currency, so the right specification is the account's +`currencySpecification` where it has one. diff --git a/wallet-simulator/findings/bitcoin-transfer-relabels-the-amount-as-btc.md b/wallet-simulator/findings/bitcoin-transfer-relabels-the-amount-as-btc.md @@ -0,0 +1,112 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# The Bitcoin transfer screen relabels the amount as BTC + +Found by the `withdraw_account_tabs` scenario once the exchange advertised a +`payto://bitcoin/…` account: the wire transfer instructions tell the user to +send **5.00 BTC** for a withdrawal of **EUR 5.00**. + +**Severity: low**, with a caveat about the configuration — see below. + +## What happens + +A manual withdrawal of EUR:5.00 from an exchange whose account for this +withdrawal is a Bitcoin address shows: + +``` +Now make a split transaction with the following three outputs. +bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq 5.00 BTC +bc1qwtsq3knjuqyd4uqlh9ma373s4445j77m57zs6l 0.00000294 BTC +bc1q7tsq3kketks3deyfjqd43t20zy3r3rlcx2y8sf 0.00000294 BTC +``` + +The two dust outputs are right — 294 satoshi each, which is how the reserve +public key is encoded into the transaction. The first line is not: the amount +is EUR 5.00 and the screen says BTC. + +The app is told the currency and overwrites it: + +```kotlin +// wallet/src/main/java/net/taler/wallet/transfer/TransferBitcoin.kt:82 +text = if (segwitAddress == address) + amount.withCurrency("BTC").toString() +``` + +and again in the text the "Copy" button puts on the clipboard: + +```kotlin +// …:107 +return "$addr ${amount.withCurrency("BTC")}\n$sr" +``` + +`withCurrency` relabels; it does not convert. Whatever the exchange said the +transfer amount was, this screen calls it BTC. + +## The caveat + +For this to be visible, an exchange has to offer a Bitcoin account for a +currency that is not BTC, which is what the simulator does deliberately +(`SIM_EXTRA_PAYTOS` in `backend/stack.sh` signs a `payto://bitcoin/…` address +on a EUR exchange, so that the Bitcoin screens can be reached at all). Whether +that configuration is meaningful is an exchange-operator question. + +What does not depend on the caveat: the wallet has the transfer amount's real +currency in hand and prints a different one. On a genuinely Bitcoin-wired +exchange the relabelling is invisible because the two agree; the moment they +do not, the screen states a confident wrong unit for an amount the user is +about to transfer, and so does the clipboard. + +## Reproduce by hand + +Needs an exchange with a signed Bitcoin account; against the simulator's stack +that is the default (see `backend/stack.sh`, `EXTRA_PAYTOS`). On another +deployment: + +```bash +taler-exchange-offline -c <conf> \ + enable-account 'payto://bitcoin/bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq' upload +taler-exchange-offline -c <conf> \ + wire-fee now bitcoin EUR:0.01 EUR:0.01 upload +``` + +(the wire fee matters: wallet-core hides an account whose method has none). +Then, in the wallet: + +1. **Withdraw**, enter 5, **Confirm withdrawal** — the manual flow, not the + bank's own button. +2. On the pending withdrawal tap **Wire transfer instructions**. +3. Select the account tab for the Bitcoin account ("Account #3"). +4. The first output reads "5.00 BTC". + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=4 python3 suite.py withdraw_account_tabs +``` + +The notes quote each wire account's instructions, the Bitcoin one included. + +## Suggested fix + +Print the amount in the currency it came in — `amount.toString()`, with the +currency specification applied the way the other transfer screens do (see +[`amounts-without-currency-specification.md`](amounts-without-currency-specification.md)) — +and keep `withCurrency("BTC")` for the segwit dust, which really is satoshi. +If an exchange offering a Bitcoin account for a non-BTC currency is to be +treated as a misconfiguration, the screen should say so rather than render it. diff --git a/wallet-simulator/findings/config-change-locks-the-wallet-out-of-its-database.diff b/wallet-simulator/findings/config-change-locks-the-wallet-out-of-its-database.diff @@ -0,0 +1,66 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/backend/BackendManager.kt b/wallet/src/main/java/net/taler/wallet/backend/BackendManager.kt +index b9ef17b5..f667e414 100644 +--- a/wallet/src/main/java/net/taler/wallet/backend/BackendManager.kt ++++ b/wallet/src/main/java/net/taler/wallet/backend/BackendManager.kt +@@ -70,6 +70,10 @@ class BackendManager( + + private var running = false + ++ /** Whether wallet-core is up in this process. */ ++ val isRunning: Boolean ++ @Synchronized get() = running ++ + private fun newScope() = CoroutineScope(Dispatchers.Default + SupervisorJob()) + + @Synchronized +diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt +index 26a8ed89..2a3c8925 100644 +--- a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt ++++ b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt +@@ -41,6 +41,9 @@ class WalletBackendApi( + + private val backendManager = BackendManager(notificationReceiver) + ++ /** Whether wallet-core is already up, and so must not be initialised again. */ ++ val isRunning: Boolean get() = backendManager.isRunning ++ + fun startWallet() { + backendManager.run() + GlobalScope.launch(Dispatchers.IO) { +diff --git a/wallet/src/main/java/net/taler/wallet/main/MainActivity.kt b/wallet/src/main/java/net/taler/wallet/main/MainActivity.kt +index 4868fbca..367faa68 100644 +--- a/wallet/src/main/java/net/taler/wallet/main/MainActivity.kt ++++ b/wallet/src/main/java/net/taler/wallet/main/MainActivity.kt +@@ -238,7 +238,14 @@ class MainActivity : FragmentActivity() { + } + } + +- model.startWallet() ++ // wallet-core belongs to the retained MainViewModel, and onDestroy ++ // deliberately leaves it running across a configuration change -- so ++ // starting it again here sends a second "init", whose fresh wallet ++ // cannot take the SQLite database from the instance still holding it ++ // ("could not acquire exclusive ownership of the wallet database"). ++ // Changing the language, the font size or the display size recreates ++ // this activity, which is how a user met that error screen. ++ if (!model.walletRunning) model.startWallet() + + handleIntents(intent) + +diff --git a/wallet/src/main/java/net/taler/wallet/main/MainViewModel.kt b/wallet/src/main/java/net/taler/wallet/main/MainViewModel.kt +index 9c2bf023..cd0e2c81 100644 +--- a/wallet/src/main/java/net/taler/wallet/main/MainViewModel.kt ++++ b/wallet/src/main/java/net/taler/wallet/main/MainViewModel.kt +@@ -165,6 +165,12 @@ class MainViewModel( + MutableStateFlow<DatabaseMigrationState>(DatabaseMigrationState.None) + val databaseMigrationState: StateFlow<DatabaseMigrationState> = mDatabaseMigrationState + ++ /** ++ * Whether wallet-core is already running, so that an activity being ++ * recreated does not start it a second time. ++ */ ++ val walletRunning: Boolean get() = api.isRunning ++ + fun startWallet() { + api.startWallet() + } diff --git a/wallet-simulator/findings/config-change-locks-the-wallet-out-of-its-database.md b/wallet-simulator/findings/config-change-locks-the-wallet-out-of-its-database.md @@ -0,0 +1,225 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# A configuration change locks the wallet out of its own database + +Found while setting up a different test — switching the app's language to +German to read the contacts screen — which is as ordinary a thing as a user +does. Enlarging the system font or the display size does it too. + +**Severity: high.** The wallet lands on its "Initialization error" screen, +which replaces the entire app, and the screen tells the user to retry while +offering no way to do so; the only way out is to swipe the app away and reopen +it. The error underneath is `WALLET_UNEXPECTED_EXCEPTION` (7001), not a handled +condition. Two of the three triggers are **accessibility** settings, so the +users most likely to meet it are the ones who changed their font size to be +able to read the screen at all. + +## What happens + +With the wallet open, set its language: + +```bash +adb shell cmd locale set-app-locales net.taler.wallet.fdroid.debug --locales de-DE +``` + +The app comes back in German — on this screen: + +``` +Fehler +Beim Starten der Wallet ist ein Fehler aufgetreten. Dies kann nach einem +App-Update oder bei inkompatiblen Wallet-Daten passieren. Bitte versuche es +erneut, … +{ + "code": 7001, + "hint": "unexpected exception (message: could not acquire exclusive ownership + of the wallet database; another wallet process may still be using it)", + "message": null, + "stack": " at acquireSqliteWalletDbOwnership (<compiled_js>:34739:20)" +} +[Fehlerdiagnose exportieren] [Kopieren] [Teilen] +``` + +The configuration change restarts the app, the new instance asks wallet-core to +`init`, and wallet-core cannot take the SQLite database because the instance it +replaced has not let go of it yet. + +## Which changes do it + +Four everyday configuration changes, each applied while the wallet was open on +a settings sub-screen, then undone and the app relaunched: + +| Change | Init error | Still broken after relaunching | +| --- | --- | --- | +| app language (`cmd locale set-app-locales … de-DE`) | **yes** | no | +| system font size (`settings put system font_scale 1.30`) | **yes** | no | +| display size (`wm density 480`) | **yes** | no | +| dark mode (`cmd uimode night yes`) | no | — | + +Nothing is lost: killing the app and reopening it recovers, and undoing the +change is not necessary. But nothing *in* the app recovers. + +Dark mode is the exception for a reason — the manifest already handles it: + +```xml +<!-- wallet/src/main/AndroidManifest.xml:65 --> +android:configChanges="keyboardHidden|orientation|screenSize|uiMode" +``` + +`uiMode` and `orientation` are in that list, so dark mode and rotation never +recreate the activity. Locale, `fontScale` and `density` are not, so they do — +and that is the whole trigger. + +## Why it happens + +It is the same process throughout — measured, not assumed: + +``` +pid before: 13611 +pid after: 13611 +same process: True +init error: True +``` + +so the message's "another wallet process" is itself misleading: the lock is +held by the previous wallet instance *inside this process*, which was never +shut down. The activity's two lifecycle halves do not agree about that: + +```kotlin +// wallet/src/main/java/net/taler/wallet/main/MainActivity.kt:241 +model.startWallet() // in onCreate, unconditionally + +// wallet/src/main/java/net/taler/wallet/main/MainActivity.kt:414 +// wallet-core belongs to the retained MainViewModel, not to this activity +if (!isChangingConfigurations) model.stopWallet() +``` + +The `onDestroy` side is right, and its comment says why: wallet-core belongs to +the retained `MainViewModel`, so a configuration change must not shut it down. +The `onCreate` side then starts it again anyway. `startWallet()` is not +idempotent in the way that needs: + +```kotlin +// wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt:44 +fun startWallet() { + backendManager.run() // a no-op, it is already running + GlobalScope.launch(Dispatchers.IO) { sendInitMessage() } // a *second* init +} +``` + +`backendManager.run()` does nothing the second time — its `running` flag and +the static `coreRunning` guard both hold, and indeed "refusing to run a second +wallet-core in this process" never appears in the log. The second `init` +message is the problem: wallet-core logs it as a "repeat initialization" and +builds a fresh wallet on the same core, which then cannot take the SQLite +database from the instance still holding it. + +Whether it fails at all is a race with the old instance letting go — the same +change applied while the wallet sits on its home screen sometimes survives, and +wallet-core logs `request-finish-success` for the repeat init. That is why this +reproduces reliably from a settings sub-screen and only sometimes from the +balance screen. + +## Why the screen is a dead end + +`MainActivity` swaps the whole navigation graph for the error screen: + +```kotlin +// wallet/src/main/java/net/taler/wallet/main/MainActivity.kt:155 +initError?.let { error -> + WalletInitErrorScreen(model = model, error = error, …) +} ?: run { + WalletNavHost(…) +} +``` + +and `WalletInitErrorScreen` offers exactly two buttons — **Export logs** and +**Export database**. Meanwhile the message it shows says: + +```xml +<!-- res/values/strings.xml:70 --> +<string name="wallet_init_error_message">An error occurred while starting the +wallet. … Please retry, and if the problem persists, export the logs and report +this issue to the developers.</string> +``` + +There is nothing to retry *with*. `initError` is a `StateFlow` that is only +cleared by a later successful init: + +```kotlin +// wallet/src/main/java/net/taler/wallet/main/MainViewModel.kt:177,192 +override fun onInitErrorReceived(error: TalerErrorInfo) { mInitError.value = error } +override fun onInitReceived(init: InitResponse) { … mInitError.value = null … } +``` + +and nothing asks for another init. So for the life of that process the wallet is +a single screen with two export buttons. + +## Reproduce by hand + +1. Open the wallet and leave it on a settings sub-screen (Settings → Contacts + is where this was first seen). +2. Make one of the three changes: + * *App info → Language* for this app, or + `adb shell cmd locale set-app-locales <pkg> --locales de-DE`; + * *Settings → Display → Font size*, or + `adb shell settings put system font_scale 1.30`; + * *Settings → Display → Display size*, or `adb shell wm density 480`. +3. The wallet comes back on the Initialization error screen. With developer + mode on, the `7001` object quoted above is on screen; without it, the hint + alone. +4. Nothing on the screen gets the wallet back. Swiping the app away from the + task switcher and reopening it does. + +Undo with `--locales` (no value), `font_scale 1.0`, `wm density reset`. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_config_change_db_ownership.py emulator-5554 +``` + +It is also measured every round now, over all four changes at once: + +```bash +cd /opt/taler-sim/driver && SIM_WORKER=0 python3 -u suite.py config_changes +``` + +## Suggested fix + +The one-line version: **do not start the wallet again when it is already +running.** `MainActivity.onCreate` calls `startWallet()` on every activity +creation, while `onDestroy` deliberately does not stop it across a +configuration change; making the start side agree with the stop side — +`if (!model.walletRunning) model.startWallet()`, or moving the call into +`MainViewModel`'s initialiser, where the retained lifetime already lives — ends +it. + +Three smaller things are worth doing anyway, because each one would have turned +this into a non-event: + +1. **Make `init` idempotent, or wait briefly for the lock.** A repeat `init` + whose predecessor is still letting go of the database could reuse it or + retry for a few hundred milliseconds instead of failing. +2. **Retry init from the error screen.** The message already promises it: + "Please retry". A button calling `model.startWallet()` would honour the + promise, and would cover every other transient init failure as well. +3. **Say "the database is busy", not "unexpected exception".** 7001 with a + compiled-JavaScript stack trace is what the user is shown for a condition + the wallet understands perfectly well — and the text blames "another wallet + process", which measurement shows is this very process. diff --git a/wallet-simulator/findings/contacts-and-mailbox-cannot-be-translated.diff b/wallet-simulator/findings/contacts-and-mailbox-cannot-be-translated.diff @@ -0,0 +1,354 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/contacts/ContactScreen.kt b/wallet/src/main/java/net/taler/wallet/contacts/ContactScreen.kt +index d59b0b00..9bc840ec 100644 +--- a/wallet/src/main/java/net/taler/wallet/contacts/ContactScreen.kt ++++ b/wallet/src/main/java/net/taler/wallet/contacts/ContactScreen.kt +@@ -139,7 +139,12 @@ fun ContactScreen( + Scaffold( + topBar = { + TopAppBar( +- title = { Text(if (sendUri != null) "Send to Contact" else "Contacts") }, ++ title = { ++ Text(stringResource( ++ if (sendUri != null) R.string.contacts_send_title ++ else R.string.contacts_title ++ )) ++ }, + navigationIcon = { + IconButton(onClick = onNavigateBack) { + Icon( +@@ -152,7 +157,7 @@ fun ContactScreen( + }, + floatingActionButton = { + FloatingActionButton(onClick = { showAddDialog = true }) { +- Icon(Icons.Default.Add, contentDescription = "Add Contact") ++ Icon(Icons.Default.Add, contentDescription = stringResource(R.string.contacts_add)) + } + } + ) { innerPadding -> +@@ -167,14 +172,20 @@ fun ContactScreen( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp, vertical = 8.dp), +- placeholder = { Text("Search contacts...") }, ++ placeholder = { Text(stringResource(R.string.contacts_search)) }, + leadingIcon = { Icon(Icons.Default.Search, contentDescription = null) }, + singleLine = true, + ) + + when (val res = contactResult) { +- is ContactResult.Loading -> Text("Loading...", modifier = Modifier.padding(16.dp)) +- is ContactResult.Error -> Text("Error: ${res.error}", modifier = Modifier.padding(16.dp)) ++ is ContactResult.Loading -> Text( ++ stringResource(R.string.loading), ++ modifier = Modifier.padding(16.dp), ++ ) ++ is ContactResult.Error -> Text( ++ stringResource(R.string.contacts_error, res.error.toString()), ++ modifier = Modifier.padding(16.dp), ++ ) + is ContactResult.Success -> { + val filteredContacts = res.contacts.filter { contact -> + contact.petname.fuzzyMatches(searchQuery) || +@@ -196,8 +207,12 @@ fun ContactScreen( + contactToConfirm?.let { contact -> + AlertDialog( + onDismissRequest = { contactToConfirm = null }, +- title = { Text("Send to ${contact.petname}") }, +- text = { Text("Are you sure you want to send this to ${contact.petname}?") }, ++ title = { Text(stringResource(R.string.contacts_send_confirm_title, contact.petname)) }, ++ text = { ++ Text(stringResource( ++ R.string.contacts_send_confirm_message, contact.petname, ++ )) ++ }, + confirmButton = { + TextButton(onClick = { + model.mailboxManager.sendMessage(contact, sendUri!!) +@@ -290,19 +305,19 @@ fun AddContactDialog( + + AlertDialog( + onDismissRequest = onDismiss, +- title = { Text("Add Contact") }, ++ title = { Text(stringResource(R.string.contacts_add)) }, + text = { + Column(modifier = Modifier.verticalScroll(rememberScrollState())) { + OutlinedTextField( + value = petname, + onValueChange = { petname = it }, +- label = { Text("Petname") }, ++ label = { Text(stringResource(R.string.contacts_petname)) }, + modifier = Modifier.fillMaxWidth().padding(bottom = 8.dp) + ) + OutlinedTextField( + value = alias, + onValueChange = { alias = it }, +- label = { Text("Alias") }, ++ label = { Text(stringResource(R.string.contacts_alias)) }, + placeholder = { + Text( + if (aliasType == stringResource(R.string.alias_registration_alias_email)) { +@@ -327,7 +342,7 @@ fun AddContactDialog( + value = aliasType, + onValueChange = {}, + readOnly = true, +- label = { Text("Alias Type") }, ++ label = { Text(stringResource(R.string.contacts_alias_type)) }, + trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = aliasTypeExpanded) }, + colors = ExposedDropdownMenuDefaults.outlinedTextFieldColors(), + modifier = Modifier +@@ -354,7 +369,7 @@ fun AddContactDialog( + + if (isDuplicate) { + Text( +- text = "A contact with this alias and type already exists.", ++ text = stringResource(R.string.contacts_duplicate), + color = MaterialTheme.colorScheme.error, + style = MaterialTheme.typography.bodySmall, + modifier = Modifier.padding(bottom = 8.dp) +@@ -373,13 +388,13 @@ fun AddContactDialog( + enabled = alias.isNotBlank() && aliasType.isNotBlank(), + modifier = Modifier.fillMaxWidth().padding(bottom = 8.dp) + ) { +- Text("Lookup with Taldir") ++ Text(stringResource(R.string.contacts_lookup_taldir)) + } + } + + if (lookupResult is LookupResult.Error) { + Text( +- text = "Lookup failed: ${lookupResult.error.userFacingMsg}", ++ text = stringResource(R.string.contacts_lookup_failed, lookupResult.error.userFacingMsg), + color = MaterialTheme.colorScheme.error, + style = MaterialTheme.typography.bodySmall, + modifier = Modifier.padding(bottom = 8.dp) +@@ -389,7 +404,7 @@ fun AddContactDialog( + OutlinedTextField( + value = mailbox, + onValueChange = { mailbox = it }, +- label = { Text("Mailbox") }, ++ label = { Text(stringResource(R.string.contacts_mailbox)) }, + modifier = Modifier.fillMaxWidth().padding(bottom = 8.dp) + ) + } +@@ -425,7 +440,7 @@ fun ContactList( + onSelect: ((ContactEntry) -> Unit)? = null, + ) { + if (contacts.isEmpty()) { +- Text("No contacts yet.", modifier = Modifier.padding(16.dp)) ++ Text(stringResource(R.string.contacts_empty), modifier = Modifier.padding(16.dp)) + } else { + LazyColumn { + items(contacts) { contact -> +@@ -470,7 +485,7 @@ fun ContactItem( + Text(contact.mailboxBaseUri, style = MaterialTheme.typography.bodySmall) + } + IconButton(onClick = { onDelete(contact) }) { +- Icon(Icons.Default.Delete, contentDescription = "Delete") ++ Icon(Icons.Default.Delete, contentDescription = stringResource(R.string.transactions_delete)) + } + } + } +diff --git a/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt b/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt +index 01073ef5..053b8c3f 100644 +--- a/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt ++++ b/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt +@@ -111,7 +111,7 @@ fun MailboxScreen( + Scaffold( + topBar = { + TopAppBar( +- title = { Text("Mailbox") }, ++ title = { Text(stringResource(R.string.mailbox_title)) }, + navigationIcon = { + IconButton(onClick = onNavigateBack) { + Icon( +@@ -124,15 +124,15 @@ fun MailboxScreen( + val state = mailboxState + if (state is MailboxResult.Success) { + IconButton(onClick = { showAddressDialog = true }) { +- Icon(Icons.Default.Info, contentDescription = "Show Mailbox Address") ++ Icon(Icons.Default.Info, contentDescription = stringResource(R.string.mailbox_show_address)) + } + } + IconButton(onClick = { showUrlDialog = true }) { +- Icon(Icons.Default.Settings, contentDescription = "Configure Mailbox") ++ Icon(Icons.Default.Settings, contentDescription = stringResource(R.string.mailbox_configure)) + } + if (state is MailboxResult.Success) { + IconButton(onClick = { mailboxManager.refreshMailbox(state.config) }) { +- Icon(Icons.Default.Refresh, contentDescription = "Refresh") ++ Icon(Icons.Default.Refresh, contentDescription = stringResource(R.string.mailbox_refresh)) + } + } + } +@@ -146,8 +146,14 @@ fun MailboxScreen( + .padding(innerPadding) + ) { + when (val res = mailboxState) { +- is MailboxResult.Loading -> Text("Loading...", modifier = Modifier.padding(16.dp)) +- is MailboxResult.Error -> Text("Error: ${res.error}", modifier = Modifier.padding(16.dp)) ++ is MailboxResult.Loading -> Text( ++ stringResource(R.string.loading), ++ modifier = Modifier.padding(16.dp), ++ ) ++ is MailboxResult.Error -> Text( ++ stringResource(R.string.mailbox_error, res.error.toString()), ++ modifier = Modifier.padding(16.dp), ++ ) + is MailboxResult.Success -> { + MessageList(res.messages, onNavigate) { message -> + mailboxManager.deleteMessage(res.config, message) +@@ -161,9 +167,10 @@ fun MailboxScreen( + val state = mailboxState + if (state is MailboxResult.Success) { + val mailboxAddressURI = "${state.config.mailboxBaseUrl}/${state.config.hAddress}" ++ val addressCopiedMessage = stringResource(R.string.mailbox_address_copied) + AlertDialog( + onDismissRequest = { showAddressDialog = false }, +- title = { Text("Your Mailbox Address") }, ++ title = { Text(stringResource(R.string.mailbox_your_address)) }, + text = { + Text(mailboxAddressURI) + }, +@@ -171,7 +178,7 @@ fun MailboxScreen( + TextButton(onClick = { + clipboardManager.setText(AnnotatedString(mailboxAddressURI)) + scope.launch { +- snackbarHostState.showSnackbar("Mailbox address URI copied to clipboard") ++ snackbarHostState.showSnackbar(addressCopiedMessage) + } + showAddressDialog = false + }) { +@@ -191,12 +198,12 @@ fun MailboxScreen( + var url by remember { mutableStateOf("https://mailbox.gnunet.org") } + AlertDialog( + onDismissRequest = { showUrlDialog = false }, +- title = { Text("Configure Mailbox URL") }, ++ title = { Text(stringResource(R.string.mailbox_configure_url)) }, + text = { + OutlinedTextField( + value = url, + onValueChange = { url = it }, +- label = { Text("Mailbox Base URL") }, ++ label = { Text(stringResource(R.string.mailbox_base_url)) }, + modifier = Modifier.fillMaxWidth() + ) + }, +@@ -224,7 +231,7 @@ fun MessageList( + onDelete: (MailboxMessageRecord) -> Unit, + ) { + if (messages.isEmpty()) { +- Text("No messages yet.", modifier = Modifier.padding(16.dp)) ++ Text(stringResource(R.string.mailbox_empty), modifier = Modifier.padding(16.dp)) + } else { + LazyColumn { + items(messages) { message -> +@@ -255,22 +262,28 @@ fun MessageItem( + Button( + onClick = { onNavigate(WalletDestination.HandleUri(message.talerUri), false) } + ) { +- Text(if (isPayPush) "Accept payment" else "Pay invoice") ++ Text(stringResource( ++ if (isPayPush) R.string.mailbox_accept_payment ++ else R.string.mailbox_pay_invoice ++ )) + } + } else { + Text(message.talerUri, style = MaterialTheme.typography.bodyMedium) + } + Text( +- "From: ${message.originMailboxBaseUrl}", ++ stringResource(R.string.mailbox_from, message.originMailboxBaseUrl), + style = MaterialTheme.typography.bodySmall + ) + Text( +- "Received: ${message.downloadedAt.ms.toAbsoluteTime(context)}", ++ stringResource( ++ R.string.mailbox_received, ++ message.downloadedAt.ms.toAbsoluteTime(context), ++ ), + style = MaterialTheme.typography.bodySmall + ) + } + IconButton(onClick = { onDelete(message) }) { +- Icon(Icons.Default.Delete, contentDescription = "Delete") ++ Icon(Icons.Default.Delete, contentDescription = stringResource(R.string.transactions_delete)) + } + } + } +diff --git a/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt b/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt +index 5d904900..afadd1e7 100644 +--- a/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt ++++ b/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt +@@ -254,22 +254,22 @@ fun SettingsScreen( + ) + + SettingsItem( +- title = "Contacts", +- summary = "Contacts", ++ title = stringResource(R.string.contacts_title), ++ summary = stringResource(R.string.settings_contacts_summary), + icon = Icons.Default.Person, + onClick = { onNavigate(WalletDestination.Contacts(), false) } + ) + + SettingsItem( +- title = "Mailbox", +- summary = "P2P Messaging", ++ title = stringResource(R.string.mailbox_title), ++ summary = stringResource(R.string.mailbox_summary), + icon = ImageVector.vectorResource(R.drawable.ic_adjust), + onClick = { onNavigate(WalletDestination.Mailbox, false) } + ) + + SettingsItem( + title = stringResource(R.string.alias_registration_title), +- summary = "Taldir Registration", ++ summary = stringResource(R.string.settings_taldir_summary), + icon = Icons.Default.Person, + onClick = { onNavigate(WalletDestination.AliasRegistration, false) } + ) +diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml +index 905e4390..eb80f552 100644 +--- a/wallet/src/main/res/values/strings.xml ++++ b/wallet/src/main/res/values/strings.xml +@@ -519,6 +519,40 @@ GNU Taler is immune to many types of fraud such as credit card data theft, phish + <string name="contact_mailbox_base_uri">Mailbox Base URI</string> + <string name="contact_petname">Petname</string> + <string name="contacts_title">Contacts</string> ++ <!-- Contacts --> ++ <string name="contacts_send_title">Send to Contact</string> ++ <string name="contacts_add">Add Contact</string> ++ <string name="contacts_search">Search contacts…</string> ++ <string name="contacts_empty">No contacts yet.</string> ++ <string name="contacts_error">Error: %1$s</string> ++ <string name="contacts_send_confirm_title">Send to %1$s</string> ++ <string name="contacts_send_confirm_message">Are you sure you want to send this to %1$s?</string> ++ <string name="contacts_petname">Petname</string> ++ <string name="contacts_alias">Alias</string> ++ <string name="contacts_alias_type">Alias Type</string> ++ <string name="contacts_mailbox">Mailbox</string> ++ <string name="contacts_lookup_taldir">Lookup with Taldir</string> ++ <string name="contacts_lookup_failed">Lookup failed: %1$s</string> ++ <string name="contacts_duplicate">A contact with this alias and type already exists.</string> ++ <!-- Mailbox --> ++ <string name="mailbox_title">Mailbox</string> ++ <string name="mailbox_summary">P2P Messaging</string> ++ <string name="mailbox_show_address">Show Mailbox Address</string> ++ <string name="mailbox_configure">Configure Mailbox</string> ++ <string name="mailbox_refresh">Refresh</string> ++ <string name="mailbox_error">Error: %1$s</string> ++ <string name="mailbox_your_address">Your Mailbox Address</string> ++ <string name="mailbox_address_copied">Mailbox address URI copied to clipboard</string> ++ <string name="mailbox_configure_url">Configure Mailbox URL</string> ++ <string name="mailbox_base_url">Mailbox Base URL</string> ++ <string name="mailbox_empty">No messages yet.</string> ++ <string name="mailbox_accept_payment">Accept payment</string> ++ <string name="mailbox_pay_invoice">Pay invoice</string> ++ <string name="mailbox_from">From: %1$s</string> ++ <string name="mailbox_received">Received: %1$s</string> ++ <!-- Settings entries for the two above --> ++ <string name="settings_contacts_summary">Manage the people you send to</string> ++ <string name="settings_taldir_summary">Taldir Registration</string> + + <!-- Settings --> + diff --git a/wallet-simulator/findings/contacts-and-mailbox-cannot-be-translated.md b/wallet-simulator/findings/contacts-and-mailbox-cannot-be-translated.md @@ -0,0 +1,177 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Two whole features are untranslatable, and nothing in the repo can tell + +Found while reading the contacts screens for the alias-registration work: every +label on them is an English string literal in the Compose source rather than an +entry in `strings.xml`. + +**Severity: moderate.** The wallet ships 19 translations and the project keeps a +135-term glossary in 27 languages (`dictionary.md`), but the contacts and +mailbox features will be English in all of them, and no amount of translation +work can change that. Two strings on the *payment prompt* — a screen every user +sees — are in the same state, as is the transaction list's selection counter. + +## What happens + +`res/values/strings.xml` is the source of truth for translations, and +`./check-translations.py` compares every `values-<lang>/strings.xml` against +it. A literal passed to a Composable is in neither file, so it is invisible to +both the translators and the checker: coverage reads 100 % while the screen is +half English. + +Set the wallet's language to German and the whole UI follows — except these: + +| Where | Untranslatable, user-visible strings | +| --- | --- | +| `contacts/ContactScreen.kt` | 18 — the screen title (`Contacts`, or `Send to Contact` when forwarding a payment), `Add Contact`, `Petname`, `Alias`, `Alias Type`, `Mailbox`, `Lookup with Taldir`, `Search contacts...`, `No contacts yet.`, `Loading...`, `Error: …`, `Lookup failed: …`, `A contact with this alias and type already exists.`, `Send to <petname>`, `Are you sure you want to send this to <petname>?`, and the `Add Contact`/`Delete` content descriptions | +| `mailbox/MailboxScreen.kt` | 16 — `Mailbox`, `Your Mailbox Address`, `Configure Mailbox URL`, `Mailbox Base URL`, `No messages yet.`, `Loading...`, `Error: …`, the `Accept payment` and `Pay invoice` buttons on a message, its `From: …` and `Received: …` lines, the `Mailbox address URI copied to clipboard` toast, and the `Show Mailbox Address`/`Configure Mailbox`/`Refresh`/`Delete` content descriptions | +| `settings/SettingsScreen.kt:257-272` | 5 — the `Contacts` and `Mailbox` entries with their summaries (`Contacts`, `P2P Messaging`), and the `Taldir Registration` summary | +| `contacts/ContactManager.kt:169` | `Alias not found` | +| `payment/PaymentManager.kt:395` | `The order could not be found. Maybe the merchant deleted it.` | +| `main/MainViewModel.kt:503` | `Database migration completed without switching to SQLite` | +| `compose/ExpandableCard.kt:96` | the `Drop Down Arrow` content description | + +**43 strings in all.** Three more (`Error`, `Event`, `Bitcoin`) are `ClipData` +labels on copy buttons, which some Android versions show in the "copied" toast. +Everything else a literal scan turns up is `@Preview` fixture data, commented +out, a `@Deprecated` message, a log line, a wallet-core operation name, or a +token that should not be translated (`payto://`, `https://`, `Cy` for Cyclos). + +The drift is visible inside a single call. The third settings entry in that +block takes its title from a resource and hard-codes its summary: + +```kotlin +// wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt:271 +SettingsItem( + title = stringResource(R.string.alias_registration_title), + summary = "Taldir Registration", +``` + +Two details sharpen it: + +* **`contacts_title` already exists** in `strings.xml` (`<string + name="contacts_title">Contacts</string>`) and is translated in the shipped + languages — but it is used for the *forward* button on a peer transaction + (`compose/QrCodeUriComposable.kt:199`), while the settings entry that opens + the contacts screen hard-codes the same word. One of the two spellings of + "Contacts" in this app is translatable and the other is not. +* **The neighbouring file gets it right.** + `contacts/AliasRegistrationScreen.kt`, in the same package, uses + `stringResource` for all 14 of its labels. So this is drift, not a + convention. + +One literal that a scan flags is *not* a live defect, and is worth naming so +nobody re-files it: `compose/SelectionModeTopAppBar.kt:48` renders +`"${selectedItems.size} selected"`, but that composable has no caller — +`TransactionsScreen` implements selection mode inline and uses +`stringResource(R.string.selection_count, …)` for the same text. The dead copy +is the hard-coded one. + +That live resource has a smaller problem of its own: + +```xml +<!-- res/values/strings.xml:93 --> +<string name="selection_count">%1$d selected</string> +``` + +A count belongs in a `<plurals>` resource; as a single string it cannot be +declined in languages that need it, and "1 selected" is wrong in several of the +19 the wallet ships. + +## Why the tooling misses it + +The repo's defences are both aimed at `strings.xml`: + +* `./check-translations.py` reads `values*/strings.xml` and reports missing or + extra keys, format-argument mismatches and string-array lengths. A string + that was never a resource cannot be missing from a translation. +* Android lint's `HardcodedText` check only looks at layout XML. These screens + are Compose, so there is no layout file and nothing is flagged — `wallet` + builds with `abortOnError true` and `ignoreWarnings false` and still passes. + +## Reproduce by hand + +The per-app language setting needs no root (Android 13+): + +```bash +adb shell cmd locale set-app-locales net.taler.wallet.fdroid.debug --locales de-DE +adb shell am force-stop net.taler.wallet.fdroid.debug # see the note below +# open the wallet: it reads "Willkommen bei Taler Wallet!", "QR-Code scannen", +# "Einstellungen" … +# and Settings, in German, lists "Contacts" and "Mailbox" +adb shell cmd locale set-app-locales net.taler.wallet.fdroid.debug --locales # undo +``` + +Expected: the two entries, and everything behind them, in the device's +language. + +The `force-stop` is not politeness: changing the language *without* restarting +the wallet drops it on its initialization error screen, which is a separate +defect — [`config-change-locks-the-wallet-out-of-its-database.md`](config-change-locks-the-wallet-out-of-its-database.md). + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_untranslated_contacts_mailbox.py emulator-5554 +``` + +It sets the language, restarts the wallet, and then walks to both screens — +needing `Settings|Einstellungen` to find its way and plain English for +everything after that: + +``` +the wallet is in German: ['Einstellungen', 'QR-Code scannen', + 'Willkommen bei Taler Wallet', 'abheben'] + home screen: Wallet | Willkommen bei Taler Wallet! | Um Ihre erste Zahlung + zu tätigen, heben Sie digitales Bargeld ab | CHF abheben | … | + Einstellungen | Internes Ereignisprotokoll | QR-Code scannen + +=== Contacts (reached by its English name) + Search contacts... | No contacts yet. | Contacts | Add Contact + 3 untranslatable labels: ['Add Contact', 'No contacts yet', 'Search contacts'] + +=== Mailbox (reached by its English name) + No messages yet. | Mailbox | Show Mailbox Address | Configure Mailbox | Refresh + 2 untranslatable labels: ['No messages yet', 'Mailbox'] + +reproduced: True (5 English labels in a German wallet, plus the two settings +entries that opened them) +``` + +Five is all an empty wallet shows; the other 39 need a contact, a message, a +lookup or an error to be on screen. The table above is from the sources, not +from this run. + +## Suggested fix + +Move the literals into `res/values/strings.xml` and reference them with +`stringResource`, as `AliasRegistrationScreen.kt` already does, and give the +settings entry a resource of its own rather than hard-coding the word that +`contacts_title` already holds. Separately, make `selection_count` a +`<plurals>`. The content descriptions matter twice over, since they are what a +screen reader announces — see +[`action-buttons-have-no-accessible-name.md`](action-buttons-have-no-accessible-name.md). + +To stop it coming back, something has to look at Kotlin rather than at XML. The +scan that produced the table above is three lines of Python over +`wallet/src/main/java`, matching string literals passed to `Text(…)` and to the +`title`/`label`/`placeholder`/`contentDescription` parameters, and skipping +`@Preview` bodies; as a check in `./check-translations.py` it would have caught +each of these the day it was written. diff --git a/wallet-simulator/findings/delete-transaction-requeries-deleted-id.diff b/wallet-simulator/findings/delete-transaction-requeries-deleted-id.diff @@ -0,0 +1,71 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt +index d7e95ce6..d6ed35d4 100644 +--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt ++++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt +@@ -37,6 +37,9 @@ import net.taler.wallet.balances.ScopeInfo + import net.taler.wallet.transactions.TransactionAction.Delete + import org.json.JSONObject + ++/** How many deleted transaction ids to remember, to recognise their transitions. */ ++private const val DELETED_IDS_REMEMBERED = 32 ++ + sealed class TransactionsResult { + data object None : TransactionsResult() + data class Error(val error: TalerErrorInfo) : TransactionsResult() +@@ -93,6 +96,30 @@ class TransactionManager( + val selectedTransaction = mSelectedTransaction.asStateFlow() + val selectedTransferOption = mSelectedTransferOption.asStateFlow() + ++ /** ++ * Ids this wallet has deleted, so their transition notifications can be ++ * ignored. ++ * ++ * Deleting a transaction makes wallet-core emit transitions for it, and ++ * [onTransactionStateTransition] asks for the transaction before it can ++ * know what the transition was -- which after a deletion is a request for ++ * something that no longer exists: 7052, logged at error level, three ++ * times per deletion. An id never comes back, so a bounded set is enough. ++ */ ++ private val deletedIds = LinkedHashSet<String>() ++ ++ @Synchronized ++ private fun rememberDeleted(transactionId: String) { ++ deletedIds.add(transactionId) ++ while (deletedIds.size > DELETED_IDS_REMEMBERED) { ++ val oldest = deletedIds.first() ++ deletedIds.remove(oldest) ++ } ++ } ++ ++ @Synchronized ++ private fun wasDeleted(transactionId: String) = transactionId in deletedIds ++ + /** + * Streams the [RECENT_LIMIT] most recent transactions for [scopeInfo], as + * shown on the balances screen. +@@ -168,6 +195,9 @@ class TransactionManager( + * not been requested yet are left untouched. + */ + fun onTransactionStateTransition(transactionId: String) = scope.launch { ++ // Nothing to refresh and no scope to reload for a transaction we ++ // deleted; asking is what filled the log with 7052 errors. ++ if (wasDeleted(transactionId)) return@launch + val transaction = getTransactionById(transactionId) + + if (transaction != null && mSelectedTransactionId.value == transactionId) { +@@ -282,6 +312,7 @@ class TransactionManager( + + fun deleteTransaction(transactionId: String, onError: (it: TalerErrorInfo) -> Unit) = + scope.launch { ++ rememberDeleted(transactionId) + api.request<Unit>("deleteTransaction") { + put("transactionId", transactionId) + }.onError { +@@ -357,6 +388,7 @@ class TransactionManager( + fullTransactions.values.flatten().filter { transaction -> + transaction.transactionId in transactionIds && Delete in transaction.txActions + }.forEach { toBeDeletedTx -> ++ rememberDeleted(toBeDeletedTx.transactionId) + api.request<Unit>("deleteTransaction") { + put("transactionId", toBeDeletedTx.transactionId) + }.onError { diff --git a/wallet-simulator/findings/delete-transaction-requeries-deleted-id.md b/wallet-simulator/findings/delete-transaction-requeries-deleted-id.md @@ -0,0 +1,117 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Deleting a transaction makes the app immediately ask wallet-core for it again + +Found by the `history_delete` scenario, which reproduces it on **every run** — +five rounds so far, three stray requests each. + +**Severity: low.** Nothing visible goes wrong — the row disappears and the user +is returned to the list — but every deletion leaves an error in the log, which +is noise in exactly the place one looks when triaging a real problem. + +## What happens + +Deleting a transaction from its detail screen deletes it, and then the screen +asks for it once more: + +``` +{"type":"error","operation":"getTransactionById","id":78, + "error":{"code":7052, + "hint":"transaction txn:payment:7W5B3DR0…X5Z0 not found", + "transactionId":"txn:payment:7W5B3DR0…X5Z0"}} +``` + +wallet-core also records it as a failed database query +(`db-query-finish-error` at `handleTxRetries/runWalletDbTx`). Three such +requests go out per deletion, consistently: + +```console +$ for d in /opt/taler-sim/run/out/*history_delete; do + echo "$(basename $d): $(grep -c '"code":7052' $d/logcat.txt)"; done +suite-w1-1792268945-history_delete: 3 +suite-w1-1792270256-history_delete: 3 +suite-w1-1792272286-history_delete: 3 +suite-w1-1792274698-history_delete: 3 +suite-w1-1792277245-history_delete: 3 +``` + +The error code makes it worse: 7052 (`WALLET_TRANSACTION_NOT_FOUND`) is not in +the app's `TalerErrorCode.kt`, so even if the app wanted to recognise this case +it could not — see `error-code-registry-behind-wallet-core.md`. + +## Reproduce by hand + +1. Install a debug build, enable **Developer mode** in Settings. +2. Get a transaction into the wallet: withdraw once, or pay for something + (against the local stack from `simulator/README.md`, or any deployment). +3. Start `adb logcat | grep -E 'getTransactionById|7052'` in a terminal. +4. On the main screen, under **Recent transactions**, tap the transaction. +5. On the detail screen tap **Delete**, then confirm **Delete** in the dialog. + +The list comes back without the row, and the log shows the +`getTransactionById` request for the id that was just deleted, answered with +"transaction … not found". + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_delete_requeries_transaction.py +``` + +Prints the stray error lines and `reproduced: True`. + +## Why + +Not the detail screen's observer, which is what this finding first said — the +requests come from the notification handler, and clearing the selection would +not stop one of them. + +Deleting a transaction makes wallet-core emit transaction-state-transition +notifications for it, and the handler asks for the transaction *before* it can +know what the transition was: + +```kotlin +// wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt:170 +fun onTransactionStateTransition(transactionId: String) = scope.launch { + val transaction = getTransactionById(transactionId) // 7052 after a delete + … + if (transaction == null) return@launch +``` + +It needs the transaction for two things — refreshing the copy the detail screen +is showing, and learning which scopes' lists to reload — and after a deletion +neither applies, but the query has already gone out. A deletion emits several +transitions, which is why exactly three requests appear rather than one. + +`getTransactionById` then logs every failure at error level +(`Log.e(TAG, "Error getting transaction $it")`), so each one lands in the log +as an error. + +## Suggested fix + +Remember the ids this wallet has just deleted and let the handler skip them: +the transaction is gone, so there is nothing to refresh and no scope to +reload. A small bounded set is enough — an id cannot come back, and only the +transitions that follow the deletion matter. + +Treating 7052 as an expected outcome instead would also work, but the app +cannot currently recognise it: `WALLET_TRANSACTION_NOT_FOUND` is not in +`TalerErrorCode.kt`, so the code does not survive deserialization (see +`error-code-registry-behind-wallet-core.md`). That makes the id-based fix the +one that can be written today. diff --git a/wallet-simulator/findings/deposit-does-not-guard-zero-amounts.md b/wallet-simulator/findings/deposit-does-not-guard-zero-amounts.md @@ -0,0 +1,102 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# The deposit screen does not guard zero or below-fee amounts + +Found by the `deposit_flow` scenario; the oracles flagged the internal error +and the transaction that came out of it looked wrong, which led to the second +half. + +**Severity: low-moderate.** Both halves are reachable by any user with a +balance, in a release build, from Settings-free navigation (the balance card's +**Deposit** button). + +## Half one: clearing the amount raises an internal error + +Type an amount, then tap **Reset**. The screen goes back to €0.00 and the app +prices the empty deposit: + +``` +{"type":"error","operation":"checkDeposit","id":50,"error":{"code":7001, + "hint":"unexpected exception (message: can't sum zero amounts)", + "stack":" at sum (<compiled_js>:5729:18) + at getCounterpartyEffectiveDepositAmount (<compiled_js>:70346:38)"}} +``` + +`WALLET_UNEXPECTED_EXCEPTION` — wallet-core treating it as a bug rather than as +a request it can decline. Nothing is shown; it repeats as the debounce fires. + +## Half two: an amount at or below the fee produces a zero deposit + +With a deposit fee of EUR:0.01, entering **0.01** and tapping **Make deposit** +creates a transaction that reads: + +``` +This transaction is finalizing +Chosen amount €0.00 +Fee -€0.01 +Amount sent -€0.01 +``` + +"Show JSON" confirms the wallet stored exactly that: + +```json +"amountRaw": "EUR:0", +"amountEffective": "EUR:0.01" +``` + +So the user asked to deposit one cent, the wallet deposited nothing, charged a +cent, and displays a negative "Amount sent" — while the deposit itself goes +through to the exchange. + +## Reproduce by hand + +Needs a wallet with a balance (withdraw once first). + +1. On the main screen tap **Deposit**. +2. Pick the bank account offered (e.g. `wallet1`). +3. Type `500` — the field fills from the right, so this is €5.00 — then tap + **Reset**. With `adb logcat | grep -i "sum zero"` running, the internal + error appears within a second or two. +4. Now type `1` (€0.01) and tap **Make deposit**. +5. The transaction screen shows "Chosen amount €0.00", "Fee −€0.01", + "Amount sent −€0.01". + +Expected: an amount of zero is not worth pricing, and an amount that cannot +cover the fee should be refused with a message — the screen already has +`R.string.amount_invalid` ("Amount invalid") and `amount_excess` for the +opposite bound. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_zero_deposit.py +``` + +## Suggested fix + +In `deposit/DepositAmountComposable.kt`, skip the `checkDeposit` call while the +amount is zero (the debounce already has the amount in hand), and disable +**Make deposit** until the amount is strictly greater than the fee reported by +`checkDeposit`, showing `amount_invalid` otherwise. Mirroring the +"Insufficient balance" treatment at the upper bound would make the two +boundaries consistent. + +Worth raising with wallet-core as well: `checkDeposit` of a zero amount is a +client asking a reasonable question, so a declined request would be a better +answer than an unexpected exception. diff --git a/wallet-simulator/findings/dev-experiment-uri-exits-the-app.md b/wallet-simulator/findings/dev-experiment-uri-exits-the-app.md @@ -0,0 +1,112 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# An unknown `dev-experiment` URI closes the wallet, and its error is never shown + +Found by the `uri_dev_experiment` scenario. + +**Severity: low** — `taler://dev-experiment/` is only accepted in developer +mode. What makes it worth fixing is the shape of the failure: the error is +collected into a variable that nothing will ever display, and the user is +dropped onto the Android home screen. + +## What happens + +Sharing `taler+http://dev-experiment/nonexistent` into the wallet: + +* wallet-core answers with `WALLET_UNEXPECTED_EXCEPTION` (7001): + `unexpected exception (message: dev-experiment id not understood nonexistent)` +* the wallet **leaves the foreground**: the next screen is the launcher, not + the wallet. This happens when the URI arrives while the wallet is closed — + scanning a QR code or following a link, which is the ordinary case. With the + wallet already open the screen pops back to the main screen instead, so the + error is merely invisible rather than disruptive. + +The simulator recorded the screen after the URI as +`['At a glance', 'Sat, Oct 17', 'Gmail', 'Photos', 'YouTube', …]` — the +emulator's home screen. + +An empty id (`taler+http://dev-experiment/`) behaves differently and correctly: +the wallet stays open on the main screen. + +## Reproduce by hand + +1. Install a debug build and enable **Developer mode**. +2. Close the wallet (swipe it away, or + `adb shell am force-stop net.taler.wallet.fdroid.debug`) — the URI has to + arrive while it is not running. +3. Run `adb logcat | grep applyDevExperiment` in a terminal. +4. Share the URI into the wallet, e.g. + + ```bash + adb shell am start -a android.intent.action.SEND -t text/plain \ + -n net.taler.wallet.fdroid.debug/net.taler.wallet.main.MainActivity \ + --es android.intent.extra.TEXT 'taler+http://dev-experiment/nonexistent' + ``` + + (A QR code with the same text, scanned from the wallet, does the same.) +5. The wallet opens, closes again and the home screen appears. The log shows + the 7001 error; nothing is shown in the app. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_dev_experiment_uri_exits_app.py +``` + +## Why + +`wallet/src/main/java/net/taler/wallet/HandleUriScreen.kt:128`: + +```kotlin +action.startsWith("dev-experiment/", ignoreCase = true) -> { + model.applyDevExperiment(u2) { error -> + errorInfo = error + } + onNavigateBack() +} +``` + +`applyDevExperiment` is asynchronous, and `onNavigateBack()` runs immediately, +without waiting for it. Two consequences: + +* the error callback assigns to `errorInfo` after the screen that would render + it has already been popped, so the message is lost; +* when the URI arrived from outside (a share or a scan), there is nothing + behind this screen, so popping it finishes the activity and the user lands + on the home screen. + +Every other branch in the same `when` navigates *forward* to a screen that +reports its own outcome; this is the only one that pops first. + +## Suggested fix + +Navigate back only on success, and let the error render: + +```kotlin +action.startsWith("dev-experiment/", ignoreCase = true) -> { + model.applyDevExperiment(u2) { error -> + errorInfo = error // stays on screen, shows the sheet + } + // onNavigateBack() only once applyDevExperiment reports success +} +``` + +Separately, "dev-experiment id not understood" is a user-supplied value being +rejected, so wallet-core returning `WALLET_UNEXPECTED_EXCEPTION` for it is +arguably wrong as well; a dedicated code would let the app say what happened. diff --git a/wallet-simulator/findings/donation-statements-button-is-wired-to-nothing.diff b/wallet-simulator/findings/donation-statements-button-is-wired-to-nothing.diff @@ -0,0 +1,80 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/balances/BalancesPagerComposable.kt b/wallet/src/main/java/net/taler/wallet/balances/BalancesPagerComposable.kt +index c2a8b928..0a09738c 100644 +--- a/wallet/src/main/java/net/taler/wallet/balances/BalancesPagerComposable.kt ++++ b/wallet/src/main/java/net/taler/wallet/balances/BalancesPagerComposable.kt +@@ -193,6 +193,7 @@ fun BalancesPagerComposable( + onShowPendingOutgoing: (ScopeInfo) -> Unit, + onShowDiscounts: (ScopeInfo?) -> Unit, + onShowPasses: (ScopeInfo?) -> Unit, ++ onShowStatements: (host: String?) -> Unit, + ) { + if (state.showWelcome()) { + return EmptyBalancesComposable( +@@ -254,7 +255,7 @@ fun BalancesPagerComposable( + onWithdrawMoneyClicked = onWithdrawMoney, + onGetDemoMoneyClicked = onGetDemoMoney, + onBalanceClicked = onBalanceSelected, +- onStatementClicked = { onBalanceSelected(null) } ++ onStatementClicked = { host -> onShowStatements(host) } + ) + } else { + val scope = balance.scopeInfo +@@ -280,7 +281,7 @@ fun BalancesPagerComposable( + onShowAllTransactions = { onShowAllTransactions(scope) }, + onShowPendingIncoming = { onShowPendingIncoming(scope) }, + onShowPendingOutgoing = { onShowPendingOutgoing(scope) }, +- onShowStatements = { onBalanceSelected(null) }, ++ onShowStatements = { onShowStatements(null) }, + onShowDiscounts = { onShowDiscounts(scope) }, + onShowPasses = { onShowPasses(scope) }, + ) +@@ -801,6 +802,7 @@ fun BalancesPagerComposablePreview() { + onShowPendingOutgoing = {}, + onShowDiscounts = {}, + onShowPasses = {}, ++ onShowStatements = {}, + ) + } + } +\ No newline at end of file +diff --git a/wallet/src/main/java/net/taler/wallet/main/MainScreen.kt b/wallet/src/main/java/net/taler/wallet/main/MainScreen.kt +index bd913dd9..4d22253d 100644 +--- a/wallet/src/main/java/net/taler/wallet/main/MainScreen.kt ++++ b/wallet/src/main/java/net/taler/wallet/main/MainScreen.kt +@@ -59,6 +59,7 @@ import net.taler.wallet.balances.BalanceState + import net.taler.wallet.balances.BalancesPagerComposable + import net.taler.wallet.compose.GlobalScaffold + import net.taler.wallet.compose.collectAsStateLifecycleAware ++import net.taler.wallet.donau.GetDonauStatus + import net.taler.wallet.scan.ScanTab + import net.taler.wallet.transactions.TransactionStateFilter + import net.taler.wallet.transactions.onTransactionClicked +@@ -81,6 +82,7 @@ fun MainScreen( + val balanceState by model.balanceManager.state.observeAsState(BalanceState.None) + val viewMode by model.viewMode.collectAsStateLifecycleAware() + val devMode by model.devMode.observeAsState(false) ++ val donauStatus by model.donauManager.donauStatus.collectAsStateLifecycleAware() + val txResults = remember(balanceState) { + (balanceState as? BalanceState.Success)?.let { state -> + state.balances.associate { balance -> +@@ -214,6 +216,20 @@ fun MainScreen( + onShowPasses = { + onNavigate(WalletDestination.PassList, false) + }, ++ onShowStatements = { host -> ++ // A statement row knows which donau it belongs to; the action ++ // button on a balance does not, so it falls back to the one ++ // the wallet is configured with -- and sends the user to the ++ // setup screen when there is none, rather than doing nothing. ++ val configured = (donauStatus as? GetDonauStatus.Success) ++ ?.donauInfo?.donauBaseUrl ++ val donau = host ?: configured ++ if (donau != null) { ++ onNavigate(WalletDestination.DonauStatement(donau), false) ++ } else { ++ onNavigate(WalletDestination.SetDonau(), false) ++ } ++ }, + ) + } + } diff --git a/wallet-simulator/findings/donation-statements-button-is-wired-to-nothing.md b/wallet-simulator/findings/donation-statements-button-is-wired-to-nothing.md @@ -0,0 +1,132 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# "Donation statements" does nothing, and its whole screen is unreachable + +The random exploration kept reporting this and it kept being filed as noise: + +``` +[silent-failure] tapping 'Donation statements' changed nothing on screen +``` + +It is not noise. The button is wired to a no-op, and behind it sits a complete +feature that nothing in the app can open. + +**Severity: moderate.** A labelled button on the main balance screen does +nothing when tapped — no navigation, no message, no change. Two composables +(~90 lines), a registered navigation destination and a wallet-core operation +are dead because of it. + +## What happens + +On the balance screen, the row under the recent transactions has three action +buttons: **Discounts**, **Passes**, **Donation statements**. The first two +open their screens. The third does nothing at all. + +If the wallet holds donau receipts, the balances list also shows a +**Donation statements** section whose rows look tappable. They do nothing +either. + +## Why + +The three buttons sit in one row, and two of them are wired to navigation +while the third is wired to clearing the balance selection: + +```kotlin +// wallet/src/main/java/net/taler/wallet/balances/BalancesPagerComposable.kt:283 +onShowStatements = { onBalanceSelected(null) }, +onShowDiscounts = { onShowDiscounts(scope) }, +onShowPasses = { onShowPasses(scope) }, +``` + +and `onBalanceSelected` only changes which balance is displayed: + +```kotlin +// wallet/src/main/java/net/taler/wallet/main/MainScreen.kt:171 +onBalanceSelected = { model.displayScope(it?.scopeInfo) }, +``` + +With `null` that is a no-op from the user's point of view. The statement rows +in the list have the same handler: + +```kotlin +// wallet/src/main/java/net/taler/wallet/balances/BalancesPagerComposable.kt:257 +onStatementClicked = { onBalanceSelected(null) } +``` + +even though `BalancesListComposable` passes a real argument for it — +`onStatementClicked(statement.donauBaseUrl)` — which is exactly the `host` the +statement screen wants. + +## What is unreachable as a result + +* `WalletDestination.DonauStatement(host)` is declared + (`WalletNavigation.kt:70`) and registered in the nav host + (`WalletNavHost.kt:291`), and **nothing navigates to it**: + + ```bash + $ grep -rn 'WalletDestination.DonauStatement' --include=*.kt wallet/src/main/java + WalletNavHost.kt:291: composable<WalletDestination.DonauStatement> { backStackEntry -> + WalletNavHost.kt:292: val dest = backStackEntry.toRoute<WalletDestination.DonauStatement>() + ``` + +* `DonauStatementScreen` (35 lines) and `DonauStatementComposable` (55 lines) + therefore never render — they read 0 % in every coverage report of this + campaign. +* `getDonauStatements` is called from exactly one place, + `DonauStatementScreen.kt:51`, so that wallet-core operation has no reachable + caller either. It is one of the operations this campaign could never + exercise from the app. + +The donau *package* sits at 38 % line coverage, the lowest of any feature +package, and this button is why. + +## Reproduce by hand + +1. Install a debug build and withdraw once, so there is a balance to show. +2. On the balance screen, scroll to the row with **Discounts**, **Passes** and + **Donation statements**. +3. Tap **Discounts** — a screen opens. Go back. Tap **Passes** — a screen + opens. Go back. +4. Tap **Donation statements** — nothing happens. `adb logcat` shows no + navigation and no error. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=0 python3 -u suite.py donau_receipt +``` + +The scenario taps the button and records the screen before and after; the +silent-failure oracle flags it, which is how it first showed up. + +## Suggested fix + +Wire it the way its two neighbours are wired: + +```kotlin +onShowStatements = { onShowStatements(scope) }, // in the pager +onStatementClicked = { host -> onStatementClicked(host) }, // in the list +``` + +with `MainScreen` navigating to `WalletDestination.DonauStatement(host)` — the +screen already fetches its own statements from the host it is given, so nothing +else is needed. The list's rows carry the right `donauBaseUrl` already. + +If the feature is meant to be unfinished, the button should not be on the +balance screen: a control that does nothing is worse than one that is absent. diff --git a/wallet-simulator/findings/error-code-registry-behind-wallet-core.md b/wallet-simulator/findings/error-code-registry-behind-wallet-core.md @@ -0,0 +1,106 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# The app's error-code registry is behind the wallet-core it ships + +Found by tallying every error reply in the simulator's logs +(`simulator/coverage/operations.py`): two of the four codes the wallet-core in +`net.taler:qtart:1.6.42` returned during normal scenarios are not in +`wallet/src/main/java/net/taler/wallet/backend/TalerErrorCode.kt`. + +**Severity: low, but it grows.** `TalerErrorInfo.rawCode` keeps the number, so +nothing crashes and the hint text still reaches the user; what is lost is the +ability to recognise the error. Any `code == TalerErrorCode.X` branch added for +one of these cases would silently never match, and triage reads "UNKNOWN". + +## What was observed + +| Operation | Code returned | Name upstream | +| --- | --- | --- | +| `getTransactionById` | 7052 | `WALLET_TRANSACTION_NOT_FOUND` | +| `startRefundQueryForUri` | 7051 | `WALLET_PURCHASE_NOT_FOUND` | + +Neither number appears in `TalerErrorCode.kt`, so both arrive as +`TalerErrorCode.UNKNOWN` with `rawCode` set. + +## The size of the gap + +Against the registry in the `taler-typescript-core` checkout (the source the +bundled wallet-core is built from), the app is missing **141 codes** +in total, of which **26** are in the wallet's own 7xxx range +and therefore reachable from the app: + +| Code | Name | +| --- | --- | +| 7050 | `WALLET_PAY_MERCHANT_INSUFFICIENT_BALANCE` | +| 7051 | `WALLET_PURCHASE_NOT_FOUND` | +| 7052 | `WALLET_TRANSACTION_NOT_FOUND` | +| 7053 | `WALLET_TRANSACTION_ACTION_UNSUPPORTED` | +| 7054 | `WALLET_KYC_LIMIT_EXCEEDED` | +| 7055 | `WALLET_NO_SUITABLE_EXCHANGE` | +| 7056 | `WALLET_BANK_ACCOUNT_NOT_FOUND` | +| 7057 | `WALLET_PEER_CONTRACT_NOT_FOUND` | +| 7058 | `WALLET_PEER_PUSH_CREDIT_PURSE_GONE` | +| 7059 | `WALLET_PEER_PULL_DEBIT_ALREADY_PAID` | +| 7060 | `WALLET_TOKENS_IN_USE` | +| 7061 | `WALLET_DB_BACKEND_UNSUPPORTED` | +| 7062 | `WALLET_MAILBOX_UNAVAILABLE` | +| 7063 | `WALLET_ALIAS_REGISTRATION_FAILED` | +| 7064 | `WALLET_CONTRACT_TERMS_UNSUPPORTED` | +| 7065 | `WALLET_EXCHANGE_SIGNATURE_INVALID` | +| 7066 | `WALLET_EXCHANGE_KEYS_NOT_ACCEPTED` | +| 7067 | `WALLET_EXCHANGE_NO_KEY_CHANGE_PENDING` | +| 7068 | `WALLET_EXCHANGE_KEY_CHANGE_MISMATCH` | +| 7069 | `WALLET_PEER_PUSH_PAYMENT_QUOTE_CHANGED` | +| 7070 | `WALLET_TRANSACTION_COMPLETED_BY_OTHER_WALLET` | +| 7071 | `WALLET_REFRESH_GROUP_FAILED` | +| 7072 | `WALLET_RECOUP_GROUP_FAILED` | +| 7073 | `WALLET_REFUND_GROUP_FAILED` | +| 7074 | `WALLET_TRANSACTION_RECOVERY_FAILED` | +| 7075 | `WALLET_TRANSACTION_DEPENDENCY_FAILED` | + +## Reproduce by hand + +```bash +# Codes the app knows nothing about, yet wallet-core can return: +grep -c 'WALLET_TRANSACTION_NOT_FOUND' \ + wallet/src/main/java/net/taler/wallet/backend/TalerErrorCode.kt # 0 +grep -c '7052' \ + wallet/src/main/java/net/taler/wallet/backend/TalerErrorCode.kt # 0 +``` + +To see one arrive, follow `delete-transaction-requeries-deleted-id.md`: deleting +a transaction logs an error with `"code":7052`. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/coverage && python3 operations.py /opt/taler-sim/run/out +``` + +The "operations that returned an error, with codes" section lists each code +observed, by operation. + +## Suggested fix + +`TalerErrorCode.kt` carries an LGPL header and is a transcription of the GANA +`gnu-taler-error-codes` registry, so it should be regenerated from that registry +rather than extended by hand — ideally pinned to the same release as the +`qtart` version in `wallet/build.gradle`, since that is what decides which +codes can actually arrive. A check that fails the build when the bundled +wallet-core knows a code the registry does not would keep the two from drifting +again. diff --git a/wallet-simulator/findings/mailbox-payment-only-actionable-for-one-scheme.diff b/wallet-simulator/findings/mailbox-payment-only-actionable-for-one-scheme.diff @@ -0,0 +1,93 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/Utils.kt b/wallet/src/main/java/net/taler/wallet/Utils.kt +index 6e0ecdc0..2c2762fe 100644 +--- a/wallet/src/main/java/net/taler/wallet/Utils.kt ++++ b/wallet/src/main/java/net/taler/wallet/Utils.kt +@@ -63,6 +63,7 @@ import net.taler.common.AmountParserException + import net.taler.lib.android.showError + import net.taler.lib.android.startActivitySafe + import net.taler.wallet.backend.TalerErrorInfo ++import java.util.Locale + + const val CURRENCY_BTC = "BITCOINBTC" + +@@ -117,6 +118,31 @@ private fun connectToWifiDeprecated(context: Context, ssid: String) { + } + } + ++/** ++ * The action part of a Taler URI, whatever scheme it arrived under. ++ * ++ * `taler://`, `ext+taler://` and `taler+http://` all carry the same actions, ++ * and schemes are case-insensitive per RFC 3986. Testing for one spelling by ++ * hand is how a payment that arrived by mailbox became unactionable and how ++ * the forward-to-contact button stopped appearing in the one mode that offers ++ * it -- so anything deciding *which* action a URI names should ask here. ++ * ++ * Returns null for a URI that is not a Taler URI at all. ++ */ ++fun talerUriAction(uri: String): String? { ++ val lower = uri.lowercase(Locale.ROOT) ++ for (scheme in listOf("taler://", "ext+taler://", "taler+http://")) { ++ if (lower.startsWith(scheme)) return lower.substring(scheme.length) ++ } ++ return null ++} ++ ++/** Whether a Taler URI names one of these actions, under any scheme. */ ++fun talerUriIsAction(uri: String, vararg actions: String): Boolean { ++ val action = talerUriAction(uri) ?: return false ++ return actions.any { action.startsWith(it) } ++} ++ + fun cleanExchange(exchange: String) = exchange.let { + if (it.startsWith("https://", ignoreCase = true)) it.substring(8) else it + }.trimEnd('/') +diff --git a/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt b/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt +index dd378132..57da5de0 100644 +--- a/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt ++++ b/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt +@@ -61,6 +61,7 @@ import net.taler.lib.android.QrCodeManager + import net.taler.lib.android.QrLogoSize + import net.taler.lib.android.copyToClipBoard + import net.taler.wallet.R ++import net.taler.wallet.talerUriIsAction + + sealed class QrCodeParams { + data object Taler: QrCodeParams() +@@ -179,7 +180,12 @@ fun ColumnScope.QrCodeUriComposable( + ), + ) + +- if (devMode && onForward != null && (qrData.startsWith("taler://pay-push") || qrData.startsWith("taler://pay-pull"))) { ++ // In developer mode the wallet's own URIs are taler+http://, so ++ // testing for taler:// here meant this button never appeared in ++ // the only mode that offers it. ++ if (devMode && onForward != null && ++ talerUriIsAction(qrData, "pay-push", "pay-pull") ++ ) { + ForwardButton( + onClick = { onForward(qrData) }, + colors = ButtonDefaults.buttonColors( +diff --git a/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt b/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt +index 01073ef5..58eee7b1 100644 +--- a/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt ++++ b/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt +@@ -68,6 +68,7 @@ import net.taler.common.Timestamp + import net.taler.lib.android.toAbsoluteTime + import net.taler.wallet.NavigateCallback + import net.taler.wallet.R ++import net.taler.wallet.talerUriIsAction + import net.taler.wallet.WalletDestination + import net.taler.wallet.compose.TalerSurface + import net.taler.wallet.main.MainViewModel +@@ -242,8 +243,8 @@ fun MessageItem( + onDelete: (MailboxMessageRecord) -> Unit, + ) { + val context = LocalContext.current +- val isPayPush = message.talerUri.startsWith("taler://pay-push") +- val isPayPull = message.talerUri.startsWith("taler://pay-pull") ++ val isPayPush = talerUriIsAction(message.talerUri, "pay-push") ++ val isPayPull = talerUriIsAction(message.talerUri, "pay-pull") + Row( + modifier = Modifier + .fillMaxWidth() diff --git a/wallet-simulator/findings/mailbox-payment-only-actionable-for-one-scheme.md b/wallet-simulator/findings/mailbox-payment-only-actionable-for-one-scheme.md @@ -0,0 +1,198 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Mailbox payments work only if the URI says "taler://" — in and out + +Found by the `mailbox_roundtrip` scenario, the first thing in this campaign to +put a real message in the wallet's mailbox: the message arrived, the row showed +the URI as plain text, and there was no way to act on it. The same test, +written later for the *sending* side, found the identical mistake there. + +**Severity: low-moderate.** The scheme that fails is `taler+http://`, which is +what every development and test deployment uses — exactly where someone would +first try the feature. The same rows also fail for the `ext+taler://` form the +app accepts everywhere else. + +On the sending side it is worse than a scheme mismatch: the button that +forwards a payment to a contact is shown **only in developer mode**, and the +scheme it insists on is the one developer mode does not produce, so the feature +cancels itself out (below). + +## What happens + +Another wallet sends a push payment to this wallet's mailbox address. The +message is received and listed: + +``` +taler+http://pay-push/localhost:8081/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +From: http://localhost:11000 +Received: October 18, 2026 at 6:38 AM +[Delete] +``` + +The URI is printed as text and the only button is **Delete**. With a +`taler://` URI, the same row shows an **"Accept payment"** button that opens +the payment. + +Both at once, from one run — two messages sent to the same mailbox differing +only in the scheme: + +``` +after two real messages: ['Accept payment', + 'From: http://localhost:11000', + 'Received: October 18, 2026 at 6:42 AM', + 'Delete', + 'taler+http://pay-push/localhost:8081/AAAA…', + 'From: http://localhost:11000', + 'Received: October 18, 2026 at 6:42 AM', …] +rows offering an action: 1 +rows showing a raw URI: ['taler+http://pay-push/localhost:8081/AAAA…'] +``` + +## Why + +The row decides by exact prefix: + +```kotlin +// wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt:245 +val isPayPush = message.talerUri.startsWith("taler://pay-push") +val isPayPull = message.talerUri.startsWith("taler://pay-pull") +… +if (isPayPush || isPayPull) { + Button(onClick = { onNavigate(WalletDestination.HandleUri(message.talerUri), false) }) { + Text(if (isPayPush) "Accept payment" else "Pay invoice") + } +} else { + Text(message.talerUri, style = MaterialTheme.typography.bodyMedium) +} +``` + +Three URIs the app handles elsewhere fall into the `else`: + +* `taler+http://pay-push/…` — the developer-mode scheme, which is the only one + that works against a local deployment; +* `ext+taler://pay-push/…` — the browser-extension form; +* `TALER://PAY-PUSH/…` — schemes are case-insensitive per RFC 3986. + +Everywhere else the app is careful about this. `HandleUriScreen` lowercases +the whole URI and strips `taler://`, `ext+taler://` or `taler+http://` before +matching the action: + +```kotlin +// wallet/src/main/java/net/taler/wallet/HandleUriScreen.kt:60 +val normalizedURL = u.lowercase(Locale.ROOT) +… +if (normalizedURL.startsWith("taler://", ignoreCase = true)) … +else if (normalizedURL.startsWith("ext+taler://", ignoreCase = true)) … +else if (normalizedURL.startsWith("taler+http://", ignoreCase = true) && devMode) … +``` + +so the mailbox row is *not* the only place that knows about one of the three. + +### The same prefix test hides the forward button + +The way *out* of the wallet has it too. A peer-push transaction's QR screen +offers a button that forwards the payment to a contact's mailbox — the only +caller of `sendTalerUriMailboxMessage` — and it is gated the same way: + +```kotlin +// wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt:183 +if (devMode && onForward != null && + (qrData.startsWith("taler://pay-push") || qrData.startsWith("taler://pay-pull"))) { + ForwardButton(onClick = { onForward(qrData) }, …) +} +``` + +Note the first condition: the button exists **only in developer mode**. But in +developer mode against a local deployment the wallet's own push URI is +`taler+http://pay-push/…`, so the prefix test fails and the button is never +drawn. Measured, with developer mode on: + +``` +forward_payment_to_contact: + Scan this QR code to receive €5.00 + Alternatively, copy and send this URI: + taler+http://pay-push/localhost:8081/3ZTJWX7HJ0G1J8R64Z6VFXGG35SX9R9XFMK4BPF79WMV5CNCYDH0 + -> no forward button on the push screen +``` + +The two conditions contradict each other: one restricts the feature to +developer mode, the other to the scheme developer mode does not produce. It +survives only when a dev-mode wallet talks to an `https://` exchange. + +## Reproduce by hand + +Needs a mailbox service and a second wallet; against the simulator's stack +(`simulator/backend/services/README.md` has the deployment): + +1. In the wallet, Settings → **Mailbox** → the gear icon → type + `http://localhost:11000` → OK. The wallet registers itself; the info icon + shows its address. +2. From another wallet, send a push payment URI to that address. With + `taler-wallet-cli`: + + ```bash + taler-wallet-cli --wallet-db /tmp/sender.sqlite3 advanced api \ + sendTalerUriMailboxMessage '{"contact":{"alias":"x@example.com","aliasType":"email", + "mailboxBaseUri":"http://127.0.0.1:11000/","mailboxAddress":"<THE ADDRESS>", + "source":"local","petname":"test","originMailboxBaseUrl":"http://127.0.0.1:11000/", + "downloadedAt":{"t_s":0},"talerUri":"","transactionId":""}, + "talerUri":"taler+http://pay-push/localhost:8081/AAAA…"}' + ``` + +3. Tap **Refresh** in the mailbox screen. The message appears with its URI as + text and no action. +4. Send the same thing again with `taler://` instead of `taler+http://`: that + row has an "Accept payment" button. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=4 python3 suite.py mailbox_roundtrip +``` + +The scenario sends one message of each scheme and reports how many rows offer +an action and which ones show a bare URI. + +For the forward button, which fails for the same reason: + +```bash +SIM_WORKER=4 python3 suite.py forward_payment_to_contact +``` + +It makes a push payment with developer mode on and looks for the button on the +QR screen; its note says what the screen offered instead. + +## Suggested fix + +Decide the action the way `HandleUriScreen` does — normalise the scheme first, +and match the action case-insensitively: + +```kotlin +val action = message.talerUri.lowercase(Locale.ROOT) + .removePrefix("ext+taler://").removePrefix("taler+http://").removePrefix("taler://") +val isPayPush = action.startsWith("pay-push") +val isPayPull = action.startsWith("pay-pull") +``` + +and the same in `QrCodeUriComposable`'s forward-button condition. + +A shared helper would be better than a fourth copy of that logic: the +normalisation is already written out in `HandleUriScreen` and partly again in +`ContactScreen`'s `fillFromUri`. One `talerUriAction(uri): String?` used by all +four would have made both of these impossible. diff --git a/wallet-simulator/findings/mailbox-private-keys-written-to-log.diff b/wallet-simulator/findings/mailbox-private-keys-written-to-log.diff @@ -0,0 +1,49 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/mailbox/MailboxManager.kt b/wallet/src/main/java/net/taler/wallet/mailbox/MailboxManager.kt +index dac720c5..809a6bae 100644 +--- a/wallet/src/main/java/net/taler/wallet/mailbox/MailboxManager.kt ++++ b/wallet/src/main/java/net/taler/wallet/mailbox/MailboxManager.kt +@@ -40,7 +40,17 @@ data class MailboxConfiguration( + val hAddress: String, + val expiration: Timestamp, + val payUri: String? = null, +-) ++) { ++ /** ++ * Without this the generated toString() puts both private keys in any log ++ * line this object is interpolated into -- and it was interpolated into ++ * two. ++ */ ++ override fun toString(): String = ++ "MailboxConfiguration(mailboxBaseUrl=$mailboxBaseUrl, hAddress=$hAddress, " + ++ "expiration=$expiration, payUri=$payUri, " + ++ "privateKey=<redacted>, privateEncryptionKey=<redacted>)" ++} + + @Serializable + data class MailboxMessageRecord( +@@ -100,14 +110,14 @@ class MailboxManager( + fun loadMailbox(baseUrl: String = "https://mailbox.gnunet.org") { + _mailbox.value = MailboxResult.Loading + scope.launch { +- Log.e(TAG, "Loading mailbox") ++ Log.d(TAG, "loading mailbox at $baseUrl") + api.request("getMailbox", GetMailboxResponse.serializer()) { + put("mailboxBaseUrl", baseUrl) + }.onSuccess { resp -> + if (null == resp.mailboxConfiguration) { + initializeMailbox(baseUrl) + } else { +- Log.e(TAG, "Got mailbox ${resp.mailboxConfiguration}") ++ Log.d(TAG, "got mailbox at ${resp.mailboxConfiguration.mailboxBaseUrl}") + getMessages(resp.mailboxConfiguration) + } + }.onError { +@@ -143,7 +153,7 @@ class MailboxManager( + + fun refreshMailbox(config: MailboxConfiguration) { + +- Log.e(TAG, "Rereshing mailbox ${config}") ++ Log.d(TAG, "refreshing mailbox at ${config.mailboxBaseUrl}") + scope.launch { + api.request("refreshMailbox", MailboxMessagesResponse.serializer()) { + JSONObject(BackendManager.json.encodeToString(config)) diff --git a/wallet-simulator/findings/mailbox-private-keys-written-to-log.md b/wallet-simulator/findings/mailbox-private-keys-written-to-log.md @@ -0,0 +1,93 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# The mailbox's private keys are written to the log every 30 seconds + +Noticed in a simulator log while investigating something else: with developer +mode on, the wallet logs its whole mailbox configuration — including both +private keys — at **error** level, every 30 seconds. + +**Severity: moderate.** It is developer-mode only, but developer mode is also +where "Debug log → Save internal log" lives, and that export is exactly what a +user is asked for when reporting a problem. Sending that file hands over the +keys to the wallet's mailbox. + +## What happens + +``` +E taler-wallet: Rereshing mailbox MailboxConfiguration( + mailboxBaseUrl=https://mailbox.gnunet.org, + privateKey=K5ZN6AW2WQVE4T7G22EXPNR1HCBZZAVKMP3JXEXTGF5X1TV2B0CG, + privateEncryptionKey=9Q59Z0H38JB4N4F40VXAB33Q799KN6XTAW1ARN2H7DTMM9Q2H5H0, + hAddress=E4RBDRX49F7M2V3H1JJVQ0MN0QVVJHTRMEG4300ZCWMXEPQMQWXMHZ7C80VBHVM69HX7Y59X05F70KNGR1K94DK87TT8BGA11TX5X2G, + expiration=Timestamp(s=1823806854), payUri=null) +``` + +`MailboxConfiguration` is a data class, so string interpolation prints every +field. + +## Reproduce by hand + +1. Install the wallet and enable **Developer mode** in Settings. +2. Run `adb logcat | grep -i "Rereshing mailbox"` (the typo is in the source). +3. Wait up to 30 seconds. The line appears, with `privateKey=` and + `privateEncryptionKey=` in full, and repeats every 30 seconds. + +The same content reaches a file through Settings → **Debug log**, which runs +`logcat -d *:V`. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_mailbox_private_keys_in_log.py +``` + +## Why + +`wallet/src/main/java/net/taler/wallet/mailbox/MailboxManager.kt:146`: + +```kotlin +fun refreshMailbox(config: MailboxConfiguration) { + + Log.e(TAG, "Rereshing mailbox ${config}") +``` + +Left-over debug output: error level, no `BuildConfig.DEBUG` guard, and a typo +in the message. `MailboxManager.start()` schedules `refreshMailbox` every 30 +seconds while `isDevMode()` is true (`MailboxManager.kt:82-98`). + +## Suggested fix + +Delete the line. If a trace is wanted, log the base URL alone and at debug +level: + +```kotlin +Log.d(TAG, "refreshing mailbox at ${config.mailboxBaseUrl}") +``` + +Worth considering alongside it: give `MailboxConfiguration` a `toString()` that +redacts the two key fields, so no future interpolation can leak them. + +## Also worth deciding + +`MainViewModel.onInitReceived` calls `mailboxManager.start()` unconditionally, +and `start()` calls `loadMailbox()` with a hardcoded +`https://mailbox.gnunet.org`. Every wallet start therefore contacts that host, +in release builds too, before the user has asked for anything to do with +messaging. Whether that is intended is a product decision, but it is worth +being deliberate about. diff --git a/wallet-simulator/findings/new_finding.py b/wallet-simulator/findings/new_finding.py @@ -0,0 +1,149 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Scaffold a finding write-up from an episode's artifacts. + +Turns the recorded action log into numbered steps a person can follow on a +device, and gathers the evidence paths, so the write-up only needs the analysis +and the suggested fix filled in. + + python3 new_finding.py <episode-dir> [fingerprint] > my-finding.md +""" + +from __future__ import annotations + +import json +import sys +from pathlib import Path + +# How each recorded action reads as an instruction to a person. +HUMAN = { + "tap_label": 'Tap **{arg}**.', + "tap_xy": "Tap the screen at {arg}.", + "long_press_label": 'Long-press **{arg}**.', + "type": 'Type `{arg}` into the text field.', + "scroll_down": "Scroll down.", + "scroll_up": "Scroll up.", + "back": "Press the back button.", + "rotate": "Rotate the device ({arg} = landscape).", + "uri": "Send the wallet this URI (share it into the app, or scan it as a QR code):\n `{arg}`", + "view_uri": "Open this link so the system hands it to the wallet:\n `{arg}`", + "process_death": "Kill the app's process (`adb shell am kill net.taler.wallet.fdroid.debug`) and reopen it.", + "relaunch": "Close the app and reopen it.", + "home_screen": "Go back to the main screen.", +} + +SETUP_TEXT = { + "fresh": "a wallet with no data, developer mode on", + "funded": "a wallet with no data, developer mode on, then one completed " + "withdrawal of EUR:10 from the local bank", + "paid": "a wallet with one completed EUR:10 withdrawal and one completed " + "EUR:2 purchase", + "keep": "whatever state the previous scenario left behind", +} + + +def steps(actions: list[dict]) -> list[str]: + out = [] + for action in actions: + template = HUMAN.get(action["op"]) + if template is None: + out.append(f"Perform `{action['op']}` ({action.get('arg')!r}).") + else: + out.append(template.format(arg=action.get("arg"))) + return out + + +def main() -> int: + if len(sys.argv) < 2: + print(__doc__) + return 2 + episode = Path(sys.argv[1]) + wanted = sys.argv[2] if len(sys.argv) > 2 else None + summary = json.loads((episode / "summary.json").read_text()) + findings = summary.get("findings", []) + if wanted: + findings = [f for f in findings if f.get("fingerprint") == wanted] + if not findings: + print(f"no findings in {episode}", file=sys.stderr) + return 1 + finding = findings[0] + detail_files = sorted(episode.glob(f"*{finding['fingerprint']}*")) + actions = json.loads((episode / "actions.json").read_text()) \ + if (episode / "actions.json").is_file() else [] + scenario = summary.get("scenario") or summary.get("name", "") + setup = summary.get("setup", "keep") + + print(f"""<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# TITLE ME + +Found by the simulator in `{scenario}` ({finding['kind']}, fingerprint +`{finding['fingerprint']}`). + +**Severity: TODO.** + +## What happens + +``` +{finding['detail'][:1200]} +``` + +Screen at the time: {summary.get('findings', [{}])[0].get('screen', '')} + +## Reproduce by hand + +Starting point: {SETUP_TEXT.get(setup, setup)}. The local stack is the one +described in `simulator/README.md`; where a step mentions a URI, the bank or +the merchant produced it. +""") + for index, step in enumerate(steps(actions), start=1): + print(f"{index}. {step}") + print(f""" +Watch the app's log while doing this: + +```bash +adb logcat | grep -E 'taler-wallet|BackendManager|FATAL' +``` + +## Why TODO + +## Suggested fix TODO + +## Evidence + +Episode directory: `{episode}` (on tripwire). +""") + for path in detail_files: + print(f"* `{path.name}`") + print("* `actions.json` — the full recorded sequence, replayable with " + "`driver/replay.py`") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/payto-link-only-accepts-iban.diff b/wallet-simulator/findings/payto-link-only-accepts-iban.diff @@ -0,0 +1,44 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt b/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt +index 821bf471..0b19306a 100644 +--- a/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt ++++ b/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt +@@ -29,6 +29,7 @@ import kotlinx.serialization.json.jsonPrimitive + import net.taler.common.Amount + import net.taler.wallet.main.TAG + import net.taler.wallet.accounts.KnownBankAccountInfo ++import net.taler.wallet.accounts.PaytoUri + import net.taler.wallet.accounts.PaytoUriBitcoin + import net.taler.wallet.accounts.PaytoUriIban + import net.taler.wallet.accounts.PaytoUriTalerBank +@@ -39,7 +40,6 @@ import net.taler.wallet.backend.WalletResponse + import net.taler.wallet.balances.BalanceManager + import net.taler.wallet.balances.ScopeInfo + import org.json.JSONObject +-import androidx.core.net.toUri + + class DepositManager( + private val api: WalletBackendApi, +@@ -50,12 +50,17 @@ class DepositManager( + private val mDepositState = MutableStateFlow<DepositState>(DepositState.Start) + internal val depositState = mDepositState.asStateFlow() + +- fun isSupportedPayToUri(uriString: String): Boolean { +- if (!uriString.startsWith("payto://")) return false +- val u = uriString.toUri() +- if (!u.authority.equals("iban", ignoreCase = true)) return false +- return u.pathSegments.isNotEmpty() +- } ++ /** ++ * Whether a payto URI names an account this wallet can deposit to. ++ * ++ * Every target type the app models counts, not just IBAN: the ++ * add-account form offers x-taler-bank, IBAN and Bitcoin, the transfer ++ * screens render all four, and a deposit to an x-taler-bank account ++ * chosen from the account list succeeds -- so refusing the same account ++ * as a *link* told the user their link was invalid when it was not. ++ */ ++ fun isSupportedPayToUri(uriString: String): Boolean = ++ PaytoUri.parse(uriString) != null + + @UiThread + fun selectAccount(account: KnownBankAccountInfo) = scope.launch { diff --git a/wallet-simulator/findings/payto-link-only-accepts-iban.md b/wallet-simulator/findings/payto-link-only-accepts-iban.md @@ -0,0 +1,134 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# A payto link is "not a valid Taler link" unless it is an IBAN + +Found by a harness defect of its own: the `deposit` scenario had been passing +for thirteen rounds while depositing nothing, because it started the deposit +from a payto link the wallet refuses. + +**Severity: moderate.** The wallet deposits to `x-taler-bank` accounts +perfectly well when one is picked from its own account list — that is how every +deposit in this campaign's local stack works — but the same account as a +`payto://` link is rejected, and the message says the *link* is invalid rather +than that the account type is unsupported. + +## What happens + +The bank in the simulator's stack hands out + +``` +payto://x-taler-bank/localhost/wallet5?receiver-name=Wallet%205 +``` + +Sharing that into the wallet opens the "Send funds" screen with one line of red +text: + +``` +['Not a valid Taler link', 'Go back', 'Send', 'Internal event log'] +``` + +Picking the very same account from *Deposit → account list* works and the money +arrives: + +``` +deposit_flow: ['This transaction was completed successfully', + 'Chosen amount', '€0.44', 'Fee', '-€0.06', 'Amount sent', '-€0.50'] +``` + +## Why + +`PayToUriScreen` asks one question before it will show the amount form, and the +answer for anything but an IBAN is no: + +```kotlin +// wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt:53 +fun isSupportedPayToUri(uriString: String): Boolean { + if (!uriString.startsWith("payto://")) return false + val u = uriString.toUri() + if (!u.authority.equals("iban", ignoreCase = true)) return false + return u.pathSegments.isNotEmpty() +} +``` + +```kotlin +// wallet/src/main/java/net/taler/wallet/deposit/PayToUriScreen.kt:81 +} else if (model.depositManager.isSupportedPayToUri(uri)) { + PayToComposable(…) +} else { + Text(text = stringResource(id = R.string.uri_invalid), …) +} +``` + +Everything else in the app disagrees with that restriction: + +* the add-account form offers **x-taler-bank**, **IBAN** and **Bitcoin** tabs, + and `AddAccountComposable` builds a payto for each; +* `Accounts.kt` models `PaytoUriIban`, `PaytoUriTaler`, `PaytoUriBitcoin` and + `PaytoUriCyclos`, and the transfer screens render all four; +* wallet-core's own payto parser accepts `iban`, `x-taler-bank`, `bitcoin`, + `upi` and more (`packages/taler-util/src/payto.ts`); +* and the deposit itself succeeds for an x-taler-bank account chosen from the + list, so nothing downstream needs the restriction. + +So the check is narrower than the feature behind it, and `uri_invalid` — +"Not a valid Taler link" — is the wrong thing to say about a well-formed payto +URI for an account the wallet can use. + +## Reproduce by hand + +1. Install a debug build, enable **Developer mode**, and withdraw once from the + local bank so the wallet has coins and knows the account. +2. Share a payto URI for a non-IBAN account into the wallet: + + ```bash + adb shell am start -a android.intent.action.VIEW \ + -d 'payto://x-taler-bank/localhost/wallet1?receiver-name=Wallet%201' + ``` + +3. The screen shows "Not a valid Taler link". +4. For the contrast: **Deposit** on the home screen, pick the `wallet1` + account, enter an amount, **Make deposit** — the same account, and it works. + +An IBAN link, for comparison, opens the amount form: + +```bash +adb shell am start -a android.intent.action.VIEW \ + -d 'payto://iban/DE89370400440532013000?receiver-name=Wallet%20One' +``` + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=0 python3 -u suite.py deposit_payto_link deposit +``` + +`deposit_payto_link` records the refusal and says so if it ever stops +happening; `deposit` now drives the account list instead and **fails** if the +bank balance does not move, which is what should have been checked all along. + +## Suggested fix + +Accept the target types the wallet already models. `isSupportedPayToUri` can +delegate to the same parsing the account forms use — `PaytoUri.parse`, which +returns `PaytoUriIban`/`PaytoUriTaler`/`PaytoUriBitcoin`/`PaytoUriCyclos` — +and treat "parsed to something we can deposit to" as supported. + +For whatever genuinely stays unsupported, say that instead of `uri_invalid`: +"this wallet cannot deposit to a <type> account" tells the user something, +where "not a valid Taler link" is both unhelpful and untrue. diff --git a/wallet-simulator/findings/pos-confirmation-shows-five-codes.md b/wallet-simulator/findings/pos-confirmation-shows-five-codes.md @@ -0,0 +1,107 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# "Confirmation code" shows five codes with no hint which one to read out + +Found by the new `payment_pos_confirmation` scenario, the first thing in this +campaign to reach `PayTotpComposable` at all. + +**Severity: low.** It only shows up at merchants that use a point-of-sale +confirmation device, and only for the human-readable half of that feature; the +NFC half is correct. + +## What happens + +Paying an order that names an OTP device, the completed purchase reads: + +``` +This transaction was completed successfully +Total €1.00 +Paid -€1.00 +Confirmation code +10179494 +80755471 +56332107 +94603659 +92288808 +``` + +Five eight-digit numbers under a singular label, in a monospace block, with +nothing to say what to do with them. + +That is not a bug in the merchant: `TALER_build_pos_confirmation` deliberately +returns *every* T-OTP code in the valid time range, newline-separated, so that +a device whose clock is off by a step or two still matches +(`exchange/src/util/crypto_confirmation.c:254`, "Return all T-OTP codes in +range separated by new lines"). `formatTotpPayload` in the wallet splits them +and writes all of them into the NDEF record, which is exactly right for a +device reading over NFC. + +The display path then prints the same string verbatim: + +```kotlin +// wallet/src/main/java/net/taler/wallet/payment/PayTotpComposable.kt:123 +Text( + text = totpString, + fontFamily = FontFamily.Monospace, + ... +) +``` + +So where NFC is not available — which is the case `enableNfc == false` exists +for — a cashier is shown five candidate codes and has to guess. The middle one +is the current time step, but nothing says so. + +## Reproduce by hand + +Needs a merchant backend you can configure; against the simulator's stack: + +1. Create an OTP device: + ```bash + curl -X POST http://localhost:8080/instances/sim/private/otp-devices \ + -H 'Content-Type: application/json' \ + -d '{"otp_device_id":"simpos","otp_device_description":"Till", + "otp_algorithm":"TOTP_WITHOUT_PRICE", + "otp_key":"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567","otp_ctr":0}' + ``` + (`otp_key` is RFC 3548 base32, not Crockford.) +2. Create an order naming it — `otp_id` is a sibling of `order`, not a field + of it: + ```bash + curl -X POST http://localhost:8080/instances/sim/private/orders \ + -H 'Content-Type: application/json' \ + -d '{"order":{"amount":"EUR:1","summary":"Till order", + "fulfillment_url":"https://example.com/f/1"},"otp_id":"simpos"}' + ``` +3. Hand the resulting `taler_pay_uri` to the wallet and pay it. +4. The completed purchase shows the block above. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_pos_confirmation_codes.py # worker 0 by default +SIM_WORKER=4 python3 suite.py payment_pos_confirmation # or the scenario +``` + +## Suggested fix + +Show the code for the current time step and keep the rest for the NFC payload: +`totpString.split("\n")` is already computed in `formatTotpPayload`, so the +display can take the middle entry (the list is centred on now) and show the +others only in developer mode. If showing all of them is deliberate, the label +should be plural and say why there are several. diff --git a/wallet-simulator/findings/purge-destroys-coins-and-history-without-saying-so.md b/wallet-simulator/findings/purge-destroys-coins-and-history-without-saying-so.md @@ -0,0 +1,115 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# "Force deletion (purge)" destroys the coins and the history, and says neither + +Found by the `history_after_forgetting_exchange` scenario, written to ask +whether the transaction history survives removing the payment service it +belongs to. It does not, and nothing warns about it. + +**Severity: moderate.** Irreversible, reachable in a release build from +Settings → Payment services, and it destroys money: the wallet went from +€9.87 and a transaction history to the first-run welcome screen. + +## What happens + +A wallet with €9.87 withdrawn from one payment service, Settings → Payment +services → the service's menu → **Delete payment service**. The dialog is: + +``` +Delete payment service +[ ] Force deletion (purge) + Delete Cancel +``` + +That is the whole dialog — a title, a checkbox, two buttons. There is no body +text, no mention of the balance held at that service, and no statement of what +"purge" additionally destroys. + +Ticking the box and pressing **Delete**: + +``` +transactions before: ['Withdraw'] +after forgetting: the payment services list, with the service gone +home afterwards: ['Wallet', 'Welcome to Taler Wallet!', + 'To make your first payment, withdraw digital cash.', …] +transactions after: [] +``` + +The €9.87 is gone, the withdrawal that produced it is gone, and the wallet +looks like a fresh install. + +Without the checkbox the app does protect the user — a plain delete of a +service that still holds coins is refused, which is what the +`exchange_delete_with_coins` scenario covers. The checkbox is the override, +and it is the override that carries no warning. + +## Why + +The dialog has no text beyond the checkbox label: + +```kotlin +// wallet/src/main/java/net/taler/wallet/exchanges/ExchangeListScreen.kt:297 +AlertDialog( + onDismissRequest = onDismiss, + title = { Text(stringResource(R.string.exchange_delete)) }, + text = { + Row(verticalAlignment = Alignment.CenterVertically) { + Checkbox(checked = purge, onCheckedChange = { purge = it }) + Text(stringResource(R.string.exchange_delete_force)) + } + }, + confirmButton = { TextButton(onClick = { onConfirm(purge) }) { … } }, + … +) +``` + +`R.string.exchange_delete_force` is the five words "Force deletion (purge)". +There is no string in the file that explains the consequence, so there is +nothing to show even if the dialog wanted to. + +For contrast, the wallet's own reset dialog *does* explain itself, and +forgetting a bank account asks "Do you really wish to forget…". + +## Reproduce by hand + +1. Withdraw some money, so the wallet has a balance and a transaction. +2. Settings → **Payment services** → the service's **Menu** → **Delete + payment service**. +3. Tick **Force deletion (purge)** and press **Delete**. +4. The service disappears. Go back to the main screen: it is the first-run + welcome screen, the balance is gone, and the transaction list is empty. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=4 python3 suite.py history_after_forgetting_exchange +``` + +The notes record the transactions before, the dialog, and the empty list +afterwards. + +## Suggested fix + +Give the dialog a body that says what will happen, and name the amount at +risk: the balance for that scope is already in `BalanceManager`, so "This +payment service holds €9.87. Deleting it will destroy that balance and the +record of every transaction made with it." is available to write. Requiring +the checkbox *and* a typed confirmation would not be excessive for an action +that cannot be undone; at the very least the consequence should be stated +before the money is gone. diff --git a/wallet-simulator/findings/qr-camera-ignores-the-plane-strides.diff b/wallet-simulator/findings/qr-camera-ignores-the-plane-strides.diff @@ -0,0 +1,538 @@ +diff --git a/taler-kotlin-android/src/main/java/net/taler/lib/android/qr/QrCameraAnalyzer.kt b/taler-kotlin-android/src/main/java/net/taler/lib/android/qr/QrCameraAnalyzer.kt +index de9d94ca..5fb26e3f 100644 +--- a/taler-kotlin-android/src/main/java/net/taler/lib/android/qr/QrCameraAnalyzer.kt ++++ b/taler-kotlin-android/src/main/java/net/taler/lib/android/qr/QrCameraAnalyzer.kt +@@ -19,6 +19,7 @@ package net.taler.lib.android.qr + import android.content.Context + import android.graphics.Bitmap + import android.media.Image ++import android.util.Log + import androidx.camera.core.Camera + import androidx.camera.core.CameraSelector + import androidx.camera.core.ExperimentalGetImage +@@ -38,7 +39,62 @@ import com.google.zxing.RGBLuminanceSource + import com.google.zxing.BarcodeFormat + import com.google.zxing.common.HybridBinarizer + import com.google.zxing.PlanarYUVLuminanceSource ++import java.nio.ByteBuffer ++import java.util.concurrent.ExecutorService + import java.util.concurrent.Executor ++import java.util.concurrent.Executors ++ ++/** ++ * The luminance plane of a YUV_420_888 frame, with its padding removed. ++ * ++ * A camera plane is not a tightly packed image: `rowStride` may exceed the ++ * width (the hardware pads each row) and `pixelStride` may exceed one (the ++ * samples are interleaved). Copying the buffer in one `get()` is only correct ++ * when neither is true, and when a row is padded every row after the first ++ * lands shifted, so the image skews and nothing decodes. Whether a given ++ * camera pads depends on the device *and* the platform version, which is how ++ * scanning can work on one Android release and fail on another. ++ * ++ * zxing's [PlanarYUVLuminanceSource] reads only this plane, so the chroma ++ * layout does not matter -- this is the whole of what the decoder needs. ++ */ ++internal fun extractLuma( ++ buffer: ByteBuffer, ++ rowStride: Int, ++ pixelStride: Int, ++ width: Int, ++ height: Int, ++): ByteArray { ++ val luma = ByteArray(width * height) ++ if (rowStride == width && pixelStride == 1) { ++ // The common case: already tightly packed. ++ buffer.position(0) ++ buffer.get(luma, 0, minOf(luma.size, buffer.remaining())) ++ return luma ++ } ++ val row = ByteArray(rowStride) ++ var out = 0 ++ for (y in 0 until height) { ++ val start = y * rowStride ++ if (start >= buffer.limit()) break ++ buffer.position(start) ++ // The last row is often short: the plane need not include its padding. ++ val len = minOf(rowStride, buffer.remaining()) ++ buffer.get(row, 0, len) ++ if (pixelStride == 1) { ++ System.arraycopy(row, 0, luma, out, minOf(width, len)) ++ } else { ++ var x = 0 ++ while (x < width && x * pixelStride < len) { ++ luma[out + x] = row[x * pixelStride] ++ x++ ++ } ++ } ++ out += width ++ } ++ return luma ++} ++ + + @androidx.annotation.OptIn(ExperimentalGetImage::class) + class QrCameraAnalyzer( +@@ -49,6 +105,14 @@ class QrCameraAnalyzer( + private val onCameraReady: ((initialLinearZoom: Float) -> Unit)? = null, + ) { + private val mainExecutor: Executor = ContextCompat.getMainExecutor(context) ++ ++ /** ++ * Frames are analysed here, not on the main thread: a frame costs a ++ * copy of the luminance plane plus a zxing decode, which is work the UI ++ * thread should not be doing thirty times a second. One thread, so the ++ * reader below needs no locking. ++ */ ++ private val analysisExecutor: ExecutorService = Executors.newSingleThreadExecutor() + private var camera: Camera? = null + + private val qrReader = MultiFormatReader().apply { +@@ -72,34 +136,21 @@ class QrCameraAnalyzer( + val analysis = ImageAnalysis.Builder() + .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) + .build().also { useCase -> +- useCase.setAnalyzer(mainExecutor) { proxy -> +- val mediaImage = proxy.image +- if (mediaImage != null) { +- val nv21 = yuv420888ToNv21(mediaImage) +- val width = mediaImage.width +- val height = mediaImage.height +- val rotation = proxy.imageInfo.rotationDegrees +- +- val (rotatedNv21, rotatedWidth, rotatedHeight) = when (rotation) { +- 90 -> rotateNV21(nv21, width, height, 90) +- 180 -> rotateNV21(nv21, width, height, 180) +- 270 -> rotateNV21(nv21, width, height, 270) +- else -> Triple(nv21, width, height) ++ useCase.setAnalyzer(analysisExecutor) { proxy -> ++ // Whatever happens to this frame, the proxy has to be ++ // closed: with STRATEGY_KEEP_ONLY_LATEST an unclosed ++ // one stops frame delivery for good, so a single ++ // unexpected frame would end scanning for the rest of ++ // the session while the viewfinder kept running. ++ try { ++ proxy.image?.let { image -> ++ decodeQr(image)?.let { text -> ++ mainExecutor.execute { onQrDetected(text) } ++ } + } +- +- val source = PlanarYUVLuminanceSource( +- rotatedNv21, rotatedWidth, rotatedHeight, 0, 0, rotatedWidth, rotatedHeight, false, +- ) +- +- val bitmap = BinaryBitmap(HybridBinarizer(source)) +- try { +- val result = qrReader.decodeWithState(bitmap) +- onQrDetected(result.text) +- } catch (_: NotFoundException) { +- } finally { +- proxy.close() +- } +- } else { ++ } catch (e: Exception) { ++ Log.w(TAG, "could not analyse a camera frame", e) ++ } finally { + proxy.close() + } + } +@@ -124,6 +175,7 @@ class QrCameraAnalyzer( + camera = null + } catch (_: Exception) { + } ++ analysisExecutor.shutdown() + } + + fun enableTorch(enabled: Boolean) { +@@ -147,84 +199,37 @@ class QrCameraAnalyzer( + cam.cameraControl.startFocusAndMetering(action) + } + +- private fun yuv420888ToNv21(image: Image): ByteArray { +- val yPlane = image.planes[0].buffer +- val uPlane = image.planes[1].buffer +- val vPlane = image.planes[2].buffer +- val ySize = yPlane.remaining() +- val uSize = uPlane.remaining() +- val vSize = vPlane.remaining() +- val nv21 = ByteArray(ySize + uSize + vSize) +- yPlane.get(nv21, 0, ySize) +- vPlane.get(nv21, ySize, vSize) +- uPlane.get(nv21, ySize + vSize, uSize) +- return nv21 +- } +- +- private fun rotateNV21(data: ByteArray, width: Int, height: Int, rotation: Int): Triple<ByteArray, Int, Int> { +- if (rotation == 0) return Triple(data, width, height) +- +- val ySize = width * height +- val uvSize = ySize / 2 +- val rotated = ByteArray(ySize + uvSize) +- +- when (rotation) { +- 90 -> { +- var i = 0 +- for (x in 0 until width) { +- for (y in height - 1 downTo 0) { +- rotated[i++] = data[y * width + x] +- } +- } +- var uvIndex = ySize +- for (x in 0 until width step 2) { +- for (y in height - 1 downTo 0 step 2) { +- val uvPos = ySize + (y * width + x) +- if (uvPos + 1 < data.size) { +- rotated[uvIndex++] = data[uvPos] +- rotated[uvIndex++] = data[uvPos + 1] +- } +- } +- } +- return Triple(rotated, height, width) +- } +- 180 -> { +- var i = ySize - 1 +- for (j in 0 until ySize) { +- rotated[j] = data[i--] +- } +- i = data.size - 1 +- for (j in ySize until data.size step 2) { +- rotated[j] = data[i - 1] +- rotated[j + 1] = data[i] +- i -= 2 +- } +- return Triple(rotated, width, height) +- } +- 270 -> { +- var i = 0 +- for (x in width - 1 downTo 0) { +- for (y in 0 until height) { +- rotated[i++] = data[y * width + x] +- } +- } +- var uvIndex = ySize +- for (x in width - 1 downTo 0 step 2) { +- for (y in 0 until height step 2) { +- val uvPos = ySize + (y * width + x - 1) +- if (uvPos + 1 < data.size) { +- rotated[uvIndex++] = data[uvPos] +- rotated[uvIndex++] = data[uvPos + 1] +- } +- } +- } +- return Triple(rotated, height, width) +- } ++ /** ++ * The `taler://` URI in [image], or null if there is no QR code in it. ++ * ++ * The frame is not rotated first. zxing locates a QR code by its three ++ * finder patterns and derives the orientation from them, so it reads a ++ * code the same whichever way up the phone is held -- rotating the plane ++ * by hand only cost a second pass over every pixel. ++ */ ++ private fun decodeQr(image: Image): String? { ++ val plane = image.planes[0] ++ val luma = extractLuma( ++ plane.buffer, ++ plane.rowStride, ++ plane.pixelStride, ++ image.width, ++ image.height, ++ ) ++ val source = PlanarYUVLuminanceSource( ++ luma, image.width, image.height, 0, 0, image.width, image.height, false, ++ ) ++ return try { ++ qrReader.decodeWithState(BinaryBitmap(HybridBinarizer(source))).text ++ } catch (_: NotFoundException) { ++ // Most frames hold no code at all; this is the ordinary case. ++ null + } +- return Triple(data, width, height) + } + + companion object { ++ private const val TAG = "QrCameraAnalyzer" ++ + fun decodeQrFromBitmap(bitmap: Bitmap): String? { + val width = bitmap.width + val height = bitmap.height +diff --git a/taler-kotlin-android/src/test/java/net/taler/lib/android/qr/ExtractLumaTest.kt b/taler-kotlin-android/src/test/java/net/taler/lib/android/qr/ExtractLumaTest.kt +new file mode 100644 +index 00000000..63f84f7f +--- /dev/null ++++ b/taler-kotlin-android/src/test/java/net/taler/lib/android/qr/ExtractLumaTest.kt +@@ -0,0 +1,104 @@ ++/* ++ * This file is part of GNU Taler ++ * (C) 2026 Taler Systems S.A. ++ * ++ * GNU Taler is free software; you can redistribute it and/or modify it under the ++ * terms of the GNU General Public License as published by the Free Software ++ * Foundation; either version 3, or (at your option) any later version. ++ * ++ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY ++ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR ++ * A PARTICULAR PURPOSE. See the GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License along with ++ * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> ++ */ ++ ++package net.taler.lib.android.qr ++ ++import org.junit.Assert.assertArrayEquals ++import org.junit.Test ++import java.nio.ByteBuffer ++ ++/** ++ * A camera's luminance plane is not a tightly packed image, and the QR decoder ++ * only works if the padding is taken out. How a plane is laid out depends on ++ * the device and the platform version, which is why this is worth pinning: ++ * reading it wrong shows up as "scanning works on one Android release and not ++ * on another" rather than as an obvious failure. ++ */ ++class ExtractLumaTest { ++ ++ /** Row y, column x of a test image, as a recognisable byte. */ ++ private fun pixel(x: Int, y: Int) = (y * 16 + x).toByte() ++ ++ private fun expected(width: Int, height: Int) = ByteArray(width * height) { ++ pixel(it % width, it / width) ++ } ++ ++ @Test ++ fun tightlyPackedPlaneIsCopiedAsIs() { ++ val width = 4 ++ val height = 3 ++ val buffer = ByteBuffer.wrap(expected(width, height)) ++ assertArrayEquals( ++ expected(width, height), ++ extractLuma(buffer, rowStride = width, pixelStride = 1, width, height), ++ ) ++ } ++ ++ @Test ++ fun paddedRowsDoNotShiftTheImage() { ++ val width = 4 ++ val height = 3 ++ val rowStride = 7 // the hardware pads each row by three bytes ++ val padded = ByteArray(rowStride * height) { 0x7F } ++ for (y in 0 until height) { ++ for (x in 0 until width) padded[y * rowStride + x] = pixel(x, y) ++ } ++ assertArrayEquals( ++ expected(width, height), ++ extractLuma(ByteBuffer.wrap(padded), rowStride, pixelStride = 1, width, height), ++ ) ++ } ++ ++ @Test ++ fun interleavedSamplesAreTakenEveryPixelStride() { ++ val width = 4 ++ val height = 2 ++ val pixelStride = 2 ++ val rowStride = width * pixelStride ++ val interleaved = ByteArray(rowStride * height) { 0x7F } ++ for (y in 0 until height) { ++ for (x in 0 until width) { ++ interleaved[y * rowStride + x * pixelStride] = pixel(x, y) ++ } ++ } ++ assertArrayEquals( ++ expected(width, height), ++ extractLuma(ByteBuffer.wrap(interleaved), rowStride, pixelStride, width, height), ++ ) ++ } ++ ++ @Test ++ fun aPlaneWithoutTrailingPaddingIsStillRead() { ++ // Some cameras stop the plane after the last row's pixels, so the ++ // buffer is rowStride * (height - 1) + width bytes, not rowStride * ++ // height. Reading past that must not throw. ++ val width = 4 ++ val height = 3 ++ val rowStride = 6 ++ val size = rowStride * (height - 1) + width ++ val plane = ByteArray(size) { 0x7F } ++ for (y in 0 until height) { ++ for (x in 0 until width) { ++ val at = y * rowStride + x ++ if (at < size) plane[at] = pixel(x, y) ++ } ++ } ++ assertArrayEquals( ++ expected(width, height), ++ extractLuma(ByteBuffer.wrap(plane), rowStride, pixelStride = 1, width, height), ++ ) ++ } ++} +diff --git a/taler-kotlin-android/src/test/java/net/taler/lib/android/qr/QrFrameDecodeTest.kt b/taler-kotlin-android/src/test/java/net/taler/lib/android/qr/QrFrameDecodeTest.kt +new file mode 100644 +index 00000000..9bdc6ba8 +--- /dev/null ++++ b/taler-kotlin-android/src/test/java/net/taler/lib/android/qr/QrFrameDecodeTest.kt +@@ -0,0 +1,163 @@ ++/* ++ * This file is part of GNU Taler ++ * (C) 2026 Taler Systems S.A. ++ * ++ * GNU Taler is free software; you can redistribute it and/or modify it under the ++ * terms of the GNU General Public License as published by the Free Software ++ * Foundation; either version 3, or (at your option) any later version. ++ * ++ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY ++ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR ++ * A PARTICULAR PURPOSE. See the GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License along with ++ * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> ++ */ ++ ++package net.taler.lib.android.qr ++ ++import com.google.zxing.BarcodeFormat ++import com.google.zxing.BinaryBitmap ++import com.google.zxing.DecodeHintType ++import com.google.zxing.EncodeHintType ++import com.google.zxing.MultiFormatReader ++import com.google.zxing.NotFoundException ++import com.google.zxing.PlanarYUVLuminanceSource ++import com.google.zxing.common.HybridBinarizer ++import com.google.zxing.qrcode.QRCodeWriter ++import org.junit.Assert.assertEquals ++import org.junit.Assert.assertNull ++import org.junit.Test ++import java.nio.ByteBuffer ++ ++/** ++ * The camera half of QR scanning, end to end, without a camera. ++ * ++ * A camera frame is only a luminance plane plus the two numbers that say how ++ * it is laid out, so a frame can be built here and put through the same ++ * decoder the analyzer uses. That covers the part of scanning that no ++ * emulator can test -- the virtual camera cannot be pointed at a code -- and ++ * it covers it on every device layout at once rather than on whichever one the ++ * test phone happens to use. ++ */ ++class QrFrameDecodeTest { ++ ++ private val payload = "taler://pay/backend.demo.taler.net/2026.123-02B5CYNPRHXRC/" ++ ++ private val width = 640 ++ private val height = 480 ++ private val codeSize = 400 ++ ++ /** ++ * The luminance plane of a frame with the code centred on white, laid out ++ * with [rowStride] bytes per row and [pixelStride] bytes per sample. ++ * [rowStride] counts bytes, so an interleaved plane needs at least ++ * `width * pixelStride` of them. ++ */ ++ private fun frame(rowStride: Int = width, pixelStride: Int = 1): ByteArray { ++ val matrix = QRCodeWriter().encode( ++ payload, BarcodeFormat.QR_CODE, codeSize, codeSize, ++ mapOf(EncodeHintType.MARGIN to 1), ++ ) ++ val plane = ByteArray(rowStride * height) { -1 } // white ++ val left = (width - codeSize) / 2 ++ val top = (height - codeSize) / 2 ++ for (y in 0 until codeSize) { ++ for (x in 0 until codeSize) { ++ if (matrix.get(x, y)) { ++ val at = (y + top) * rowStride + (x + left) * pixelStride ++ plane[at] = 0 // ink ++ } ++ } ++ } ++ return plane ++ } ++ ++ /** The analyzer's decoder: zxing over a luminance plane. */ ++ private fun decode(luma: ByteArray, width: Int, height: Int): String? { ++ val reader = MultiFormatReader().apply { ++ setHints( ++ mapOf( ++ DecodeHintType.POSSIBLE_FORMATS to listOf(BarcodeFormat.QR_CODE), ++ DecodeHintType.CHARACTER_SET to "UTF-8", ++ ), ++ ) ++ } ++ val source = PlanarYUVLuminanceSource( ++ luma, width, height, 0, 0, width, height, false, ++ ) ++ return try { ++ reader.decodeWithState(BinaryBitmap(HybridBinarizer(source))).text ++ } catch (_: NotFoundException) { ++ null ++ } ++ } ++ ++ private fun lumaOf(rowStride: Int, pixelStride: Int = 1) = extractLuma( ++ ByteBuffer.wrap(frame(rowStride, pixelStride)), ++ rowStride, pixelStride, width, height, ++ ) ++ ++ @Test ++ fun aTightlyPackedFrameDecodes() { ++ assertEquals(payload, decode(lumaOf(width), width, height)) ++ } ++ ++ @Test ++ fun aFrameWithPaddedRowsDecodes() { ++ // Whether the camera pads, and by how much, is the camera's choice. ++ for (padding in listOf(16, 32, 64, 128)) { ++ val rowStride = width + padding ++ assertEquals( ++ "padding of $padding bytes", ++ payload, ++ decode(lumaOf(rowStride), width, height), ++ ) ++ } ++ } ++ ++ @Test ++ fun aFrameWithInterleavedSamplesDecodes() { ++ assertEquals(payload, decode(lumaOf(width * 2, pixelStride = 2), width, height)) ++ } ++ ++ @Test ++ fun copyingAPaddedPlaneWholesaleDoesNotDecode() { ++ // What the analyzer used to do, kept as the reason the code above ++ // exists: one bulk copy of a padded plane shifts every row after the ++ // first, and the decoder then never finds anything at all. ++ val rowStride = width + 32 ++ assertNull(decode(frame(rowStride), width, height)) ++ } ++ ++ @Test ++ fun theCodeIsReadWhicheverWayUpThePhoneIsHeld() { ++ // zxing finds a QR code by its finder patterns and takes the ++ // orientation from them, so the analyzer does not have to rotate the ++ // frame to the upright position first. ++ val upright = lumaOf(width) ++ for (degrees in listOf(0, 90, 180, 270)) { ++ val turned = rotate(upright, width, height, degrees) ++ val w = if (degrees == 90 || degrees == 270) height else width ++ val h = if (degrees == 90 || degrees == 270) width else height ++ assertEquals("rotated by $degrees", payload, decode(turned, w, h)) ++ } ++ } ++ ++ /** Clockwise rotation of a tightly packed plane, as the sensor would give it. */ ++ private fun rotate(plane: ByteArray, width: Int, height: Int, degrees: Int): ByteArray { ++ val out = ByteArray(width * height) ++ for (y in 0 until height) { ++ for (x in 0 until width) { ++ val v = plane[y * width + x] ++ when (degrees) { ++ 90 -> out[x * height + (height - 1 - y)] = v ++ 180 -> out[(height - 1 - y) * width + (width - 1 - x)] = v ++ 270 -> out[(width - 1 - x) * height + y] = v ++ else -> out[y * width + x] = v ++ } ++ } ++ } ++ return out ++ } ++} diff --git a/wallet-simulator/findings/qr-camera-ignores-the-plane-strides.md b/wallet-simulator/findings/qr-camera-ignores-the-plane-strides.md @@ -0,0 +1,297 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Scanning a QR code reads the camera frame wrong, and one bad frame ends scanning + +Investigated after a report that scanning works on Android 15 but not on +Android 14. The camera cannot be driven from an emulator — the virtual scene's +camera pose cannot be aimed at a code — so the pipeline was taken apart +instead: a camera frame is a luminance plane plus two numbers saying how it is +laid out, which can be built on a workstation and put through the app's own +arithmetic. Everything below is reproducible with a JDK and the zxing jar the +app already depends on; no device, no emulator, no camera. + +**Severity: high.** Two independent defects, each of which stops scanning +outright rather than degrading it. Neither produces an error message: the +viewfinder keeps running, the user waves the phone at a valid code, and the +wallet never reacts. + +## Defect 1 — the frame's layout is ignored, so nothing decodes + +`QrCameraAnalyzer` converts each frame by hand and never looks at how it is +laid out: + +```kotlin +// taler-kotlin-android/src/main/java/net/taler/lib/android/qr/QrCameraAnalyzer.kt:150 +private fun yuv420888ToNv21(image: Image): ByteArray { + val yPlane = image.planes[0].buffer + … + val ySize = yPlane.remaining() + yPlane.get(nv21, 0, ySize) // one bulk copy + … +} +``` + +```console +$ grep -c 'rowStride\|pixelStride' QrCameraAnalyzer.kt +0 +``` + +A `YUV_420_888` plane is not a tightly packed image. `rowStride` is the +distance between the starts of two rows and the hardware is free to pad, so +`rowStride >= width`; `pixelStride` is the distance between two samples. +(`ImageFormat.YUV_420_888` documents the Y plane's pixel stride as always one, +so row padding is the part that varies in practice — the patch handles both +because handling both costs nothing.) A single `get()` is correct only when the +plane happens to be tight. With padded rows every row after the first lands +shifted by the padding, the image shears a little further on each line, the +finder patterns stop being squares, and zxing returns `NotFoundException` for +every frame — which the analyzer swallows, so a systematically broken decoder +looks exactly like an empty viewfinder. + +Run against the current code, `repro_qr_plane_strides.java`: + +``` +== 1. control: tightly packed plane, rotation 0 +app pipeline, rowStride == width decoded + +== 2. the same frame with padded rows (rowStride > width) +app pipeline, rowStride = 656 (pad 16) FAIL: NotFoundException + patched extractLuma, same frame decoded + zxing dataWidth = rowStride, no copy at all decoded +app pipeline, rowStride = 672 (pad 32) FAIL: NotFoundException + … (same for 64, 128) + +== 3. interleaved luma (pixelStride 2) +app pipeline FAIL: NotFoundException + patched extractLuma decoded +``` + +Not "degraded": no padding value decodes a single frame, and the same frame +decodes the moment the stride is honoured. The code is in the frame, unchanged; +only the arithmetic differs. + +## Defect 2 — a frame that throws stops the camera for good + +`proxy.close()` sits in the `finally` of the *decode* `try`, which is entered +after the conversion and rotation have already run: + +```kotlin +val nv21 = yuv420888ToNv21(mediaImage) // throws here … +val (rotatedNv21, …) = rotateNV21(nv21, …) // … or here +… +try { + onQrDetected(qrReader.decodeWithState(bitmap).text) +} catch (_: NotFoundException) { +} finally { + proxy.close() // … and this never runs +} +``` + +The analysis use case is built with `STRATEGY_KEEP_ONLY_LATEST`, under which +CameraX holds one frame and acquires the next only once the current proxy is +closed. So an exception anywhere above that `try` does not cost one frame: it +ends frame delivery for the rest of the screen's life, while the preview — a +separate use case — carries on looking perfectly healthy. + +That is not hypothetical, because the two defects meet. `rotateNV21` sizes its +output from `width * height` while the array it was handed was sized from the +*padded* `remaining()`, and its 180° branch copies the chroma tail out to +`data.size`: + +``` +== 4. the app's rotation on a padded plane +rotation 90 degrees, rowStride = 672 FAIL: NotFoundException +rotation 180 degrees, rowStride = 672 THREW ArrayIndexOutOfBoundsException: Index 460800 out of bounds for length 460800 +rotation 270 degrees, rowStride = 672 FAIL: NotFoundException +``` + +`rotationDegrees == 180` is reached when the device is held in the orientation +opposite to the sensor's, and nothing in the wallet constrains that: + +```console +$ grep -rn screenOrientation wallet/src/main/AndroidManifest.xml +$ # no output -- the scan screen rotates freely +``` + +So on a device whose camera pads its rows, turning the phone around during a +scan kills scanning until the screen is left and re-entered — with no error, +no log line, and a live preview. + +## Defect 3 — the analysis runs on the UI thread + +```kotlin +useCase.setAnalyzer(mainExecutor) { proxy -> … } +``` + +Every frame costs a copy of the luminance plane plus a zxing decode, and both +happen on the main thread, at frame rate. It is not why scanning fails, but it +is why the scan screen janks, and it makes a slow decode cost dropped frames. + +## What is *not* wrong + +Worth recording, because each of these is a plausible place to go looking: + +* **The rotation arithmetic is correct.** On a tightly packed plane all three + branches produce a decodable image (section 6 of the reproducer). The 270° + branch's odd-looking indexing is in the chroma half, which nothing reads. +* **The rotation is not needed at all.** zxing locates a QR code by its three + finder patterns and derives the orientation from them: + + ``` + == 5. is the rotation needed at all? (tight plane, kept as it arrives) + frame arrives rotated 0, decoded as-is decoded + frame arrives rotated 90, decoded as-is decoded + frame arrives rotated 180, decoded as-is decoded + frame arrives rotated 270, decoded as-is decoded + ``` + + So `rotateNV21` buys nothing, and it is where the crash lives. Deleting it is + the fix, not repairing it. +* **Asking zxing to rotate instead would be worse.** The obvious replacement, + `PlanarYUVLuminanceSource.rotateCounterClockwise()`, is not implemented: + zxing 3.5.3 *and* 3.5.4 inherit the base class, where + `isRotateSupported()` returns false and the method throws + `UnsupportedOperationException`. The merchant terminal's copy of this + pipeline does exactly that — see + `pos-config-scanner-asks-for-a-rotation-zxing-refuses.md`. +* **The decoder and the hints are fine**, and so is the gallery path. Importing + a photo of a code decodes 10 of 10 on API 34 and on API 36, with identical + screens; that route goes through `decodeQrFromBitmap`, which builds an + `RGBLuminanceSource` from `Bitmap.getPixels` and so never touches any of the + arithmetic above. A working gallery import is therefore not evidence that the + camera path works — it is the control that isolates it. + +## Why this can differ between Android versions + +The layout is the camera's choice, not the app's: it comes from the HAL, +together with the resolution CameraX selects from the device's advertised +stream configurations. Both can change when a device is upgraded — the same +hardware with a new vendor camera stack may pad where it did not before, or +offer a different analysis resolution — and both differ between devices. +"Works on 15, not on 14" is precisely the shape of a stride assumption, which +is why the report points here. It is *not* proof: the two numbers that decide +it can be printed in one log line, which is the first manual test below. + +## Reproduce + +Without a device, against an unpatched checkout: + +```bash +ZX=$(find ~/.gradle ~/.m2 -name 'core-3.5.*.jar' | head -1) +javac -cp "$ZX" -d /tmp/qrrepro simulator/findings/repro_qr_plane_strides.java +java -cp "$ZX:/tmp/qrrepro" repro_qr_plane_strides +``` + +With the patch applied, the same ground is covered by unit tests that stay in +the tree: + +```bash +./gradlew :taler-kotlin-android:testDebugUnitTest \ + --tests 'net.taler.lib.android.qr.*' +``` + +`ExtractLumaTest` (4 cases) pins the layout arithmetic; +`QrFrameDecodeTest` (5 cases) encodes a real QR code, lays it out tight, +padded by 16/32/64/128 bytes and interleaved, and asserts it decodes — plus +one case asserting that the *old* bulk copy does not decode, and one that the +code reads at all four orientations. All nine pass with the patch; the four +`ExtractLumaTest` cases were written first and three of them failed against the +original arithmetic. + +By hand on an affected device: open **Scan QR code**, point it at any valid +`taler://` code, and nothing happens — no error, no reaction, and `adb logcat` +shows nothing, because the per-frame `NotFoundException` is caught and dropped. + +## Fix + +`qr-camera-ignores-the-plane-strides.diff` does all of it in one file: + +* `extractLuma(buffer, rowStride, pixelStride, width, height)` — a pure + function, so it is testable without an emulator — copies the luminance plane + row by row, skips the padding, steps by `pixelStride`, keeps the single + `get()` fast path for the tight case, and drops the chroma copy that zxing + never read. +* `rotateNV21` is deleted (see above). +* The whole frame body is wrapped in `try { … } catch (e: Exception) { Log.w } + finally { proxy.close() }`, so no frame can stop the camera. +* Analysis moves to a single-thread executor, with `onQrDetected` posted back + to the main thread. + +Verified: `:taler-kotlin-android:compileDebugKotlin`, `:taler-kotlin-android:lintDebug` +(0 errors) and the nine unit tests above all pass. Not verified on a real +camera — that is what the manual tests are for. + +### Reference implementations, none of them Google Play + +The arithmetic above is the minimal change. Two alternatives are worth knowing, +because both move the problem out of the app entirely, and neither needs Play +Services (no ML Kit anywhere): + +1. **Let zxing take the stride.** `PlanarYUVLuminanceSource`'s constructor + already separates the buffer's layout from the image: + `(yuvData, dataWidth, dataHeight, left, top, width, height, reverseHoriz)`. + Passing `rowStride` as `dataWidth` and `width`/`height` as the crop decodes + a padded frame with no stride arithmetic in the app at all — the + "no copy at all" line in section 2 of the reproducer. This is what the + merchant terminal's patch uses, being a four-line change there. +2. **Let CameraX do the conversion.** `camera-core` 1.5.3 (already a + dependency) carries, verified by `javap` on the resolved artifact: + `ImageAnalysis.Builder.setOutputImageFormat(OUTPUT_IMAGE_FORMAT_NV21)`, + `setOutputImageRotationEnabled(boolean)`, and internally + `ImageProcessingUtil.rotateYUVAndConvertToNV21` over a libyuv + `nativeRotateYUV`. That delivers a tightly packed, already-rotated NV21 + buffer from native code, which is exactly what `PlanarYUVLuminanceSource` + wants, and deletes both hand-written functions. CameraX's own stride-aware + conversion, `androidx.camera.core.internal.utils.ImageUtil.yuv_420_888toNv21`, + is worth reading as the reference arithmetic but is a restricted API — read + it, do not call it. + `OUTPUT_IMAGE_FORMAT_RGBA_8888` plus `ImageProxy.toBitmap()` would go + further and let the camera and gallery paths share the one + `decodeQrFromBitmap` decoder, at the cost of an RGBA conversion per frame + where zxing only ever reads luminance. + +Worth doing alongside, in any variant: count consecutive failed decodes and log +one debug line when the count crosses a threshold. Both defects above were +silent, and that single counter would have named either of them in a minute. + +## Attended tests the developer should run + +These need a human holding a phone; each one is chosen to separate a cause +rather than to confirm a guess. + +1. **Print the layout, once per session.** `rowStride`, `pixelStride`, + `width`, `height` of `planes[0]`, plus `rotationDegrees` and the resolution + CameraX chose, on every device and OS version in the report. This is the + decisive test: if `rowStride == width` on Android 15 and `rowStride > width` + on Android 14 for the same hardware, defect 1 is the report, and nothing + else needs proving. Ideally on the same device before and after the upgrade. +2. **Scan in all four orientations**, portrait, both landscapes and upside + down, on a device whose rows are padded. Reverse orientation is where + `rotationDegrees == 180`, the branch that throws. +3. **After a failed scan, check whether frames still arrive** — a temporary + per-frame counter in the analyzer is enough. "No frames" means defect 2; + "frames but no decode" means defect 1. Then leave the screen and come back: + if scanning works again until the next failure, that is defect 2 confirmed. +4. **Import a photo of the same code from the gallery.** It goes through a + different decoder. Gallery decodes, camera does not ⇒ the fault is in the + frame handling, not in the code, the decoder or the lighting. +5. **Vary the code's size in the frame and the light**: filling the frame, + then small and at arm's length, then dim. A layout fault fails all of them + identically; focus and resolution problems do not. +6. **Scan a non-Taler QR code** (any URL). It exercises the same pipeline + without the app's URI handling, so a decode that the wallet ignores + separates "could not read the code" from "read it and did nothing with it". diff --git a/wallet-simulator/findings/refresh-fails-on-mixed-age-denominations.md b/wallet-simulator/findings/refresh-fails-on-mixed-age-denominations.md @@ -0,0 +1,117 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Change is lost when a denomination family mixes age-restricted and ordinary coins + +Found by the `refund` scenario in round 7, once the simulator's exchange was +given age-restricted denominations alongside the ordinary ones. + +**Severity: moderate, and it applies to the shipped app.** What is certain is +that the exchange refuses the melt and wallet-core retries the refresh group +indefinitely — a permanent background failure on an ordinary spend. What is +*not* established is money loss: in the run measured here the displayed balance +after withdraw / pay / refund was exactly what the arithmetic predicts +(EUR:8.75), with nothing shown as pending, so the user may see nothing wrong +while a refresh churns underneath. Whether the affected coins remain spendable +over a longer horizon was not determined. + +It only shows on an exchange that offers both kinds of denomination for the +same value — which is exactly what an exchange supporting age restriction +looks like. + +**Already fixed upstream**: wallet-core commit `efb714f76`, "wallet-core: +preserve denomination age masks during refresh" (2026-09-14). The app ships +`net.taler:qtart:1.6.42`, which is wallet-core `c2e11ad42` of 2026-09-01 — +thirteen days older. Bumping `qtart_version` in `wallet/build.gradle` to a +build that contains that commit is the fix here. + +## What happens + +Withdraw, spend part of a coin, take a refund. The exchange rejects the melt +that the refresh needs: + +```json +{"code":1365, + "hint":"The client provided invalid age commitment data: missing, not an + array, or array of invalid size.", + "detail":"old_age_commitment_h"} +``` + +`EXCHANGE_REFRESHES_REVEAL_AGE_RESTRICTION_COMMITMENT_INVALID`. wallet-core +then reports the group as incomplete and keeps retrying: + +``` +refresh:54W1D6A47J8PPS8EE681YRWCD5S2QACVM5GEK1MEGEQTGFFJ70CG: + code 7029: Error (WALLET_REFRESH_GROUP_INCOMPLETE) +refresh:54W1D6A47J8PPS8EE681YRWCD5S2QACVM5GEK1MEGEQTGFFJ70CG: retried 5 times +``` + +In that one episode: 8 rejections from the exchange, 22 refresh-incomplete +errors. The retry counter keeps climbing (5, then 8, …) for as long as the +wallet is watched. + +Which member of the denomination family the wallet picks for the new coins +decides whether the age mask matches, so it is not certain on every spend — +but it is common: the reproducer below hit it on its **first** withdraw / +spend / refund cycle (six rejections), while one earlier run of the `refund` +scenario on the same stack produced none. + +## Reproduce by hand + +1. Run an exchange that offers age-restricted *and* ordinary denominations for + the same values. In the simulator's `backend/sim.conf` that is + `AGE_RESTRICTION_ENABLED = YES` in `[exchange]` plus the `coin_eur_*` and + `coin_eur_*_age_restricted` sections; `/keys` then advertises group age + masks of both `0` and `2446593`. +2. Install the wallet, enable **Developer mode**, and withdraw from that + exchange (no age restriction needed). +3. Pay for something that costs less than one coin — the remainder has to be + refreshed into change. +4. Take a refund for part of it. +5. Watch `adb logcat | grep -E '"code":1365|REFRESH_GROUP_INCOMPLETE'`. When + the wallet picks an incompatible family member, the rejection appears and + repeats as the refresh is retried. + +Nothing is shown in the UI — no error, nothing pending — which is what makes +this worth fixing even where the balance ends up right: a user has no way to +know their wallet is retrying a request the exchange will always refuse. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_age_restricted_refresh_fails.py # three cycles +python3 ../findings/repro_age_restricted_refresh_fails.py emulator-5562 5 +``` + +## Why + +`refresh.ts` sends `old_age_commitment_h` with the melt, and the new coins +have to be chosen with an age mask compatible with the old one. Before +`efb714f76`, the denomination selected for the new coins could come from a +different member of the same family — one with a different age mask — and the +exchange rejects the reveal as inconsistent. The commit's own words: "Select a +compatible member of each denomination family and use the same age-mask +constraint for refresh cost estimates. Families can contain both restricted +and unrestricted denominations." + +## Suggested fix + +Bump `qtart_version` in `wallet/build.gradle` past wallet-core `efb714f76`, +and keep an age-restriction-enabled exchange in whatever integration testing +the app does — the defect is invisible without one, which is why it survived +to a release. diff --git a/wallet-simulator/findings/release-error-screen-explains-nothing.diff b/wallet-simulator/findings/release-error-screen-explains-nothing.diff @@ -0,0 +1,61 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt +index a73e286c..dc719377 100644 +--- a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt ++++ b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt +@@ -78,6 +78,14 @@ data class TalerErrorInfo( + // so they are not re-encoded as -1. + val rawCode: Int = code.code, + ) { ++ /** ++ * What to show a user, which is often nothing: plenty of errors carry ++ * neither a hint nor a message -- 7001 and 7048 among them -- and this is ++ * then empty. A display site that has a [android.content.Context] should ++ * fall back to the error code; this class has none, and the code's own ++ * name ("WALLET_UNEXPECTED_EXCEPTION") is not something to put in front ++ * of a user. ++ */ + val userFacingMsg: String + get() { + return StringBuilder().apply { +@@ -93,7 +101,7 @@ data class TalerErrorInfo( + hint?.let { append(it) } + message?.let { append(" ").append(it) } + } +- }.toString() ++ }.toString().trim() + } + + fun getStringExtra(key: String): String? = +diff --git a/wallet/src/main/java/net/taler/wallet/compose/ErrorComposable.kt b/wallet/src/main/java/net/taler/wallet/compose/ErrorComposable.kt +index d3a8165f..ddd2d0ed 100644 +--- a/wallet/src/main/java/net/taler/wallet/compose/ErrorComposable.kt ++++ b/wallet/src/main/java/net/taler/wallet/compose/ErrorComposable.kt +@@ -116,7 +116,15 @@ fun ErrorComposable( + } + } else { + Text( +- text = error.userFacingMsg, ++ // Without developer mode this is the whole explanation, and ++ // for an error with neither a hint nor a message it is empty, ++ // which leaves the sheet saying only "Error". The code is ++ // not an explanation either, but it is something the user can ++ // report. rawCode rather than code.code: a code newer than ++ // this app's registry is preserved there. ++ text = error.userFacingMsg.ifEmpty { ++ stringResource(R.string.error_code_only, error.rawCode) ++ }, + fontFamily = FontFamily.Default, + textAlign = TextAlign.Center, + ) +diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml +index 905e4390..b3a63920 100644 +--- a/wallet/src/main/res/values/strings.xml ++++ b/wallet/src/main/res/values/strings.xml +@@ -65,6 +65,7 @@ GNU Taler is immune to many types of fraud such as credit card data theft, phish + <string name="enter_uri_label">Taler link</string> + <string name="enter_uri_prefix" translatable="false">taler://</string> + <string name="error">Error</string> ++ <string name="error_code_only">Error code %1$d</string> + <string name="error_export">Export error diagnostics</string> + <string name="wallet_init_error_title">Initialization error</string> + <string name="wallet_init_error_message">An error occurred while starting the wallet. This can happen after an app update or if the wallet data is incompatible. Please retry, and if the problem persists, export the logs and report this issue to the developers.</string> diff --git a/wallet-simulator/findings/release-error-screen-explains-nothing.md b/wallet-simulator/findings/release-error-screen-explains-nothing.md @@ -0,0 +1,225 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# In a release build, an error screen can explain nothing at all + +Found by the `error_screen_without_dev_mode` scenario, written because +everything else in this campaign runs with developer mode on — where the error +screen prints the whole error as JSON and the defect is invisible. + +**Severity: moderate, release builds only.** It applies to every error whose +explanation wallet-core puts somewhere other than `hint` or `message`, which +includes `WALLET_CORE_API_BAD_REQUEST` (7048) — one of the codes this campaign +hit in ordinary runs. + +## What happens + +With developer mode **on**, an error with no hint and no message shows the raw +object, which at least names the code: + +``` +Error +{ + "code": 7001, + "hint": null, + "message": null +} +Export error diagnostics [Copy] [Share] +``` + +With developer mode **off** — which is what a release build is — the same error +shows: + +``` +Error +Export error diagnostics [Copy] [Share] +``` + +An icon, the word "Error", and an invitation to export diagnostics. Nothing +about what failed, what to do, or which operation it was. + +## Why + +`ErrorComposable` has two branches, and the release one prints a single string: + +```kotlin +// wallet/src/main/java/net/taler/wallet/compose/ErrorComposable.kt:105 +if (devMode) { + … Text(text = jsonError, fontFamily = FontFamily.Monospace) … +} else { + Text(text = error.userFacingMsg, …) +} +``` + +and that string is the hint and the message concatenated, with no fallback: + +```kotlin +// wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt:81 +val userFacingMsg: String + get() = StringBuilder().apply { + if (extra.containsKey("errorResponse")) { … } + else { + hint?.let { append(it) } + message?.let { append(" ").append(it) } + } + }.toString() +``` + +Both null gives the empty string, and `Text("")` is nothing. + +This is not hypothetical. wallet-core puts the explanation of a bad request in +`detail`, which this very campaign has logged: + +``` +{"type":"error","operation":"addExchange","id":100, + "error":{"code":7048,"detail":"URL cannot be parsed"}} +``` + +`detail` is not lost — the custom `TalerErrorInfoSerializer` keeps every +unknown key in `extra`, and the "Copy"/"Share" buttons export the complete +object including it. It is simply never *shown*: `userFacingMsg` looks at +`hint`, at `message`, and at one special case (`extra["errorResponse"].hint`), +and at nothing else. + +The other end of the same problem: whatever *is* in `message` goes to the user +verbatim, exception class names included. Feeding the balance screen a reply +with an out-of-spec currency (`api_response_hostile`) produced + +``` +{"code": 0, "hint": "", + "message": "net.taler.common.AmountParserException: Invalid currency: VERYLONGCURRENCY"} +``` + +so a release build would show the user a Java class name — and the whole +balance screen becomes an error page, which for a *rejected* value is the right +severity but the wrong words. + +The mailbox screen does not even go through `ErrorComposable`; it interpolates +the error object into a string: + +```kotlin +// wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt:150 +is MailboxResult.Error -> Text("Error: ${res.error}", modifier = Modifier.padding(16.dp)) +``` + +which is a Kotlin data-class dump. Typing a malformed mailbox URL puts this on +the screen, in any build: + +``` +Error: TalerErrorInfo(code=WALLET_UNEXPECTED_EXCEPTION, hint=unexpected +exception (message: Invalid base URL: http://localhost:11000unet.org), +message=null, extra={when={"t_ms":…}, stack=" at URLImpl (<compiled_js>:4523:28) + at registerMailbox (<compiled_js>:… +``` + +— a QuickJS stack trace, shown to the user, on a screen that is not +developer-mode gated. + +## Reproduce by hand + +Needs a debug build (to deliver the URI) and one trip through the developer +mode switch: + +1. Enable **Developer mode** in Settings. +2. Queue an error with neither hint nor message — `{"code": 7001}`, base64url + encoded: + + ```bash + adb shell am start -a android.intent.action.VIEW -d \ + 'taler+http://dev-experiment/api-error?operation=getBalances&detail=eyJjb2RlIjogNzAwMX0&count=20' + ``` + +3. Go to the main screen: the error screen appears with the JSON. +4. Turn **Developer mode** off and go back to the main screen. +5. The error screen now shows only "Error" and the export buttons. + +A release build reaches the same state without step 1 or 4, with any error of +that shape — for example by adding `file:///etc/passwd` as a payment service, +whose refusal is a 7048 with only a `detail` (that one is also never shown at +all; see +[`add-payment-service-fails-silently.md`](add-payment-service-fails-silently.md)). + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_release_error_screen.py +SIM_WORKER=4 python3 suite.py error_screen_without_dev_mode +``` + +The notes record the screen with developer mode on, then off, and list +everything on the second one that could explain the error — which is nothing. + +## Fix + +`release-error-screen-explains-nothing.diff` makes the error sheet fall back to +the code when there is no text to show: + +```kotlin +// wallet/src/main/java/net/taler/wallet/compose/ErrorComposable.kt +text = error.userFacingMsg.ifEmpty { + stringResource(R.string.error_code_only, error.rawCode) +}, +``` + +with `<string name="error_code_only">Error code %1$d</string>` beside it, and +`userFacingMsg` left honest — trimmed, and empty when the error carries nothing +— with a doc comment saying where the fallback belongs. `rawCode` rather than +`code.code`, because a code newer than this app's registry is preserved there +while `code` has become `-1`. + +The screen then reads: + +``` +Error +Error code 7001 +Export error diagnostics [Copy] [Share] +``` + +### What running it changed + +The first version of this patch put the fallback inside `userFacingMsg` itself +and rendered `"Error code ${code.code} (${code.name})"`. It compiled, it +lint-passed, and on a device it produced: + +``` +Error code 7001 (WALLET_UNEXPECTED_EXCEPTION) +``` + +which the simulator immediately flagged as an `internal-error-screen` — its +oracle looks for words like "unexpected" and "exception" on screen, on the +grounds that they should not reach a user, and it was right. The enum name is +an identifier for developers; it is also untranslatable English in a UI that is +otherwise localised, and `TalerErrorInfo` has no `Context` to localise with. +Moving the fallback to the sheet, where there *is* a `Context`, fixes both: the +string is in `strings.xml` like every other, and the user sees a number they can +report rather than a phrase that reads like a crash. + +The second version was re-run on the same scenario, on a device, and the sheet +is now recorded as an ordinary error screen rather than an internal one: + +``` + error_screen_without_dev_mode ok 0 serious, 2 total, 128.7s + [error-screen] { "code": 7001, "hint": null, "message": null } + [error-screen] Error code 7001 +``` + +Worth noting for whoever takes this further: the other six places that render +`userFacingMsg` — the transactions list, the peer screens, the contact and +alias screens, and `TestWithdrawStatus` — still show nothing for an error that +carries neither hint nor message. The sheet is the one a release user meets +first, which is why the patch stops there. diff --git a/wallet-simulator/findings/repro_aborted_fee.py b/wallet-simulator/findings/repro_aborted_fee.py @@ -0,0 +1,77 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: an aborted withdrawal shows the whole amount as a fee. + +The fee row on every credit screen is the difference between the raw and the +effective amount. Aborting zeroes the effective amount, so the difference +becomes the entire amount and the screen claims it all went to fees. + + cd /opt/taler-sim/driver + python3 ../findings/repro_aborted_fee.py [emulator-5554] +""" + +from __future__ import annotations + +import re +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from device import Device # noqa: E402 +from stack import Bank, Env # noqa: E402 +from wallet import Wallet # noqa: E402 + +AMOUNT = "EUR:5" +AS_SHOWN = "5.00" + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + bank = Bank(env.bank) + + app.fresh_start(dev_mode=True) + op = bank.create_withdrawal(*scenarios.WALLET_USER, AMOUNT) + app.handle_uri(op["taler_withdraw_uri"]) + scenarios.accept_tos(app) + dev.tap_text(r"(?i)confirm withdrawal", timeout=60) + dev.wait_for(r"(?i)Waiting for authorization|Authorize in bank", timeout=60) + + # Abort before the bank confirms: nothing is withdrawn and no fee is paid. + dev.tap_text(r"(?i)^Abort$", timeout=30) + time.sleep(1.5) + if dev.dump().find(r"(?i)Abort transaction|Are you sure") is not None: + dev.tap_text(r"(?i)^Abort$|^OK$|^Yes$", timeout=15) + screen = dev.wait_for(r"(?i)was aborted|has failed", timeout=60) + time.sleep(1) + screen = dev.dump() + texts = screen.texts() + print(f"aborted transaction: {texts[:14]}") + + has_fee_row = screen.find(r"(?i)^Fee$") is not None + amounts = [t for t in texts if re.match(r"^[-−]?[€$]?\d", t)] + whole_as_fee = any(t.lstrip("-−").lstrip("€$") == AS_SHOWN for t in amounts[1:]) + print(f"fee row present: {has_fee_row}") + print(f"amounts shown: {amounts[:6]}") + print(f"\nreproduced: {has_fee_row and whole_as_fee}") + return 0 if (has_fee_row and whole_as_fee) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/repro_action_buttons_no_a11y_name.py b/wallet-simulator/findings/repro_action_buttons_no_a11y_name.py @@ -0,0 +1,76 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: the balance card's action buttons have no accessible name. + +Needs a wallet with a balance, so the action row is on screen; run +`driver/smoke_withdraw.py` first, or pass --fund to do a withdrawal here. + + cd /opt/taler-sim/driver + python3 ../findings/repro_action_buttons_no_a11y_name.py [--fund] + +Exits 0 when the defect is present (unnamed clickable buttons paired with +separate text labels), 1 when every action button has a name. +""" + +from __future__ import annotations + +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import Device # noqa: E402 +from stack import Bank, Env # noqa: E402 +from wallet import Wallet # noqa: E402 + +ACTIONS = ("Send", "Request", "Withdraw", "Deposit") + + +def main() -> int: + dev = Device(sys.argv[1] if len(sys.argv) > 1 and sys.argv[1].startswith("emulator") + else "emulator-5554") + app = Wallet(dev) + if "--fund" in sys.argv: + import scenarios + env = Env.load() + app.fresh_start(dev_mode=True) + scenarios.withdraw(app, Bank(env.bank), "EUR:10") + screen = app.home() + + labels = {name: screen.find(f"^{name}$") for name in ACTIONS} + missing = [name for name, node in labels.items() if node is None] + if missing: + print(f"action row not on screen (missing {missing}); " + f"does the wallet have a balance?\nscreen: {screen.texts()}") + return 2 + + unnamed = [] + for name, node in labels.items(): + button = screen.tap_target(node) + named = bool(button.label.strip()) + print(f"{name:10} label node at {node.center}, " + f"clickable={node.clickable} -> button {button.cls.rsplit('.', 1)[-1]} " + f"at {button.center} accessible-name={button.label.strip()!r}") + if not named and button is not node: + unnamed.append(name) + + print(f"\nclickable nodes on this screen with no accessible name: " + f"{len(screen.unnamed_clickables())}") + print(f"action buttons without an accessible name: {unnamed}") + print(f"\nreproduced: {len(unnamed) == len(ACTIONS)}") + return 0 if len(unnamed) == len(ACTIONS) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/repro_add_exchange_fails_silently.py b/wallet-simulator/findings/repro_add_exchange_fails_silently.py @@ -0,0 +1,90 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: adding a payment service with a bad URL fails without saying so. + + cd /opt/taler-sim/driver + python3 ../findings/repro_add_exchange_fails_silently.py [emulator-5554] + +Exits 0 when wallet-core rejected the URL and nothing said so on screen. +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +BAD_URL = "file:///etc/passwd" +COMPLAINT = r"(?i)could not add|error|invalid|failed|not supported" + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + app.fresh_start(dev_mode=True) + + app.open_settings() + app.scroll_to_text(r"(?i)^Payment services$") + dev.tap_text(r"(?i)^Payment services$", timeout=30) + time.sleep(2) + dev.tap_text(r"(?i)^Add payment service$", timeout=30) + time.sleep(2) + + screen = dev.dump() + fields = screen.editable() + if not fields: + print(f"no URL field: {screen.texts()}") + return 2 + dev.tap_node(fields[0], screen) + dev.type_text(BAD_URL) + time.sleep(1) + dev.logcat(clear=True) + + screen = dev.dump() + ok = screen.find(r"(?i)^OK$") + if ok is None: + print(f"no OK button: {screen.texts()}") + return 2 + dev.tap_node(ok, screen) + + # Watch for anything that explains the failure, for longer than a snackbar + # would last. + complaints = [] + for _ in range(6): + time.sleep(1.5) + current = dev.dump() + found = current.find(COMPLAINT) + if found is not None: + complaints.append(found.label) + log = dev.logcat() + rejected = [ln for ln in log.splitlines() + if "addExchange" in ln and '"code":7048' in ln] + + print(f"wallet-core rejections logged: {len(rejected)}") + if rejected: + print(" " + rejected[0][-200:]) + print(f"anything shown to the user: {complaints or 'nothing'}") + print(f"screen now: {dev.dump().texts()[:8]}") + print(f"\nreproduced: {bool(rejected) and not complaints}") + return 0 if (rejected and not complaints) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/repro_age_restricted_refresh_fails.py b/wallet-simulator/findings/repro_age_restricted_refresh_fails.py @@ -0,0 +1,101 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: spending age-restricted coins leaves the change stuck. + +Withdraws with an age restriction, spends part of it, and watches what the +exchange says about the refresh that follows. + + cd /opt/taler-sim/driver + python3 ../findings/repro_age_restricted_refresh_fails.py [emulator-5554] + +Needs a stack whose exchange offers age-restricted denominations (the +simulator's sim.conf does). Exits 0 when the exchange rejects the refresh. +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import oracles # noqa: E402 +import scenarios # noqa: E402 +from device import Device # noqa: E402 +from stack import Bank, Env, Merchant # noqa: E402 +from wallet import Wallet # noqa: E402 + +CYCLES = int(sys.argv[2]) if len(sys.argv) > 2 else 3 + + +def spend_and_refund(app: Wallet, dev: Device, bank: Bank, merchant: Merchant, + env: Env) -> list[str]: + """Withdraw, spend part of it, take a refund — each step leaves change to + refresh, which is where the exchange rejects the melt.""" + app.fresh_start(dev_mode=True) + scenarios.withdraw(app, bank, "EUR:10") + app.home() + dev.logcat(clear=True) + + order = merchant.create_order("EUR:2", summary="Partial spend") + app.handle_uri(order["pay_uri"]) + dev.tap_text(r"(?i)^Pay\b|confirm payment", timeout=60) + for _ in range(25): + if merchant.order_status(order["order_id"], + order["token"]).get("order_status") == "paid": + break + time.sleep(2) + # A refund puts the money back, which also has to be refreshed. + res = merchant.refund(order["order_id"], "EUR:1") + if res.get("taler_refund_uri"): + app.handle_uri(res["taler_refund_uri"]) + + rejections: list[str] = [] + for _ in range(5): + time.sleep(15) + log = dev.logcat(lines=6000) + rejections = [ln for ln in log.splitlines() if '"code":1365' in ln] + if rejections: + break + return rejections + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + bank, merchant = Bank(env.bank), Merchant(env.merchant) + + for attempt in range(1, CYCLES + 1): + print(f"--- cycle {attempt} ---") + rejections = spend_and_refund(app, dev, bank, merchant, env) + stuck = [f for f in oracles.background_failures(dev) + if f.kind in ("stuck-operation", "background-error") + and "refresh" in f.detail] + print(f"age-commitment rejections: {len(rejections)}") + for finding in stuck: + print(f" {finding.detail[:140]}") + if rejections: + print(" " + rejections[0][-220:]) + print("\nreproduced: True") + return 0 + print("\nreproduced: False (it is probabilistic: which member of a " + "denomination family the wallet picks decides it)") + return 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/repro_config_change_db_ownership.py b/wallet-simulator/findings/repro_config_change_db_ownership.py @@ -0,0 +1,105 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: a configuration change locks the wallet out of its database. + +Changing the app's language restarts it, and the new instance cannot take the +SQLite database while the one it replaced still holds it: + + code 7001, "could not acquire exclusive ownership of the wallet database; + another wallet process may still be using it" + +which lands the user on the Initialization error screen -- the whole app +replaced by two export buttons and an invitation to retry that nothing on the +screen can act on. + +It is a race between the dying and the starting process, so this tries a few +times and reports how often it lost, rather than pretending it is certain. + + cd /opt/taler-sim/driver + python3 ../findings/repro_config_change_db_ownership.py [emulator-5554] [attempts] + +Exits 0 when at least one attempt reaches the error screen. +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +ERROR_SCREEN = (r"(?i)Initialization error|Initialisierungsfehler" + r"|error occurred while starting|Fehler aufgetreten") +OWNERSHIP = r"(?i)exclusive ownership of the wallet database" + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + attempts = int(sys.argv[2]) if len(sys.argv) > 2 else 3 + dev = Device(serial) + app = Wallet(dev) + + if dev.sdk_int < 33: + print(f"this device is API {dev.sdk_int}; this reproducer changes the " + "per-app language, which needs 33+. The same defect should be " + "reachable by changing the font size or the display size, which " + "every version supports -- see the finding's table.") + return 2 + broke = 0 + try: + for n in range(1, attempts + 1): + dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales", check=False) + app.fresh_start(dev_mode=True) + # Any screen will do; a settings sub-screen is where it was first + # seen, and it keeps the wallet busy while the change lands. + app.open_settings() + app.scroll_to_text(r"(?i)^Contacts$", max_scrolls=12) + dev.tap_text(r"(?i)^Contacts$", timeout=20) + time.sleep(3) + + dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales de-DE", + check=False) + time.sleep(9) + screen = dev.dump() + hit = screen.find(ERROR_SCREEN) is not None + print(f"attempt {n}: " + + ("INITIALIZATION ERROR" if hit else "survived") + + f" -- {' | '.join(screen.texts()[:4])[:150]}") + if hit: + broke += 1 + if screen.find(OWNERSHIP) is not None: + print(" the error is the database ownership one") + # Nothing on the screen can retry; the app has to be killed. + buttons = [n_.label for n_ in screen.tappable() if n_.label] + print(f" what the screen offers: {buttons}") + dev.stop() + time.sleep(2) + dev.launch() + time.sleep(10) + again = dev.dump().find(ERROR_SCREEN) is not None + print(f" still broken after a relaunch: {again}") + break + + print(f"\nreproduced: {broke > 0} ({broke} of {n} attempts)") + return 0 if broke else 1 + finally: + dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales", check=False) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/wallet-simulator/findings/repro_delete_requeries_transaction.py b/wallet-simulator/findings/repro_delete_requeries_transaction.py @@ -0,0 +1,83 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: deleting a transaction makes the app ask for it again. + + cd /opt/taler-sim/driver + python3 ../findings/repro_delete_requeries_transaction.py [emulator-5554] + +Exits 0 when the stray getTransactionById error shows up in the log. +""" + +from __future__ import annotations + +import re +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +import suite # noqa: E402 +from device import Device # noqa: E402 +from stack import Env # noqa: E402 +from wallet import Wallet # noqa: E402 + +# The error carries a nested "when" object between the code and the hint, so +# the two are matched independently rather than with one span. +STRAY = re.compile(r'"operation":"getTransactionById".*?"code":(\d+).*?not found') + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + + # A wallet with one finished withdrawal and one finished purchase. + scenarios.funded_and_paid(app, env) + dev.logcat(clear=True) + + screen = app.home() + if screen.find(r"(?i)^Recent transactions$") is None: + screen = app.scroll_to_text(r"(?i)^Recent transactions$") + rows = suite.transaction_rows(screen) + if not rows: + print(f"no transactions to delete; screen: {screen.texts()}") + return 2 + dev.tap_node(rows[0], screen) + time.sleep(2) + dev.tap_text(r"(?i)^Delete$", timeout=30) + time.sleep(1) + # Confirm the dialog. + confirm = dev.dump().find(r"(?i)^Delete$") + if confirm is not None: + dev.tap_node(confirm, dev.dump()) + time.sleep(4) + + log = dev.logcat() + hits = [ln for ln in log.splitlines() if STRAY.search(ln)] + queries = [ln for ln in log.splitlines() + if '"operation": "getTransactionById"' in ln or + '"operation":"getTransactionById"' in ln] + print(f"getTransactionById mentions after the delete: {len(queries)}") + for line in hits[:4]: + print(line.strip()[:320]) + print(f"\nscreen now: {dev.dump().texts()[:10]}") + print(f"reproduced: {bool(hits)}") + return 0 if hits else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/repro_dev_experiment_uri_exits_app.py b/wallet-simulator/findings/repro_dev_experiment_uri_exits_app.py @@ -0,0 +1,82 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: an unknown dev-experiment URI errors internally and exits the app. + +The wallet must be closed when the URI arrives — scanning a QR code or opening +a link from elsewhere — because that is the case where the screen it pops is +the only one in the task. + + cd /opt/taler-sim/driver + python3 ../findings/repro_dev_experiment_uri_exits_app.py [emulator-5554] + +Exits 0 when both halves reproduce: the 7001 error in the log, and the wallet +no longer being the foreground app. +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import PKG, Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +URI = "taler+http://dev-experiment/nonexistent" + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + app.fresh_start(dev_mode=True) + app.home() + # The URI has to arrive while the wallet is *not* open: with the app + # already running the screen pops back to the main screen, and only a + # cold start has nothing behind it to pop to. + dev.stop() + time.sleep(2) + dev.logcat(clear=True) + + dev.send_uri(URI) + # The wallet opens, handles the URI and only then pops the screen, so the + # foreground is sampled until it settles rather than once. + left_at = None + for _ in range(10): + time.sleep(2) + if PKG not in dev.current_activity(): + left_at = dev.current_activity() + break + + screen = dev.dump() + log = dev.logcat() + internal = [ln for ln in log.splitlines() + if "applyDevExperiment" in ln and "7001" in ln] + left_app = left_at is not None or PKG not in screen.activity + + print(f"foreground activity afterwards: " + f"{left_at or screen.activity or '(none)'}") + print(f"on screen: {screen.texts()[:8]}") + for line in internal[:2]: + print(line.strip()[:260]) + print(f"\nwallet left the foreground: {left_app}") + print(f"internal error logged: {bool(internal)}") + print(f"reproduced: {left_app and bool(internal)}") + return 0 if (left_app and internal) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/repro_failed_query_empty_state.py b/wallet-simulator/findings/repro_failed_query_empty_state.py @@ -0,0 +1,88 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: a failed query is shown as an empty wallet. + +Two screens state a failure as a fact about the user's wallet: the deposit +screen says there are no bank accounts, and the send screen offers €0.00. +Both are driven by an injected failure of the one wallet-core call each screen +makes. + + cd /opt/taler-sim/driver + python3 ../findings/repro_failed_query_empty_state.py [emulator-5554] +""" + +from __future__ import annotations + +import base64 +import json +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from device import PKG, Device # noqa: E402 +from stack import Env # noqa: E402 +from wallet import Wallet # noqa: E402 + + +def inject(app: Wallet, dev: Device, operation: str, count: int = 4) -> None: + detail = base64.urlsafe_b64encode( + json.dumps({"code": 7001, "hint": "injected"}).encode() + ).decode().rstrip("=") + app.handle_uri(f"taler+http://dev-experiment/api-error?operation={operation}" + f"&detail={detail}&count={count}") + time.sleep(2) + # Applying an experiment ends with a back navigation, which closes the app + # when the URI is what started it. + for _ in range(3): + if dev.dump().activity.startswith(PKG): + return + dev.launch() + time.sleep(6) + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + scenarios.fund_wallet(app, env, "EUR:10") + + inject(app, dev, "getDepositWireTypes") + app.home() + dev.tap_text(r"(?i)^Deposit$", timeout=30) + time.sleep(4) + deposit = dev.dump().texts() + print(f"deposit screen: {deposit[:8]}") + no_accounts = any("No bank accounts" in t for t in deposit) + + app.home() + inject(app, dev, "getMaxPeerPushDebitAmount") + app.home() + dev.tap_text(r"(?i)^Send$", timeout=30) + time.sleep(4) + send = dev.dump().texts() + print(f"send screen: {send[:10]}") + zero_to_send = any(t.strip() in ("€0.00", "Send €0.00") for t in send) + + print(f"\ndeposit claims there are no accounts: {no_accounts}") + print(f"send offers nothing to send: {zero_to_send}") + print(f"reproduced: {no_accounts or zero_to_send}") + return 0 if (no_accounts or zero_to_send) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/repro_global_currency_null_masterpub.py b/wallet-simulator/findings/repro_global_currency_null_masterpub.py @@ -0,0 +1,68 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Minimal reproducer: "Treat as global" on an un-contacted exchange. + +Found by explore.py (seed 11, step 34) and shrunk to four taps. See +addglobalcurrencyexchange-null-masterpub.md for the analysis. + + cd /opt/taler-sim/driver && python3 ../findings/repro_global_currency_null_masterpub.py + +Exits 0 when the internal error reproduces, 1 when it does not. +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +# A builtin exchange the wallet has never talked to, so its masterPub is still +# null. exchange.demo.taler.net works too; the local one does not, because +# withdrawing from it fetches /keys and fills masterPub in. +UNCONTACTED = "exchange.taler-ops.ch" + + +def main() -> int: + dev = Device(sys.argv[1] if len(sys.argv) > 1 else "emulator-5554") + app = Wallet(dev) + + app.fresh_start(dev_mode=True) + dev.logcat(clear=True) + + app.open_settings() + app.scroll_to_text(r"(?i)^Payment services$") + dev.tap_text(r"(?i)^Payment services$") + dev.wait_for(UNCONTACTED, timeout=30) + dev.tap_text(f"Menu: {UNCONTACTED}", timeout=30) + dev.tap_text(r"(?i)^Treat as global$", timeout=30) + time.sleep(3) + + log = dev.logcat() + screen = dev.dump() + hit = "addGlobalCurrencyExchange error" in log and "exchangeMasterPub" in log + print(f"screen after the tap: {screen.texts()}") + for line in log.splitlines(): + if "addGlobalCurrencyExchange" in line and "error" in line: + print(line.strip()[:400]) + print(f"\nreproduced: {hit}") + return 0 if hit else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/wallet-simulator/findings/repro_mailbox_private_keys_in_log.py b/wallet-simulator/findings/repro_mailbox_private_keys_in_log.py @@ -0,0 +1,61 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: mailbox private keys end up in the log. + +The periodic refresh runs every 30 seconds while developer mode is on, so this +waits a little over one period. + + cd /opt/taler-sim/driver + python3 ../findings/repro_mailbox_private_keys_in_log.py [emulator-5554] + +Exits 0 when a private key is found in logcat. +""" + +from __future__ import annotations + +import re +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +KEYS = re.compile(r"(privateKey|privateEncryptionKey)=([A-Z0-9]{20,})") + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + app.fresh_start(dev_mode=True) + dev.logcat(clear=True) + + print("waiting for the 30 s mailbox refresh ...") + found: list[tuple[str, str]] = [] + deadline = time.time() + 120 + while time.time() < deadline and not found: + time.sleep(10) + found = KEYS.findall(dev.logcat()) + + for field, value in found[:4]: + print(f" {field} = {value[:12]}… ({len(value)} chars) in logcat") + print(f"\nreproduced: {bool(found)}") + return 0 if found else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/repro_pos_confirmation_codes.py b/wallet-simulator/findings/repro_pos_confirmation_codes.py @@ -0,0 +1,81 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: the point-of-sale confirmation shows every code in the window. + +An order that names a merchant OTP device gets a `pos_confirmation` in its pay +reply, and the wallet prints it verbatim -- which is every T-OTP code in the +valid time range, newline separated, under the singular label "Confirmation +code". + + cd /opt/taler-sim/driver + python3 ../findings/repro_pos_confirmation_codes.py [emulator-5554] +""" + +from __future__ import annotations + +import re +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from device import Device # noqa: E402 +from stack import Env, Merchant # noqa: E402 +from wallet import Wallet # noqa: E402 + +DEVICE_ID = "reprotill" + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + merchant = Merchant(env.merchant) + + scenarios.fund_wallet(app, env, "EUR:10") + merchant.create_otp_device(DEVICE_ID) + order = merchant.create_order("EUR:1", summary="Reproducer till order", + otp_id=DEVICE_ID) + app.handle_uri(order["pay_uri"]) + dev.tap_text(r"(?i)^pay\b|confirm payment", timeout=60) + + deadline = time.time() + 90 + while time.time() < deadline: + if merchant.order_status(order["order_id"], + order["token"]).get("order_status") == "paid": + break + time.sleep(2) + else: + print("the order was never paid") + return 2 + + screen = dev.wait_for(r"(?i)Confirmation code|completed successfully", timeout=45) + time.sleep(2) + screen = dev.dump() + codes = [line.strip() for t in screen.texts() for line in t.splitlines() + if re.fullmatch(r"\d{6,}", line.strip())] + labelled = screen.find(r"(?i)^Confirmation code$") is not None + + print(f"screen: {screen.texts()[:12]}") + print(f"'Confirmation code' label present: {labelled}") + print(f"codes shown: {codes}") + print(f"\nreproduced: {labelled and len(codes) > 1}") + return 0 if (labelled and len(codes) > 1) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/repro_release_error_screen.py b/wallet-simulator/findings/repro_release_error_screen.py @@ -0,0 +1,91 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: a release build's error screen can explain nothing. + +With developer mode off, the whole explanation is `userFacingMsg` -- the hint +and the message concatenated -- so an error carrying neither renders as the +word "Error" and the export buttons. + + cd /opt/taler-sim/driver + python3 ../findings/repro_release_error_screen.py [emulator-5554] +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from device import PKG, Device # noqa: E402 +from stack import Env # noqa: E402 +from wallet import Wallet # noqa: E402 + +# {"code": 7001}: no hint, no message. +BARE_ERROR = ("taler+http://dev-experiment/api-error?operation=getBalances" + "&detail=eyJjb2RlIjogNzAwMX0&count=20") +CHROME = ("Error", "Copy", "Share", "Settings", "Internal event log", + "Scan QR code", "Wallet") + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + scenarios.fund_wallet(app, env, "EUR:10") + + app.handle_uri(BARE_ERROR) + time.sleep(2) + for _ in range(3): + if dev.dump().activity.startswith(PKG): + break + dev.launch() + time.sleep(6) + app.home() + time.sleep(3) + print(f"with developer mode: {dev.dump().texts()[:8]}") + + # Turn developer mode off: that is what a release build is. + app.open_settings() + app.scroll_to_text(r"(?i)^Developer mode$") + screen = dev.dump() + row = screen.find(r"(?i)^Developer mode$") + if row is None: + print("no developer mode row") + return 2 + _, y = row.center + width = max(n.bounds[2] for n in screen.nodes) + dev.tap(width - 100, y) + time.sleep(2) + if app.dev_mode_on(): + print("could not turn developer mode off") + return 2 + + app.home() + time.sleep(4) + texts = dev.dump().texts() + print(f"without developer mode: {texts[:8]}") + said_error = any(t.strip() == "Error" for t in texts) + explained = [t for t in texts + if t.strip() not in CHROME and "Export error" not in t] + print(f"anything explaining it: {explained[:6]}") + print(f"\nreproduced: {said_error and not explained}") + return 0 if (said_error and not explained) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/repro_unknown_currency_formatting.py b/wallet-simulator/findings/repro_unknown_currency_formatting.py @@ -0,0 +1,58 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: a word-shaped currency symbol is glued to the number. + + cd /opt/taler-sim/driver + python3 ../findings/repro_unknown_currency_formatting.py [emulator-5554] + +Exits 0 when an amount like "UNKNOWN0.00" is on screen. +""" + +from __future__ import annotations + +import re +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +# A currency word immediately followed by digits, with no separator. +GLUED = re.compile(r"^[A-Za-z]{3,}\d") +# Any order id that does not exist at the merchant will do. +PAY_URI = "taler+http://pay/localhost:8080/instances/sim/NOSUCHORDER12345/" + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + app.fresh_start(dev_mode=True) + app.handle_uri(PAY_URI) + time.sleep(8) + + screen = dev.dump() + texts = screen.texts() + glued = [t for t in texts if GLUED.match(t.strip())] + print(f"screen: {texts[:14]}") + print(f"amounts rendered without a separator: {glued}") + print(f"\nreproduced: {bool(glued)}") + return 0 if glued else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/repro_unknown_wire_method.py b/wallet-simulator/findings/repro_unknown_wire_method.py @@ -0,0 +1,76 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: an unknown wire method hangs the add-account form. + +The exchange advertises a `cyclos` account; `WireType` has no member for it and +the property it decodes into has no default, so the whole getDepositWireTypes +reply throws and the form sits on its spinner for ever. + +Needs the simulator's stack, whose exchange signs a Cyclos address by default +(SIM_EXTRA_PAYTOS in backend/stack.sh). + + cd /opt/taler-sim/driver + python3 ../findings/repro_unknown_wire_method.py [emulator-5554] +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from device import Device # noqa: E402 +from stack import Env # noqa: E402 +from wallet import Wallet # noqa: E402 + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + scenarios.fund_wallet(app, env, "EUR:10") + + dev.logcat(clear=True) + app.open_settings() + app.scroll_to_text(r"(?i)^Bank accounts$") + dev.tap_text(r"(?i)^Bank accounts$", timeout=20) + time.sleep(3) + dev.tap_text(r"(?i)^Add account$", timeout=20) + # Give the form far longer than it should need. + time.sleep(20) + texts = dev.dump().texts() + print(f"the add-account form after 20s: {texts}") + + log = dev.logcat(lines=600) + failures = [l for l in log.splitlines() if "getDepositWireTypes" in l + and "Error" in l] + print("the log says: " + (failures[-1][-220:] if failures else "nothing")) + + fields = dev.dump().editable() + stuck = not fields and not any( + t.strip().lower() in ("iban", "x-taler-bank", "bitcoin") for t in texts) + unknown_method = any("does not contain element with name" in l + for l in failures) + print(f"\nform is empty: {stuck}") + print(f"an unknown wire method is why: {unknown_method}") + print(f"reproduced: {stuck and unknown_method}") + return 0 if (stuck and unknown_method) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/repro_unreachable_host_zombie_purchase.py b/wallet-simulator/findings/repro_unreachable_host_zombie_purchase.py @@ -0,0 +1,80 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: a pay URI the app may never fetch leaves an empty, retrying purchase. + + cd /opt/taler-sim/driver + python3 ../findings/repro_unreachable_host_zombie_purchase.py [emulator-5554] + +Exits 0 when the purchase screen comes up empty and the request keeps being +retried. +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import oracles # noqa: E402 +from device import Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +# 127.0.0.1 is the same machine as localhost, but the app's network security +# config names only "localhost", so the platform refuses the connection. +URI = "taler+http://pay/127.0.0.1:8080/instances/sim/" + "A" * 52 + "/" + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + app.fresh_start(dev_mode=True) + dev.logcat(clear=True) + + app.handle_uri(URI) + time.sleep(10) + screen = dev.dump() + labels = screen.texts() + empty = [t for t in labels + if t.strip().lower() not in ("go back", "purchase", "internal event log")] + refusals = [ln for ln in dev.logcat(lines=800).splitlines() if "CLEARTEXT" in ln] + + print(f"screen: {labels[:10]}") + print(f"content beyond the title and back button: {empty or 'none'}") + print(f"cleartext refusals in the first 10 s: {len(refusals)}") + if refusals: + print(" " + refusals[0][-140:]) + + # Watch the retry counter climb rather than the transaction giving up. + counts = [] + for _ in range(2): + time.sleep(25) + for finding in oracles.background_failures(dev): + if finding.kind == "stuck-operation": + counts.append(finding.detail) + for line in counts: + print(f" {line}") + + blank = not empty + retrying = len(refusals) > 1 and bool(counts) + print(f"\nblank purchase screen: {blank}") + print(f"still retrying a request that can never succeed: {retrying}") + print(f"reproduced: {blank and retrying}") + return 0 if (blank and retrying) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/repro_unspecced_amounts.py b/wallet-simulator/findings/repro_unspecced_amounts.py @@ -0,0 +1,100 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: amounts rendered without their currency specification. + +Two screens show the wallet's fallback notation ("5.00 EUR") where the rest of +the app shows "€5.00": + + * the manual withdrawal's wire transfer instructions, which put both + notations in one sentence; + * the incoming peer-payment prompt, whose composable takes no currency + specification at all. + + cd /opt/taler-sim/driver + python3 ../findings/repro_unspecced_amounts.py [emulator-5554] +""" + +from __future__ import annotations + +import re +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from cli import CliWallet # noqa: E402 +from device import Device # noqa: E402 +from stack import Bank, Env # noqa: E402 +from wallet import Wallet # noqa: E402 + +# "5.00 EUR": a number followed by the currency code, which is what +# Amount.toString() produces when it has no specification to work from. +UNSPECCED = re.compile(r"\d+[.,]\d\d\s+[A-Z]{3,}") + + +def transfer_instructions(dev: Device, app: Wallet, bank: Bank) -> list[str]: + """A manual withdrawal, as far as the wire transfer instructions.""" + app.home() + dev.tap_text(r"(?i)^Withdraw$", timeout=30) + dev.wait_for(r"(?i)Amount to withdraw|Total amount", timeout=30) + screen = dev.dump() + fields = screen.editable() + if fields: + dev.tap_node(fields[0], screen) + dev.type_text("500") + time.sleep(2) + scenarios.accept_tos(app) + dev.tap_text(r"(?i)Confirm withdrawal", timeout=30) + dev.wait_for(r"(?i)Wire transfer instructions|transaction is pending", timeout=60) + dev.tap_text(r"(?i)Wire transfer instructions", timeout=30) + screen = dev.wait_for(r"(?i)Subject|Recipient|IBAN|Account", timeout=30) + time.sleep(1) + return dev.dump().texts() + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + bank = Bank(env.bank) + + scenarios.fund_wallet(app, env, "EUR:10") + instructions = transfer_instructions(dev, app, bank) + bad_transfer = [t for t in instructions if UNSPECCED.search(t)] + print(f"transfer instructions: {instructions[:6]}") + print(f"unformatted there: {bad_transfer[:2]}") + + # The peer prompt: another wallet pushes money to this one. The prompt is + # read before accepting anything, so nothing here depends on the timing of + # the accept. + peer = CliWallet() + app.home() + scenarios.fund_peer(peer, env, "EUR:5") + uri = peer.peer_send("EUR:1", env.exchange) + app.handle_uri(uri) + prompt = dev.wait_for(r"(?i)Do you want to receive this payment|Total:", + timeout=60) + bad_peer = [t for t in prompt.texts() if UNSPECCED.search(t)] + print(f"peer prompt: {prompt.texts()[:10]}") + print(f"unformatted there: {bad_peer[:3]}") + + print(f"\nreproduced: {bool(bad_transfer) or bool(bad_peer)}") + return 0 if (bad_transfer or bad_peer) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/repro_untranslated_contacts_mailbox.py b/wallet-simulator/findings/repro_untranslated_contacts_mailbox.py @@ -0,0 +1,140 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: the contacts and mailbox screens stay English in every language. + +Their labels are string literals in the Compose sources rather than entries in +strings.xml, so there is nothing for a translator to translate and nothing for +./check-translations.py to miss. + +The script's own navigation is the evidence. Reaching Settings in a German +wallet needs a bilingual pattern ("Settings|Einstellungen") because that label +*is* translated; the two entries inside it, and every label on the screens they +open, are matched in English alone -- and found. + +The app is restarted after the language is set, which is what a user does +anyway, and which avoids the unrelated defect in +`config-change-locks-the-wallet-out-of-its-database.md`. + + cd /opt/taler-sim/driver + python3 ../findings/repro_untranslated_contacts_mailbox.py [emulator-5554] + +Exits 0 when English labels are on screen in a German wallet. The per-app +language needs no root (Android 13+) and is restored on the way out. +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +from device import Device # noqa: E402 +from wallet import Wallet # noqa: E402 + +# Labels with no entry in res/values/strings.xml, so no values-de/ can carry +# them, per screen, with the (English) settings entry that opens it. +SCREENS = { + "Contacts": [r"^Add Contact$", r"^Petname$", r"^Alias$", r"^Alias Type$", + r"Lookup with Taldir", r"No contacts yet", r"Search contacts"], + "Mailbox": [r"^Your Mailbox Address$", r"^Configure Mailbox URL$", + r"^Mailbox Base URL$", r"No messages yet", r"^Mailbox$"], +} +# These are translated, so the script has to know both spellings to get around. +SETTINGS = r"(?i)^(Settings|Einstellungen)$" +IN_SETTINGS = r"(?i)Developer mode|Entwicklermodus|Payment services|Bezahldienste" +# A fresh wallet shows its welcome state rather than the four action +# buttons, so the markers have to cover both. +GERMAN_HOME = [r"^Einstellungen$", r"^QR-Code scannen$", + r"Willkommen bei Taler Wallet", r"abheben", + r"^Senden$", r"^Anfordern$"] + + +HOME = r"(?i)^(Scan QR code|QR-Code scannen)$" + + +def go_home(dev: Device) -> None: + """Back out to the wallet's own home screen, in either language. + + Wallet.home() looks for the English "Scan QR code" only, so in a German + wallet it presses back until the app itself is gone. + """ + for _ in range(6): + if dev.dump().find(HOME) is not None: + return + dev.back() + time.sleep(1) + # Backed out of the app altogether; bring it up again. + dev.launch() + time.sleep(8) + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + + if dev.sdk_int < 33: + print(f"this device is API {dev.sdk_int}; a per-app language needs 33+, " + "so there is no way to switch the wallet's language from here") + return 2 + try: + dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales", check=False) + app.fresh_start(dev_mode=True) + app.home() + + dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales de-DE", + check=False) + time.sleep(3) + dev.stop() + time.sleep(2) + dev.launch() + time.sleep(12) + home = dev.dump() + german = [p for p in GERMAN_HOME if home.find(f"(?i){p}") is not None] + print(f"the wallet is in German: {[p.strip('^$') for p in german]}") + print(f" home screen: {' | '.join(home.texts()[:10])}") + if not german: + print("the language did not change; nothing to measure") + return 1 + + found: dict[str, list[str]] = {} + for entry, labels in SCREENS.items(): + dev.tap_text(SETTINGS, timeout=30) + dev.wait_for(IN_SETTINGS, timeout=30) + app.scroll_to_text(rf"(?i)^{entry}$", max_scrolls=12) + # The entry itself is matched in English, in a German wallet. + dev.tap_text(rf"(?i)^{entry}$", timeout=20) + time.sleep(3) + shown = dev.dump() + found[entry] = [l for l in labels + if shown.find(f"(?i){l}") is not None] + print(f"\n=== {entry} (reached by its English name)") + print(" " + " | ".join(shown.texts()[:14])) + print(f" {len(found[entry])} untranslatable labels: " + f"{[l.strip('^$') for l in found[entry]]}") + go_home(dev) + + total = sum(len(v) for v in found.values()) + print(f"\nreproduced: {total >= 4} ({total} English labels in a German " + f"wallet, plus the two settings entries that opened them)") + return 0 if total >= 4 else 1 + finally: + dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales", check=False) + print("restored the app's language") + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/wallet-simulator/findings/repro_wallet_lock_bypass.py b/wallet-simulator/findings/repro_wallet_lock_bypass.py @@ -0,0 +1,96 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: the wallet lock opens with no credential. + +"Protect access to wallet" can only be switched on while the device can +authenticate, but nothing re-checks afterwards: when the credential is gone, +the prompt fails with ERROR_NO_DEVICE_CREDENTIAL and the app unlocks anyway, +while still showing its lock screen. + +Touches the device's lock settings and clears them again afterwards. + + cd /opt/taler-sim/driver + python3 ../findings/repro_wallet_lock_bypass.py [emulator-5554] +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from device import Device # noqa: E402 +from stack import Env # noqa: E402 +from wallet import Wallet # noqa: E402 + +PIN = "1234" + + +def restart(dev: Device, app: Wallet) -> None: + dev.stop() + time.sleep(2) + dev.launch() + time.sleep(6) + + +def locked(dev: Device) -> bool: + """The overlay covers the app, but the nodes underneath are still dumped.""" + return dev.dump().find(r"(?i)Tap to unlock") is not None + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + try: + out = dev.shell(f"locksettings set-pin {PIN}", check=False) + if "set" not in out.lower(): + print(f"could not set a device credential: {out.strip()[:120]}") + return 2 + scenarios.fund_wallet(app, env, "EUR:10") + app.open_settings() + app.scroll_to_text(r"(?i)^Protect access to wallet$") + dev.tap_text(r"(?i)^Protect access to wallet$", timeout=20) + time.sleep(3) + + restart(dev, app) + with_credential = locked(dev) + print(f"locked with a credential: {with_credential}") + if not with_credential: + print("the switch did not take; nothing to test") + return 2 + + print(dev.shell(f"locksettings clear --old {PIN}", check=False).strip()) + restart(dev, app) + before = locked(dev) + print(f"locked after the credential was removed: {before}") + dev.tap_text(r"(?i)Tap to unlock", timeout=20) + time.sleep(5) + after = locked(dev) + texts = dev.dump().texts() + print(f"still locked after tapping unlock: {after}") + print(f"screen: {texts[:10]}") + print(f"\nreproduced: {before and not after}") + return 0 if (before and not after) else 1 + finally: + dev.shell(f"locksettings clear --old {PIN}", check=False) + dev.shell("locksettings set-disabled true", check=False) + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/repro_zero_deposit.py b/wallet-simulator/findings/repro_zero_deposit.py @@ -0,0 +1,108 @@ +# This file is part of GNU Taler +# (C) 2026 Taler Systems S.A. +# +# GNU Taler is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +"""Reproducer: the deposit screen does not guard the zero/below-fee case. + +Two halves: + * clearing the amount asks wallet-core to price a zero deposit, which fails + with WALLET_UNEXPECTED_EXCEPTION ("can't sum zero amounts"); + * depositing an amount at or below the deposit fee creates a transaction + whose raw amount is zero. + + cd /opt/taler-sim/driver + python3 ../findings/repro_zero_deposit.py [emulator-5554] +""" + +from __future__ import annotations + +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) + +import scenarios # noqa: E402 +from device import Device # noqa: E402 +from stack import Env # noqa: E402 +from wallet import Wallet # noqa: E402 + + +def open_deposit_amount(dev: Device, app: Wallet): + app.home() + dev.tap_text(r"(?i)^Deposit$", timeout=30) + time.sleep(3) + screen = dev.dump() + account = screen.find(r"(?i)^wallet\d+$") or screen.find(r"(?i)x-taler-bank") + if account is not None: + dev.tap_node(account, screen) + time.sleep(3) + return dev.dump() + + +def main() -> int: + serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" + dev = Device(serial) + app = Wallet(dev) + env = Env.load() + scenarios.fund_wallet(app, env, "EUR:10") + + # Half one: type an amount, then clear it. + screen = open_deposit_amount(dev, app) + fields = screen.editable() + if not fields: + print(f"no amount field: {screen.texts()}") + return 2 + dev.tap_node(fields[0], screen) + dev.type_text("500") # 5.00 + time.sleep(3) + dev.logcat(clear=True) + screen = dev.dump() + reset = screen.find(r"(?i)^Reset$") + if reset is None: + print(f"no Reset button: {screen.texts()}") + return 2 + dev.tap_node(reset, screen) + time.sleep(5) + log = dev.logcat() + zero_sum = [ln for ln in log.splitlines() if "sum zero amounts" in ln] + print(f"internal errors after clearing the amount: {len(zero_sum)}") + if zero_sum: + print(" " + zero_sum[0][-200:]) + + # Half two: deposit exactly the fee. + screen = open_deposit_amount(dev, app) + fields = screen.editable() + dev.tap_node(fields[0], screen) + dev.type_text("1") # 0.01, at or below the deposit fee + time.sleep(2) + screen = dev.dump() + make = screen.find(r"(?i)^Make deposit$") + if make is None: + print(f"no Make deposit button: {screen.texts()}") + return 2 + dev.tap_node(make, screen) + time.sleep(8) + after = dev.dump() + texts = after.texts() + print(f"transaction afterwards: {texts[:10]}") + degenerate = any("0.00" in t for t in texts) and any( + t.startswith("-") or t.startswith("−") for t in texts) + + print(f"\nzero-amount pricing error: {bool(zero_sum)}") + print(f"zero-value deposit created: {degenerate}") + print(f"reproduced: {bool(zero_sum) or degenerate}") + return 0 if (zero_sum or degenerate) else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/wallet-simulator/findings/reset-dialog-puts-the-wipe-where-cancel-belongs.diff b/wallet-simulator/findings/reset-dialog-puts-the-wipe-where-cancel-belongs.diff @@ -0,0 +1,41 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt b/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt +index 5d904900..fd354ce8 100644 +--- a/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt ++++ b/wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt +@@ -295,10 +295,15 @@ fun SettingsScreen( + onClick = { + MaterialAlertDialogBuilder(context) + .setMessage(R.string.settings_dialog_import_message) +- .setNegativeButton(R.string.import_db) { _, _ -> ++ // The affirmative action goes in the positive slot: ++ // MaterialAlertDialogBuilder draws that one on the ++ // right, where this app's other dialogs and the ++ // platform put "continue" -- and the left-hand ++ // button is the one a user taps to back out. ++ .setPositiveButton(R.string.import_db) { _, _ -> + dbImportLauncher.launch(arrayOf("application/json")) + } +- .setPositiveButton(R.string.cancel) { _, _ -> ++ .setNegativeButton(R.string.cancel) { _, _ -> + scope.launch { snackbarHostState.showSnackbar(importCanceledMessage) } + } + .show() +@@ -358,13 +363,16 @@ fun SettingsScreen( + onClick = { + MaterialAlertDialogBuilder(context) + .setMessage(R.string.settings_dialog_reset_message) +- .setNegativeButton(R.string.reset) { _, _ -> ++ // Likewise: wiping the wallet is the affirmative ++ // action, so it belongs on the right rather than ++ // where a dismissive tap lands. ++ .setPositiveButton(R.string.reset) { _, _ -> + settingsManager.clearDb { + model.dangerouslyReset() + } + scope.launch { snackbarHostState.showSnackbar(resetDoneMessage) } + } +- .setPositiveButton(R.string.cancel) { _, _ -> ++ .setNegativeButton(R.string.cancel) { _, _ -> + scope.launch { snackbarHostState.showSnackbar(resetCanceledMessage) } + } + .show() diff --git a/wallet-simulator/findings/reset-dialog-puts-the-wipe-where-cancel-belongs.md b/wallet-simulator/findings/reset-dialog-puts-the-wipe-where-cancel-belongs.md @@ -0,0 +1,125 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# The two dialogs that can destroy a wallet put their button where Cancel belongs + +Found while writing the scenario that confirms a wallet reset — the only thing +that calls `clearDb`, and therefore the only scenario that had ever seen this +dialog's buttons. + +**Severity: moderate.** Nothing is wrong with the reset itself; the danger is +where its button is drawn. A user who dismisses dialogs by tapping the +left-hand button — the position Android has used for "Cancel" since +Holo — destroys their wallet, and the dialog's own text says what that costs: +"you will lose all coins and purchases". + +## What happens + +**Settings → Reset Wallet (dangerous!)** opens + +``` +Do you really want to reset the wallet and lose all coins and purchases? + + [ Reset ] [ Cancel ] +``` + +Measured on a 1080-wide screen, the buttons' centres are + +``` +the reset dialog's buttons, left to right: [('Reset', 642), ('Cancel', 836)] +``` + +so **Reset is the left-hand button and Cancel the right-hand one** — the +opposite of every other confirmation in the app and of the platform +convention, where the rightmost text button is the affirmative one and the +dismissive action sits to its left. + +Tapping Reset does reset: the balance goes to nothing and `clearDb` runs. + +## Why + +The two buttons are assigned the wrong way round: + +```kotlin +// wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt:358 +MaterialAlertDialogBuilder(context) + .setMessage(R.string.settings_dialog_reset_message) + .setNegativeButton(R.string.reset) { _, _ -> // destroys the wallet + settingsManager.clearDb { model.dangerouslyReset() } + … + } + .setPositiveButton(R.string.cancel) { _, _ -> // does nothing + … + } + .show() +``` + +`MaterialAlertDialogBuilder` draws the **positive** button rightmost, so +putting `cancel` there and `reset` in the negative slot swaps them on screen. + +It is not the only one. The app uses `MaterialAlertDialogBuilder` in exactly +two places that matter, and **both** are inverted the same way — the other is +the database import, which is also destructive: + +```kotlin +// wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt:295 + .setMessage(R.string.settings_dialog_import_message) // "This operation + .setNegativeButton(R.string.import_db) { _, _ -> … } // will overwrite + .setPositiveButton(R.string.cancel) { _, _ -> … } // your existing + // database" +``` + +Every *other* confirmation in the app is a Compose `AlertDialog` with +`confirmButton`/`dismissButton` — the bank-account forget dialog, the +transaction delete dialog, the contacts send dialog — and those are right by +construction, because Compose places `confirmButton` on the right. The two +builder-based dialogs are the only ones where the slot has to be chosen by +hand, and both chose wrong. + +## Reproduce by hand + +1. Install a debug build and withdraw something, so there is money to lose. +2. **Settings → Reset Wallet (dangerous!)**. +3. Look at the buttons: **Reset** is on the left, **Cancel** on the right. +4. Tap the left-hand button the way one dismisses a dialog. The wallet is + emptied — balance gone, transactions gone. + +Expected: the destructive action on the right, where this app and the platform +put affirmative actions, so that the reflexive left-hand tap is the safe one. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=0 python3 -u suite.py settings_reset_confirmed +``` + +The scenario reports the two buttons with their x coordinates, confirms +`clearDb` reached wallet-core, and checks that no coins survive. + +## Suggested fix + +Swap them, in both dialogs: + +```kotlin +.setPositiveButton(R.string.reset) { _, _ -> settingsManager.clearDb { … } } +.setNegativeButton(R.string.cancel) { _, _ -> … } +``` + +A dialog that can destroy someone's money is also worth a second gate — the +database exports warn first ("this file holds your money… Export anyway?"), +and the reset is strictly more destructive than an export. diff --git a/wallet-simulator/findings/suspended-looks-like-completed-in-the-list.diff b/wallet-simulator/findings/suspended-looks-like-completed-in-the-list.diff @@ -0,0 +1,40 @@ +diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionsComposable.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionsComposable.kt +index c6a17561..90bcfc33 100644 +--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionsComposable.kt ++++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionsComposable.kt +@@ -85,8 +85,12 @@ import net.taler.wallet.transactions.TransactionMajorState.Aborted + import net.taler.wallet.transactions.TransactionMajorState.Aborting + import net.taler.wallet.transactions.TransactionMajorState.Dialog + import net.taler.wallet.transactions.TransactionMajorState.Done ++import net.taler.wallet.transactions.TransactionMajorState.Expired + import net.taler.wallet.transactions.TransactionMajorState.Failed + import net.taler.wallet.transactions.TransactionMajorState.Pending ++import net.taler.wallet.transactions.TransactionMajorState.Suspended ++import net.taler.wallet.transactions.TransactionMajorState.SuspendedAborting ++import net.taler.wallet.transactions.TransactionMajorState.SuspendedFinalizing + import net.taler.wallet.transactions.TransactionMinorState.BalanceKycRequired + import net.taler.wallet.transactions.TransactionMinorState.BankConfirmTransfer + import net.taler.wallet.transactions.TransactionMinorState.KycAuthRequired +@@ -423,6 +427,22 @@ fun TransactionExtraInfo(tx: Transaction) { + + tx.txState.major == Dialog -> {} + ++ // Suspended and its two compound forms said nothing at all here, so a ++ // suspended transaction looked exactly like a completed one in the ++ // list -- the only difference was on the detail screen. The string ++ // already exists. ++ tx.txState.major == Suspended || ++ tx.txState.major == SuspendedFinalizing || ++ tx.txState.major == SuspendedAborting -> Text( ++ stringResource(R.string.transaction_state_suspended), ++ color = MaterialTheme.colorScheme.error, ++ ) ++ ++ tx.txState.major == Expired -> Text( ++ stringResource(R.string.transaction_state_expired), ++ color = MaterialTheme.colorScheme.error, ++ ) ++ + tx is TransactionWithdrawal && !tx.confirmed -> Text(stringResource(R.string.withdraw_waiting_confirm)) + tx is TransactionPeerPushCredit && tx.info.summary != null -> Text(tx.info.summary) + tx is TransactionPeerPushDebit && tx.info.summary != null -> Text(tx.info.summary) diff --git a/wallet-simulator/findings/suspended-looks-like-completed-in-the-list.md b/wallet-simulator/findings/suspended-looks-like-completed-in-the-list.md @@ -0,0 +1,137 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# A suspended transaction is indistinguishable from a completed one in the list + +Found by the `transaction_states_rendered` scenario, which renders every +transaction state the app has a branch for by feeding the list a canned +wallet-core reply. + +**Severity: low-moderate.** Suspending is an action the app offers on nearly +every transaction, and the transaction list — the screen a user scans to see +what is going on — gives no sign that anything was suspended. For a suspended +withdrawal the row goes further and says "Waiting for confirmation", which is +the opposite of what is happening. + +## What happens + +Six withdrawals, one per state, in the transaction list: + +| state | what the row shows | +| --- | --- | +| `pending` + `kyc` | the "PENDING" chip and "KYC required to proceed" | +| `aborting` | "Aborting" | +| `failed` | "Failed" | +| `done` | nothing, which is right | +| **`suspended`** | **nothing** | +| an unknown future state | nothing | + +The detail screen does say it — "This transaction is suspended" — so the +information is there; it is the row that omits it. + +On a *real* suspension it is worse than an omission. Suspending a withdrawal +that is waiting for the bank gives this: + +``` +its detail screen: ['This transaction is suspended', 'Chosen amount', '€5.00', + 'Fee', '-€0.12', 'Total amount', '€4.88', …] +its row in the list: ['0 min. ago', 'Withdraw', 'Waiting for confirmation', '+4.88'] +``` + +The row says **"Waiting for confirmation"** — i.e. that the wallet is waiting +for the bank — when in fact the transaction is suspended and nothing is +happening until the user resumes it. That comes from the fall-through at the +end of the same `when`: + +```kotlin +tx is TransactionWithdrawal && !tx.confirmed -> Text(stringResource(R.string.withdraw_waiting_confirm)) +``` + +which a suspended, unconfirmed withdrawal reaches because no earlier branch +claimed it. + +## Why + +The row's state line has no branch for `Suspended`, and the "PENDING" chip is +only drawn for `Pending` and `Dialog`: + +```kotlin +// wallet/src/main/java/net/taler/wallet/transactions/TransactionsComposable.kt:382 +if (tx.txState.major == Pending || tx.txState.major == Dialog) { + … Text(stringResource(R.string.transaction_pending)) // the "PENDING" chip +} +… +// …:395 +when { + tx.txState.major == Aborted -> Text(…payment_aborted…) + tx.txState.minor == Repurchase -> … + tx.txState.major == Failed -> Text(…payment_failed…) + tx.txState.major == Aborting -> Text(…payment_aborting…) + tx.txState.major == Pending -> when (tx.txState.minor) { … } + tx.txState.major == Dialog -> {} + … +} +``` + +`Suspended` falls through all of it. The detail screen's own state card +(`TransactionStateComposable`) *does* handle it. + +The same `when` has no branch for a state this version of the app does not +know, and the detail screen's card ends in `else -> return` — so a future +state renders as nothing in both places, although `TransactionState` goes out +of its way to keep the unrecognised name (`majorName`, `minorName`) precisely +so that it could be shown. + +## Reproduce by hand + +No injection needed for the suspended case: + +1. Start a withdrawal and confirm it, so it waits for the bank. +2. On its detail screen tap **Suspend**. The screen says "This transaction is + suspended". +3. Go back to the main screen and look at the row under "Recent + transactions": it shows the time, "Withdraw" and the amount, exactly as a + completed withdrawal does. + +For the unknown-state case, a canned reply is needed (developer mode): + +```bash +# {"transactions":[{… "txState":{"major":"transmogrified","minor":"inside-out"} …}]} +adb shell am start -a android.intent.action.VIEW -d \ + 'taler+http://dev-experiment/api-response?operation=getTransactionsV2&response=<base64url>&count=8' +``` + +`simulator/driver/suite.py`'s `_fake_withdrawal` builds the object; the +scenario below does the encoding. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +SIM_WORKER=4 python3 suite.py transaction_states_rendered # all six states +SIM_WORKER=4 python3 suite.py withdraw_suspend_resume # a real suspension +``` + +The first prints the whole list; the second reports what the suspended +transaction's own row says, which is nothing. + +## Suggested fix + +Add `tx.txState.major == Suspended -> Text(stringResource(R.string.transaction_state_suspended))` +to the row's `when`, before the `!tx.confirmed` fall-through — the string +already exists — and a final `else` that shows the unrecognised state name the +app kept, rather than nothing. diff --git a/wallet-simulator/findings/taldir-protocol-version-mismatch.md b/wallet-simulator/findings/taldir-protocol-version-mismatch.md @@ -0,0 +1,108 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# The wallet and the Taler directory disagree on the protocol version + +Found while deploying a real directory beside the simulator's stack +(`git://git.taler.net/taldir` at `3dca5c1b`, master of 2026-10-18): the wallet +refuses to talk to it at all, before any alias is registered. + +**Severity: low-moderate, and it is an integration fact rather than a bug in +either side.** Both are in development; the point is that today's heads do not +interoperate, and the failure is reported as a generic error. + +## What happens + +The directory's configuration endpoint answers: + +```json +{"version":"0:0:0","name":"taler-directory", + "alias_types":[{"name":"email","challenge_fee":"EUR:0"}],"monthly_fee":"EUR:0"} +``` + +and that version is a literal in the service: + +```go +// taldir, pkg/taldir/taldir.go:694 +cfg := VersionResponse{ + Version: "0:0:0", + Name: "taler-directory", +``` + +The wallet's client declares `1:0:0` and checks compatibility before using the +service: + +```ts +// taler-util/src/http-client/taldir.ts:53 +public static readonly PROTOCOL_VERSION = "1:0:0"; +``` + +```ts +// taler-util/src/operation.ts:166, in carefullyParseConfig +if (!LibtoolVersion.isCompatible(clientVersion, minBody.version)) { + throw TalerError.fromUncheckedDetail({ + code: TalerErrorCode.GENERIC_CLIENT_UNSUPPORTED_PROTOCOL_VERSION, + … + detail: `Unsupported protocol version, client supports ${clientVersion}, server supports ${minBody.version}`, + }); +} +``` + +`1:0:0` against `0:0:0` is incompatible in libtool terms, so `lookupAlias`, +`registerAlias` and `completeRegisterAlias` all fail at the first step. What +reaches the caller is not the version detail but +`WALLET_ALIAS_REGISTRATION_FAILED` with the hint "could not read the +configuration of the directory service" — the specific reason is thrown away +by `taldir.ts`'s own `default:` branch. + +For contrast, the mailbox service gets this right: `taler-mailbox`'s +`Makefile.in` carries `LT_VERSION="1:1:0"` and passes it in at build time, and +`1:0:0` against `1:1:0` is compatible. + +## How it was established + +Deploy the directory and ask it: + +```bash +git clone git://git.taler.net/taldir && cd taldir +GOFLAGS=-mod=vendor go build -o taldir-server ./cmd/taldir-server +./taldir-dbinit -c sim.conf && ./taldir-server -c sim.conf & +curl -s http://127.0.0.1:11001/config +``` + +Then point wallet-core at it (the app cannot be pointed anywhere, see +[`alias-registration-hardcodes-the-directory.md`](alias-registration-hardcodes-the-directory.md)): + +```bash +taler-wallet-cli --wallet-db /tmp/w.sqlite3 advanced api lookupAlias \ + '{"alias":"sim@example.com","aliasType":"email","taldirBaseUrl":"http://127.0.0.1:11001/"}' +``` + +With the service as it ships, that fails. With one character changed in +`taldir.go` (`0:0:0` → `1:0:0`) the whole flow — register, challenge, +complete, look up — works on the first attempt. + +## Suggested fix + +Whichever side is wrong about the number, two things would have helped: + +* taldir should take its protocol version from `LT_VERSION` at build time, the + way `taler-mailbox` does, rather than hard-coding it in the handler; +* `taldir.ts` should pass the configuration error through instead of replacing + it: its `default:` branch turns a precise + `GENERIC_CLIENT_UNSUPPORTED_PROTOCOL_VERSION` ("client supports 1:0:0, + server supports 0:0:0") into "could not read the configuration of the + directory service", which is what an operator would have to debug from. diff --git a/wallet-simulator/findings/unknown-wire-method-hangs-the-deposit-form.md b/wallet-simulator/findings/unknown-wire-method-hangs-the-deposit-form.md @@ -0,0 +1,166 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# An unknown wire method hangs the add-account form for ever + +Found by the `deposit_methods` scenario in round 12, the first round after the +simulator's exchange was given a `payto://cyclos/…` account: the add-account +form came up empty and stayed that way. + +**Severity: moderate.** Any exchange that advertises a wire method this version +of the app does not know breaks the deposit account form for every wallet of +that version — and `cyclos` is not hypothetical, the app has a Cyclos +*transfer* screen already. The failure mode is a spinner with no message. + +## What happens + +Settings → **Bank accounts** → **Add account** shows only the app bar: + +``` +['Go back', 'Add account', 'Internal event log'] +``` + +no fields, no tabs, no error — the form's `LoadingScreen`, for ever. The log +says why: + +``` +E taler-wallet: Error getDepositWireTypes TalerErrorInfo(code=NONE, hint=, + message=kotlinx.serialization.SerializationException: + net.taler.wallet.deposit.WireType does not contain element with name 'cyclos', + extra={}, rawCode=0) +``` + +One unrecognised method makes the whole reply undecodable, so the app has no +wire types at all, and `AddBankAccountScreen` shows `LoadingScreen` while +`depositWireTypes == null`: + +```kotlin +// wallet/src/main/java/net/taler/wallet/accounts/AddBankAccountScreen.kt:63 +LaunchedEffect(Unit) { depositWireTypes = depositManager.getDepositWireTypes() } +… +if (depositWireTypes == null || (bankAccountId != null && bankAccount == null)) { + LoadingScreen(Modifier.padding(paddingValues)) +} +``` + +and `getDepositWireTypes` returns `null` on error, logging it and nothing else +(the same shape as +[`a-failed-query-is-shown-as-an-empty-wallet.md`](a-failed-query-is-shown-as-an-empty-wallet.md), +with a spinner instead of an empty list). + +## Why the fallback does not fire + +The enum already has the member it needs: + +```kotlin +// wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt:296 +@Serializable +enum class WireType { + Unknown, + @SerialName("iban") IBAN, + @SerialName("x-taler-bank") TalerBank, + @SerialName("bitcoin") Bitcoin, +} +``` + +and `BackendManager.json` is built with `coerceInputValues = true`, which is +exactly the switch for "coerce an unrecognised value to the default". But +kotlinx only coerces to a declared *default value* (or to null for a nullable +property), and the property has neither: + +```kotlin +// …/DepositManager.kt:311 +val paymentTargetType: WireType, +``` + +So `Unknown` is unreachable, and the decode throws. + +**Two more enums have the same shape**, each with an `Unknown` member that can +never be used: + +- `WithdrawalOperationStatusFlag` — `withdraw/WithdrawManager.kt:184`, + `val status: WithdrawalOperationStatusFlag` (an unknown status from the bank + would break the withdrawal status reply); +- `ExchangeTosStatus` — `exchanges/Exchanges.kt:38`, `val tosStatus: + ExchangeTosStatus` (an unknown terms status would break the exchange list). + +`InsufficientBalanceHint` is used only through nullable properties, where +`coerceInputValues` does fire, so that one is safe. + +## Reproduce by hand + +Give any exchange a wire method the app does not know — `cyclos` will do, and +the wire fee matters because wallet-core hides a method that has none: + +```bash +taler-exchange-offline -c <conf> \ + enable-account 'payto://cyclos/cyclos.example.com/exchange?receiver-name=Test' upload +taler-exchange-offline -c <conf> \ + wire-fee now cyclos EUR:0.01 EUR:0.01 upload +``` + +Then in the wallet: + +1. Settings → **Bank accounts** → **Add account**. +2. The screen stays empty. `adb logcat | grep getDepositWireTypes` shows the + `SerializationException`. +3. The same happens on the **Deposit** flow's account form. + +The simulator can do this for you, but not by default: keeping a Cyclos +address signed blocks every deposit scenario, so it is opt-in — + +```bash +SIM_EXTRA_PAYTOS='payto://cyclos/cyclos.example.com/exchange?receiver-name=X' \ + backend/stack.sh start +``` + +(it was signed by default for one round, which is how this was found). + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/backend +SIM_EXTRA_PAYTOS='payto://cyclos/cyclos.example.com/exchange?receiver-name=X' \ + ./stack.sh start # sign a method the app does not know +cd ../driver && python3 stack.py # re-provision after the restart +python3 ../findings/repro_unknown_wire_method.py # worker 0 by default +``` + +The reproducer waits twenty seconds on the form and then reports both what is +on it and the `SerializationException` from the log. Restart the stack without +`SIM_EXTRA_PAYTOS` afterwards to get the deposit scenarios working again. + +## Suggested fix + +Give each of the three properties the default its enum was written for: + +```kotlin +val paymentTargetType: WireType = WireType.Unknown, +``` + +With `coerceInputValues = true` already set, that is enough to make an +unrecognised method decode as `Unknown` instead of throwing; the UI then needs +to skip `Unknown` entries when listing tabs (`AddAccountComposable` already +has an `else -> {}` branch for them) rather than showing nothing at all. + +Separately: `getDepositWireTypes` returning `null` for both "no answer yet" +and "the answer did not parse" is what turns the failure into an endless +spinner. An error state would make this visible even when the next unknown +method arrives. + +Worth adding `cyclos` to `WireType` as well — the app renders a Cyclos +transfer screen, so it already knows the method exists. diff --git a/wallet-simulator/findings/unreachable-host-leaves-blank-retrying-purchase.diff b/wallet-simulator/findings/unreachable-host-leaves-blank-retrying-purchase.diff @@ -0,0 +1,21 @@ +diff --git a/wallet/src/main/res/xml/network_security_config.xml b/wallet/src/main/res/xml/network_security_config.xml +index de61259a..546a817f 100644 +--- a/wallet/src/main/res/xml/network_security_config.xml ++++ b/wallet/src/main/res/xml/network_security_config.xml +@@ -1,6 +1,16 @@ + <?xml version="1.0" encoding="utf-8"?> + <network-security-config> ++ <!-- ++ 127.0.0.1 and ::1 are the same machine as "localhost", but the platform ++ matches this by name: a developer pointing the wallet at ++ http://127.0.0.1:8081/ got UnknownServiceException ("CLEARTEXT ++ communication to 127.0.0.1 not permitted by network security policy"), ++ which wallet-core retries for ever because it looks like a transient ++ network failure. ++ --> + <domain-config cleartextTrafficPermitted="true"> + <domain includeSubdomains="true">localhost</domain> ++ <domain includeSubdomains="false">127.0.0.1</domain> ++ <domain includeSubdomains="false">::1</domain> + </domain-config> + </network-security-config> diff --git a/wallet-simulator/findings/unreachable-host-leaves-blank-retrying-purchase.md b/wallet-simulator/findings/unreachable-host-leaves-blank-retrying-purchase.md @@ -0,0 +1,188 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# A prompt the app cannot prepare shows an empty screen and retries for ever + +Found by random exploration (seeds 31 and 33, from the hostile-URI corpus) and +reproduced deliberately. + +**Severity: moderate.** The original trigger was a URI the wallet cannot reach +— a stale QR code, a typo, a developer pointing the wallet at `127.0.0.1` — +and what the user gets is a screen with nothing on it and a transaction that +never stops trying. Fault injection then showed the same empty screen for +eleven unrelated failures of the exchange, including ones that look like an +attack, and that it does not recover when the failure goes away. + +## What happens + +Sharing `taler+http://pay/127.0.0.1:8080/instances/sim/AAAA…/` into the wallet: + +* the purchase screen opens with **no content at all** — the only labels are + "Purchase", "Go back" and the developer-mode log button; +* the request is refused by the platform, 32 times in the first ten seconds: + + ``` + D taler-wallet: java.net.UnknownServiceException: CLEARTEXT communication to + 127.0.0.1 not permitted by network security policy + ``` + +* wallet-core records it as a retried operation and keeps going — the retry + counter was still climbing (7 → 8 → …) a minute later, and in the + exploration runs it reached 12. + +`[::1]` behaves identically. The refusal is permanent: the app's +`res/xml/network_security_config.xml` permits cleartext for the name +`localhost` only, so no number of retries will ever make `127.0.0.1` or `::1` +work. + +## Reproduce by hand + +1. Install a debug build and enable **Developer mode** (needed for + `taler+http://`; an `https://` URI to an unreachable host shows the same + empty screen without it). +2. Run `adb logcat | grep -E "CLEARTEXT|taler-wallet"`. +3. Share the URI into the wallet: + + ```bash + adb shell am start -a android.intent.action.SEND -t text/plain \ + -n net.taler.wallet.fdroid.debug/net.taler.wallet.main.MainActivity \ + --es android.intent.extra.TEXT \ + 'taler+http://pay/127.0.0.1:8080/instances/sim/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/' + ``` + +4. The wallet opens an empty "Purchase" screen. The log fills with cleartext + refusals, and they keep coming. + +Expected: the screen says what went wrong, and a refusal the platform will +never allow is not retried. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_unreachable_host_zombie_purchase.py +``` + +## The empty prompt is not specific to this cause + +Fault injection showed the same screen for every way of spoiling the +exchange's replies. With `taler-twister` in front of the exchange, a +withdrawal whose preparation fails renders as + +``` +['Go back', 'Withdraw UNKNOWN', 'Internal event log'] +``` + +— no amount, no error, and "UNKNOWN" where the currency belongs. That held for +a truncated response, HTTP 500, 404, 403 and 502, a wrong content type, and +for structural damage (a deleted `denoms`, a deleted signature, a flipped +master public key, a rewritten version or currency). + +In that run the wallet was in fact refusing for a different reason — +`WALLET_EXCHANGE_BASE_URL_MISMATCH` (7030), logged six times — which makes the +point more sharply: the wallet detected a problem and told the user nothing. +A prompt with no error state looks the same whatever went wrong. + +A later fault-injection run put a number on "whatever went wrong". With +`taler-twister` between the wallet and the exchange, kept armed for the whole +withdrawal, **eleven different faults all produced the same screen**: + +``` +['Go back', 'Withdraw UNKNOWN', 'Internal event log'] +``` + +a truncated response, HTTP 500, 404, 403 and 502, a response with the wrong +content type, a `/keys` with its denomination list deleted, with a flipped +master public key, with a forged denomination signature, with no wire fees, and +with an impossible protocol version. The withdrawal prompt is empty in all +eleven cases, and the title reads "Withdraw UNKNOWN" — the placeholder +currency, because the wallet has no exchange configuration to take a currency +from. + +Two things make this worse than the original observation: + +* **It does not recover.** The run disarmed each fault and waited; the screen + was still `['Go back', 'Withdraw UNKNOWN', 'Internal event log']` afterwards + for every fault that damaged `/keys`. There is nothing on the screen to + retry with, so a withdrawal interrupted by a bad reply is lost even once the + exchange is healthy again. +* **The same screen means "your exchange is lying to you".** A forged + denomination signature and a flipped master public key are what an attack + looks like, and the wallet shows the same blank page it shows for a + typo. + +## Why + +Two separate things meet here. + +* **The screen renders nothing while it has nothing.** `PromptPayment` is + waiting for contract terms that will never arrive, and there is no state for + "still fetching" or "could not fetch" — so the user is left looking at an + empty page rather than a spinner or an error. +* **A policy refusal looks like a network blip.** `UnknownServiceException` + reaches wallet-core as a generic HTTP failure (code 7003), which is retried + with backoff like any transient error. It is not transient: the cleartext + policy is fixed at build time. + +## The cheapest reproduction of the empty prompt + +No proxy needed at all: one injected error does it. With developer mode on, + +```bash +adb shell am start -a android.intent.action.VIEW -d \ + 'taler+http://dev-experiment/api-error?operation=getWithdrawalDetailsForAmount&detail=eyJjb2RlIjogNzAwMSwgImhpbnQiOiAiaW5qZWN0ZWQifQ&count=4' +``` + +then tapping **Withdraw** gives +`['Go back', 'Withdraw from bank', 'Internal event log']` — the same empty +screen, from a single failed call. This is one of the screens +[`a-failed-query-is-shown-as-an-empty-wallet.md`](a-failed-query-is-shown-as-an-empty-wallet.md) +sweeps. + +## Reproduce with fault injection + +No manual reproduction for this half: it needs a proxy between the wallet and +the exchange. + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +./phase.sh sim-twister.conf twister_withdraw_faults twister_field_faults +``` + +The phase swaps in `backend/sim-twister.conf` (the exchange behind +`taler-twister` on port 8088), runs the scenarios and restores the ordinary +stack. Each scenario's notes list what every fault produced, and how many +times the fault was re-armed — a fault is one-shot, so it has to be re-armed +continuously or it lands on an unrelated poll instead of on the request under +test. + +## Suggested fix + +Give the payment and withdrawal prompts something to show while they are +loading, and an error state when the load fails — the error sheet used +elsewhere would do. The withdrawal prompt additionally needs a title that does +not say "UNKNOWN" when it has no currency yet, and a way to try again. + +For the retries, treat `UnknownServiceException` (and the cleartext refusal in +particular) as permanent in `NetworkInterface`, so the transaction fails with +an explanation instead of looping. A user-visible "this address cannot be +reached over plain HTTP" is far more useful than silence. + +Worth considering separately: `network_security_config.xml` permits cleartext +for the name `localhost` but not for `127.0.0.1` or `::1`, which are the same +machine. Adding both would save developers this exact confusion. diff --git a/wallet-simulator/findings/wallet-lock-opens-when-the-credential-is-gone.md b/wallet-simulator/findings/wallet-lock-opens-when-the-credential-is-gone.md @@ -0,0 +1,112 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# "Protect access to wallet" opens the wallet when the device credential is gone + +Found by the `wallet_lock_without_credential` scenario, written to see what a +locked wallet does when the screen lock it depends on is taken away. + +**Severity: moderate, security-relevant, release builds.** The lock screen +still appears, so the user has every reason to believe the wallet is +protected, and it opens on a single tap with no authentication of any kind. + +## What happens + +1. With a device credential set (a PIN is enough), Settings → **Protect + access to wallet** can be switched on. The app checks that the device can + authenticate before allowing this (`enableBiometrics` in + `settings/SettingsScreen.kt` requires `BIOMETRIC_SUCCESS`). +2. Restarting the app now covers it with `BiometricOverlay`: a shield and a + single **Tap to unlock** button. +3. The user later removes their screen lock — Settings → Security → screen + lock → None, which is an ordinary thing to do and needs the credential + they still have. +4. The wallet still shows the lock screen on every start. **Tapping "Tap to + unlock" opens it**, with no prompt, no credential, nothing. + +Measured, on a device whose credential was removed after the lock was +switched on: + +``` +after a restart with a credential: locked=True +cleared the device credential +after a restart with no credential: locked=True +after tapping unlock: still locked=False <- wallet open +``` + +The code says so plainly: + +```kotlin +// wallet/src/main/java/net/taler/wallet/main/MainActivity.kt:281 +override fun onAuthenticationError(errorCode: Int, errString: CharSequence) { + super.onAuthenticationError(errorCode, errString) + if (errorCode == ERROR_NO_BIOMETRICS || errorCode == ERROR_NO_DEVICE_CREDENTIAL) { + model.unlockWallet() + } + Toast.makeText(this@MainActivity, getString(R.string.biometric_auth_error, errString), LENGTH_SHORT).show() +} +``` + +Unlocking on `ERROR_NO_BIOMETRICS` / `ERROR_NO_DEVICE_CREDENTIAL` is +presumably there so that nobody is locked out of their own money — which is a +real concern, since the only other way back in is clearing the app's data, +and that destroys the coins. But as written, the protection disappears +silently: the preference stays on, the overlay keeps appearing, and anyone +holding the phone gets in. + +## Reproduce by hand + +On a device or emulator with a screen lock: + +1. Settings → **Protect access to wallet** → on. (The switch refuses if the + device has no credential; that part is correct.) +2. Close and reopen the wallet: the shield screen appears, and unlocking asks + for the PIN or fingerprint. +3. In the *system* settings, remove the screen lock (Security → Screen lock → + None). +4. Reopen the wallet. The shield screen appears as before. Tap **Tap to + unlock**: the wallet opens immediately, showing the balance, with no + authentication. + +On an emulator the same thing without touching the system UI: + +```bash +adb shell locksettings set-pin 1234 # before step 1 +adb shell locksettings clear --old 1234 # instead of step 3 +``` + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_wallet_lock_bypass.py # worker 0 +SIM_WORKER=4 SIM_DESTRUCTIVE=1 python3 suite.py wallet_lock_without_credential +``` + +The scenario sets a PIN, switches the lock on, clears the PIN, restarts the +app and reports `locked=` at each step. It clears the device credential again +whatever happens, because the setting is device-wide. + +## Suggested fix + +Do not treat "this device cannot authenticate" as "this user is +authenticated". When the overlay finds that `canAuthenticate()` no longer +returns `BIOMETRIC_SUCCESS`, say so on the overlay and offer to turn the +protection off explicitly — a deliberate act by the user, which also clears +the preference, instead of a silent unlock that leaves the switch on. The +escape hatch stays (nobody is locked out), but the user is told that the +protection is gone and the UI stops claiming otherwise. diff --git a/wallet-simulator/findings/word-currency-symbol-glued-to-amount.md b/wallet-simulator/findings/word-currency-symbol-glued-to-amount.md @@ -0,0 +1,125 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# A word-shaped currency symbol is glued to the amount: "UNKNOWN0.00" + +Found while testing QR scanning: a code pointing at an order that does not +exist leaves a failed purchase in the history whose amounts read +**`UNKNOWN0.00`**. + +**Severity: low (cosmetic), and it is not limited to the UNKNOWN placeholder.** +The same run showed a real payment prompt reading **`Total: EUR1.00`**, because +the contract's currency specification gives `alt_unit_names[0] = "EUR"` rather +than a sign. Any currency whose first alternative unit name is a word — a +regional currency called `KUDOS`, or `EUR` as served by a backend that +publishes no symbol — renders this way. + +## What happens + +A purchase whose contract could not be downloaded: + +``` +This transaction has failed or been abandoned +Total UNKNOWN0.00 +Paid UNKNOWN0.00 +``` + +And an ordinary payment prompt, against a merchant whose currency +specification carries no symbol: + +``` +Simulator Shop +Review order +QR scanned order +Total: EUR1.00 +``` + +wallet-core reports the amounts of a purchase whose contract it could not +download with its placeholder currency: + +```json +"amountRaw":"UNKNOWN:0", "amountEffective":"UNKNOWN:0", +"currencySpecification":{"name":"UNKNOWN", … ,"alt_unit_names":{"0":"UNKNOWN"}} +``` + +## Reproduce by hand + +1. Install a debug build and enable **Developer mode** in Settings. +2. Share a `taler+http://pay/…` URI for an order id that does not exist into + the wallet — scan it as a QR code, or share it as text. Against the + simulator's stack: + `taler+http://pay/localhost:8080/instances/sim/NOSUCHORDER12345/` + (Any deployment works; the point is that the merchant has no such order.) +3. The wallet opens a transaction that failed, with "Total" and "Paid" shown + as `UNKNOWN0.00`. + +Expected: a separator, as in `0.00 UNKNOWN`, which is what the same formatter +produces when there is no currency specification at all. + +## Reproduce with the simulator + +```bash +ssh root@tripwire.taler.net +cd /opt/taler-sim/driver +python3 ../findings/repro_unknown_currency_formatting.py +``` + +## Why + +`CurrencySpecification.symbol` is defined as the first alternative unit name +(`taler-kotlin-android/.../CurrencySpecification.kt:37`): + +```kotlin +val symbol: String? get() = altUnitNames[0] +``` + +`Amount.toString()` then hands that to a currency formatter +(`Amount.kt:272`): + +```kotlin +val format = NumberFormat.getCurrencyInstance() +s.currencySymbol = spec.symbol ?: "" +… +return if (spec.symbol != null) fmt else "$fmt $currency" +``` + +`NumberFormat.getCurrencyInstance()` places the symbol immediately before the +number in most locales, which is right for `€` or `$` and wrong for a word. +The branch that already formats as `"$fmt $currency"` is only taken when there +is no symbol at all. + +The existing unit test covers a one-character symbol (`"ク"`), so the word case +is untested. + +## Suggested fix + +Use the currency-instance layout only for a sign-shaped symbol, and fall back +to the spaced form otherwise, e.g. in `Amount.toString()`: + +```kotlin +val sign = spec.symbol?.takeIf { it.length <= 2 && !it.any(Char::isLetter) } +… +return if (sign != null) fmt else "$fmt ${spec.symbol ?: currency}".trim() +``` + +An `AmountTest` case with `symbol = "KUDOS"` would pin it. + +## Also worth deciding + +The wallet records a *failed purchase transaction* for a URI that pointed at +nothing, so a mistyped or stale QR code leaves a permanent entry in the +history. Reporting the failure without keeping a transaction may be the better +behaviour; that is a product decision rather than a defect. diff --git a/wallet-simulator/tls/README.md b/wallet-simulator/tls/README.md @@ -0,0 +1,85 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# Answering for the names the app hard-codes + +Two service URLs are literals in the wallet: + +* `https://taldir.gnunet.org` — the Taler directory, in two files, with no way + to change it (`findings/alias-registration-hardcodes-the-directory.md`); +* `https://mailbox.gnunet.org` — the mailbox default, which the UI *can* + override, so this only saves typing. + +To exercise those code paths as they ship, two separate things are needed: the +device has to *resolve* the names to something local, and the app has to +*trust* what answers. Neither one changes a URL the app under test uses. + +Trust is the easy half, and it belongs in the APK: the `sim` build type — which +exists for the simulator and is never published — carries the CA as an extra +trust anchor in `wallet/src/sim/res/xml/network_security_config.xml`, alongside +the system store and with src/main's cleartext policy unchanged. The private +key stays on the host running the stack, so the committed certificate on its +own authorises nobody. + +```bash +# once, on the host +openssl req -x509 -newkey rsa:2048 -nodes -keyout ca.key -out ca.crt -days 3650 \ + -subj "/CN=Taler wallet simulator CA" \ + -addext "basicConstraints=critical,CA:TRUE" -addext "keyUsage=critical,keyCertSign,cRLSign" +openssl req -newkey rsa:2048 -nodes -keyout srv.key -out srv.csr -subj "/CN=taldir.gnunet.org" +printf 'subjectAltName=DNS:taldir.gnunet.org,DNS:mailbox.gnunet.org\nextendedKeyUsage=serverAuth\n' > srv.ext +openssl x509 -req -in srv.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out srv.crt -days 3650 -extfile srv.ext + +# regenerating the CA means rebuilding the APK that trusts it +cp ca.crt ../../wallet/src/sim/res/raw/sim_ca.crt + +GOTOOLCHAIN=local go build -o tlsproxy . # this directory +./tlsproxy & # 127.0.0.1:8443, routes by Host + +# per emulator +../emu/tls-names.sh 4 +``` + +`tls-names.sh` does the resolving half: it roots that one emulator (a root adbd +is what makes a privileged listening port possible), bind-mounts a hosts file +carrying `127.0.0.1 taldir.gnunet.org mailbox.gnunet.org` over +`/system/etc/hosts`, and forwards the device's port 443 to the host's 8443. + +It is undone by rebooting or wiping the emulator, so re-run it after one. The +scenarios that need it (`alias_registration_real`) check for the port-443 +mapping and skip with a note when it is absent, rather than measuring the +refusal. + +## Why the trust anchor is not installed on the device + +That was tried first, and it is a trap worth recording. + +* There are **two** system stores on these images — + `/apex/com.android.conscrypt/cacerts` and `/system/etc/security/cacerts`, + which is a real directory and not a symlink into the APEX — and the app reads + the second one. +* Both are read-only, so each has to be replaced by a `tmpfs` holding a copy of + the originals plus ours. A mount made from `adbd` is **invisible to app + processes**, because APEX paths live in a mount namespace of their own; it has + to be made inside init's namespace (`nsenter --mount=/proc/1/ns/mnt`). +* Zygote has already forked by then, so the framework has to be restarted + (`stop && start`) for apps to see the store at all. That leaves the network at + `PARTIAL_CONNECTIVITY` for a while, and a wallet on such a network refuses + everything with "This action requires internet connection" — which looks + exactly like a wallet bug. + +All of that for a file the build system can simply put in the APK, in a build +type that never ships. diff --git a/wallet-simulator/tls/go.mod b/wallet-simulator/tls/go.mod @@ -0,0 +1,3 @@ +module tlsproxy + +go 1.21 diff --git a/wallet-simulator/tls/tlsproxy.go b/wallet-simulator/tls/tlsproxy.go @@ -0,0 +1,67 @@ +// A TLS front end for the simulator's local services. +// +// The wallet hard-codes https://taldir.gnunet.org for the directory and +// https://mailbox.gnunet.org as the mailbox default, so the only way to +// exercise those code paths is to answer for those names: this listens with a +// certificate for both and forwards by Host header to the plain-HTTP service +// behind. The app is not modified; the device is told the names resolve here. +package main + +import ( + "crypto/tls" + "flag" + "log" + "net/http" + "net/http/httputil" + "net/url" + "strings" +) + +func proxyTo(target string) *httputil.ReverseProxy { + u, err := url.Parse(target) + if err != nil { + log.Fatalf("bad target %q: %v", target, err) + } + p := httputil.NewSingleHostReverseProxy(u) + p.Director = func(r *http.Request) { + r.URL.Scheme = u.Scheme + r.URL.Host = u.Host + r.Host = u.Host + } + return p +} + +func main() { + listen := flag.String("listen", "127.0.0.1:8443", "address to listen on") + taldir := flag.String("taldir", "http://127.0.0.1:11001", "directory service") + mailbox := flag.String("mailbox", "http://127.0.0.1:11000", "mailbox service") + cert := flag.String("cert", "srv.crt", "server certificate") + key := flag.String("key", "srv.key", "server key") + flag.Parse() + + routes := map[string]*httputil.ReverseProxy{ + "taldir.gnunet.org": proxyTo(*taldir), + "mailbox.gnunet.org": proxyTo(*mailbox), + } + mux := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + host := r.Host + if i := strings.IndexByte(host, ':'); i >= 0 { + host = host[:i] + } + p, ok := routes[host] + if !ok { + log.Printf("no route for %q (%s)", host, r.URL.Path) + http.Error(w, "no route for "+host, http.StatusNotFound) + return + } + log.Printf("%s %s%s", r.Method, host, r.URL.Path) + p.ServeHTTP(w, r) + }) + srv := &http.Server{ + Addr: *listen, + Handler: mux, + TLSConfig: &tls.Config{MinVersion: tls.VersionTLS12}, + } + log.Printf("TLS front end on %s: taldir=%s mailbox=%s", *listen, *taldir, *mailbox) + log.Fatal(srv.ListenAndServeTLS(*cert, *key)) +} diff --git a/wallet/build.gradle b/wallet/build.gradle @@ -46,6 +46,11 @@ android { versionName "1.6.9" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } + // The androidTest variant is only created for the testBuildType, and + // enableAndroidTestCoverage only instruments the app's classes when such a + // variant exists -- so the simulator's build type has to be the one. + // Nothing else in the repo has instrumented tests, so this costs nothing. + testBuildType "sim" buildTypes { release { minifyEnabled true @@ -60,6 +65,17 @@ android { // tests are not run. enableUnitTestCoverage true } + // Build type for simulator/, the emulator-driven exploration harness. + // Same application id as debug (so the simulator drives the same + // package a developer would install), plus JaCoCo instrumentation and + // the debug-only hooks in src/sim. Never published. + sim { + initWith debug + signingConfig signingConfigs.debug + minifyEnabled false + enableAndroidTestCoverage true + matchingFallbacks = ['debug'] + } } flavorDimensions = ["distributionChannel"] productFlavors { @@ -184,6 +200,14 @@ dependencies { testImplementation "junit:junit:$junit_version" testImplementation 'org.json:json:20251224' + + // Only the "sim" build type has instrumented tests; see + // src/androidTestSim and simulator/README.md. They exist so that AGP + // creates an androidTest variant, which is what makes + // enableAndroidTestCoverage instrument the app's classes. + androidTestSimImplementation "junit:junit:$junit_version" + androidTestSimImplementation "androidx.test:runner:1.7.0" + androidTestSimImplementation "androidx.test.ext:junit:1.3.0" } tasks.withType(KotlinCompile).configureEach { diff --git a/wallet/src/androidTestSim/java/net/taler/wallet/sim/SimCoverageAnchorTest.kt b/wallet/src/androidTestSim/java/net/taler/wallet/sim/SimCoverageAnchorTest.kt @@ -0,0 +1,43 @@ +/* + * This file is part of GNU Taler + * (C) 2026 Taler Systems S.A. + * + * GNU Taler is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 3, or (at your option) any later version. + * + * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +package net.taler.wallet.sim + +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals +import org.junit.Test + +/** + * Exists so that the "sim" build type has an androidTest variant. + * + * `enableAndroidTestCoverage` only instruments the app's classes when such a + * variant exists; without any instrumented test source, AGP creates no + * androidTest variant, no JaCoCo instrumentation and no coverage tasks, and + * the agent in the APK then reports an empty session. The simulator drives + * the app from outside and never runs this test — it only needs the + * instrumented APK that building it produces. + * + * This source set belongs to the sim build type alone, so debug and release + * builds are unaffected. + */ +class SimCoverageAnchorTest { + + @Test + fun theAppUnderTestIsTheWallet() { + val context = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("net.taler.wallet.fdroid.debug", context.packageName) + } +} diff --git a/wallet/src/sim/AndroidManifest.xml b/wallet/src/sim/AndroidManifest.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="utf-8"?><!-- + ~ This file is part of GNU Taler + ~ (C) 2026 Taler Systems S.A. + ~ + ~ GNU Taler is free software; you can redistribute it and/or modify it under the + ~ terms of the GNU General Public License as published by the Free Software + ~ Foundation; either version 3, or (at your option) any later version. + ~ + ~ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + ~ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + ~ A PARTICULAR PURPOSE. See the GNU General Public License for more details. + ~ + ~ You should have received a copy of the GNU General Public License along with + ~ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + --> + +<!-- Hooks for the "sim" build type only: this manifest is not part of any + published variant. --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android"> + + <application> + <receiver + android:name="net.taler.wallet.sim.SimHooks" + android:exported="true"> + <intent-filter> + <action android:name="net.taler.wallet.sim.DUMP_COVERAGE" /> + <action android:name="net.taler.wallet.sim.SEND_NDEF" /> + <action android:name="net.taler.wallet.sim.SET_CLIPBOARD" /> + </intent-filter> + </receiver> + </application> + +</manifest> diff --git a/wallet/src/sim/java/net/taler/wallet/sim/SimHooks.kt b/wallet/src/sim/java/net/taler/wallet/sim/SimHooks.kt @@ -0,0 +1,137 @@ +/* + * This file is part of GNU Taler + * (C) 2026 Taler Systems S.A. + * + * GNU Taler is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 3, or (at your option) any later version. + * + * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +package net.taler.wallet.sim + +import android.content.BroadcastReceiver +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.nfc.NdefMessage +import android.nfc.NdefRecord +import android.nfc.NfcAdapter +import android.util.Log +import java.io.File + +/** + * The two things the simulator cannot do from outside the app. + * + * Everything else it needs — wiping data, sharing a URI in, reading the view + * hierarchy, reading wallet-core's log — is already reachable over adb, so it + * stays out of here. This receiver exists only in the "sim" build type. + * + * Coverage: + * + * adb shell am broadcast -a net.taler.wallet.sim.DUMP_COVERAGE \ + * -n net.taler.wallet.fdroid.debug/net.taler.wallet.sim.SimHooks + * adb exec-out run-as net.taler.wallet.fdroid.debug cat files/coverage.ec > ep.ec + * + * Clipboard, for text "input text" cannot type at all (it maps characters + * through a KeyCharacterMap and throws on anything non-ASCII): + * + * adb shell am broadcast -a net.taler.wallet.sim.SET_CLIPBOARD \ + * -n net.taler.wallet.fdroid.debug/net.taler.wallet.sim.SimHooks \ + * --es text '日本語' + * adb shell input keyevent KEYCODE_PASTE + * + * NDEF (the tap-to-pay entry point, which has no adb equivalent because the + * extra is a Parcelable): + * + * adb shell am broadcast -a net.taler.wallet.sim.SEND_NDEF \ + * -n net.taler.wallet.fdroid.debug/net.taler.wallet.sim.SimHooks \ + * --es uri 'taler+http://pay/localhost:8080/...' + */ +class SimHooks : BroadcastReceiver() { + + override fun onReceive(context: Context, intent: Intent) { + when (intent.action) { + ACTION_DUMP_COVERAGE -> dumpCoverage(context, intent.getStringExtra("file")) + ACTION_SEND_NDEF -> sendNdef(context, intent.getStringExtra("uri")) + ACTION_SET_CLIPBOARD -> setClipboard(context, intent.getStringExtra("text")) + else -> Log.w(TAG, "ignoring ${intent.action}") + } + } + + /** + * Ask the JaCoCo runtime for the data collected so far and write it next to + * the app's files, where "run-as <pkg> cat" can reach it. Reflection keeps + * this compiling in build types without the agent on the classpath. + */ + private fun dumpCoverage(context: Context, name: String?) { + val out = File(context.filesDir, name ?: "coverage.ec") + try { + val rt = Class.forName("org.jacoco.agent.rt.RT") + val agent = rt.getMethod("getAgent").invoke(null) + val data = agent.javaClass + .getMethod("getExecutionData", Boolean::class.javaPrimitiveType) + .invoke(agent, false) as ByteArray + out.writeBytes(data) + Log.i(TAG, "coverage: ${data.size} bytes to ${out.absolutePath}") + } catch (e: Throwable) { + // A missing agent is a build configuration problem, so say so + // loudly rather than silently producing no coverage. + Log.e(TAG, "no JaCoCo agent: is enableAndroidTestCoverage set?", e) + } + } + + /** + * Put text on the clipboard so the driver can paste it into a field. + * + * Only the foreground app may write the clipboard on Android 10 and later, + * which is fine here: the simulator pastes into the screen it is looking + * at. + */ + private fun setClipboard(context: Context, text: String?) { + if (text == null) { + Log.w(TAG, "SET_CLIPBOARD without text") + return + } + val manager = context.getSystemService(ClipboardManager::class.java) + manager.setPrimaryClip(ClipData.newPlainText("taler-sim", text)) + Log.i(TAG, "clipboard set to ${text.length} chars") + } + + /** + * Deliver a URI the way a tapped NFC tag would, which is the one wallet + * entry point that cannot be reached with "am start" alone. + */ + private fun sendNdef(context: Context, uri: String?) { + if (uri == null) { + Log.w(TAG, "SEND_NDEF without a uri") + return + } + val message = NdefMessage(arrayOf(NdefRecord.createUri(uri))) + val intent = Intent(NfcAdapter.ACTION_NDEF_DISCOVERED).apply { + setClassName(context, "net.taler.wallet.main.MainActivity") + // MainActivity prefers intent.data and only falls back to the NDEF + // records when it is absent, so both paths are worth exercising; + // this one leaves the data unset on purpose. + putExtra(NfcAdapter.EXTRA_NDEF_MESSAGES, arrayOf(message)) + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + } + context.startActivity(intent) + Log.i(TAG, "dispatched NDEF ${Uri.parse(uri).scheme} URI") + } + + companion object { + private const val TAG = "SimHooks" + const val ACTION_DUMP_COVERAGE = "net.taler.wallet.sim.DUMP_COVERAGE" + const val ACTION_SEND_NDEF = "net.taler.wallet.sim.SEND_NDEF" + const val ACTION_SET_CLIPBOARD = "net.taler.wallet.sim.SET_CLIPBOARD" + } +} diff --git a/wallet/src/sim/res/raw/sim_ca.crt b/wallet/src/sim/res/raw/sim_ca.crt @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDOTCCAiGgAwIBAgIUUJou1L3V/dmJSGfXz4EstnS5pw8wDQYJKoZIhvcNAQEL +BQAwJDEiMCAGA1UEAwwZVGFsZXIgd2FsbGV0IHNpbXVsYXRvciBDQTAeFw0yNjEw +MTgwNDI2MzJaFw0zNjEwMTUwNDI2MzJaMCQxIjAgBgNVBAMMGVRhbGVyIHdhbGxl +dCBzaW11bGF0b3IgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCZ +wKI3xx3xTqxHA3vursssSnFQ/G8VddcY5FNUcs2z0UtA6Fab2bKWD/UhBLnB6tz3 +lOUp02s92bOaL0zjHlvBnbcjHA/XrUwcAV1T7mVwOhCw6ZkbC1iEdwMXGlFvcGTX +wN5m9lj8IV99KyICQDoPxKAQAeQYZ6xTl4TOylcYcFH2dYb+bvX6sqUDAkbW9VCm +aNHDjRJH113v4elZCmi2NUjBig+agwktIT7reAmyfE47EVujM5hOe2rLgdbhVVxV +BKRFctLJM/2ED1DxQKpwHZXBLOLHM5DKHuWss3I+SHPMFSl6EP/97sgC8W8Gpnq9 +nUt0SPKPyRBYWf5WIvGZAgMBAAGjYzBhMB0GA1UdDgQWBBS1uKyFIWhul9KrxC4C +ctjR7FilmjAfBgNVHSMEGDAWgBS1uKyFIWhul9KrxC4CctjR7FilmjAPBgNVHRMB +Af8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjANBgkqhkiG9w0BAQsFAAOCAQEAf45M +lXyo3ZycI7Loybd1flR7G5AzenAWlCmUdo5rVrXi2dz6z+cBFx1AaLPCPbAViEJn +YUWvrnr8NV6QtTpOJCoiCylCeF70C1p2znBN9xqcrHdYW74L0y4tp7rCmUDHV04y +UGwaY+z+otqFnGSFwBH92MyIakDr7WQMg3VgAI4SiHhf2pRe2ShVfKap5kyTNUTy +hblpYW4Nb89MzZOAkTscgh1VVSnpz4bHdTcVWcIPgY5aC0nHhJbs8WgL5EM3u1qr +UVLDuzoeE1xZtaDhF4PBzdxPXoh6u8NvVw1Nxlj6SUOVD93Ukbto3bIWjshsrkM3 +0lKER1R7V6umnIK67w== +-----END CERTIFICATE----- diff --git a/wallet/src/sim/res/xml/network_security_config.xml b/wallet/src/sim/res/xml/network_security_config.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Network policy for the "sim" build type only (simulator/, never published). + + It is src/main's policy — cleartext for the name "localhost" and nothing else + — plus one extra trust anchor: the simulator's own CA, so the emulator can be + pointed at a TLS front end answering for the hostnames the app hard-codes + (https://taldir.gnunet.org, https://mailbox.gnunet.org) without patching + those URLs out of the code under test. See simulator/tls/README.md; the + matching private key is generated per installation and is not in the tree, + so this certificate on its own authorises nobody. +--> +<network-security-config> + <base-config> + <trust-anchors> + <certificates src="system" /> + <certificates src="user" /> + <certificates src="@raw/sim_ca" /> + </trust-anchors> + </base-config> + <domain-config cleartextTrafficPermitted="true"> + <domain includeSubdomains="true">localhost</domain> + </domain-config> +</network-security-config>