Skip to content

Commit a9b1d47

Browse files
committed
fix: tests
1 parent 0ad4311 commit a9b1d47

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

sdk-libs/sdk-types/src/cpi_accounts.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,13 @@ impl<'a, T: AccountInfoTrait> CpiAccounts<'a, T> {
200200
}
201201

202202
pub fn cpi_context(&self) -> Result<&'a T> {
203-
let index = CompressionCpiAccountIndex::CpiContext as usize;
203+
let mut index = CompressionCpiAccountIndex::CpiContext as usize;
204+
if !self.config.sol_pool_pda {
205+
index -= 1;
206+
}
207+
if !self.config.sol_compression_recipient {
208+
index -= 1;
209+
}
204210
self.accounts
205211
.get(index)
206212
.ok_or(LightSdkTypesError::CpiAccountsIndexOutOfBounds(index))

sdk-libs/sdk/src/cpi/accounts.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ pub fn get_account_metas_from_config(config: CpiInstructionConfig<'_, '_>) -> Ve
7575
is_writable: false,
7676
});
7777

78-
// 8. Light System Program (readonly)
79-
let light_system_program_meta = AccountMeta {
78+
// 8. Light System Program (readonly) - reused for optional accounts
79+
let create_light_system_meta = || AccountMeta {
8080
pubkey: Pubkey::from(LIGHT_SYSTEM_PROGRAM_ID),
8181
is_signer: false,
8282
is_writable: false,
@@ -90,7 +90,7 @@ pub fn get_account_metas_from_config(config: CpiInstructionConfig<'_, '_>) -> Ve
9090
is_writable: true,
9191
});
9292
} else {
93-
account_metas.push(light_system_program_meta.clone());
93+
account_metas.push(create_light_system_meta());
9494
}
9595

9696
// 10. Sol Compression Recipient (writable) OR Light System Program (readonly)
@@ -101,7 +101,7 @@ pub fn get_account_metas_from_config(config: CpiInstructionConfig<'_, '_>) -> Ve
101101
is_writable: true,
102102
});
103103
} else {
104-
account_metas.push(light_system_program_meta.clone());
104+
account_metas.push(create_light_system_meta());
105105
}
106106

107107
// 11. System Program (readonly) - always default pubkey
@@ -119,7 +119,7 @@ pub fn get_account_metas_from_config(config: CpiInstructionConfig<'_, '_>) -> Ve
119119
is_writable: true,
120120
});
121121
} else {
122-
account_metas.push(light_system_program_meta);
122+
account_metas.push(create_light_system_meta());
123123
}
124124

125125
for acc in config.packed_accounts {

0 commit comments

Comments
 (0)