Skip to content

Commit 07b8d19

Browse files
committed
fix tests, fix: account compression cpi size calculation
1 parent 5c7e2e5 commit 07b8d19

File tree

20 files changed

+211
-81
lines changed

20 files changed

+211
-81
lines changed

.github/workflows/light-system-programs-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
- program: light-compressed-token
6565
sub-tests: '["cargo-test-sbf -p compressed-token-test"]'
6666
- program: system-cpi-test
67-
sub-tests: '["cargo-test-sbf -p system-cpi-test"]'
67+
sub-tests: '["cargo-test-sbf -p system-cpi-test", "cargo test -p light-system-program-pinocchio --all-features"]'
6868
- program: system-cpi-test-v2-event
6969
sub-tests: '["cargo-test-sbf -p system-cpi-v2-test -- event::parse"]'
7070
- program: system-cpi-test-v2-functional

anchor-programs/system/src/cpi_context_account.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ impl CpiContextAccount {
4141
}
4242
}
4343

44-
pub struct ZCpiContextAccount<'a> {
44+
pub struct ZCpiContextAccount2<'a> {
4545
pub fee_payer: Ref<&'a mut [u8], light_compressed_account::pubkey::Pubkey>,
4646
pub associated_merkle_tree: Ref<&'a mut [u8], light_compressed_account::pubkey::Pubkey>,
4747
pub context: Vec<ZInstructionDataInvokeCpi<'a>>,
4848
}
4949

