Skip to content

Commit 70de96d

Browse files
author
tilo-14
committed
Refactor tests to use to_account_metas, remove unused dependency
- Replace manual AccountMeta vectors with to_account_metas(Some(true)) - Fix create-token-account: change account field to Signer for CPI - Remove unused light-token-interface dependency from all Cargo.toml
1 parent af76cbd commit 70de96d

27 files changed

Lines changed: 159 additions & 205 deletions

File tree

program-examples/anchor/programs-sdk/Cargo.lock

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

program-examples/anchor/programs-sdk/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@ solana-program = "2.2"
3838
light-sdk = { version = "0.19.0", features = ["anchor", "idl-build", "v2", "anchor-discriminator", "cpi-context"] }
3939
light-token = { version = "0.4.0", features = ["anchor"] }
4040
light-token-types = { version = "0.4.0", features = ["anchor"] }
41-
light-token-interface = "0.3.0"
4241
light-program-test = "0.19.0"
4342
light-client = { version = "0.19.0", features = ["v2", "anchor"] }

program-examples/anchor/programs-sdk/approve/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ light-token = { workspace = true }
2121
[dev-dependencies]
2222
light-program-test = { workspace = true }
2323
light-client = { workspace = true }
24-
light-token-interface = { workspace = true }
2524
borsh = { workspace = true }
2625
tokio = { workspace = true }
2726
solana-sdk = { workspace = true }

program-examples/anchor/programs-sdk/approve/tests/test.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
use anchor_lang::InstructionData;
1+
use anchor_lang::{InstructionData, ToAccountMetas};
22
use light_program_test::Rpc;
33
use light_token::instruction::LIGHT_TOKEN_PROGRAM_ID;
4-
use light_token_anchor_approve::{instruction::Approve, ID};
5-
use solana_sdk::{
6-
instruction::{AccountMeta, Instruction},
7-
signature::Keypair,
8-
signer::Signer,
9-
system_program,
10-
};
4+
use light_token_anchor_approve::{accounts, instruction::Approve, ID};
5+
use solana_sdk::{instruction::Instruction, signature::Keypair, signer::Signer, system_program};
116
use test_utils::{mint_tokens, setup_test_env};
127

