Skip to content

Commit 8d1d53d

Browse files
committed
Rename 'factories' to 'factory' and expose all factories at top-level
Address review comments.
1 parent 4900468 commit 8d1d53d

File tree

4 files changed

+42
-24
lines changed

4 files changed

+42
-24
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ Example usage:
2222

2323
```python
2424
from web3 import Web3
25-
from autonity import networks
26-
from autonity.factories import Autonity, Liquid
25+
from autonity import Autonity, Liquid, networks
2726

2827
# Connect to the default RPC provider on the Autonity Piccadilly Testnet
2928
w3 = Web3(networks.piccadilly.http_provider)
@@ -82,7 +81,7 @@ can be reviewed to determine which methods have been modified, removed or
8281
added. The generated Python bindings include the contract ABIs as Python dictionaries.
8382

8483
If there is a new contract to include, add a new target to `Makefile` and a new
85-
factory function to `autonity/factories.py`.
84+
factory function to `autonity/factories.py` and `autonity/__init__.py`.
8685

8786
## Reporting a Vulnerability
8887

autonity/__init__.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@
22

33
"""Package for interacting with the protocol contracts of the Autonity network."""
44

5-
from . import constants, contracts, factories, networks
5+
from . import constants, contracts, networks
6+
from .factory import (
7+
Accountability,
8+
ACU,
9+
Autonity,
10+
InflationController,
11+
Liquid,
12+
NonStakableVesting,
13+
Oracle,
14+
Stabilization,
15+
SupplyControl,
16+
UpgradeManager,
17+
)
618

7-
__all__ = ("constants", "contracts", "factories", "networks")
19+
__all__ = (
20+
"constants",
21+
"contracts",
22+
"networks",
23+
"Accountability",
24+
"ACU",
25+
"Autonity",
26+
"InflationController",
27+
"Liquid",
28+
"NonStakableVesting",
29+
"Oracle",
30+
"Stabilization",
31+
"SupplyControl",
32+
"UpgradeManager",
33+
)

tests/test_sanity.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# type: ignore
2+
13
from enum import IntEnum
24
from inspect import isclass, signature
35
from typing import Callable, List
@@ -8,23 +10,14 @@
810
from web3.exceptions import ContractLogicError, ContractPanicError
911
from web3.contract.contract import ContractFunction
1012

11-
from autonity import factories, networks
13+
import autonity
1214
from autonity.constants import AUTONITY_CONTRACT_ADDRESS
1315
from autonity.contracts import ierc20
1416

1517

16-
BINDINGS = [
17-
factories.Accountability,
18-
factories.ACU,
19-
factories.Autonity,
20-
factories.InflationController,
21-
factories.Liquid,
22-
factories.NonStakableVesting,
23-
factories.Oracle,
24-
factories.Stabilization,
25-
factories.SupplyControl,
26-
factories.UpgradeManager,
27-
ierc20.IERC20,
18+
FACTORIES = [attr for attr in autonity.__dict__.values() if isinstance(attr, Callable)]
19+
BINDINGS = FACTORIES + [
20+
ierc20.IERC20, # IERC20 is used internally by aut-cli, not part of the public API
2821
]
2922

3023
TEST_INPUTS = {
@@ -47,16 +40,16 @@ def pytest_generate_tests(metafunc):
4740
ids = []
4841

4942
for binding in BINDINGS:
50-
w3 = Web3(networks.piccadilly.http_provider)
43+
w3 = Web3(autonity.networks.piccadilly.http_provider)
5144

5245
if binding.__name__ == "Liquid":
53-
autonity = factories.Autonity(w3)
54-
validator = autonity.get_validator(autonity.get_validators()[0])
55-
contract = binding(w3, validator.liquid_contract) # type: ignore
46+
aut = autonity.Autonity(w3)
47+
validator = aut.get_validator(aut.get_validators()[0])
48+
contract = binding(w3, validator.liquid_contract)
5649
elif binding.__name__ == "IERC20":
57-
contract = binding(w3, AUTONITY_CONTRACT_ADDRESS) # type: ignore
50+
contract = binding(w3, AUTONITY_CONTRACT_ADDRESS)
5851
else:
59-
contract = binding(w3) # type: ignore
52+
contract = binding(w3)
6053

6154
for attr_name in dir(contract):
6255
if attr_name.startswith("_"):

0 commit comments

Comments
 (0)