import os
import pytest
from web3 import Web3
from .contract_service import ContractService
TEST_SHAMAN_ADDRESS = "0xA84036A18ecd8f4F3D21ca7f85BEcC033571b15e"
pytestmark = pytest.mark.skipif(
os.environ.get("RUN_CONTRACT_SERVICE_TESTS") != "1",
reason=(
"Requires a running Ethereum JSON-RPC node and deployed contracts. "
"Set RUN_CONTRACT_SERVICE_TESTS=1 to enable."
),
)
@pytest.fixture
def contract_service() -> ContractService:
return ContractService()
@pytest.fixture
def checksum_address() -> str:
return Web3.to_checksum_address(TEST_SHAMAN_ADDRESS)
def test_backend_has_role(contract_service: ContractService) -> None:
has_role = contract_service.check_backend_has_role()
assert has_role, "Backend EOA should have BACKEND_ROLE"
def test_grant_verified_shaman_role(
contract_service: ContractService, checksum_address: str
) -> None:
verified_shaman_role = (
contract_service.contract.functions.VERIFIED_SHAMAN_ROLE().call()
)
success, error = contract_service.grant_verified_shaman_role(checksum_address)
assert success, f"Failed to grant role: {error}"
has_role_after = contract_service.contract.functions.hasRole(
verified_shaman_role, checksum_address
).call()
assert has_role_after, "Address should have VERIFIED_SHAMAN_ROLE after granting"