From 41f6d8bc8605980e0fe2c1211abab5c48753629d Mon Sep 17 00:00:00 2001 From: shreyav Date: Mon, 17 Mar 2025 14:52:18 -0700 Subject: [PATCH] Fix falsy 0 check --- uma_vasp/__init__.py | 16 +++++++++++++--- uma_vasp/sending_vasp.py | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/uma_vasp/__init__.py b/uma_vasp/__init__.py index 342318f..85ef37d 100644 --- a/uma_vasp/__init__.py +++ b/uma_vasp/__init__.py @@ -3,13 +3,21 @@ from typing import Optional from urllib.parse import parse_qs, unquote_plus, urlencode, urlparse, urlunparse -from flask import Flask, jsonify, redirect, render_template, request, session, url_for +from flask import ( + Flask, + jsonify, + redirect, + render_template, + request, + session, + url_for, + current_app, +) from flask_cors import CORS from lightspark import LightsparkSyncClient from uma import ( InMemoryNonceCache, InMemoryPublicKeyCache, - InvalidSignatureException, ErrorCode, PostTransactionCallback, UmaException, @@ -115,7 +123,9 @@ def handle_utxo_callback(): print(tx_callback.to_json()) - if tx_callback.vasp_domain: + # Skip signature verification in testing mode to avoid needing to run 2 VASPs. + is_testing = current_app.config.get("TESTING", False) + if tx_callback.vasp_domain and not is_testing: other_vasp_pubkeys = fetch_public_key_for_vasp( vasp_domain=tx_callback.vasp_domain, cache=pubkey_cache, diff --git a/uma_vasp/sending_vasp.py b/uma_vasp/sending_vasp.py index c78ac9f..3a9f255 100644 --- a/uma_vasp/sending_vasp.py +++ b/uma_vasp/sending_vasp.py @@ -252,7 +252,10 @@ def handle_pay_invoice(self): cache=self.vasp_pubkey_cache, ) - verify_uma_invoice_signature(invoice, receiver_vasp_pubkey) + # Skip signature verification in testing mode to avoid needing to run 2 VASPs. + is_testing = current_app.config.get("TESTING", False) + if not is_testing: + verify_uma_invoice_signature(invoice, receiver_vasp_pubkey) receiving_currency = CURRENCIES[invoice.receving_currency.code] @@ -472,7 +475,9 @@ def _handle_internal_uma_payreq( ) print(f"payreq_response: {payreq_response.to_dict()}") - if uma_version == 1: + # Skip signature verification in testing mode to avoid needing to run 2 VASPs. + is_testing = current_app.config.get("TESTING", False) + if uma_version == 1 and not is_testing: verify_pay_req_response_signature( user.get_uma_address(self.config), receiver_uma, @@ -515,7 +520,8 @@ def _handle_internal_uma_payreq( amount_receiving_currency = ( payreq_response.payment_info.amount - if payreq_response.payment_info and payreq_response.payment_info.amount + if payreq_response.payment_info + and payreq_response.payment_info.amount is not None else round(amount_as_msats(invoice_data.amount) / 1000) ) @@ -634,7 +640,10 @@ def handle_request_pay_invoice(self, invoice: Invoice): vasp_domain=receiving_domain, cache=self.vasp_pubkey_cache, ) - verify_uma_invoice_signature(invoice, receiver_vasp_pubkey) + # Skip signature verification in testing mode to avoid needing to run 2 VASPs. + is_testing = current_app.config.get("TESTING", False) + if not is_testing: + verify_uma_invoice_signature(invoice, receiver_vasp_pubkey) receiving_currency = CURRENCIES[invoice.receving_currency.code] if not receiving_currency: abort_with_error(