MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_apis

Function test_apis

tests/test_currencyrate.py:48–79  ·  view source on GitHub ↗
(node_factory)

Source from the content-addressed store, hash-verified

46
47
48def test_apis(node_factory):
49 l1 = node_factory.get_node()
50
51 for source in ALL_RESOURCES:
52 try:
53 rate = l1.rpc.call("currencyrate", ["USD", source])["rate"]
54 LOGGER.info(rate)
55 assert rate > 10_000
56 except RpcError as e:
57 LOGGER.warning(f"{source} reported error: {e}")
58 msg = str(e)
59 # Keyless tiers get throttled: usually 429, but coingecko's
60 # CloudFront edge reports the same condition as 403.
61 assert ("HTTP error 429" in msg
62 or "HTTP error 401" in msg
63 or "HTTP error 403" in msg)
64 continue
65
66 rateslist = l1.rpc.call("listcurrencyrates", ["USD"])['currencyrates']
67 LOGGER.info(rateslist)
68 rates = [{entry["source"]: entry["amount"] for entry in rateslist}]
69
70 rates.sort()
71
72 convert = l1.rpc.call("currencyconvert", [100, "USD"])
73 LOGGER.info(convert)
74
75 assert "msat" in convert
76 assert convert["msat"] > 0
77 assert convert["msat"] in median_conversion(100, rateslist)
78
79 assert int(l1.rpc.currencyrate("usd")['rate']) in median_rate(rateslist)
80
81
82def test_no_sources(node_factory):

Callers

nothing calls this directly

Calls 5

median_conversionFunction · 0.85
median_rateFunction · 0.85
sortMethod · 0.80
get_nodeMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected