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

Function test_bitcoin_pruned

tests/test_misc.py:166–261  ·  view source on GitHub ↗

Test that we try to fetch blocks from a peer if we can not find them on our local bitcoind.

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

164
165
166def test_bitcoin_pruned(node_factory, bitcoind):
167 """Test that we try to fetch blocks from a peer if we can not find
168 them on our local bitcoind.
169 """
170 fetched_peerblock = False
171
172 def mock_getblock(r):
173 # Simulate a pruned node that reutrns an error when asked for a block.
174 nonlocal fetched_peerblock
175 if fetched_peerblock:
176 fetched_peerblock = False
177 conf_file = os.path.join(bitcoind.bitcoin_dir, "bitcoin.conf")
178 brpc = RawProxy(btc_conf_file=conf_file)
179 return {
180 "result": brpc._call(r["method"], *r["params"]),
181 "error": None,
182 "id": r["id"],
183 }
184 return {
185 "id": r["id"],
186 "result": None,
187 "error": {"code": -1, "message": "Block not available (pruned data)"},
188 }
189
190 def mock_getpeerinfo(r, error=False):
191 if error:
192 return {"id": r["id"], "error": {"code": -1, "message": "unknown"}}
193 return {
194 "id": r["id"],
195 "result": [
196 {
197 "id": 1,
198 "services": "000000000000040d",
199 },
200 {
201 "id": 2,
202 "services": "0000000000000001",
203 },
204 {
205 "id": 3,
206 "services": "0000000000000000",
207 },
208 ],
209 }
210
211 def mock_getblockfrompeer(error=False, release_after=0):
212 getblock_counter = 0
213
214 def mock_getblockfrompeer_inner(r):
215 nonlocal getblock_counter
216 getblock_counter += 1
217
218 if error and getblock_counter < release_after:
219 return {
220 "id": r["id"],
221 "error": {"code": -1, "message": "peer unknown"},
222 }
223 if getblock_counter >= release_after:

Callers

nothing calls this directly

Calls 6

mock_rpcMethod · 0.80
wait_for_logMethod · 0.80
generate_blockMethod · 0.80
mock_getblockfrompeerFunction · 0.70
get_nodeMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected