Skip to content

Commit

Permalink
Cannot init blockfrost chain context (#358)
Browse files Browse the repository at this point in the history
* Update blockfrost.py

* Add tests

* Fix format

---------

Co-authored-by: Jerry <[email protected]>
  • Loading branch information
thaopt and cffls authored Jun 8, 2024
1 parent 7fbbe68 commit cc378c2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pycardano/backend/blockfrost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions test/pycardano/backend/test_blockfrost.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cc378c2

Please sign in to comment.