mirror of https://github.com/nucypher/nucypher.git
Updates ritual and participant mocks; sync MockCoordinator
parent
cdea26074d
commit
6dfe7f9953
|
@ -246,8 +246,8 @@ class ActiveRitualTracker:
|
|||
Returns node's participant information for the provided
|
||||
ritual id; None if node is not participating in the ritual
|
||||
"""
|
||||
participants = self.coordinator_agent.get_ritual(ritual_id=ritual_id)
|
||||
for p in participants:
|
||||
ritual = self.coordinator_agent.get_ritual(ritual_id=ritual_id)
|
||||
for p in ritual.participants:
|
||||
if p.provider == self.operator.checksum_address:
|
||||
return p
|
||||
|
||||
|
|
|
@ -180,6 +180,11 @@ def test_ursula_ritualist(
|
|||
print(
|
||||
"==================== BLOCKING UNTIL DKG FINALIZED ===================="
|
||||
)
|
||||
assert (
|
||||
mock_coordinator_agent.get_ritual_status(ritual_id=ritual_id)
|
||||
== mock_coordinator_agent.Ritual.Status.DKG_AWAITING_AGGREGATIONS
|
||||
)
|
||||
|
||||
execute_round_2(ritual_id, cohort)
|
||||
|
||||
def finality(_):
|
||||
|
|
|
@ -152,7 +152,7 @@ def test_first_scan_start_block_calc_is_not_perfect_go_back_more_blocks(ritualis
|
|||
seconds=target_average_block_time * sample_window
|
||||
).epoch
|
||||
|
||||
expected_number_blocks_in_past = (int)(ritual_timeout / target_average_block_time)
|
||||
expected_number_blocks_in_past = int(ritual_timeout / target_average_block_time)
|
||||
expected_timestamp = now.subtract(seconds=ritual_timeout).epoch
|
||||
|
||||
initial_calc_potential_first_scan_block_number = (
|
||||
|
@ -243,6 +243,7 @@ def test_first_scan_start_block_calc_is_not_perfect_go_back_more_blocks(ritualis
|
|||
|
||||
|
||||
def test_get_ritual_participant_info(ritualist, get_random_checksum_address):
|
||||
mocked_agent = ritualist.coordinator_agent
|
||||
active_ritual_tracker = ActiveRitualTracker(operator=ritualist)
|
||||
|
||||
participants = []
|
||||
|
@ -253,13 +254,17 @@ def test_get_ritual_participant_info(ritualist, get_random_checksum_address):
|
|||
)
|
||||
participants.append(participant)
|
||||
|
||||
mock_ritual = Mock()
|
||||
mock_ritual.participants = participants
|
||||
mocked_agent.get_ritual.return_value = mock_ritual
|
||||
|
||||
# operator not in participants list
|
||||
participant_info = active_ritual_tracker._get_ritual_participant_info(ritual_id=0)
|
||||
assert participant_info is None
|
||||
|
||||
# add operator to participants list
|
||||
participant = CoordinatorAgent.Ritual.Participant(
|
||||
provider=ritualist.checksum_address
|
||||
index=i + 1, provider=ritualist.checksum_address
|
||||
)
|
||||
participants.append(participant)
|
||||
|
||||
|
@ -272,16 +277,21 @@ def test_get_ritual_participant_info(ritualist, get_random_checksum_address):
|
|||
def test_get_participation_state_values_from_contract(
|
||||
ritualist, get_random_checksum_address
|
||||
):
|
||||
mocked_agent = ritualist.coordinator_agent
|
||||
active_ritual_tracker = ActiveRitualTracker(operator=ritualist)
|
||||
|
||||
participants = []
|
||||
# random participants
|
||||
for i in range(0, 5):
|
||||
participant = CoordinatorAgent.Ritual.Participant(
|
||||
provider=get_random_checksum_address()
|
||||
index=i, provider=get_random_checksum_address()
|
||||
)
|
||||
participants.append(participant)
|
||||
|
||||
mock_ritual = Mock()
|
||||
mock_ritual.participants = participants
|
||||
mocked_agent.get_ritual.return_value = mock_ritual
|
||||
|
||||
# not participating so everything should be False
|
||||
(
|
||||
participating,
|
||||
|
@ -294,7 +304,7 @@ def test_get_participation_state_values_from_contract(
|
|||
|
||||
# add operator to participants list
|
||||
ritual_participant = CoordinatorAgent.Ritual.Participant(
|
||||
provider=ritualist.checksum_address
|
||||
index=i + 1, provider=ritualist.checksum_address
|
||||
)
|
||||
participants.append(ritual_participant)
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import time
|
||||
from copy import deepcopy
|
||||
from enum import Enum
|
||||
from typing import Dict, List, NamedTuple, Optional
|
||||
|
||||
|
@ -94,7 +93,8 @@ class MockCoordinatorAgent(MockContractAgent):
|
|||
init_timestamp=init_timestamp,
|
||||
end_timestamp=end_timestamp,
|
||||
participants=[
|
||||
self.Participant(index=0, provider=provider) for provider in providers
|
||||
self.Participant(index=i, provider=provider)
|
||||
for i, provider in enumerate(providers)
|
||||
],
|
||||
dkg_size=len(providers),
|
||||
threshold=self.get_threshold_for_ritual_size(len(providers)),
|
||||
|
@ -211,7 +211,7 @@ class MockCoordinatorAgent(MockContractAgent):
|
|||
def get_ritual(
|
||||
self, ritual_id: int, transcripts: bool = False, participants: bool = True
|
||||
) -> CoordinatorAgent.Ritual:
|
||||
ritual = deepcopy(self.rituals[ritual_id])
|
||||
ritual = self.rituals[ritual_id]
|
||||
return ritual
|
||||
|
||||
def is_participant(self, ritual_id: int, provider: ChecksumAddress) -> bool:
|
||||
|
@ -226,11 +226,7 @@ class MockCoordinatorAgent(MockContractAgent):
|
|||
) -> Participant:
|
||||
for p in self.rituals[ritual_id].participants:
|
||||
if p.provider == provider:
|
||||
# if not transcripts:
|
||||
# p = deepcopy(p)
|
||||
# p.transcript = b""
|
||||
return p
|
||||
|
||||
raise ValueError(f"Provider {provider} not found for ritual #{ritual_id}")
|
||||
|
||||
def get_providers(self, ritual_id: int) -> List[ChecksumAddress]:
|
||||
|
|
|
@ -111,7 +111,7 @@ def test_perform_round_1(
|
|||
participants=list(participants.values()),
|
||||
)
|
||||
agent.get_ritual = lambda *args, **kwargs: ritual
|
||||
agent.get_participant = lambda ritual_id, provider, transcripts: participants[
|
||||
agent.get_participant = lambda ritual_id, provider, transcript: participants[
|
||||
provider
|
||||
]
|
||||
|
||||
|
@ -210,7 +210,9 @@ def test_perform_round_2(
|
|||
)
|
||||
|
||||
agent.get_ritual = lambda *args, **kwargs: ritual
|
||||
agent.get_participant = lambda ritual_id, provider: participants[provider]
|
||||
agent.get_participant = lambda ritual_id, provider, transcript: participants[
|
||||
provider
|
||||
]
|
||||
|
||||
# ensure no operation performed for non-application-state
|
||||
non_application_states = [
|
||||
|
@ -248,7 +250,9 @@ def test_perform_round_2(
|
|||
)
|
||||
|
||||
# participant already posted aggregated transcript
|
||||
participant = agent.get_participant(ritual_id=0, provider=ursula.checksum_address)
|
||||
participant = agent.get_participant(
|
||||
ritual_id=0, provider=ursula.checksum_address, transcript=False
|
||||
)
|
||||
participant.aggregated = True
|
||||
|
||||
# try submitting again
|
||||
|
|
Loading…
Reference in New Issue