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

Function test_custom_source

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

Source from the content-addressed store, hash-verified

136
137
138def test_custom_source(node_factory):
139 opts = {
140 "currencyrate-disable-source": ALL_RESOURCES,
141 "currencyrate-add-source": [
142 r"my-coingecko,https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies={currency_lc},bitcoin,{currency_lc}",
143 r"my-kraken,https://api.kraken.com/0/public/Ticker?pair=XXBTZ{currency},result,XXBTZ{currency},c,0",
144 ],
145 }
146 l1 = node_factory.get_node(options=opts)
147
148 rateslist = l1.rpc.call("listcurrencyrates", ["USD"])['currencyrates']
149 LOGGER.info(rateslist)
150 rates = {entry["source"]: entry["amount"] for entry in rateslist}
151
152 assert "bitstamp" not in rates
153 assert "coinbase" not in rates
154 assert "coingecko" not in rates
155 assert "kraken" not in rates
156 assert "blockchain.info" not in rates
157 assert "coindesk" not in rates
158 assert "binance" not in rates
159
160 assert "my-coingecko" in rates
161 assert "my-kraken" in rates
162
163 assert rates["my-coingecko"] > 0
164 assert rates["my-kraken"] > 0
165
166 rates = [
167 rates["my-coingecko"],
168 rates["my-kraken"],
169 ]
170 rates.sort()
171
172 convert = l1.rpc.call("currencyconvert", [100, "USD"])
173 LOGGER.info(convert)
174
175 assert "msat" in convert
176 assert convert["msat"] > 0
177 assert convert["msat"] in median_conversion(100, rateslist)
178
179 assert int(l1.rpc.currencyrate("USD")['rate']) in median_rate(rateslist)
180
181
182def 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