Skip to content

Commit

Permalink
test script
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravleen-Solulab committed Sep 13, 2024
1 parent f20a59e commit 2f7f0af
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/valory/skills/decision_maker_abci/tests/test_dialogues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2021-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.
#
# ------------------------------------------------------------------------------

"""Test the dialogues.py module of the skill."""

# pylint: skip-file

import packages.valory.skills.decision_maker_abci.dialogues # noqa


def test_import() -> None:
"""Test that the 'dialogues.py' Python module can be imported."""
175 changes: 175 additions & 0 deletions packages/valory/skills/decision_maker_abci/tests/test_rounds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import pytest
from unittest.mock import MagicMock

from packages.valory.skills.decision_maker_abci.rounds import DecisionMakerAbciApp
from packages.valory.skills.decision_maker_abci.states.base import Event
from packages.valory.skills.decision_maker_abci.states.bet_placement import BetPlacementRound
from packages.valory.skills.decision_maker_abci.states.blacklisting import BlacklistingRound
from packages.valory.skills.decision_maker_abci.states.check_benchmarking import CheckBenchmarkingModeRound
from packages.valory.skills.decision_maker_abci.states.claim_subscription import ClaimRound
from packages.valory.skills.decision_maker_abci.states.decision_receive import DecisionReceiveRound
from packages.valory.skills.decision_maker_abci.states.decision_request import DecisionRequestRound
from packages.valory.skills.decision_maker_abci.states.final_states import (
BenchmarkingDoneRound,
BenchmarkingModeDisabledRound,
FinishedDecisionMakerRound,
FinishedDecisionRequestRound,
FinishedSubscriptionRound,
FinishedWithoutDecisionRound,
FinishedWithoutRedeemingRound,
ImpossibleRound,
RefillRequiredRound,
)
from packages.valory.skills.decision_maker_abci.states.order_subscription import (
SubscriptionRound,
)
from packages.valory.skills.decision_maker_abci.states.randomness import RandomnessRound
from packages.valory.skills.decision_maker_abci.states.redeem import RedeemRound
from packages.valory.skills.decision_maker_abci.states.sampling import SamplingRound
from packages.valory.skills.decision_maker_abci.states.tool_selection import ToolSelectionRound


from packages.valory.skills.decision_maker_abci.states.base import SynchronizedData


@pytest.fixture
def setup_app():
"""Set up the initial app instance for testing."""
# Create mock objects for the required arguments
synchronized_data = MagicMock(spec=SynchronizedData)
logger = MagicMock() # Mock logger
context = MagicMock() # Mock context

# Initialize the app with the mocked dependencies
return DecisionMakerAbciApp(synchronized_data, logger, context)


def test_initial_state(setup_app):
"""Test the initial round of the application."""
app = setup_app
assert app.initial_round_cls == CheckBenchmarkingModeRound
assert CheckBenchmarkingModeRound in app.initial_states




def test_check_benchmarking_transition(setup_app):
"""Test transitions from CheckBenchmarkingModeRound."""
app = setup_app
transition_function = app.transition_function[CheckBenchmarkingModeRound]

# Transition on benchmarking enabled
assert transition_function[Event.BENCHMARKING_ENABLED] == RandomnessRound

# Transition on benchmarking disabled
assert transition_function[Event.BENCHMARKING_DISABLED] == BenchmarkingModeDisabledRound

# Test no majority
assert transition_function[Event.NO_MAJORITY] == CheckBenchmarkingModeRound


def test_sampling_round_transition(setup_app):
"""Test transitions from SamplingRound."""
app = setup_app
transition_function = app.transition_function[SamplingRound]

# Transition on done
assert transition_function[Event.DONE] == SubscriptionRound

# Test none and no majority
assert transition_function[Event.NONE] == FinishedWithoutDecisionRound
assert transition_function[Event.NO_MAJORITY] == SamplingRound


def test_subscription_round_transition(setup_app):
"""Test transitions from SubscriptionRound."""
app = setup_app
transition_function = app.transition_function[SubscriptionRound]

# Transition on done
assert transition_function[Event.DONE] == FinishedSubscriptionRound

# Mock transaction cases
assert transition_function[Event.MOCK_TX] == RandomnessRound
assert transition_function[Event.NO_SUBSCRIPTION] == RandomnessRound


def test_claim_round_transition(setup_app):
"""Test transitions from ClaimRound."""
app = setup_app
transition_function = app.transition_function[ClaimRound]

# Test transition on done
assert transition_function[Event.DONE] == RandomnessRound


def test_randomness_round_transition(setup_app):
"""Test transitions from RandomnessRound."""
app = setup_app
transition_function = app.transition_function[RandomnessRound]

# Transition on done
assert transition_function[Event.DONE] == ToolSelectionRound


def test_tool_selection_round_transition(setup_app):
"""Test transitions from ToolSelectionRound."""
app = setup_app
transition_function = app.transition_function[ToolSelectionRound]

# Test transition on done
assert transition_function[Event.DONE] == DecisionRequestRound


def test_decision_request_round_transition(setup_app):
"""Test transitions from DecisionRequestRound."""
app = setup_app
transition_function = app.transition_function[DecisionRequestRound]

# Test transition on done
assert transition_function[Event.DONE] == FinishedDecisionRequestRound
assert transition_function[Event.MOCK_MECH_REQUEST] == DecisionReceiveRound


def test_decision_receive_round_transition(setup_app):
"""Test transitions from DecisionReceiveRound."""
app = setup_app
transition_function = app.transition_function[DecisionReceiveRound]

# Test transition on done
assert transition_function[Event.DONE] == BetPlacementRound


def test_blacklisting_round_transition(setup_app):
"""Test transitions from BlacklistingRound."""
app = setup_app
transition_function = app.transition_function[BlacklistingRound]

# Test transition on done
assert transition_function[Event.DONE] == FinishedWithoutDecisionRound


def test_bet_placement_round_transition(setup_app):
"""Test transitions from BetPlacementRound."""
app = setup_app
transition_function = app.transition_function[BetPlacementRound]

# Test transition on done
assert transition_function[Event.DONE] == FinishedDecisionMakerRound


def test_redeem_round_transition(setup_app):
"""Test transitions from RedeemRound."""
app = setup_app
transition_function = app.transition_function[RedeemRound]

# Test transition on done
assert transition_function[Event.DONE] == FinishedDecisionMakerRound


def test_final_states(setup_app):
"""Test the final states of the application."""
app = setup_app
assert FinishedDecisionMakerRound in app.final_states
assert BenchmarkingModeDisabledRound in app.final_states
assert FinishedWithoutDecisionRound in app.final_states

0 comments on commit 2f7f0af

Please sign in to comment.