taler-android

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

repro_aborted_fee.py (2875B)


      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: an aborted withdrawal shows the whole amount as a fee.
     15 
     16 The fee row on every credit screen is the difference between the raw and the
     17 effective amount.  Aborting zeroes the effective amount, so the difference
     18 becomes the entire amount and the screen claims it all went to fees.
     19 
     20     cd /opt/taler-sim/driver
     21     python3 ../findings/repro_aborted_fee.py [emulator-5554]
     22 """
     23 
     24 from __future__ import annotations
     25 
     26 import re
     27 import sys
     28 import time
     29 from pathlib import Path
     30 
     31 sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver"))
     32 
     33 import scenarios  # noqa: E402
     34 from device import Device  # noqa: E402
     35 from stack import Bank, Env  # noqa: E402
     36 from wallet import Wallet  # noqa: E402
     37 
     38 AMOUNT = "EUR:5"
     39 AS_SHOWN = "5.00"
     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     bank = Bank(env.bank)
     48 
     49     app.fresh_start(dev_mode=True)
     50     op = bank.create_withdrawal(*scenarios.WALLET_USER, AMOUNT)
     51     app.handle_uri(op["taler_withdraw_uri"])
     52     scenarios.accept_tos(app)
     53     dev.tap_text(r"(?i)confirm withdrawal", timeout=60)
     54     dev.wait_for(r"(?i)Waiting for authorization|Authorize in bank", timeout=60)
     55 
     56     # Abort before the bank confirms: nothing is withdrawn and no fee is paid.
     57     dev.tap_text(r"(?i)^Abort$", timeout=30)
     58     time.sleep(1.5)
     59     if dev.dump().find(r"(?i)Abort transaction|Are you sure") is not None:
     60         dev.tap_text(r"(?i)^Abort$|^OK$|^Yes$", timeout=15)
     61     screen = dev.wait_for(r"(?i)was aborted|has failed", timeout=60)
     62     time.sleep(1)
     63     screen = dev.dump()
     64     texts = screen.texts()
     65     print(f"aborted transaction: {texts[:14]}")
     66 
     67     has_fee_row = screen.find(r"(?i)^Fee$") is not None
     68     amounts = [t for t in texts if re.match(r"^[-−]?[€$]?\d", t)]
     69     whole_as_fee = any(t.lstrip("-−").lstrip("€$") == AS_SHOWN for t in amounts[1:])
     70     print(f"fee row present: {has_fee_row}")
     71     print(f"amounts shown: {amounts[:6]}")
     72     print(f"\nreproduced: {has_fee_row and whole_as_fee}")
     73     return 0 if (has_fee_row and whole_as_fee) else 1
     74 
     75 
     76 if __name__ == "__main__":
     77     raise SystemExit(main())