Skip to content

Commit

Permalink
test and format
Browse files Browse the repository at this point in the history
  • Loading branch information
ruiqic committed Apr 17, 2024
1 parent daaa697 commit 1fb0f30
Show file tree
Hide file tree
Showing 34 changed files with 105 additions and 67 deletions.
1 change: 1 addition & 0 deletions src/solana/_layouts/vote_instructions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Byte layouts for vote program instructions."""

from enum import IntEnum

from construct import (
Expand Down
1 change: 1 addition & 0 deletions src/solana/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Exceptions native to solana-py."""

from typing import Any, Callable


Expand Down
1 change: 1 addition & 0 deletions src/solana/rpc/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""API client to interact with the Solana JSON RPC Endpoint.""" # pylint: disable=too-many-lines

from __future__ import annotations

from time import sleep, time
Expand Down
1 change: 1 addition & 0 deletions src/solana/rpc/async_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Async API client to interact with the Solana JSON RPC Endpoint.""" # pylint: disable=too-many-lines

import asyncio
from time import time
from typing import Dict, List, Optional, Sequence, Union
Expand Down
1 change: 1 addition & 0 deletions src/solana/rpc/commitment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
In descending order of commitment (most finalized to least finalized), clients may specify:
"""

from typing import NewType

Commitment = NewType("Commitment", str)
Expand Down
12 changes: 7 additions & 5 deletions src/solana/rpc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,11 @@ def _get_token_accounts_convert(
pubkey: Pubkey,
opts: types.TokenAccountOpts,
commitment: Optional[Commitment],
) -> Tuple[Pubkey, Union[RpcTokenAccountsFilterMint, RpcTokenAccountsFilterProgramId], RpcAccountInfoConfig,]:
) -> Tuple[
Pubkey,
Union[RpcTokenAccountsFilterMint, RpcTokenAccountsFilterProgramId],
RpcAccountInfoConfig,
]:
commitment_to_use = _COMMITMENT_TO_SOLDERS[commitment or self._commitment]
encoding_to_use = _ACCOUNT_ENCODING_TO_SOLDERS[opts.encoding]
maybe_data_slice = opts.data_slice
Expand Down Expand Up @@ -486,14 +490,12 @@ def _send_raw_transaction_post_send_args(
@overload
def _simulate_transaction_body(
self, txn: Transaction, sig_verify: bool, commitment: Optional[Commitment]
) -> SimulateLegacyTransaction:
...
) -> SimulateLegacyTransaction: ...

@overload
def _simulate_transaction_body(
self, txn: VersionedTransaction, sig_verify: bool, commitment: Optional[Commitment]
) -> SimulateVersionedTransaction:
...
) -> SimulateVersionedTransaction: ...

def _simulate_transaction_body(
self, txn: Union[Transaction, VersionedTransaction], sig_verify: bool, commitment: Optional[Commitment]
Expand Down
1 change: 1 addition & 0 deletions src/solana/rpc/providers/async_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Async base RPC Provider."""

from typing import Type

