Skip to content

Commit a92678c

Browse files
committed
add tests
1 parent 7edaf8f commit a92678c

2 files changed

Lines changed: 43 additions & 19 deletions

File tree

test-integration/programs/schedulecommit/src/api.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use solana_program::{
1010

1111
use crate::{
1212
BookUpdate, DelegateCpiArgs, DelegateOrderBookArgs, ScheduleCommitCpiArgs,
13-
ScheduleCommitInstruction,
13+
ScheduleCommitInstruction, ScheduleCommitType,
1414
};
1515

1616
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
@@ -212,11 +212,12 @@ pub fn update_order_book_instruction(
212212
)
213213
}
214214

215-
pub fn schedule_commit_diff_instruction_for_order_book(
215+
pub fn schedule_commit_instruction_for_order_book(
216216
payer: Pubkey,
217217
order_book: Pubkey,
218218
magic_program_id: Pubkey,
219219
magic_context_id: Pubkey,
220+
commit_type: ScheduleCommitType,
220221
) -> Instruction {
221222
let program_id = crate::id();
222223
let account_metas = vec![
@@ -228,7 +229,7 @@ pub fn schedule_commit_diff_instruction_for_order_book(
228229

229230
Instruction::new_with_borsh(
230231
program_id,
231-
&ScheduleCommitInstruction::ScheduleCommitForOrderBook,
232+
&ScheduleCommitInstruction::ScheduleCommitForOrderBook(commit_type),
232233
account_metas,
233234
)
234235
}

test-integration/programs/schedulecommit/src/lib.rs

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,14 @@ pub enum ScheduleCommitInstruction {
160160
UpdateOrderBook(BookUpdate),
161161

162162
/// ScheduleCommitDiffCpi
163-
ScheduleCommitForOrderBook,
163+
ScheduleCommitForOrderBook(ScheduleCommitType),
164+
}
165+
166+
#[derive(BorshSerialize, BorshDeserialize, Debug, Clone)]
167+
pub enum ScheduleCommitType {
168+
CommitAndUndelegate,
169+
CommitFinalize,
170+
CommitFinalizeAndUndelegate,
164171
}
165172

166173
pub fn process_instruction<'a>(
@@ -217,8 +224,8 @@ pub fn process_instruction<'a>(
217224
}
218225
DelegateOrderBook(args) => process_delegate_order_book(accounts, args),
219226
UpdateOrderBook(args) => process_update_order_book(accounts, args),
220-
ScheduleCommitForOrderBook => {
221-
process_schedulecommit_for_orderbook(accounts)
227+
ScheduleCommitForOrderBook(commit_type) => {
228+
process_schedulecommit_for_orderbook(accounts, commit_type)
222229
}
223230
}
224231
}
@@ -451,6 +458,7 @@ fn process_update_order_book<'a>(
451458
// -----------------
452459
pub fn process_schedulecommit_for_orderbook(
453460
accounts: &[AccountInfo],
461+
commit_type: ScheduleCommitType,
454462
) -> Result<(), ProgramError> {
455463
msg!("Processing schedulecommit (for orderbook) instruction");
456464

@@ -461,12 +469,32 @@ pub fn process_schedulecommit_for_orderbook(
461469

462470
assert_is_signer(payer, "payer")?;
463471

464-
commit_finalize_and_undelegate_accounts(
465-
payer,
466-
vec![order_book_account],
467-
magic_context,
468-
magic_program,
469-
)?;
472+
match commit_type {
473+
ScheduleCommitType::CommitAndUndelegate => {
474+
commit_and_undelegate_accounts(
475+
payer,
476+
vec![order_book_account],
477+
magic_context,
478+
magic_program,
479+
)?;
480+
}
481+
ScheduleCommitType::CommitFinalize => {
482+
commit_finalize_accounts(
483+
payer,
484+
vec![order_book_account],
485+
magic_context,
486+
magic_program,
487+
)?;
488+
}
489+
ScheduleCommitType::CommitFinalizeAndUndelegate => {
490+
commit_finalize_and_undelegate_accounts(
491+
payer,
492+
vec![order_book_account],
493+
magic_context,
494+
magic_program,
495+
)?;
496+
}
497+
};
470498

471499
Ok(())
472500
}
@@ -578,19 +606,14 @@ pub fn process_schedulecommit_cpi(
578606

579607
if args.undelegate {
580608
// TODO (snawaz): temporary change. UNDO THIS
581-
commit_finalize_and_undelegate_accounts(
609+
commit_and_undelegate_accounts(
582610
payer,
583611
committees,
584612
magic_context,
585613
magic_program,
586614
)?;
587615
} else {
588-
commit_finalize_accounts(
589-
payer,
590-
committees,
591-
magic_context,
592-
magic_program,
593-
)?;
616+
commit_accounts(payer, committees, magic_context, magic_program)?;
594617
}
595618

596619
Ok(())

0 commit comments

Comments
 (0)