-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6adb7c5
commit bd286d5
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
packages/valory/skills/decision_maker_abci/tests/states/test_randomness.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# Copyright 2023-2024 Valory AG | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
|
||
import pytest | ||
from packages.valory.skills.decision_maker_abci.states.base import Event | ||
from packages.valory.skills.transaction_settlement_abci.rounds import RandomnessTransactionSubmissionRound | ||
from packages.valory.skills.decision_maker_abci.rounds import RandomnessRound | ||
|
||
class MockSynchronizedData: | ||
"""A mock class for SynchronizedData to provide necessary attributes.""" | ||
pass | ||
|
||
class MockContext: | ||
"""A mock class for context used in RandomnessTransactionSubmissionRound.""" | ||
def __init__(self): | ||
self.sender = "mock_sender" | ||
|
||
|
||
class TestRandomnessRound: | ||
|
||
@pytest.fixture | ||
def setup_randomness_round(self): | ||
"""Fixture to set up a RandomnessRound instance.""" | ||
context = MockContext() | ||
synchronized_data = MockSynchronizedData() | ||
return RandomnessRound(context=context, synchronized_data=synchronized_data) | ||
|
||
def test_randomness_round_properties(self, setup_randomness_round): | ||
"""Test the properties of the RandomnessRound class.""" | ||
randomness_round = setup_randomness_round | ||
|
||
assert randomness_round.done_event == Event.DONE | ||
assert randomness_round.no_majority_event == Event.NO_MAJORITY | ||
|
||
def test_randomness_round_inherits_randomness_transaction_submission_round(self): | ||
"""Test that RandomnessRound inherits from RandomnessTransactionSubmissionRound.""" | ||
assert issubclass(RandomnessRound, RandomnessTransactionSubmissionRound) | ||
|
||
def test_randomness_round_event_handling(self, setup_randomness_round): | ||
"""Test the event handling mechanism.""" | ||
randomness_round = setup_randomness_round | ||
randomness_round.current_event = Event.DONE # Simulate setting the event | ||
assert randomness_round.current_event == Event.DONE | ||
|
||
randomness_round.current_event = Event.NO_MAJORITY # Simulate setting another event | ||
assert randomness_round.current_event == Event.NO_MAJORITY |