Skip to content

Commit ce2395e

Browse files
committed
interface: include onramp in deposit/withdraw
1 parent 474d7f1 commit ce2395e

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

program/src/instruction.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ pub fn deposit_stake(
315315
let accounts = vec![
316316
AccountMeta::new_readonly(*pool_address, false),
317317
AccountMeta::new(find_pool_stake_address(program_id, pool_address), false),
318+
AccountMeta::new_readonly(find_pool_onramp_address(program_id, pool_address), false),
318319
AccountMeta::new(find_pool_mint_address(program_id, pool_address), false),
319320
AccountMeta::new_readonly(
320321
find_pool_stake_authority_address(program_id, pool_address),
@@ -393,6 +394,7 @@ pub fn withdraw_stake(
393394
let accounts = vec![
394395
AccountMeta::new_readonly(*pool_address, false),
395396
AccountMeta::new(find_pool_stake_address(program_id, pool_address), false),
397+
AccountMeta::new_readonly(find_pool_onramp_address(program_id, pool_address), false),
396398
AccountMeta::new(find_pool_mint_address(program_id, pool_address), false),
397399
AccountMeta::new_readonly(
398400
find_pool_stake_authority_address(program_id, pool_address),

program/tests/accounts.rs

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mod helpers;
55

66
use {
77
helpers::*,
8-
solana_instruction::AccountMeta,
98
solana_program_test::*,
109
solana_pubkey::pubkey,
1110
solana_sdk::{
@@ -36,7 +35,7 @@ async fn build_instructions(
3635
context: &mut ProgramTestContext,
3736
accounts: &SinglePoolAccounts,
3837
test_mode: TestMode,
39-
include_onramp: bool,
38+
remove_onramp: bool,
4039
) -> (Vec<Instruction>, usize) {
4140
let initialize_instructions = if test_mode == TestMode::Initialize {
4241
let slot = context.genesis_config().epoch_schedule.first_normal_slot + 1;
@@ -131,29 +130,15 @@ async fn build_instructions(
131130
vec![]
132131
};
133132

134-
if include_onramp {
133+
if remove_onramp {
135134
let instruction = match test_mode {
136135
TestMode::Deposit => deposit_instructions.last_mut().unwrap(),
137136
TestMode::Withdraw => withdraw_instructions.last_mut().unwrap(),
138137
TestMode::Initialize => unreachable!(),
139138
};
140139

141-
if instruction.accounts[2].pubkey == accounts.mint {
142-
instruction.accounts.insert(
143-
2,
144-
AccountMeta {
145-
pubkey: accounts.onramp_account,
146-
is_writable: false,
147-
is_signer: false,
148-
},
149-
);
150-
} else {
151-
panic!(
152-
"this test enforces forwards-compat pre-instruction builder change. \
153-
if you are adding onramp to builders, refactor `include_onramp` to \
154-
be an `exclude_onramp` and test backwards-compat instead"
155-
);
156-
}
140+
assert_eq!(instruction.accounts[2].pubkey, accounts.onramp_account);
141+
instruction.accounts.remove(2);
157142
}
158143

159144
// ints hardcoded to guard against instructions moving with code changes
@@ -172,16 +157,16 @@ async fn build_instructions(
172157

173158
// test that account addresses are checked properly
174159
#[test_case(TestMode::Initialize, false; "initialize")]
175-
#[test_case(TestMode::Deposit, false; "deposit_legacy")]
176-
#[test_case(TestMode::Withdraw, false; "withdraw_legacy")]
177-
#[test_case(TestMode::Deposit, true; "deposit_onramp")]
178-
#[test_case(TestMode::Withdraw, true; "withdraw_onramp")]
160+
#[test_case(TestMode::Deposit, true; "deposit_legacy")]
161+
#[test_case(TestMode::Withdraw, true; "withdraw_legacy")]
162+
#[test_case(TestMode::Deposit, false; "deposit_onramp")]
163+
#[test_case(TestMode::Withdraw, false; "withdraw_onramp")]
179164
#[tokio::test]
180-
async fn fail_account_checks(test_mode: TestMode, include_onramp: bool) {
165+
async fn fail_account_checks(test_mode: TestMode, remove_onramp: bool) {
181166
let mut context = program_test(false).start_with_context().await;
182167
let accounts = SinglePoolAccounts::default();
183168
let (instructions, i) =
184-
build_instructions(&mut context, &accounts, test_mode, include_onramp).await;
169+
build_instructions(&mut context, &accounts, test_mode, remove_onramp).await;
185170
let bad_pubkey = pubkey!("BAD1111111111111111111111111111111111111111");
186171

187172
for j in 0..instructions[i].accounts.len() {
@@ -195,8 +180,7 @@ async fn fail_account_checks(test_mode: TestMode, include_onramp: bool) {
195180

196181
// while onramp is optional, an incorrect onramp misaligns all subsequent accounts
197182
// this is not a problem for the program and causes the mint to fail to validate, but requires tweaking this test
198-
// NOTE once deposit/withdraw require onramp, delete this block
199-
if include_onramp && instruction_pubkey == accounts.pool {
183+
if !remove_onramp && instruction_pubkey == accounts.pool {
200184
if let Some(onramp_account) = instructions[i]
201185
.accounts
202186
.iter_mut()

0 commit comments

Comments
 (0)