Skip to content

Commit

Permalink
style: ci lint with black
Browse files Browse the repository at this point in the history
  • Loading branch information
gosuto-inzasheru authored and github-actions[bot] committed Apr 21, 2024
1 parent cf98a90 commit c302e41
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 66 deletions.
7 changes: 5 additions & 2 deletions bal_addresses/errors.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@

class MultipleMatchesError(Exception):
pass


class NoResultError(Exception):
pass


class ChecksumError(Exception):
pass


class GraphQLRequestError(Exception):
pass


class UnexpectedListLengthError(Exception):
pass
pass
38 changes: 23 additions & 15 deletions bal_addresses/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
class BalPermissions:
def __init__(self, chain):
self.chain = chain
self.active_permissions_by_action_id = requests.get(f"{GITHUB_RAW_OUTPUTS}/permissions/active/{chain}.json").json()
self.action_ids_by_contract_by_deployment = requests.get(f"{GITHUB_DEPLOYMENTS_RAW}/action-ids/{chain}/action-ids.json").json()
self.active_permissions_by_action_id = requests.get(
f"{GITHUB_RAW_OUTPUTS}/permissions/active/{chain}.json"
).json()
self.action_ids_by_contract_by_deployment = requests.get(
f"{GITHUB_DEPLOYMENTS_RAW}/action-ids/{chain}/action-ids.json"
).json()

# Define
self.paths_by_action_id = defaultdict(set)
Expand All @@ -23,7 +27,9 @@ def __init__(self, chain):
for contract, contract_data in contracts.items():
for fx, action_id in contract_data["actionIds"].items():
path = f"{deployment}/{contract}/{fx}"
assert path not in self.action_id_by_path.values(), f"{path} shows up twice?"
assert (
path not in self.action_id_by_path.values()
), f"{path} shows up twice?"
self.action_id_by_path[path] = action_id
self.deployments_by_fx[fx].add(deployment)
self.contracts_by_fx[fx].add(contract)
Expand All @@ -35,30 +41,35 @@ def search_path(self, substr) -> list[str]:
results = [path for path in search if path in self.action_id_by_path]
return results

def search_many_paths_by_unique_deployment(self, deployment_substr, fx_substr) -> list[dict[str, str]]:
def search_many_paths_by_unique_deployment(
self, deployment_substr, fx_substr
) -> list[dict[str, str]]:
a = AddrBook(self.chain)
results = []
deployment = a.search_unique_deployment(deployment_substr)
deployment_fxs = self.search_path(deployment.deployment)
search = [s for s in deployment_fxs if fx_substr in s]
for r in search:
result = Munch.fromDict({
"path": r,
"action_id": self.action_id_by_path[r]
})
result = Munch.fromDict({"path": r, "action_id": self.action_id_by_path[r]})
results.append(result)
return Munch.fromDict(results)

def search_unique_path_by_unique_deployment(self, deployment_substr, fx_substr) -> dict[str, str]:
results = self.search_many_paths_by_unique_deployment(deployment_substr, fx_substr)
def search_unique_path_by_unique_deployment(
self, deployment_substr, fx_substr
) -> dict[str, str]:
results = self.search_many_paths_by_unique_deployment(
deployment_substr, fx_substr
)
if len(results) > 1:
raise MultipleMatchesError(f"{fx_substr} Multiple matches found: {results}")
if len(results) < 1:
raise NoResultError(f"{fx_substr}")
return results[0]

def needs_authorizer(self, contract, deployment) -> bool:
return self.action_ids_by_contract_by_deployment[deployment][contract]["useAdaptor"]
return self.action_ids_by_contract_by_deployment[deployment][contract][
"useAdaptor"
]

def allowed_addresses(self, action_id) -> list[str]:
try:
Expand All @@ -72,8 +83,5 @@ def allowed_caller_names(self, action_id) -> list[str]:
addresslist = self.active_permissions_by_action_id[action_id]
except KeyError:
raise NoResultError(f"{action_id} has no authorized callers")
names = [a.flatbook.get(item, 'undef') for item in addresslist]
names = [a.flatbook.get(item, "undef") for item in addresslist]
return names



6 changes: 4 additions & 2 deletions bal_addresses/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

### These functions are to deal with differing web3 versions and the need to use 5.x for legacy brownie code
def to_checksum_address(address: str):
if hasattr(Web3, 'toChecksumAddress'):
if hasattr(Web3, "toChecksumAddress"):
return Web3.toChecksumAddress(address)
if hasattr(Web3, "to_checksum_address"):
return Web3.to_checksum_address(address)


def is_address(address: str):
if hasattr(Web3, "isAddress"):
return Web3.isAddress(address)
if hasattr(Web3, "is_address"):
return Web3.isAddress(address)
return Web3.isAddress(address)
2 changes: 1 addition & 1 deletion gen_mono_addressbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ def process_deployments(deployments, old=False):


if __name__ == "__main__":
main()
main()
21 changes: 14 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from setuptools import setup, find_packages

VERSION = '0.9.1'
DESCRIPTION = 'Balancer Maxi Addressbook'
LONG_DESCRIPTION = 'Balancer Maxi Addressbook and Balancer Permissions helper'
VERSION = "0.9.1"
DESCRIPTION = "Balancer Maxi Addressbook"
LONG_DESCRIPTION = "Balancer Maxi Addressbook and Balancer Permissions helper"

