Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
glevco committed Jun 9, 2023
1 parent 0a228e3 commit c7639d2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
7 changes: 5 additions & 2 deletions hathor/simulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from hathor.conf import HathorSettings
from hathor.daa import TestMode, _set_test_mode
from hathor.manager import HathorManager
from hathor.p2p.peer_id import PeerId
from hathor.simulator.clock import HeapClock
from hathor.simulator.miner.dummy_miner import DummyMiner
from hathor.simulator.miner.geometric_miner import GeometricMiner
Expand Down Expand Up @@ -145,26 +146,28 @@ def get_default_builder(self) -> Builder:
"""
return Builder() \
.set_network(self._network) \
.set_peer_id(PeerId()) \
.set_soft_voided_tx_ids(set()) \
.enable_full_verification() \
.enable_sync_v1() \
.enable_sync_v2() \
.use_memory()

def create_peer(self, builder: Builder) -> HathorManager:
def create_peer(self, builder: Optional[Builder] = None) -> HathorManager:
"""
Returns a manager from a builder, after configuring it for simulator use.
You may get a builder from get_default_builder() for convenience.
"""
artifacts = self.create_artifacts(builder)
return artifacts.manager

def create_artifacts(self, builder: Builder) -> BuildArtifacts:
def create_artifacts(self, builder: Optional[Builder] = None) -> BuildArtifacts:
"""
Returns build artifacts from a builder, after configuring it for simulator use.
You may get a builder from get_default_builder() for convenience.
"""
assert self._started, 'Simulator is not started.'
builder = builder or self.get_default_builder()

wallet = HDWallet(gap_limit=2)
wallet._manually_initialize()
Expand Down
4 changes: 1 addition & 3 deletions tests/feature_activation/test_feature_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from hathor.feature_activation.model.criteria import Criteria
from hathor.feature_activation.resources.feature import FeatureResource
from hathor.feature_activation.settings import Settings as FeatureSettings
from hathor.p2p.peer_id import PeerId
from hathor.simulator.trigger import StopAfterNMinedBlocks
from tests import unittest
from tests.resources.base_resource import StubSite
Expand All @@ -47,8 +46,7 @@ class BaseTestFeatureSimulation(SimulatorTestCase):

def setUp(self):
super().setUp()
peer_id = PeerId()
artifacts = self.simulator.create_peer_artifacts(peer_id=peer_id)
artifacts = self.simulator.create_artifacts()
manager = artifacts.manager
manager.allow_mining_without_peers()

Expand Down
5 changes: 1 addition & 4 deletions tests/simulation/test_trigger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from hathor.p2p.peer_id import PeerId
from hathor.simulator import Simulator
from hathor.simulator.trigger import StopAfterMinimumBalance, StopAfterNMinedBlocks
from tests import unittest
Expand All @@ -11,9 +10,7 @@ def setUp(self):
self.simulator = Simulator()
self.simulator.start()

peer_id = PeerId()
builder = self.simulator.get_default_builder().set_peer_id(peer_id)
self.manager1 = self.simulator.create_peer(builder)
self.manager1 = self.simulator.create_peer()
self.manager1.allow_mining_without_peers()

print('-' * 30)
Expand Down

0 comments on commit c7639d2

Please sign in to comment.