Skip to content

Commit 5268eba

Browse files
committed
Add a test using huge OrderBook account
1 parent d65bbb9 commit 5268eba

File tree

13 files changed

+735
-100
lines changed

13 files changed

+735
-100
lines changed

magicblock-committor-service/src/tasks/args_task.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ impl BaseTask for ArgsTask {
112112
),
113113
allow_undelegation: value.allow_undelegation,
114114
};
115+
log::warn!("DIFF computed: {:?}", args.diff);
115116
dlp::instruction_builder::commit_diff(
116117
*validator,
117118
value.committed_account.pubkey,
@@ -213,7 +214,7 @@ impl BaseTask for ArgsTask {
213214
ArgsTaskType::Commit(_) => TaskType::Commit,
214215
// TODO (snawaz): What should we use here? Commit (in the sense of "category of task"), or add a
215216
// new variant "CommitDiff" to indicate a specific instruction?
216-
ArgsTaskType::CommitDiff(_) => unimplemented!("task_type"), //TaskType::Commit,
217+
ArgsTaskType::CommitDiff(_) => TaskType::Commit,
217218
ArgsTaskType::BaseAction(_) => TaskType::Action,
218219
ArgsTaskType::Undelegate(_) => TaskType::Undelegate,
219220
ArgsTaskType::Finalize(_) => TaskType::Finalize,

test-integration/Cargo.lock

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

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

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use solana_program::{
99
};
1010

1111
use crate::{
12-
DelegateCpiArgs, ScheduleCommitCpiArgs, ScheduleCommitInstruction,
12+
BookUpdate, DelegateCpiArgs, ScheduleCommitCpiArgs,
13+
ScheduleCommitInstruction,
1314
};
1415

1516
pub fn init_account_instruction(
@@ -30,6 +31,45 @@ pub fn init_account_instruction(
3031
)
3132
}
3233

34+
pub fn init_order_book_instruction(
35+
payer: Pubkey,
36+
order_book: Pubkey,
37+
) -> Instruction {
38+
let program_id = crate::id();
39+
let account_metas = vec![
40+
AccountMeta::new(payer, true),
41+
AccountMeta::new(order_book, false),
42+
//AccountMeta::new_readonly(system_program::id(), false),
43+
AccountMeta::new_readonly(system_program::id(), false),
44+
];
45+
46+
Instruction::new_with_borsh(
47+
program_id,
48+
&ScheduleCommitInstruction::InitOrderBook,
49+
account_metas,
50+
)
51+
}
52+
53+
pub fn grow_order_book_instruction(
54+
payer: Pubkey,
55+
order_book: Pubkey,
56+
additional_space: u64,
57+
) -> Instruction {
58+
let program_id = crate::id();
59+
let account_metas = vec![
60+
AccountMeta::new(payer, true),
61+
AccountMeta::new(order_book, false),
62+
//AccountMeta::new_readonly(system_program::id(), false),
63+
AccountMeta::new_readonly(system_program::id(), false),
64+
];
65+
66+
Instruction::new_with_borsh(
67+
program_id,
68+
&ScheduleCommitInstruction::GrowOrderBook(additional_space),
69+
account_metas,
70+
)
71+
}
72+
3373
pub fn init_payer_escrow(payer: Pubkey) -> [Instruction; 2] {
3474
let top_up_ix = dlp::instruction_builder::top_up_ephemeral_balance(
3575
payer,
@@ -53,9 +93,13 @@ pub fn init_payer_escrow(payer: Pubkey) -> [Instruction; 2] {
5393
[top_up_ix, delegate_ix]
5494
}
5595

56-
pub fn delegate_account_cpi_instruction(player: Pubkey) -> Instruction {
96+
pub fn delegate_account_cpi_instruction(
97+
player: Pubkey,
98+
user_seed: &[u8],
99+
) -> Instruction {
57100
let program_id = crate::id();
58-
let (pda, _) = pda_and_bump(&player);
101+
let (pda, _) =
102+
Pubkey::find_program_address(&[user_seed, player.as_ref()], &crate::ID);
59103

60104
let args = DelegateCpiArgs {
61105
valid_until: i64::MAX,
@@ -78,7 +122,11 @@ pub fn delegate_account_cpi_instruction(player: Pubkey) -> Instruction {
78122

79123
Instruction::new_with_borsh(
80124
program_id,
81-
&ScheduleCommitInstruction::DelegateCpi(args),
125+
&if user_seed == b"magic_schedule_commit" {
126+
ScheduleCommitInstruction::DelegateCpi(args)
127+
} else {
128+
ScheduleCommitInstruction::DelegateOrderBook(args)
129+
},
82130
account_metas,
83131
)
84132
}
@@ -114,6 +162,45 @@ pub fn schedule_commit_cpi_instruction(
114162
)
115163
}
116164

165+
pub fn update_order_book_instruction(
166+
payer: Pubkey,
167+
order_book: Pubkey,
168+
update: BookUpdate,
169+
) -> Instruction {
170+
let program_id = crate::id();
171+
let account_metas = vec![
172+
AccountMeta::new(payer, true),
173+
AccountMeta::new(order_book, false),
174+
];
175+
176+
Instruction::new_with_borsh(
177+
program_id,
178+
&ScheduleCommitInstruction::UpdateOrderBook(update),
179+
account_metas,
180+
)
181+
}
182+
183+
pub fn schedule_commit_diff_instruction_for_order_book(
184+
payer: Pubkey,
185+
order_book: Pubkey,
186+
magic_program_id: Pubkey,
187+
magic_context_id: Pubkey,
188+
) -> Instruction {
189+
let program_id = crate::id();
190+
let account_metas = vec![
191+
AccountMeta::new(payer, true),
192+
AccountMeta::new(order_book, false),
193+
AccountMeta::new(magic_context_id, false),
194+
AccountMeta::new_readonly(magic_program_id, false),
195+
];
196+
197+
Instruction::new_with_borsh(
198+
program_id,
199+
&ScheduleCommitInstruction::ScheduleCommitForOrderBook,
200+
account_metas,
201+
)
202+
}
203+
117204
pub fn schedule_commit_with_payer_cpi_instruction(
118205
payer: Pubkey,
119206
magic_program_id: Pubkey,

0 commit comments

Comments
 (0)