from solders.rpc.requests import Body
Expand Down
19 changes: 7 additions & 12 deletions src/solana/rpc/providers/async_http.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Async HTTP RPC Provider."""

from typing import Dict, Optional, Tuple, Type, overload

import httpx
Expand Down Expand Up @@ -72,28 +73,22 @@ async def make_batch_request_unparsed(self, reqs: Tuple[Body, ...]) -> str:
return _after_request_unparsed(raw_response)

@overload
async def make_batch_request(self, reqs: _BodiesTup, parsers: _Tup) -> _RespTup:
...
async def make_batch_request(self, reqs: _BodiesTup, parsers: _Tup) -> _RespTup: ...

@overload
async def make_batch_request(self, reqs: _BodiesTup1, parsers: _Tup1) -> _RespTup1:
...
async def make_batch_request(self, reqs: _BodiesTup1, parsers: _Tup1) -> _RespTup1: ...

@overload
async def make_batch_request(self, reqs: _BodiesTup2, parsers: _Tup2) -> _RespTup2:
...
async def make_batch_request(self, reqs: _BodiesTup2, parsers: _Tup2) -> _RespTup2: ...

@overload
async def make_batch_request(self, reqs: _BodiesTup3, parsers: _Tup3) -> _RespTup3:
...
async def make_batch_request(self, reqs: _BodiesTup3, parsers: _Tup3) -> _RespTup3: ...

@overload
async def make_batch_request(self, reqs: _BodiesTup4, parsers: _Tup4) -> _RespTup4:
...
async def make_batch_request(self, reqs: _BodiesTup4, parsers: _Tup4) -> _RespTup4: ...

@overload
async def make_batch_request(self, reqs: _BodiesTup5, parsers: _Tup5) -> _RespTup5:
...
async def make_batch_request(self, reqs: _BodiesTup5, parsers: _Tup5) -> _RespTup5: ...

async def make_batch_request(self, reqs: Tuple[Body, ...], parsers: _Tuples) -> Tuple[RPCResult, ...]:
"""Make an async HTTP batch request to an http rpc endpoint.
Expand Down
1 change: 1 addition & 0 deletions src/solana/rpc/providers/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Base RPC Provider."""

from solders.rpc.requests import Body
from typing_extensions import Type

Expand Down
37 changes: 13 additions & 24 deletions src/solana/rpc/providers/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helper code for HTTP provider classes."""

import itertools
import logging
import os
Expand Down Expand Up @@ -99,33 +100,27 @@ def _parse_raw(raw: str, parser: Type[T]) -> T:


@overload
def _parse_raw_batch(raw: str, parsers: _Tup) -> _RespTup:
...
def _parse_raw_batch(raw: str, parsers: _Tup) -> _RespTup: ...


@overload
def _parse_raw_batch(raw: str, parsers: _Tup1) -> _RespTup1:
...
def _parse_raw_batch(raw: str, parsers: _Tup1) -> _RespTup1: ...


@overload
def _parse_raw_batch(raw: str, parsers: _Tup2) -> _RespTup2:
...
def _parse_raw_batch(raw: str, parsers: _Tup2) -> _RespTup2: ...


@overload
def _parse_raw_batch(raw: str, parsers: _Tup3) -> _RespTup3:
...
def _parse_raw_batch(raw: str, parsers: _Tup3) -> _RespTup3: ...


@overload
def _parse_raw_batch(raw: str, parsers: _Tup4) -> _RespTup4:
...
def _parse_raw_batch(raw: str, parsers: _Tup4) -> _RespTup4: ...


@overload
def _parse_raw_batch(raw: str, parsers: _Tup5) -> _RespTup5:
...
def _parse_raw_batch(raw: str, parsers: _Tup5) -> _RespTup5: ...


def _parse_raw_batch(raw: str, parsers: _Tuples) -> Tuple[RPCResult, ...]:
Expand All @@ -138,33 +133,27 @@ def _after_request_unparsed(raw_response: httpx.Response) -> str:


@overload
def _after_batch_request(raw_response: httpx.Response, parsers: _Tup) -> _RespTup:
...
def _after_batch_request(raw_response: httpx.Response, parsers: _Tup) -> _RespTup: ...


@overload
def _after_batch_request(raw_response: httpx.Response, parsers: _Tup1) -> _RespTup1:
...
def _after_batch_request(raw_response: httpx.Response, parsers: _Tup1) -> _RespTup1: ...


@overload
def _after_batch_request(raw_response: httpx.Response, parsers: _Tup2) -> _RespTup2:
...
def _after_batch_request(raw_response: httpx.Response, parsers: _Tup2) -> _RespTup2: ...


@overload
def _after_batch_request(raw_response: httpx.Response, parsers: _Tup3) -> _RespTup3:
...
def _after_batch_request(raw_response: httpx.Response, parsers: _Tup3) -> _RespTup3: ...


@overload
def _after_batch_request(raw_response: httpx.Response, parsers: _Tup4) -> _RespTup4:
...
def _after_batch_request(raw_response: httpx.Response, parsers: _Tup4) -> _RespTup4: ...


