Skip to content

Commit e496457

Browse files
committed
fix tests
1 parent 5e9c354 commit e496457

File tree

9 files changed

+141
-119
lines changed

9 files changed

+141
-119
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ use magicblock_rpc_client::{
2525
MagicBlockRpcClientError, MagicBlockSendTransactionConfig,
2626
MagicBlockSendTransactionOutcome, MagicblockRpcClient,
2727
};
28-
29-
use solana_keypair::Keypair;
30-
use solana_message::VersionedMessage;
31-
3228
#[cfg(any(test, feature = "dev-context-only-utils"))]
3329
pub use null_task_info_fetcher::*;
34-
30+
use solana_keypair::Keypair;
31+
use solana_message::VersionedMessage;
3532
use solana_pubkey::Pubkey;
3633
use solana_rpc_client_api::config::RpcTransactionConfig;
3734
use solana_signature::Signature;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use magicblock_metrics::metrics::LabelValue;
44
use solana_instruction::Instruction;
55
use solana_pubkey::Pubkey;
66

7+
#[cfg(any(test, feature = "dev-context-only-utils"))]
8+
use super::args_task::ArgsTaskType;
79
#[cfg(test)]
810
use crate::tasks::TaskStrategy;
911
use crate::{
@@ -62,6 +64,17 @@ impl BufferTask {
6264
}
6365
}
6466

