Skip to content

Commit 66b275c

Browse files
committed
linting
1 parent 15ef39e commit 66b275c

File tree

10 files changed

+78
-276
lines changed

10 files changed

+78
-276
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ repos:
1010
entry: poetry run black .
1111
pass_filenames: false
1212
language: system
13-
- id: mypy
14-
name: mypy
15-
entry: poetry run mypy program_admin/ tests/
13+
- id: pyright
14+
name: pyright
15+
entry: poetry run pyright program_admin/ tests/
1616
pass_filenames: false
1717
language: system
18-
- id: pylint
19-
name: pylint
20-
entry: poetry run pylint program_admin/ tests/
18+
- id: pyflakes
19+
name: pyflakes
20+
entry: poetry run pyflakes program_admin/ tests/
2121
pass_filenames: false
2222
language: system

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
lint:
22
poetry run isort --profile=black program_admin/ tests/
33
poetry run black program_admin/ tests/
4-
poetry run mypy program_admin/ tests/
5-
poetry run pylint program_admin/ tests/
4+
poetry run pyright program_admin/ tests/
5+
poetry run pyflakes program_admin/ tests/
66

77
install:
88
poetry install

poetry.lock

Lines changed: 21 additions & 226 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

program_admin/__init__.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import json
22
import os
3-
import sys
4-
from dataclasses import asdict
53
from pathlib import Path
6-
from typing import Any, Dict, List, Literal, Optional, Tuple
4+
from typing import Dict, List, Literal, Optional, Tuple
75

86
from loguru import logger
97
from solana import system_program
@@ -16,13 +14,7 @@
1614

