Skip to content

Commit d0bf8f4

Browse files
authored
chore: fix and rename sdk test to anchor sdk test (#1645)
* chore: fix and rename sdk test to anchor sdk test * fix: pnpm lockfile * chore: renamed anchor-sdk-test -> sdk-anchor-test * fix: pnpm lock * remove warnings * cleanup sdk-anchor-test
1 parent cb803c0 commit d0bf8f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1971
-1100
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ members = [
2424
"sdk-libs/program-test",
2525
"xtask",
2626
"examples/anchor/token-escrow",
27-
"examples/anchor/name-service-without-macros",
28-
"examples/anchor/counter",
29-
"examples/anchor/memo",
27+
# "examples/anchor/name-service-without-macros",
28+
# "examples/anchor/counter",
29+
# "examples/anchor/memo",
3030
"program-tests/account-compression-test",
3131
"program-tests/compressed-token-test",
3232
"program-tests/e2e-test",
3333
"program-tests/registry-test",
3434
"program-tests/system-cpi-test",
3535
"program-tests/system-test",
36-
"program-tests/sdk-test-program/programs/sdk-test",
36+
"program-tests/sdk-anchor-test/programs/sdk-anchor-test",
37+
"program-tests/sdk-test",
3738
"program-tests/create-address-test-program",
3839
"program-tests/utils",
3940
"program-tests/merkle-tree",

examples/anchor/counter/src/lib.rs

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub mod counter {
1212
use light_hasher::Discriminator;
1313
use light_sdk::{
1414
address::derive_address, error::LightSdkError,
15-
program_merkle_context::unpack_address_merkle_context,
15+
program_merkle_context::unpack_address_merkle_context, system_accounts::LightCpiAccounts,
1616
};
1717

1818
use super::*;
@@ -48,8 +48,20 @@ pub mod counter {
4848

4949
counter.owner = ctx.accounts.signer.key();
5050
counter.value = 0;
51-
52-
verify_light_accounts(&ctx, inputs.proof, &[counter], None, false, None)?;
51+
let light_cpi_accounts = LightCpiAccounts::new(
52+
ctx.accounts.signer.as_ref(),
53+
ctx.accounts.cpi_signer.as_ref(),
54+
ctx.remaining_accounts,
55+
);
56+
verify_light_accounts(
57+
&light_cpi_accounts,
58+
inputs.proof,
59+
&[counter],
60+
None,
61+
false,
62+
None,
63+
)
64+
.map_err(ProgramError::from)?;
5365

5466
Ok(())
5567
}
@@ -70,8 +82,20 @@ pub mod counter {
7082
return err!(CustomError::Unauthorized);
7183
}
7284
counter.value = counter.value.checked_add(1).ok_or(CustomError::Overflow)?;
73-
verify_light_accounts(&ctx, inputs.proof, &[counter], None, false, None)?;
74-
85+
let light_cpi_accounts = LightCpiAccounts::new(
86+
ctx.accounts.signer.as_ref(),
87+
ctx.accounts.cpi_signer.as_ref(),
88+
ctx.remaining_accounts,
89+
);
90+
verify_light_accounts(
91+
&light_cpi_accounts,
92+
inputs.proof,
93+
&[counter],
94+
None,
95+
false,
96+
None,
97+
)
98+
.map_err(ProgramError::from)?;
7599
Ok(())
76100
}
77101
pub fn decrement_counter<'info>(
@@ -93,8 +117,20 @@ pub mod counter {
93117

94118
counter.value = counter.value.checked_sub(1).ok_or(CustomError::Underflow)?;
95119

96-
verify_light_accounts(&ctx, inputs.proof, &[counter], None, false, None)?;
97-
120+
let light_cpi_accounts = LightCpiAccounts::new(
121+
ctx.accounts.signer.as_ref(),
122+
ctx.accounts.cpi_signer.as_ref(),
123+
ctx.remaining_accounts,
124+
);
125+
verify_light_accounts(
126+
&light_cpi_accounts,
127+
inputs.proof,
128+
&[counter],
129+
None,
130+
false,
131+
None,
132+
)
133+
.map_err(ProgramError::from)?;
98134
Ok(())
99135
}
100136

@@ -116,8 +152,20 @@ pub mod counter {
116152
}
117153

118154
counter.value = 0;
119-
verify_light_accounts(&ctx, inputs.proof, &[counter], None, false, None)?;
120-
155+
let light_cpi_accounts = LightCpiAccounts::new(
156+
ctx.accounts.signer.as_ref(),
157+
ctx.accounts.cpi_signer.as_ref(),
158+
ctx.remaining_accounts,
159+
);
160+
verify_light_accounts(
161+
&light_cpi_accounts,
162+
inputs.proof,
163+
&[counter],
164+
None,
165+
false,
166+
None,
167+
)
168+
.map_err(ProgramError::from)?;
121169
Ok(())
122170
}
123171
}

examples/anchor/memo/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"]
2424
anchor-lang = { workspace = true }
2525
borsh = { workspace = true }
2626
light-hasher = { workspace = true, features = ["solana"] }
27-
light-sdk = { workspace = true }
27+
light-sdk = { workspace = true, features = ["anchor"] }
2828
light-compressed-account = { workspace = true }
29+
solana-program = { workspace = true }
2930

