forked from solana-labs/solana-program-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
token: Transition perf-monitor to solana-program-test (solana-labs#2586)
* token: Transition perf-monitor to solana-program-test * fmt * Refactor for clarity
- Loading branch information
Showing
10 changed files
with
854 additions
and
184 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,140 @@ | ||
use { | ||
solana_program_test::BanksClient, | ||
solana_sdk::{ | ||
hash::Hash, | ||
program_pack::Pack, | ||
pubkey::Pubkey, | ||
signature::{Keypair, Signer}, | ||
system_instruction, | ||
transaction::Transaction, | ||
transport::TransportError, | ||
}, | ||
spl_token_2022::{ | ||
id, instruction, | ||
state::{Account, Mint}, | ||
}, | ||
}; | ||
|
||
pub async fn create_mint( | ||
banks_client: &mut BanksClient, | ||
payer: &Keypair, | ||
recent_blockhash: Hash, | ||
pool_mint: &Keypair, | ||
manager: &Pubkey, | ||
decimals: u8, | ||
) -> Result<(), TransportError> { | ||
let rent = banks_client.get_rent().await.unwrap(); | ||
let mint_rent = rent.minimum_balance(Mint::LEN); | ||
|
||
let transaction = Transaction::new_signed_with_payer( | ||
&[ | ||
system_instruction::create_account( | ||
&payer.pubkey(), | ||
&pool_mint.pubkey(), | ||
mint_rent, | ||
Mint::LEN as u64, | ||
&id(), | ||
), | ||
instruction::initialize_mint(&id(), &pool_mint.pubkey(), manager, None, decimals) | ||
.unwrap(), | ||
], | ||
Some(&payer.pubkey()), | ||
&[payer, pool_mint], | ||
recent_blockhash, | ||
); | ||
banks_client.process_transaction(transaction).await?; | ||
Ok(()) | ||
} | ||
|
||
pub async fn create_account( | ||
banks_client: &mut BanksClient, | ||
payer: &Keypair, | ||
recent_blockhash: Hash, | ||
account: &Keypair, | ||
pool_mint: &Pubkey, | ||
owner: &Pubkey, | ||
) -> Result<(), TransportError> { | ||
let rent = banks_client.get_rent().await.unwrap(); | ||
let account_rent = rent.minimum_balance(Account::LEN); | ||
|
||
let transaction = Transaction::new_signed_with_payer( | ||
&[ | ||
system_instruction::create_account( | ||
&payer.pubkey(), | ||
&account.pubkey(), | ||
account_rent, | ||
Account::LEN as u64, | ||
&id(), | ||
), | ||
instruction::initialize_account(&id(), &account.pubkey(), pool_mint, owner).unwrap(), | ||
], | ||
Some(&payer.pubkey()), | ||
&[payer, account], | ||
recent_blockhash, | ||
); | ||
banks_client.process_transaction(transaction).await?; | ||
Ok(()) | ||
} | ||
|
||
pub async fn mint_to( | ||
banks_client: &mut BanksClient, | ||
payer: &Keypair, | ||
recent_blockhash: Hash, | ||
mint: &Pubkey, | ||
account: &Pubkey, | ||
mint_authority: &Keypair, | ||
amount: u64, | ||
) -> Result<(), TransportError> { | ||
let transaction = Transaction::new_signed_with_payer( | ||
&[ | ||
instruction::mint_to(&id(), mint, account, &mint_authority.pubkey(), &[], amount) | ||
.unwrap(), | ||
], | ||
Some(&payer.pubkey()), | ||
&[payer, mint_authority], | ||
recent_blockhash, | ||
); | ||
banks_client.process_transaction(transaction).await?; | ||
Ok(()) | ||
} | ||
|
||
pub async fn transfer( | ||
banks_client: &mut BanksClient, | ||
payer: &Keypair, | ||
recent_blockhash: Hash, | ||
source: &Pubkey, | ||
destination: &Pubkey, | ||
authority: &Keypair, | ||
amount: u64, | ||
) -> Result<(), TransportError> { | ||
let transaction = Transaction::new_signed_with_payer( | ||
&[ | ||
instruction::transfer(&id(), source, destination, &authority.pubkey(), &[], amount) | ||
.unwrap(), | ||
], | ||
Some(&payer.pubkey()), | ||
&[payer, authority], | ||
recent_blockhash, | ||
); | ||
banks_client.process_transaction(transaction).await?; | ||
Ok(()) | ||
} | ||
|
||
pub async fn burn( | ||
banks_client: &mut BanksClient, | ||
payer: &Keypair, | ||
recent_blockhash: Hash, | ||
mint: &Pubkey, | ||
account: &Pubkey, | ||
authority: &Keypair, | ||
amount: u64, | ||
) -> Result<(), TransportError> { | ||
let transaction = Transaction::new_signed_with_payer( | ||
&[instruction::burn(&id(), account, mint, &authority.pubkey(), &[], amount).unwrap()], | ||
Some(&payer.pubkey()), | ||
&[payer, authority], | ||
recent_blockhash, | ||
); | ||
banks_client.process_transaction(transaction).await?; | ||
Ok(()) | ||
} |
Oops, something went wrong.