|
| 1 | +import pytest |
| 2 | +from random import ( |
| 3 | + randint, |
| 4 | +) |
| 5 | + |
| 6 | +import pytest_asyncio |
| 7 | + |
| 8 | +from web3.beacon import ( |
| 9 | + AsyncBeacon, |
| 10 | +) |
| 11 | + |
| 12 | +from .conftest import ( |
| 13 | + assert_valid_response, |
| 14 | +) |
| 15 | + |
| 16 | + |
| 17 | +@pytest_asyncio.fixture() |
| 18 | +async def async_beacon(): |
| 19 | + return AsyncBeacon(base_url="http://localhost:5051") |
| 20 | + |
| 21 | + |
| 22 | +# Beacon endpoint tests: |
| 23 | + |
| 24 | + |
| 25 | +@pytest.mark.asyncio |
| 26 | +async def test_async_cl_beacon_get_genesis(async_beacon): |
| 27 | + response = await async_beacon.get_genesis() |
| 28 | + assert_valid_response(response) |
| 29 | + |
| 30 | + |
| 31 | +@pytest.mark.asyncio |
| 32 | +async def test_async_cl_beacon_get_hash_root(async_beacon): |
| 33 | + response = await async_beacon.get_hash_root() |
| 34 | + assert_valid_response(response) |
| 35 | + |
| 36 | + |
| 37 | +@pytest.mark.asyncio |
| 38 | +async def test_async_cl_beacon_get_fork_data(async_beacon): |
| 39 | + response = await async_beacon.get_fork_data() |
| 40 | + assert_valid_response(response) |
| 41 | + |
| 42 | + |
| 43 | +@pytest.mark.asyncio |
| 44 | +async def test_async_cl_beacon_get_finality_checkpoint(async_beacon): |
| 45 | + response = await async_beacon.get_finality_checkpoint() |
| 46 | + assert_valid_response(response) |
| 47 | + |
| 48 | + |
| 49 | +@pytest.mark.asyncio |
| 50 | +async def test_async_cl_beacon_get_validators(async_beacon): |
| 51 | + response = await async_beacon.get_validators() |
| 52 | + assert_valid_response(response) |
| 53 | + |
| 54 | + |
| 55 | +@pytest.mark.asyncio |
| 56 | +async def test_async_cl_beacon_get_validator(async_beacon): |
| 57 | + validators_response = await async_beacon.get_validators() |
| 58 | + assert_valid_response(validators_response) |
| 59 | + |
| 60 | + validators = validators_response["data"] |
| 61 | + random_validator = validators[randint(0, len(validators))] |
| 62 | + random_validator_pubkey = random_validator["validator"]["pubkey"] |
| 63 | + |
| 64 | + response = await async_beacon.get_validator(random_validator_pubkey) |
| 65 | + assert_valid_response(response) |
| 66 | + |
| 67 | + |
| 68 | +@pytest.mark.asyncio |
| 69 | +async def test_async_cl_beacon_get_validator_balances(async_beacon): |
| 70 | + response = await async_beacon.get_validator_balances() |
| 71 | + assert_valid_response(response) |
| 72 | + |
| 73 | + |
| 74 | +@pytest.mark.asyncio |
| 75 | +async def test_async_cl_beacon_get_epoch_committees(async_beacon): |
| 76 | + response = await async_beacon.get_epoch_committees() |
| 77 | + assert_valid_response(response) |
| 78 | + |
| 79 | + |
| 80 | +@pytest.mark.asyncio |
| 81 | +async def test_async_cl_beacon_get_block_headers(async_beacon): |
| 82 | + response = await async_beacon.get_block_headers() |
| 83 | + assert_valid_response(response) |
| 84 | + |
| 85 | + |
| 86 | +@pytest.mark.asyncio |
| 87 | +async def test_async_cl_beacon_get_block_header(async_beacon): |
| 88 | + response = await async_beacon.get_block_header("head") |
| 89 | + assert_valid_response(response) |
| 90 | + |
| 91 | + |
| 92 | +@pytest.mark.asyncio |
| 93 | +async def test_async_cl_beacon_get_block(async_beacon): |
| 94 | + response = await async_beacon.get_block("head") |
| 95 | + assert_valid_response(response) |
| 96 | + |
| 97 | + |
| 98 | +@pytest.mark.asyncio |
| 99 | +async def test_async_cl_beacon_get_block_root(async_beacon): |
| 100 | + response = await async_beacon.get_block_root("head") |
| 101 | + assert_valid_response(response) |
| 102 | + |
| 103 | + |
| 104 | +@pytest.mark.asyncio |
| 105 | +async def test_async_cl_beacon_get_block_attestations(async_beacon): |
| 106 | + response = await async_beacon.get_block_attestations("head") |
| 107 | + assert_valid_response(response) |
| 108 | + |
| 109 | + |
| 110 | +@pytest.mark.asyncio |
| 111 | +async def test_async_cl_beacon_get_attestations(async_beacon): |
| 112 | + response = await async_beacon.get_attestations() |
| 113 | + assert_valid_response(response) |
| 114 | + |
| 115 | + |
| 116 | +@pytest.mark.asyncio |
| 117 | +async def test_async_cl_beacon_get_attester_slashings(async_beacon): |
| 118 | + response = await async_beacon.get_attester_slashings() |
| 119 | + assert_valid_response(response) |
| 120 | + |
| 121 | + |
| 122 | +@pytest.mark.asyncio |
| 123 | +async def test_async_cl_beacon_get_proposer_slashings(async_beacon): |
| 124 | + response = await async_beacon.get_proposer_slashings() |
| 125 | + assert_valid_response(response) |
| 126 | + |
| 127 | + |
| 128 | +@pytest.mark.asyncio |
| 129 | +async def test_async_cl_beacon_get_voluntary_exits(async_beacon): |
| 130 | + response = await async_beacon.get_voluntary_exits() |
| 131 | + assert_valid_response(response) |
| 132 | + |
| 133 | + |
| 134 | +# Config endpoint tests: |
| 135 | + |
| 136 | + |
| 137 | +@pytest.mark.asyncio |
| 138 | +async def test_async_cl_config_get_fork_schedule(async_beacon): |
| 139 | + response = await async_beacon.get_fork_schedule() |
| 140 | + assert_valid_response(response) |
| 141 | + |
| 142 | + |
| 143 | +@pytest.mark.asyncio |
| 144 | +async def test_async_cl_config_get_spec(async_beacon): |
| 145 | + response = await async_beacon.get_spec() |
| 146 | + assert_valid_response(response) |
| 147 | + |
| 148 | + |
| 149 | +@pytest.mark.asyncio |
| 150 | +async def test_async_cl_config_get_deposit_contract(async_beacon): |
| 151 | + response = await async_beacon.get_deposit_contract() |
| 152 | + assert_valid_response(response) |
| 153 | + |
| 154 | + |
| 155 | +# Debug endpoint test_asyncs: |
| 156 | + |
| 157 | + |
| 158 | +@pytest.mark.asyncio |
| 159 | +async def test_async_cl_debug_get_beacon_state(async_beacon): |
| 160 | + response = await async_beacon.get_beacon_state() |
| 161 | + assert_valid_response(response) |
| 162 | + |
| 163 | + |
| 164 | +@pytest.mark.asyncio |
| 165 | +async def test_async_cl_debug_get_beacon_heads(async_beacon): |
| 166 | + response = await async_beacon.get_beacon_heads() |
| 167 | + assert_valid_response(response) |
| 168 | + |
| 169 | + |
| 170 | +# Node endpoint test_asyncs: |
| 171 | + |
| 172 | + |
| 173 | +@pytest.mark.asyncio |
| 174 | +async def test_async_cl_node_get_node_identity(async_beacon): |
| 175 | + response = await async_beacon.get_node_identity() |
| 176 | + assert_valid_response(response) |
| 177 | + |
| 178 | + |
| 179 | +@pytest.mark.asyncio |
| 180 | +async def test_async_cl_node_get_peers(async_beacon): |
| 181 | + response = await async_beacon.get_peers() |
| 182 | + assert_valid_response(response) |
| 183 | + |
| 184 | + |
| 185 | +@pytest.mark.asyncio |
| 186 | +async def test_async_cl_node_get_peer(async_beacon): |
| 187 | + response = await async_beacon.get_peer("") |
| 188 | + assert_valid_response(response) |
| 189 | + |
| 190 | + |
| 191 | +@pytest.mark.asyncio |
| 192 | +async def test_async_cl_node_get_health(async_beacon): |
| 193 | + response = await async_beacon.get_health() |
| 194 | + assert response <= 206 |
| 195 | + |
| 196 | + |
| 197 | +@pytest.mark.asyncio |
| 198 | +async def test_async_cl_node_get_version(async_beacon): |
| 199 | + response = await async_beacon.get_version() |
| 200 | + assert_valid_response(response) |
| 201 | + |
| 202 | + |
| 203 | +@pytest.mark.asyncio |
| 204 | +async def test_async_cl_node_get_syncing(async_beacon): |
| 205 | + response = await async_beacon.get_syncing() |
| 206 | + assert_valid_response(response) |
0 commit comments