From cc378c20aa31bd580458f1d8eb98ee2ff0b48297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phan=20Th=E1=BA=BF=20Th=E1=BA=A3o?= Date: Sat, 8 Jun 2024 23:50:05 +0700 Subject: [PATCH] Cannot init blockfrost chain context (#358) * Update blockfrost.py * Add tests * Fix format --------- Co-authored-by: Jerry --- pycardano/backend/blockfrost.py | 2 +- test/pycardano/backend/test_blockfrost.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/pycardano/backend/test_blockfrost.py 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