taler-android

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

repro_failed_query_empty_state.py (3105B)


      1 # This file is part of GNU Taler
      2 # (C) 2026 Taler Systems S.A.
      3 #
      4 # GNU Taler is free software; you can redistribute it and/or modify it under the
      5 # terms of the GNU General Public License as published by the Free Software
      6 # Foundation; either version 3, or (at your option) any later version.
      7 #
      8 # GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
      9 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     10 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     11 #
     12 # You should have received a copy of the GNU General Public License along with
     13 # GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     14 """Reproducer: a failed query is shown as an empty wallet.
     15 
     16 Two screens state a failure as a fact about the user's wallet: the deposit
     17 screen says there are no bank accounts, and the send screen offers €0.00.
     18 Both are driven by an injected failure of the one wallet-core call each screen
     19 makes.
     20 
     21     cd /opt/taler-sim/driver
     22     python3 ../findings/repro_failed_query_empty_state.py [emulator-5554]
     23 """
     24 
     25 from __future__ import annotations
     26 
     27 import base64
     28 import json
     29 import sys
     30 import time
     31 from pathlib import Path
     32 
     33 sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver"))
     34 
     35 import scenarios  # noqa: E402
     36 from device import PKG, Device  # noqa: E402
     37 from stack import Env  # noqa: E402
     38 from wallet import Wallet  # noqa: E402
     39 
     40 
     41 def inject(app: Wallet, dev: Device, operation: str, count: int = 4) -> None:
     42     detail = base64.urlsafe_b64encode(
     43         json.dumps({"code": 7001, "hint": "injected"}).encode()
     44     ).decode().rstrip("=")
     45     app.handle_uri(f"taler+http://dev-experiment/api-error?operation={operation}"
     46                    f"&detail={detail}&count={count}")
     47     time.sleep(2)
     48     # Applying an experiment ends with a back navigation, which closes the app
     49     # when the URI is what started it.
     50     for _ in range(3):
     51         if dev.dump().activity.startswith(PKG):
     52             return
     53         dev.launch()
     54         time.sleep(6)
     55 
     56 
     57 def main() -> int:
     58     serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554"
     59     dev = Device(serial)
     60     app = Wallet(dev)
     61     env = Env.load()
     62     scenarios.fund_wallet(app, env, "EUR:10")
     63 
     64     inject(app, dev, "getDepositWireTypes")
     65     app.home()
     66     dev.tap_text(r"(?i)^Deposit$", timeout=30)
     67     time.sleep(4)
     68     deposit = dev.dump().texts()
     69     print(f"deposit screen: {deposit[:8]}")
     70     no_accounts = any("No bank accounts" in t for t in deposit)
     71 
     72     app.home()
     73     inject(app, dev, "getMaxPeerPushDebitAmount")
     74     app.home()
     75     dev.tap_text(r"(?i)^Send$", timeout=30)
     76     time.sleep(4)
     77     send = dev.dump().texts()
     78     print(f"send screen: {send[:10]}")
     79     zero_to_send = any(t.strip() in ("€0.00", "Send €0.00") for t in send)
     80 
     81     print(f"\ndeposit claims there are no accounts: {no_accounts}")
     82     print(f"send offers nothing to send: {zero_to_send}")
     83     print(f"reproduced: {no_accounts or zero_to_send}")
     84     return 0 if (no_accounts or zero_to_send) else 1
     85 
     86 
     87 if __name__ == "__main__":
     88     raise SystemExit(main())