taler-android

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

repro_delete_requeries_transaction.py (2947B)


      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: deleting a transaction makes the app ask for it again.
     15 
     16     cd /opt/taler-sim/driver
     17     python3 ../findings/repro_delete_requeries_transaction.py [emulator-5554]
     18 
     19 Exits 0 when the stray getTransactionById error shows up in the log.
     20 """
     21 
     22 from __future__ import annotations
     23 
     24 import re
     25 import sys
     26 import time
     27 from pathlib import Path
     28 
     29 sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver"))
     30 
     31 import scenarios  # noqa: E402
     32 import suite  # noqa: E402
     33 from device import Device  # noqa: E402
     34 from stack import Env  # noqa: E402
     35 from wallet import Wallet  # noqa: E402
     36 
     37 # The error carries a nested "when" object between the code and the hint, so
     38 # the two are matched independently rather than with one span.
     39 STRAY = re.compile(r'"operation":"getTransactionById".*?"code":(\d+).*?not found')
     40 
     41 
     42 def main() -> int:
     43     serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554"
     44     dev = Device(serial)
     45     app = Wallet(dev)
     46     env = Env.load()
     47 
     48     # A wallet with one finished withdrawal and one finished purchase.
     49     scenarios.funded_and_paid(app, env)
     50     dev.logcat(clear=True)
     51 
     52     screen = app.home()
     53     if screen.find(r"(?i)^Recent transactions$") is None:
     54         screen = app.scroll_to_text(r"(?i)^Recent transactions$")
     55     rows = suite.transaction_rows(screen)
     56     if not rows:
     57         print(f"no transactions to delete; screen: {screen.texts()}")
     58         return 2
     59     dev.tap_node(rows[0], screen)
     60     time.sleep(2)
     61     dev.tap_text(r"(?i)^Delete$", timeout=30)
     62     time.sleep(1)
     63     # Confirm the dialog.
     64     confirm = dev.dump().find(r"(?i)^Delete$")
     65     if confirm is not None:
     66         dev.tap_node(confirm, dev.dump())
     67     time.sleep(4)
     68 
     69     log = dev.logcat()
     70     hits = [ln for ln in log.splitlines() if STRAY.search(ln)]
     71     queries = [ln for ln in log.splitlines()
     72                if '"operation": "getTransactionById"' in ln or
     73                '"operation":"getTransactionById"' in ln]
     74     print(f"getTransactionById mentions after the delete: {len(queries)}")
     75     for line in hits[:4]:
     76         print(line.strip()[:320])
     77     print(f"\nscreen now: {dev.dump().texts()[:10]}")
     78     print(f"reproduced: {bool(hits)}")
     79     return 0 if hits else 1
     80 
     81 
     82 if __name__ == "__main__":
     83     raise SystemExit(main())