# Setting up
setup(
Expand All @@ -14,15 +14,22 @@
long_description=LONG_DESCRIPTION,
packages=find_packages(),
include_package_data=True, # Automatically include non-Python files
package_data={'': ['graphql/**/*.gql', 'abis/*.json']},
package_data={"": ["graphql/**/*.gql", "abis/*.json"]},
url="https://github.com/BalancerMaxis/bal_addresses",
install_requires=["setuptools>=42", "wheel", "munch==4.0.0", "web3", "gql[requests]", "requests"],
keywords=['python', 'first package'],
install_requires=[
"setuptools>=42",
"wheel",
"munch==4.0.0",
"web3",
"gql[requests]",
"requests",
],
keywords=["python", "first package"],
classifiers=[
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3.9",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: Linux",
]
],
)
62 changes: 23 additions & 39 deletions tests/test_addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_deployments_populated():
"/bal_addresses/main/outputs/deployments.json",
json={
"BFactory": "0x9424B1412450D0f8Fc2255FAf6046b98213B76Bd",
}
},
)
responses.add(
responses.GET,
Expand All @@ -23,32 +23,29 @@ def test_deployments_populated():
"contracts": [
{
"name": "Vault",
"address": "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
"address": "0xBA12222222228d8Ba445958a75a0704d566BF2C8",
},
{
"name": "BalancerHelpers",
"address": "0x5aDDCCa35b7A0D07C74063c48700C8590E87864E"
"address": "0x5aDDCCa35b7A0D07C74063c48700C8590E87864E",
},
{
"name": "ProtocolFeesCollector",
"address": "0xce88686553686DA562CE7Cea497CE749DA109f9F"
}
"address": "0xce88686553686DA562CE7Cea497CE749DA109f9F",
},
],
"status": "ACTIVE"
"status": "ACTIVE",
}
}
},
)
responses.add(
responses.GET,
"https://raw.githubusercontent.com/BalancerMaxis"
"/bal_addresses/main/extras/mainnet.json",
json={
"zero": {
"zero": "0x0000000000000000000000000000000000000000"
},
"balancer": {}

}
"zero": {"zero": "0x0000000000000000000000000000000000000000"},
"balancer": {},
},
)
responses.add(
responses.GET,
Expand All @@ -58,15 +55,16 @@ def test_deployments_populated():
"mainnet": {
"dao": "0x10A19e7eE7d7F8a52822f6817de8ea18204F2e4f",
}
}
},
)
a = AddrBook("mainnet")

a.populate_deployments()
assert a.deployments.vault.status == "ACTIVE"
assert a.deployments.vault.contracts.Vault.name == "Vault"
assert (
a.deployments.vault.contracts.Vault.address == "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
a.deployments.vault.contracts.Vault.address
== "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
)
assert a.deployments.vault.contracts.BalancerHelpers.name == "BalancerHelpers"
# Make sure that when we try to access a non-existing attribute, we get an error
Expand All @@ -81,6 +79,7 @@ def test_deployments_populated():
print(a.multisigs)
assert a.multisigs.dao == "0x10A19e7eE7d7F8a52822f6817de8ea18204F2e4f"


@responses.activate
def test_deployments_invalid_format():
"""
Expand All @@ -92,40 +91,25 @@ def test_deployments_invalid_format():
"/bal_addresses/main/outputs/deployments.json",
json={
"BFactory": "0x9424B1412450D0f8Fc2255FAf6046b98213B76Bd",
}
},
)
responses.add(
responses.GET,
"https://raw.githubusercontent.com/balancer"
"/balancer-deployments/master/addresses/mainnet.json",
json={
"20210418-vault": {
"contracts": {'name': 'Vault'},
"status": "ACTIVE"
}
}
json={"20210418-vault": {"contracts": {"name": "Vault"}, "status": "ACTIVE"}},
)
responses.add(
responses.GET,
"https://raw.githubusercontent.com/BalancerMaxis"
"/bal_addresses/main/extras/mainnet.json",
json={
"vault": {
"contracts": {'name': 'Vault'},
"status": "ACTIVE"
}
}
json={"vault": {"contracts": {"name": "Vault"}, "status": "ACTIVE"}},
)
responses.add(
responses.GET,
"https://raw.githubusercontent.com/BalancerMaxis"
"/bal_addresses/main/extras/multisigs.json",
json={
"mainnet": {
"contracts": {'name': 'Vault'},
"status": "ACTIVE"
}
}
json={"mainnet": {"contracts": {"name": "Vault"}, "status": "ACTIVE"}},
)
a = AddrBook("mainnet")

Expand All @@ -146,28 +130,28 @@ def test_deployments_not_populated():
"/bal_addresses/main/outputs/deployments.json",
json={
"BFactory": "0x9424B1412450D0f8Fc2255FAf6046b98213B76Bd",
}
},
)
responses.add(
responses.GET,
"https://raw.githubusercontent.com/balancer"
"/balancer-deployments/master/addresses/mainnet.json",
json={},
status=404
status=404,
)
responses.add(
responses.GET,
"https://raw.githubusercontent.com/BalancerMaxis"
"/bal_addresses/main/extras/mainnet.json",
json={},
status=404
status=404,
)
responses.add(
responses.GET,
"https://raw.githubusercontent.com/BalancerMaxis"
"/bal_addresses/main/extras/multisigs.json",
json={},
status=404
status=404,
)
a = AddrBook("mainnet")
assert a.deployments is None
Expand All @@ -178,4 +162,4 @@ def test_deployments_not_populated():
assert a.extras.non_existing_attribute
assert a.multisigs == {}
with pytest.raises(AttributeError):
assert a.multisigs.non_existing_attribute
assert a.multisigs.non_existing_attribute

0 comments on commit c302e41

Please sign in to comment.