@overload
def _after_batch_request(raw_response: httpx.Response, parsers: _Tup5) -> _RespTup5:
...
def _after_batch_request(raw_response: httpx.Response, parsers: _Tup5) -> _RespTup5: ...


def _after_batch_request(raw_response: httpx.Response, parsers: _Tuples) -> Tuple[RPCResult, ...]:
Expand Down
19 changes: 7 additions & 12 deletions src/solana/rpc/providers/http.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""HTTP RPC Provider."""

from typing import Tuple, Type, overload

import httpx
Expand Down Expand Up @@ -61,28 +62,22 @@ def make_batch_request_unparsed(self, reqs: Tuple[Body, ...]) -> str:
return _after_request_unparsed(raw_response)

@overload
def make_batch_request(self, reqs: _BodiesTup, parsers: _Tup) -> _RespTup:
...
def make_batch_request(self, reqs: _BodiesTup, parsers: _Tup) -> _RespTup: ...

@overload
def make_batch_request(self, reqs: _BodiesTup1, parsers: _Tup1) -> _RespTup1:
...
def make_batch_request(self, reqs: _BodiesTup1, parsers: _Tup1) -> _RespTup1: ...

@overload
def make_batch_request(self, reqs: _BodiesTup2, parsers: _Tup2) -> _RespTup2:
...
def make_batch_request(self, reqs: _BodiesTup2, parsers: _Tup2) -> _RespTup2: ...

@overload
def make_batch_request(self, reqs: _BodiesTup3, parsers: _Tup3) -> _RespTup3:
...
def make_batch_request(self, reqs: _BodiesTup3, parsers: _Tup3) -> _RespTup3: ...

@overload
def make_batch_request(self, reqs: _BodiesTup4, parsers: _Tup4) -> _RespTup4:
...
def make_batch_request(self, reqs: _BodiesTup4, parsers: _Tup4) -> _RespTup4: ...

@overload
def make_batch_request(self, reqs: _BodiesTup5, parsers: _Tup5) -> _RespTup5:
...
def make_batch_request(self, reqs: _BodiesTup5, parsers: _Tup5) -> _RespTup5: ...

def make_batch_request(self, reqs: Tuple[Body, ...], parsers: _Tuples) -> Tuple[RPCResult, ...]:
"""Make a HTTP batch request to an http rpc endpoint.
Expand Down
1 change: 1 addition & 0 deletions src/solana/rpc/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""RPC types."""

from typing import NamedTuple, NewType, Optional

from solders.pubkey import Pubkey
Expand Down
1 change: 1 addition & 0 deletions src/solana/rpc/websocket_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module contains code for interacting with the RPC Websocket endpoint."""

import itertools
from typing import Any, Dict, List, Optional, Sequence, Union, cast

Expand Down
1 change: 1 addition & 0 deletions src/solana/transaction.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Library to package an atomic sequence of instructions to a transaction."""

from __future__ import annotations

from typing import Any, List, NamedTuple, Optional, Sequence, Tuple, Union
Expand Down
1 change: 0 additions & 1 deletion src/solana/utils/security_txt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Utils for security.txt."""


from dataclasses import dataclass, fields
from typing import Any, List, Optional

Expand Down
1 change: 1 addition & 0 deletions src/solana/utils/validate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Validation utilities."""

from __future__ import annotations

from enum import IntEnum
Expand Down
1 change: 1 addition & 0 deletions src/solana/vote_program.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Library to interface with the vote program."""

from __future__ import annotations

from typing import NamedTuple
Expand Down
1 change: 1 addition & 0 deletions src/spl/memo/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Memo program constants."""

from solders.pubkey import Pubkey

MEMO_PROGRAM_ID: Pubkey = Pubkey.from_string("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr")
Expand Down
1 change: 1 addition & 0 deletions src/spl/memo/instructions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Memo program instructions."""

from __future__ import annotations

