From f100b1cdf1174d4a9ed12021919ee7268cdd4fb1 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 2 Feb 2024 14:55:14 +1030 Subject: [PATCH] Add type `sat`. We actually use this in multiple places for requests. The key difference between this and msat is what we do when presented with a raw number! I prefer insisting on explicit suffixes, for this reason, but at least this will document the field correctly! Signed-off-by: Rusty Russell --- contrib/pyln-testing/pyln/testing/fixtures.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/contrib/pyln-testing/pyln/testing/fixtures.py b/contrib/pyln-testing/pyln/testing/fixtures.py index 7b89de6ee..a1fb7fb71 100644 --- a/contrib/pyln-testing/pyln/testing/fixtures.py +++ b/contrib/pyln-testing/pyln/testing/fixtures.py @@ -348,6 +348,16 @@ def _extra_validator(is_request: bool): except TypeError: return False + def is_sat(checker, instance): + """sat fields can be raw integers, sats, btc.""" + try: + # For plain integers, this gives the wrong value by 1000, + # but all we care about is the type here. + Millisatoshi(instance) + return True + except TypeError: + return False + def is_msat_response(checker, instance): """A positive integer""" return type(instance) is int and instance >= 0 @@ -396,6 +406,7 @@ def _extra_validator(is_request: bool): "u16": is_u16, "u8": is_u8, "pubkey": is_pubkey, + "sat": is_sat, "msat": is_msat, "msat_or_all": is_msat_or_all, "msat_or_any": is_msat_or_any,