taler-android

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

repro_zero_deposit.py (3721B)


      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: the deposit screen does not guard the zero/below-fee case.
     15 
     16 Two halves:
     17   * clearing the amount asks wallet-core to price a zero deposit, which fails
     18     with WALLET_UNEXPECTED_EXCEPTION ("can't sum zero amounts");
     19   * depositing an amount at or below the deposit fee creates a transaction
     20     whose raw amount is zero.
     21 
     22     cd /opt/taler-sim/driver
     23     python3 ../findings/repro_zero_deposit.py [emulator-5554]
     24 """
     25 
     26 from __future__ import annotations
     27 
     28 import sys
     29 import time
     30 from pathlib import Path
     31 
     32 sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver"))
     33 
     34 import scenarios  # noqa: E402
     35 from device import Device  # noqa: E402
     36 from stack import Env  # noqa: E402
     37 from wallet import Wallet  # noqa: E402
     38 
     39 
     40 def open_deposit_amount(dev: Device, app: Wallet):
     41     app.home()
     42     dev.tap_text(r"(?i)^Deposit$", timeout=30)
     43     time.sleep(3)
     44     screen = dev.dump()
     45     account = screen.find(r"(?i)^wallet\d+$") or screen.find(r"(?i)x-taler-bank")
     46     if account is not None:
     47         dev.tap_node(account, screen)
     48         time.sleep(3)
     49     return dev.dump()
     50 
     51 
     52 def main() -> int:
     53     serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554"
     54     dev = Device(serial)
     55     app = Wallet(dev)
     56     env = Env.load()
     57     scenarios.fund_wallet(app, env, "EUR:10")
     58 
     59     # Half one: type an amount, then clear it.
     60     screen = open_deposit_amount(dev, app)
     61     fields = screen.editable()
     62     if not fields:
     63         print(f"no amount field: {screen.texts()}")
     64         return 2
     65     dev.tap_node(fields[0], screen)
     66     dev.type_text("500")                 # 5.00
     67     time.sleep(3)
     68     dev.logcat(clear=True)
     69     screen = dev.dump()
     70     reset = screen.find(r"(?i)^Reset$")
     71     if reset is None:
     72         print(f"no Reset button: {screen.texts()}")
     73         return 2
     74     dev.tap_node(reset, screen)
     75     time.sleep(5)
     76     log = dev.logcat()
     77     zero_sum = [ln for ln in log.splitlines() if "sum zero amounts" in ln]
     78     print(f"internal errors after clearing the amount: {len(zero_sum)}")
     79     if zero_sum:
     80         print("  " + zero_sum[0][-200:])
     81 
     82     # Half two: deposit exactly the fee.
     83     screen = open_deposit_amount(dev, app)
     84     fields = screen.editable()
     85     dev.tap_node(fields[0], screen)
     86     dev.type_text("1")                   # 0.01, at or below the deposit fee
     87     time.sleep(2)
     88     screen = dev.dump()
     89     make = screen.find(r"(?i)^Make deposit$")
     90     if make is None:
     91         print(f"no Make deposit button: {screen.texts()}")
     92         return 2
     93     dev.tap_node(make, screen)
     94     time.sleep(8)
     95     after = dev.dump()
     96     texts = after.texts()
     97     print(f"transaction afterwards: {texts[:10]}")
     98     degenerate = any("0.00" in t for t in texts) and any(
     99         t.startswith("-") or t.startswith("−") for t in texts)
    100 
    101     print(f"\nzero-amount pricing error: {bool(zero_sum)}")
    102     print(f"zero-value deposit created: {degenerate}")
    103     print(f"reproduced: {bool(zero_sum) or degenerate}")
    104     return 0 if (zero_sum or degenerate) else 1
    105 
    106 
    107 if __name__ == "__main__":
    108     raise SystemExit(main())