Skip to content

p-token: Clean-up test_case annotation #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion p-token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ solana-program-test = "2.1"
solana-sdk = "2.1"
spl-token = { version="^4", features=["no-entrypoint"] }
spl-token-2022 = { version="^7", features=["no-entrypoint"] }
test-case = "3.3.1"

[lints]
workspace = true
9 changes: 3 additions & 6 deletions p-token/tests/amount_to_ui_amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use {
solana_sdk::{pubkey::Pubkey, signature::Signer, transaction::Transaction},
};

#[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
#[tokio::test]
async fn amount_to_ui_amount(token_program: Pubkey) {
async fn amount_to_ui_amount() {
let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
.start_with_context()
.await;
Expand All @@ -22,15 +21,13 @@ async fn amount_to_ui_amount(token_program: Pubkey) {
&mut context,
mint_authority,
Some(freeze_authority),
&token_program,
&TOKEN_PROGRAM_ID,
)
.await
.unwrap();

let mut amount_to_ui_amount_ix =
let amount_to_ui_amount_ix =
spl_token::instruction::amount_to_ui_amount(&spl_token::ID, &mint, 1000).unwrap();
// Switches the program id to the token program.
amount_to_ui_amount_ix.program_id = token_program;

let tx = Transaction::new_signed_with_payer(
&[amount_to_ui_amount_ix],
Expand Down
13 changes: 6 additions & 7 deletions p-token/tests/approve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use {
},
};

#[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
#[tokio::test]
async fn approve(token_program: Pubkey) {
async fn approve() {
let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
.start_with_context()
.await;
Expand All @@ -27,7 +26,7 @@ async fn approve(token_program: Pubkey) {
&mut context,
mint_authority.pubkey(),
Some(freeze_authority),
&token_program,
&TOKEN_PROGRAM_ID,
)
.await
.unwrap();
Expand All @@ -36,15 +35,16 @@ async fn approve(token_program: Pubkey) {

let owner = Keypair::new();

let account = account::initialize(&mut context, &mint, &owner.pubkey(), &token_program).await;
let account =
account::initialize(&mut context, &mint, &owner.pubkey(), &TOKEN_PROGRAM_ID).await;

mint::mint(
&mut context,
&mint,
&account,
&mint_authority,
100,
&token_program,
&TOKEN_PROGRAM_ID,
)
.await
.unwrap();
Expand All @@ -53,7 +53,7 @@ async fn approve(token_program: Pubkey) {

let delegate = Pubkey::new_unique();

let mut approve_ix = spl_token::instruction::approve(
let approve_ix = spl_token::instruction::approve(
&spl_token::ID,
&account,
&delegate,
Expand All @@ -62,7 +62,6 @@ async fn approve(token_program: Pubkey) {
50,
)
.unwrap();
approve_ix.program_id = token_program;

let tx = Transaction::new_signed_with_payer(
&[approve_ix],
Expand Down
15 changes: 7 additions & 8 deletions p-token/tests/approve_checked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use {
},
};

#[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
#[tokio::test]
async fn approve_checked(token_program: Pubkey) {
async fn approve_checked() {
let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
.start_with_context()
.await;
Expand All @@ -27,7 +26,7 @@ async fn approve_checked(token_program: Pubkey) {
&mut context,
mint_authority.pubkey(),
Some(freeze_authority),
&token_program,
&TOKEN_PROGRAM_ID,
)
.await
.unwrap();
Expand All @@ -36,15 +35,16 @@ async fn approve_checked(token_program: Pubkey) {

let owner = Keypair::new();

let account = account::initialize(&mut context, &mint, &owner.pubkey(), &token_program).await;
let account =
account::initialize(&mut context, &mint, &owner.pubkey(), &TOKEN_PROGRAM_ID).await;

mint::mint(
&mut context,
&mint,
&account,
&mint_authority,
100,
&token_program,
&TOKEN_PROGRAM_ID,
)
.await
.unwrap();
Expand All @@ -53,8 +53,8 @@ async fn approve_checked(token_program: Pubkey) {

let delegate = Pubkey::new_unique();

let mut approve_ix = spl_token::instruction::approve_checked(
&spl_token::ID,
let approve_ix = spl_token::instruction::approve_checked(
&TOKEN_PROGRAM_ID,
&account,
&mint,
&delegate,
Expand All @@ -64,7 +64,6 @@ async fn approve_checked(token_program: Pubkey) {
4,
)
.unwrap();
approve_ix.program_id = token_program;

let tx = Transaction::new_signed_with_payer(
&[approve_ix],
Expand Down
25 changes: 12 additions & 13 deletions p-token/tests/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ fn batch_instruction(instructions: Vec<Instruction>) -> Result<Instruction, Prog
})
}

#[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
#[tokio::test]
async fn batch(token_program: Pubkey) {
async fn batch() {
let context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
.start_with_context()
.await;
Expand All @@ -63,10 +62,10 @@ async fn batch(token_program: Pubkey) {
&mint_a.pubkey(),
mint_rent,
mint_len as u64,
&token_program,
&TOKEN_PROGRAM_ID,
);
let initialize_mint_ix = spl_token::instruction::initialize_mint(
&token_program,
&TOKEN_PROGRAM_ID,
&mint_a.pubkey(),
&mint_authority.pubkey(),
None,
Expand All @@ -82,10 +81,10 @@ async fn batch(token_program: Pubkey) {
&mint_b.pubkey(),
mint_rent,
mint_len as u64,
&token_program,
&TOKEN_PROGRAM_ID,
);
let initialize_mint_with_freeze_authority_ix = spl_token::instruction::initialize_mint2(
&token_program,
&TOKEN_PROGRAM_ID,
&mint_b.pubkey(),
&mint_authority.pubkey(),
Some(&freeze_authority),
Expand All @@ -104,24 +103,24 @@ async fn batch(token_program: Pubkey) {
&owner_a_ta_a.pubkey(),
account_rent,
account_len as u64,
&token_program,
&TOKEN_PROGRAM_ID,
);
let create_owner_b_ta_a = system_instruction::create_account(
&context.payer.pubkey(),
&owner_b_ta_a.pubkey(),
account_rent,
account_len as u64,
&token_program,
&TOKEN_PROGRAM_ID,
);
let intialize_owner_a_ta_a = spl_token::instruction::initialize_account3(
&token_program,
&TOKEN_PROGRAM_ID,
&owner_a_ta_a.pubkey(),
&mint_a.pubkey(),
&owner_a.pubkey(),
)
.unwrap();
let intialize_owner_b_ta_a = spl_token::instruction::initialize_account3(
&token_program,
&TOKEN_PROGRAM_ID,
&owner_b_ta_a.pubkey(),
&mint_a.pubkey(),
&owner_b.pubkey(),
Expand All @@ -130,7 +129,7 @@ async fn batch(token_program: Pubkey) {

// Mint Token A to Owner A
let mint_token_a_to_owner_a = spl_token::instruction::mint_to(
&token_program,
&TOKEN_PROGRAM_ID,
&mint_a.pubkey(),
&owner_a_ta_a.pubkey(),
&mint_authority.pubkey(),
Expand All @@ -141,7 +140,7 @@ async fn batch(token_program: Pubkey) {

// Transfer Token A from Owner A to Owner B
let transfer_token_a_to_owner_b = spl_token::instruction::transfer(
&token_program,
&TOKEN_PROGRAM_ID,
&owner_a_ta_a.pubkey(),
&owner_b_ta_a.pubkey(),
&owner_a.pubkey(),
Expand All @@ -152,7 +151,7 @@ async fn batch(token_program: Pubkey) {

// Close Token A
let close_owner_a_ta_a = spl_token::instruction::close_account(
&token_program,
&TOKEN_PROGRAM_ID,
&owner_a_ta_a.pubkey(),
&owner_a.pubkey(),
&owner_a.pubkey(),
Expand Down
13 changes: 6 additions & 7 deletions p-token/tests/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use {
},
};

#[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
#[tokio::test]
async fn burn(token_program: Pubkey) {
async fn burn() {
let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
.start_with_context()
.await;
Expand All @@ -27,7 +26,7 @@ async fn burn(token_program: Pubkey) {
&mut context,
mint_authority.pubkey(),
Some(freeze_authority),
&token_program,
&TOKEN_PROGRAM_ID,
)
.await
.unwrap();
Expand All @@ -36,25 +35,25 @@ async fn burn(token_program: Pubkey) {

let owner = Keypair::new();

let account = account::initialize(&mut context, &mint, &owner.pubkey(), &token_program).await;
let account =
account::initialize(&mut context, &mint, &owner.pubkey(), &TOKEN_PROGRAM_ID).await;

mint::mint(
&mut context,
&mint,
&account,
&mint_authority,
100,
&token_program,
&TOKEN_PROGRAM_ID,
)
.await
.unwrap();

// When we burn 50 tokens.

let mut burn_ix =
let burn_ix =
spl_token::instruction::burn(&spl_token::ID, &account, &mint, &owner.pubkey(), &[], 50)
.unwrap();
burn_ix.program_id = token_program;

let tx = Transaction::new_signed_with_payer(
&[burn_ix],
Expand Down
13 changes: 6 additions & 7 deletions p-token/tests/burn_checked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use {
},
};

#[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
#[tokio::test]
async fn burn_checked(token_program: Pubkey) {
async fn burn_checked() {
let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
.start_with_context()
.await;
Expand All @@ -27,7 +26,7 @@ async fn burn_checked(token_program: Pubkey) {
&mut context,
mint_authority.pubkey(),
Some(freeze_authority),
&token_program,
&TOKEN_PROGRAM_ID,
)
.await
.unwrap();
Expand All @@ -36,22 +35,23 @@ async fn burn_checked(token_program: Pubkey) {

let owner = Keypair::new();

let account = account::initialize(&mut context, &mint, &owner.pubkey(), &token_program).await;
let account =
account::initialize(&mut context, &mint, &owner.pubkey(), &TOKEN_PROGRAM_ID).await;

mint::mint(
&mut context,
&mint,
&account,
&mint_authority,
100,
&token_program,
&TOKEN_PROGRAM_ID,
)
.await
.unwrap();

// When we burn 50 tokens.

let mut burn_ix = spl_token::instruction::burn_checked(
let burn_ix = spl_token::instruction::burn_checked(
&spl_token::ID,
&account,
&mint,
Expand All @@ -61,7 +61,6 @@ async fn burn_checked(token_program: Pubkey) {
4,
)
.unwrap();
burn_ix.program_id = token_program;

let tx = Transaction::new_signed_with_payer(
&[burn_ix],
Expand Down
Loading