Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions auto_dev/contracts/param_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,21 @@ class ParamType(Enum):

ADDRESS = "address"
ADDRESS_ARRAY = "address[]"

BOOL = "bool"

BYTES = "bytes"
BYTES_ARRAY = "bytes[]"
BYTES4 = "bytes4"
BYTES32 = "bytes32"
BYTES32_ARRAY = "bytes32[]"
BYTES32_ARRAY_ARRAY = "bytes32[][]"

INT8 = "int8"
INT16 = "int16"
INT24 = "int24"
INT32 = "int32"
INT64 = "int64"
INT80_ARRAY = "int80[]"
INT128 = "int128"
INT256 = "int256"
INT256_ARRAY = "int256[]"

STRING = "string"
STRING_ARRAY = "string[]"

TUPLE = "tuple"
TUPLE_ARRAY = "tuple[]"

UINT8 = "uint8"
UINT8_ARRAY = "uint8[]"
UINT16 = "uint16"
Expand All @@ -48,3 +37,9 @@ class ParamType(Enum):
UINT256_ARRAY = "uint256[]"
UINT256_2_ARRAY = "uint256[2]"
UINT256_3_ARRAY = "uint256[3]"
INT80_ARRAY = "int80[]"
STRING = "string"
TUPLE_ARRAY = "tuple[]"
INT24 = "int24"
BYTES4 = "bytes4"
BOOL_ARRAY = "bool[]"
1 change: 1 addition & 0 deletions auto_dev/contracts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
ParamType.UINT256_ARRAY: "List[int]",
ParamType.UINT256_2_ARRAY: "List[int]",
ParamType.UINT256_3_ARRAY: "List[int]",
ParamType.BOOL_ARRAY: "List[bool]",
}


Expand Down
24 changes: 13 additions & 11 deletions auto_dev/data/templates/behaviours/simple_fsm.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ class BaseState(State, ABC):
self._event = None
self._is_done = False # Initially, the state is not done

def act(self) -> None:
"""Perform the act."""
print(f"Performing action for state {self._state}")
self._is_done = True
self._event = {{class_name}}Events.DONE

def is_done(self) -> bool:
"""Is done."""
return self._is_done
Expand All @@ -66,17 +60,25 @@ class BaseState(State, ABC):
{% for state in states %}
class {{ state }}(BaseState):
"""This class implements the behaviour of the state {{ state }}."""
def __init__(self, **kwargs: Any) -> None:
super().__init__(**kwargs)
self._state = {{class_name}}States.{{state.upper()}}
{% endfor %}

_state = {{class_name}}States.{{state.upper()}}

def act(self) -> None:
"""Perform the act."""
print(f"Performing action for state {self._state}")
self._is_done = True
self._event = {{class_name}}Events.DONE
{% endfor %}


class {{class_name}}FsmBehaviour(FSMBehaviour):
"""This class implements a simple Finite State Machine behaviour."""

rounds = [
{% for state in states %}
{{state}},
{% endfor %}
]

def __init__(self, **kwargs: Any) -> None:
super().__init__(**kwargs)
self.register_state({{class_name}}States.{{default_start_state.upper()}}.value, {{default_start_state}}(**kwargs), True)
Expand Down
56 changes: 56 additions & 0 deletions auto_dev/data/templates/behaviours/simple_fsm_tests.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2023 {{author}}
# Copyright 2023 valory-xyz
#
# 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.
#
# ------------------------------------------------------------------------------

"""This package contains a behaviour test that is autogenerated from the protocol `{{protocol_name}}`."""

import json
import logging
from typing import cast
from pathlib import Path
from unittest.mock import patch
import pytest

from aea.test_tools.test_skill import BaseSkillTestCase
from aea.protocols.dialogue.base import DialogueMessage

from packages.{{public_id.author}}.skills.{{public_id.name}} import PUBLIC_ID
from packages.{{public_id.author}}.skills.{{public_id.name}}.behaviours import (
{{class_name}}FsmBehaviour,
)

ROOT_DIR = Path(__file__).parent.parent.parent.parent.parent.parent


class BaseTestCase(BaseSkillTestCase):
"""Base test case for the fsm."""

path_to_skill = Path(ROOT_DIR, "packages", PUBLIC_ID.author, "skills", PUBLIC_ID.name)

{% for state in states %}
class Test{{state}}Act(BaseSkillTestCase):
"""Test {{state}}."""
round_class = {{class_name}}FsmBehaviour.{{state}}

def test_act(self):
"""Test the act method of the round."""
round = self.round_class(name="test", skill_context=self.skill.skill_context)
round.act()
assert round.is_done()
{% endfor %}
Loading
Loading