From 53edf33c30456cf98da387118672ba7ce79fd17c Mon Sep 17 00:00:00 2001 From: AvhiMaz Date: Fri, 14 Nov 2025 14:37:00 +0530 Subject: [PATCH 1/5] fix: migrate integration tests to production dlp without unit_test_config (#602) Replace the precompiled dlp.so binary with a production version compiled without the unit_test_config feature, which hardcoded test validator authorities. Update integration tests and test programs to accept and properly pass custom validator identities instead of relying on hardcoded test values. Fixes #602 Signed-off-by: AvhiMaz --- .../programs/flexi-counter/src/instruction.rs | 7 ++++++ .../src/processor/call_handler.rs | 3 ++- .../programs/schedulecommit/src/api.rs | 9 +++++++- .../client/src/schedule_commit_context.rs | 12 ++++++++-- .../tests/02_commit_and_undelegate.rs | 5 +++++ .../tests/auto_airdrop_feepayer.rs | 2 ++ .../tests/06_delegated_account.rs | 2 ++ .../tests/test_claim_fees.rs | 2 ++ test-integration/test-runner/bin/run_tests.rs | 2 ++ .../tests/test_schedule_intents.rs | 22 ++++++++++++++----- .../test-task-scheduler/src/lib.rs | 2 ++ .../test-tools/src/loaded_accounts.rs | 15 ++++++++----- 12 files changed, 68 insertions(+), 15 deletions(-) diff --git a/test-integration/programs/flexi-counter/src/instruction.rs b/test-integration/programs/flexi-counter/src/instruction.rs index 8986f4850..e9350af1e 100644 --- a/test-integration/programs/flexi-counter/src/instruction.rs +++ b/test-integration/programs/flexi-counter/src/instruction.rs @@ -307,6 +307,13 @@ pub fn create_delegate_ix_with_commit_frequency_ms( ) } +pub fn create_delegate_ix_with_validator( + payer: Pubkey, + _validator: Option, +) -> Instruction { + create_delegate_ix(payer) +} + pub fn create_add_and_schedule_commit_ix( payer: Pubkey, count: u8, diff --git a/test-integration/programs/flexi-counter/src/processor/call_handler.rs b/test-integration/programs/flexi-counter/src/processor/call_handler.rs index 9e655ee9c..cbee175d3 100644 --- a/test-integration/programs/flexi-counter/src/processor/call_handler.rs +++ b/test-integration/programs/flexi-counter/src/processor/call_handler.rs @@ -99,6 +99,7 @@ pub fn process_undelegate_action_handler( #[allow(dead_code)] fn process_redelegation_call_handler<'a, 'b>( accounts: &[AccountInfo], + validator: Option, ) -> ProgramResult where 'a: 'b, @@ -128,7 +129,7 @@ where // Could be passed in CallHandlerArgs::data DelegateConfig { commit_frequency_ms: 1000, - validator: None, + validator, }, )?; diff --git a/test-integration/programs/schedulecommit/src/api.rs b/test-integration/programs/schedulecommit/src/api.rs index 8f359a56c..28b1a8433 100644 --- a/test-integration/programs/schedulecommit/src/api.rs +++ b/test-integration/programs/schedulecommit/src/api.rs @@ -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, +) -> [Instruction; 2] { let top_up_ix = dlp::instruction_builder::top_up_ephemeral_balance( payer, payer, @@ -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, }, }, ); diff --git a/test-integration/schedulecommit/client/src/schedule_commit_context.rs b/test-integration/schedulecommit/client/src/schedule_commit_context.rs index 269d49488..0878dc900 100644 --- a/test-integration/schedulecommit/client/src/schedule_commit_context.rs +++ b/test-integration/schedulecommit/client/src/schedule_commit_context.rs @@ -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; @@ -241,7 +241,15 @@ impl ScheduleCommitTestContext { } pub fn escrow_lamports_for_payer(&self) -> Result { - 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, + ); // The init tx for all payers is funded by the first payer for simplicity let tx = Transaction::new_signed_with_payer( diff --git a/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs b/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs index 5973b34a6..2630679a5 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs @@ -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; + } + assert_is_one_of_instruction_errors( tx_err, &tx_result_err, diff --git a/test-integration/test-config/tests/auto_airdrop_feepayer.rs b/test-integration/test-config/tests/auto_airdrop_feepayer.rs index 7971ae4e5..28d19bf5b 100644 --- a/test-integration/test-config/tests/auto_airdrop_feepayer.rs +++ b/test-integration/test-config/tests/auto_airdrop_feepayer.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use std::str::FromStr; use cleanass::{assert, assert_eq}; diff --git a/test-integration/test-ledger-restore/tests/06_delegated_account.rs b/test-integration/test-ledger-restore/tests/06_delegated_account.rs index 0aca0e1e5..fbe8b001f 100644 --- a/test-integration/test-ledger-restore/tests/06_delegated_account.rs +++ b/test-integration/test-ledger-restore/tests/06_delegated_account.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use std::{path::Path, process::Child}; use cleanass::assert_eq; diff --git a/test-integration/test-magicblock-api/tests/test_claim_fees.rs b/test-integration/test-magicblock-api/tests/test_claim_fees.rs index 5b7ffc8a9..65fab3ce5 100644 --- a/test-integration/test-magicblock-api/tests/test_claim_fees.rs +++ b/test-integration/test-magicblock-api/tests/test_claim_fees.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use std::{thread::sleep, time::Duration}; use dlp::instruction_builder::validator_claim_fees; diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index 6a5a6e9c7..ef470ec3b 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use std::{ error::Error, io, diff --git a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs index fa30b64f0..eaad4f2f4 100644 --- a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs +++ b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs @@ -3,7 +3,7 @@ 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, }; @@ -297,14 +297,26 @@ 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) + let delegate_ix = dlp::instruction_builder::delegate_ephemeral_balance( + payer.pubkey(), + payer.pubkey(), + dlp::args::DelegateEphemeralBalanceArgs { + index: 0, + 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 @@ -344,7 +356,7 @@ 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(); diff --git a/test-integration/test-task-scheduler/src/lib.rs b/test-integration/test-task-scheduler/src/lib.rs index 44c9f0c6c..e73c54afb 100644 --- a/test-integration/test-task-scheduler/src/lib.rs +++ b/test-integration/test-task-scheduler/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use std::{process::Child, str::FromStr, time::Duration}; use integration_test_tools::{ diff --git a/test-integration/test-tools/src/loaded_accounts.rs b/test-integration/test-tools/src/loaded_accounts.rs index b1e998f80..6cf528a0e 100644 --- a/test-integration/test-tools/src/loaded_accounts.rs +++ b/test-integration/test-tools/src/loaded_accounts.rs @@ -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 = "issue-602", + 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( From 953edd8208fe2065a4a40b7c5baa1bc7e4eecec7 Mon Sep 17 00:00:00 2001 From: AvhiMaz Date: Fri, 14 Nov 2025 15:29:18 +0530 Subject: [PATCH 2/5] fix: use production dlp for integration tests Signed-off-by: AvhiMaz --- .../test-schedule-intent/tests/test_schedule_intents.rs | 2 +- test-integration/test-tools/src/loaded_accounts.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs index eaad4f2f4..db7675ba9 100644 --- a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs +++ b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs @@ -308,7 +308,7 @@ fn setup_payer(ctx: &IntegrationTestContext) -> Keypair { payer.pubkey(), payer.pubkey(), dlp::args::DelegateEphemeralBalanceArgs { - index: 0, + index: 1, delegate_args: dlp::args::DelegateArgs { commit_frequency_ms: 0, seeds: vec![], diff --git a/test-integration/test-tools/src/loaded_accounts.rs b/test-integration/test-tools/src/loaded_accounts.rs index 6cf528a0e..31f1f58f7 100644 --- a/test-integration/test-tools/src/loaded_accounts.rs +++ b/test-integration/test-tools/src/loaded_accounts.rs @@ -55,7 +55,7 @@ impl LoadedAccounts { /// Use `new_with_new_validator_authority()` instead for new tests. /// Keep this only for backward compatibility with existing test infrastructure. #[deprecated( - since = "issue-602", + since = "0.2.3", 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 { From 518d1375c83f5b818229724daa8f0bc8921c73eb Mon Sep 17 00:00:00 2001 From: AvhiMaz Date: Fri, 14 Nov 2025 15:38:35 +0530 Subject: [PATCH 3/5] fix: update deprecation version to match test-integration workspace Signed-off-by: AvhiMaz --- test-integration/test-tools/src/loaded_accounts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-integration/test-tools/src/loaded_accounts.rs b/test-integration/test-tools/src/loaded_accounts.rs index 31f1f58f7..5ba15deae 100644 --- a/test-integration/test-tools/src/loaded_accounts.rs +++ b/test-integration/test-tools/src/loaded_accounts.rs @@ -55,7 +55,7 @@ impl LoadedAccounts { /// Use `new_with_new_validator_authority()` instead for new tests. /// Keep this only for backward compatibility with existing test infrastructure. #[deprecated( - since = "0.2.3", + 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 { From ed1441bb88984ae16ee1693c0090dddfe02a007c Mon Sep 17 00:00:00 2001 From: AvhiMaz Date: Fri, 14 Nov 2025 16:08:32 +0530 Subject: [PATCH 4/5] fix: fix formatting issue Signed-off-by: AvhiMaz --- .../client/src/schedule_commit_context.rs | 7 ++----- .../tests/test_schedule_intents.rs | 15 +++++++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/test-integration/schedulecommit/client/src/schedule_commit_context.rs b/test-integration/schedulecommit/client/src/schedule_commit_context.rs index 0878dc900..58d81e44f 100644 --- a/test-integration/schedulecommit/client/src/schedule_commit_context.rs +++ b/test-integration/schedulecommit/client/src/schedule_commit_context.rs @@ -241,11 +241,8 @@ impl ScheduleCommitTestContext { } pub fn escrow_lamports_for_payer(&self) -> Result { - let validator_identity = self - .common_ctx - .ephem_validator_identity - .as_ref() - .copied(); + 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, diff --git a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs index db7675ba9..33b2e4c33 100644 --- a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs +++ b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs @@ -3,7 +3,8 @@ use integration_test_tools::IntegrationTestContext; use program_flexi_counter::{ delegation_program_id, instruction::{ - create_add_ix, create_delegate_ix_with_validator, create_init_ix, create_intent_ix, + create_add_ix, create_delegate_ix_with_validator, create_init_ix, + create_intent_ix, }, state::FlexiCounter, }; @@ -316,8 +317,11 @@ fn setup_payer(ctx: &IntegrationTestContext) -> Keypair { }, }, ); - ctx.send_and_confirm_instructions_with_payer_chain(&[top_up_ix, delegate_ix], &payer) - .unwrap(); + 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); @@ -356,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_with_validator(payer.pubkey(), ctx.ephem_validator_identity); + let ix = create_delegate_ix_with_validator( + payer.pubkey(), + ctx.ephem_validator_identity, + ); ctx.send_and_confirm_instructions_with_payer_chain(&[ix], payer) .unwrap(); From b6108616ad7692f4093ce6179488182eec91937a Mon Sep 17 00:00:00 2001 From: AvhiMaz Date: Sun, 18 Jan 2026 11:48:45 +0530 Subject: [PATCH 5/5] fix: add validator field & update related functions Signed-off-by: AvhiMaz --- .../programs/flexi-counter/src/instruction.rs | 33 +++++++++++++++++-- .../programs/flexi-counter/src/processor.rs | 2 +- .../test-config/tests/allowed_programs.rs | 2 +- .../test-config/tests/clone_config.rs | 2 +- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/test-integration/programs/flexi-counter/src/instruction.rs b/test-integration/programs/flexi-counter/src/instruction.rs index e9350af1e..efdbc285e 100644 --- a/test-integration/programs/flexi-counter/src/instruction.rs +++ b/test-integration/programs/flexi-counter/src/instruction.rs @@ -15,6 +15,7 @@ use crate::state::FlexiCounter; pub struct DelegateArgs { pub valid_until: i64, pub commit_frequency_ms: u32, + pub validator: Option, } #[derive(BorshSerialize, BorshDeserialize, Debug, Clone)] @@ -298,6 +299,7 @@ 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( @@ -309,9 +311,36 @@ pub fn create_delegate_ix_with_commit_frequency_ms( pub fn create_delegate_ix_with_validator( payer: Pubkey, - _validator: Option, + validator: Option, ) -> Instruction { - create_delegate_ix(payer) + 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( + *program_id, + &FlexiCounterInstruction::Delegate(args), + account_metas, + ) } pub fn create_add_and_schedule_commit_ix( diff --git a/test-integration/programs/flexi-counter/src/processor.rs b/test-integration/programs/flexi-counter/src/processor.rs index 47ad47cff..4206fbbd8 100644 --- a/test-integration/programs/flexi-counter/src/processor.rs +++ b/test-integration/programs/flexi-counter/src/processor.rs @@ -301,7 +301,7 @@ fn process_delegate( &seeds_no_bump, DelegateConfig { commit_frequency_ms: args.commit_frequency_ms, - validator: None, + validator: args.validator, }, )?; diff --git a/test-integration/test-config/tests/allowed_programs.rs b/test-integration/test-config/tests/allowed_programs.rs index a4e6f6770..e33b0a0f8 100644 --- a/test-integration/test-config/tests/allowed_programs.rs +++ b/test-integration/test-config/tests/allowed_programs.rs @@ -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"); diff --git a/test-integration/test-config/tests/clone_config.rs b/test-integration/test-config/tests/clone_config.rs index 9dc434164..8db3fb103 100644 --- a/test-integration/test-config/tests/clone_config.rs +++ b/test-integration/test-config/tests/clone_config.rs @@ -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);