Skip to content

Commit 0f00a2b

Browse files
authored
Merge pull request #607 from 8ball030/feat/contract-scaffolding-params-additions
feat/contract scaffolding params additions
2 parents 69181a1 + 21dc83d commit 0f00a2b

6 files changed

Lines changed: 1037 additions & 1226 deletions

File tree

auto_dev/contracts/param_type.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,21 @@ class ParamType(Enum):
88

99
ADDRESS = "address"
1010
ADDRESS_ARRAY = "address[]"
11-
1211
BOOL = "bool"
13-
1412
BYTES = "bytes"
1513
BYTES_ARRAY = "bytes[]"
16-
BYTES4 = "bytes4"
1714
BYTES32 = "bytes32"
1815
BYTES32_ARRAY = "bytes32[]"
1916
BYTES32_ARRAY_ARRAY = "bytes32[][]"
20-
2117
INT8 = "int8"
2218
INT16 = "int16"
23-
INT24 = "int24"
2419
INT32 = "int32"
2520
INT64 = "int64"
26-
INT80_ARRAY = "int80[]"
2721
INT128 = "int128"
2822
INT256 = "int256"
2923
INT256_ARRAY = "int256[]"
30-
31-
STRING = "string"
3224
STRING_ARRAY = "string[]"
33-
3425
TUPLE = "tuple"
35-
TUPLE_ARRAY = "tuple[]"
36-
3726
UINT8 = "uint8"
3827
UINT8_ARRAY = "uint8[]"
3928
UINT16 = "uint16"
@@ -48,3 +37,9 @@ class ParamType(Enum):
4837
UINT256_ARRAY = "uint256[]"
4938
UINT256_2_ARRAY = "uint256[2]"
5039
UINT256_3_ARRAY = "uint256[3]"
40+
INT80_ARRAY = "int80[]"
41+
STRING = "string"
42+
TUPLE_ARRAY = "tuple[]"
43+
INT24 = "int24"
44+
BYTES4 = "bytes4"
45+
BOOL_ARRAY = "bool[]"

auto_dev/contracts/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
ParamType.UINT256_ARRAY: "List[int]",
6565
ParamType.UINT256_2_ARRAY: "List[int]",
6666
ParamType.UINT256_3_ARRAY: "List[int]",
67+
ParamType.BOOL_ARRAY: "List[bool]",
6768
}
6869

6970

auto_dev/data/templates/behaviours/simple_fsm.jinja

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ class BaseState(State, ABC):
4646
self._event = None
4747
self._is_done = False # Initially, the state is not done
4848

49-
def act(self) -> None:
50-
"""Perform the act."""
51-
print(f"Performing action for state {self._state}")
52-
self._is_done = True
53-
self._event = {{class_name}}Events.DONE
54-
5549
def is_done(self) -> bool:
5650
"""Is done."""
5751
return self._is_done
@@ -66,17 +60,25 @@ class BaseState(State, ABC):
6660
{% for state in states %}
6761
class {{ state }}(BaseState):
6862
"""This class implements the behaviour of the state {{ state }}."""
69-
def __init__(self, **kwargs: Any) -> None:
70-
super().__init__(**kwargs)
71-
self._state = {{class_name}}States.{{state.upper()}}
72-
{% endfor %}
73-
63+
_state = {{class_name}}States.{{state.upper()}}
7464

65+
def act(self) -> None:
66+
"""Perform the act."""
67+
print(f"Performing action for state {self._state}")
68+
self._is_done = True
69+
self._event = {{class_name}}Events.DONE
70+
{% endfor %}
7571

7672

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

76+
rounds = [
77+
{% for state in states %}
78+
{{state}},
79+
{% endfor %}
80+
]
81+
8082
def __init__(self, **kwargs: Any) -> None:
8183
super().__init__(**kwargs)
8284
self.register_state({{class_name}}States.{{default_start_state.upper()}}.value, {{default_start_state}}(**kwargs), True)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# -*- coding: utf-8 -*-
2+
# ------------------------------------------------------------------------------
3+
#
4+
# Copyright 2023 {{author}}
5+
# Copyright 2023 valory-xyz
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# ------------------------------------------------------------------------------
20+
21+
"""This package contains a behaviour test that is autogenerated from the protocol `{{protocol_name}}`."""
22+
23+
import json
24+
import logging
25+
from typing import cast
26+
from pathlib import Path
27+
from unittest.mock import patch
28+
import pytest
29+
30+
from aea.test_tools.test_skill import BaseSkillTestCase
31+
from aea.protocols.dialogue.base import DialogueMessage
32+
33+
from packages.{{public_id.author}}.skills.{{public_id.name}} import PUBLIC_ID
34+
from packages.{{public_id.author}}.skills.{{public_id.name}}.behaviours import (
35+
{{class_name}}FsmBehaviour,
36+
)
37+
38+
ROOT_DIR = Path(__file__).parent.parent.parent.parent.parent.parent
39+
40+
41+
class BaseTestCase(BaseSkillTestCase):
42+
"""Base test case for the fsm."""
43+
44+
path_to_skill = Path(ROOT_DIR, "packages", PUBLIC_ID.author, "skills", PUBLIC_ID.name)
45+
46+
{% for state in states %}
47+
class Test{{state}}Act(BaseSkillTestCase):
48+
"""Test {{state}}."""
49+
round_class = {{class_name}}FsmBehaviour.{{state}}
50+
51+
def test_act(self):
52+
"""Test the act method of the round."""
53+
round = self.round_class(name="test", skill_context=self.skill.skill_context)
54+
round.act()
55+
assert round.is_done()
56+
{% endfor %}

0 commit comments

Comments
 (0)