138
#[tokio::test]
@@ -24,13 +19,14 @@ async fn test_approve() {
2419

2520
let ix = Instruction {
2621
program_id: ID,
27-
accounts: vec![
28-
AccountMeta::new_readonly(LIGHT_TOKEN_PROGRAM_ID, false),
29-
AccountMeta::new(env.ata, false),
30-
AccountMeta::new_readonly(delegate.pubkey(), false),
31-
AccountMeta::new_readonly(env.payer.pubkey(), true),
32-
AccountMeta::new_readonly(system_program::ID, false),
33-
],
22+
accounts: accounts::ApproveAccounts {
23+
light_token_program: LIGHT_TOKEN_PROGRAM_ID,
24+
token_account: env.ata,
25+
delegate: delegate.pubkey(),
26+
owner: env.payer.pubkey(),
27+
system_program: system_program::ID,
28+
}
29+
.to_account_metas(Some(true)),
3430
data: Approve { amount: approve_amount }.data(),
3531
};
3632

program-examples/anchor/programs-sdk/burn/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ light-token = { workspace = true }
2222
light-program-test = { workspace = true }
2323
light-client = { workspace = true }
2424
light-token = { workspace = true }
25-
light-token-interface = { workspace = true }
2625
borsh = { workspace = true }
2726
tokio = { workspace = true }
2827
solana-sdk = { workspace = true }

program-examples/anchor/programs-sdk/burn/tests/test.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
use anchor_lang::InstructionData;
1+
use anchor_lang::{InstructionData, ToAccountMetas};
22
use light_program_test::Rpc;
33
use light_token::instruction::LIGHT_TOKEN_PROGRAM_ID;
4-
use light_token_anchor_burn::{instruction::Burn, ID};
5-
use solana_sdk::{
6-
instruction::{AccountMeta, Instruction},
7-
signer::Signer,
8-
system_program,
9-
};
4+
use light_token_anchor_burn::{accounts, instruction::Burn, ID};
5+
use solana_sdk::{instruction::Instruction, signer::Signer, system_program};
106
use test_utils::{mint_tokens, setup_test_env};
117

128
#[tokio::test]
@@ -21,13 +17,14 @@ async fn test_burn() {
2117
let burn_amount = 250_000u64;
2218
let ix = Instruction {
2319
program_id: ID,
24-
accounts: vec![
25-
AccountMeta::new_readonly(LIGHT_TOKEN_PROGRAM_ID, false),
26-
AccountMeta::new(env.ata, false),
27-
AccountMeta::new(env.mint_pda, false),
28-
AccountMeta::new_readonly(env.payer.pubkey(), true),
29-
AccountMeta::new_readonly(system_program::ID, false),
30-
],
20+
accounts: accounts::BurnAccounts {
21+
light_token_program: LIGHT_TOKEN_PROGRAM_ID,
22+
source: env.ata,
23+
mint: env.mint_pda,
24+
authority: env.payer.pubkey(),
25+
system_program: system_program::ID,
26+
}
27+
.to_account_metas(Some(true)),
3128
data: Burn { amount: burn_amount }.data(),
3229
};
3330

program-examples/anchor/programs-sdk/close/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ light-token = { workspace = true }
2121
[dev-dependencies]
2222
light-program-test = { workspace = true }
2323
light-client = { workspace = true }
24-
light-token-interface = { workspace = true }
2524
borsh = { workspace = true }
2625
tokio = { workspace = true }
2726
solana-sdk = { workspace = true }

program-examples/anchor/programs-sdk/close/tests/test.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
use anchor_lang::InstructionData;
1+
use anchor_lang::{InstructionData, ToAccountMetas};
22
use light_program_test::Rpc;
33
use light_token::instruction::{rent_sponsor_pda, LIGHT_TOKEN_PROGRAM_ID};
4-
use light_token_anchor_close::{instruction::CloseAccount, ID};
5-
use solana_sdk::{
6-
instruction::{AccountMeta, Instruction},
7-
signer::Signer,
8-
};
4+
use light_token_anchor_close::{accounts, instruction::CloseAccount, ID};
5+
use solana_sdk::{instruction::Instruction, signer::Signer};
96
use test_utils::setup_test_env;
107

118
#[tokio::test]
@@ -19,13 +16,14 @@ async fn test_close() {
1916

2017
let ix = Instruction {
2118
program_id: ID,
22-
accounts: vec![
23-
AccountMeta::new_readonly(LIGHT_TOKEN_PROGRAM_ID, false),
24-
AccountMeta::new(env.ata, false),
25-
AccountMeta::new(env.payer.pubkey(), false),
26-
AccountMeta::new_readonly(env.payer.pubkey(), true),
27-
AccountMeta::new(rent_sponsor, false),
28-
],
19+
accounts: accounts::CloseAccountAccounts {
20+
light_token_program: LIGHT_TOKEN_PROGRAM_ID,
21+
account: env.ata,
22+
destination: env.payer.pubkey(),
23+
owner: env.payer.pubkey(),
24+
rent_sponsor,
25+
}
26+
.to_account_metas(Some(true)),
2927
data: CloseAccount {}.data(),
3028
};
3129

program-examples/anchor/programs-sdk/create-ata/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ light-token = { workspace = true }
2121
[dev-dependencies]
2222
light-program-test = { workspace = true }
2323
light-client = { workspace = true }
24-
light-token-interface = { workspace = true }
2524
borsh = { workspace = true }
2625
tokio = { workspace = true }
2726
solana-sdk = { workspace = true }

program-examples/anchor/programs-sdk/create-ata/tests/test.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use anchor_lang::InstructionData;
1+
use anchor_lang::{InstructionData, ToAccountMetas};
22
use light_client::indexer::AddressWithTree;
33
use light_program_test::{Indexer, LightProgramTest, ProgramTestConfig, Rpc};
4-
use light_token_anchor_create_ata::{instruction::CreateAta, ID};
4+
use light_token_anchor_create_ata::{accounts, instruction::CreateAta, ID};
55
use light_token::instruction::{
66
CreateMint, CreateMintParams, config_pda, derive_mint_compressed_address, derive_token_ata,
77
find_mint_address, rent_sponsor_pda, LIGHT_TOKEN_PROGRAM_ID,
88
};
99
use anchor_lang::system_program;
1010
use solana_sdk::{
11-
instruction::{AccountMeta, Instruction},
11+
instruction::Instruction,
1212
signature::Keypair,
1313
signer::Signer,
1414
};
@@ -82,16 +82,17 @@ async fn test_create_ata() {
8282

8383
let ix = Instruction {
8484
program_id: ID,
85-
accounts: vec![
86-
AccountMeta::new_readonly(LIGHT_TOKEN_PROGRAM_ID, false),
87-
AccountMeta::new_readonly(payer.pubkey(), false),
88-
AccountMeta::new_readonly(mint_pda, false),
89-
AccountMeta::new(payer.pubkey(), true),
90-
AccountMeta::new(ata, false),
91-
AccountMeta::new_readonly(system_program::ID, false),
92-
AccountMeta::new_readonly(compressible_config, false),
93-
AccountMeta::new(rent_sponsor, false),
94-
],
85+
accounts: accounts::CreateAtaAccounts {
86+
light_token_program: LIGHT_TOKEN_PROGRAM_ID,
87+
owner: payer.pubkey(),
88+
mint: mint_pda,
89+
payer: payer.pubkey(),
90+
associated_token_account: ata,
91+
system_program: system_program::ID,
92+
compressible_config,
93+
rent_sponsor,
94+
}
95+
.to_account_metas(Some(true)),
9596
data: CreateAta {
9697
bump: ata_bump,
9798
idempotent: false,

0 commit comments

Comments
 (0)