Skip to content

Commit

Permalink
test:state
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravleen-Solulab committed Sep 27, 2024
1 parent bd286d5 commit fe58225
Showing 1 changed file with 123 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# -*- 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.abstract_round_abci.base import (
BaseSynchronizedData,
DegenerateRound,
)
from packages.valory.skills.decision_maker_abci.states.final_states import (
BenchmarkingModeDisabledRound,
FinishedDecisionMakerRound,
FinishedDecisionRequestRound,
FinishedSubscriptionRound,
FinishedWithoutRedeemingRound,
FinishedWithoutDecisionRound,
RefillRequiredRound,
BenchmarkingDoneRound,
ImpossibleRound,
)

class MockSynchronizedData(BaseSynchronizedData):
"""A mock class for SynchronizedData."""
def __init__(self, db=None):
super().__init__(db) # Pass db to the parent class

class MockContext:
"""A mock class for context used in the rounds."""
def __init__(self):
self.some_attribute = "mock_value" # Add any necessary attributes here

class TestFinalStates:

@pytest.fixture
def setup_round(self):
"""Fixture to set up a round instance."""
synchronized_data = MockSynchronizedData(db="mock_db") # Provide a mock db value
context = MockContext()
return synchronized_data, context

def test_benchmarking_mode_disabled_round(self, setup_round):
"""Test instantiation of BenchmarkingModeDisabledRound."""
synchronized_data, context = setup_round
round_instance = BenchmarkingModeDisabledRound(context=context, synchronized_data=synchronized_data)
assert isinstance(round_instance, BenchmarkingModeDisabledRound)
assert isinstance(round_instance, DegenerateRound)

def test_finished_decision_maker_round(self, setup_round):
"""Test instantiation of FinishedDecisionMakerRound."""
synchronized_data, context = setup_round
round_instance = FinishedDecisionMakerRound(context=context, synchronized_data=synchronized_data)
assert isinstance(round_instance, FinishedDecisionMakerRound)
assert isinstance(round_instance, DegenerateRound)

def test_finished_decision_request_round(self, setup_round):
"""Test instantiation of FinishedDecisionRequestRound."""
synchronized_data, context = setup_round
round_instance = FinishedDecisionRequestRound(context=context, synchronized_data=synchronized_data)
assert isinstance(round_instance, FinishedDecisionRequestRound)
assert isinstance(round_instance, DegenerateRound)

def test_finished_subscription_round(self, setup_round):
"""Test instantiation of FinishedSubscriptionRound."""
synchronized_data, context = setup_round
round_instance = FinishedSubscriptionRound(context=context, synchronized_data=synchronized_data)
assert isinstance(round_instance, FinishedSubscriptionRound)
assert isinstance(round_instance, DegenerateRound)

def test_finished_without_redeeming_round(self, setup_round):
"""Test instantiation of FinishedWithoutRedeemingRound."""
synchronized_data, context = setup_round
round_instance = FinishedWithoutRedeemingRound(context=context, synchronized_data=synchronized_data)
assert isinstance(round_instance, FinishedWithoutRedeemingRound)
assert isinstance(round_instance, DegenerateRound)

def test_finished_without_decision_round(self, setup_round):
"""Test instantiation of FinishedWithoutDecisionRound."""
synchronized_data, context = setup_round
round_instance = FinishedWithoutDecisionRound(context=context, synchronized_data=synchronized_data)
assert isinstance(round_instance, FinishedWithoutDecisionRound)
assert isinstance(round_instance, DegenerateRound)

def test_refill_required_round(self, setup_round):
"""Test instantiation of RefillRequiredRound."""
synchronized_data, context = setup_round
round_instance = RefillRequiredRound(context=context, synchronized_data=synchronized_data)
assert isinstance(round_instance, RefillRequiredRound)
assert isinstance(round_instance, DegenerateRound)

def test_benchmarking_done_round(self, setup_round):
"""Test instantiation of BenchmarkingDoneRound and its end_block method."""
synchronized_data, context = setup_round
round_instance = BenchmarkingDoneRound(context=context, synchronized_data=synchronized_data)
assert isinstance(round_instance, BenchmarkingDoneRound)
assert isinstance(round_instance, DegenerateRound)

# Test the end_block method
with pytest.raises(SystemExit):
round_instance.end_block() # Should exit the program

def test_impossible_round(self, setup_round):
"""Test instantiation of ImpossibleRound."""
synchronized_data, context = setup_round
round_instance = ImpossibleRound(context=context, synchronized_data=synchronized_data)
assert isinstance(round_instance, ImpossibleRound)
assert isinstance(round_instance, DegenerateRound)


0 comments on commit fe58225

Please sign in to comment.