Skip to content

Commit a5b0831

Browse files
authored
Fix falsy 0 check, use testing config everywhere (#25)
1 parent a7b403c commit a5b0831

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

uma_vasp/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@
33
from typing import Optional
44
from urllib.parse import parse_qs, unquote_plus, urlencode, urlparse, urlunparse
55

6-
from flask import Flask, jsonify, redirect, render_template, request, session, url_for
6+
from flask import (
7+
Flask,
8+
jsonify,
9+
redirect,
10+
render_template,
11+
request,
12+
session,
13+
url_for,
14+
current_app,
15+
)
716
from flask_cors import CORS
817
from lightspark import LightsparkSyncClient
918
from uma import (
1019
InMemoryNonceCache,
1120
InMemoryPublicKeyCache,
12-
InvalidSignatureException,
1321
ErrorCode,
1422
PostTransactionCallback,
1523
UmaException,
@@ -115,7 +123,9 @@ def handle_utxo_callback():
115123

116124
print(tx_callback.to_json())
117125

118-
if tx_callback.vasp_domain:
126+
# Skip signature verification in testing mode to avoid needing to run 2 VASPs.
127+
is_testing = current_app.config.get("TESTING", False)
128+
if tx_callback.vasp_domain and not is_testing:
119129
other_vasp_pubkeys = fetch_public_key_for_vasp(
120130
vasp_domain=tx_callback.vasp_domain,
121131
cache=pubkey_cache,

uma_vasp/sending_vasp.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,10 @@ def handle_pay_invoice(self):
252252
cache=self.vasp_pubkey_cache,
253253
)
254254

255-
verify_uma_invoice_signature(invoice, receiver_vasp_pubkey)
255+
# Skip signature verification in testing mode to avoid needing to run 2 VASPs.
256+
is_testing = current_app.config.get("TESTING", False)
257+
if not is_testing:
258+
verify_uma_invoice_signature(invoice, receiver_vasp_pubkey)
256259

257260
receiving_currency = CURRENCIES[invoice.receving_currency.code]
258261

@@ -472,7 +475,9 @@ def _handle_internal_uma_payreq(
472475
)
473476

474477
print(f"payreq_response: {payreq_response.to_dict()}")
475-
if uma_version == 1:
478+
# Skip signature verification in testing mode to avoid needing to run 2 VASPs.
479+
is_testing = current_app.config.get("TESTING", False)
480+
if uma_version == 1 and not is_testing:
476481
verify_pay_req_response_signature(
477482
user.get_uma_address(self.config),
478483
receiver_uma,
@@ -515,7 +520,8 @@ def _handle_internal_uma_payreq(
515520

516521
amount_receiving_currency = (
517522
payreq_response.payment_info.amount
518-
if payreq_response.payment_info and payreq_response.payment_info.amount
523+
if payreq_response.payment_info
524+
and payreq_response.payment_info.amount is not None
519525
else round(amount_as_msats(invoice_data.amount) / 1000)
520526
)
521527

@@ -634,7 +640,10 @@ def handle_request_pay_invoice(self, invoice: Invoice):
634640
vasp_domain=receiving_domain,
635641
cache=self.vasp_pubkey_cache,
636642
)
637-
verify_uma_invoice_signature(invoice, receiver_vasp_pubkey)
643+
# Skip signature verification in testing mode to avoid needing to run 2 VASPs.
644+
is_testing = current_app.config.get("TESTING", False)
645+
if not is_testing:
646+
verify_uma_invoice_signature(invoice, receiver_vasp_pubkey)
638647
receiving_currency = CURRENCIES[invoice.receving_currency.code]
639648
if not receiving_currency:
640649
abort_with_error(

0 commit comments

Comments
 (0)