67+
#[cfg(any(test, feature = "dev-context-only-utils"))]
68+
impl From<ArgsTaskType> for BufferTaskType {
69+
fn from(value: ArgsTaskType) -> Self {
70+
match value {
71+
ArgsTaskType::Commit(task) => BufferTaskType::Commit(task),
72+
ArgsTaskType::CommitDiff(_) => panic!("BufferTask doesn't support CommitDiff yet. Disable your tests temporarily till the next PR"),
73+
_ => unimplemented!("Only commit task can be BufferTask currently. Fix your tests"),
74+
}
75+
}
76+
}
77+
6578
impl BaseTask for BufferTask {
6679
fn instruction(&self, validator: &Pubkey) -> Instruction {
6780
let BufferTaskType::Commit(ref value) = self.task_type;

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

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub(crate) mod task_visitors;
2929
pub mod utils;
3030
pub mod visitor;
3131

32+
pub use task_builder::TaskBuilderImpl;
33+
3234
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
3335
pub enum TaskType {
3436
Commit,
@@ -301,6 +303,8 @@ pub type BaseTaskResult<T> = Result<T, BaseTaskError>;
301303

302304
#[cfg(test)]
303305
mod serialization_safety_test {
306+
use std::sync::Arc;
307+
304308
use magicblock_program::{
305309
args::ShortAccountMeta, magic_scheduled_base_intent::ProgramArgs,
306310
};
@@ -310,7 +314,7 @@ mod serialization_safety_test {
310314
intent_executor::NullTaskInfoFetcher,
311315
tasks::{
312316
args_task::{ArgsTask, ArgsTaskType},
313-
buffer_task::{BufferTask, BufferTaskType},
317+
buffer_task::BufferTask,
314318
task_builder::TaskBuilderImpl,
315319
*,
316320
},
@@ -382,25 +386,26 @@ mod serialization_safety_test {
382386
async fn test_buffer_task_instruction_serialization() {
383387
let validator = Pubkey::new_unique();
384388

385-
let buffer_task =
386-
BufferTask::new_preparation_required(BufferTaskType::Commit(
387-
TaskBuilderImpl::create_commit_task(
388-
456,
389-
false,
390-
CommittedAccount {
391-
pubkey: Pubkey::new_unique(),
392-
account: Account {
393-
lamports: 2000,
394-
data: vec![7, 8, 9],
395-
owner: Pubkey::new_unique(),
396-
executable: false,
397-
rent_epoch: 0,
398-
},
389+
let buffer_task = BufferTask::new_preparation_required(
390+
TaskBuilderImpl::create_commit_task(
391+
456,
392+
false,
393+
CommittedAccount {
394+
pubkey: Pubkey::new_unique(),
395+
account: Account {
396+
lamports: 2000,
397+
data: vec![7, 8, 9],
398+
owner: Pubkey::new_unique(),
399+
executable: false,
400+
rent_epoch: 0,
399401
},
400-
&Arc::new(NullTaskInfoFetcher),
401-
)
402-
.await,
403-
));
402+
},
403+
&Arc::new(NullTaskInfoFetcher),
404+
)
405+
.await
406+
.task_type
407+
.into(),
408+
);
404409
assert_serializable(&buffer_task.instruction(&validator));
405410
}
406411

@@ -410,25 +415,26 @@ mod serialization_safety_test {
410415
let authority = Pubkey::new_unique();
411416

412417
// Test BufferTask preparation
413-
let buffer_task =
414-
BufferTask::new_preparation_required(BufferTaskType::Commit(
415-
TaskBuilderImpl::create_commit_task(
416-
789,
417-
true,
418-
CommittedAccount {
419-
pubkey: Pubkey::new_unique(),
420-
account: Account {
421-
lamports: 3000,
422-
data: vec![0; 1024], // Larger data to test chunking
423-
owner: Pubkey::new_unique(),
424-
executable: false,
425-
rent_epoch: 0,
426-
},
418+
let buffer_task = BufferTask::new_preparation_required(
419+
TaskBuilderImpl::create_commit_task(
420+
789,
421+
true,
422+
CommittedAccount {
423+
pubkey: Pubkey::new_unique(),
424+
account: Account {
425+
lamports: 3000,
426+
data: vec![0; 1024], // Larger data to test chunking
427+
owner: Pubkey::new_unique(),
428+
executable: false,
429+
rent_epoch: 0,
427430
},
428-
&Arc::new(NullTaskInfoFetcher),
429-
)
430-
.await,
431-
));
431+
},
432+
&Arc::new(NullTaskInfoFetcher),
433+
)
434+
.await
435+
.task_type
436+
.into(),
437+
);
432438

433439
let PreparationState::Required(preparation_task) =
434440
buffer_task.preparation_state()

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use magicblock_program::magic_scheduled_base_intent::{
1010
use solana_pubkey::Pubkey;
1111
use solana_signature::Signature;
1212

13+
use super::{CommitDiffTask, CommitTask};
1314
use crate::{
1415
intent_executor::task_info_fetcher::{
1516
TaskInfoFetcher, TaskInfoFetcherError,
@@ -21,8 +22,6 @@ use crate::{
2122
},
2223
};
2324

24-
use super::{CommitDiffTask, CommitTask};
25-
2625
#[async_trait]
2726
pub trait TasksBuilder {
2827
// Creates tasks for commit stage
@@ -43,10 +42,12 @@ pub trait TasksBuilder {
4342
/// V1: Actions are part of finalize tx
4443
pub struct TaskBuilderImpl;
4544

46-
// Accounts larger than COMMIT_STATE_SIZE_THRESHOLD, use CommitDiff to
47-
// reduce instruction size. Below this, commit is sent as CommitState.
48-
// Chose 256 as thresold seems good enough as it could hold 8 u32 fields
49-
// or 4 u64 fields.
45+
// Accounts larger than COMMIT_STATE_SIZE_THRESHOLD use CommitDiff to
46+
// reduce instruction size. Below this threshold, the commit is sent
47+
// as CommitState. The value (256) is chosen because it is sufficient
48+
// for small accounts, which typically could hold up to 8 u32 fields or
49+
// 4 u64 fields. These integers are expected to be on the hot path
50+
// and updated continuously.
5051
const COMMIT_STATE_SIZE_THRESHOLD: usize = 256;
5152

5253
impl TaskBuilderImpl {
@@ -78,14 +79,14 @@ impl TaskBuilderImpl {
7879

7980
if let Some(base_account) = base_account {
8081
ArgsTaskType::CommitDiff(CommitDiffTask {
81-
commit_id: commit_id,
82+
commit_id,
8283
allow_undelegation,
8384
committed_account: account,
8485
base_account,
8586
})
8687
} else {
8788
ArgsTaskType::Commit(CommitTask {
88-
commit_id: commit_id,
89+
commit_id,
8990
allow_undelegation,
9091
committed_account: account,
9192
})

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

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -373,27 +373,30 @@ mod tests {
373373
use magicblock_program::magic_scheduled_base_intent::{
374374
BaseAction, CommittedAccount, ProgramArgs,
375375
};
376+
use magicblock_rpc_client::MagicBlockRpcClientResult;
376377
use solana_account::Account;
378+
use solana_program::system_program;
377379
use solana_pubkey::Pubkey;
378380
use solana_system_program::id as system_program_id;
379381

380382
use super::*;
381383
use crate::{
382384
intent_execution_manager::intent_scheduler::create_test_intent,
383-
intent_executor::task_info_fetcher::NullTaskInfoFetcher,
384-
intent_executor::task_info_fetcher::{
385-
ResetType, TaskInfoFetcher, TaskInfoFetcherResult,
385+
intent_executor::{
386+
task_info_fetcher::{
387+
ResetType, TaskInfoFetcher, TaskInfoFetcherResult,
388+
},
389+
NullTaskInfoFetcher,
386390
},
387391
persist::IntentPersisterImpl,
388392
tasks::{
389-
intent_executor::NullTaskInfoFetcher,
390-
persist::IntentPersisterImpl,
391393
task_builder::{TaskBuilderImpl, TasksBuilder},
392-
BaseActionTask, CommitTask, TaskStrategy, UndelegateTask,
394+
BaseActionTask, TaskStrategy, UndelegateTask,
393395
},
394396
};
395397

396398
struct MockInfoFetcher;
399+
397400
#[async_trait::async_trait]
398401
impl TaskInfoFetcher for MockInfoFetcher {
399402
async fn fetch_next_commit_ids(
@@ -415,31 +418,36 @@ mod tests {
415418
}
416419

417420
fn reset(&self, _: ResetType) {}
421+
422+
async fn get_base_account(
423+
&self,
424+
_pubkey: &Pubkey,
425+
) -> MagicBlockRpcClientResult<Option<Account>> {
426+
Ok(None) // Account Not Found
427+
}
418428
}
419429

420430
// Helper to create a simple commit task
421431
async fn create_test_commit_task(
422432
commit_id: u64,
423433
data_size: usize,
424434
) -> ArgsTask {
425-
ArgsTask::new(ArgsTaskType::Commit(
426-
TaskBuilderImpl::create_commit_task(
427-
commit_id,
428-
false,
429-
CommittedAccount {
430-
pubkey: Pubkey::new_unique(),
431-
account: Account {
432-
lamports: 1000,
433-
data: vec![1; data_size],
434-
owner: system_program::id(),
435-
executable: false,
436-
rent_epoch: 0,
437-
},
435+
TaskBuilderImpl::create_commit_task(
436+
commit_id,
437+
false,
438+
CommittedAccount {
439+
pubkey: Pubkey::new_unique(),
440+
account: Account {
441+
lamports: 1000,
442+
data: vec![1; data_size],
443+
owner: system_program::id(),
444+
executable: false,
445+
rent_epoch: 0,
438446
},
439-
&Arc::new(NullTaskInfoFetcher),
440-
)
441-
.await,
442-
))
447+
},
448+
&Arc::new(NullTaskInfoFetcher),
449+
)
450+
.await
443451
}
444452

445453
// Helper to create a Base action task

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use solana_program::{
1515
entrypoint::{self, ProgramResult},
1616
instruction::{AccountMeta, Instruction},
1717
msg,
18-
program::invoke,
19-
program::invoke_signed,
18+
program::{invoke, invoke_signed},
2019
program_error::ProgramError,
2120
pubkey::Pubkey,
2221
rent::Rent,

test-integration/test-committor-service/tests/common.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use magicblock_committor_service::{
1212
task_info_fetcher::{
1313
ResetType, TaskInfoFetcher, TaskInfoFetcherResult,
1414
},
15-
IntentExecutorImpl, NullTaskInfoFetcher,
15+
IntentExecutorImpl,
1616
},
17-
tasks::{CommitTask, TaskBuilderImpl},
17+
tasks::CommitTask,
1818
transaction_preparator::{
1919
delivery_preparator::DeliveryPreparator, TransactionPreparatorImpl,
2020
},
@@ -159,12 +159,12 @@ pub fn generate_random_bytes(length: usize) -> Vec<u8> {
159159
}
160160

161161
#[allow(dead_code)]
162-
pub async fn create_commit_task(data: &[u8]) -> CommitTask {
162+
pub fn create_commit_task(data: &[u8]) -> CommitTask {
163163
static COMMIT_ID: AtomicU64 = AtomicU64::new(0);
164-
TaskBuilderImpl::create_commit_task(
165-
COMMIT_ID.fetch_add(1, Ordering::Relaxed),
166-
false,
167-
CommittedAccount {
164+
CommitTask {
165+
commit_id: COMMIT_ID.fetch_add(1, Ordering::Relaxed),
166+
allow_undelegation: false,
167+
committed_account: CommittedAccount {
168168
pubkey: Pubkey::new_unique(),
169169
account: Account {
170170
lamports: 1000,
@@ -174,9 +174,7 @@ pub async fn create_commit_task(data: &[u8]) -> CommitTask {
174174
rent_epoch: 0,
175175
},
176176
},
177-
&Arc::new(NullTaskInfoFetcher),
178-
)
179-
.await
177+
}
180178
}
181179

182180
#[allow(dead_code)]

0 commit comments

Comments
 (0)