3031
[target.'cfg(not(target_os = "solana"))'.dependencies]
3132
solana-sdk = { workspace = true }

examples/anchor/memo/src/lib.rs

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ use anchor_lang::prelude::*;
22
use borsh::BorshDeserialize;
33
use light_sdk::{
44
account::LightAccount, instruction_data::LightInstructionData, light_system_accounts,
5-
verify::verify_light_accounts, LightDiscriminator, LightHasher, LightTraits,
5+
system_accounts::LightCpiAccounts, verify::verify_light_accounts, LightDiscriminator,
6+
LightHasher, LightTraits,
67
};
78

9+
use solana_program::program_error::ProgramError;
10+
811
declare_id!("GRLu2hKaAiMbxpkAM1HeXzks9YeGuz18SEgXEizVvPqX");
912

1013
#[program]
@@ -30,7 +33,8 @@ pub mod memo {
3033

3134
let address_merkle_context = accounts[0]
3235
.address_merkle_context
33-
.ok_or(LightSdkError::ExpectedAddressMerkleContext)?;
36+
.ok_or(LightSdkError::ExpectedAddressMerkleContext)
37+
.map_err(ProgramError::from)?;
3438
let address_merkle_context =
3539
unpack_address_merkle_context(address_merkle_context, ctx.remaining_accounts);
3640
let (address, address_seed) = derive_address(
@@ -45,12 +49,27 @@ pub mod memo {
4549
address,
4650
address_seed,
4751
&crate::ID,
48-
)?;
52+
)
53+
.map_err(ProgramError::from)?;
4954

5055
memo.authority = ctx.accounts.signer.key();
5156
memo.message = message;
5257

53-
verify_light_accounts(&ctx, inputs.proof, &[memo], None, false, None)?;
58+
let light_cpi_accounts = LightCpiAccounts::new(
59+
ctx.accounts.signer.as_ref(),
60+
ctx.accounts.cpi_signer.as_ref(),
61+
ctx.remaining_accounts,
62+
);
63+
64+
verify_light_accounts(
65+
&light_cpi_accounts,
66+
inputs.proof,
67+
&[memo],
68+
None,
69+
false,
70+
None,
71+
)
72+
.map_err(ProgramError::from)?;
5473

5574
Ok(())
5675
}
@@ -64,18 +83,34 @@ pub mod memo {
6483
let accounts = inputs
6584
.accounts
6685
.as_ref()
67-
.ok_or(LightSdkError::ExpectedAccounts)?;
86+
.ok_or(LightSdkError::ExpectedAccounts)
87+
.map_err(ProgramError::from)?;
6888

6989
let mut memo: LightAccount<'_, MemoAccount> =
70-
LightAccount::from_meta_mut(&accounts[0], MemoAccount::discriminator(), &crate::ID)?;
90+
LightAccount::from_meta_mut(&accounts[0], MemoAccount::discriminator(), &crate::ID)
91+
.map_err(ProgramError::from)?;
7192

7293
if memo.authority != ctx.accounts.signer.key() {
7394
return err!(CustomError::Unauthorized);
7495
}
7596

7697
memo.message = new_message;
7798

78-
verify_light_accounts(&ctx, inputs.proof, &[memo], None, false, None)?;
99+
let light_cpi_accounts = LightCpiAccounts::new(
100+
ctx.accounts.signer.as_ref(),
101+
ctx.accounts.cpi_signer.as_ref(),
102+
ctx.remaining_accounts,
103+
);
104+
105+
verify_light_accounts(
106+
&light_cpi_accounts,
107+
inputs.proof,
108+
&[memo],
109+
None,
110+
false,
111+
None,
112+
)
113+
.map_err(ProgramError::from)?;
79114

80115
Ok(())
81116
}
@@ -88,16 +123,31 @@ pub mod memo {
88123
let accounts = inputs
89124
.accounts
90125
.as_ref()
91-
.ok_or(LightSdkError::ExpectedAccounts)?;
126+
.ok_or(LightSdkError::ExpectedAccounts)
127+
.map_err(ProgramError::from)?;
92128

93129
let memo: LightAccount<'_, MemoAccount> =
94-
LightAccount::from_meta_close(&accounts[0], MemoAccount::discriminator(), &crate::ID)?;
130+
LightAccount::from_meta_close(&accounts[0], MemoAccount::discriminator(), &crate::ID)
131+
.map_err(ProgramError::from)?;
95132

96133
if memo.authority != ctx.accounts.signer.key() {
97134
return err!(CustomError::Unauthorized);
98135
}
136+
let light_cpi_accounts = LightCpiAccounts::new(
137+
ctx.accounts.signer.as_ref(),
138+
ctx.accounts.cpi_signer.as_ref(),
139+
ctx.remaining_accounts,
140+
);
99141

100-
verify_light_accounts(&ctx, inputs.proof, &[memo], None, false, None)?;
142+
verify_light_accounts(
143+
&light_cpi_accounts,
144+
inputs.proof,
145+
&[memo],
146+
None,
147+
false,
148+
None,
149+
)
150+
.map_err(ProgramError::from)?;
101151

102152
Ok(())
103153
}

