diff --git a/pycardano/backend/blockfrost.py b/pycardano/backend/blockfrost.py index 4f475baa..40c9ccc7 100644 --- a/pycardano/backend/blockfrost.py +++ b/pycardano/backend/blockfrost.py @@ -90,7 +90,7 @@ def __init__( ) # Set network value to mainnet if base_url contains "mainnet". - if "mainnet" in self._base_url.value: + if "mainnet" in self._base_url: self._network = Network.MAINNET self.api = BlockFrostApi(project_id=self._project_id, base_url=self._base_url) diff --git a/test/pycardano/backend/test_blockfrost.py b/test/pycardano/backend/test_blockfrost.py new file mode 100644 index 00000000..5dcb2cbb --- /dev/null +++ b/test/pycardano/backend/test_blockfrost.py @@ -0,0 +1,22 @@ +from unittest.mock import MagicMock, patch + +from blockfrost import ApiUrls + +from pycardano.backend.blockfrost import BlockFrostChainContext +from pycardano.network import Network + + +@patch("pycardano.backend.blockfrost.BlockFrostApi") +def test_blockfrost_chain_context(mock_api): + mock_api.return_value = MagicMock() + chain_context = BlockFrostChainContext("project_id", base_url=ApiUrls.mainnet.value) + assert chain_context.network == Network.MAINNET + + chain_context = BlockFrostChainContext("project_id", base_url=ApiUrls.testnet.value) + assert chain_context.network == Network.TESTNET + + chain_context = BlockFrostChainContext("project_id", base_url=ApiUrls.preprod.value) + assert chain_context.network == Network.TESTNET + + chain_context = BlockFrostChainContext("project_id", base_url=ApiUrls.preview.value) + assert chain_context.network == Network.TESTNET