from typing import NamedTuple
Expand Down
1 change: 1 addition & 0 deletions src/spl/token/_layouts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Token instruction layouts."""

from enum import IntEnum

from construct import Bytes, Int8ul, Int32ul, Int64ul, Pass, Switch
Expand Down
8 changes: 7 additions & 1 deletion src/spl/token/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,13 @@ async def create_wrapped_native_account(
"""
# Allocate memory for the account
balance_needed = await AsyncToken.get_min_balance_rent_for_exempt_for_account(conn)
(new_account_public_key, txn, payer, new_account, opts,) = _TokenCore._create_wrapped_native_account_args(
(
new_account_public_key,
txn,
payer,
new_account,
opts,
) = _TokenCore._create_wrapped_native_account_args(
program_id,
owner,
payer,
Expand Down
8 changes: 7 additions & 1 deletion src/spl/token/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,13 @@ def create_wrapped_native_account(
"""
# Allocate memory for the account
balance_needed = Token.get_min_balance_rent_for_exempt_for_account(conn)
(new_account_public_key, txn, payer, new_account, opts,) = _TokenCore._create_wrapped_native_account_args(
(
new_account_public_key,
txn,
payer,
new_account,
opts,
) = _TokenCore._create_wrapped_native_account_args(
program_id,
owner,
payer,
Expand Down
6 changes: 3 additions & 3 deletions src/spl/token/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ def decode_initialize_mint(instruction: Instruction) -> InitializeMintParams:
program_id=instruction.program_id,
mint=instruction.accounts[0].pubkey,
mint_authority=Pubkey(parsed_data.args.mint_authority),
freeze_authority=Pubkey(parsed_data.args.freeze_authority)
if parsed_data.args.freeze_authority_option
else None,
freeze_authority=(
Pubkey(parsed_data.args.freeze_authority) if parsed_data.args.freeze_authority_option else None
),
)


Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Fixtures for pytest."""

import asyncio
import time
from typing import NamedTuple
Expand Down
7 changes: 3 additions & 4 deletions tests/integration/test_async_http_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the HTTP API Client."""

from typing import Tuple

import pytest
Expand Down Expand Up @@ -615,10 +616,8 @@ async def test_batch_request(test_http_client_async: AsyncClient):
"""Test get vote accounts."""
reqs = (GetBlockHeight(), GetFirstAvailableBlock())
parsers = (GetBlockHeightResp, GetFirstAvailableBlockResp)
resp: Tuple[
Resp[GetBlockHeightResp], Resp[GetFirstAvailableBlockResp]
] = await test_http_client_async._provider.make_batch_request( # pylint: disable=protected-access
reqs, parsers
resp: Tuple[Resp[GetBlockHeightResp], Resp[GetFirstAvailableBlockResp]] = (
await test_http_client_async._provider.make_batch_request(reqs, parsers) # pylint: disable=protected-access
)
assert_valid_response(resp[0])
assert_valid_response(resp[1])
7 changes: 3 additions & 4 deletions tests/integration/test_http_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the HTTP API Client."""

from typing import Tuple

import pytest
Expand Down Expand Up @@ -591,10 +592,8 @@ def test_batch_request(test_http_client: Client):
"""Test get vote accounts."""
reqs = (GetBlockHeight(), GetFirstAvailableBlock())
parsers = (GetBlockHeightResp, GetFirstAvailableBlockResp)
resp: Tuple[
Resp[GetBlockHeightResp], Resp[GetFirstAvailableBlockResp]
] = test_http_client._provider.make_batch_request( # pylint: disable=protected-access
reqs, parsers
resp: Tuple[Resp[GetBlockHeightResp], Resp[GetFirstAvailableBlockResp]] = (
test_http_client._provider.make_batch_request(reqs, parsers) # pylint: disable=protected-access
)
assert_valid_response(resp[0])
assert_valid_response(resp[1])
1 change: 1 addition & 0 deletions tests/integration/test_memo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Memo program."""

import pytest
from solders.keypair import Keypair
from solders.transaction_status import ParsedInstruction
Expand Down
Loading

0 comments on commit 1fb0f30

Please sign in to comment.