This repository has been archived by the owner on Jan 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add vote init instruction for cleaner tests
- Loading branch information
Showing
16 changed files
with
240 additions
and
84 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import pytest | ||
from solana.keypair import Keypair | ||
|
||
from stake.actions import create_stake | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_create_stake(async_client, payer): | ||
reserve_stake = Keypair() | ||
await create_stake(async_client, payer, reserve_stake, payer.public_key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pytest | ||
from solana.keypair import Keypair | ||
from solana.rpc.commitment import Confirmed | ||
|
||
import system.actions | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_airdrop(async_client): | ||
manager = Keypair() | ||
airdrop_lamports = 1_000_000 | ||
await system.actions.airdrop(async_client, manager.public_key, airdrop_lamports) | ||
resp = await async_client.get_balance(manager.public_key, commitment=Confirmed) | ||
assert resp['result']['value'] == airdrop_lamports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import pytest | ||
from solana.keypair import Keypair | ||
|
||
from spl_token.actions import create_mint, create_associated_token_account | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_create_mint(async_client, payer): | ||
pool_mint = Keypair() | ||
await create_mint(async_client, payer, pool_mint, payer.public_key) | ||
await create_associated_token_account( | ||
async_client, | ||
payer, | ||
payer.public_key, | ||
pool_mint.public_key, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import pytest | ||
from solana.keypair import Keypair | ||
|
||
from vote.actions import create_vote | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_create_vote(async_client, payer): | ||
vote = Keypair() | ||
node = Keypair() | ||
await create_vote(async_client, payer, vote, node, payer.public_key, payer.public_key, 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from solana.publickey import PublicKey | ||
from solana.keypair import Keypair | ||
from solana.rpc.async_api import AsyncClient | ||
from solana.rpc.commitment import Confirmed | ||
from solana.rpc.types import TxOpts | ||
from solana.sysvar import SYSVAR_CLOCK_PUBKEY, SYSVAR_RENT_PUBKEY | ||
from solana.transaction import Transaction | ||
import solana.system_program as sys | ||
|
||
from vote.constants import VOTE_PROGRAM_ID, VOTE_STATE_LEN | ||
from vote.instructions import initialize, InitializeParams | ||
|
||
|
||
async def create_vote( | ||
client: AsyncClient, payer: Keypair, vote: Keypair, node: Keypair, | ||
voter: PublicKey, withdrawer: PublicKey, commission: int): | ||
print(f"Creating vote account {vote.public_key}") | ||
resp = await client.get_minimum_balance_for_rent_exemption(VOTE_STATE_LEN) | ||
txn = Transaction() | ||
txn.add( | ||
sys.create_account( | ||
sys.CreateAccountParams( | ||
from_pubkey=payer.public_key, | ||
new_account_pubkey=vote.public_key, | ||
lamports=resp['result'], | ||
space=VOTE_STATE_LEN, | ||
program_id=VOTE_PROGRAM_ID, | ||
) | ||
) | ||
) | ||
txn.add( | ||
initialize( | ||
InitializeParams( | ||
vote=vote.public_key, | ||
rent_sysvar=SYSVAR_RENT_PUBKEY, | ||
clock_sysvar=SYSVAR_CLOCK_PUBKEY, | ||
node=node.public_key, | ||
authorized_voter=voter, | ||
authorized_withdrawer=withdrawer, | ||
commission=commission, | ||
) | ||
) | ||
) | ||
await client.send_transaction( | ||
txn, payer, vote, node, opts=TxOpts(skip_confirmation=False, preflight_commitment=Confirmed)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.