Test that we try to fetch blocks from a peer if we can not find them on our local bitcoind.
(node_factory, bitcoind)
| 164 | |
| 165 | |
| 166 | def 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: |
nothing calls this directly
no test coverage detected