Skip to content

Commit 8d88564

Browse files
committed
Address taco's feedback
1 parent 9f09261 commit 8d88564

File tree

11 files changed

+115
-110
lines changed

11 files changed

+115
-110
lines changed

magicblock-committor-service/src/intent_executor/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub mod two_stage_executor;
66

77
use std::{mem, ops::ControlFlow, sync::Arc, time::Duration};
88

9-
#[cfg(any(test, feature = "dev-context-only-utils"))]
9+
#[cfg(test)]
1010
mod null_task_info_fetcher;
1111

1212
use async_trait::async_trait;
@@ -25,7 +25,7 @@ use magicblock_rpc_client::{
2525
MagicBlockRpcClientError, MagicBlockSendTransactionConfig,
2626
MagicBlockSendTransactionOutcome, MagicblockRpcClient,
2727
};
28-
#[cfg(any(test, feature = "dev-context-only-utils"))]
28+
#[cfg(test)]
2929
pub use null_task_info_fetcher::*;
3030
use solana_keypair::Keypair;
3131
use solana_message::VersionedMessage;

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

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -303,33 +303,28 @@ pub type BaseTaskResult<T> = Result<T, BaseTaskError>;
303303

304304
#[cfg(test)]
305305
mod serialization_safety_test {
306-
use std::sync::Arc;
307306

308307
use magicblock_program::{
309308
args::ShortAccountMeta, magic_scheduled_base_intent::ProgramArgs,
310309
};
311310
use solana_account::Account;
312311

313-
use crate::{
314-
intent_executor::NullTaskInfoFetcher,
315-
tasks::{
316-
args_task::{ArgsTask, ArgsTaskType},
317-
buffer_task::BufferTask,
318-
task_builder::TaskBuilderImpl,
319-
*,
320-
},
312+
use crate::tasks::{
313+
args_task::{ArgsTask, ArgsTaskType},
314+
buffer_task::{BufferTask, BufferTaskType},
315+
*,
321316
};
322317

323318
// Test all ArgsTask variants
324-
#[tokio::test]
325-
async fn test_args_task_instruction_serialization() {
319+
#[test]
320+
fn test_args_task_instruction_serialization() {
326321
let validator = Pubkey::new_unique();
327322

328323
// Test Commit variant
329-
let commit_task: ArgsTask = TaskBuilderImpl::create_commit_task(
330-
123,
331-
true,
332-
CommittedAccount {
324+
let commit_task: ArgsTask = ArgsTaskType::Commit(CommitTask {
325+
commit_id: 123,
326+
allow_undelegation: true,
327+
committed_account: CommittedAccount {
333328
pubkey: Pubkey::new_unique(),
334329
account: Account {
335330
lamports: 1000,
@@ -339,9 +334,8 @@ mod serialization_safety_test {
339334
rent_epoch: 0,
340335
},
341336
},
342-
&Arc::new(NullTaskInfoFetcher),
343-
)
344-
.await;
337+
})
338+
.into();
345339
assert_serializable(&commit_task.instruction(&validator));
346340

347341
// Test Finalize variant
@@ -382,15 +376,15 @@ mod serialization_safety_test {
382376
}
383377

384378
// Test BufferTask variants
385-
#[tokio::test]
386-
async fn test_buffer_task_instruction_serialization() {
379+
#[test]
380+
fn test_buffer_task_instruction_serialization() {
387381
let validator = Pubkey::new_unique();
388382

389383
let buffer_task = BufferTask::new_preparation_required(
390-
TaskBuilderImpl::create_commit_task(
391-
456,
392-
false,
393-
CommittedAccount {
384+
BufferTaskType::Commit(CommitTask {
385+
commit_id: 456,
386+
allow_undelegation: false,
387+
committed_account: CommittedAccount {
394388
pubkey: Pubkey::new_unique(),
395389
account: Account {
396390
lamports: 2000,
@@ -400,26 +394,22 @@ mod serialization_safety_test {
400394
rent_epoch: 0,
401395
},
402396
},
403-
&Arc::new(NullTaskInfoFetcher),
404-
)
405-
.await
406-
.task_type
407-
.into(),
397+
}),
408398
);
409399
assert_serializable(&buffer_task.instruction(&validator));
410400
}
411401

412402
// Test preparation instructions
413-
#[tokio::test]
414-
async fn test_preparation_instructions_serialization() {
403+
#[test]
404+
fn test_preparation_instructions_serialization() {
415405
let authority = Pubkey::new_unique();
416406

417407
// Test BufferTask preparation
418408
let buffer_task = BufferTask::new_preparation_required(
419-
TaskBuilderImpl::create_commit_task(
420-
789,
421-
true,
422-
CommittedAccount {
409+
BufferTaskType::Commit(CommitTask {
410+
commit_id: 789,
411+
allow_undelegation: true,
412+
committed_account: CommittedAccount {
423413
pubkey: Pubkey::new_unique(),
424414
account: Account {
425415
lamports: 3000,
@@ -429,11 +419,7 @@ mod serialization_safety_test {
429419
rent_epoch: 0,
430420
},
431421
},
432-
&Arc::new(NullTaskInfoFetcher),
433-
)
434-
.await
435-
.task_type
436-
.into(),
422+
}),
437423
);
438424

439425
let PreparationState::Required(preparation_task) =

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

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ use crate::{
1313
ScheduleCommitInstruction,
1414
};
1515

16+
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
17+
pub enum UserSeeds {
18+
MagicScheduleCommit,
19+
OrderBook,
20+
}
21+
22+
impl UserSeeds {
23+
pub fn bytes(&self) -> &'static [u8] {
24+
match self {
25+
UserSeeds::MagicScheduleCommit => b"magic_schedule_commit",
26+
UserSeeds::OrderBook => b"order_book",
27+
}
28+
}
29+
}
30+
1631
pub fn init_account_instruction(
1732
payer: Pubkey,
1833
player: Pubkey,
@@ -101,20 +116,15 @@ pub fn delegate_account_cpi_instruction(
101116
payer: Pubkey,
102117
validator: Option<Pubkey>,
103118
player_or_book_manager: Pubkey,
104-
user_seed: &[u8],
119+
user_seed: UserSeeds,
105120
) -> Instruction {
106121
let program_id = crate::id();
107122
let (pda, _) = Pubkey::find_program_address(
108-
&[user_seed, player_or_book_manager.as_ref()],
123+
&[user_seed.bytes(), player_or_book_manager.as_ref()],
109124
&crate::ID,
110125
);
111126

112127
let delegate_accounts = DelegateAccounts::new(pda, program_id);
113-
println!("delegate_accounts: {:#?}", delegate_accounts);
114-
println!(
115-
"config: {:#?}",
116-
dlp::pda::program_config_from_program_id(&crate::ID)
117-
);
118128

119129
let delegate_metas = DelegateAccountMetas::from(delegate_accounts);
120130
let account_metas = vec![
@@ -130,21 +140,24 @@ pub fn delegate_account_cpi_instruction(
130140

131141
Instruction::new_with_borsh(
132142
program_id,
133-
&if user_seed == b"magic_schedule_commit" {
134-
ScheduleCommitInstruction::DelegateCpi(DelegateCpiArgs {
135-
valid_until: i64::MAX,
136-
commit_frequency_ms: 1_000_000_000,
137-
player: player_or_book_manager,
138-
validator,
139-
})
140-
} else {
141-
ScheduleCommitInstruction::DelegateOrderBook(
142-
DelegateOrderBookArgs {
143+
&match user_seed {
144+
UserSeeds::MagicScheduleCommit => {
145+
ScheduleCommitInstruction::DelegateCpi(DelegateCpiArgs {
146+
valid_until: i64::MAX,
143147
commit_frequency_ms: 1_000_000_000,
144-
book_manager: player_or_book_manager,
148+
player: player_or_book_manager,
145149
validator,
146-
},
147-
)
150+
})
151+
}
152+
UserSeeds::OrderBook => {
153+
ScheduleCommitInstruction::DelegateOrderBook(
154+
DelegateOrderBookArgs {
155+
commit_frequency_ms: 1_000_000_000,
156+
book_manager: player_or_book_manager,
157+
validator,
158+
},
159+
)
160+
}
148161
},
149162
account_metas,
150163
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ pub struct MainAccount {
230230
}
231231

232232
impl MainAccount {
233-
pub const SIZE: u64 = std::mem::size_of::<Self>() as u64;
233+
pub const SIZE: usize = std::mem::size_of::<Self>();
234234

235235
pub fn try_decode(data: &[u8]) -> std::io::Result<Self> {
236236
Self::try_from_slice(data)
@@ -821,7 +821,7 @@ fn process_undelegate_request(
821821

822822
{
823823
let mut data = delegated_account.try_borrow_mut_data()?;
824-
match data.len() as u64 {
824+
match data.len() {
825825
MainAccount::SIZE => match MainAccount::try_from_slice(&data) {
826826
Ok(counter) => {
827827
msg!("counter: {:?}", counter);

test-integration/programs/schedulecommit/src/utils/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub struct AllocateAndAssignAccountArgs<'a, 'b> {
5050
pub payer_info: &'a AccountInfo<'a>,
5151
pub account_info: &'a AccountInfo<'a>,
5252
pub owner: &'a Pubkey,
53-
pub size: u64,
53+
pub size: usize,
5454
pub signer_seeds: &'b [&'b [u8]],
5555
}
5656

@@ -68,7 +68,7 @@ pub fn allocate_account_and_assign_owner(
6868
} = args;
6969

7070
let required_lamports = rent
71-
.minimum_balance(size as usize)
71+
.minimum_balance(size)
7272
.max(1)
7373
.saturating_sub(account_info.lamports());
7474

@@ -87,7 +87,10 @@ pub fn allocate_account_and_assign_owner(
8787
// At this point the account is still owned by the system program
8888
msg!(" create_account() allocate space");
8989
invoke_signed(
90-
&system_instruction::allocate(account_info.key, size),
90+
&system_instruction::allocate(
91+
account_info.key,
92+
size.try_into().unwrap(),
93+
),
9194
// 0. `[WRITE, SIGNER]` New account
9295
std::slice::from_ref(account_info),
9396
&[signer_seeds],

test-integration/schedulecommit/client/src/schedule_commit_context.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use integration_test_tools::IntegrationTestContext;
55
use log::*;
66
use program_schedulecommit::api::{
77
delegate_account_cpi_instruction, init_account_instruction,
8-
init_order_book_instruction, init_payer_escrow,
8+
init_order_book_instruction, init_payer_escrow, UserSeeds,
99
};
1010
use solana_rpc_client::rpc_client::{RpcClient, SerializableTransaction};
1111
use solana_rpc_client_api::config::RpcSendTransactionConfig;
@@ -31,7 +31,7 @@ pub struct ScheduleCommitTestContext {
3131
pub payer_ephem: Keypair,
3232
// The Payer keypairs along with its PDA pubkey which we'll commit
3333
pub committees: Vec<(Keypair, Pubkey)>,
34-
user_seed: Vec<u8>,
34+
user_seed: UserSeeds,
3535

3636
common_ctx: IntegrationTestContext,
3737
}
@@ -65,18 +65,18 @@ impl ScheduleCommitTestContext {
6565
// -----------------
6666
pub fn try_new_random_keys(
6767
ncommittees: usize,
68-
user_seed: &[u8],
68+
user_seed: UserSeeds,
6969
) -> Result<Self> {
7070
Self::try_new_internal(ncommittees, true, user_seed)
7171
}
72-
pub fn try_new(ncommittees: usize, user_seed: &[u8]) -> Result<Self> {
72+
pub fn try_new(ncommittees: usize, user_seed: UserSeeds) -> Result<Self> {
7373
Self::try_new_internal(ncommittees, false, user_seed)
7474
}
7575

7676
fn try_new_internal(
7777
ncommittees: usize,
7878
random_keys: bool,
79-
user_seed: &[u8],
79+
user_seed: UserSeeds,
8080
) -> Result<Self> {
8181
let ictx = IntegrationTestContext::try_new()?;
8282

@@ -113,7 +113,7 @@ impl ScheduleCommitTestContext {
113113
)
114114
.unwrap();
115115
let (pda, _bump) = Pubkey::find_program_address(
116-
&[user_seed, payer_ephem.pubkey().as_ref()],
116+
&[user_seed.bytes(), payer_ephem.pubkey().as_ref()],
117117
&program_schedulecommit::ID,
118118
);
119119
(payer_ephem, pda)
@@ -155,7 +155,7 @@ impl ScheduleCommitTestContext {
155155
payer_ephem,
156156
committees,
157157
common_ctx: ictx,
158-
user_seed: user_seed.to_vec(),
158+
user_seed,
159159
})
160160
}
161161

@@ -167,8 +167,8 @@ impl ScheduleCommitTestContext {
167167
ComputeBudgetInstruction::set_compute_unit_limit(1_400_000),
168168
ComputeBudgetInstruction::set_compute_unit_price(10_000),
169169
];
170-
match self.user_seed.as_slice() {
171-
b"magic_schedule_commit" => {
170+
match self.user_seed {
171+
UserSeeds::MagicScheduleCommit => {
172172
ixs.extend(self.committees.iter().map(
173173
|(player, committee)| {
174174
init_account_instruction(
@@ -179,7 +179,7 @@ impl ScheduleCommitTestContext {
179179
},
180180
));
181181
}
182-
b"order_book" => {
182+
UserSeeds::OrderBook => {
183183
ixs.extend(self.committees.iter().map(
184184
|(book_manager, committee)| {
185185
init_order_book_instruction(
@@ -205,9 +205,6 @@ impl ScheduleCommitTestContext {
205205
// },
206206
// ));
207207
}
208-
_ => {
209-
return Err(anyhow::anyhow!("Unsupported user_seed: {:?} ; expected b\"magic_schedule_commit\" or b\"order_book\"", self.user_seed));
210-
}
211208
};
212209

213210
let mut signers = self
@@ -272,7 +269,7 @@ impl ScheduleCommitTestContext {
272269
self.payer_chain.pubkey(),
273270
self.ephem_validator_identity,
274271
player.pubkey(),
275-
&self.user_seed,
272+
self.user_seed,
276273
);
277274
ixs.push(ix);
278275
}

0 commit comments

Comments
 (0)