Skip to content

Commit

Permalink
make tests pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tritium committed Jul 26, 2023
1 parent d8e9dcd commit e56e15a
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ init:
pip install -r bal_addresses/requirements.txt
pip install -r bal_addresses/requirements-dev.txt
ci:
pytest
pytest
25 changes: 25 additions & 0 deletions bal_addresses/addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
GITHUB_RAW_OUTPUTS = (
"https://raw.githubusercontent.com/BalancerMaxis/bal_addresses/main/outputs"
)
GITHUB_RAW_EXTRAS = (
"https://raw.githubusercontent.com/BalancerMaxis/bal_addresses/main/extras"
)
ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"


Expand All @@ -39,6 +42,7 @@ class AddrBook:
fx_description_by_name = DotMap(requests.get(
"https://raw.githubusercontent.com/BalancerMaxis/bal_addresses/main/extras/func_desc_by_name.json"
).json())
chain_ids_by_name = chains.CHAIN_IDS_BY_NAME

def __init__(self, chain, jsonfile=False):
self.jsonfile = jsonfile
Expand Down Expand Up @@ -124,6 +128,27 @@ def _process_deployment(self, deployment: Dict) -> Dict:
processed_deployment[deployment_identifier] = v
return processed_deployment


def populate_extras(self) -> None:
chain_extras = requests.get(
f"{GITHUB_RAW_EXTRAS}/{self.chain}.json"
)
if chain_extras.ok:
self._extras = Munch.fromDict(chain_extras.json())


def populate_multisigs(self) -> None:
msigs = requests.get(
f"{GITHUB_RAW_EXTRAS}/multisigs.json"
).json()
if msigs.get(self.chain):
self._multisigs = Munch.fromDict(msigs[self.chain])
else:
print(f"Warning: No multisigs for chain {self.chain}, multisigs must be added in extras/multisig.json")
self._multisigs = {}



def search_unique(self, substr):
results = [s for s in self.flatbook.keys() if substr in s]
if len(results) > 1:
Expand Down
77 changes: 76 additions & 1 deletion tests/test_addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ def test_deployments_populated():
}
}
)
responses.add(
responses.GET,
"https://raw.githubusercontent.com/BalancerMaxis"
"/bal_addresses/main/extras/mainnet.json",
json={
"zero": {
"zero": "0x0000000000000000000000000000000000000000"
},
"balancer": {}

}
)
responses.add(
responses.GET,
"https://raw.githubusercontent.com/BalancerMaxis"
"/bal_addresses/main/extras/multisigs.json",
json={
"mainnet": {
"dao": "0x10A19e7eE7d7F8a52822f6817de8ea18204F2e4f",
}
}
)
a = AddrBook("mainnet")

a.populate_deployments()
Expand All @@ -50,7 +72,14 @@ def test_deployments_populated():
# Make sure that when we try to access a non-existing attribute, we get an error
with pytest.raises(AttributeError):
assert a.deployments.vault.non_existing_attribute

a.populate_extras()
assert a.extras.zero.zero == "0x0000000000000000000000000000000000000000"
# Make sure that when we try to access a non-existing attribute, we get an error
with pytest.raises(AttributeError):
assert a.extras.balancer.non_existing_attribute
a.populate_multisigs()
print(a.multisigs)
assert a.multisigs.dao == "0x10A19e7eE7d7F8a52822f6817de8ea18204F2e4f"

@responses.activate
def test_deployments_invalid_format():
Expand All @@ -76,10 +105,36 @@ def test_deployments_invalid_format():
}
}
)
responses.add(
responses.GET,
"https://raw.githubusercontent.com/BalancerMaxis"
"/bal_addresses/main/extras/mainnet.json",
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"
}
}
)
a = AddrBook("mainnet")

a.populate_deployments()
assert a.deployments.vault.contracts.name == "Vault"
a.populate_extras()
assert a.extras.vault.status == "ACTIVE"
a.populate_multisigs()
assert a.multisigs.status == "ACTIVE"


@responses.activate
Expand All @@ -99,7 +154,27 @@ def test_deployments_not_populated():
json={},
status=404
)
responses.add(
responses.GET,
"https://raw.githubusercontent.com/BalancerMaxis"
"/bal_addresses/main/extras/mainnet.json",
json={},
status=404
)
responses.add(
responses.GET,
"https://raw.githubusercontent.com/BalancerMaxis"
"/bal_addresses/main/extras/multisigs.json",
json={},
status=404
)
a = AddrBook("mainnet")
assert a.deployments is None
with pytest.raises(AttributeError):
assert a.deployments.vault.non_existing_attribute
assert a.extras is None
with pytest.raises(AttributeError):
assert a.extras.non_existing_attribute
assert a.multisigs is None
with pytest.raises(AttributeError):
assert a.multisigs.non_existing_attribute

0 comments on commit e56e15a

Please sign in to comment.