Skip to content

Commit feb11f8

Browse files
authored
p-token: Clean-up test_case annotation (solana-program#53)
* Add mint as authority test * Add tests * Fix test comment * Update test names * Remove test case annotation * Remove dependency
1 parent 25b0d8c commit feb11f8

26 files changed

+161
-280
lines changed

Cargo.lock

Lines changed: 0 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

p-token/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ solana-program-test = "2.1"
2626
solana-sdk = "2.1"
2727
spl-token = { version="^4", features=["no-entrypoint"] }
2828
spl-token-2022 = { version="^7", features=["no-entrypoint"] }
29-
test-case = "3.3.1"
3029

3130
[lints]
3231
workspace = true

p-token/tests/amount_to_ui_amount.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use {
66
solana_sdk::{pubkey::Pubkey, signature::Signer, transaction::Transaction},
77
};
88

9-
#[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
109
#[tokio::test]
11-
async fn amount_to_ui_amount(token_program: Pubkey) {
10+
async fn amount_to_ui_amount() {
1211
let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
1312
.start_with_context()
1413
.await;
@@ -22,15 +21,13 @@ async fn amount_to_ui_amount(token_program: Pubkey) {
2221
&mut context,
2322
mint_authority,
2423
Some(freeze_authority),
25-
&token_program,
24+
&TOKEN_PROGRAM_ID,
2625
)
2726
.await
2827
.unwrap();
2928

30-
let mut amount_to_ui_amount_ix =
29+
let amount_to_ui_amount_ix =
3130
spl_token::instruction::amount_to_ui_amount(&spl_token::ID, &mint, 1000).unwrap();
32-
// Switches the program id to the token program.
33-
amount_to_ui_amount_ix.program_id = token_program;
3431

3532
let tx = Transaction::new_signed_with_payer(
3633
&[amount_to_ui_amount_ix],

p-token/tests/approve.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use {
1111
},
1212
};
1313

14-
#[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
1514
#[tokio::test]
16-
async fn approve(token_program: Pubkey) {
15+
async fn approve() {
1716
let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
1817
.start_with_context()
1918
.await;
@@ -27,7 +26,7 @@ async fn approve(token_program: Pubkey) {
2726
&mut context,
2827
mint_authority.pubkey(),
2928
Some(freeze_authority),
30-
&token_program,
29+
&TOKEN_PROGRAM_ID,
3130
)
3231
.await
3332
.unwrap();
@@ -36,15 +35,16 @@ async fn approve(token_program: Pubkey) {
3635

3736
let owner = Keypair::new();
3837

39-
let account = account::initialize(&mut context, &mint, &owner.pubkey(), &token_program).await;
38+
let account =
39+
account::initialize(&mut context, &mint, &owner.pubkey(), &TOKEN_PROGRAM_ID).await;
4040

4141
mint::mint(
4242
&mut context,
4343
&mint,
4444
&account,
4545
&mint_authority,
4646
100,
47-
&token_program,
47+
&TOKEN_PROGRAM_ID,
4848
)
4949
.await
5050
.unwrap();
@@ -53,7 +53,7 @@ async fn approve(token_program: Pubkey) {
5353

5454
let delegate = Pubkey::new_unique();
5555

56-
let mut approve_ix = spl_token::instruction::approve(
56+
let approve_ix = spl_token::instruction::approve(
5757
&spl_token::ID,
5858
&account,
5959
&delegate,
@@ -62,7 +62,6 @@ async fn approve(token_program: Pubkey) {
6262
50,
6363
)
6464
.unwrap();
65-
approve_ix.program_id = token_program;
6665

6766
let tx = Transaction::new_signed_with_payer(
6867
&[approve_ix],

p-token/tests/approve_checked.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use {
1111
},
1212
};
1313

14-
#[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
1514
#[tokio::test]
16-
async fn approve_checked(token_program: Pubkey) {
15+
async fn approve_checked() {
1716
let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
1817
.start_with_context()
1918
.await;
@@ -27,7 +26,7 @@ async fn approve_checked(token_program: Pubkey) {
2726
&mut context,
2827
mint_authority.pubkey(),
2928
Some(freeze_authority),
30-
&token_program,
29+
&TOKEN_PROGRAM_ID,
3130
)
3231
.await
3332
.unwrap();
@@ -36,15 +35,16 @@ async fn approve_checked(token_program: Pubkey) {
3635

3736
let owner = Keypair::new();
3837

39-
let account = account::initialize(&mut context, &mint, &owner.pubkey(), &token_program).await;
38+
let account =
39+
account::initialize(&mut context, &mint, &owner.pubkey(), &TOKEN_PROGRAM_ID).await;
4040

4141
mint::mint(
4242
&mut context,
4343
&mint,
4444
&account,
4545
&mint_authority,
4646
100,
47-
&token_program,
47+
&TOKEN_PROGRAM_ID,
4848
)
4949
.await
5050
.unwrap();
@@ -53,8 +53,8 @@ async fn approve_checked(token_program: Pubkey) {
5353

5454
let delegate = Pubkey::new_unique();
5555

56-
let mut approve_ix = spl_token::instruction::approve_checked(
57-
&spl_token::ID,
56+
let approve_ix = spl_token::instruction::approve_checked(
57+
&TOKEN_PROGRAM_ID,
5858
&account,
5959
&mint,
6060
&delegate,
@@ -64,7 +64,6 @@ async fn approve_checked(token_program: Pubkey) {
6464
4,
6565
)
6666
.unwrap();
67-
approve_ix.program_id = token_program;
6867

6968
let tx = Transaction::new_signed_with_payer(
7069
&[approve_ix],

p-token/tests/batch.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ fn batch_instruction(instructions: Vec<Instruction>) -> Result<Instruction, Prog
4040
})
4141
}
4242

43-
#[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
4443
#[tokio::test]
45-
async fn batch(token_program: Pubkey) {
44+
async fn batch() {
4645
let context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
4746
.start_with_context()
4847
.await;
@@ -63,10 +62,10 @@ async fn batch(token_program: Pubkey) {
6362
&mint_a.pubkey(),
6463
mint_rent,
6564
mint_len as u64,
66-
&token_program,
65+
&TOKEN_PROGRAM_ID,
6766
);
6867
let initialize_mint_ix = spl_token::instruction::initialize_mint(
69-
&token_program,
68+
&TOKEN_PROGRAM_ID,
7069
&mint_a.pubkey(),
7170
&mint_authority.pubkey(),
7271
None,
@@ -82,10 +81,10 @@ async fn batch(token_program: Pubkey) {
8281
&mint_b.pubkey(),
8382
mint_rent,
8483
mint_len as u64,
85-
&token_program,
84+
&TOKEN_PROGRAM_ID,
8685
);
8786
let initialize_mint_with_freeze_authority_ix = spl_token::instruction::initialize_mint2(
88-
&token_program,
87+
&TOKEN_PROGRAM_ID,
8988
&mint_b.pubkey(),
9089
&mint_authority.pubkey(),
9190
Some(&freeze_authority),
@@ -104,24 +103,24 @@ async fn batch(token_program: Pubkey) {
104103
&owner_a_ta_a.pubkey(),
105104
account_rent,
106105
account_len as u64,
107-
&token_program,
106+
&TOKEN_PROGRAM_ID,
108107
);
109108
let create_owner_b_ta_a = system_instruction::create_account(
110109
&context.payer.pubkey(),
111110
&owner_b_ta_a.pubkey(),
112111
account_rent,
113112
account_len as u64,
114-
&token_program,
113+
&TOKEN_PROGRAM_ID,
115114
);
116115
let intialize_owner_a_ta_a = spl_token::instruction::initialize_account3(
117-
&token_program,
116+
&TOKEN_PROGRAM_ID,
118117
&owner_a_ta_a.pubkey(),
119118
&mint_a.pubkey(),
120119
&owner_a.pubkey(),
121120
)
122121
.unwrap();
123122
let intialize_owner_b_ta_a = spl_token::instruction::initialize_account3(
124-
&token_program,
123+
&TOKEN_PROGRAM_ID,
125124
&owner_b_ta_a.pubkey(),
126125
&mint_a.pubkey(),
127126
&owner_b.pubkey(),
@@ -130,7 +129,7 @@ async fn batch(token_program: Pubkey) {
130129

131130
// Mint Token A to Owner A
132131
let mint_token_a_to_owner_a = spl_token::instruction::mint_to(
133-
&token_program,
132+
&TOKEN_PROGRAM_ID,
134133
&mint_a.pubkey(),
135134
&owner_a_ta_a.pubkey(),
136135
&mint_authority.pubkey(),
@@ -141,7 +140,7 @@ async fn batch(token_program: Pubkey) {
141140

142141
// Transfer Token A from Owner A to Owner B
143142
let transfer_token_a_to_owner_b = spl_token::instruction::transfer(
144-
&token_program,
143+
&TOKEN_PROGRAM_ID,
145144
&owner_a_ta_a.pubkey(),
146145
&owner_b_ta_a.pubkey(),
147146
&owner_a.pubkey(),
@@ -152,7 +151,7 @@ async fn batch(token_program: Pubkey) {
152151

153152
// Close Token A
154153
let close_owner_a_ta_a = spl_token::instruction::close_account(
155-
&token_program,
154+
&TOKEN_PROGRAM_ID,
156155
&owner_a_ta_a.pubkey(),
157156
&owner_a.pubkey(),
158157
&owner_a.pubkey(),

p-token/tests/burn.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use {
1111
},
1212
};
1313

14-
#[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
1514
#[tokio::test]
16-
async fn burn(token_program: Pubkey) {
15+
async fn burn() {
1716
let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
1817
.start_with_context()
1918
.await;
@@ -27,7 +26,7 @@ async fn burn(token_program: Pubkey) {
2726
&mut context,
2827
mint_authority.pubkey(),
2928
Some(freeze_authority),
30-
&token_program,
29+
&TOKEN_PROGRAM_ID,
3130
)
3231
.await
3332
.unwrap();
@@ -36,25 +35,25 @@ async fn burn(token_program: Pubkey) {
3635

3736
let owner = Keypair::new();
3837

39-
let account = account::initialize(&mut context, &mint, &owner.pubkey(), &token_program).await;
38+
let account =
39+
account::initialize(&mut context, &mint, &owner.pubkey(), &TOKEN_PROGRAM_ID).await;
4040

4141
mint::mint(
4242
&mut context,
4343
&mint,
4444
&account,
4545
&mint_authority,
4646
100,
47-
&token_program,
47+
&TOKEN_PROGRAM_ID,
4848
)
4949
.await
5050
.unwrap();
5151

5252
// When we burn 50 tokens.
5353

54-
let mut burn_ix =
54+
let burn_ix =
5555
spl_token::instruction::burn(&spl_token::ID, &account, &mint, &owner.pubkey(), &[], 50)
5656
.unwrap();
57-
burn_ix.program_id = token_program;
5857

5958
let tx = Transaction::new_signed_with_payer(
6059
&[burn_ix],

p-token/tests/burn_checked.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use {
1111
},
1212
};
1313

14-
#[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
1514
#[tokio::test]
16-
async fn burn_checked(token_program: Pubkey) {
15+
async fn burn_checked() {
1716
let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
1817
.start_with_context()
1918
.await;
@@ -27,7 +26,7 @@ async fn burn_checked(token_program: Pubkey) {
2726
&mut context,
2827
mint_authority.pubkey(),
2928
Some(freeze_authority),
30-
&token_program,
29+
&TOKEN_PROGRAM_ID,
3130
)
3231
.await
3332
.unwrap();
@@ -36,22 +35,23 @@ async fn burn_checked(token_program: Pubkey) {
3635

3736
let owner = Keypair::new();
3837

39-
let account = account::initialize(&mut context, &mint, &owner.pubkey(), &token_program).await;
38+
let account =
39+
account::initialize(&mut context, &mint, &owner.pubkey(), &TOKEN_PROGRAM_ID).await;
4040

4141
mint::mint(
4242
&mut context,
4343
&mint,
4444
&account,
4545
&mint_authority,
4646
100,
47-
&token_program,
47+
&TOKEN_PROGRAM_ID,
4848
)
4949
.await
5050
.unwrap();
5151

5252
// When we burn 50 tokens.
5353

54-
let mut burn_ix = spl_token::instruction::burn_checked(
54+
let burn_ix = spl_token::instruction::burn_checked(
5555
&spl_token::ID,
5656
&account,
5757
&mint,
@@ -61,7 +61,6 @@ async fn burn_checked(token_program: Pubkey) {
6161
4,
6262
)
6363
.unwrap();
64-
burn_ix.program_id = token_program;
6564

6665
let tx = Transaction::new_signed_with_payer(
6766
&[burn_ix],

0 commit comments

Comments
 (0)