smoke_withdraw.py (3820B)
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: withdraw from the local libeufin bank into the wallet app. 15 16 Prints every screen it sees, because the labels it discovers are what the 17 scenario library will later be written against. 18 """ 19 20 from __future__ import annotations 21 22 import sys 23 import time 24 25 from device import Device 26 from stack import Bank, Env, provision 27 from wallet import Wallet 28 29 AMOUNT = "EUR:10" 30 31 32 def main() -> int: 33 env = Env.load() 34 bank = Bank(env.bank) 35 print("provisioning:", provision(env)) 36 37 dev = Device(sys.argv[1] if len(sys.argv) > 1 else "emulator-5554") 38 app = Wallet(dev) 39 dev.logcat(clear=True) 40 dev.stop() 41 # A fresh profile in developer mode: taler+http:// URIs are rejected 42 # outright without it. 43 app.fresh_start(dev_mode=True) 44 print("\n--- home (developer mode on) ---") 45 print(dev.dump()) 46 47 before = bank.balance("wallet1", "walletpass1") 48 op = bank.create_withdrawal("wallet1", "walletpass1", AMOUNT) 49 uri = op["taler_withdraw_uri"] 50 print(f"\nbank balance before: {before}\nwithdraw uri: {uri}") 51 52 dev.send_uri(uri) 53 screen = dev.wait_for(r"(?i)withdraw|exchange|confirm|accept|terms", timeout=90) 54 print("\n--- withdrawal screen ---") 55 print(screen) 56 57 # The exchange is unknown to a fresh wallet, so terms of service have to be 58 # accepted before the withdrawal can be confirmed. Both labels are tried, 59 # in the order they can appear. 60 for pattern in (r"(?i)^(accept|agree|i accept)", r"(?i)confirm|withdraw now|^withdraw$"): 61 try: 62 tapped = dev.tap_text(pattern, timeout=20) 63 print(f"\ntapped {pattern!r} on screen with {tapped.texts()}") 64 time.sleep(3) 65 except TimeoutError as e: 66 print(f"\n(no match for {pattern!r}: {e})") 67 68 print("\n--- after confirm attempt ---") 69 print(dev.dump()) 70 71 status = bank.withdrawal_status(op["withdrawal_id"]) 72 print("\nbank-side withdrawal status:", status) 73 74 # The wallet has selected the exchange and registered the reserve; the 75 # human step left is confirming in the bank, which the host does here. 76 bank.confirm_withdrawal("wallet1", "walletpass1", op["withdrawal_id"]) 77 print("confirmed in bank") 78 79 deadline = time.monotonic() + 120 80 seen = None 81 while time.monotonic() < deadline: 82 screen = dev.dump() 83 seen = screen.texts() 84 if screen.find(r"EUR|€|\d+\.\d\d"): 85 break 86 time.sleep(3) 87 print("\n--- final wallet screen ---") 88 print("\n".join(str(t) for t in (seen or []))) 89 print("\nbank balance after:", bank.balance("wallet1", "walletpass1")) 90 91 log = dev.logcat() 92 bad = [ln for ln in log.splitlines() 93 if "FATAL EXCEPTION" in ln or "ANR in" in ln 94 or "unexpected exception" in ln.lower() 95 or "invariant" in ln.lower()] 96 print(f"\noracle hits in logcat: {len(bad)}") 97 for ln in bad[:10]: 98 print(" ", ln) 99 with open("/opt/taler-sim/run/smoke-logcat.txt", "w") as f: 100 f.write(log) 101 print("full logcat: /opt/taler-sim/run/smoke-logcat.txt") 102 return 0 103 104 105 if __name__ == "__main__": 106 sys.exit(main())