repro_unspecced_amounts.py (3782B)
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: amounts rendered without their currency specification. 15 16 Two screens show the wallet's fallback notation ("5.00 EUR") where the rest of 17 the app shows "€5.00": 18 19 * the manual withdrawal's wire transfer instructions, which put both 20 notations in one sentence; 21 * the incoming peer-payment prompt, whose composable takes no currency 22 specification at all. 23 24 cd /opt/taler-sim/driver 25 python3 ../findings/repro_unspecced_amounts.py [emulator-5554] 26 """ 27 28 from __future__ import annotations 29 30 import re 31 import sys 32 import time 33 from pathlib import Path 34 35 sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) 36 37 import scenarios # noqa: E402 38 from cli import CliWallet # noqa: E402 39 from device import Device # noqa: E402 40 from stack import Bank, Env # noqa: E402 41 from wallet import Wallet # noqa: E402 42 43 # "5.00 EUR": a number followed by the currency code, which is what 44 # Amount.toString() produces when it has no specification to work from. 45 UNSPECCED = re.compile(r"\d+[.,]\d\d\s+[A-Z]{3,}") 46 47 48 def transfer_instructions(dev: Device, app: Wallet, bank: Bank) -> list[str]: 49 """A manual withdrawal, as far as the wire transfer instructions.""" 50 app.home() 51 dev.tap_text(r"(?i)^Withdraw$", timeout=30) 52 dev.wait_for(r"(?i)Amount to withdraw|Total amount", timeout=30) 53 screen = dev.dump() 54 fields = screen.editable() 55 if fields: 56 dev.tap_node(fields[0], screen) 57 dev.type_text("500") 58 time.sleep(2) 59 scenarios.accept_tos(app) 60 dev.tap_text(r"(?i)Confirm withdrawal", timeout=30) 61 dev.wait_for(r"(?i)Wire transfer instructions|transaction is pending", timeout=60) 62 dev.tap_text(r"(?i)Wire transfer instructions", timeout=30) 63 screen = dev.wait_for(r"(?i)Subject|Recipient|IBAN|Account", timeout=30) 64 time.sleep(1) 65 return dev.dump().texts() 66 67 68 def main() -> int: 69 serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" 70 dev = Device(serial) 71 app = Wallet(dev) 72 env = Env.load() 73 bank = Bank(env.bank) 74 75 scenarios.fund_wallet(app, env, "EUR:10") 76 instructions = transfer_instructions(dev, app, bank) 77 bad_transfer = [t for t in instructions if UNSPECCED.search(t)] 78 print(f"transfer instructions: {instructions[:6]}") 79 print(f"unformatted there: {bad_transfer[:2]}") 80 81 # The peer prompt: another wallet pushes money to this one. The prompt is 82 # read before accepting anything, so nothing here depends on the timing of 83 # the accept. 84 peer = CliWallet() 85 app.home() 86 scenarios.fund_peer(peer, env, "EUR:5") 87 uri = peer.peer_send("EUR:1", env.exchange) 88 app.handle_uri(uri) 89 prompt = dev.wait_for(r"(?i)Do you want to receive this payment|Total:", 90 timeout=60) 91 bad_peer = [t for t in prompt.texts() if UNSPECCED.search(t)] 92 print(f"peer prompt: {prompt.texts()[:10]}") 93 print(f"unformatted there: {bad_peer[:3]}") 94 95 print(f"\nreproduced: {bool(bad_transfer) or bool(bad_peer)}") 96 return 0 if (bad_transfer or bad_peer) else 1 97 98 99 if __name__ == "__main__": 100 raise SystemExit(main())