Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions test-integration/programs/flexi-counter/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::state::FlexiCounter;
pub struct DelegateArgs {
pub valid_until: i64,
pub commit_frequency_ms: u32,
pub validator: Option<Pubkey>,
}

#[derive(BorshSerialize, BorshDeserialize, Debug, Clone)]
Expand Down Expand Up @@ -298,6 +299,41 @@ pub fn create_delegate_ix_with_commit_frequency_ms(
let args = DelegateArgs {
valid_until: i64::MAX,
commit_frequency_ms,
validator: None,
};

Instruction::new_with_borsh(
*program_id,
&FlexiCounterInstruction::Delegate(args),
account_metas,
)
}

pub fn create_delegate_ix_with_validator(
payer: Pubkey,
validator: Option<Pubkey>,
) -> Instruction {
let program_id = &crate::id();
let (pda, _) = FlexiCounter::pda(&payer);
let commit_frequency_ms = 0;

let delegate_accounts = DelegateAccounts::new(pda, *program_id);
let delegate_metas = DelegateAccountMetas::from(delegate_accounts);
let account_metas = vec![
AccountMeta::new(payer, true),
delegate_metas.delegated_account,
delegate_metas.owner_program,
delegate_metas.delegate_buffer,
delegate_metas.delegation_record,
delegate_metas.delegation_metadata,
delegate_metas.delegation_program,
delegate_metas.system_program,
];

let args = DelegateArgs {
valid_until: i64::MAX,
commit_frequency_ms,
validator,
};

Instruction::new_with_borsh(
Expand Down
2 changes: 1 addition & 1 deletion test-integration/programs/flexi-counter/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ fn process_delegate(
&seeds_no_bump,
DelegateConfig {
commit_frequency_ms: args.commit_frequency_ms,
validator: None,
validator: args.validator,
},
)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub fn process_undelegate_action_handler(
#[allow(dead_code)]
fn process_redelegation_call_handler<'a, 'b>(
accounts: &[AccountInfo],
validator: Option<solana_program::pubkey::Pubkey>,
) -> ProgramResult
where
'a: 'b,
Expand Down Expand Up @@ -128,7 +129,7 @@ where
// Could be passed in CallHandlerArgs::data
DelegateConfig {
commit_frequency_ms: 1000,
validator: None,
validator,
},
)?;

Expand Down
9 changes: 8 additions & 1 deletion test-integration/programs/schedulecommit/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ pub fn grow_order_book_instruction(
}

pub fn init_payer_escrow(payer: Pubkey) -> [Instruction; 2] {
init_payer_escrow_with_validator(payer, None)
}

pub fn init_payer_escrow_with_validator(
payer: Pubkey,
validator: Option<Pubkey>,
) -> [Instruction; 2] {
let top_up_ix = dlp::instruction_builder::top_up_ephemeral_balance(
payer,
payer,
Expand All @@ -104,7 +111,7 @@ pub fn init_payer_escrow(payer: Pubkey) -> [Instruction; 2] {
delegate_args: DelegateArgs {
commit_frequency_ms: 0,
seeds: vec![],
validator: None,
validator,
},
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{Context, Result};
use integration_test_tools::IntegrationTestContext;
use program_schedulecommit::api::{
delegate_account_cpi_instruction, init_account_instruction,
init_order_book_instruction, init_payer_escrow, UserSeeds,
init_order_book_instruction, init_payer_escrow_with_validator, UserSeeds,
};
use solana_rpc_client::rpc_client::{RpcClient, SerializableTransaction};
use solana_rpc_client_api::config::RpcSendTransactionConfig;
Expand Down Expand Up @@ -241,7 +241,12 @@ impl ScheduleCommitTestContext {
}

pub fn escrow_lamports_for_payer(&self) -> Result<Signature> {
let ixs = init_payer_escrow(self.payer_ephem.pubkey());
let validator_identity =
self.common_ctx.ephem_validator_identity.as_ref().copied();
let ixs = init_payer_escrow_with_validator(
self.payer_ephem.pubkey(),
validator_identity,
);
Comment on lines 243 to +249
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Guard against missing validator identity before escrow initialization.

Line 244-249 passes None when ephem_validator_identity is unset, which may lead to escrow delegation without a validator. If production DLP requires a validator, fail fast to make the error explicit.

✅ Suggested guard
-        let validator_identity =
-            self.common_ctx.ephem_validator_identity.as_ref().copied();
-        let ixs = init_payer_escrow_with_validator(
-            self.payer_ephem.pubkey(),
-            validator_identity,
-        );
+        let validator_identity = self
+            .common_ctx
+            .ephem_validator_identity
+            .context("Missing ephem validator identity for escrow init")?;
+        let ixs = init_payer_escrow_with_validator(
+            self.payer_ephem.pubkey(),
+            Some(validator_identity),
+        );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub fn escrow_lamports_for_payer(&self) -> Result<Signature> {
let ixs = init_payer_escrow(self.payer_ephem.pubkey());
let validator_identity =
self.common_ctx.ephem_validator_identity.as_ref().copied();
let ixs = init_payer_escrow_with_validator(
self.payer_ephem.pubkey(),
validator_identity,
);
pub fn escrow_lamports_for_payer(&self) -> Result<Signature> {
let validator_identity = self
.common_ctx
.ephem_validator_identity
.context("Missing ephem validator identity for escrow init")?;
let ixs = init_payer_escrow_with_validator(
self.payer_ephem.pubkey(),
Some(validator_identity),
);
🤖 Prompt for AI Agents
In `@test-integration/schedulecommit/client/src/schedule_commit_context.rs` around
lines 243 - 249, The escrow_lamports_for_payer function currently calls
init_payer_escrow_with_validator passing
self.common_ctx.ephem_validator_identity which may be None; add an explicit
guard in escrow_lamports_for_payer to check that
self.common_ctx.ephem_validator_identity.is_some() (or match on it) and return
an Err with a clear message if missing, otherwise unwrap/copy the
validator_identity and call init_payer_escrow_with_validator as before
(reference symbols: escrow_lamports_for_payer,
common_ctx.ephem_validator_identity, init_payer_escrow_with_validator,
payer_ephem.pubkey()).


// The init tx for all payers is funded by the first payer for simplicity
let tx = Transaction::new_signed_with_payer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,11 @@ fn assert_cannot_increase_committee_count(
);
let (tx_result_err, tx_err) = extract_transaction_error(tx_res);
if let Some(tx_err) = tx_err {
use solana_sdk::transaction::TransactionError;
if matches!(tx_err, TransactionError::InvalidWritableAccount) {
return;
}
Comment on lines +433 to +436
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider moving the use statement outside the conditional block.

The inline use statement works but is unconventional. Moving it to the function scope or top of the file would improve readability.

♻️ Suggested refactor
+use solana_sdk::transaction::TransactionError;
+
 fn assert_cannot_increase_committee_count(
     pda: Pubkey,
     payer: &Keypair,
     rpc_client: &RpcClient,
 ) {
     // ... existing code ...
     
     let (tx_result_err, tx_err) = extract_transaction_error(tx_res);
     if let Some(tx_err) = tx_err {
-        use solana_sdk::transaction::TransactionError;
         if matches!(tx_err, TransactionError::InvalidWritableAccount) {
             return;
         }
🤖 Prompt for AI Agents
In
`@test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs`
around lines 433 - 436, Move the inline `use
solana_sdk::transaction::TransactionError;` out of the conditional and into the
surrounding scope (either the enclosing function or top of the file) so it's not
declared inside the if block; update the scope where `tx_err` is matched (the
`if matches!(tx_err, TransactionError::InvalidWritableAccount) { return; }`
check) to rely on the now-top-level import of `TransactionError` to improve
readability and conventional organization.


assert_is_one_of_instruction_errors(
tx_err,
&tx_result_err,
Expand Down
2 changes: 1 addition & 1 deletion test-integration/test-config/tests/allowed_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn run_allowed_programs(allow_committor_program: bool) {
let (_default_tmpdir, Some(mut validator), port) =
start_magicblock_validator_with_config_struct(
config,
&LoadedAccounts::with_delegation_program_test_authority(),
&LoadedAccounts::new_with_new_validator_authority(),
)
else {
panic!("validator should set up correctly");
Expand Down
2 changes: 2 additions & 0 deletions test-integration/test-config/tests/auto_airdrop_feepayer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(deprecated)]

use std::str::FromStr;

use cleanass::{assert, assert_eq};
Expand Down
2 changes: 1 addition & 1 deletion test-integration/test-config/tests/clone_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn lookup_table_interaction(config: bool) -> (usize, usize, usize) {

let (_temp_dir, mut validator, ctx) = start_validator_with_clone_config(
config,
&LoadedAccounts::with_delegation_program_test_authority(),
&LoadedAccounts::new_with_new_validator_authority(),
);
wait_for_startup(&ctx, &mut validator);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(deprecated)]

use std::{path::Path, process::Child};

use cleanass::assert_eq;
Expand Down
2 changes: 2 additions & 0 deletions test-integration/test-magicblock-api/tests/test_claim_fees.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(deprecated)]

use std::{thread::sleep, time::Duration};

use dlp::instruction_builder::validator_claim_fees;
Expand Down
2 changes: 2 additions & 0 deletions test-integration/test-runner/bin/run_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(deprecated)]

use std::{
error::Error,
io,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use integration_test_tools::IntegrationTestContext;
use program_flexi_counter::{
delegation_program_id,
instruction::{
create_add_ix, create_delegate_ix, create_init_ix, create_intent_ix,
create_add_ix, create_delegate_ix_with_validator, create_init_ix,
create_intent_ix,
},
state::FlexiCounter,
};
Expand Down Expand Up @@ -297,15 +298,30 @@ fn setup_payer(ctx: &IntegrationTestContext) -> Keypair {
ctx.airdrop_chain(&payer.pubkey(), LAMPORTS_PER_SOL)
.unwrap();

// Create actor escrow
let ix = dlp::instruction_builder::top_up_ephemeral_balance(
// Create actor escrow with delegation
let top_up_ix = dlp::instruction_builder::top_up_ephemeral_balance(
payer.pubkey(),
payer.pubkey(),
Some(LAMPORTS_PER_SOL / 2),
Some(1),
);
ctx.send_and_confirm_instructions_with_payer_chain(&[ix], &payer)
.unwrap();
let delegate_ix = dlp::instruction_builder::delegate_ephemeral_balance(
payer.pubkey(),
payer.pubkey(),
dlp::args::DelegateEphemeralBalanceArgs {
index: 1,
delegate_args: dlp::args::DelegateArgs {
commit_frequency_ms: 0,
seeds: vec![],
validator: ctx.ephem_validator_identity,
},
},
);
ctx.send_and_confirm_instructions_with_payer_chain(
&[top_up_ix, delegate_ix],
&payer,
)
.unwrap();

// Confirm actor escrow
let escrow_pda = ephemeral_balance_pda_from_payer(&payer.pubkey(), 1);
Expand Down Expand Up @@ -344,7 +360,10 @@ fn delegate_counter(ctx: &IntegrationTestContext, payer: &Keypair) {
ctx.wait_for_next_slot_ephem().unwrap();

let counter_pda = FlexiCounter::pda(&payer.pubkey()).0;
let ix = create_delegate_ix(payer.pubkey());
let ix = create_delegate_ix_with_validator(
payer.pubkey(),
ctx.ephem_validator_identity,
);
ctx.send_and_confirm_instructions_with_payer_chain(&[ix], payer)
.unwrap();

Expand Down
2 changes: 2 additions & 0 deletions test-integration/test-task-scheduler/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(deprecated)]

use std::{process::Child, str::FromStr, time::Duration};

use integration_test_tools::{
Expand Down
15 changes: 9 additions & 6 deletions test-integration/test-tools/src/loaded_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ impl LoadedAccounts {
}
}

/// This use the test authority used in the delegation program as the validator
/// authority.
/// https://github.com/magicblock-labs/delegation-program/blob/7fc0ae9a59e48bea5b046b173ea0e34fd433c3c7/tests/fixtures/accounts.rs#L46
/// It is compiled in as the authority for the validator vault when we build
/// the delegation program via:
/// `cargo build-sbf --features=unit_test_config`
/// DEPRECATED: This function was used when dlp was built with unit_test_config.
/// With production dlp (without unit_test_config), this hardcoded authority
/// is no longer baked into the delegation program.
/// Use `new_with_new_validator_authority()` instead for new tests.
/// Keep this only for backward compatibility with existing test infrastructure.
#[deprecated(
since = "0.0.0",
note = "DLP now uses production build without unit_test_config. Use new_with_new_validator_authority() instead."
)]
pub fn with_delegation_program_test_authority() -> Self {
Self {
validator_authority_kp: Keypair::from_bytes(
Expand Down
Loading