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

Function fake_rateserver

tests/test_currencyrate.py:129–175  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

127
128@pytest.fixture
129def fake_rateserver():
130 app = Flask(__name__)
131 state = {
132 "fast": 100_000_000,
133 "slow": 50_000_000,
134 "slow_delay": 1,
135 "too_high": 50_000.0116,
136 "too_low": 50_000.0114,
137 "midpoint": 50_000.0115,
138 }
139
140 @app.get("/fast")
141 def fast():
142 return jsonify({"price": state["fast"]})
143
144 @app.get("/slow")
145 def slow():
146 time.sleep(state["slow_delay"])
147 return jsonify({"price": state["slow"]})
148
149 @app.get("/too_high")
150 def too_high():
151 return jsonify({"price": state["too_high"]})
152
153 @app.get("/too_low")
154 def too_low():
155 return jsonify({"price": state["too_low"]})
156
157 @app.get("/midpoint")
158 def midpoint():
159 return jsonify({"price": state["midpoint"]})
160
161 @app.get("/invalid")
162 def invalid():
163 currency = request.args.get("currency")
164 return jsonify({"price": state[currency]})
165
166 srv = _ServerThread(app)
167 srv.start()
168 try:
169 yield {
170 "url": f"http://127.0.0.1:{srv.port}",
171 "state": state,
172 }
173 finally:
174 srv.shutdown()
175 srv.join()
176
177
178def test_cached_median(node_factory, fake_rateserver):

Callers

nothing calls this directly

Calls 4

_ServerThreadClass · 0.85
joinMethod · 0.80
startMethod · 0.45
shutdownMethod · 0.45

Tested by

no test coverage detected