From 4ade9cf068bd69188d1bc99b4805cf15a482eb87 Mon Sep 17 00:00:00 2001 From: David Minarsch Date: Mon, 22 Aug 2022 18:47:28 +0100 Subject: [PATCH 01/16] chore: clean up tox.ini and Makefile --- .github/workflows/workflow.yml | 16 ++++---- HISTORY.md | 2 +- Makefile | 68 ++++++++-------------------------- scripts/RELEASE_PROCESS.md | 4 +- tox.ini | 44 ++++++++++++---------- 5 files changed, 51 insertions(+), 83 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index a05ca4dac6..3baaf31031 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -134,13 +134,13 @@ jobs: - name: License Check run: tox -e liccheck - name: AEA Package Hashes Check - run: tox -e hash_check -- --timeout 60.0 + run: tox -e hash-check - name: Check package versions in documentation - run: tox -e package_version_checks + run: tox -e package-version-checks - name: Check package dependencies - run: tox -e package_dependencies_checks + run: tox -e package-dependencies-checks - name: Check generate protocols - run: tox -e check_generate_all_protocols + run: tox -e check-generate-all-protocols - name: Generate Documentation run: tox -e docs @@ -189,11 +189,11 @@ jobs: - name: Install markdown-spellcheck run: sudo npm install -g markdown-spellcheck - name: Check Docs links and IPFS hashes - run: tox -e check_doc_links_hashes + run: tox -e check-doc-links-hashes - name: Check API Docs updated - run: tox -e check_api_docs + run: tox -e check-api-docs - name: Check spelling - run: tox -e spell_check + run: tox -e spell-check scan: name: gitleaks @@ -235,7 +235,7 @@ jobs: pip install -e .[all] - name: Check aea dependenices and imports run: | - tox -e dependencies_check + tox -e dependencies-check plugins_install_check: continue-on-error: False diff --git a/HISTORY.md b/HISTORY.md index 678fc14318..035daa2a83 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -10,7 +10,7 @@ AEA: - Adds check to make sure all the packages in an AEA project are listed in the `aea-config.yaml` - Fixes a bug related to async function call on `TCPSocketProtocol` - Updates transaction building to handle gas estimation properly -- Update `ContractConfig` class to include contract dependencies in the depedency list +- Update `ContractConfig` class to include contract dependencies in the dependency list Docs: - Adds missing command on the `http-echo-demo.md` doc. diff --git a/Makefile b/Makefile index abdb7c9e6d..e881da9376 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ .PHONY: clean -clean: clean-build clean-pyc clean-test clean-docs +clean: clean-test clean-build clean-pyc clean-docs .PHONY: clean-build clean-build: @@ -9,9 +9,8 @@ clean-build: rm -fr pip-wheel-metadata find . -name '*.egg-info' -exec rm -fr {} + find . -name '*.egg' -exec rm -fr {} + + find . -type d -name __pycache__ -exec rm -rv {} + rm -fr Pipfile.lock - rm -rf plugins/*/build - rm -rf plugins/*/dist .PHONY: clean-docs clean-docs: @@ -35,42 +34,20 @@ clean-test: rm -fr .hypothesis rm -fr .pytest_cache rm -fr .mypy_cache/ - rm -fr input_file - rm -fr output_file + rm -fr .hypothesis/ find . -name 'log.txt' -exec rm -fr {} + find . -name 'log.*.txt' -exec rm -fr {} + -.PHONY: lint -lint: - black aea benchmark examples packages plugins scripts tests - isort aea benchmark examples packages plugins scripts tests - flake8 aea benchmark examples packages plugins scripts tests - vulture aea scripts/whitelist.py --exclude "*_pb2.py" - darglint aea benchmark examples libs packages plugins scripts - -.PHONY: pylint -pylint: - pylint -j4 aea benchmark packages scripts plugins/aea-ledger-fetchai/aea_ledger_fetchai plugins/aea-ledger-ethereum/aea_ledger_ethereum plugins/aea-ledger-cosmos/aea_ledger_cosmos plugins/aea-cli-ipfs/aea_cli_ipfs examples/* - -.PHONY: static -static: - mypy aea benchmark examples --disallow-untyped-defs - mypy packages tests plugins/aea-ledger-fetchai/aea_ledger_fetchai plugins/aea-ledger-ethereum/aea_ledger_ethereum plugins/aea-ledger-cosmos/aea_ledger_cosmos plugins/aea-cli-ipfs/aea_cli_ipfs - -.PHONY: package_checks +.PHONY: package-checks package_checks: - python -m aea.cli hash all --check - python -m aea.cli hash all --packages-dir=./tests/data/packages --check - python scripts/check_package_versions_in_docs.py - python -m aea.cli check-packages + tox -e hash-check + tox -e package-version-checks + tox -e package-dependencies-checks .PHONY: docs docs: mkdocs build --clean -.PHONY: common_checks -common_checks: security misc_checks lint static docs - .PHONY: test test: pytest -rfE plugins/aea-ledger-fetchai/tests --cov=aea_ledger_fetchai --cov-report=term --cov-report=term-missing --cov-config=.coveragerc @@ -128,12 +105,7 @@ release: v := $(shell pip -V | grep virtualenvs) .PHONY: all-checks -all-checks: - make clean \ - && make formatters \ - && make code-checks \ - && make common-checks \ - && make security \ +all-checks: clean formatters code-checks common-checks security .PHONY: new_env new_env: clean @@ -190,26 +162,18 @@ security: # update copyright headers .PHONY: generators generators: + tox -e fix-copyright python -m aea.cli generate-all-protocols python -m aea.cli generate-all-protocols tests/data/packages python -m aea.cli hash all python -m aea.cli hash all --packages-dir=./tests/data/packages - python scripts/generate_api_docs.py - python scripts/check_copyright_notice.py - python scripts/check_doc_ipfs_hashes.py --fix + tox -e generate-api-documentation -.PHONY: common-checks +.PHONY: common-checks-1 common-checks: - tox -p -e check-copyright -e hash_check -e package_dependencies_checks - -.PHONY: doc-checks -doc-checks: - tox -e check_doc_links_hashes -e check_api_docs - -.PHONY: copyright -copyright: - python scripts/check_copyright_notice.py + tox -p -e check-copyright -e hash_check -e package-dependencies-checks -.PHONY: check-copyright -check-copyright: - tox -e check-copyright +.PHONY: common-checks-2 +common-checks-2: + tox -e check-api-docs + tox -e check-doc-links-hashes diff --git a/scripts/RELEASE_PROCESS.md b/scripts/RELEASE_PROCESS.md index 48f9148fe0..52b6f36f6a 100644 --- a/scripts/RELEASE_PROCESS.md +++ b/scripts/RELEASE_PROCESS.md @@ -40,9 +40,9 @@ 18. Publish the latest packages to the IPFS registry using `aea init --reset --author valory --ipfs --remote` and `aea push-all`. If necessary, run it several times until all packages are updated. -19. Build the release images using `skaffold build -p release` which will also publish them on docker. This builds with no cache so to ensure replicable builds. Before running it, copy packages: `cp -R packages/ deploy-image/packages/` +19. Build the release images using `skaffold build -p release` which will also publish them to Docker Hub. This builds with no cache so to ensure replicable builds. -20. Tag the latest images using `skaffold build -p release-latest` which will also publish them on docker. +20. Tag the latest images using `skaffold build -p release-latest` which will also publish them to Docker Hub. If something goes wrong and only needs a small fix do `LAST_VERSION.post1` as version, apply fixes, push again to PyPI. diff --git a/tox.ini b/tox.ini index d3aae3d0fe..9d82b9e168 100644 --- a/tox.ini +++ b/tox.ini @@ -6,8 +6,9 @@ ; we set the associated flag (e.g. for linting we don't need ; the package installation). [tox] -envlist = bandit, black, black-check, isort, isort-check, copyright_check, docs, flake8, liccheck, mypy, py{3.7,3.8,3.9,3.10}, dependencies_check, plugins_deps - +envlist = bandit, safety, black, black-check, isort, isort-check, fix-copyright, check-copyright, hash-check, docs, flake8, liccheck, mypy, pylint, vulture, {plugins-,}py{3.7,3.8,3.9,3.10,3.10-cov}, dependencies-check, package-version-checks, package-dependencies-checks, plugins_deps, check-doc-links-hashes, check-generate-all-protocols, spell-check, generate-api-documentation +; when running locally we don't want to fail for no good reason +skip_missing_interpreters = true [testenv] basepython = python3.10 @@ -47,7 +48,6 @@ deps = pycryptodome>=3.10.1 cosmpy>=0.4.1,<0.5.0 setuptools==59.6.0 - commands = ; for some reason tox installs aea without respect to the dependencies version specified in seetup.py. at least in CI env ; so install current aea in a normal way @@ -143,7 +143,7 @@ skip_install = True deps = commands = {toxinidir}/scripts/check_copyright_notice.py --check -[testenv:hash_check] +[testenv:hash-check] skipsdist = True usedevelop = True deps = @@ -152,13 +152,13 @@ commands = python -m aea.cli hash all --check python -m aea.cli hash all --packages-dir=./tests/data/packages --check -[testenv:package_version_checks] +[testenv:package-version-checks] skipsdist = True usedevelop = True deps = commands = {toxinidir}/scripts/check_package_versions_in_docs.py -[testenv:package_dependencies_checks] +[testenv:package-dependencies-checks] skipsdist = True usedevelop = True deps = @@ -218,8 +218,8 @@ skip_install = True deps = mypy==0.910 commands = mypy aea packages --disallow-untyped-defs - mypy benchmark examples --check-untyped-defs - mypy scripts tests + mypy benchmark examples --disallow-untyped-defs + mypy scripts tests plugins/aea-ledger-fetchai/aea_ledger_fetchai plugins/aea-ledger-ethereum/aea_ledger_ethereum plugins/aea-ledger-cosmos/aea_ledger_cosmos plugins/aea-cli-ipfs/aea_cli_ipfs [testenv:pylint] whitelist_externals = @@ -231,7 +231,6 @@ deps = pytest==7.0.0 gitpython>=3.1.14 protobuf==3.19.4 - commands = python -m pip install --no-deps file://{toxinidir}/plugins/aea-ledger-ethereum python -m pip install --no-deps file://{toxinidir}/plugins/aea-ledger-cosmos @@ -260,7 +259,7 @@ deps = darglint==1.8.0 commands = darglint aea benchmark examples libs packages plugins scripts -[testenv:check_doc_links_hashes] +[testenv:check-doc-links-hashes] skipsdist = True usedevelop = True deps = @@ -269,14 +268,14 @@ commands = python {toxinidir}/scripts/check_doc_links.py python {toxinidir}/scripts/check_doc_ipfs_hashes.py python {toxinidir}/scripts/check_ipfs_hashes_pushed.py -[testenv:check_api_docs] +[testenv:check-api-docs] skipsdist = True usedevelop = True deps = pydoc-markdown==4.6.3 commands = {toxinidir}/scripts/generate_api_docs.py --check-clean -[testenv:check_generate_all_protocols] +[testenv:check-generate-all-protocols] skipsdist = True usedevelop = True deps = @@ -286,14 +285,14 @@ deps = isort==5.7.0 commands = python -m aea.cli generate-all-protocols --check-clean -[testenv:spell_check] +[testenv:spell-check] +whitelist_externals = mdspell skipsdist = True usedevelop = True deps = -commands = {toxinidir}/scripts/spell-check.sh +commands = mdspell -r -n -a --en-gb '**/*.md' '!docker-images/*.md' '!docs/api/**/*.md' - -[testenv:dependencies_check] +[testenv:dependencies-check] skipsdist = True skip_install = True commands = @@ -301,7 +300,6 @@ commands = pip uninstall open-aea -y python {toxinidir}/scripts/check_imports_and_dependencies.py - [testenv:plugins_env] skipsdist = True skip_install = True @@ -313,7 +311,6 @@ commands = - /bin/sh -c "rm -fr ./*private_key.txt" {posargs} - [testenv_multi] basepython = python3 whitelist_externals = /bin/sh @@ -352,7 +349,6 @@ deps = pycryptodome>=3.10.1 cosmpy>=0.4.1,<0.5.0 setuptools==59.6.0 - commands = ; for some reason tox installs aea without respect to the dependencies version specified in seetup.py. at least in CI env ; so install current aea in a normal way @@ -392,4 +388,12 @@ commands = {[plugins]commands} [testenv:plugins-py3.9] basepython = python3.9 deps = {[testenv_multi]deps} -commands = {[plugins]commands} \ No newline at end of file +commands = {[plugins]commands} + +[testenv:generate-api-documentation] +skipsdist = True +skip_install = True +deps = + pydoc-markdown==4.3.2 + open-aea==1.16.0 +commands = {toxinidir}/scripts/generate_api_documentation.py From ec33da9094c1c5ce837f94d4b035841036273047 Mon Sep 17 00:00:00 2001 From: David Minarsch Date: Mon, 22 Aug 2022 18:56:11 +0100 Subject: [PATCH 02/16] chore: fix typos and issues introduced in previous commit --- Makefile | 5 ++++- tox.ini | 11 +++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index e881da9376..3a788cdee9 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,8 @@ clean-build: find . -name '*.egg' -exec rm -fr {} + find . -type d -name __pycache__ -exec rm -rv {} + rm -fr Pipfile.lock + rm -rf plugins/*/build + rm -rf plugins/*/dist .PHONY: clean-docs clean-docs: @@ -105,7 +107,7 @@ release: v := $(shell pip -V | grep virtualenvs) .PHONY: all-checks -all-checks: clean formatters code-checks common-checks security +all-checks: clean formatters code-checks common-checks-1 common-checks-2 security .PHONY: new_env new_env: clean @@ -168,6 +170,7 @@ generators: python -m aea.cli hash all python -m aea.cli hash all --packages-dir=./tests/data/packages tox -e generate-api-documentation + tox -e fix-doc-hashes .PHONY: common-checks-1 common-checks: diff --git a/tox.ini b/tox.ini index 9d82b9e168..b2a8a6e7c2 100644 --- a/tox.ini +++ b/tox.ini @@ -6,7 +6,7 @@ ; we set the associated flag (e.g. for linting we don't need ; the package installation). [tox] -envlist = bandit, safety, black, black-check, isort, isort-check, fix-copyright, check-copyright, hash-check, docs, flake8, liccheck, mypy, pylint, vulture, {plugins-,}py{3.7,3.8,3.9,3.10,3.10-cov}, dependencies-check, package-version-checks, package-dependencies-checks, plugins_deps, check-doc-links-hashes, check-generate-all-protocols, spell-check, generate-api-documentation +envlist = bandit, safety, black, black-check, isort, isort-check, fix-copyright, check-copyright, hash-check, docs, flake8, liccheck, mypy, pylint, vulture, {plugins-,}py{3.7,3.8,3.9,3.10,3.10-cov}, dependencies-check, package-version-checks, package-dependencies-checks, plugins_deps, fix-doc-hashes, check-doc-links-hashes, check-generate-all-protocols, spell-check, generate-api-documentation ; when running locally we don't want to fail for no good reason skip_missing_interpreters = true @@ -259,6 +259,13 @@ deps = darglint==1.8.0 commands = darglint aea benchmark examples libs packages plugins scripts +[testenv:fix-doc-hashes] +skipsdist = True +usedevelop = True +deps = + PyYAML==5.4.1 +commands = python {toxinidir}/scripts/check_doc_ipfs_hashes.py --fix + [testenv:check-doc-links-hashes] skipsdist = True usedevelop = True @@ -394,6 +401,6 @@ commands = {[plugins]commands} skipsdist = True skip_install = True deps = - pydoc-markdown==4.3.2 + pydoc-markdown==4.6.3 open-aea==1.16.0 commands = {toxinidir}/scripts/generate_api_documentation.py From 506536917d25e7a897a28a013ddca5bfab84e134 Mon Sep 17 00:00:00 2001 From: David Minarsch Date: Mon, 22 Aug 2022 19:46:21 +0100 Subject: [PATCH 03/16] fix: some links and commands --- docs/gym-skill.md | 2 +- docs/limits.md | 2 +- examples/gym_ex/proxy/env.py | 6 +++--- tox.ini | 6 ++---- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/docs/gym-skill.md b/docs/gym-skill.md index 8ba38d9036..80004b1c01 100644 --- a/docs/gym-skill.md +++ b/docs/gym-skill.md @@ -1,4 +1,4 @@ -The AEA gym skill demonstrates how a custom Reinforcement Learning agent, that uses OpenAI's gym library, may be embedded into an AEA skill and connection. +The AEA gym skill demonstrates how a custom Reinforcement Learning agent, that uses OpenAI's gym library, may be embedded into an AEA skill and connection. ### Discussion diff --git a/docs/limits.md b/docs/limits.md index 7321449281..677cd10c0b 100644 --- a/docs/limits.md +++ b/docs/limits.md @@ -154,7 +154,7 @@ This could be taken further, and a reduced spec version for Nuitka and it would be desirable to explore how useful and practical this would be in the context of AEA. +Python is not a compiled language. However, various projects attempt this, e.g. Nuitka and it would be desirable to explore how useful and practical this would be in the context of AEA. #### DID integration diff --git a/examples/gym_ex/proxy/env.py b/examples/gym_ex/proxy/env.py index f0a5c0f8ca..25c6cf2453 100755 --- a/examples/gym_ex/proxy/env.py +++ b/examples/gym_ex/proxy/env.py @@ -139,7 +139,7 @@ def step(self, action: Action) -> Feedback: return observation, reward, done, info - def render(self, mode="human") -> None: + def render(self, mode: str = "human") -> None: """ Render the environment. @@ -177,7 +177,7 @@ def close(self) -> None: self._disconnect() - def _connect(self): + def _connect(self) -> None: """Connect to this proxy environment. It starts a proxy agent that can interact with the framework.""" if cast(Thread, self._agent_thread).is_alive(): raise ValueError("Agent already running.") @@ -186,7 +186,7 @@ def _connect(self): while not self._agent.runtime.is_running: # check agent completely running time.sleep(0.01) - def _disconnect(self): + def _disconnect(self) -> None: """Disconnect from this proxy environment. It stops the proxy agent and kills its thread.""" self._agent.stop() cast(Thread, self._agent_thread).join() diff --git a/tox.ini b/tox.ini index b2a8a6e7c2..a9814fb542 100644 --- a/tox.ini +++ b/tox.ini @@ -398,9 +398,7 @@ deps = {[testenv_multi]deps} commands = {[plugins]commands} [testenv:generate-api-documentation] -skipsdist = True -skip_install = True +usedevelop = True deps = pydoc-markdown==4.6.3 - open-aea==1.16.0 -commands = {toxinidir}/scripts/generate_api_documentation.py +commands = {toxinidir}/scripts/generate_api_docs.py From d1cfb981f2f19fc49d12487f9ae8b066c83223b3 Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Tue, 23 Aug 2022 06:02:11 +0000 Subject: [PATCH 04/16] chore: fix mypy errors --- aea/cli/add.py | 2 +- aea/cli/push.py | 2 +- .../aea-cli-ipfs/aea_cli_ipfs/ipfs_utils.py | 8 +-- plugins/aea-cli-ipfs/aea_cli_ipfs/registry.py | 2 +- .../aea_ledger_cosmos/cosmos.py | 4 +- .../aea_ledger_ethereum/ethereum.py | 65 +++++++++++-------- .../aea_ledger_fetchai/_cosmos.py | 4 +- scripts/publish_packages_to_local_registry.py | 4 +- setup.cfg | 12 ++++ 9 files changed, 65 insertions(+), 38 deletions(-) diff --git a/aea/cli/add.py b/aea/cli/add.py index 285409eb72..d83a60d5af 100644 --- a/aea/cli/add.py +++ b/aea/cli/add.py @@ -208,7 +208,7 @@ def fetch_item_remote( if get_default_remote_registry() == REMOTE_IPFS: try: - return fetch_ipfs(item_type, item_public_id, dest_path) + return cast(Path, fetch_ipfs(item_type, item_public_id, dest_path)) except HashNotProvided: click.echo(f"Hash was not provided for: {item_public_id}") click.echo("Will try with http repository.") diff --git a/aea/cli/push.py b/aea/cli/push.py index d7163469d7..b922e808af 100644 --- a/aea/cli/push.py +++ b/aea/cli/push.py @@ -208,7 +208,7 @@ def push_item_ipfs(component_path: Path, public_id: PublicId) -> None: ) ipfs_tool = IPFSTool(get_ipfs_node_multiaddr()) - _, package_hash, _ = ipfs_tool.add(component_path) + _, package_hash, _ = ipfs_tool.add(str(component_path)) package_hash = to_v1(package_hash) click.echo("Pushed component with:") diff --git a/plugins/aea-cli-ipfs/aea_cli_ipfs/ipfs_utils.py b/plugins/aea-cli-ipfs/aea_cli_ipfs/ipfs_utils.py index ab515fd1c8..3a8a157dc1 100644 --- a/plugins/aea-cli-ipfs/aea_cli_ipfs/ipfs_utils.py +++ b/plugins/aea-cli-ipfs/aea_cli_ipfs/ipfs_utils.py @@ -23,7 +23,7 @@ import signal import subprocess # nosec from pathlib import Path -from typing import Dict, List, Optional, Set, Tuple, cast +from typing import Dict, IO, List, Optional, Set, Tuple, cast import ipfshttpclient # type: ignore import requests @@ -163,7 +163,7 @@ def start(self) -> None: env=os.environ.copy(), ) empty_outputs = 0 - for stdout_line in iter(self.process.stdout.readline, ""): + for stdout_line in iter(cast(IO[bytes], self.process.stdout).readline, ""): if b"Daemon is ready" in stdout_line: break if stdout_line == b"": @@ -175,7 +175,7 @@ def stop(self) -> None: # pragma: nocover """Terminate the ipfs daemon if it was started internally.""" if self.process is None: return - self.process.stdout.close() + cast(IO[bytes], self.process.stdout).close() self.process.send_signal(signal.SIGTERM) self.process.wait(timeout=30) poll = self.process.poll() @@ -207,7 +207,7 @@ def __init__(self, addr: Optional[str] = None): if addr is None: addr = os.environ.get("OPEN_AEA_IPFS_ADDR", DEFAULT_IPFS_URL) - _, host, *_ = resolve_addr(addr) # verify addr + _, host, *_ = resolve_addr(cast(str, addr)) # verify addr self._addr = addr self.is_remote = is_remote_addr(host) diff --git a/plugins/aea-cli-ipfs/aea_cli_ipfs/registry.py b/plugins/aea-cli-ipfs/aea_cli_ipfs/registry.py index 1c51e70bbf..66e3b7214a 100644 --- a/plugins/aea-cli-ipfs/aea_cli_ipfs/registry.py +++ b/plugins/aea-cli-ipfs/aea_cli_ipfs/registry.py @@ -164,7 +164,7 @@ def fetch_ipfs( ipfs_tool = IPFSTool(addr=DEFAULT_IPFS_URL_LOCAL) try: - package_hash = public_id.hash + package_hash: Optional[str] = public_id.hash except ValueError: package_hash = ( None if remote else get_ipfs_hash_from_public_id(item_type, public_id) diff --git a/plugins/aea-ledger-cosmos/aea_ledger_cosmos/cosmos.py b/plugins/aea-ledger-cosmos/aea_ledger_cosmos/cosmos.py index 5519d3d7da..b059846ec9 100644 --- a/plugins/aea-ledger-cosmos/aea_ledger_cosmos/cosmos.py +++ b/plugins/aea-ledger-cosmos/aea_ledger_cosmos/cosmos.py @@ -263,7 +263,7 @@ def get_event_attributes(tx_receipt: JSONLike) -> Dict: """ return { i["key"]: i["value"] - for i in chain(*[i["attributes"] for i in tx_receipt["logs"][0]["events"]]) + for i in chain(*[i["attributes"] for i in tx_receipt["logs"][0]["events"]]) # type: ignore } @classmethod @@ -1307,7 +1307,7 @@ def _get_transaction( ) # Get account and signer info for each sender - signer_infos: List[SignerInfo] = [] + signer_infos: List[SignerInfo] = [] # type: ignore sign_data: JSONLike = {} for from_address, pub_key, sequence, account_number in zip( from_addresses, pub_keys, sequences, account_numbers diff --git a/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py b/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py index 1e5396f506..5d688664d7 100644 --- a/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py +++ b/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py @@ -158,7 +158,7 @@ def estimate_priority_fee( fee_history_blocks: int, fee_history_percentile: int, priority_fee_increase_boundary: int, -) -> int: +) -> Optional[int]: """Estimate priority fee from base fee.""" if base_fee_gwei < priority_fee_estimation_trigger: @@ -226,7 +226,7 @@ def eip1559_price_strategy( estimated_priority_fee = estimate_priority_fee( web3, - base_fee_gwei, + cast(int, base_fee_gwei), block_number, priority_fee_estimation_trigger=priority_fee_estimation_trigger, default_priority_fee=default_priority_fee, @@ -244,7 +244,7 @@ def eip1559_price_strategy( max_priority_fee_per_gas = max( estimated_priority_fee, to_wei(default_priority_fee, "gwei") ) - multiplier = get_base_fee_multiplier(base_fee_gwei) + multiplier = get_base_fee_multiplier(cast(int, base_fee_gwei)) potential_max_fee = base_fee * multiplier max_fee_per_gas = ( @@ -271,7 +271,7 @@ def get_gas_price_strategy_eip1559_polygon( gas_endpoint: str, fallback_estimate: Dict[str, Optional[int]], speed: Optional[str] = SPEED_FAST, -) -> Callable[[], Dict[str, Wei]]: +) -> Callable[[Any, Any], Dict[str, Wei]]: """Get the gas price strategy.""" def eip1559_price_strategy( @@ -999,11 +999,11 @@ def _get_gas_price_strategy( return None _default_logger.debug(f"Using strategy: {gas_price_strategy}") - gas_price_strategy_getter = self._gas_price_strategy_callables.get( - gas_price_strategy, None + gas_price_strategy_getter = cast( + Callable, self._gas_price_strategy_callables.get(gas_price_strategy) ) - parameters = DEFAULT_GAS_PRICE_STRATEGIES.get(gas_price_strategy) + parameters = cast(dict, DEFAULT_GAS_PRICE_STRATEGIES.get(gas_price_strategy)) parameters.update(self._gas_price_strategies.get(gas_price_strategy, {})) parameters.update(extra_config or {}) return gas_price_strategy, gas_price_strategy_getter(**parameters) @@ -1287,17 +1287,10 @@ def get_contract_instance( ) return instance - def get_deploy_transaction( # pylint: disable=arguments-differ + def get_deploy_transaction( # pylint: disable=arguments-differ # type: ignore self, contract_interface: Dict[str, str], deployer_address: Address, - value: int = 0, - gas: Optional[int] = None, - max_fee_per_gas: Optional[int] = None, - max_priority_fee_per_gas: Optional[str] = None, - gas_price: Optional[str] = None, - gas_price_strategy: Optional[str] = None, - gas_price_strategy_extra_config: Optional[Dict] = None, raise_on_try: bool = False, **kwargs: Any, ) -> Optional[JSONLike]: @@ -1306,17 +1299,36 @@ def get_deploy_transaction( # pylint: disable=arguments-differ :param contract_interface: the contract interface. :param deployer_address: The address that will deploy the contract. - :param value: value to send to contract (in Wei) - :param gas: the gas to be used (in Wei) - :param max_fee_per_gas: maximum amount you’re willing to pay, inclusive of `baseFeePerGas` and `maxPriorityFeePerGas`. The difference between `maxFeePerGas` and `baseFeePerGas + maxPriorityFeePerGas` is refunded (in Wei). - :param max_priority_fee_per_gas: the part of the fee that goes to the miner (in Wei). - :param gas_price: the gas price (in Wei) - :param gas_price_strategy: the gas price strategy to be used. - :param gas_price_strategy_extra_config: extra config for gas price strategy. :param raise_on_try: whether the method will raise or log on error :param kwargs: keyword arguments :return: the transaction dictionary. """ + + # value to send to contract (in Wei) + value: int = kwargs.pop("value", 0) + + # the gas to be used (in Wei) + gas: Optional[int] = kwargs.pop("gas") + + # maximum amount you’re willing to pay, inclusive of `baseFeePerGas` and + # `maxPriorityFeePerGas`. The difference between `maxFeePerGas` and + # `baseFeePerGas + maxPriorityFeePerGas` is refunded (in Wei). + max_fee_per_gas: Optional[int] = kwargs.pop("max_fee_per_gas") + + # the part of the fee that goes to the miner (in Wei). + max_priority_fee_per_gas: Optional[str] = kwargs.pop("max_priority_fee_per_gas") + + # the gas price (in Wei) + gas_price: Optional[str] = kwargs.pop("gas_price") + + # the gas price strategy to be used. + gas_price_strategy: Optional[str] = kwargs.pop("gas_price_strategy") + + # extra config for gas price strategy. + gas_price_strategy_extra_config: Optional[Dict] = kwargs.pop( + "gas_price_strategy_extra_config" + ) + transaction: Optional[JSONLike] = None _deployer_address = self.api.toChecksumAddress(deployer_address) nonce = self._try_get_transaction_count( @@ -1404,12 +1416,12 @@ def contract_method_call( result = method(**method_args).call() return result - def build_transaction( # pylint: disable=too-many-arguments + def build_transaction( # pylint: disable=too-many-arguments # type: ignore self, contract_instance: Any, method_name: str, - method_args: Dict, - tx_args: Dict, + method_args: Optional[Dict[Any, Any]], + tx_args: Optional[Dict[Any, Any]], raise_on_try: bool = False, ) -> Optional[JSONLike]: """Prepare a transaction @@ -1422,7 +1434,8 @@ def build_transaction( # pylint: disable=too-many-arguments :return: the transaction """ method = getattr(contract_instance.functions, method_name) - tx = method(**method_args) + tx = method(**cast(Dict, method_args)) + tx_args = cast(Dict, tx_args) nonce = self.api.eth.get_transaction_count(tx_args["sender_address"]) tx_params = { diff --git a/plugins/aea-ledger-fetchai/aea_ledger_fetchai/_cosmos.py b/plugins/aea-ledger-fetchai/aea_ledger_fetchai/_cosmos.py index 5519d3d7da..b059846ec9 100644 --- a/plugins/aea-ledger-fetchai/aea_ledger_fetchai/_cosmos.py +++ b/plugins/aea-ledger-fetchai/aea_ledger_fetchai/_cosmos.py @@ -263,7 +263,7 @@ def get_event_attributes(tx_receipt: JSONLike) -> Dict: """ return { i["key"]: i["value"] - for i in chain(*[i["attributes"] for i in tx_receipt["logs"][0]["events"]]) + for i in chain(*[i["attributes"] for i in tx_receipt["logs"][0]["events"]]) # type: ignore } @classmethod @@ -1307,7 +1307,7 @@ def _get_transaction( ) # Get account and signer info for each sender - signer_infos: List[SignerInfo] = [] + signer_infos: List[SignerInfo] = [] # type: ignore sign_data: JSONLike = {} for from_address, pub_key, sequence, account_number in zip( from_addresses, pub_keys, sequences, account_numbers diff --git a/scripts/publish_packages_to_local_registry.py b/scripts/publish_packages_to_local_registry.py index ef36e2268c..37d0b71e78 100644 --- a/scripts/publish_packages_to_local_registry.py +++ b/scripts/publish_packages_to_local_registry.py @@ -55,7 +55,9 @@ def main() -> None: ipfs_tool = IPFSTool(addr="/ip4/127.0.0.1/tcp/5001/http") with IPFSDaemon(): for package_path in packages: - register_package(ipfs_tool=ipfs_tool, dir_path=package_path, no_pin=False) + register_package( + ipfs_tool=ipfs_tool, dir_path=str(package_path), no_pin=False + ) print("Done!") diff --git a/setup.cfg b/setup.cfg index aade6db38f..f45fda84dd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -279,6 +279,18 @@ ignore_missing_imports = True [mypy-multihash.*] ignore_missing_imports = True +[mypy-Crypto.*] +ignore_missing_imports = True + +[mypy-eth_typing.*] +ignore_missing_imports = True + +[mypy-bech32.*] +ignore_missing_imports = True + +[mypy-eth_utils.*] +ignore_missing_imports = True + [darglint] docstring_style=sphinx strictness=short From 104e423ef92602e24d90b72c0593639fe130c4b9 Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Tue, 23 Aug 2022 06:11:15 +0000 Subject: [PATCH 05/16] chore: remove unwanted nocover marker --- plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py b/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py index 5d688664d7..d4408ac6eb 100644 --- a/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py +++ b/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py @@ -1287,7 +1287,7 @@ def get_contract_instance( ) return instance - def get_deploy_transaction( # pylint: disable=arguments-differ # type: ignore + def get_deploy_transaction( # pylint: disable=arguments-differ self, contract_interface: Dict[str, str], deployer_address: Address, From eb2a11b8b5c4cdc1b4e7acb469efb786e58ef633 Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Tue, 23 Aug 2022 06:17:02 +0000 Subject: [PATCH 06/16] chore: update API docs --- .spelling | 5 +++ .../plugins/aea_ledger_ethereum/ethereum.md | 41 ++++++------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/.spelling b/.spelling index 35fd9df774..a05f9c31e2 100644 --- a/.spelling +++ b/.spelling @@ -285,6 +285,11 @@ v0 ipfsdaemon py3.6 async +gnosis +abci +metaclass +abstractroundbehaviour's +api - docs/language-agnostic-definition.md fetchai protocol_id diff --git a/docs/api/plugins/aea_ledger_ethereum/ethereum.md b/docs/api/plugins/aea_ledger_ethereum/ethereum.md index 3fbbe06d8e..0778ac57c4 100644 --- a/docs/api/plugins/aea_ledger_ethereum/ethereum.md +++ b/docs/api/plugins/aea_ledger_ethereum/ethereum.md @@ -39,12 +39,11 @@ Returns multiplier value. #### estimate`_`priority`_`fee ```python -def estimate_priority_fee(web3_object: Web3, base_fee_gwei: int, - block_number: int, - priority_fee_estimation_trigger: int, - default_priority_fee: int, fee_history_blocks: int, - fee_history_percentile: int, - priority_fee_increase_boundary: int) -> int +def estimate_priority_fee( + web3_object: Web3, base_fee_gwei: int, block_number: int, + priority_fee_estimation_trigger: int, default_priority_fee: int, + fee_history_blocks: int, fee_history_percentile: int, + priority_fee_increase_boundary: int) -> Optional[int] ``` Estimate priority fee from base fee. @@ -72,7 +71,8 @@ Get the gas price strategy. def get_gas_price_strategy_eip1559_polygon( gas_endpoint: str, fallback_estimate: Dict[str, Optional[int]], - speed: Optional[str] = SPEED_FAST) -> Callable[[], Dict[str, Wei]] + speed: Optional[str] = SPEED_FAST +) -> Callable[[Any, Any], Dict[str, Wei]] ``` Get the gas price strategy. @@ -793,18 +793,10 @@ the contract instance #### get`_`deploy`_`transaction ```python -def get_deploy_transaction( - contract_interface: Dict[str, str], - deployer_address: Address, - value: int = 0, - gas: Optional[int] = None, - max_fee_per_gas: Optional[int] = None, - max_priority_fee_per_gas: Optional[str] = None, - gas_price: Optional[str] = None, - gas_price_strategy: Optional[str] = None, - gas_price_strategy_extra_config: Optional[Dict] = None, - raise_on_try: bool = False, - **kwargs: Any) -> Optional[JSONLike] +def get_deploy_transaction(contract_interface: Dict[str, str], + deployer_address: Address, + raise_on_try: bool = False, + **kwargs: Any) -> Optional[JSONLike] ``` Get the transaction to deploy the smart contract. @@ -813,13 +805,6 @@ Get the transaction to deploy the smart contract. - `contract_interface`: the contract interface. - `deployer_address`: The address that will deploy the contract. -- `value`: value to send to contract (in Wei) -- `gas`: the gas to be used (in Wei) -- `max_fee_per_gas`: maximum amount you’re willing to pay, inclusive of `baseFeePerGas` and `maxPriorityFeePerGas`. The difference between `maxFeePerGas` and `baseFeePerGas + maxPriorityFeePerGas` is refunded (in Wei). -- `max_priority_fee_per_gas`: the part of the fee that goes to the miner (in Wei). -- `gas_price`: the gas price (in Wei) -- `gas_price_strategy`: the gas price strategy to be used. -- `gas_price_strategy_extra_config`: extra config for gas price strategy. - `raise_on_try`: whether the method will raise or log on error - `kwargs`: keyword arguments @@ -875,8 +860,8 @@ the call result ```python def build_transaction(contract_instance: Any, method_name: str, - method_args: Dict, - tx_args: Dict, + method_args: Optional[Dict[Any, Any]], + tx_args: Optional[Dict[Any, Any]], raise_on_try: bool = False) -> Optional[JSONLike] ``` From 2db4fda93a7a6ab8ac54f3d413a67322af8acb0e Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Tue, 23 Aug 2022 06:45:35 +0000 Subject: [PATCH 07/16] fix: replace pop with get --- .../aea_ledger_ethereum/ethereum.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py b/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py index d4408ac6eb..b8504a4834 100644 --- a/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py +++ b/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py @@ -1305,27 +1305,27 @@ def get_deploy_transaction( # pylint: disable=arguments-differ """ # value to send to contract (in Wei) - value: int = kwargs.pop("value", 0) + value: int = kwargs.get("value", 0) # the gas to be used (in Wei) - gas: Optional[int] = kwargs.pop("gas") + gas: Optional[int] = kwargs.get("gas") # maximum amount you’re willing to pay, inclusive of `baseFeePerGas` and # `maxPriorityFeePerGas`. The difference between `maxFeePerGas` and # `baseFeePerGas + maxPriorityFeePerGas` is refunded (in Wei). - max_fee_per_gas: Optional[int] = kwargs.pop("max_fee_per_gas") + max_fee_per_gas: Optional[int] = kwargs.get("max_fee_per_gas") # the part of the fee that goes to the miner (in Wei). - max_priority_fee_per_gas: Optional[str] = kwargs.pop("max_priority_fee_per_gas") + max_priority_fee_per_gas: Optional[str] = kwargs.get("max_priority_fee_per_gas") # the gas price (in Wei) - gas_price: Optional[str] = kwargs.pop("gas_price") + gas_price: Optional[str] = kwargs.get("gas_price") # the gas price strategy to be used. - gas_price_strategy: Optional[str] = kwargs.pop("gas_price_strategy") + gas_price_strategy: Optional[str] = kwargs.get("gas_price_strategy") # extra config for gas price strategy. - gas_price_strategy_extra_config: Optional[Dict] = kwargs.pop( + gas_price_strategy_extra_config: Optional[Dict] = kwargs.get( "gas_price_strategy_extra_config" ) From 2e35279bf0f14f26a463ff7cba147d6e5b78761c Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Tue, 23 Aug 2022 09:00:48 +0000 Subject: [PATCH 08/16] test: fix eip tests --- .../aea_ledger_ethereum/ethereum.py | 19 +++++++++++-------- .../tests/test_ethereum_contract.py | 10 +++++----- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py b/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py index b8504a4834..f2c85cf66c 100644 --- a/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py +++ b/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py @@ -262,6 +262,7 @@ def eip1559_price_strategy( return { "maxFeePerGas": round_to_whole_gwei(max_fee_per_gas), "maxPriorityFeePerGas": round_to_whole_gwei(max_priority_fee_per_gas), + "baseFee": None, } return eip1559_price_strategy @@ -1305,28 +1306,30 @@ def get_deploy_transaction( # pylint: disable=arguments-differ """ # value to send to contract (in Wei) - value: int = kwargs.get("value", 0) + value: int = kwargs.pop("value", 0) # the gas to be used (in Wei) - gas: Optional[int] = kwargs.get("gas") + gas: Optional[int] = kwargs.pop("gas", None) # maximum amount you’re willing to pay, inclusive of `baseFeePerGas` and # `maxPriorityFeePerGas`. The difference between `maxFeePerGas` and # `baseFeePerGas + maxPriorityFeePerGas` is refunded (in Wei). - max_fee_per_gas: Optional[int] = kwargs.get("max_fee_per_gas") + max_fee_per_gas: Optional[int] = kwargs.pop("max_fee_per_gas", None) # the part of the fee that goes to the miner (in Wei). - max_priority_fee_per_gas: Optional[str] = kwargs.get("max_priority_fee_per_gas") + max_priority_fee_per_gas: Optional[str] = kwargs.pop( + "max_priority_fee_per_gas", None + ) # the gas price (in Wei) - gas_price: Optional[str] = kwargs.get("gas_price") + gas_price: Optional[str] = kwargs.pop("gas_price", None) # the gas price strategy to be used. - gas_price_strategy: Optional[str] = kwargs.get("gas_price_strategy") + gas_price_strategy: Optional[str] = kwargs.pop("gas_price_strategy", None) # extra config for gas price strategy. - gas_price_strategy_extra_config: Optional[Dict] = kwargs.get( - "gas_price_strategy_extra_config" + gas_price_strategy_extra_config: Optional[Dict] = kwargs.pop( + "gas_price_strategy_extra_config", None ) transaction: Optional[JSONLike] = None diff --git a/plugins/aea-ledger-ethereum/tests/test_ethereum_contract.py b/plugins/aea-ledger-ethereum/tests/test_ethereum_contract.py index 21cb703a5d..cf66f4d0ca 100644 --- a/plugins/aea-ledger-ethereum/tests/test_ethereum_contract.py +++ b/plugins/aea-ledger-ethereum/tests/test_ethereum_contract.py @@ -41,14 +41,14 @@ def test_get_contract_instance(ethereum_testnet_config, ganache): tx = ethereum_api.get_deploy_transaction( contract_interface, ec.address, - 0, + value=0, max_priority_fee_per_gas=1000000000, max_fee_per_gas=1000000000, ) tx = ethereum_api.get_deploy_transaction( contract_interface, ec.address, - 0, + value=0, gas=1000000, max_priority_fee_per_gas=1000000000, max_fee_per_gas=1000000000, @@ -83,7 +83,7 @@ def test_gas_station_strategy(ethereum_testnet_config, ganache): full_path = Path(ROOT_DIR, "tests", "data", "dummy_contract", "build", "some.json") contract_interface = ethereum_api.load_contract_interface(full_path) tx = ethereum_api.get_deploy_transaction( - contract_interface, ec.address, 0, gas_price_strategy="gas_station" + contract_interface, ec.address, value=0, gas_price_strategy="gas_station" ) assert all( [ @@ -93,7 +93,7 @@ def test_gas_station_strategy(ethereum_testnet_config, ganache): ) -@pytest.mark.flaky(reruns=MAX_FLAKY_RERUNS) +# @pytest.mark.flaky(reruns=MAX_FLAKY_RERUNS) @pytest.mark.integration @pytest.mark.ledger def test_eip1559_strategy(ethereum_testnet_config, ganache): @@ -104,7 +104,7 @@ def test_eip1559_strategy(ethereum_testnet_config, ganache): full_path = Path(ROOT_DIR, "tests", "data", "dummy_contract", "build", "some.json") contract_interface = ethereum_api.load_contract_interface(full_path) tx = ethereum_api.get_deploy_transaction( - contract_interface, ec.address, 0, gas_price_strategy="eip1559" + contract_interface, ec.address, value=0, gas_price_strategy="eip1559" ) logging.info(tx.keys()) assert all( From e1e756e9cd4568c8ebb0cf8529a2d5711437e4a4 Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Tue, 23 Aug 2022 09:02:40 +0000 Subject: [PATCH 09/16] chore: uncomment flaky mark --- plugins/aea-ledger-ethereum/tests/test_ethereum_contract.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/aea-ledger-ethereum/tests/test_ethereum_contract.py b/plugins/aea-ledger-ethereum/tests/test_ethereum_contract.py index cf66f4d0ca..414e59cc36 100644 --- a/plugins/aea-ledger-ethereum/tests/test_ethereum_contract.py +++ b/plugins/aea-ledger-ethereum/tests/test_ethereum_contract.py @@ -93,7 +93,7 @@ def test_gas_station_strategy(ethereum_testnet_config, ganache): ) -# @pytest.mark.flaky(reruns=MAX_FLAKY_RERUNS) +@pytest.mark.flaky(reruns=MAX_FLAKY_RERUNS) @pytest.mark.integration @pytest.mark.ledger def test_eip1559_strategy(ethereum_testnet_config, ganache): From be2481550c630a04f3ea5674c34308d9feada99d Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Tue, 23 Aug 2022 09:05:19 +0000 Subject: [PATCH 10/16] chore: remove unwanted nocover mark --- plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py b/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py index f2c85cf66c..818b9b3b20 100644 --- a/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py +++ b/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py @@ -1419,7 +1419,7 @@ def contract_method_call( result = method(**method_args).call() return result - def build_transaction( # pylint: disable=too-many-arguments # type: ignore + def build_transaction( # pylint: disable=too-many-arguments self, contract_instance: Any, method_name: str, From 563aa212dff256eacd59b7299e428a86e4ed7a54 Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Tue, 23 Aug 2022 10:11:32 +0000 Subject: [PATCH 11/16] feat: raise issues where None variables are not handled properly --- plugins/aea-cli-ipfs/aea_cli_ipfs/ipfs_utils.py | 9 ++++++++- .../aea_ledger_ethereum/ethereum.py | 14 +++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/plugins/aea-cli-ipfs/aea_cli_ipfs/ipfs_utils.py b/plugins/aea-cli-ipfs/aea_cli_ipfs/ipfs_utils.py index 3a8a157dc1..a3647d0ff0 100644 --- a/plugins/aea-cli-ipfs/aea_cli_ipfs/ipfs_utils.py +++ b/plugins/aea-cli-ipfs/aea_cli_ipfs/ipfs_utils.py @@ -163,6 +163,10 @@ def start(self) -> None: env=os.environ.copy(), ) empty_outputs = 0 + + if self.process.stdout is None: + raise RuntimeError("Could not start IPFS daemon.") + for stdout_line in iter(cast(IO[bytes], self.process.stdout).readline, ""): if b"Daemon is ready" in stdout_line: break @@ -175,7 +179,10 @@ def stop(self) -> None: # pragma: nocover """Terminate the ipfs daemon if it was started internally.""" if self.process is None: return - cast(IO[bytes], self.process.stdout).close() + + if self.process.stdout is not None: + self.process.stdout.close() + self.process.send_signal(signal.SIGTERM) self.process.wait(timeout=30) poll = self.process.poll() diff --git a/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py b/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py index 818b9b3b20..314dbb31ae 100644 --- a/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py +++ b/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py @@ -1000,9 +1000,9 @@ def _get_gas_price_strategy( return None _default_logger.debug(f"Using strategy: {gas_price_strategy}") - gas_price_strategy_getter = cast( - Callable, self._gas_price_strategy_callables.get(gas_price_strategy) - ) + gas_price_strategy_getter = self._gas_price_strategy_callables[ + gas_price_strategy + ] parameters = cast(dict, DEFAULT_GAS_PRICE_STRATEGIES.get(gas_price_strategy)) parameters.update(self._gas_price_strategies.get(gas_price_strategy, {})) @@ -1436,8 +1436,16 @@ def build_transaction( # pylint: disable=too-many-arguments :param raise_on_try: whether the method will raise or log on error :return: the transaction """ + + if method_args is None: + raise ValueError("Argument 'method_args' cannot be 'None'.") + method = getattr(contract_instance.functions, method_name) tx = method(**cast(Dict, method_args)) + + if tx_args is None: + raise ValueError("Argument 'tx_args' cannot be 'None'.") + tx_args = cast(Dict, tx_args) nonce = self.api.eth.get_transaction_count(tx_args["sender_address"]) From 04c1fb18bc903f3c9039a14967b284270e6d45e2 Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Tue, 23 Aug 2022 11:54:46 +0000 Subject: [PATCH 12/16] fix: gas pricing test --- plugins/aea-ledger-ethereum/tests/test_ethereum.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/aea-ledger-ethereum/tests/test_ethereum.py b/plugins/aea-ledger-ethereum/tests/test_ethereum.py index cd60326567..6a642ca1e9 100644 --- a/plugins/aea-ledger-ethereum/tests/test_ethereum.py +++ b/plugins/aea-ledger-ethereum/tests/test_ethereum.py @@ -485,9 +485,9 @@ def test_gas_price_strategy_eip1559() -> None: with get_block_mock: with fee_history_mock: gas_stregy = callable_(web3, "tx_params") + gas_stregy.pop("baseFee") assert all([key in gas_stregy for key in ["maxFeePerGas", "maxPriorityFeePerGas"]]) - assert all([value > 1e8 for value in gas_stregy.values()]) @@ -818,6 +818,7 @@ def test_try_get_gas_pricing( # test gas pricing gas_price = ethereum_api.try_get_gas_pricing(gas_price_strategy=strategy["name"]) + gas_price.pop("baseFee", None) assert set(strategy["params"]) == set(gas_price.keys()) assert all( gas_price[param] > 0 and isinstance(gas_price[param], int) @@ -828,6 +829,7 @@ def test_try_get_gas_pricing( gas_reprice = ethereum_api.try_get_gas_pricing( gas_price_strategy=strategy["name"], old_price=gas_price ) + gas_reprice.pop("baseFee", None) assert all( gas_reprice[param] > 0 and isinstance(gas_reprice[param], int) for param in strategy["params"] From 16bf4a96913d311cb7f64b1217f875e5840d0d69 Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Tue, 23 Aug 2022 13:23:45 +0000 Subject: [PATCH 13/16] test: update ethereum plugin tests --- .../tests/test_ethereum.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/plugins/aea-ledger-ethereum/tests/test_ethereum.py b/plugins/aea-ledger-ethereum/tests/test_ethereum.py index 6a642ca1e9..710d2859e7 100644 --- a/plugins/aea-ledger-ethereum/tests/test_ethereum.py +++ b/plugins/aea-ledger-ethereum/tests/test_ethereum.py @@ -23,6 +23,7 @@ import logging import math import random +import re import tempfile import time from pathlib import Path @@ -674,6 +675,25 @@ def pass_tx_params(tx_params): eth_api = EthereumApi(**ethereum_testnet_config) + with pytest.raises( + ValueError, match=re.escape("Argument 'method_args' cannot be 'None'.") + ): + eth_api.build_transaction( + contract_instance=contract_instance, + method_name="dummy_method", + method_args=None, + tx_args={}, + ) + with pytest.raises( + ValueError, match=re.escape("Argument 'tx_args' cannot be 'None'.") + ): + eth_api.build_transaction( + contract_instance=contract_instance, + method_name="dummy_method", + method_args={}, + tx_args=None, + ) + with mock.patch( "web3.eth.Eth.get_transaction_count", return_value=0, From 505768dd119a7b6a5230c5521f6ee9f874535aac Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Tue, 23 Aug 2022 13:48:05 +0000 Subject: [PATCH 14/16] feat: remove unused `baseFee` param --- .../aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py | 2 -- plugins/aea-ledger-ethereum/tests/test_ethereum.py | 7 ------- .../aea-ledger-ethereum/tests/test_ethereum_contract.py | 1 - 3 files changed, 10 deletions(-) diff --git a/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py b/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py index 818b9b3b20..956e8dd50c 100644 --- a/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py +++ b/plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py @@ -91,7 +91,6 @@ FALLBACK_ESTIMATE = { "maxFeePerGas": to_wei(20, "gwei"), "maxPriorityFeePerGas": to_wei(DEFAULT_PRIORITY_FEE, "gwei"), - "baseFee": None, } PRIORITY_FEE_INCREASE_BOUNDARY = 200 # percentage @@ -262,7 +261,6 @@ def eip1559_price_strategy( return { "maxFeePerGas": round_to_whole_gwei(max_fee_per_gas), "maxPriorityFeePerGas": round_to_whole_gwei(max_priority_fee_per_gas), - "baseFee": None, } return eip1559_price_strategy diff --git a/plugins/aea-ledger-ethereum/tests/test_ethereum.py b/plugins/aea-ledger-ethereum/tests/test_ethereum.py index 6a642ca1e9..468291296a 100644 --- a/plugins/aea-ledger-ethereum/tests/test_ethereum.py +++ b/plugins/aea-ledger-ethereum/tests/test_ethereum.py @@ -485,7 +485,6 @@ def test_gas_price_strategy_eip1559() -> None: with get_block_mock: with fee_history_mock: gas_stregy = callable_(web3, "tx_params") - gas_stregy.pop("baseFee") assert all([key in gas_stregy for key in ["maxFeePerGas", "maxPriorityFeePerGas"]]) assert all([value > 1e8 for value in gas_stregy.values()]) @@ -518,8 +517,6 @@ def test_gas_price_strategy_eip1559_estimate_none() -> None: assert all([key in gas_stregy for key in ["maxFeePerGas", "maxPriorityFeePerGas"]]) - assert gas_stregy["baseFee"] is None - def test_gas_price_strategy_eip1559_fallback() -> None: """Test eip1559 based gas price strategy.""" @@ -550,8 +547,6 @@ def test_gas_price_strategy_eip1559_fallback() -> None: assert all([key in gas_stregy for key in ["maxFeePerGas", "maxPriorityFeePerGas"]]) - assert gas_stregy["baseFee"] is None - def test_gas_price_strategy_eth_gasstation(): """Test the gas price strategy when using eth gasstation.""" @@ -818,7 +813,6 @@ def test_try_get_gas_pricing( # test gas pricing gas_price = ethereum_api.try_get_gas_pricing(gas_price_strategy=strategy["name"]) - gas_price.pop("baseFee", None) assert set(strategy["params"]) == set(gas_price.keys()) assert all( gas_price[param] > 0 and isinstance(gas_price[param], int) @@ -829,7 +823,6 @@ def test_try_get_gas_pricing( gas_reprice = ethereum_api.try_get_gas_pricing( gas_price_strategy=strategy["name"], old_price=gas_price ) - gas_reprice.pop("baseFee", None) assert all( gas_reprice[param] > 0 and isinstance(gas_reprice[param], int) for param in strategy["params"] diff --git a/plugins/aea-ledger-ethereum/tests/test_ethereum_contract.py b/plugins/aea-ledger-ethereum/tests/test_ethereum_contract.py index 414e59cc36..a917c01b55 100644 --- a/plugins/aea-ledger-ethereum/tests/test_ethereum_contract.py +++ b/plugins/aea-ledger-ethereum/tests/test_ethereum_contract.py @@ -117,7 +117,6 @@ def test_eip1559_strategy(ethereum_testnet_config, ganache): "nonce", "maxFeePerGas", "maxPriorityFeePerGas", - "baseFee", "data", "from", ] From 0b46f8a9acdfdf003cdeb4f19ae2b1718bd8b208 Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Wed, 24 Aug 2022 05:15:13 +0000 Subject: [PATCH 15/16] chore: fix .spelling file --- .spelling | 1 - 1 file changed, 1 deletion(-) diff --git a/.spelling b/.spelling index a05f9c31e2..e0116246e2 100644 --- a/.spelling +++ b/.spelling @@ -288,7 +288,6 @@ async gnosis abci metaclass -abstractroundbehaviour's api - docs/language-agnostic-definition.md fetchai From d4884bc7f76ed6ced78cb721b9a17d48e592c6dc Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Wed, 24 Aug 2022 10:19:42 +0000 Subject: [PATCH 16/16] chore: spell check --- .spelling | 1 + 1 file changed, 1 insertion(+) diff --git a/.spelling b/.spelling index e0116246e2..72f02e5327 100644 --- a/.spelling +++ b/.spelling @@ -289,6 +289,7 @@ gnosis abci metaclass api +gitleaks - docs/language-agnostic-definition.md fetchai protocol_id