1715
from program_admin import instructions as pyth_program
1816
from program_admin.keys import load_keypair
19-
from program_admin.parsing import (
20-
parse_account,
21-
parse_overrides_json,
22-
parse_permissions_json,
23-
parse_products_json,
24-
parse_publishers_json,
25-
)
17+
from program_admin.parsing import parse_account
2618
from program_admin.types import (
2719
Network,
2820
PythAuthorityPermissionAccount,
@@ -72,7 +64,7 @@ def __init__(
7264
key_dir: str,
7365
program_key: str,
7466
commitment: Literal["confirmed", "finalized"],
75-
rpc_endpoint: str = None,
67+
rpc_endpoint: str = "",
7668
):
7769
self.network = network
7870
self.rpc_endpoint = rpc_endpoint or RPC_ENDPOINTS[network]
@@ -223,7 +215,7 @@ async def send_transaction(
223215

224216
async def sync(
225217
self,
226-
ref_products: ReferenceProduct,
218+
ref_products: Dict[str, ReferenceProduct],
227219
ref_publishers: ReferencePublishers,
228220
ref_permissions: ReferencePermissions,
229221
ref_authority_permissions: ReferenceAuthorityPermissions,
@@ -252,6 +244,10 @@ async def sync(
252244
await self.send_transaction(
253245
authority_instructions, authority_signers
254246
)
247+
else:
248+
logger.debug(
249+
"Reference data for authority permissions is not defined, skipping..."
250+
)
255251

256252
# Sync mapping accounts
257253
mapping_instructions, mapping_keypairs = await self.sync_mapping_instructions(
@@ -310,11 +306,6 @@ async def sync(
310306
if send_transactions:
311307
await self.send_transaction(price_instructions, price_keypairs)
312308

313-
else:
314-
logger.debug(
315-
"Reference data for authority permissions is not defined, skipping..."
316-
)
317-
318309
return instructions
319310

320311
async def sync_mapping_instructions(

program_admin/cli.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def set_minimum_publishers(funding_key, program_key, price_key, value, outfile):
119119
@click.option("--funding-key", help="Funding key", envvar="FUNDING_KEY")
120120
@click.option("--program-key", help="Pyth program key", envvar="PROGRAM_KEY")
121121
@click.option("--product-key", help="Product account key", envvar="PRODUCT_KEY")
122-
@click.option("--metadata", help="Metadata to add to product", type=dict)
122+
@click.option("--metadata", help="Metadata to add to product", type=str)
123123
@click.option(
124124
"--outfile",
125125
help="File location to write instructions",
@@ -130,7 +130,9 @@ def update_product_metadata(funding_key, program_key, product_key, metadata, out
130130
funding = PublicKey(funding_key)
131131
program = PublicKey(program_key)
132132
product = PublicKey(product_key)
133-
instruction = instructions.update_product(program, funding, product, metadata)
133+
instruction = instructions.update_product(
134+
program, funding, product, json.loads(metadata)
135+
)
134136

135137
instruction_output = json.dumps(
136138
[
@@ -448,12 +450,10 @@ def sync(
448450
ref_permissions = parse_permissions_with_overrides(
449451
Path(permissions), Path(overrides), network
450452
)
451-
ref_authority_permissions = None
452453

453-
if authority_permissions:
454-
ref_authority_permissions = parse_authority_permissions_json(
455-
Path(authority_permissions)
456-
)
454+
ref_authority_permissions = parse_authority_permissions_json(
455+
Path(authority_permissions)
456+
)
457457

458458
asyncio.run(
459459
program_admin.sync(
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
from .accept import AcceptAccounts, accept
22
from .propose import ProposeAccounts, propose
33
from .revert import RevertAccounts, revert
4+
5+
assert AcceptAccounts
6+
assert accept
7+
assert ProposeAccounts
8+
assert propose
9+
assert RevertAccounts
10+
assert revert

program_admin/types.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass
2-
from typing import Dict, List, Literal, Optional, TypedDict, Union
2+
from typing import Dict, Generic, List, Literal, Optional, TypedDict, TypeVar, Union
33

44
from solana.publickey import PublicKey
55

@@ -130,35 +130,37 @@ def __str__(self) -> str:
130130

131131
AccountData = Union[MappingData, ProductData, PriceData, AuthorityPermissionData]
132132

133+
T = TypeVar("T", bound=AccountData)
134+
133135

134136
@dataclass
135-
class PythAccount:
137+
class PythAccount(Generic[T]):
136138
public_key: PublicKey
137139
owner: PublicKey
138140
lamports: int
139-
data: AccountData
141+
data: T
140142

141143
def __str__(self) -> str:
142144
return f"PythAccount(key={str(self.public_key)[0:5]}..., data={self.data})"
143145

144146

145147
@dataclass
146-
class PythMappingAccount(PythAccount):
148+
class PythMappingAccount(PythAccount[MappingData]):
147149
data: MappingData
148150

149151

150152
@dataclass
151-
class PythProductAccount(PythAccount):
153+
class PythProductAccount(PythAccount[ProductData]):
152154
data: ProductData
153155

154156

155157
@dataclass
156-
class PythPriceAccount(PythAccount):
158+
class PythPriceAccount(PythAccount[PriceData]):
157159
data: PriceData
158160

159161

160162
@dataclass
161-
class PythAuthorityPermissionAccount(PythAccount):
163+
class PythAuthorityPermissionAccount(PythAccount[AuthorityPermissionData]):
162164
"""
163165
On-chain authorities permissions account.
164166

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ requests = "^2.32.3"
2626
black = { version = "^22.3.0" }
2727
isort = { version = "^5.10.0" }
2828
ipython = "^8.2.0"
29-
mypy = "^0.942"
30-
pylint = "^2.13.0"
3129
types-ujson = "^4.2.0"
3230
pytest = "^7.1.2"
3331
pytest-asyncio = "^0.18.3"
3432
types-requests = "^2.32.0.20240622"
33+
pyright = "^1.1.369"
34+
pyflakes = "^3.2.0"
3535

3636
[tool.poetry.scripts]
3737
program-admin = "program_admin.cli:cli"

tests/test_cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_minimum_publishers():
1919
"--price-key",
2020
"6bRsDGmuSfUCND9vZioUbWfB56dkrCqNE8f2DW7eNU5D",
2121
"--value",
22-
20,
22+
"20",
2323
],
2424
)
2525
assert result.exit_code == 0
@@ -46,7 +46,7 @@ def test_toggle_publisher():
4646
"--publisher-key",
4747
"6bRsDGmuSfUCND9vZioUbWfB56dkrCqNE8f2DW7eNU5E",
4848
"--status",
49-
True,
49+
"true",
5050
],
5151
)
5252

@@ -72,7 +72,7 @@ def test_update_product():
7272
"--product-key",
7373
"6bRsDGmuSfUCND9vZioUbWfB56dkrCqNE8f2DW7eNU5D",
7474
"--metadata",
75-
{"data": "meta"},
75+
'{"data": "meta"}',
7676
],
7777
)
7878
assert result.exit_code == 0

tests/test_sync.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async def oracle():
8686
outfile = "tests/pyth_oracle.so"
8787

8888
try:
89-
response = requests.get(api_url)
89+
response = requests.get(api_url, timeout=300)
9090
response.raise_for_status()
9191
release_info = response.json()
9292

@@ -97,8 +97,11 @@ async def oracle():
9797
asset_url = asset["browser_download_url"]
9898
break
9999

100+
if not asset_url:
101+
raise Exception(f"Unable to find asset URL for {filename}")
102+
100103
# Download the asset
101-
download_response = requests.get(asset_url)
104+
download_response = requests.get(asset_url, timeout=300)
102105
download_response.raise_for_status()
103106

104107
# Save the file to the specified path
@@ -107,9 +110,9 @@ async def oracle():
107110

108111
LOGGER.debug(f"File {filename} downloaded successfully to {outfile}.")
109112

110-
except requests.exceptions.RequestException as e:
111-
LOGGER.error(f"An error occurred: {e}")
112-
raise e
113+
except requests.exceptions.RequestException as error:
114+
LOGGER.error(f"An error occurred: {error}")
115+
raise error
113116

114117
yield outfile
115118

@@ -437,7 +440,11 @@ async def test_sync(
437440

438441
product_accounts = list(program_admin._product_accounts.values())
439442
price_accounts = list(program_admin._price_accounts.values())
440-
authority_permissions = program_admin.authority_permission_account.data
443+
authority_permission_account = program_admin.authority_permission_account
444+
if authority_permission_account:
445+
authority_permissions = authority_permission_account.data
446+
else:
447+
raise Exception("Authority permissions not found")
441448

442449
reference_symbols = ["Crypto.BTC/USD", "Equity.US.AAPL/USD"]
443450

0 commit comments

Comments
 (0)