Skip to content

Commit

Permalink
Add more program constants
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhly committed Jun 9, 2024
1 parent db9574d commit 68bb424
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
20 changes: 20 additions & 0 deletions src/solana/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
"""Solana constants."""

from solders.pubkey import Pubkey

LAMPORTS_PER_SOL: int = 1_000_000_000
"""Number of lamports per SOL, where 1 SOL equals 1 billion lamports."""

SYSTEM_PROGRAM_ID = Pubkey.from_string("11111111111111111111111111111111")
"""Program ID for the System Program."""

CONFIG_PROGRAM_ID: Pubkey = Pubkey.from_string("Config1111111111111111111111111111111111111")
"""Program ID for the Config Program."""

STAKE_PROGRAM_ID: Pubkey = Pubkey.from_string("Stake11111111111111111111111111111111111111")
"""Program ID for the Stake Program."""

VOTE_PROGRAM_ID: Pubkey = Pubkey.from_string("Vote111111111111111111111111111111111111111")
"""Program ID for the Vote Program."""

ADDRESS_LOOKUP_TABLE_PROGRAM_ID: Pubkey = Pubkey.from_string("AddressLookupTab1e1111111111111111111111111")
"""Program ID for the Address Lookup Table Program."""

BPF_LOADER_PROGRAM_ID: Pubkey = Pubkey.from_string("BPFLoaderUpgradeab1e11111111111111111111111")
"""Program ID for the BPF Loader Program."""
5 changes: 1 addition & 4 deletions src/solana/vote_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
from solders.instruction import AccountMeta, Instruction
from solders.pubkey import Pubkey

from solana.constants import VOTE_PROGRAM_ID
from solana._layouts.vote_instructions import VOTE_INSTRUCTIONS_LAYOUT, InstructionType

VOTE_PROGRAM_ID: Pubkey = Pubkey.from_string("Vote111111111111111111111111111111111111111")
"""Public key that identifies the Vote program."""


# Instrection Params
class WithdrawFromVoteAccountParams(NamedTuple):
"""Transfer SOL from vote account to identity."""
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/test_async_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from solders.transaction import VersionedTransaction
from spl.token.constants import WRAPPED_SOL_MINT

from solana.constants import VOTE_PROGRAM_ID
from solana.rpc.async_api import AsyncClient
from solana.rpc.commitment import Confirmed, Finalized, Processed
from solana.rpc.core import RPCException, TransactionExpiredBlockheightExceededError
Expand Down Expand Up @@ -360,9 +361,7 @@ async def test_get_blocks(test_http_client_async):
@pytest.mark.integration
async def test_get_signatures_for_address(test_http_client_async: AsyncClient):
"""Test get signatures for addresses."""
resp = await test_http_client_async.get_signatures_for_address(
Pubkey.from_string("Vote111111111111111111111111111111111111111"), limit=1, commitment=Confirmed
)
resp = await test_http_client_async.get_signatures_for_address(VOTE_PROGRAM_ID, limit=1, commitment=Confirmed)
assert_valid_response(resp)


Expand Down
7 changes: 3 additions & 4 deletions tests/integration/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
from solders.rpc.requests import GetBlockHeight, GetFirstAvailableBlock
from solders.rpc.responses import GetBlockHeightResp, GetFirstAvailableBlockResp, Resp
from solders.transaction import VersionedTransaction
from spl.token.constants import WRAPPED_SOL_MINT

from solana.constants import VOTE_PROGRAM_ID
from solana.rpc.api import Client
from solana.rpc.commitment import Confirmed, Finalized, Processed
from solana.rpc.core import RPCException, TransactionExpiredBlockheightExceededError
from solana.rpc.types import DataSliceOpts, TxOpts
from solana.transaction import Transaction
from spl.token.constants import WRAPPED_SOL_MINT

from ..utils import AIRDROP_AMOUNT, assert_valid_response

Expand Down Expand Up @@ -344,9 +345,7 @@ def test_get_blocks(test_http_client: Client):
@pytest.mark.integration
def test_get_signatures_for_address(test_http_client: Client):
"""Test get signatures for addresses."""
resp = test_http_client.get_signatures_for_address(
Pubkey.from_string("Vote111111111111111111111111111111111111111"), limit=1, commitment=Confirmed
)
resp = test_http_client.get_signatures_for_address(VOTE_PROGRAM_ID, limit=1, commitment=Confirmed)
assert_valid_response(resp)


Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from solders.rpc.requests import GetSignaturesForAddress
from solders.signature import Signature

from solana.constants import SYSTEM_PROGRAM_ID
from solana.exceptions import SolanaRpcException
from solana.rpc.commitment import Finalized

Expand All @@ -26,7 +27,7 @@ async def test_async_client_http_exception(unit_test_http_client_async):
def test_client_address_sig_args_no_commitment(unit_test_http_client_async):
"""Test generating getSignaturesForAddressBody."""
expected = GetSignaturesForAddress(
Pubkey.from_string("11111111111111111111111111111111"),
SYSTEM_PROGRAM_ID,
RpcSignaturesForAddressConfig(
limit=5, before=Signature.default(), until=Signature.default(), commitment=CommitmentLevel.Processed
),
Expand All @@ -39,7 +40,7 @@ def test_client_address_sig_args_no_commitment(unit_test_http_client_async):

def test_client_address_sig_args_with_commitment(unit_test_http_client_async):
expected = GetSignaturesForAddress(
Pubkey.from_string("11111111111111111111111111111111"),
SYSTEM_PROGRAM_ID,
RpcSignaturesForAddressConfig(limit=5, commitment=CommitmentLevel.Finalized),
)
actual = unit_test_http_client_async._get_signatures_for_address_body(
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from solders.rpc.requests import GetSignaturesForAddress
from solders.signature import Signature

from solana.constants import SYSTEM_PROGRAM_ID
from solana.exceptions import SolanaRpcException
from solana.rpc.commitment import Finalized

Expand All @@ -26,7 +27,7 @@ def test_client_http_exception(unit_test_http_client):
def test_client_address_sig_args_no_commitment(unit_test_http_client):
"""Test generating getSignaturesForAddress body."""
expected = GetSignaturesForAddress(
Pubkey.from_string("11111111111111111111111111111111"),
SYSTEM_PROGRAM_ID,
RpcSignaturesForAddressConfig(
limit=5, before=Signature.default(), until=Signature.default(), commitment=CommitmentLevel.Processed
),
Expand All @@ -39,7 +40,7 @@ def test_client_address_sig_args_no_commitment(unit_test_http_client):

def test_client_address_sig_args_with_commitment(unit_test_http_client):
expected = GetSignaturesForAddress(
Pubkey.from_string("11111111111111111111111111111111"),
SYSTEM_PROGRAM_ID,
RpcSignaturesForAddressConfig(limit=5, commitment=CommitmentLevel.Finalized),
)
actual = unit_test_http_client._get_signatures_for_address_body(Pubkey([0] * 31 + [0]), None, None, 5, Finalized)
Expand Down

0 comments on commit 68bb424

Please sign in to comment.