examples/anchor/token-escrow/src/escrow_with_compressed_pda/escrow.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ use light_compressed_token::{
1818
};
1919
use light_hasher::{errors::HasherError, DataHasher, Hasher, Poseidon};
2020
use light_sdk::{
21-
legacy::create_cpi_inputs_for_new_account, light_system_accounts, verify::verify, LightTraits,
21+
legacy::create_cpi_inputs_for_new_account,
22+
light_system_accounts,
23+
system_accounts::{LightCpiAccounts, SystemAccountInfoConfig},
24+
traits::*,
25+
verify::verify,
26+
LightTraits,
2227
};
2328

2429
use crate::{create_change_output_compressed_token_account, program::TokenEscrow, EscrowTimeLock};
@@ -97,7 +102,6 @@ pub fn process_escrow_compressed_tokens_with_compressed_pda<'info>(
97102
cpi_compressed_pda_transfer(ctx, proof, new_address_params, compressed_pda, cpi_context)?;
98103
Ok(())
99104
}
100-
101105
fn cpi_compressed_pda_transfer<'info>(
102106
ctx: Context<'_, '_, '_, 'info, EscrowCompressedTokensWithCompressedPda<'info>>,
103107
proof: CompressedProof,
@@ -116,8 +120,33 @@ fn cpi_compressed_pda_transfer<'info>(
116120
compressed_pda,
117121
Some(cpi_context),
118122
);
123+
let mut system_accounts = vec![
124+
ctx.accounts.get_light_system_program().clone(),
125+
ctx.accounts.get_authority().clone(),
126+
ctx.accounts.get_registered_program_pda().clone(),
127+
ctx.accounts.get_noop_program().clone(),
128+
ctx.accounts.get_account_compression_authority().clone(),
129+
ctx.accounts.get_account_compression_program().clone(),
130+
ctx.accounts.self_program.to_account_info(),
131+
ctx.accounts.get_system_program().clone(),
132+
ctx.accounts
133+
.get_cpi_context_account()
134+
.unwrap_or(&ctx.accounts.get_light_system_program())
135+
.clone(),
136+
];
137+
system_accounts.extend_from_slice(ctx.remaining_accounts);
138+
let light_accounts = LightCpiAccounts::new_with_config(
139+
ctx.accounts.signer.as_ref(),
140+
&system_accounts,
141+
SystemAccountInfoConfig {
142+
self_program: crate::ID,
143+
cpi_context: true,
144+
..Default::default()
145+
},
146+
)
147+
.unwrap();
119148

120-
verify(&ctx, &inputs_struct, &[&signer_seeds])?;
149+
verify(&light_accounts, &inputs_struct, &[&signer_seeds]).map_err(ProgramError::from)?;
121150

122151
Ok(())
123152
}

examples/anchor/token-escrow/src/escrow_with_compressed_pda/withdrawal.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ use light_compressed_token::process_transfer::{
1414
PackedTokenTransferOutputData,
1515
};
1616
use light_hasher::{DataHasher, Poseidon};
17-
use light_sdk::verify::verify;
17+
use light_sdk::{
18+
system_accounts::{LightCpiAccounts, SystemAccountInfoConfig},
19+
traits::*,
20+
verify::verify,
21+
};
1822

1923
use crate::{
2024
create_change_output_compressed_token_account, EscrowCompressedTokensWithCompressedPda,
@@ -148,8 +152,32 @@ fn cpi_compressed_pda_withdrawal<'info>(
148152
is_compress: false,
149153
cpi_context: Some(cpi_context),
150154
};
151-
152-
verify(&ctx, &inputs_struct, &[&signer_seeds])?;
155+
let mut system_accounts = vec![
156+
ctx.accounts.get_light_system_program().clone(),
157+
ctx.accounts.get_authority().clone(),
158+
ctx.accounts.get_registered_program_pda().clone(),
159+
ctx.accounts.get_noop_program().clone(),
160+
ctx.accounts.get_account_compression_authority().clone(),
161+
ctx.accounts.get_account_compression_program().clone(),
162+
ctx.accounts.self_program.to_account_info(),
163+
ctx.accounts.get_system_program().clone(),
164+
ctx.accounts
165+
.get_cpi_context_account()
166+
.unwrap_or(&ctx.accounts.get_light_system_program())
167+
.clone(),
168+
];
169+
system_accounts.extend_from_slice(ctx.remaining_accounts);
170+
let light_accounts = LightCpiAccounts::new_with_config(
171+
ctx.accounts.signer.as_ref(),
172+
&system_accounts,
173+
SystemAccountInfoConfig {
174+
self_program: crate::ID,
175+
cpi_context: true,
176+
..Default::default()
177+
},
178+
)
179+
.unwrap();
180+
verify(&light_accounts, &inputs_struct, &[&signer_seeds]).map_err(ProgramError::from)?;
153181

154182
Ok(())
155183
}

0 commit comments

Comments
 (0)