From fe58225990a4e0ca85b0c62b9eb9f030c472860f Mon Sep 17 00:00:00 2001 From: Ravleen-Solulab Date: Fri, 27 Sep 2024 17:00:26 +0530 Subject: [PATCH] test:state --- .../tests/states/test_final_states.py | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 packages/valory/skills/decision_maker_abci/tests/states/test_final_states.py diff --git a/packages/valory/skills/decision_maker_abci/tests/states/test_final_states.py b/packages/valory/skills/decision_maker_abci/tests/states/test_final_states.py new file mode 100644 index 000000000..86f069b89 --- /dev/null +++ b/packages/valory/skills/decision_maker_abci/tests/states/test_final_states.py @@ -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) + +