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
4 changes: 2 additions & 2 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
- "3.10"
- "3.11"
os:
- ubuntu-20.04
- ubuntu-22.04
poetry-version:
- 2.0.1
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
env:
PYTHONPATH: .
steps:
Expand Down
18 changes: 18 additions & 0 deletions auto_dev/contracts/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
from copy import deepcopy
from pathlib import Path
from textwrap import dedent

import yaml
from web3 import Web3
Expand Down Expand Up @@ -204,13 +205,30 @@ def update_all(self) -> None:
self.update_contract_yaml()
self.update_contract_py()
self.update_contract_init__()
self.ensure_test_file()

# format and lint the contract
paths = get_paths(self.path)
single_thread_lint(paths, verbose=True, logger=get_logger())
single_thread_fmt(paths, verbose=True, logger=get_logger())
single_thread_lint(paths, verbose=True, logger=get_logger())

def ensure_test_file(self) -> None:
"""Ensure the test file exists."""
test_path = self.path / "tests" / f"test_{self.name}.py"
if test_path.exists():
return
test_path.parent.mkdir(parents=True, exist_ok=True)

test_template = dedent(f"""{HEADER}
'''This module contains the tests for the {self.name} contract.'''
def test_{self.name.lower()}_contract():
'''Test the {self.name} contract.'''
assert True
""")

write_to_file(str(test_path), test_template, FileType.TEXT)

def scaffold_read_function(self, function):
"""Scaffold a read function."""
return ContractFunction(function, FunctionType.READ)
Expand Down
17 changes: 12 additions & 5 deletions auto_dev/contracts/contract_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from auto_dev.utils import camel_to_snake
from auto_dev.contracts.utils import SOLIDITY_TO_PYTHON_TYPES
from auto_dev.contracts.variable import Variable
from auto_dev.contracts.contract_templates import EVENT_TEMPLATE
from auto_dev.contracts.contract_templates import EVENT_TEMPLATE, GENERIC_EVENT_TEMPLATE


@dataclass
Expand Down Expand Up @@ -35,11 +35,18 @@ def inputs_with_types(self):

def to_string(self):
"""Return the event as a string."""
return EVENT_TEMPLATE.substitute(
name=camel_to_snake(self.name),
params=("=None,".join([var.to_str_params() for var in self.vars()])) + "=None",
kwargs = {}
if self.vars():
kwargs=dict(params=("=None,".join([var.to_str_params() for var in self.vars()])) + "=None",
args=",".join([var.to_str_arg() for var in self.vars()]),
keywords=", ".join(v.to_key_value() for v in self.vars()))
template = EVENT_TEMPLATE
else:
template = GENERIC_EVENT_TEMPLATE

return template.substitute(
name=camel_to_snake(self.name),
python_names=",".join([var.python_name() for var in self.vars()]),
keywords=", ".join(v.to_key_value() for v in self.vars()),
camel_name=self.name,
**kwargs
)
29 changes: 29 additions & 0 deletions auto_dev/contracts/contract_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,35 @@ def get_${name}_events(
}
"""
)
GENERIC_EVENT_TEMPLATE: Template = Template(
"""
@classmethod
def get_${name}_events(
cls,
ledger_api: LedgerApi,
contract_address: str,
look_back: int=1000,
to_block: str="latest",
from_block: int=None
) -> JSONLike:
\"\"\"Handler method for the '$camel_name' events .\"\"\"

instance = cls.get_instance(ledger_api, contract_address)
to_block = to_block or "latest"
if to_block == "latest":
to_block = ledger_api.api.eth.block_number
from_block = from_block or (to_block - look_back)
result = instance.events.$camel_name().get_logs(
fromBlock=from_block,
toBlock=to_block,
)
return {
"events": result,
"from_block": from_block,
"to_block": to_block,
}
"""
)


READ_TEST_CASES = [
Expand Down
2 changes: 1 addition & 1 deletion auto_dev/data/repo/templates/autonomy/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function setup_autonomy() {
# Extract author from config file with fallback to ci
author=$(grep "^author:" ~/.aea/cli_config.yaml 2>/dev/null | sed 's/author:[[:space:]]*//') || author="ci"

poetry run aea init --remote --author $author > /dev/null || exit 1
poetry run aea init --ipfs --remote --author $author > /dev/null || exit 1
echo 'Done initializing the author and remote for aea using the author: ' $author
echo 'To change the author, run the command;
`poetry run aea init --remote --author <author>`'
Expand Down
4 changes: 0 additions & 4 deletions contract_list.yaml

This file was deleted.

Loading
Loading