Skip to content

Commit

Permalink
fix: legacy node data without best_block property
Browse files Browse the repository at this point in the history
- Fix by making the best_block property Optional.
  • Loading branch information
alexruzenhack committed Jan 18, 2024
1 parent 364aea3 commit 79fe0f9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion domain/network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class AggregatedNode:
uptime: float
state: NodeState
latest_timestamp: int
best_block: BlockInfo
best_block: Optional[BlockInfo]
entrypoints: List[str]
connected_peers: List[str]

Expand Down
25 changes: 24 additions & 1 deletion tests/unit/gateways/test_node_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from gateways.node_gateway import NodeGateway
from tests.fixtures.network_factory import NetworkFactory
from tests.fixtures.network_factory import AggregatedNodeFactory, NetworkFactory
from tests.fixtures.node_factory import NodeFactory


Expand Down Expand Up @@ -114,6 +114,29 @@ def test_get_network(self, cache_client):
assert result.peers[0].id == network.peers[0].id
assert result.nodes[0].id == network.nodes[0].id

def test_get_network_no_best_block(self, cache_client):
"""Test legacy node data stored in the cache."""

network = NetworkFactory(nodes=[AggregatedNodeFactory()])
network_dict = network.to_dict()

# remove best_block as property from each node
for each_node in network_dict.get("nodes"):
each_node.pop("best_block")

cache_client.get = MagicMock(return_value=network_dict)

gateway = NodeGateway(cache_client=cache_client)

result = gateway.get_network()

cache_client.get.assert_called_once_with("network", "v1")

assert result.peers[0].id == network.peers[0].id
assert result.nodes[0].id == network.nodes[0].id
assert hasattr(result.nodes[0], "best_block")
assert result.nodes[0].best_block is None

def test_get_no_network(self, cache_client):
cache_client.get = MagicMock(return_value=None)

Expand Down

0 comments on commit 79fe0f9

Please sign in to comment.