taler-android

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

smoke_pay.py (3119B)


      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 """P0 smoke test: pay a merchant order, then take a refund.
     15 
     16 Assumes the wallet already holds coins (run smoke_withdraw.py first); it keeps
     17 the app's state rather than wiping it, because paying from an existing balance
     18 is the state the explorer will spend most of its time in.
     19 """
     20 
     21 from __future__ import annotations
     22 
     23 import json
     24 import sys
     25 import time
     26 
     27 from device import Device
     28 from stack import Env, Merchant
     29 from wallet import Wallet
     30 
     31 PRICE = "EUR:2"
     32 REFUND = "EUR:1"
     33 
     34 
     35 def main() -> int:
     36     env = Env.load()
     37     merchant = Merchant(env.merchant)
     38 
     39     dev = Device(sys.argv[1] if len(sys.argv) > 1 else "emulator-5554")
     40     app = Wallet(dev)
     41     dev.logcat(clear=True)
     42     app.home()
     43     print("balances on screen:", app.balances())
     44 
     45     order = merchant.create_order(PRICE, summary="Simulator test order")
     46     print("order:", order["order_id"], "pay uri:", order["pay_uri"])
     47 
     48     screen = app.handle_uri(order["pay_uri"])
     49     print("\n--- payment prompt ---")
     50     print(screen)
     51 
     52     # The button carries the amount: "Pay €2.00".
     53     dev.tap_text(r"(?i)^pay\b|confirm payment", timeout=60)
     54     time.sleep(4)
     55     print("\n--- after paying ---")
     56     print(dev.dump())
     57 
     58     paid = False
     59     for _ in range(20):
     60         status = merchant.order_status(order["order_id"], order["token"])
     61         if status.get("order_status") == "paid":
     62             paid = True
     63             break
     64         time.sleep(2)
     65     print("\nmerchant order status:", json.dumps(
     66         {k: v for k, v in merchant.order_status(order['order_id'], order['token']).items()
     67          if k in ("order_status", "refunded", "wired", "deposit_total")}, indent=2))
     68     if not paid:
     69         print("ORDER NOT PAID")
     70 
     71     # Refund: the merchant grants it, the wallet picks it up from the URI the
     72     # merchant hands back.
     73     res = merchant.refund(order["order_id"], REFUND)
     74     refund_uri = res.get("taler_refund_uri")
     75     print("\nrefund uri:", refund_uri)
     76     if refund_uri:
     77         screen = app.handle_uri(refund_uri)
     78         print("\n--- after refund uri ---")
     79         print(screen)
     80 
     81     log = dev.logcat()
     82     bad = [ln for ln in log.splitlines()
     83            if "FATAL EXCEPTION" in ln or "ANR in" in ln
     84            or "unexpected exception" in ln.lower() or "invariant" in ln.lower()]
     85     print(f"\noracle hits in logcat: {len(bad)}")
     86     for ln in bad[:10]:
     87         print("  ", ln)
     88     return 0 if paid else 1
     89 
     90 
     91 if __name__ == "__main__":
     92     sys.exit(main())