Skip to content

Commit 94a247d

Browse files
rustyrussellShahanaFarooqui
authored andcommitted
pyln-testing: fail typecheck gracefully on integer.
We say the offer amount arg can be either an `msat_or_any` or a `currency` string, but technically the order of evaluation is undefined, so it can check the other way, and it should not crash: ``` > offer = l3.rpc.offer(1000, 'test_pay_blindedpath_nodeaddr') tests/test_pay.py:5692: ... checker = <TypeChecker types={'array', 'bip340sig', 'boolean', 'currency', 'feerate', 'hash', 'hex', 'integer', 'msat', 'msat_or..._all', 'secret', 'short_channel_id', 'short_channel_id_dir', 'signature', 'string', 'txid', 'u16', 'u32', 'u64', 'u8'}> instance = 1000 def is_currency(checker, instance): """currency including currency code""" pattern = re.compile(r'^\d+(\.\d+)?[A-Z][A-Z][A-Z]$') > if pattern.match(instance): E TypeError: expected string or bytes-like object ``` Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 459c756 commit 94a247d

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

contrib/pyln-testing/pyln/testing/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def is_sat_or_all(checker, instance):
403403
def is_currency(checker, instance):
404404
"""currency including currency code"""
405405
pattern = re.compile(r'^\d+(\.\d+)?[A-Z][A-Z][A-Z]$')
406-
if pattern.match(instance):
406+
if checker.is_type(instance, "string") and pattern.match(instance):
407407
return True
408408
return False
409409

0 commit comments

Comments
 (0)