From 1e96534a160f202b490a64464ac7c646ccbac55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phan=20Th=E1=BA=BF=20Th=E1=BA=A3o?= Date: Fri, 7 Jun 2024 11:26:31 +0700 Subject: [PATCH 1/3] Update blockfrost.py --- pycardano/backend/blockfrost.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From ddf9b0bcb940e5dd5d26c6ea68b20a78bc662d91 Mon Sep 17 00:00:00 2001 From: Jerry Date: Sat, 8 Jun 2024 09:37:15 -0700 Subject: [PATCH 2/3] Add tests --- test/pycardano/backend/test_blockfrost.py | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/pycardano/backend/test_blockfrost.py diff --git a/test/pycardano/backend/test_blockfrost.py b/test/pycardano/backend/test_blockfrost.py new file mode 100644 index 00000000..14e7cbf5 --- /dev/null +++ b/test/pycardano/backend/test_blockfrost.py @@ -0,0 +1,29 @@ +from unittest.mock import patch, MagicMock + +from blockfrost import ApiUrls + +from pycardano.network import Network +from pycardano.backend.blockfrost import BlockFrostChainContext + +@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 From f5f92392202556e6c127e9c3a42678aea8b69fcf Mon Sep 17 00:00:00 2001 From: Jerry Date: Sat, 8 Jun 2024 09:44:23 -0700 Subject: [PATCH 3/3] Fix format --- test/pycardano/backend/test_blockfrost.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/test/pycardano/backend/test_blockfrost.py b/test/pycardano/backend/test_blockfrost.py index 14e7cbf5..5dcb2cbb 100644 --- a/test/pycardano/backend/test_blockfrost.py +++ b/test/pycardano/backend/test_blockfrost.py @@ -1,29 +1,22 @@ -from unittest.mock import patch, MagicMock +from unittest.mock import MagicMock, patch from blockfrost import ApiUrls -from pycardano.network import Network 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 - ) + 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 - ) + 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 - ) + 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 - ) + chain_context = BlockFrostChainContext("project_id", base_url=ApiUrls.preview.value) assert chain_context.network == Network.TESTNET