5050
pub fn deserialize_cpi_context_account<'info, 'a>(
5151
account_info: &AccountInfo<'info>,
52-
) -> std::result::Result<ZCpiContextAccount<'a>, ZeroCopyError> {
52+
) -> std::result::Result<ZCpiContextAccount2<'a>, ZeroCopyError> {
5353
let mut account_data = account_info.try_borrow_mut_data().unwrap();
5454
let data = unsafe { slice::from_raw_parts_mut(account_data.as_mut_ptr(), account_data.len()) };
5555
let (fee_payer, data) =
@@ -64,7 +64,7 @@ pub fn deserialize_cpi_context_account<'info, 'a>(
6464
context.push(context_item);
6565
data = new_data;
6666
}
67-
Ok(ZCpiContextAccount {
67+
Ok(ZCpiContextAccount2 {
6868
fee_payer,
6969
associated_merkle_tree,
7070
context,

cli/accounts/cpi_context_cpi1uHzrEhBG733DoEJNgHCyRS3XmmyVNZx5fonubE4.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

cli/accounts/cpi_context_cpi2cdhkH5roePvcudTgUL8ppEBfTay1desGh8G8QxK.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

program-libs/account-checks/src/account_iterator.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ impl<'info, T: AccountInfoTrait> AccountIterator<'info, T> {
110110
Ok(account_info)
111111
}
112112

113+
#[inline(always)]
114+
#[track_caller]
115+
pub fn next_signer_non_mut(&mut self, account_name: &str) -> Result<&'info T, AccountError> {
116+
let account_info = self.next_signer(account_name)?;
117+
check_non_mut(account_info)
118+
.inspect_err(|e| self.print_on_error(e, account_name, Location::caller()))?;
119+
Ok(account_info)
120+
}
121+
113122
#[inline(always)]
114123
#[track_caller]
115124
pub fn next_non_mut(&mut self, account_name: &str) -> Result<&'info T, AccountError> {

program-tests/system-test/tests/test_re_init_cpi_account.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use light_program_test::{
88
ProgramTestConfig,
99
};
1010
use light_sdk::constants::{
11-
CPI_CONTEXT_ACCOUNT_DISCRIMINATOR, CPI_CONTEXT_ACCOUNT_DISCRIMINATOR_V1,
11+
CPI_CONTEXT_ACCOUNT_2_DISCRIMINATOR, CPI_CONTEXT_ACCOUNT_DISCRIMINATOR,
1212
};
1313
use light_system_program_pinocchio::cpi_context::state::deserialize_cpi_context_account;
1414
use light_test_utils::{legacy_cpi_context_account::get_legacy_cpi_context_account, Rpc};
@@ -63,7 +63,7 @@ async fn test_re_init_cpi_account() {
6363
.unwrap();
6464
assert_eq!(
6565
&pre_account.data[0..8],
66-
&CPI_CONTEXT_ACCOUNT_DISCRIMINATOR_V1,
66+
&CPI_CONTEXT_ACCOUNT_2_DISCRIMINATOR,
6767
"Account should have legacy discriminator"
6868
);
6969
assert_eq!(

programs/compressed-token/src/process_transfer.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,16 @@ pub fn cpi_execute_compressed_transaction_transfer<
471471
);
472472
data.extend(inputs);
473473

474-
// 4 static accounts
475-
let accounts_len = 4 + remaining_accounts.len() + cpi_context.is_some() as usize;
474+
// 6 static accounts
475+
let accounts_len = 6 + remaining_accounts.len() + cpi_context.is_some() as usize;
476476
let mut account_infos = Vec::with_capacity(accounts_len);
477477
let mut account_metas = Vec::with_capacity(accounts_len);
478478
account_infos.push(ctx.get_fee_payer().to_account_info());
479479
account_infos.push(cpi_authority_pda);
480480
account_infos.push(ctx.get_registered_program_pda().to_account_info());
481481
account_infos.push(ctx.get_account_compression_authority().to_account_info());
482+
account_infos.push(ctx.get_account_compression_program().to_account_info());
483+
account_infos.push(ctx.get_system_program().to_account_info());
482484

483485
account_metas.push(AccountMeta {
484486
pubkey: account_infos[0].key(),

programs/system/src/accounts/account_checks.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use light_program_profiler::profile;
1414
use pinocchio::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey};
1515

1616
use crate::{
17-
cpi_context::state::ZCpiContextAccount,
17+
cpi_context::state::ZCpiContextAccount2,
1818
processor::sol_compression::{SOL_POOL_PDA_BUMP, SOL_POOL_PDA_SEED},
1919
Result,
2020
};
@@ -104,7 +104,7 @@ pub fn check_anchor_option_cpi_context_account(
104104
} else {
105105
{
106106
check_owner(&crate::ID, option_cpi_context_account)?;
107-
check_discriminator::<ZCpiContextAccount>(
107+
check_discriminator::<ZCpiContextAccount2>(
108108
option_cpi_context_account.try_borrow_data()?.as_ref(),
109109
)?;
110110
}
@@ -149,7 +149,7 @@ pub fn check_option_cpi_context_account<'a>(
149149
location.column()
150150
)
151151
})?;
152-
check_discriminator::<ZCpiContextAccount>(account_info.try_borrow_data()?.as_ref())
152+
check_discriminator::<ZCpiContextAccount2>(account_info.try_borrow_data()?.as_ref())
153153
.inspect_err(|_| {
154154
let location = Location::caller();
155155
solana_msg::msg!(

programs/system/src/accounts/init_context_account.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ use light_program_profiler::profile;
1111
use pinocchio::{account_info::AccountInfo, program_error::ProgramError};
1212

1313
use crate::{
14-
cpi_context::state::{
15-
cpi_context_account_new, CpiContextAccountInitParams, CpiContextAccountLegacy,
16-
},
14+
cpi_context::state::{cpi_context_account_new, CpiContextAccount, CpiContextAccountInitParams},
1715
errors::SystemProgramError,
1816
Result,
1917
};
@@ -62,7 +60,7 @@ pub fn init_cpi_context_account(accounts: &[AccountInfo]) -> Result<()> {
6260
let ctx = InitializeCpiContextAccount::from_account_infos(accounts)?;
6361
let params: CpiContextAccountInitParams =
6462
CpiContextAccountInitParams::new(*ctx.associated_merkle_tree.key());
65-
cpi_context_account_new::<false>(ctx.cpi_context_account, params)?;
63+
cpi_context_account_new::<false>(ctx.cpi_context_account, params).map(|_| ())?;
6664

6765
Ok(())
6866
}
@@ -75,13 +73,13 @@ pub fn reinit_cpi_context_account(accounts: &[AccountInfo]) -> Result<()> {
7573
let cpi_context_account = &accounts[0];
7674
let associated_merkle_tree = {
7775
let data = cpi_context_account.try_borrow_data()?;
78-
CpiContextAccountLegacy::deserialize(&mut &data[8..])
76+
CpiContextAccount::deserialize(&mut &data[8..])
7977
.map_err(|_| ProgramError::BorshIoError)?
8078
.associated_merkle_tree
8179
};
8280
let params: CpiContextAccountInitParams =
8381
CpiContextAccountInitParams::new(associated_merkle_tree);
84-
cpi_context_account_new::<true>(cpi_context_account, params)?;
82+
cpi_context_account_new::<true>(cpi_context_account, params).map(|_| ())?;
8583

8684
Ok(())
8785
}

programs/system/src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub const INVOKE_CPI_INSTRUCTION: [u8; 8] = [49, 212, 191, 129, 39, 194, 43, 196
1212
pub const INVOKE_CPI_WITH_READ_ONLY_INSTRUCTION: [u8; 8] = [86, 47, 163, 166, 21, 223, 92, 8];
1313
// discriminator of CpiContextAccount2
1414
pub const CPI_CONTEXT_ACCOUNT_DISCRIMINATOR: [u8; 8] = [34, 184, 183, 14, 100, 80, 183, 124];
15-
pub const CPI_CONTEXT_ACCOUNT_DISCRIMINATOR_V1: [u8; 8] = [22, 20, 149, 218, 74, 204, 128, 166];
15+
pub const CPI_CONTEXT_ACCOUNT_2_DISCRIMINATOR: [u8; 8] = [22, 20, 149, 218, 74, 204, 128, 166];
1616
pub const INVOKE_CPI_WITH_ACCOUNT_INFO_INSTRUCTION: [u8; 8] = [228, 34, 128, 84, 47, 139, 86, 240];
1717
pub const RE_INIT_CPI_CONTEXT_ACCOUNT_INSTRUCTION: [u8; 8] =
1818
[187, 147, 22, 142, 104, 180, 136, 190];

0 commit comments

Comments
 (0)