Skip to content

Commit

Permalink
feat: support for Sonic blockchain (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
markuslevonyak authored Oct 17, 2024
1 parent dc41eed commit 7689af2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 39 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
.vscode/
build/
dist/
find.sh
local/
/local/
.coverage
requirements.txt
tmp
4 changes: 3 additions & 1 deletion pantos/common/blockchains/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class Blockchain(enum.IntEnum):
SOLANA = 4
POLYGON = 5
CRONOS = 6
FANTOM = 7
# Renamed from "FANTOM" to "SONIC" on 2024-10-17 due to
# network renaming
SONIC = 7
CELO = 8
# Decomissioned: AURORA = 9

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
"""Module for Fantom-specific utilities and errors. Since Fantom is
"""Module for Sonic-specific utilities and errors. Since Sonic is
Ethereum-compatible, the utilities implementation inherits from the
pantos.common.blockchains.ethereum module.
Note that Pantos used to support Sonic's predecessor Fantom. This module
was renamed accordingly on 2024-10-17.
"""
from pantos.common.blockchains.base import BlockchainUtilitiesError
from pantos.common.blockchains.enums import Blockchain
from pantos.common.blockchains.ethereum import EthereumUtilities
from pantos.common.blockchains.ethereum import EthereumUtilitiesError


class FantomUtilitiesError(EthereumUtilitiesError):
"""Exception class for all Fantom utilities errors.
class SonicUtilitiesError(EthereumUtilitiesError):
"""Exception class for all Sonic utilities errors.
"""
pass


class FantomUtilities(EthereumUtilities):
"""Class for Fantom-specific utilities.
class SonicUtilities(EthereumUtilities):
"""Class for Sonic-specific utilities.
"""
@classmethod
def get_blockchain(cls) -> Blockchain:
# Docstring inherited
return Blockchain.FANTOM
return Blockchain.SONIC

@classmethod
def get_error_class(cls) -> type[BlockchainUtilitiesError]:
# Docstring inherited
return FantomUtilitiesError
return SonicUtilitiesError
6 changes: 3 additions & 3 deletions tests/blockchains/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from pantos.common.blockchains.factory import _blockchain_utilities
from pantos.common.blockchains.factory import get_blockchain_utilities
from pantos.common.blockchains.factory import initialize_blockchain_utilities
from pantos.common.blockchains.fantom import FantomUtilities
from pantos.common.blockchains.polygon import PolygonUtilities
from pantos.common.blockchains.solana import SolanaUtilities
from pantos.common.blockchains.sonic import SonicUtilities
from pantos.common.exceptions import NotInitializedError


Expand Down Expand Up @@ -60,8 +60,8 @@ def _get_blockchain_utilities_class(blockchain):
return CronosUtilities
if blockchain is Blockchain.ETHEREUM:
return EthereumUtilities
if blockchain is Blockchain.FANTOM:
return FantomUtilities
if blockchain is Blockchain.SONIC:
return SonicUtilities
if blockchain is Blockchain.POLYGON:
return PolygonUtilities
if blockchain is Blockchain.SOLANA:
Expand Down
25 changes: 0 additions & 25 deletions tests/blockchains/test_fantom.py

This file was deleted.

25 changes: 25 additions & 0 deletions tests/blockchains/test_sonic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest

from pantos.common.blockchains.enums import Blockchain
from pantos.common.blockchains.sonic import SonicUtilities
from pantos.common.blockchains.sonic import SonicUtilitiesError


@pytest.fixture(scope='module')
def sonic_utilities(blockchain_node_urls, fallback_blockchain_node_urls,
average_block_time, required_transaction_confirmations,
transaction_network_id):
return SonicUtilities(blockchain_node_urls, fallback_blockchain_node_urls,
average_block_time,
required_transaction_confirmations,
transaction_network_id)


def test_get_blockchain_correct(sonic_utilities):
assert sonic_utilities.get_blockchain() is Blockchain.SONIC
assert SonicUtilities.get_blockchain() is Blockchain.SONIC


def test_get_error_class_correct(sonic_utilities):
assert sonic_utilities.get_error_class() is SonicUtilitiesError
assert SonicUtilities.get_error_class() is SonicUtilitiesError

0 comments on commit 7689af2

Please sign in to comment.