1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
import pytest
from eth_typing import (
ChainId,
)
from eth_utils import (
Network,
ValidationError,
name_from_chain_id,
network_from_chain_id,
short_name_from_chain_id,
)
@pytest.mark.parametrize(
("chain_id", "expected_name"),
[
(1, "Ethereum Mainnet"),
(2, "Expanse Network"),
(42, "LUKSO Mainnet"),
],
)
def test_network_name_from_chain_id(chain_id, expected_name):
result = name_from_chain_id(chain_id)
assert result == expected_name
@pytest.mark.parametrize(
("chain_id", "expected_short_name"),
[
(1, "eth"),
(2, "exp"),
(42, "lukso"),
],
)
def test_short_name_from_chain_id(chain_id, expected_short_name):
result = short_name_from_chain_id(chain_id)
assert isinstance(result, str)
assert result == expected_short_name
@pytest.mark.parametrize(
("chain_id", "expected_network"),
[
(1, Network(1, "Ethereum Mainnet", "eth", ChainId.ETH)),
(2, Network(2, "Expanse Network", "exp", ChainId.EXP)),
(42, Network(42, "LUKSO Mainnet", "lukso", ChainId.LUKSO)),
(43, Network(43, "Darwinia Pangolin Testnet", "pangolin", ChainId.PANGOLIN)),
],
)
def test_network_from_chain_id(chain_id, expected_network):
result = network_from_chain_id(chain_id)
assert isinstance(result, Network)
assert result == expected_network
@pytest.mark.parametrize("invalid_chain_id", (222**222, 333**333, 444**444))
def test_from_chain_id_utility_methods_with_invalid_chain_id(invalid_chain_id):
error_message = f"chain_id is not recognized: {invalid_chain_id}"
# test network_from_chain_id
with pytest.raises(ValidationError, match=error_message):
network_from_chain_id(invalid_chain_id)
# test short_name_from_chain_id
with pytest.raises(ValidationError, match=error_message):
short_name_from_chain_id(invalid_chain_id)
# test name_from_chain_id
with pytest.raises(ValidationError, match=error_message):
name_from_chain_id(invalid_chain_id)
|