Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excercise 1 of third session #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions hello_world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Hello World ABCI Agent

This agent uses the `abci` connection and the `hello_world_abci` skill
to demonstrate a Hello World ABCI implementation.
20 changes: 20 additions & 0 deletions hello_world/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2022 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.
#
# ------------------------------------------------------------------------------

"""Module hello_world agent."""
133 changes: 133 additions & 0 deletions hello_world/aea-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
agent_name: hello_world
author: valory
version: 0.1.0
license: Apache-2.0
description: Hello World ABCI example.
aea_version: '>=1.0.0, <2.0.0'
fingerprint:
README.md: bafybeifzdekpjcas6egpwxj24tir5ozzffmkq5ecyi6rw3i6fqfd763etu
__init__.py: bafybeiehvk4wlv2bcbplwc66owg4qdnisiihijq7iegcmjjxtz3dulnrgm
tests/__init__.py: bafybeiasj5kqyvalbnedototb6ooxfnro3vjmgscja2iccccotfjnd6cha
tests/test_hello_world.py: bafybeifbgqpywtwhk6n4wngdrrk3oujwqw3fsbk54gsw5sep3pkkgym2ue
fingerprint_ignore_patterns: []
connections:
- valory/abci:0.1.0:bafybeicidr6u3w4vbalvrsfo4xraptxuti7cyrjlvqqn7udekxpm5hnho4
- valory/http_client:0.23.0:bafybeihi772xgzpqeipp3fhmvpct4y6e6tpjp4sogwqrnf3wqspgeilg4u
- valory/ipfs:0.1.0:bafybeigcijdbwgdekow5c2ikeltetoteabfp52ewy3xfkd7ygaqbl7j3ke
- valory/ledger:0.19.0:bafybeig7woeog4srdby75hpjkmx4rhpkzncbf4h2pm5r6varsp26pf2uhu
- valory/p2p_libp2p_client:0.1.0:bafybeid3xg5k2ol5adflqloy75ibgljmol6xsvzvezebsg7oudxeeolz7e
contracts:
- valory/service_registry:0.1.0:bafybeigqcbzsfuobmhthdrmc2bcrepfpsp476veopvakkpicie3oqf5n44
protocols:
- open_aea/signing:1.0.0:bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi
- valory/abci:0.1.0:bafybeiaqmp7kocbfdboksayeqhkbrynvlfzsx4uy4x6nohywnmaig4an7u
- valory/acn:1.1.0:bafybeidluaoeakae3exseupaea4i3yvvk5vivyt227xshjlffywwxzcxqe
- valory/contract_api:1.0.0:bafybeidgu7o5llh26xp3u3ebq3yluull5lupiyeu6iooi2xyymdrgnzq5i
- valory/http:1.0.0:bafybeifugzl63kfdmwrxwphrnrhj7bn6iruxieme3a4ntzejf6kmtuwmae
- valory/ipfs:0.1.0:bafybeiftxi2qhreewgsc5wevogi7yc5g6hbcbo4uiuaibauhv3nhfcdtvm
- valory/ledger_api:1.0.0:bafybeihdk6psr4guxmbcrc26jr2cbgzpd5aljkqvpwo64bvaz7tdti2oni
- valory/tendermint:0.1.0:bafybeig4mi3vmlv5zpbjbfuzcgida6j5f2nhrpedxicmrrfjweqc5r7cra
skills:
- valory/abstract_abci:0.1.0:bafybeicr24cgdovqdp4bh25bpun77v7u33maydwuxwled3tuhyiaepw5gu
- valory/abstract_round_abci:0.1.0:bafybeia6lemk5s64f26qjnd2746s5mufpzxuaf5frsqhfbr62kk3ma6sp4
- valory/hello_world_abci:0.1.0:bafybeifdkofq3yrtds3o236dsrywnfcrhlvzhxylrqvsnocwuk4paaorgm
default_ledger: ethereum
required_ledgers:
- ethereum
default_routing: {}
connection_private_key_paths: {}
private_key_paths: {}
logging_config:
version: 1
disable_existing_loggers: false
formatters:
standard:
format: '[%(asctime)s] [%(levelname)s] %(message)s'
handlers:
logfile:
class: logging.FileHandler
formatter: standard
filename: ${LOG_FILE:str:log.txt}
level: INFO
console:
class: logging.StreamHandler
formatter: standard
stream: ext://sys.stdout
loggers:
aea:
handlers:
- logfile
- console
propagate: true
dependencies:
open-aea-ledger-ethereum:
version: ==1.53.0
open-aea-test-autonomy:
version: ==0.15.0
customs: []
default_connection: null
---
public_id: valory/hello_world_abci:0.1.0
type: skill
models:
benchmark_tool:
args:
log_dir: ${str:/benchmarks}
params:
args:
hello_world_message: ${str:HELLO_WORLD!}
owner_address: ${str:0x0000000000000000000000000000000000000000}
reset_pause_duration: ${int:10}
service_registry_address: ${str:null}
share_tm_config_on_startup: ${bool:false}
on_chain_service_id: ${int:null}
setup:
all_participants: ${list:[]}
safe_contract_address: ${str:'0x0000000000000000000000000000000000000000'}
consensus_threshold: ${int:null}
tendermint_url: ${str:http://localhost:26657}
tendermint_com_url: ${str:http://localhost:8080}
tendermint_p2p_url: ${str:localhost:26656}
---
public_id: valory/abci:0.1.0
type: connection
config:
target_skill_id: valory/hello_world_abci:0.1.0
host: ${str:localhost}
port: ${int:26658}
use_tendermint: ${bool:false}
---
public_id: valory/ledger:0.19.0
type: connection
config:
ledger_apis:
ethereum:
address: ${str:http://localhost:8545}
chain_id: ${int:31337}
poa_chain: ${bool:false}
default_gas_price_strategy: ${str:eip1559}
---
public_id: valory/p2p_libp2p_client:0.1.0
type: connection
config:
nodes:
- uri: ${str:acn.staging.autonolas.tech:9005}
public_key: ${str:02d3a830c9d6ea1ae91936951430dee11f4662f33118b02190693be835359a9d77}
- uri: ${str:acn.staging.autonolas.tech:9006}
public_key: ${str:02e741c62d706e1dcf6986bf37fa74b98681bc32669623ac9ee6ff72488d4f59e8}
cert_requests:
- identifier: acn
ledger_id: ethereum
message_format: '{public_key}'
not_after: '2023-01-01'
not_before: '2022-01-01'
public_key: ${str:02d3a830c9d6ea1ae91936951430dee11f4662f33118b02190693be835359a9d77}
save_path: .certs/acn_cosmos_9005.txt
- identifier: acn
ledger_id: ethereum
message_format: '{public_key}'
not_after: '2023-01-01'
not_before: '2022-01-01'
public_key: ${str:02e741c62d706e1dcf6986bf37fa74b98681bc32669623ac9ee6ff72488d4f59e8}
save_path: .certs/acn_cosmos_9006.txt
is_abstract: true
20 changes: 20 additions & 0 deletions hello_world/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2022 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.
#
# ------------------------------------------------------------------------------

"""Tests for hello_world agent."""
187 changes: 187 additions & 0 deletions hello_world/tests/test_hello_world.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2021-2023 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.
#
# ------------------------------------------------------------------------------

"""End2end tests for the valory/hello_world skill."""

# pylint: skip-file

from pathlib import Path
from typing import Tuple

import pytest
from aea_test_autonomy.base_test_classes.agents import (
BaseTestEnd2EndExecution,
RoundChecks,
)
from aea_test_autonomy.configurations import KEY_PAIRS
from aea_test_autonomy.fixture_helpers import ( # noqa: F401
abci_host,
abci_port,
flask_tendermint,
ipfs_daemon,
ipfs_domain,
tendermint_port,
)

from packages.valory.skills.hello_world_abci.behaviours import (
CollectRandomnessBehaviour,
RegistrationBehaviour,
SelectKeeperBehaviour,
)
from packages.valory.skills.hello_world_abci.rounds import (
CollectRandomnessRound,
PrintMessageRound,
RegistrationRound,
ResetAndPauseRound,
SelectKeeperRound,
)


HAPPY_PATH = (
RoundChecks(RegistrationRound.auto_round_id()),
RoundChecks(PrintMessageRound.auto_round_id(), n_periods=3),
RoundChecks(CollectRandomnessRound.auto_round_id(), n_periods=3),
RoundChecks(SelectKeeperRound.auto_round_id(), n_periods=2),
RoundChecks(ResetAndPauseRound.auto_round_id(), n_periods=2),
)

# strict check log messages of the happy path
STRICT_CHECK_STRINGS = (
"Period end",
" in period 0 says: HELLO_WORLD!",
" in period 1 says: HELLO_WORLD!",
" in period 2 says: HELLO_WORLD!",
" in period 3 says: HELLO_WORLD!",
)


# normal execution
@pytest.mark.e2e
class BaseHelloWorldABCITest(
BaseTestEnd2EndExecution,
):
"""Test the hello_world_abci skill with four agents."""

agent_package = "valory/hello_world:0.1.0"
skill_package = "valory/hello_world_abci:0.1.0"
wait_to_finish = 160
happy_path = HAPPY_PATH
key_pairs = KEY_PAIRS
strict_check_strings: Tuple[str, ...] = STRICT_CHECK_STRINGS
package_registry_src_rel = Path(__file__).parent.parent.parent.parent.parent
ROUND_TIMEOUT_SECONDS = 30
RESET_PAUSE_DURATION = 10


@pytest.mark.usefixtures(
"flask_tendermint", "tendermint_port", "abci_host", "abci_port"
)
@pytest.mark.parametrize("nb_nodes", (1,))
class TestHelloWorldABCISingleAgent(BaseHelloWorldABCITest):
"""Test the hello_world_abci skill with only one agent."""


@pytest.mark.usefixtures(
"flask_tendermint", "tendermint_port", "abci_host", "abci_port"
)
@pytest.mark.parametrize("nb_nodes", (2,))
class TestHelloWorldABCITwoAgents(BaseHelloWorldABCITest):
"""Test the hello_world_abci skill with two agents."""


@pytest.mark.usefixtures(
"flask_tendermint", "tendermint_port", "abci_host", "abci_port"
)
@pytest.mark.parametrize("nb_nodes", (4,))
class TestHelloWorldABCIFourAgents(BaseHelloWorldABCITest):
"""Test the hello_world_abci skill with four agents."""


# catchup test
class BaseHelloWorldABCITestCatchup(BaseHelloWorldABCITest):
"""Test the hello_world_abci skill with catch up behaviour."""

stop_string = RegistrationBehaviour.auto_behaviour_id()
restart_after = 10
n_terminal = 1


# four behaviours and different stages of termination and restart
@pytest.mark.parametrize("nb_nodes", (4,))
class TestHelloWorldABCIFourAgentsCatchupOnRegister(BaseHelloWorldABCITestCatchup):
"""Test hello_world_abci skill with four agents; one restarting on `register`."""

stop_string = RegistrationBehaviour.auto_behaviour_id()


@pytest.mark.parametrize("nb_nodes", (4,))
class TestHelloWorldABCIFourAgentsCatchupRetrieveRandomness(
BaseHelloWorldABCITestCatchup
):
"""Test hello_world_abci skill with four agents; one restarting on `collect_randomness`."""

stop_string = CollectRandomnessBehaviour.auto_behaviour_id()


@pytest.mark.parametrize("nb_nodes", (4,))
class TestHelloWorldABCIFourAgentsCatchupSelectKeeper(BaseHelloWorldABCITestCatchup):
"""Test hello_world_abci skill with four agents; one restarting on `select_keeper`."""

stop_string = SelectKeeperBehaviour.auto_behaviour_id()


# multiple agents terminating and restarting
@pytest.mark.parametrize("nb_nodes", (4,))
class TestHelloWorldABCIFourAgentsTwoAgentRestarting(BaseHelloWorldABCITestCatchup):
"""Test the hello_world_abci skill with four agents and two restarting."""

n_terminal = 2


@pytest.mark.skip(reason="https://github.com/valory-xyz/open-autonomy/issues/1709")
@pytest.mark.parametrize("nb_nodes", (1,))
class TestHelloWorldABCISingleAgentGrpc(
BaseHelloWorldABCITest,
):
"""Test that the hello_world_abci skill with only one agent."""

USE_GRPC = True
strict_check_strings = STRICT_CHECK_STRINGS + ("Starting gRPC server",)


@pytest.mark.skip(reason="https://github.com/valory-xyz/open-autonomy/issues/1709")
@pytest.mark.parametrize("nb_nodes", (2,))
class TestHelloWorldABCITwoAgentsGrpc(
BaseHelloWorldABCITest,
):
"""Test that the hello_world_abci skill with two agents."""

USE_GRPC = True
strict_check_strings = STRICT_CHECK_STRINGS + ("Starting gRPC server",)


@pytest.mark.skip(reason="https://github.com/valory-xyz/open-autonomy/issues/1709")
@pytest.mark.parametrize("nb_nodes", (4,))
class TestHelloWorldABCIFourAgentsGrpc(
BaseHelloWorldABCITest,
):
"""Test that the hello_world_abci skill with four agents."""

USE_GRPC = True
strict_check_strings = STRICT_CHECK_STRINGS + ("Starting gRPC server",)
Empty file.
Loading