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

Function test_cached_median

tests/test_currencyrate.py:274–301  ·  view source on GitHub ↗

This should use the median of available sources

(node_factory, fake_rateserver)

Source from the content-addressed store, hash-verified

272
273
274def test_cached_median(node_factory, fake_rateserver):
275 """This should use the median of available sources"""
276 opts = {
277 "currencyrate-disable-source": ALL_RESOURCES,
278 "currencyrate-add-source": [
279 f"fast,{fake_rateserver['url']}/fast,price",
280 f"slow,{fake_rateserver['url']}/slow,price",
281 ],
282 }
283 l1 = node_factory.get_node(options=opts)
284
285 rateslist = l1.rpc.call("listcurrencyrates", ["USD"])['currencyrates']
286 LOGGER.info(rateslist)
287 rates = {entry["source"]: entry["amount"] for entry in rateslist}
288
289 assert "fast" in rates
290 assert "slow" in rates
291
292 assert rates["fast"] == fake_rateserver["state"]["fast"]
293 assert rates["slow"] == fake_rateserver["state"]["slow"]
294
295 # Cached result should be median of two rates.
296 median_rate = (fake_rateserver["state"]["fast"] + fake_rateserver["state"]["slow"]) / 2
297 convert = l1.rpc.call("currencyconvert", [100, "USD"])
298 LOGGER.info(convert)
299
300 # Median of raw rates is used.
301 assert convert["msat"] == 100 * 100_000_000_000 // median_rate
302
303
304def test_bkpr_listaccountevents_currencyrate(node_factory, fake_rateserver):

Callers

nothing calls this directly

Calls 2

get_nodeMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected