Add unit test for structures in domains.py.

pull/3262/head
derekpierre 2023-10-05 06:21:34 -04:00
parent d8b9180921
commit 247b93859e
2 changed files with 62 additions and 1 deletions

View File

@ -42,9 +42,10 @@ class TACoDomain:
MAINNET = DomainInfo("mainnet", EthChain.MAINNET, PolygonChain.POLYGON)
# Testnets
ORYX = DomainInfo("oryx", EthChain.GOERLI, PolygonChain.POLYGON)
LYNX = DomainInfo("lynx", EthChain.GOERLI, PolygonChain.MUMBAI)
TAPIR = DomainInfo("tapir", EthChain.SEPOLIA, PolygonChain.MUMBAI)
# TODO remove these (oryx, ibex) when appropriate
ORYX = DomainInfo("oryx", EthChain.GOERLI, PolygonChain.POLYGON)
IBEX = DomainInfo(
"ibex", EthChain.GOERLI, None
) # this is required for configuration file migrations (backwards compatibility)

View File

@ -0,0 +1,60 @@
import pytest
from nucypher.blockchain.eth.domains import (
EthChain,
PolygonChain,
TACoDomain,
)
@pytest.mark.parametrize(
"eth_chain_test",
(
(EthChain.MAINNET, "mainnet", 1),
(EthChain.GOERLI, "goerli", 5),
(EthChain.SEPOLIA, "sepolia", 11155111),
),
)
def test_eth_chains(eth_chain_test):
eth_chain, expected_name, expected_id = eth_chain_test
assert eth_chain.name == expected_name
assert eth_chain.id == expected_id
@pytest.mark.parametrize(
"poly_chain_test",
(
(PolygonChain.POLYGON, "polygon", 137),
(PolygonChain.MUMBAI, "mumbai", 80001),
),
)
def test_polygon_chains(poly_chain_test):
eth_chain, expected_name, expected_id = poly_chain_test
assert eth_chain.name == expected_name
assert eth_chain.id == expected_id
@pytest.mark.parametrize(
"taco_domain_test",
(
(TACoDomain.MAINNET, "mainnet", EthChain.MAINNET, PolygonChain.POLYGON),
(TACoDomain.LYNX, "lynx", EthChain.GOERLI, PolygonChain.MUMBAI),
(TACoDomain.TAPIR, "tapir", EthChain.SEPOLIA, PolygonChain.MUMBAI),
),
)
def test_taco_domain_info(taco_domain_test):
(
domain_info,
expected_name,
expected_eth_chain,
expected_polygon_chain,
) = taco_domain_test
assert domain_info.name == expected_name
assert domain_info.eth_chain == expected_eth_chain
assert domain_info.polygon_chain == expected_polygon_chain
assert domain_info.is_testnet == (expected_name != "mainnet")
# magic methods
assert str(domain_info) == expected_name
assert bytes(domain_info) == expected_name.encode()